Example #1
0
L = 10 * 20  # int(sys.argv[1])
window = 3
delay = 1
dataStreamLength = 10
trainingSize = 150
testSize = 150
O = 2**(2**window)

seed = 0
np.random.seed(seed)

bn_directory = os.getcwd() + '/BN_realization/'
directory = os.getcwd() + '/'
print(os.getcwd())

varF, F, init = bn.getRandomParameters(N + I, K, isConstantConnectivity=False)
res = Reservoir(I, L, bn_directory + 'time_series_data_3.csv',
                directory + 'test_2018-08-03.csv', N, varF, F, init)
print('reservoir initialized')
functionInputs = [f_utils.getInputTuple(window) for i in range(O)]

functionsToApproximate, functionVectors = [], []

for i in range(O):
    function_vector = f_utils.convertIntToBinaryVector(i, 2**window)
    func = f_utils.convertVectorToFunction(function_vector)
    functionsToApproximate.append(func)
    # Only for printing purposes
    functionVectors.append(function_vector)

output = OutputLayer(res, O, functionsToApproximate, functionInputs, delay,
Example #2
0
# Initialize functions and inputs
functionInputs = [[(0, 0), (0, 1), (-1, 1)]]
functionsToApproximate = [f_utils.parity]

# Test parameter set
data = np.zeros((len(N_list), len(L_list)))
for i in range(len(N_list)):
    for j in range(len(L_list)):
        L = L_list[j] * N_list[i] // 100

        # Initialize reservoir
        bn_directory = os.getcwd() + '/BN_realization/'
        directory = os.getcwd() + '/'
        varF, F, init = bn.getRandomParameters(N_list[i] + I,
                                               K + (L / N_list[i]),
                                               isConstantConnectivity=False)
        res = Reservoir(I, L, bn_directory + 'time_series_data_3.csv',
                        directory + 'experiment1_2018-08-03.csv', N_list[i],
                        varF, F, init)

        # Train and test output layer
        output = OutputLayer(res,
                             O,
                             functionsToApproximate,
                             functionInputs,
                             delay,
                             dataStreamLength,
                             nonRecursiveArgs=[[(0, 2)]])
        output.train(trainingSize)
        output.test(testSize)
Example #3
0
            if not (df.iloc[index] - df.iloc[testIndex]).any():
                return index
    return None


N = 10
K = 2
p = 0.5
ensemble_size = 1000
networkUpdates = 11
loc = '/Users/maxnotarangelo/Documents/ISB/BN_testing'

ensemble = []
for index in range(ensemble_size):
    (linkages, functions,
     init) = bn.getRandomParameters(N, K, isConstantConnectivity=True, bias=p)
    net = bn.BooleanNetwork(N, linkages, functions, init, loc,
                            'network_%d.csv' % index)
    ensemble.append(net)

print('Done initializing ensemble')

steps_until_attractor = []
for i in range(len(ensemble)):
    ensemble[i].update(networkUpdates)
    filepath = os.path.join(loc, 'network_%d.csv' % i)
    net_data = pd.read_csv(filepath)
    steps_until_attractor.append(stepsUntilAttractorIsReached(net_data))
    if i % 100 == 0:
        print(i)
Example #4
0
import reservoir
from reservoir import Reservoir

ensembleSize = 50
N = 10
K = 2
I = 1
L = 5

input_fp = '/Users/maxnotarangelo/Documents/ISB/BN_realization/time_series_data.csv'
directory = '/Users/maxnotarangelo/Documents/ISB/rc_ensemble_data/'

np.random.seed(0)
ensemble = []
for i in range(ensembleSize):
    (links, funcs, inits) = bn.getRandomParameters(N, K)
    res = Reservoir(I, L, input_fp, directory + 'reservoir_%d_output' % i, N,
                    links, funcs, inits)
    res.update(100)
    # print('Reservoir %d has vector representation\n' % i)
    # print(res.getHistoryAsVectors())
    ensemble.append(res)
    if i % 5 == 0:
        print(i, '. . .')

success = 0
failure = 0
data_real = None
print('first stage completed.')
for res in ensemble:
    df = pd.DataFrame(res.getHistoryAsVectors())
import os
import numpy as np
import pandas as pd
import scipy.stats as stats
from matplotlib import pyplot as plt
import seaborn as sns
import booleanNetwork as bn
from reservoir import Reservoir
from sklearn.linear_model import Lasso
from sklearn.linear_model import LinearRegression

fp = '/Users/maxnotarangelo/Documents/ISB/BN_realization/time_series_data.csv'
N = 100
numberOfInputs = 1
L = 5
(random_linkages, random_functions, random_init) = bn.getRandomParameters(N, 2)
r = Reservoir(numberOfInputs, L, fp, N, random_linkages, random_functions,
              random_init)
r.update(100)

reservoir_data_file = '/Users/maxnotarangelo/Documents/ISB/log.csv'
rdf = pd.read_csv(reservoir_data_file)
rdf.head()

func_data_file = '/Users/maxnotarangelo/Documents/ISB/BN_realization/function_data.csv'
fdf = pd.read_csv(func_data_file)
fdf.head()

rdf['Majority'] = fdf.get('Majority')

X = rdf.drop(['Input Node 1', 'Majority'], axis=1)