<s> import cPickle <EOL> import os <EOL> import gzip <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> from pyhawkes . models import DiscreteTimeNetworkHawkesModelSpikeAndSlab <EOL> from pyhawkes . plotting . plotting import plot_network <EOL> def generate_synthetic_data ( seed = None ) : <EOL> """<STR_LIT>""" <EOL> if seed is None : <EOL> seed = np . random . randint ( <NUM_LIT:2> ** <NUM_LIT:32> ) <EOL> print "<STR_LIT>" , seed <EOL> np . random . seed ( seed ) <EOL> T_test = <NUM_LIT:1000> <EOL> C = <NUM_LIT:1> <EOL> K = <NUM_LIT:50> <EOL> T = <NUM_LIT> <EOL> dt = <NUM_LIT:1.0> <EOL> B = <NUM_LIT:3> <EOL> p = <NUM_LIT> <EOL> kappa = <NUM_LIT> <EOL> v = kappa * <NUM_LIT> <EOL> c = np . zeros ( K , dtype = np . int ) <EOL> network_hypers = { '<STR_LIT:C>' : C , '<STR_LIT>' : kappa , '<STR_LIT:c>' : c , '<STR_LIT:p>' : p , '<STR_LIT:v>' : v } <EOL> from pyhawkes . internals . network import ErdosRenyiFixedSparsity <EOL> network = ErdosRenyiFixedSparsity ( K , p , kappa , v = v ) <EOL> true_model = DiscreteTimeNetworkHawkesModelSpikeAndSlab ( K = K , dt = dt , B = B , <EOL> network = network ) <EOL> assert true_model . check_stability ( ) <EOL> plt . ion ( ) <EOL> plot_network ( true_model . weight_model . A , <EOL> true_model . weight_model . W ) <EOL> plt . pause ( <NUM_LIT> ) <EOL> S , R = true_model . generate ( T = T , keep = False , print_interval = <NUM_LIT:50> ) <EOL> out_dir = os . path . join ( '<STR_LIT:data>' , "<STR_LIT>" ) <EOL> out_name = '<STR_LIT>' % ( K , C , T ) <EOL> out_path = os . path . join ( out_dir , out_name ) <EOL> with gzip . open ( out_path , '<STR_LIT:w>' ) as f : <EOL> print "<STR_LIT>" , out_path <EOL> cPickle . dump ( ( S , true_model ) , f , protocol = - <NUM_LIT:1> ) <EOL> S_test , _ = true_model . generate ( T = T_test , keep = False ) <EOL> out_dir = os . path . join ( '<STR_LIT:data>' , "<STR_LIT>" ) <EOL> out_name = '<STR_LIT>' % ( K , C , T_test ) <EOL> out_path = os . path . join ( out_dir , out_name ) <EOL> with gzip . open ( out_path , '<STR_LIT:w>' ) as f : <EOL> print "<STR_LIT>" , out_path <EOL> cPickle . dump ( ( S_test , true_model ) , f , protocol = - <NUM_LIT:1> ) <EOL> generate_synthetic_data ( <NUM_LIT> ) </s>
