hearsay package¶
Submodules¶
hearsay.hearsay module¶
HEARSAY.
This module contains tools to compute and analyze numerical simulations of a Galaxy with constrained causally connected nodes. It simulates a 2D simplified version of a disk galaxy and perform discrete event simulations to explore three parameters: 1. the mean time for the appeareance of new nodes, 2. the mean lifetime of the nodes, and 3. the maximum reach of signals.
A simulation is a realization of the Constrained Causally Connected Network (C3Net) model. The details of this model are explained in Lares, Funes & Gramajo (under review).
Classes in this module: - Parser - C3Net - Results
Additionally, it contains the function unwrap_run which is used for parallel runs with the joblib library.
-
class
hearsay.hearsay.
C3Net
(conf=None) Bases:
object
C3Net: Constrained Causally Connected Network model.
-
init
()¶ creates a node
-
__len__
()¶ None
-
__repr__
()¶ None
-
__str__
()¶ None
-
run
()¶ Run a suite of simulations for the full parametet set in the configuration file.
-
run_suite
()¶ Run a suite of simulations for a given parameter set.
-
run_suite_II
()¶ Run a suite of simulations for a given parameter set, to be run in parallel.
-
run_simulation
()¶ Run a simulation for a point in parameter space.
-
show_single_ccns
()¶ Show the contents of a simulation run.
-
prepare_dirs
(filenames) Prepare directories for experiments from dataframes.
Takes a list of paths and filenames and check if all paths exist.
- Parameters
filenames (list) – A list with all filenames
- Returns
- Return type
None
-
run
(parallel=False, njobs=None, interactive=False) Run an experiment.
An experiment requires a set of at least three parameters, which are taken from the configuration file.
- Parameters
parallel (Boolean) – Flag to indicate if run is made using the parallelized version. Default: False.
njobs (int) – Number of concurrent jobs for the parallel version. If parallel is False njobs is ignored.
interactive (boolean) – Flag to indicate if the result of the simulation suite is returned as a variable.
- Returns
res – Only returned if interactive=True. Contains the results from the simulations. The size of the list is the number of simulations in the experiment, i.e., the number of lines in self.params. Each element of the list is a dictionary containing the complete list of CCNs and their contacts.
- Return type
list
See also
hearsay.results.ccn_stats()
Example
If the following experiment is set: >>> conf.load_config([‘nran’], [‘2’] >>> A = [5000, 10000, 20000] >>> S = [20000] >>> D = [20000] >>> G.set_parameters(A=A, S=S, D=D) then a total of 6 experiments will be performed. The result of this function is a list of length 6, each element containing an element that can be printed with the show_single_ccns method. See that method for more details.
-
run_simulation
(p=None, pars=None) Make experiment.
A single value of parameters
- Parameters
(configuration object) (p) –
(list) (pars) – tau_A, tau_S and D_max
- Raises
None –
- Returns
MPL (list)
MPL is a list of size the number of nodes in the simulation.
Each element of this list contains a list whose first element
is –
- [ID of CCN,
ID of CCN (repeated), x coordinate of the position in the Galaxy, y coordinate of the position in the Galaxy, time of the A event, time of the D event]
Moreover, if there are contacts with this node –
- [ID of receiving node,
ID of emiting node, x coordinate of the position in the Galaxy of emiting node, y coordinate of the position in the Galaxy of emiting node, time of the C event, time of the B event]
-
run_suite
(interactive=False) Make experiment.
Requires a single value of parameters. Writes output on a file
- Parameters
(list) (params) –
Format, e.g. (simulation.) –
- Raises
None –
- Returns
- Return type
None
-
run_suite_II
(njobs, interactive=False) Run an experiment, parallel version.
An experiment requires a set of at least three parameters, which are taken from the configuration file.
- Parameters
params (the parameters) –
njobs (number of jobs) –
-
set_parameters
(spars=None, A=None, S=None, D=None, write_file=False) Set parameters for the experiment.
If no arguments are given, the parameters are set from the ini file. :param spars (dataframe, list or string, optional): :param Parameters to set the experiment.: :param If spars is a pandas DataFrame, it must contain the keys: :param [‘tau_awakening’, ‘tau_survive’, ‘d_max’, ‘filename’].: :param If spars is a list, it must have length=4, comprisong the: :param tau_awakening, tau_survive, d_max, and filename lists.: :param If spars is a string, a file with that name will be read.: :param The file must contain the same four columns, with the names.: :param A (number or list, optional): :type A (number or list, optional): Values of the tau_awakening parameter :param S (number or list, optional): :type S (number or list, optional): Values of the tau_survive parameter :param D (number or list, optional): :type D (number or list, optional): Values of the D_max parameter :param write_file (optional): :type write_file (optional): filename to write the parameter set.
-
show_single_ccns
(MPL=None, interactive=False) Show simulation results.
- Parameters
None –
-
-
class
hearsay.hearsay.
Parser
(argv=None, *args, **kwargs) Bases:
configparser.ConfigParser
parser class.
Manipulation of configuration parameters. This method allows to read a configuration file or to set parameters for a Constrained Causally Conected Network (C3Net) model.
-
check_file
(sys_args='') Parse paramenters for the simulation from a .ini file.
- Parameters
(str) (filename) –
- Raises
None –
- Returns
- Return type
None
-
check_settings
() Check if parameters make sense.
- Parameters
None –
- Raises
None –
- Returns
- Return type
Exception if settings have inconsistencies.
-
load_config
(keys=None, values=None, nran=None, *args, **kwargs) Load parameters from config file.
- Parameters
None –
- Raises
None –
- Returns
- Return type
list of parameters as a named tuple
-
load_filenames
() Make filenames based on info in config file.
- Parameters
None –
- Raises
None –
- Returns
- Return type
list of filenames
-
read_config_file
() Parse paramenters for the simulation from a .ini file.
- Parameters
None –
- Raises
None –
- Returns
- Return type
None
-
-
class
hearsay.hearsay.
Results
(G=None) Bases:
hearsay.hearsay.C3Net
results: load and visualize results from simulations and experiments.
description
-
ccn_stats
(CCN) Return statistics for a single causally connected network.
This corresponds to a single simulation run, that gives a list of nodes, its properties and its contacts. The properties of a node are the ID, the times of the A and D events and the postition in the (simulated) Galaxy.
- Parameters
CCN (dict) – An object (as read from pickle files) that represents a network of CCNs from a single simulation run
- Returns
stats – A tuple containing several statistics about the network.
- Return type
tuple
Notes
The stats tuple includes parameters with counters (1, 2, 3), parameters with CCNs values (4-7) and parameters with contacts values (8-11)
N : Total number of CCNs in the full period. Length=1
02. M : Total number of contacts (i.e., CCNs that are on the space-time cone of another CCN.)
03. K : Total number of CCNs that make at least one contact (i.e., CCNs that are on the space-time cone of at least another CCN.)
04. lP : Time periods for each CCN. Equivalent to the time span between the A and D events. Length=N
lI : Number of contacts each CETI receives. Length=N
lX : X position within the Galaxy disc. Length=N
lY : Y position within the Galaxy disc. Length=N
lL : Distances between contacted nodes. Length=K
lH : Duration of each contact. Length=K
lW : Time elapsed from awakening to contact. Length=K
11. lF : Time elapsed from awakening to the first contact. length=N
-
load
() Load parameter set and data.
Load all data generated from an experiment.
-
redux
(subset=None) Redux experiment.
Given a set of parameters, returns the global values
- Parameters
subset (boolean array) – Filter to the values in self.params
- Returns
N (list) – Total number of nodes for each simulation in self.params
M (list) – Total number of contacts for each simulation in self.params A contact is produced any time a node enters the light cone of another node.
K (list) – Total number of nodes that make at least one contact, for each simulation in self.params.
lP (array) – Time periods from t_A to t_D.
lI (array) – Number of contacts that each node receives.
lX (array) – X position within the Galaxy disc.
lY (array) – Y position within the Galaxy disc.
lL (array) – Distances between contacted nodes.
lH (array) – Duration of each contact.
lW (array) – Time elapsed from awakening to contact.
lF (array) – Time elapsed from awakening to the first contact.
-
redux_1d
(subset=None, applyto=None) Reddux experiment.
Compute statistics for the set of parameters limited to subset
- Parameters
subset (logical array) – Filter for the full parameter set.
applyto (string) – Name of the variable to be used as X-axis
Results –
------- –
-
redux_2d
(show_progress=False) Reddux experiment to 2D matrices.
Takes all the experiments in self.params and reduces the data to matrices containing: 1) fraction of nodes that make contact in (t_A, t_D) 2) fraction of nodes that make contact in t_A
- Parameters
show_progress (boolean) – Show if a progress indicator is shown
- Returns
m1 (ndarray) – Matrix containing the fraction of nodes that make contact in (t_A,t_D) as a function of tau_awakening and tau_survive values
m2 (ndarray) – Matrix containing the fraction of nodes that make contact in t_A as a function of tau_awakening and tau_survive values
Notes
To do: allow to compute any quantity.
-
show_ccns
(i, interactive=False) Show simulation results.
- Parameters
None –
-
-
hearsay.hearsay.
unwrap_run
(arg, **kwarg) Wrap the serial function for parallel run.
This function just call the serialized version, but allows to run it concurrently.
hearsay.olists module¶
OLISTS.
Module for the manipulation of ordered lists. This module is internal to hearsay.
-
class
hearsay.olists.
Node
(data) Bases:
object
Node and linked list classes.
This class contains tools to manipulate nodes. A node is a point in the Galaxy that a acquires the ability to emit and receive messages at a given time. A set of nodes make a linked list.
-
getData
() Get data in a node.
-
getNext
() Get the next node, if exists.
-
setNext
(newnext) Set the next node.
-
-
class
hearsay.olists.
OrderedList
Bases:
object
Ordered list class.
Tools to make ordered lists. This structure is useful because it can be traversed and a new node can be added at any stage. # based on http://interactivepython.org/courselib/static/pythonds/ # BasicDS/ImplementinganOrderedList.html
-
add
(data) Add an element to an ordered list.
-
isEmpty
() Ask if list is empty.
-
remove_first
() Remove first element.
-
show
() Print an ordered list.
-
size
() Retrieve the size of the list.
-
Module contents¶
Software for the Constrained Causally Connected Network Model.
This model is used to perform a statistical analysis of the hypothesis space for the contacts between nodes in a simplified galaxy.