Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_names(self, variable_type, comp, type_, i_step=None, i_stage=None, j_stage=None):
if variable_type == 'states':
variables_dict = self._ode_options._states
elif variable_type == 'dynamic_parameters':
variables_dict = self._ode_options._dynamic_parameters
names_list = []
for variable_name, variable in iteritems(variables_dict):
if type_ == 'rate_source':
names = '{}.{}'.format(comp, variable['rate_source'])
elif type_ == 'targets':
names = ['{}.{}'.format(comp, tgt) for tgt in variable['targets']] \
if variable['targets'] else []
else:
names = '{}.{}'.format(comp, get_name(
type_, variable_name, i_step=i_step, i_stage=i_stage, j_stage=j_stage))
names_list.append(names)
return names_list
time_units = self.options['time_units']
num_stages = self.options['num_stages']
num_step_vars = self.options['num_step_vars']
i_step = self.options['i_step']
glm_B = self.options['glm_B']
glm_V = self.options['glm_V']
self.dy_dF = dy_dF = {}
self.add_input('h', units=time_units)
for state_name, state in iteritems(self.options['states']):
size = np.prod(state['shape'])
shape = state['shape']
F_name = get_name('F', state_name, i_step=i_step)
y_old_name = get_name('y_old', state_name, i_step=i_step)
y_new_name = get_name('y_new', state_name, i_step=i_step)
self.add_input(
F_name, shape=(num_stages,) + shape,
units=get_rate_units(state['units'], time_units))
self.add_input(
y_old_name, shape=(num_step_vars,) + shape,
units=state['units'])
self.add_output(
y_new_name, shape=(num_step_vars,) + shape,
units=state['units'])
F_arange = np.arange(num_stages * size).reshape(
def compute(self, inputs, outputs):
num_times = self.options['num_times']
num_stages = self.options['num_stages']
num_step_vars = self.options['num_step_vars']
for state_name, state in iteritems(self.options['states']):
size = np.prod(state['shape'])
shape = state['shape']
F_name = get_name('F', state_name)
Y_out_name = get_name('Y_out', state_name)
Y_in_name = get_name('Y_in', state_name)
y0_name = get_name('y0', state_name)
mtx_y0 = self.mtx_y0_dict[state_name]
mtx = self.mtx_dict[state_name]
mtx_h = self.mtx_h_dict[state_name]
Y_shape = outputs[Y_out_name].shape
outputs[Y_out_name] = -inputs[Y_in_name] \
+ mtx.dot(mtx_h.dot(inputs['h_vec']) * inputs[F_name].flatten()).reshape(Y_shape) \
+ mtx_y0.dot(inputs[y0_name].flatten()).reshape(Y_shape)
def compute(self, inputs, outputs):
glm_A = self.metadata['glm_A']
glm_U = self.metadata['glm_U']
for state_name, state in iteritems(self.metadata['states']):
size = np.prod(state['shape'])
shape = state['shape']
F_name = get_name('F', state_name)
y_name = get_name('y', state_name)
Y_out_name = get_name('Y_out', state_name)
Y_in_name = get_name('Y_in', state_name)
outputs[Y_out_name] = -inputs[Y_in_name] \
+ np.einsum('jk,i,ik...->ij...', glm_A, inputs['h_vec'], inputs[F_name]) \
+ np.einsum('jk,ik...->ij...', glm_U, inputs[y_name][:-1, :, :])
def compute_partials(self, inputs, partials):
num_times = self.options['num_times']
num_stages = self.options['num_stages']
num_step_vars = self.options['num_step_vars']
for state_name, state in iteritems(self.options['states']):
size = np.prod(state['shape'])
shape = state['shape']
F_name = get_name('F', state_name)
Y_out_name = get_name('Y_out', state_name)
Y_in_name = get_name('Y_in', state_name)
y0_name = get_name('y0', state_name)
mtx_y0 = self.mtx_y0_dict[state_name]
mtx = self.mtx_dict[state_name]
mtx_h = self.mtx_h_dict[state_name]
partials[Y_out_name, 'h_vec'][:, :] = \
mtx.dot(np.diag(inputs[F_name].flatten())).dot(mtx_h)
partials[Y_out_name, F_name][:, :] = mtx.dot(np.diag(mtx_h.dot(inputs['h_vec'])))
partials[Y_out_name, y0_name][:, :] = mtx_y0
num_stages = self.options['num_stages']
num_step_vars = self.options['num_step_vars']
i_step = self.options['i_step']
glm_B = self.options['glm_B']
glm_V = self.options['glm_V']
self.dy_dF = dy_dF = {}
self.add_input('h', units=time_units)
for state_name, state in iteritems(self.options['states']):
size = np.prod(state['shape'])
shape = state['shape']
F_name = get_name('F', state_name, i_step=i_step)
y_old_name = get_name('y_old', state_name, i_step=i_step)
y_new_name = get_name('y_new', state_name, i_step=i_step)
self.add_input(
F_name, shape=(num_stages,) + shape,
units=get_rate_units(state['units'], time_units))
self.add_input(
y_old_name, shape=(num_step_vars,) + shape,
units=state['units'])
self.add_output(
y_new_name, shape=(num_step_vars,) + shape,
units=state['units'])
F_arange = np.arange(num_stages * size).reshape(
(num_stages,) + shape)
num_stages = self.options['num_stages']
num_step_vars = self.options['num_step_vars']
i_stage = self.options['i_stage']
glm_A = self.options['glm_A']
glm_U = self.options['glm_U']
i_step = self.options['i_step']
for state_name, state in iteritems(self.options['states']):
size = np.prod(state['shape'])
Y_name = get_name('Y', state_name, i_step=i_step, i_stage=i_stage)
partials[Y_name, 'h'][:, 0] = 0.
for j_stage in range(i_stage):
F_name = get_name('F', state_name, i_step=i_step, i_stage=i_stage, j_stage=j_stage)
partials[Y_name, F_name] = inputs['h'] * glm_A[i_stage, j_stage]
partials[Y_name, 'h'][:, 0] += glm_A[i_stage, j_stage] * inputs[F_name].flatten()
def compute(self, inputs, outputs):
num_starting_times = self.options['num_starting_times']
num_my_times = self.options['num_my_times']
starting_coeffs = self.options['starting_coeffs']
for state_name, state in iteritems(self.options['states']):
y_name = get_name('y', state_name)
starting_state_name = get_name('starting_state', state_name)
out_state_name = get_name('state', state_name)
starting_name = get_name('starting', state_name)
outputs[out_state_name][num_starting_times - 1:] = inputs[y_name][:, 0, :]
def compute_partials(self, inputs, partials):
num_times = self.options['num_times']
num_stages = self.options['num_stages']
num_step_vars = self.options['num_step_vars']
for state_name, state in iteritems(self.options['states']):
size = np.prod(state['shape'])
shape = state['shape']
F_name = get_name('F', state_name)
Y_out_name = get_name('Y_out', state_name)
Y_in_name = get_name('Y_in', state_name)
y0_name = get_name('y0', state_name)
mtx_y0 = self.mtx_y0_dict[state_name]
mtx = self.mtx_dict[state_name]
mtx_h = self.mtx_h_dict[state_name]
partials[Y_out_name, 'h_vec'][:, :] = \
mtx.dot(np.diag(inputs[F_name].flatten())).dot(mtx_h)
partials[Y_out_name, F_name][:, :] = mtx.dot(np.diag(mtx_h.dot(inputs['h_vec'])))
partials[Y_out_name, y0_name][:, :] = mtx_y0
def compute(self, inputs, outputs):
glm_A = self.metadata['glm_A']
glm_U = self.metadata['glm_U']
for state_name, state in iteritems(self.metadata['states']):
size = np.prod(state['shape'])
shape = state['shape']
F_name = get_name('F', state_name)
y_name = get_name('y', state_name)
Y_out_name = get_name('Y_out', state_name)
Y_in_name = get_name('Y_in', state_name)
outputs[Y_out_name] = -inputs[Y_in_name] \
+ np.einsum('jk,i,ik...->ij...', glm_A, inputs['h_vec'], inputs[F_name]) \
+ np.einsum('jk,ik...->ij...', glm_U, inputs[y_name][:-1, :, :])