navis 1.4.0
  • Install
  • Quickstart
  • Tutorials
  • API
  • Changelog
  • Github
  • Ecosystem
  • Site
    • Page
        • navis.models.network_models.BayesianTraversalModel
          • BayesianTraversalModel
            • BayesianTraversalModel.__init__()

    navis.models.network_models.BayesianTraversalModel¶

    class navis.models.network_models.BayesianTraversalModel(*args, traversal_func=None, **kwargs)[source]¶

    Model for traversing a network starting with given seed nodes.

    This model is a Bayes net version of TraversalModel that propagates traversal probabilities through the network and converges to a distribution of time of traversal for each node, rather than stochastically sampling.

    Unlike TraversalModel, this model should only be run once. Note alse that traversal_func should be a function returing probabilities of traversal, rather than a random boolean of traversal.

    Parameters:
    • edges (pandas.DataFrame) – DataFrame representing an edge list. Must minimally have a source and target column.

    • seeds (iterable) – Seed nodes for traversal. Nodes that aren’t found in edges['source'] will be (silently) removed.

    • weights (str, optional) – Name of a column in edges used as weights. If not provided, all edges will be given a weight of 1. If using the default activation function the weights need to be between 0 and 1.

    • max_steps (int) – Limits the number of steps for each iteration.

    • traversal_func (callable, optional) – Function returning probability whether a given edge will be traversed or not in a given step. Must take numpy array (N, 1) of edge weights and return an array with probabilities of equal size. Defaults to linear_activation_p() which will linearly scale probability of traversal from 0 to 100% between edges weights 0 to 0.3.

    Examples

    >>> from navis.models import BayesianTraversalModel
    >>> import networkx as nx
    >>> import numpy as np
    >>> # Generate a random graph
    >>> G = nx.fast_gnp_random_graph(1000, .2, directed=True)
    >>> # Turn into edge list
    >>> edges = nx.to_pandas_edgelist(G)
    >>> # Add random edge weights
    >>> edges['weight'] = np.random.random(edges.shape[0])
    >>> # Initialize model
    >>> model = BayesianTraversalModel(edges, seeds=list(G.nodes)[:10])
    >>> # Run model
    >>> res = model.run()
    >>> # Get a summary
    >>> model.summary.tail()                                    
          layer_min  layer_max  layer_mean  layer_median
    node
    995           2          2        2.00             2
    996           2          3        2.33             2
    997           2          2        2.00             2
    998           2          2        2.00             2
    999           2          2        2.00             2
    

    Above Graph was traversed quickly (3 steps max). Let’s adjust the traversal function:

    >>> from navis.models import linear_activation_p
    >>> # Use a lower probability for activation
    >>> def my_act(x):
    ...     return linear_activation_p(x, max_w=10)
    >>> model = BayesianTraversalModel(edges, seeds=list(G.nodes)[:10],
    ...                                traversal_func=my_act)
    >>> res = model.run()
    >>> res.tail()                                              
          layer_min  layer_max  layer_mean  layer_median
    node
    995           2          4       3.210           3.0
    996           2          4       3.280           3.0
    997           2          4       3.260           3.0
    998           2          4       3.320           3.0
    999           2          4       3.195           3.0
    

    Initialize model.

    __init__(*args, traversal_func=None, **kwargs)[source]¶

    Initialize model.

    Methods

    __init__(*args[, traversal_func])

    Initialize model.

    initializer()

    make_summary()

    Generate summary.

    run(**kwargs)

    Run model (single process).

    run_parallel(*args, **kwargs)

    Run model using parallel processes.

    Attributes

    has_results

    Check if model has results.

    n_nodes

    Return unique nodes in network.

    summary

    Per-node summary.

    Back to top

    Source

    © Copyright 2018, Philipp Schlegel.
    Created using Sphinx 5.3.0.