Skip to content

Commit

Permalink
Leftover changes
Browse files Browse the repository at this point in the history
Leftover changes
  • Loading branch information
AlainKadar authored Feb 6, 2024
2 parents c66683a + c635a48 commit f19f0d1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 34 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ To use, clone, build, and install from the `GitHub repository

.. code:: bash
conda install igraph eigen cython
git clone https://github.com/AlainKadar/StructuralGT
conda install -c conda-forge igraph eigen cython
cd StructuralGT
python setup.py install
Expand All @@ -33,5 +33,5 @@ The following minimal example shows how the package can be used to calculate the
Nanofibre3DNetwork.set_graph(weight_type=['Length'])
S = Structural()
S.compute(ANF)
S.compute(Nanofibre3DNetwork)
print(S.diameter)
2 changes: 1 addition & 1 deletion StructuralGT/average_nodal_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from StructuralGT import _average_nodal_connectivity_cast

class AverageNodalConnectivity(_Compute):
"""A module solely for calculating the average nodal connectivity.
"""A module for calculating the average nodal connectivity.
Written separately because it is computationally very expensive, yet has
been shown to correlate well with material properties.REF
"""
Expand Down
8 changes: 4 additions & 4 deletions StructuralGT/betweenness.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def compute(self, network, sources, targets, skips=None, incoming=None,
network (:class:`Network`):
The :class:`Network` object.
sources (list):
The set of source nodes, $S$.
The set of source nodes, :math:`S`.
targets (list):
The set of target nodes, $T$.
The set of target nodes, :math:`T`.
weights (str, optional):
The name of the edge attribute to be used in weighting the
random walks. If omitted, an unweighted network is used.
Expand All @@ -118,10 +118,10 @@ def bounded(self):
c_B(v) =\sum_{s\in S,t \in T} \frac{\sigma(s, t|e)}{\sigma(s, t)}
where $S$ is the set of sources, $T$ is the set of targets,
where :math:`S` is the set of sources, :math:`T` is the set of targets,
$\sigma(s, t)$ is the number of shortest $(s, t)$-paths,
and $\sigma(s, t|e)$ is the number of those paths
passing through edge $e$ :cite:`Brandes2008` (which is unity for real
passing through edge :math:`e` :cite:`Brandes2008` (which is unity for real
value weighted graphs).
"""
return self._bounded_betweenness
Expand Down
51 changes: 26 additions & 25 deletions StructuralGT/structural.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Structural(_Compute):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def compute(self, network, skips=None):
def compute(self, network):
"""Calculates graph diameter, density, assortativity by degree,
and average clustering coefficient. Also calculates per node degree,
closeness, betweenness, and clustering.
Expand Down Expand Up @@ -64,23 +64,24 @@ def density(self):
.. math::
\rho = \frac{2e}{n(n-1)}
\rho = \frac{2e}{n(n-1)}
"""
return self.Density

@_Compute._computed_property
def clustering(self):
r""":class:`np.ndarray`: Array of clustering coefficients, $\delta_i$s.
The clustering coefficient is the fraction of neighbors of a node that
are directly connected to each other as well (forming a triangle):
r""":class:`np.ndarray`: Array of clustering coefficients,
:math:`\delta_i`s. The clustering coefficient is the fraction of
neighbors of a node that are directly connected to each other as well
(forming a triangle):
.. math::
\delta_i = \frac{2*T_i}{k_i(k_i-1)}
\delta_i = \frac{2*T_i}{k_i(k_i-1)}
Where $T_i$ Ti is the number of connected triples (visually triangles)
on node i.
Where :math:`T_i` is the number of connected triples (visually triangles)
on node :math:`i`.
"""
return self.Clustering
Expand All @@ -91,7 +92,7 @@ def average_clustering_coefficient(self):
.. math::
\Delta = \frac{\sum_i{\delta}}{n}
\Delta = \frac{\sum_i{\delta}}{n}
"""
return np.mean(self.clustering)
Expand All @@ -102,49 +103,49 @@ def assortativity(self):
connections by node degree. This value approaches 1 if nodes with the
same degree are directly connected to each other and approaches −1
if nodes are all connected to nodes with different degree. A value
near 0 indicates random orientation: :cite:`Newman2002`
near 0 indicates uncorrelated connections: :cite:`Newman2018`
.. math::
r = \frac{1}{\sigma_q^2}\sum_{jk} jk(e_{jk}-q_j * q_k)
r = \frac{1}{\sigma_q^2}\sum_{jk} jk(e_{jk}-q_j * q_k)
where $q$ is the *remaining degree distribution*, $\sigma_{q}^2$ is its
variance. $e_{jk}$ is the joint probability distribution of the
remaining degrees of the two vertices at either end of a randomly
chosen edge.
where :math:`q` is the *remaining degree distribution*,
:math:`\sigma_{q}^2` is it variance. :math:`e_{jk}` is the joint
probability distribution of the remaining degrees of the two vertices
at either end of a randomly chosen edge.
"""
return self.Degree_Assortativity

@_Compute._computed_property
def betweenness(self):
r""":class:`np.ndarray`: The betweenness centrality of node $i$ is a measure of how
frequently the shortest path between other nodes $u$ and $v$ pass
through node $i$:
r""":class:`np.ndarray`: The betweenness centrality of node :math:`i` is a measure of how
frequently the shortest path between other nodes :math:`u` and :math:`v` pass
through node :math:`i`:
.. math::
C_{B}(i) = \sum_{u,v}\frac{\sigma(u,v)}{\sigma(u,v \parallel i)}
C_{B}(i) = \sum_{u,v}\frac{\sigma(u,v)}{\sigma(u,v \parallel i)}
where $\sigma(u,v)$ represents the number of shortest
paths that exist between nodes $u$ and $v$, with the term
paths that exist between nodes :math:`u` and :math:`v`, with the term
$\sigma(u,v \parallel i)$ representing the number of those paths that
pass through node $i$. For variations on this parameter, see the
pass through node :math:`i`. For variations on this parameter, see the
:class:`Betweenness` module.
"""
return np.asarray(self.Betweenness)/(self.vcount-1)/(self.vcount-2)*2

@_Compute._computed_property
def closeness(self):
r""":class:`np.ndarray`: The closeness centrality of node $i$ is the
reciprocal of the average shortest distance from node $i$ to all
r""":class:`np.ndarray`: The closeness centrality of node :math:`i` is the
reciprocal of the average shortest distance from node :math:`i` to all
other nodes:
.. math::
C_{C}(i) = \frac{n-1}{\sum_{j=1}^{n-1}L(i,j)}
C_{C}(i) = \frac{n-1}{\sum_{j=1}^{n-1}L(i,j)}
where $L(i,j)$ is the shortest path between nodes $i$ and $j$.
where $L(i,j)$ is the shortest path between nodes :math:`i` and :math:`j`.
"""
return self.Closeness
Expand Down
4 changes: 2 additions & 2 deletions doc/source/gettingstarted/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Introduction
============

StructuralGT is a Python package for graph theoretic analysis of image data. Originally prototyped as a GUI based package for microscopy data:cite:`Vecchio2020` the package outlined in this documentation is designed for terminal based use. Addtionally, this package offers the possibility of analysing 3-dimensional datasets and property predictions. Initial graph theoretic studies of microscopy datasets have shown structural differences betweeen disordered architectures of various nanoscale materials. This API offers the users the possiblility of performing analysis that had not been anticipated by the developers' original implementation. Examples of such analyses are given in Examples.
StructuralGT is a Python package for graph theoretic analysis of image data. Originally prototyped as a GUI based package for microscopy data,:cite:`Vecchio2020` the package outlined in this documentation is designed for terminal based use. Addtionally, this package offers the possibility of analysing 3-dimensional datasets and property predictions. Initial graph theoretic studies of microscopy datasets have shown structural differences betweeen disordered architectures of various nanoscale materials. This API offers the users the possiblility of performing analysis beyond what has been reported in the literature. Some basic examples of analyses are given in Examples.

All analyses carried out with StructuralGT involve a :class:`Network` class, which represents the system being studied. To motivate it's construction, we first outline the conceptual differecne between a `network` and a `graph`. Networks are real-world objects which exhibit a structure akin to points linked by connections. Their study belongs to the discipline of `network science` and examples may include social networks, internet networks, or material networks. The mathematical objects which abstract these structures are graphs, and the discipline which examines them is `graph theory`. A graph may be defined only by it's nodes and connecting edges. While the nodes and edges may contain attributes, to give further detail, a large part of the network's description is lost as a result of it's abstraction into a graph (most notably, its geometric features). Hence we construct the :class:`Network` class to contain a conventional graph, and all other information that would be otherwise lost. Specifically, after the appropriate graph extraction methods have been called, the :class:`Network` class is populated with a :attr:`graph` attribute.

The second component required for analysis in StructuralGT is a :class:`Compute` class, which represents the calculations being carried out on the system (i.e. :class:`Network` class). All compute methods may be instantiated with a weight type, to specify whether graph weights are to be used in the calculations. Compute modules contain a :meth:`compute` method, which populates the object with attributes containing the results of the calculations. Generally, compute modules call a mixture of python functions and fast graph theoretic computations, via the :code:`igraph` C library:cite:`Csardi`. In some cases, (:class:`AverageNodalConnectivity` and :class:`Betweenness`), compute modules call custom C-routines as well. When the user wishes to carry out their own custom analysis with C-level speed, they may implement their own C routines, which expose the results to the Python API. Instructions on this implementation are given in REF.
The second component required for analysis in StructuralGT is a :class:`Compute` class, which represents the calculations being carried out on the system (i.e. :class:`Network` class). All compute methods may be instantiated with a weight type, to specify whether graph weights are to be used in the calculations. Compute modules contain a :meth:`compute` method, which populates the object with attributes containing the results of the calculations. Generally, compute modules call a mixture of python functions and fast graph theoretic computations, via the :code:`igraph` C library:cite:`Csardi`. When the user wishes to carry out their own custom analysis with C-level speed, they may implement their own C routines, which expose the results to the Python API. Instructions on this implementation are given in Adding C++ Scripts.

0 comments on commit f19f0d1

Please sign in to comment.