Exemplo n.º 1
0
def load_json_taco(fp):
    """
    Loads a temporal network from a .taco-file (which is actually in json format).

    Parameters
    ----------
    fp : file-like or :obj:`str`
        read from this file

    Returns
    -------
    temporal network
        type as given in the .taco-file
    """

    file_is_string = isinstance(fp, str)

    if file_is_string:
        fp = os.path.abspath(os.path.expanduser(fp))
        with open(fp, 'r') as f:
            this_data = json.load(f)

    else:
        this_data = json.load(fp)

    if this_data['type'] == 'edge_changes':
        temporal_network = tc.edge_changes()
        temporal_network.t = this_data['t']
        temporal_network.t0 = this_data['t0']
        temporal_network.tmax = this_data['tmax']
        temporal_network.N = this_data['N']
        temporal_network.edges_initial = this_data['edges_initial']
        temporal_network.edges_in = this_data['edges_in']
        temporal_network.edges_out = this_data['edges_out']
        temporal_network.int_to_node = {
            int(i): s
            for i, s in this_data['int_to_node'].items()
        }
        temporal_network.notes = this_data['notes']
        temporal_network.time_unit = this_data['time_unit']

    elif this_data['type'] == 'edge_lists':
        temporal_network = tc.edge_lists()
        temporal_network.t = this_data['t']
        temporal_network.tmax = this_data['tmax']
        temporal_network.N = this_data['N']
        temporal_network.edges = this_data['edges']
        temporal_network.int_to_node = {
            int(i): s
            for i, s in this_data['int_to_node'].items()
        }
        temporal_network.notes = this_data['notes']
        temporal_network.time_unit = this_data['time_unit']

    else:
        raise ValueError(
            'file is corrupted, unknown temporal network format: ' +
            this_data['type'])

    return temporal_network
Exemplo n.º 2
0
              (1,2), (0,2)
            ],
            [
              (0,1)
            ],
           ]

result = tc.measure_group_sizes_and_durations_for_edge_lists(L)

print "N_m =", result.aggregated_size_histogram
print "sum(m*N_m) =", np.dot(np.arange(0,L.N+1),result.aggregated_size_histogram), "should be N =", L.N


print "===== edge_changes => edge_lists ====="

C = tc.edge_changes()

C.N = 3
C.edges_initial = [ (0,1) ]
C.t0 = 0.0
C.tmax = 3.0
C.t = [ 1.0, 2.0 ]
C.edges_in = [
                [
                    (1,2), (0,2)
                ],
                [
                    (0,1),
                ],
             ]
C.edges_out = [
Exemplo n.º 3
0
import tacoma as tc
from tacoma.interactive import visualize

# define temporal network as a list of edge changes
temporal_network = tc.edge_changes()
temporal_network.N = 10
temporal_network.edges_initial = [ (0,1), (2,3), (1,7), (3,5), (1,9), (7,2) ]
temporal_network.t0 = 0.0
temporal_network.t = [ 0.8, 2.4 ]
temporal_network.tmax = 3.1
temporal_network.edges_in = [ 
                              [ (0, 5), (3, 6) ], 
                              [ (3, 7), (4, 9), (7, 8) ],
                            ]
temporal_network.edges_out = [ 
                                [ (0, 1) ],
                                [ (2, 3), (3, 6) ],
                             ]

visualize(temporal_network, frame_dt = 0.05)
Exemplo n.º 4
0
from __future__ import print_function
import tacoma as tc

dyn_RGG = tc.dynamic_RGG(N=3, t_run_total=10, mean_link_duration=2.0)
test_list = tc.edge_lists(dyn_RGG)
#test_list.copy_from(dyn_RGG)

print(test_list.t, dyn_RGG.t)
print(test_list.tmax, dyn_RGG.tmax)
print(test_list.edges)
print(dyn_RGG.edges)
print(test_list.N, dyn_RGG.N)

zsbb = tc.ZSBB_model([], 3, 0.6, 0.6, 0.6, t_run_total=100)

test_list = tc.edge_changes(zsbb)

print(test_list.t, zsbb.t)
print(test_list.t0, zsbb.t0)
print(test_list.tmax, zsbb.tmax)
print(test_list.edges_in)
print(zsbb.edges_in)
print(test_list.edges_out)
print(zsbb.edges_out)
print(test_list.N, zsbb.N)
plot_size = False

print "simulating"
result = tc.ZSBB_model([],
                       N,
                       lambda_,
                       b0,
                       b1,
                       t_sim,
                       t_equilibration=t_eq,
                       seed=1346,
                       record_sizes_and_durations=True)
print "done"

this = tc.edge_changes()
this.t = result.t
this.N = result.N
this.edges_initial = result.edges_initial
this.t0 = result.t0
this.tmax = result.tmax
this.edges_in = result.edges_in
this.edges_out = result.edges_out
print len(this.t), len(this.edges_in)
print "first time point: ", this.t[0]

second_result = tc.measure_group_sizes_and_durations_for_edge_changes(
    this,
    #verbose=True,
)
Exemplo n.º 6
0
def naive_varying_rate_edge_activity_simulation(N, t, network_densities,
                                                activity_rates, tmax):
    r"""
    Do a naive simulation of edge activity model systems where the network density and edge activity rates
    vary over time as step functions. It is called `naive` because the rate change will not
    be considered when evaluating the inter-event time at time points when the rates change.
    I.e. at a rate change at time `t`, the new model will be initiated as if the 
    last event happened at time `t`.

    Parameters
    ----------
    N : int
        number of nodes
    t : numpy.ndarray of float
        time points at which :math:`\alpha` and :math`\beta` change
    network_densities : numpy.ndarray of float
        values of :math:`\rho` for the corresponding time values in ``t``.
    activity_rates : numpy.ndarray of float
        values of :math:`\omega` for the corresponding time values in ``t``.
    tmax : float
        time at which the simulation is supposed to end.

    Returns
    -------
    edge_changes : :class:`_tacoma.edge_changes`
        The simulated edge activity model instance.
    """

    if len(t) != len(network_densities) or len(activity_rates) != len(
            network_densities):
        raise ValueError(
            'The arrays `t`, `activity_rates` and `network_densities` must have the same length.'
        )

    assert (t[-1] < tmax)
    t = np.append(t, tmax)

    all_networks = []
    it = 0
    initial_edges = []

    result = None
    for r_, w_ in zip(network_densities, activity_rates):

        dt = t[it + 1] - t[it]

        if r_ == 1.0:
            r_ = (0.5 * (N - 1) * N - 1) / (0.5 * (N - 1) * N)
        elif r_ == 0.0:
            r_ = 1e-100

        #print("rho =", r_, "omega =", w_)

        if w_ > 0.0:

            EAM = tc.EdgeActivityModel(N, r_, w_, save_temporal_network=True)
            if it > 0:
                EAM.set_initial_edgelist(0.0, initial_edges)
            tc.simulate_EdgeActivityModel(EAM,
                                          dt,
                                          reset_simulation_objects=False)
            this_result = EAM.edge_changes
            if it < len(activity_rates) - 1:
                initial_edges = EAM.get_current_edgelist()

        else:
            this_result = tc.edge_changes()
            this_result.edges_initial = initial_edges
            this_result.N = N
            this_result.t0 = 0.0
            this_result.tmax = dt

        all_networks.append(this_result)

        it += 1

    result = tc.concatenate(all_networks)

    return result