Beispiel #1
0
    def test_ConductanceMinimization(self):
        """Solve for NMDA conductances with constrained firing rates"""

        system = no_subpopulation()

        constraints = [
            MFConstraint(
                "%s-%s" %
                (p.name, "gNMDA"), partial(lambda x: x.inputs[0][IP.GM], p),
                partial(lambda x, val: x.inputs[0].__setitem__(IP.GM, val), p),
                partial(lambda x: x.rate - x.rate_prediction,
                        p), 0. * nsiemens, 500. * nsiemens)
            for p in system.populations
        ] + [
            MFConstraint("%s-%s" %
                         (p.name, "v_mean"), partial(lambda x: x.v_mean, p),
                         partial(lambda x, val: setattr(x, "v_mean", val), p),
                         partial(lambda x: x.v_mean - x.v_mean_prediction,
                                 p), -80. * mV, -50. * mV)
            for p in system.populations
        ]

        state = MFState(constraints, bounds_check=True)
        solver = MFSolver(state, solver='hybr')
        solver.run()

        for p in system.populations:
            assert p.rate_prediction.has_same_dimensions(p.rate)
            np.testing.assert_almost_equal(np.array(p.rate_prediction),
                                           np.array(p.rate))
Beispiel #2
0
    def test_ConductanceMinimizationRatio(self):
        """Solve for NMDA & Gaba conductances with constrained firing rates & EI fixed ratio"""

        system = no_subpopulation()
        ratio = 4.

        def e_setter(p, val):
            p.inputs[0].__setitem__(IP.GM, val)
            p.inputs[1].__setitem__(IP.GM, ratio * val)

        constraints = [
            MFConstraint("%s-%s" % (print(p.inputs), "gNMDA"),
                         partial(lambda x: x.inputs[0][IP.GM], p),
                         partial(e_setter, p),
                         partial(lambda x: x.rate - x.rate_prediction, p),
                         0. * nsiemens, 500. * nsiemens)
            for p in system.populations
        ] + [
            MFConstraint("%s-%s" %
                         (p.name, "v_mean"), partial(lambda x: x.v_mean, p),
                         partial(lambda x, val: setattr(x, "v_mean", val), p),
                         partial(lambda x: x.v_mean - x.v_mean_prediction,
                                 p), -80. * mV, 50. * mV)
            for p in system.populations
        ]

        state = MFState(constraints)
        solver = MFSolver(state, maxiter=1)
        solver.run()

        for p in system.populations:
            assert p.rate_prediction.has_same_dimensions(p.rate)
            np.testing.assert_almost_equal(np.array(p.rate_prediction),
                                           np.array(p.rate))
Beispiel #3
0
    def test_MFSolver_RatesVoltages(self):
        """Solve for firing rates & voltages with specialized subclass"""

        solver = MFSolver.rates_voltages(self.system)
        r1 = solver.run()

        # take old implementation and compare
        state = self.test_MFState()
        solver = MFSolver(state)
        r2 = solver.run()

        for key in [c.name for c in r1.constraints]:
            assert r1[key] == r2[key]
Beispiel #4
0
 def test_MFSolver(self):
     """Solve for firing rates & voltages with explicit function"""
     state = self.test_MFState()
     solver = MFSolver(state)
     solver.run()