dynsimf.models.components.conditions package

Submodules

dynsimf.models.components.conditions.Condition module

class dynsimf.models.components.conditions.Condition.Condition(condition_type, chained_condition=None)

Bases: object

Condition base class

abstract get_arguments(model_input)

Empty function that should be specified in a subclass to get the desired arguments for the test function. Note that this function must take in the model_input tuple of the form: (nodes, states matrix, adjacency matrix, utility matrix)

Parameters:

model_input (tuple) – Standard parameter for any condition sample function, it has the form: (nodes, states matrix, adjacency matrix, utility matrix)

get_function()

Get the function that takes the model input and returns the valid nodes that meet the condition. Note that this function is overwritten when using the CustomCondition class

Returns:

The function that returns the nodes for which the condition applies

Return type:

function

get_state()

Get the state name that the condition is targeting

Returns:

The state the condition targets

Return type:

str or None

get_valid_nodes(model_input)

Get all valid nodes that meet this and the chained conditions

Parameters:

model_input (tuple) – Gives all important model values from the current iteration: (nodes, states matrix, adjacency matrix, utility matrix)

Returns:

List of all nodes that meet the condition

Return type:

list

test_adjacency()

Empty function that should be specified in a subclass to test for an adjacency condition

test_states()

Empty function that should be specified in a subclass to test for a state condition

test_utility()

Empty function that should be specified in a subclass to test for a utility condition

validate_condition()

Validate whether a condition is configured correctly

Raises:
  • ValueError – if an uncorrect condition_type is specified at initialisation

  • ValueError – if the chained condition is not of Condition type

class dynsimf.models.components.conditions.Condition.ConditionType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

The condition type enum, specifying what the condition is targeting

ADJACENCY = 1
CUSTOM = 3
EDGE_VALUES = 4
STATE = 0
UTILITY = 2

dynsimf.models.components.conditions.CustomCondition module

class dynsimf.models.components.conditions.CustomCondition.CustomCondition(function, arguments=None, chained_condition=None)

Bases: Condition

Base class that can be used to create custom conditions that do not fit under stochastic or threshold conditions

get_arguments(model_input)

Get the arguments for the custom condition, note that this returns the model_input tuple plus whatever custom arguments have been specified

Parameters:

model_input (tuple) – the model_input tuple of form: (nodes, states matrix, adjacency matrix, utility matrix) that is automatically provided to the sample function of the custom condition

Returns:

A list of arguments, where the first argument is the model_input tuple and the other arguments are any custom provided arguments

Return type:

list

get_function()

Get the sample function of the custom condition

Returns:

The sample function of the custom condition

Return type:

function

validate()

Validate the custom condition

Raises:
  • ValueError – if no function is provided

  • ValueError – if the function does not take the ‘model_input’ tuple as argument

dynsimf.models.components.conditions.StochasticCondition module

class dynsimf.models.components.conditions.StochasticCondition.StochasticCondition(condition_type, p, chained_condition=None)

Bases: Condition

A class for creating a stochastic condition where any node has a certain chance of being randomly sampled

get_arguments(model_input)

Get the arguments for the stochastic condition sample function. In this case, no matter the condition type, only the nodes are returned from the model_input

Parameters:

model_input (tuple) – the model_input tuple of form: (nodes, states matrix, adjacency matrix, utility matrix)

Returns:

A list of all nodes in the model

Return type:

list

get_function()

Get the sample function of the stochastic condition

Returns:

The sample function

Return type:

function

random_sample(nodes)

The function that samples the nodes in the model based on the configured probability. For every node a random number is generated and if one of the drawn numbers is less than the selected probability that node is selected and returned together with the other selected nodes.

Returns:

A list of sampled nodes

Return type:

list

test_adjacency(nodes)

Empty function that is not used because the random_sample function is used instead

test_states(nodes)

Empty function that is not used because the random_sample function is used instead

test_utility(nodes)

Empty function that is not used because the random_sample function is used instead

validate()

Validate whether the probability is in the correct format

Raises:

ValueError – if the probability member is neither a float or int

dynsimf.models.components.conditions.ThresholdCondition module

class dynsimf.models.components.conditions.ThresholdCondition.ThresholdCondition(condition_type, config, chained_condition=None)

Bases: Condition

get_arguments(model_input)

Get the arguments for the threshold condition sample function

Parameters:

model_input (tuple) – the model_input tuple of form: (nodes, states matrix, adjacency matrix, utility matrix) that is automatically provided to the sample function of the custom condition

Returns:

A list of arguments depending on the specified condition_type

Return type:

list

set_state_index(index)

Set the state index corresponding to the selected state in the config. Essentially the state string is now also stored as the specific index that refers to the state in the complete states matrix in the model.

Parameters:

index (int) – The index of the state in the config that indexes to the state in the model’s states matrix

test_adjacency(nodes, adjacency_matrix)

Calculates the amount of neighbors for each node and applies the threshold operator on each node’s neighbor amount

Returns the nodes for which: threshold operator(n_neighbors, condition.threshold) is true

Parameters:
  • nodes (list) – A list of nodes to be sampled

  • adjacency_matrix (numpy.ndarray) – A matrix of the adjacency in the model at the current iteration

Returns:

The nodes that meet the threshold condition

Return type:

list

test_states(nodes, states)

Find the indices of nodes for which the threshold operator holds for the set state index

Parameters:
  • nodes (list) – A list of nodes to be sampled

  • states (numpy.ndarray) – A matrix of the states in the model at the current iteration

Returns:

The nodes that meet the threshold condition

Return type:

list

Raises:

ValueError – if no state index has been set in the config member

test_utility(nodes, utility_matrix)

Find the indices of nodes that have at least one utility edge value for which the threshold operator holds. Returns indices of the nodes for which threshold operator(utility_edge, condition.threshold) is true

Parameters:
  • nodes (list) – A list of nodes to be sampled

  • utility_matrix (numpy.ndarray) – A matrix of the utility in the model at the current iteration

Returns:

The nodes that meet the threshold condition

Return type:

list

validate()

Validate whether the configuration type is correct and if states have been set if the threshold should apply on a state

Raises:
  • ValueError – if the config member is not of type ThresholdConfiguration

  • ValueError – if no state has been set in the config but the condition_type member is set to ConditionType.STATE

  • Warning – if a state has been set in the config, but the condition_type member is not ConditionType.STATE

class dynsimf.models.components.conditions.ThresholdCondition.ThresholdConfiguration(threshold_operator, threshold, state=None)

Bases: object

Configuration class used to configure a threshold condition

validate()

Validate whether the threshold operator is of enum type ThresholdOperator

class dynsimf.models.components.conditions.ThresholdCondition.ThresholdOperator(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

An enumeration that is used to select the specific operator for the threshold condition

GE = <built-in function ge>
GT = <built-in function gt>
LE = <built-in function le>
LT = <built-in function lt>

Module contents