Beispiel #1
0
    def _simulate(self, model: Model, final_time=0.0):
        starter = model.update(self.starter)
        system = model.update(self.variant)

        starter = starter.run_to_steady_state()
        system = system.update_initial(starter)

        return BioluciaSystemSimulation(system, final_time)
Beispiel #2
0
    def test_updating(self):
        m = equilibrium_model()
        con1 = InitialValueExperiment(equilibrium_dose_variant())
        con2 = InitialValueExperiment(Model().add('A0 = 15', 'kf = 0.3'))

        active_parameters = ActiveParameters.from_model_experiments(
            m, [con1, con2], ['kr'], [[], ['A0', 'kf']])
        updated_parameters = active_parameters.update_parameters(
            [4.0, 1.3, 2.0])
        self.assertEqual(
            updated_parameters,
            ActiveParameters(OrderedDict([
                ('kr', 4.0)
            ]), [OrderedDict(),
                 OrderedDict([('A0', 1.3), ('kf', 2.0)])]))

        active_parameters = ActiveParameters.from_model_experiments(
            m, [con2, con2], ['kr'], [['kf'], ['A0', 'kf']])
        updated_parameters = active_parameters.update_parameters(
            [4.0, 3.4, 1.3, 2.0])
        self.assertEqual(
            updated_parameters,
            ActiveParameters(OrderedDict([('kr', 4.0)]), [
                OrderedDict([('kf', 3.4)]),
                OrderedDict([('A0', 1.3), ('kf', 2.0)])
            ]))
Beispiel #3
0
    def __init__(self, system: Model, final_time: float = 0.0):
        self._observable_names = system.observable_names()
        self.ode_system = system.build_odes()

        self.final_time = 0.0
        self.final_state = self.ode_system.ics()

        self.solution_times = [0.0]
        self.solution_states = [self.final_state]

        # Ensure the discontinuities are sorted and there is always an infinity and never a 0
        sorted_disc = sorted(set(self.ode_system.discontinuities + self.ode_system.dose_times + (inf,)))
        zeroless_disc = sorted_disc if sorted_disc[0] != 0.0 else sorted_disc[1:]
        self.all_discontinuities = zeroless_disc

        self.i_next_discontinuity = 0

        self.integrate_to(final_time)
Beispiel #4
0
    def make_model(x):
        maybe_options, components = x

        if maybe_options:
            raise NotImplementedError

        parts, events = collapse_components(components)

        new_model = Model(parts, events)
        return new_model
Beispiel #5
0
    def test_basic_fitting(self):
        m = Model().add('k = 10')
        con = InitialValueExperiment()
        obj = LinearWeightedSumOfSquaresObservation(
            [0], ['k'], AffineMeasurementUncertainty(1, 0)).objective([20])

        fitted_parameters = fit_parameters(m, [con], [obj],
                                           model_parameters='k')

        self.assertAlmostEqual(fitted_parameters.model_parameters['k'], 20)
Beispiel #6
0
    def test_extraction(self):
        m = equilibrium_model()
        con1 = InitialValueExperiment(equilibrium_dose_variant())
        con2 = InitialValueExperiment(Model().add('A0 = 15', 'kf = 0.3'))

        active_parameters = ActiveParameters.from_model_experiments(
            m, [con1], ['kf', 'kr'], [[]])
        self.assertEqual(
            active_parameters,
            ActiveParameters(OrderedDict([('kf', 0.5), ('kr', 0.2)]),
                             [OrderedDict()]))

        active_parameters = ActiveParameters.from_model_experiments(
            m, [con1, con2], ['kf', 'kr'], [])
        self.assertEqual(
            active_parameters,
            ActiveParameters(OrderedDict([('kf', 0.5), ('kr', 0.2)]),
                             [OrderedDict(), OrderedDict()]))

        active_parameters = ActiveParameters.from_model_experiments(
            m, [con1, con2], ['kr', 'kf'], [])
        self.assertEqual(
            active_parameters,
            ActiveParameters(OrderedDict([('kr', 0.2), ('kf', 0.5)]),
                             [OrderedDict(), OrderedDict()]))

        active_parameters = ActiveParameters.from_model_experiments(
            m, [con1, con2], ['kr', 'kf'], [])
        self.assertEqual(
            active_parameters,
            ActiveParameters(OrderedDict([('kr', 0.2), ('kf', 0.5)]),
                             [OrderedDict(), OrderedDict()]))

        active_parameters = ActiveParameters.from_model_experiments(
            m, [con1, con2], [], [[], ['A0']])
        self.assertEqual(
            active_parameters,
            ActiveParameters(
                OrderedDict(),
                [OrderedDict(), OrderedDict([('A0', 15)])]))

        active_parameters = ActiveParameters.from_model_experiments(
            m, [con1, con2], [], [[], ['A0', 'kf']])
        self.assertEqual(
            active_parameters,
            ActiveParameters(
                OrderedDict(),
                [OrderedDict(),
                 OrderedDict([('A0', 15), ('kf', 0.3)])]))
Beispiel #7
0
 def _simulate(self, model: Model, final_time=0.0):
     system = model.update(self.variant)
     return BioluciaSystemSimulation(system, final_time)
Beispiel #8
0
 def __init__(self, starter: Model = Model(), variant: Model = Model()):
     self.starter = starter
     self.variant = variant
Beispiel #9
0
 def __init__(self, variant: Model = Model()):
     self.variant = variant