コード例 #1
0
ファイル: test_imports.py プロジェクト: stjordanis/neurolib
    def setUpClass(cls):
        from neurolib.models.fhn import FHNModel

        fhn = FHNModel()
        fhn.run()
        cls.model = fhn

        from neurolib.utils.parameterSpace import ParameterSpace

        pars = ParameterSpace({"x": [1, 2]})
        cls.pars = pars
コード例 #2
0
    def setUpClass(cls):
        ds = Dataset("hcp")
        model = FHNModel(Cmat=ds.Cmat, Dmat=ds.Dmat)
        model.params.duration = 10 * 1000  # ms
        model.params.dt = 0.05
        model.params.bold = True
        parameters = ParameterSpace(
            {
                "x_ext": [
                    np.ones((model.params["N"], )) * a
                    for a in np.linspace(0, 2, 2)
                ],
                "K_gl":
                np.linspace(0, 2, 2),
                "coupling": ["additive", "diffusive"],
            },
            kind="grid",
        )
        search = BoxSearch(
            model=model,
            parameterSpace=parameters,
            filename=f"test_exploration_utils_{randomString(20)}.hdf")

        search.run(chunkwise=True, bold=True)

        search.loadResults()
        # flatten x_ext parameter
        search.dfResults.x_ext = [a[0] for a in list(search.dfResults.x_ext)]

        cls.model = model
        cls.search = search
        cls.ds = ds
コード例 #3
0
ファイル: test_exploration.py プロジェクト: rcofre/neurolib
    def test_fhn_brain_network_exploration(self):
        ds = Dataset("hcp")
        model = FHNModel(Cmat=ds.Cmat, Dmat=ds.Dmat)
        model.params.duration = 10 * 1000  # ms
        model.params.dt = 0.2
        model.params.bold = True
        parameters = ParameterSpace(
            {
                "x_ext": [
                    np.ones((model.params["N"], )) * a
                    for a in np.linspace(0, 2, 2)
                ],
                "K_gl":
                np.linspace(0, 2, 2),
                "coupling": ["additive", "diffusive"],
            },
            kind="grid",
        )
        search = BoxSearch(model=model,
                           parameterSpace=parameters,
                           filename="test_fhn_brain_network_exploration.hdf")

        search.run(chunkwise=True, bold=True)

        pu.getTrajectorynamesInFile(
            os.path.join(paths.HDF_DIR,
                         "test_fhn_brain_network_exploration.hdf"))
        search.loadDfResults()
        search.getRun(0, pypetShortNames=True)
        search.getRun(0, pypetShortNames=False)
        search.loadResults()
        search.info()
コード例 #4
0
    def test_network(self):
        logging.info("\t > FHN: Testing brain network (chunkwise integration and BOLD simulation) ...")
        start = time.time()
        ds = Dataset("gw")
        fhn = FHNModel(Cmat=ds.Cmat, Dmat=ds.Dmat)
        fhn.params["signalV"] = 4.0
        fhn.params["duration"] = 10 * 1000
        fhn.params["sigma_ou"] = 0.1
        fhn.params["K_gl"] = 0.6
        fhn.params["x_ext_mean"] = 0.72

        fhn.run(chunkwise=True, bold=True, append_outputs=True)
        end = time.time()
        logging.info("\t > Done in {:.2f} s".format(end - start))
コード例 #5
0
    def test_single_node(self):
        logging.info("\t > FHN: Testing single node ...")
        start = time.time()
        fhn = FHNModel()
        fhn.params["duration"] = 2.0 * 1000
        fhn.params["sigma_ou"] = 0.03

        fhn.run()

        end = time.time()
        logging.info("\t > Done in {:.2f} s".format(end - start))
コード例 #6
0
 def test_compare_w_neurolib_native_model(self):
     """
     Compare with neurolib's native FitzHugh-Nagumo model.
     """
     # run this model
     fhn_multi = self._create_node()
     multi_result = fhn_multi.run(DURATION, DT, ZeroInput(DURATION, DT).as_array(), backend="numba")
     # run neurolib's model
     fhn = FHNModel(seed=SEED)
     fhn.params["duration"] = DURATION
     fhn.params["dt"] = DT
     fhn.run()
     for var in NEUROLIB_VARIABLES_TO_TEST:
         corr_mat = np.corrcoef(fhn[var], multi_result[var].values.T)
         self.assertTrue(np.greater(corr_mat, CORR_THRESHOLD).all())
コード例 #7
0
 def test_compare_w_neurolib_native_model(self):
     """
     Compare with neurolib's native FitzHugh-Nagumo model.
     """
     # run this model - default is diffusive coupling
     fhn_multi = FitzHughNagumoNetwork(self.SC, self.DELAYS, seed=SEED)
     multi_result = fhn_multi.run(
         DURATION,
         DT,
         ZeroInput(fhn_multi.num_noise_variables).as_array(DURATION, DT),
         backend="numba")
     # run neurolib's model
     fhn_neurolib = FHNModel(Cmat=self.SC, Dmat=self.DELAYS, seed=SEED)
     fhn_neurolib.params["duration"] = DURATION
     fhn_neurolib.params["dt"] = DT
     # there is no "global coupling" parameter in MultiModel
     fhn_neurolib.params["K_gl"] = 1.0
     # delays <-> length matrix
     fhn_neurolib.params["signalV"] = 1.0
     fhn_neurolib.params["coupling"] = "diffusive"
     fhn_neurolib.params["sigma_ou"] = 0.0
     fhn_neurolib.params["xs_init"] = fhn_multi.initial_state[::2][:, np.
                                                                   newaxis]
     fhn_neurolib.params["ys_init"] = fhn_multi.initial_state[1::2][:, np.
                                                                    newaxis]
     fhn_neurolib.run()
     for var in NEUROLIB_VARIABLES_TO_TEST:
         corr_mat = np.corrcoef(fhn_neurolib[var],
                                multi_result[var].values.T)
         self.assertTrue(np.greater(corr_mat, CORR_THRESHOLD).all())