def get_rbn_meta(i): print "GOGO" + str(i) rbn_reservoir = RBNNode(connectivity=conf.connectivity, n_nodes=n_nodes, input_connectivity=n_nodes / 2) reservoir_system = ReservoirSystem(rbn_reservoir) reservoir_system.train_on(*conf.training_data) accuracy = reservoir_system.test_on(*conf.test_data) bns_file = "{}/{}.bns".format(conf.output_dir, i) cnet_file = "{}/{}.cnet".format(conf.output_dir, i) acc_file = "{}/{}.acc".format(conf.output_dir, i) with open(cnet_file, 'w') as f: f.write(rbn_reservoir.into_cnet()) with open(bns_file, 'w') as f: subprocess.call(['./analytics/SAT/bns', cnet_file], stdout=f) with open(bns_file, 'r') as bns: attractors = map( int, re.findall("Attractor \d+ is of length (\d+)", bns.read())) with open(acc_file, 'w') as acc: acc.write( json.dumps({ "accuracy": accuracy, "attractors": attractors, "mean_attractor_length": np.mean(attractors), "n_attractors": len(attractors) }))
def get_rbn_meta(i): print "GOGO" + str(i) rbn_reservoir = RBNNode(connectivity=conf.connectivity, n_nodes=n_nodes, input_connectivity=n_nodes/2) reservoir_system = ReservoirSystem(rbn_reservoir) reservoir_system.train_on(*conf.training_data) accuracy = reservoir_system.test_on(*conf.test_data) bns_file = "{}/{}.bns".format(conf.output_dir, i) cnet_file = "{}/{}.cnet".format(conf.output_dir, i) acc_file = "{}/{}.acc".format(conf.output_dir, i) with open(cnet_file, 'w') as f: f.write(rbn_reservoir.into_cnet()) with open(bns_file, 'w') as f: subprocess.call(['./analytics/SAT/bns', cnet_file], stdout=f) with open(bns_file, 'r') as bns: attractors = map(int, re.findall("Attractor \d+ is of length (\d+)", bns.read())) with open(acc_file, 'w') as acc: acc.write(json.dumps({ "accuracy": accuracy, "attractors": attractors, "mean_attractor_length": np.mean(attractors), "n_attractors": len(attractors) }))
def calculate_accuracy((n_nodes, input_connectivity, output_connectivity)): accuracies = [] description = '-'.join( map(str, [n_nodes, input_connectivity, output_connectivity])) print "START-" + description for sample in range(conf.n_samples): rbn_reservoir = RBNNode(connectivity=conf.connectivity, input_connectivity=input_connectivity, n_nodes=n_nodes, output_connectivity=output_connectivity) reservoir_system = ReservoirSystem(rbn_reservoir) reservoir_system.train_on(*conf.training_data) accuracy = reservoir_system.test_on(*conf.test_data) accuracies.append(accuracy) print "END-" + description return { "accuracies": accuracies, "n_nodes": n_nodes, "n_samples": conf.n_samples, "input_connectivity": input_connectivity, "output_connectivity": output_connectivity }
def get_rbn_meta(_): print "!!!", _ rbn_reservoir = RBNNode(connectivity=conf.connectivity, input_connectivity=reservoir_size / 2, n_nodes=reservoir_size) reservoir_system = ReservoirSystem(rbn_reservoir) reservoir_system.train_on(*conf.training_data) accuracy = reservoir_system.test_on(*conf.test_data) attractors_meta = find_attractors(rbn_reservoir) attractors_meta["accuracy"] = accuracy return attractors_meta
from tasks.temporal import create_datasets from rbn.sklearn_rbn_node import RBNNode from sklearn.linear_model import Ridge datasets = create_datasets(10, task_size=200, window_size=3, dataset_type='temporal_parity') training_datasets, test_dataset = datasets[:-1], datasets[-1] rbn_reservoir = RBNNode(connectivity=3, input_connectivity=50, n_nodes=100, output_connectivity=0) readout_layer = Ridge() for td in training_datasets[:1]: #rbn_reservoir.reset_state() reservoir_input, expected_output = td states = rbn_reservoir.execute(reservoir_input) readout_layer.fit(states, expected_output) predictions = readout_layer.predict(states) for prediction in predictions: prediction[0] = 1 if prediction[0] > 0.5 else 0 errors = sum(predictions != expected_output) accuracy = 1 - float(errors) / len(predictions)
from tasks.temporal import create_datasets from rbn.sklearn_rbn_node import RBNNode from sklearn.linear_model import Ridge datasets = create_datasets( 10, task_size=200, window_size=3, dataset_type='temporal_parity') training_datasets, test_dataset = datasets[:-1], datasets[-1] rbn_reservoir = RBNNode(connectivity=3, input_connectivity=50, n_nodes=100, output_connectivity=0) readout_layer = Ridge() for td in training_datasets[:1]: rbn_reservoir.reset_state() reservoir_input, expected_output = td states = rbn_reservoir.execute(reservoir_input) readout_layer.fit(states, expected_output) predictions = readout_layer.predict(states) for prediction in predictions: prediction[0] = 1 if prediction[0] > 0.5 else 0 errors = sum(predictions != expected_output) accuracy = 1 - float(errors) / len(predictions)