Ejemplo n.º 1
0
def newData(new_thetas, toexp=False):
    model = monochain()
    compiled_solver = VariableSSACSolver(model)

    new_data = [
        simulator(x, model, compiled_solver, toexp=toexp) for x in new_thetas
    ]
    new_data, = compute(new_data)
    new_data, = compute(new_data)

    x = []
    y = []
    for e, i in enumerate(new_data):
        if type(i) == float:
            continue
        elif np.max(i) > 2000:
            continue
        else:
            x.append(i)
            y.append(new_thetas[e])

    new_data = np.asarray(x)
    new_thetas = np.asarray(y)
    new_data = np.reshape(
        new_data, (new_data.shape[0], new_data.shape[2], new_data.shape[3]))
    return (new_data, new_thetas)
 def test_change_parameter(self):
     model = Example()
     initial_expression = model.listOfParameters['k1'].expression
     solver = VariableSSACSolver(model)
     results = model.run(solver=solver, variables={'k1': 0})
     with self.subTest(msg='Test changed parameter simulation'):
         self.assertEqual(results['Sp'][-1], results['Sp'][0])
     with self.subTest(msg='Test changed parameter model integrity'):
         self.assertEqual(model.listOfParameters['k1'].expression,
                          initial_expression)
 def test_change_species(self):
     model = Example()
     initial_value = model.listOfSpecies['Sp'].initial_value
     solver = VariableSSACSolver(model)
     results = model.run(solver=solver, variables={'Sp': 3})
     with self.subTest(msg='Test changed species simulation'):
         self.assertEqual(results['Sp'][0], 3)
     with self.subTest(msg='Test changed species model integrity'):
         self.assertEqual(model.listOfSpecies['Sp'].initial_value,
                          initial_value)
 def test_create(self):
     model = Example()
     solver = VariableSSACSolver(model)
 def test_invalid_variable(self):
     model = Example()
     solver = VariableSSACSolver(model)
     with self.assertRaises(SimulationError):
         results = model.run(solver=solver, variables={'foobar': 0})
 def test_run_example_precompiled(self):
     model = Example()
     solver = VariableSSACSolver(model)
     results = model.run(solver=solver)
 def test_file_with_directory_name_exists(self):
     with self.assertRaises(DirectoryError):
         temp = tempfile.NamedTemporaryFile()
         model = Example()
         solver = VariableSSACSolver(model, temp.name)
Ejemplo n.º 8
0
    if transform:
        # Extract only observed species
        prey = res['prey']
        predator = res['predator']

        return np.vstack([prey, predator])
    else:
        return res


def wrapper(param):
    return simulator(param, vilar_model, solver)


vilar_model = lotka_volterra()
solver = VariableSSACSolver(vilar_model)


class SummaryNet_large(nn.Module):
    def __init__(self):
        super().__init__()
        # 2D convolutional layer
        self.conv1 = nn.Conv1d(in_channels=2,
                               out_channels=20,
                               kernel_size=3,
                               padding=2)
        # Maxpool layer that reduces YxY image to length (20,4)
        self.pool = nn.MaxPool1d(kernel_size=5, stride=5)
        # Fully connected layer taking as input the 6 flattened output arrays from the maxpooling layer
        self.fc = nn.Linear(in_features=20 * 5 * 2, out_features=8)
Ejemplo n.º 9
0
        self.add_parameter(Parameter(name="k3", expression=1.0))

        # Species
        self.add_species(Species(name='prey', initial_value = 100, mode = 'discrete'))
        self.add_species(Species(name='predator', initial_value = 100, mode = 'discrete'))
        
        # Reactions
        self.add_reaction(Reaction(name="r1", reactants = {'prey' : 1}, products = {'prey' : 2}, rate = self.listOfParameters['k1']))
        self.add_reaction(Reaction(name="r2", reactants = {'predator' : 1, 'prey' : 1}, products = {'predator' : 2}, rate = self.listOfParameters['k2']))
        self.add_reaction(Reaction(name="r3", reactants = {'predator' : 1}, products = {}, rate = self.listOfParameters['k3']))

        # Timespan
        self.timespan(np.linspace(0, 50, 51))
        
model = lotka_volterra()
compiled_solver = VariableSSACSolver(model)


# # Data



#target_ts = np.load('target_ts.npy')
obs_data = np.load('target_original_shape_ts.npy')


# # Prior Distributions