def set_up_evodynamics(self): fargs_list = [(a, ) for a in [self.ca_rule]] exp = experiment.Experiment(input_start=0, input_delay=self.reservoir_height, training_delay=5) g_ca = exp.add_group_cells(name="g_ca", amount=self.ca_width) neighbors, center_idx = ca.create_pattern_neighbors_ca1d(3) g_ca_bin = g_ca.add_binary_state(state_name='g_ca_bin', init="zeros") g_ca_bin_conn = ca.create_conn_matrix_ca1d('g_ca_bin_conn', self.ca_width, neighbors=neighbors, center_idx=center_idx) input_connection = exp.add_input(tf.float64, [self.ca_width], "input_connection") exp.add_connection( "input_conn", connection.IndexConnection(input_connection, g_ca_bin, np.arange(self.ca_width))) exp.add_connection( "g_ca_conn", connection.WeightedConnection(g_ca_bin, g_ca_bin, act.rule_binary_ca_1d_width3_func, g_ca_bin_conn, fargs_list=fargs_list)) # exp.add_monitor("g_ca", "g_ca_bin") exp.initialize_cells() # assign to self rather then return touple return exp, input_connection
input_size = width // 10 exp = experiment.Experiment() input_esn = exp.add_input(tf.float64, [input_size], "input_esn") g_esn = exp.add_group_cells(name="g_esn", amount=width) g_esn_real = g_esn.add_real_state(state_name='g_esn_bin') # Generate custom connection matrix conn_matrix = np.random.normal(loc=0.0, scale=0.4, size=(width, width)) conn_matrix[np.round(conn_matrix) == 0.0] = 0.0 g_esn_real_conn = conn_custom.create_custom_matrix('g_ca_bin_conn',conn_matrix) exp.add_connection("input_conn", connection.IndexConnection(input_esn,g_esn_real,np.arange(input_size))) exp.add_connection("g_esn_conn", connection.WeightedConnection(g_esn_real, g_esn_real,act.sigmoid, g_esn_real_conn)) exp.initialize_cells() weight_matrix = exp.session.run(exp.get_connection("g_esn_conn").w) def adjacency2indices_values(adjacency_matrix): indices = np.argwhere(adjacency_matrix != 0) values = adjacency_matrix[np.where(adjacency_matrix != 0)] return indices, values
input_ca = exp.add_input(tf.float64, [input_size], "input_ca") desired_output = exp.add_desired_output(tf.float64, [output_layer_size], "desired_output") g_ca = exp.add_group_cells(name="g_ca", amount=width) neighbors, center_idx = ca.create_pattern_neighbors_ca1d(3) g_ca_bin = g_ca.add_binary_state(state_name='g_ca_bin', init="zeros") g_ca_bin_conn = ca.create_conn_matrix_ca1d('g_ca_bin_conn',width,\ neighbors=neighbors,\ center_idx=center_idx) fargs_list = [(a, ) for a in [110]] exp.add_connection( "input_conn", connection.IndexConnection(input_ca, g_ca_bin, np.arange(input_size))) exp.add_connection( "g_ca_conn", connection.WeightedConnection(g_ca_bin, g_ca_bin, act.rule_binary_ca_1d_width3_func, g_ca_bin_conn, fargs_list=fargs_list)) g_ca_memory = exp.add_state_memory(g_ca_bin, memory_size) output_layer = exp.add_group_cells(name="output_layer", amount=output_layer_size) output_layer_real_state = output_layer.add_real_state( state_name='output_layer_real_state', stddev=0)
input_ca = exp.add_input(tf.float64, [input_size], "input_ca") desired_output = exp.add_desired_output(tf.float64, [output_layer_size], "desired_output") g_ca = exp.add_group_cells(name="g_ca", amount=width) neighbors, center_idx = ca.create_pattern_neighbors_ca1d(3) g_ca_bin = g_ca.add_binary_state(state_name='g_ca_bin', init="zeros") g_ca_bin_conn = ca.create_conn_matrix_ca1d('g_ca_bin_conn',width,\ neighbors=neighbors,\ center_idx=center_idx) fargs_list = [(a, ) for a in [170]] exp.add_connection("input_conn", connection.IndexConnection(input_ca, g_ca_bin, [width - 1])) exp.add_connection( "g_ca_conn", connection.WeightedConnection(g_ca_bin, g_ca_bin, act.rule_binary_ca_1d_width3_func, g_ca_bin_conn, fargs_list=fargs_list)) output_layer = exp.add_group_cells(name="output_layer", amount=output_layer_size) output_layer_real_state = output_layer.add_real_state( state_name='output_layer_real_state', stddev=0) ca_output_conn = randon_conn.create_xavier_connection("ca_output_conn", width,
training_delay=memory_size-1,reset_cells_after_train=True, reset_memories_after_train=True) input_ca = exp.add_input(tf.float64, [input_size], "input_ca") desired_output = exp.add_desired_output(tf.float64, [output_layer_size], "desired_output") g_ca = exp.add_group_cells(name="g_ca", amount=width) neighbors, center_idx = ca.create_pattern_neighbors_ca1d(3) g_ca_bin = g_ca.add_binary_state(state_name='g_ca_bin', init="zeros") g_ca_bin_conn = ca.create_conn_matrix_ca1d('g_ca_bin_conn',width,\ neighbors=neighbors,\ center_idx=center_idx) fargs_list = [(a,) for a in [110]] exp.add_connection("input_conn", connection.IndexConnection(input_ca,g_ca_bin, [width-1])) exp.add_connection("g_ca_conn", connection.WeightedConnection(g_ca_bin,g_ca_bin, act.rule_binary_ca_1d_width3_func, g_ca_bin_conn, fargs_list=fargs_list)) g_ca_memory = exp.add_state_memory(g_ca_bin,memory_size) output_layer = exp.add_group_cells(name="output_layer", amount=output_layer_size) output_layer_real_state = output_layer.add_real_state(state_name='output_layer_real_state', stddev=0) ca_output_conn = randon_conn.create_xavier_connection("ca_output_conn", width*memory_size, output_layer_size) exp.add_trainable_connection("output_conn", connection.WeightedConnection(g_ca_memory, output_layer_real_state,
input_esn = exp.add_input(tf.float64, [input_size], "input_esn") g_esn = exp.add_group_cells(name="g_esn", amount=width) g_esn_real = g_esn.add_real_state(state_name='g_esn_bin') indices = [[i, (i + 1) % width] for i in range(width)] values = [1.5] * width dense_shape = [width, width] g_esn_real_conn = conn_custom.create_custom_sparse_matrix( 'g_ca_bin_conn', indices, values, dense_shape) exp.add_connection( "input_conn", connection.IndexConnection(input_esn, g_esn_real, np.arange(input_size))) exp.add_connection( "g_esn_conn", connection.WeightedConnection(g_esn_real, g_esn_real, act.sigmoid, g_esn_real_conn)) exp.initialize_cells() weight_matrix = exp.session.run(exp.get_connection("g_esn_conn").w) G = nx.DiGraph() G.add_edges_from(weight_matrix[0]) pos_dict = {} for i in range(width):
input_ca = exp.add_input(tf.float64, [input_size], "input_ca") desired_output = exp.add_desired_output(tf.float64, [output_layer_size], "desired_output") g_ca = exp.add_group_cells(name="g_ca", amount=width) neighbors, center_idx = ca.create_pattern_neighbors_ca1d(3) g_ca_bin = g_ca.add_binary_state(state_name='g_ca_bin', init="zeros") g_ca_bin_conn = ca.create_conn_matrix_ca1d('g_ca_bin_conn',width,\ neighbors=neighbors,\ center_idx=center_idx) fargs_list = [(a, ) for a in [51]] exp.add_connection( "input_conn", connection.IndexConnection(input_ca, g_ca_bin, np.arange(width))) exp.add_connection( "g_ca_conn", connection.WeightedConnection(g_ca_bin, g_ca_bin, act.rule_binary_ca_1d_width3_func, g_ca_bin_conn, fargs_list=fargs_list)) output_layer = exp.add_group_cells(name="output_layer", amount=output_layer_size) output_layer_real_state = output_layer.add_real_state( state_name='output_layer_real_state', stddev=0) ca_output_conn = randon_conn.create_xavier_connection("ca_output_conn", width,
input_delay=0, training_start=0, training_delay=0, reset_cells_after_train=True, batch_size=batch_size) input_esn = exp.add_input(tf.float64, [input_size], "input_esn") desired_output = exp.add_desired_output(tf.float64, [output_layer_size], "desired_output") g_esn = exp.add_group_cells(name="g_esn", amount=width) g_esn_real = g_esn.add_real_state(state_name='g_esn_real') exp.add_connection( "input_conn", connection.IndexConnection(input_esn, g_esn_real, np.arange(width))) indices = [[i, i] for i in range(width)] values = [1] * width dense_shape = [width, width] g_esn_real_conn = conn_custom.create_custom_sparse_matrix( 'g_esn_real_conn', indices, values, dense_shape) exp.add_connection( "g_esn_conn", connection.WeightedConnection(g_esn_real, g_esn_real, act.relu, g_esn_real_conn)) output_layer = exp.add_group_cells(name="output_layer", amount=output_layer_size)
import evodynamic.connection as connection import evodynamic.cells.activation as act import networkx as nx width = 16 input_size = width // 10 exp = experiment.Experiment() input_rbn = exp.add_input(tf.float64, [input_size], "input_rbn") g_rbn = exp.add_group_cells(name="g_rbn", amount=width) g_rbn_bin = g_rbn.add_binary_state(state_name='g_rbn_bin') g_rbn_bin_conn = rbn.create_conn_matrix('g_ca_bin_conn',width) exp.add_connection("input_conn", connection.IndexConnection(input_rbn,g_rbn_bin,np.arange(input_size))) fargs_list = [(a,) for a in [110]] exp.add_connection("g_rbn_conn", connection.WeightedConnection(g_rbn_bin, g_rbn_bin,act.rule_binary_ca_1d_width3_func, g_rbn_bin_conn,fargs_list=fargs_list)) exp.initialize_cells() weight_matrix = exp.session.run(exp.get_connection("g_rbn_conn").w) G = nx.DiGraph() G.add_edges_from(weight_matrix[0]) pos_dict = {}