API Documentation
API Documentation#
- class model.HybridModel(ABM: networkx.classes.graph.Graph)#
Create a ABM/FCM hybrid model for simulation based on a created the graph Each node of the ABM graph will have an ‘FCM’ attribute that points to an FCM graph. Each node of an FCM graph will have a ‘val’ attribute that has the value of that node.
- Parameters
ABM (networkx.Graph) – The ABM/FCM graph created using networkx
- generate_communities(community_algo)#
Partition the network into communities
- Parameters
community_algo (func) – the community algorithm to be used
- get_neighbors(node: int) list #
Get neighbors for node in an adjacency matrix representation of a graph
- Parameters
node (int) – the node for which neighbors are fetched
- Returns
a list of neighbors of the requested node
- Return type
list
- loadNewValues() None #
Sets FCM values to future values for each FCM in each agent infrom numba import cuda the simulation
- runFCM(focus, threshold, max_it=100)#
Runs fuzzy cognitive map for all agents
- Parameters
focus (list) – list of focus nodes
threshold (list) – a list of thresholds corresponding to each focus node
max_it (int, optional) – the maximum number of iterations for each agent, defaults to 100
- run_parallel(focus, threshold, iters, func, args, steps=20, with_community=False, community_algo=None)#
Run the interaction function and stabelize each FCM in parallel for each step
- Parameters
focus (list) – list concept names to stabilize
threshold (list) – stabilization thresholds for corresponding focus nodes
iters (int) – maximum amount of times to iterate
func (function) – interaction function between agents
args (list) – list of arguments for interaction function
steps (int) – number of steps of the simulation
- Returns
average values for each focus concept
- Return type
Dict
- run_parallel_community(focus, threshold, iters, func, args, steps, community_algo)#
Run the interaction function and stabelize each FCM in parallel for each step
- Parameters
focus (list) – list concept names to stabilize
threshold (list) – stabilization thresholds for corresponding focus nodes
iters (int) – maximum amount of times to iterate
func (function) – interaction function between agents
args (list) – list of arguments for interaction function
steps (int) – number of steps of the simulation
- Returns
average values for each focus concept
- Return type
Dict
- run_serial(focus, threshold, iters, func, argv, steps=20) float #
Run the model serially on CPU
- Parameters
focus (list(Float64)) – a list of focus nodes
threshold (list(Float64)) – a list of thresholds for each focus nodes
iters (int) – the maximum number of iterations when running FCM for each agent
func (function) – the function for interaction between agents
argv (list) – a list of arguments for the interaction function
steps (int, optional) – the number of steps the model will be run, defaults to 20
- Returns
the average values of the focus concepts of all agents of after the simulation
- Return type
dict
- transformNetwork(G: networkx.classes.graph.Graph)#
Use the networkx.Graph provided to extract information, including ABM and FCM adjacency matrices, a dictionary that maps FCM lables to their indices in the FCM adjacency matrix, along with other information
- Parameters
G (networkx.Graph) – networkx graph to be transformed
- model.create_FCM_file(filename) networkx.classes.digraph.DiGraph #
Create FCM graph for an agent
- Parameters
filename (string) – the path to the file for FCM model
- Returns
a directed graph based on the provided file
- Return type
networkx.DiGraph
- model.create_graph(agent_count, graph_type, filename)#
Create ABM graph
- Parameters
agent_count (int) – the number of agents in the model
graph_type (string) – the graph type to be created (watts, sf, newman, or barabasi)
filename (string) – the path to a text file that has the edges for the FCM graph
- Returns
a graph for the ABM/FCM hybrid model
- Return type
networkx.Graph
- model.generate_model(agent_count, filename, graph_type)#
Create a general model
- Parameters
agent_count (int) – number of agents in the model
filename (string) – the path to a file that stores the edges for the FCM
graph_type (string) – the type of graphs, pick from watts, sf, newman, and barabasi
- Returns
a HybridModel
- Return type