Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gibbsdavidl committed Nov 6, 2018
1 parent 53ecb78 commit 3ef0d5a
Show file tree
Hide file tree
Showing 72 changed files with 493,912 additions and 0 deletions.
802 changes: 802 additions & 0 deletions BN_realization/function_data.csv

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions BN_realization/functions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Node 1,Node 2,Node 3,Node 4,Node 5
0,0,0,0,0
1,1,1,1,0
1,1,1,-1,0
1,0,0,-1,0
0,0,1,-1,0
1,1,1,-1,0
1,1,0,-1,0
1,1,1,-1,1
3 changes: 3 additions & 0 deletions BN_realization/functions_2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Node 1,Node 2,Node 3,Node 4,Node 5,Node 6
0,0,0,0,0,0
1,1,1,1,1,1
40 changes: 40 additions & 0 deletions BN_realization/generateFunctionData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@


# memoryLength should be even so that the majority function is always defined;
# the input to the majority function includes the current timestep and the
# previous memoryLength timesteps
def generateMajorityFunctionData(memoryLength,
timeseries_filepath,
function_output_filepath):
time_series_file = open(timeseries_filepath)
contents = time_series_file.read()
time_series = []
for char in contents:
if char == '1':
time_series.append(1)
elif char == '0':
time_series.append(0)
time_series_file.close()

majority_data = [-1 for _ in range(memoryLength)]
for i in range(memoryLength, len(time_series)):
numberOfOnes = sum(time_series[i - memoryLength: i + 1])
if 2 * numberOfOnes > memoryLength:
majority_data.append(1)
else:
majority_data.append(0)

# Note that right now this only works with 1 input
strToWrite = 'Majority\n'
for datum in majority_data:
strToWrite += str(datum)
strToWrite += '\n'
output_file = open(function_output_filepath, 'w')
output_file.write(strToWrite)


folder = '/Users/maxnotarangelo/Documents/ISB/BN_realization/'
ts_filepath = folder + 'time_series_data.csv'
output_filepath = folder + 'function_data.csv'

generateMajorityFunctionData(2, ts_filepath, output_filepath)
39 changes: 39 additions & 0 deletions BN_realization/generateTimeseries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys

def create_timeseries_csv(input_filepath, output_filepath, numberOfInputs):
input_file = open(input_filepath)
raw_input = input_file.readlines()
input_file.close()

one_line_input = ''
for line in raw_input:
one_line_input += line

list_input = []
for char in one_line_input:
if char == '1':
list_input.append(1)
elif char == '0':
list_input.append(0)

strToWrite = ''
for i in range(numberOfInputs):
strToWrite += 'Input_%d,' % (i + 1)
strToWrite = strToWrite[:-1] + '\n'

for i in range(len(list_input) // numberOfInputs):
for j in range(numberOfInputs):
strToWrite += str(list_input[numberOfInputs * i + j])
strToWrite += ','
strToWrite = strToWrite[:-1] + '\n'

output_file = open(output_filepath, 'w')
output_file.write(strToWrite)


inputFile = '/Users/maxnotarangelo/Documents/ISB/code/BN_realization/' + \
sys.argv[1] # 'time_series_raw_2.txt'
outputFile = '/Users/maxnotarangelo/Documents/ISB/code/BN_realization/' + \
sys.argv[2] # 'time_series_data_3.csv'

create_timeseries_csv(inputFile, outputFile, int(sys.argv[3]))
2 changes: 2 additions & 0 deletions BN_realization/initial_nodes.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Node 1,Node 2,Node 3,Node 4,Node 5
0,1,1,0,1
2 changes: 2 additions & 0 deletions BN_realization/initial_nodes_2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Node 1,Node 2,Node 3,Node 4,Node 5,Node 6
0,0,0,0,0,0
4 changes: 4 additions & 0 deletions BN_realization/linkages.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Node 1,Node 2,Node 3,Node 4,Node 5
5,3,3,4,5
2,5,1,-1,4
4,4,5,-1,1
2 changes: 2 additions & 0 deletions BN_realization/linkages_2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Node 1,Node 2,Node 3,Node 4,Node 5,Node 6
1,2,3,4,5,6
Loading

0 comments on commit 3ef0d5a

Please sign in to comment.