Models
cynetdiff.models
¶
DiffusionModel
¶
Base class for Diffusion Models. This class provides an interface for advancing, resetting, and retrieving newly activated nodes. Nodes for the graph of the diffusion process have labels in [0, n-1] and the graph is represented in compressed sparse row format.
advance_model()
method descriptor
¶
Advances the diffusion model by one step.
advance_until_completion()
method descriptor
¶
Continuously advances the model until the diffusion process is complete.
get_activated_nodes()
method descriptor
¶
Yields all activated nodes.
Yields:
Type | Description |
---|---|
int
|
All of the currently activated nodes. |
get_newly_activated_nodes()
method descriptor
¶
A generator yielding the nodes that were newly activated in the last iteration of the model.
Yields:
Type | Description |
---|---|
int
|
The label of a node that was newly activated. |
get_num_activated_nodes()
¶
Returns the total number of activated nodes in the model.
Returns:
Type | Description |
---|---|
int
|
Total number of activated nodes. |
reset_model()
method descriptor
¶
Resets the model to the original set of seed nodes. This is useful if running many simulations over the same original seed set.
set_seeds(seeds)
¶
Sets the initial active nodes (seeds) for the diffusion process. Must be valid nodes in the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seeds |
Iterable[int]
|
Seeds to set as initially active. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If a node in the seed set is invalid (not in the graph). |
IndependentCascadeModel
¶
Bases: cynetdiff.models.DiffusionModel
A Diffusion Model representing the Independent Cascade process. This class is a subclass of the DiffusionModel and provides specific implementations for the Independent Cascade diffusion process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
starts |
array
|
An array of start indices for each node's edges in the edge array. Type
of array elements must be |
required |
edges |
array
|
An array of edges represented as integer indices of nodes. Type
of array elements must be |
required |
payoffs |
array
|
An array of payoffs for each node if activated. Type of array elements must be |
None
|
activation_prob |
float
|
Uniform activation probability for the Independent Cascade model.
Defaults to |
0.1
|
activation_probs |
array
|
Set individual activation probabilities for the Independent Cascade model.
Overrides |
None
|
_edge_probabilities |
array
|
An array of success probabilities for each edge, default is None. |
None
|
compute_marginal_gains(seed_set, new_seeds, num_trials)
method descriptor
¶
Computes the marginal gain of adding each seed in new_seeds on top of the original seed_set. Averages over num_trials number of randomized activations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seed_set |
Iterable[int]
|
An iterable representing the current seed set. Can be empty. |
required |
new_seeds |
List[int]
|
New seeds to compute marginal gains on. Can be empty. |
required |
num_trials |
int
|
Number of randomized trials to run. |
required |
Returns:
Type | Description |
---|---|
List[float]
|
List containing computed marginal gains. First entry is average influence of the starting seed set. Following entries are marginal gains with the addition of vertices from new_seeds in order. Has length len(new_seeds)+1. |
LinearThresholdModel
¶
Bases: cynetdiff.models.DiffusionModel
A Diffusion Model representing the Linear Threshold process. This class is a subclass of the DiffusionModel and provides specific implementations for the Linear Threshold diffusion process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
starts |
array
|
An array of start indices for each node's edges in the edge array. Type
of array elements must be |
required |
edges |
array
|
An array of edges represented as integer indices of nodes. Type
of array elements must be |
required |
payoffs |
array
|
An array of payoffs for each node if activated. Type of array elements must be |
None
|
influence |
array
|
An array of influence values for each edge. Array elements must be
|
None
|
compute_marginal_gains(seed_set, new_seeds, num_trials, *, _node_thresholds=None)
method descriptor
¶
Computes the marginal gain of adding each seed in new_seeds on top of the original seed_set. Averages over num_trials number of randomized activations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seed_set |
Iterable[int]
|
An iterable representing the current seed set. Can be empty. |
required |
new_seeds |
List[int]
|
New seeds to compute marginal gains on. Can be empty. |
required |
num_trials |
int
|
Number of randomized trials to run. |
required |
Returns:
Type | Description |
---|---|
List[float]
|
List containing computed marginal gains. First entry is average influence of the starting seed set. Following entries are marginal gains with the addition of vertices from new_seeds in order. Has length len(new_seeds)+1. |