Fill output NANs with previous value
This commit is contained in:
parent
f6f6e7b3fd
commit
afc48e72b7
|
|
@ -3,6 +3,7 @@ from fn import _
|
|||
from fn.op import foldr, call
|
||||
from ui.config import behavior_ops
|
||||
|
||||
|
||||
def getColResults(step, sL, s, funcs):
|
||||
return list(map(lambda f: f(step, sL, s), funcs))
|
||||
|
||||
|
|
@ -15,7 +16,6 @@ def getBehaviorInput(step, sL, s, funcs, ops = behavior_ops):
|
|||
ops = ops[::-1]
|
||||
|
||||
return foldr(call, getColResults(step, sL, s, funcs))(ops)
|
||||
# return getColResults(step, sL, s, funcs)
|
||||
|
||||
def apply_env_proc(env_processes, state_dict, step):
|
||||
for state in state_dict.keys():
|
||||
|
|
@ -36,13 +36,22 @@ def mech_step(m_step, sL, state_funcs, behavior_funcs, env_processes, t_step, ru
|
|||
|
||||
_input = exception_handler(getBehaviorInput, m_step, sL, last_in_obj, behavior_funcs)
|
||||
|
||||
# print(sL)
|
||||
|
||||
# *** add env_proc value here as wrapper function ***
|
||||
last_in_copy = dict([ exception_handler(f, m_step, sL, last_in_obj, _input) for f in state_funcs ])
|
||||
|
||||
for k in last_in_obj:
|
||||
if k not in last_in_copy:
|
||||
last_in_copy[k] = last_in_obj[k]
|
||||
|
||||
del last_in_obj
|
||||
|
||||
# make env proc trigger field agnostic
|
||||
apply_env_proc(env_processes, last_in_copy, last_in_copy['timestamp']) # mutating last_in_copy
|
||||
|
||||
last_in_copy["mech_step"], last_in_copy["time_step"], last_in_copy['run'] = m_step, t_step, run
|
||||
# print(last_in_copy)
|
||||
sL.append(last_in_copy)
|
||||
del last_in_copy
|
||||
|
||||
|
|
@ -52,6 +61,7 @@ def mech_step(m_step, sL, state_funcs, behavior_funcs, env_processes, t_step, ru
|
|||
def block_gen(states_list, configs, env_processes, t_step, run):
|
||||
m_step = 0
|
||||
states_list_copy = deepcopy(states_list)
|
||||
# remove copy
|
||||
genesis_states = states_list_copy[-1]
|
||||
genesis_states['mech_step'], genesis_states['time_step'] = m_step, t_step
|
||||
states_list = [genesis_states]
|
||||
|
|
@ -60,8 +70,6 @@ def block_gen(states_list, configs, env_processes, t_step, run):
|
|||
for config in configs:
|
||||
s_conf, b_conf = config[0], config[1]
|
||||
states_list = mech_step(m_step, states_list, s_conf, b_conf, env_processes, t_step, run)
|
||||
# print(states_list)
|
||||
# print(b_conf)
|
||||
m_step += 1
|
||||
|
||||
t_step += 1
|
||||
|
|
@ -91,7 +99,6 @@ def simulation(states_list, configs, env_processes, time_seq, runs):
|
|||
head[-1]['mech_step'], head[-1]['time_step'], head[-1]['run'] = 0, 0, 0
|
||||
simulation_list = [head] + tail
|
||||
pipe_run += simulation_list
|
||||
# print(pipe_run)
|
||||
else:
|
||||
transient_states_list = [pipe_run[-1][-1]]
|
||||
_, *tail = pipe(transient_states_list, configs, env_processes, time_seq, run)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ from engine.configProcessor import generate_config, create_tensor_field
|
|||
from engine.mechanismExecutor import simulation
|
||||
from engine.utils import flatten
|
||||
from tabulate import tabulate
|
||||
#from tabulate import tabulate
|
||||
import pandas as pd
|
||||
|
||||
def main():
|
||||
|
|
@ -13,17 +12,13 @@ def main():
|
|||
# print(len(configs))
|
||||
print(tabulate(create_tensor_field(mechanisms, ep), headers='keys', tablefmt='psql'))
|
||||
print
|
||||
# print(configs)
|
||||
# print(states_list)
|
||||
# print(configs)
|
||||
# p = pipeline(states_list, configs, env_processes, range(10))
|
||||
T = sim_config['T']
|
||||
N = sim_config['N']
|
||||
|
||||
# Dimensions: N x r x mechs
|
||||
s = simulation(states_list, configs, env_processes, T, N)
|
||||
|
||||
result = pd.DataFrame(flatten(s))
|
||||
# print('Test')
|
||||
# print(tabulate(result, headers='keys', tablefmt='psql'))
|
||||
# remove print and tabulate functions, so it returns a dataframe
|
||||
|
||||
return result
|
||||
2
setup.py
2
setup.py
|
|
@ -6,6 +6,6 @@ setup(name='SimCAD',
|
|||
url='https://github.com/BlockScience/DiffyQ-SimCAD',
|
||||
author='Joshua E. Jodesty',
|
||||
author_email='joshua@block.science',
|
||||
license='MIT',
|
||||
# license='MIT',
|
||||
packages=['engine'],
|
||||
zip_safe=False)
|
||||
|
|
@ -149,7 +149,7 @@ def dict_elemwise_sum(f = _ + _):
|
|||
|
||||
# [1, 2] = {'b1': ['a'], 'b2', [1]} =
|
||||
# behavior_ops = [ behavior_to_dict, print_fwd, sum_dict_values ]
|
||||
behavior_ops = [ print_fwd, foldr(dict_elemwise_sum()) ]
|
||||
behavior_ops = [ foldr(dict_elemwise_sum(_ + _)) ]
|
||||
# behavior_ops = []
|
||||
|
||||
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
|
||||
|
|
@ -162,7 +162,7 @@ mechanisms = {
|
|||
},
|
||||
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
|
||||
"s1": s1m1,
|
||||
"s2": s2m1
|
||||
# "s2": s2m1
|
||||
}
|
||||
},
|
||||
"m2": {
|
||||
|
|
@ -172,7 +172,7 @@ mechanisms = {
|
|||
},
|
||||
"states": {
|
||||
"s1": s1m2,
|
||||
"s2": s2m2
|
||||
# "s2": s2m2
|
||||
}
|
||||
},
|
||||
"m3": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue