Module aisa.base
Functions
def best_partition(graph, T=None, beta=0.0, init_part=None, kmin=None, kmax=None, invtemp=1000000.0, compute_steady=True, tsteps=10000)-
Find the best partition for
graph.Parameters
graph:nx.Graphornx.DiGraph- The graph to be aggregated (a random walk is considered as dynamical system)
init_part:dict, optional- initial partition to start the optimization. (Default: N singletons)
T:int, default=None- time scale parameter value. Default to None, meaning it will in fact use T=1
beta:float, default=0.0- model selection parameter.
kmin:int- minimum number of partition to be accepted
kmax:int- maximum number of partition to be accepted
invtemp:float, default=1e6- the inverse of the pseudo-temperature for the simulated annealing process
compute_steady:bool- If steady state need to be computed. (Default: True) If False, the steady state will be the marginal.
tsteps:int- Maximum number of steps in the optimization process. (Default: 10k)
Returns
partition:dict- Dictionary with nodes as keys and partitions as values.
autoinformation:float- Value of the autoinformation
Raises
ValueError :- init_part should be None or dict
def entrogram(graph, partition, depth=3)-
Compute the entrogram for the graph and the given partition.
A random walk is assumed as Markovian process on the original network.
Parameters
graph:nx.Graphornx.DiGraphpartition:dict- A dictionary with nodes as keys and values as classes.
depth:int- The number of bars the final entrogram should have. (Default: 3)
Returns
entrogram:tuple-
- ( H_{KS} )
- list of entrogram entries
def merge_pgraph(pgraph, beta=0.0, kmin=1, kmax=inf)-
Hierarchical merging of classes.
pgraphwill be updated to the best encounteded partition.Parameters
pgraph:PGraph- A graph plus partition.
beta:float- Model selection parameter (Default: 0.0)
kmin:int- minimum number of partition to be accepted
kmax:int- maximum number of partition to be accepted
def optimize(pgraph, kmin, kmax, invtemp, tsteps, beta=0.0)-
Optimize the partition enbedded into
pgraph.Parameters
pgraph:PGraph- A graph plus partition.
kmin:int- minimum number of partition to be accepted
kmax:int- maximum number of partition to be accepted
invtemp:float- the inverse of the pseudo-temperature for the simulated annealing process
tsteps:int- Maximum number of steps in the optimization process. (Default: 10k)
Returns
best_partition:dict- best partition after otpimization (pgraph will be updated accordingly)
Classes
class PGraph (graph, init_part=None, compute_steady=True, T=None)-
A graph with a partition.
Initialize from
networkxgraphs.Parameters
graph:nx.[Di]Graph()- The graph
init_part:dict- initial partition to start the optimization. (Default: N singletons)
compute_steady:bool- If steady state need to be computed. (Default: True) If False, the steady state will be the marginal.
T:int- time scale parameter value. (Default: 1)
Instance variables
var nn-
Return the number of nodes.
var np-
Return the number of partitions.
Methods
def autoinformation(self, beta)-
Return the autoinformation value for the current partion.
Parameters
beta:float- model selection parameter. (Default: 0)
Returns
autoinformation:float- the autoinformation
def merge_partitions(self, part1, part2)-
Merge partitions into one.
Merge partition
part1andpart2and update pgraph accordingly.Parameters
part1:int- integer index of the first partition to be merged
part2:int- integer index of the second partition to be merged
def nodes(self)-
Iterate over nodes names.
Yields
nodes
def partition(self)-
Return the partition.
Returns
partition:dict- a dictionary with nodes as keys and classes as values.
def print_partition(self)-
Try to print the partition to screen using ASCII chars.
def set_partition(self, partition=None)-
Set/Change the graph partition.
Parameters
partition:dict- The partition to be set. A dict with nodes as keys and classes as values