Package: wisdom-of-crowds
wisdom-of-crowdsThe packageThis package provides a replication and extension of the measures described in Sullivan et al. (2020) Vulnerability in Social Epistemic NetworksInternational Journal of Philosophical Studieshttps://doi.org/10.1080/09672559.2020.1782562The core idea is that we can get a sense of the epistemic position of people in a social network--conceived of as a directed graph--by looking at both the diversity and relatedness of their sources. The key concept is that of an m,k-observer: a node n is an m,k-observer just in case it has at least one set of m source nodes that are pairwise at least k-distant from one another along paths that do not include n. Distance is assumed to be directed, though the measure is defined for undirected graphs.The package itself provides a single classCrowd()which is initialized with anetworkxgraph (typically aDiGraph).Crowd()allows for computation of several functions directly. Most functions callis_mk_observer(node,m,k)The functionS(node)gives the max m*k for which  node is an m,k-observer. The functionh_measure(node)returns the max h such that node is an h,h-observer (compare to the h-index).There is also a functionD(node)that returns thediversityof a node, defined as the number of distinct  sources from which a node receives testimony. This requires an  attribute (default'T') which is used to query inbound nodes. The attribute may yield a single value or a set of values.D(node)is defined as the number of distinct values  across all source nodes/edges.  Finally,pi(node)is defined as D*S.As per Sullivan et al,Sis not calculated for k<2, so a node with zero or one inputs has S=0.Installationwisdom_of_crowdsv1.1.1 is live on pypi (pip), so to get started, just install with pip(3), depending on OSpipinstallwisdom_of_crowds# assuming the Python install is >=3.7, and not on a Mac environmentpip3installwisdom_of_crowds# assuming the Python install is >=3.7 and on a Mac - due to clashes with the default Mac Python 2.x installQuick start guideFor example, given anetworkxgraph, say a digraphGof a social network, we can easily use the package as follows:c=Crowd(G)# defaultscheck_n=c.is_mk_observer('n',3,3)# checks if node 'n' in G is a 3,3-observerS_n=c.S('n')# returns the S-value of node 'n'; S = max_{(m,k) in MK}(m * k)D_n=c.D('n')# returns the D-value (Diversity) of node 'n'pi_n=c.pi('n')# returns the pi-value of node 'n'; pi = S * Dh_n=c.h_measure('n')# returns the h-measure of node 'n'; the highest h for which mk_observer('n', h, h) is TrueExample with visualizationRefer toexample notebook.ipynbfor a more detailed ready-to-use example with visualization.DocumentationThe documentation is availablehere, generated using the amazinglazydocstool.Implementation notesDetermining whether a node is an m,k-observer involves solving combinatorially many multiple shortest path problems along with a minimal independent set problem. Both are computationally demanding. Our goal was to be able to run the above algorithms on large graphs in a reasonable time.To that end, there are several speedups implemented. Behind the scenesCrowddoes a lot of caching of seen paths. The means that lookups for single nodes may seem slow, but iterating over all nodes ofen speeds up over time. It also means that pickling aCrowd()can result in surprisingly large files, though on the plus side it means that re-computing values is often trivial.  The clique-finding problem is optimized to terminate early if possible, but verifying that a node isnotan m,k-observer can be time consuming on nodes with a large number of sources.On the plus side, the optimizations mean that calcluating measures for an entire graph can be very fast. It is possible to compute (e.g.) measures for every node in a realistic social graph (tens of thousands of nodes,  hundreds of thousands of edges) in a few hours on desktop machines.License and CitationThis software is released under the GNU General Public License version 3 (GPL3.0)https://opensource.org/licenses/GPL-3.0If you use this package, we'd appreciate a citation! (Watch this space for details)Version historyv1.01.2 2 June 2022 -- bugfix on sparse graphsv1.01.1 11 May 2022 -- first version on pypi, successfully testedv1.01 2 Mar 2022 -- License updatev1.0  17 Dec 2021  -- released to publicTechnologies and components usedLibraries:networkx,matplotlib,pytest,coverageDocumentation/badging:lazydocs,genbadge,shields.io