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())
 def test_run(self):
     fhn = FitzHughNagumoNetwork(self.SC, self.DELAYS)
     all_results = []
     for backend, noise_func in BACKENDS_TO_TEST.items():
         result = fhn.run(
             DURATION,
             DT,
             noise_func(ZeroInput(fhn.num_noise_variables), DURATION, DT),
             backend=backend,
         )
         self.assertTrue(isinstance(result, xr.Dataset))
         self.assertEqual(len(result),
                          fhn.num_state_variables / fhn.num_nodes)
         self.assertTrue(
             all(result[result_].shape == (int(DURATION / DT),
                                           fhn.num_nodes)
                 for result_ in result))
         all_results.append(result)
     # test results are the same from different backends
     for state_var in all_results[0]:
         corr_mat = np.corrcoef(
             np.vstack([
                 result[state_var].values.flatten().astype(float)
                 for result in all_results
             ]))
         self.assertTrue(np.greater(corr_mat, CORR_THRESHOLD).all())
示例#3
0
 def test_run_chunkwise(self):
     DELAY = 13.0
     fhn_net = FitzHughNagumoNetwork(np.random.rand(2, 2),
                                     np.array([[0.0, DELAY], [DELAY, 0.0]]))
     model = MultiModel(fhn_net)
     # not implemented for now
     with pytest.raises((NotImplementedError, AssertionError)):
         model.run(chunkwise=True)
示例#4
0
 def test_init(self):
     DELAY = 13.0
     fhn_net = FitzHughNagumoNetwork(np.random.rand(2, 2),
                                     np.array([[0.0, DELAY], [DELAY, 0.0]]))
     model = MultiModel(fhn_net)
     self.assertEqual(model.model_instance, fhn_net)
     self.assertTrue(isinstance(model.params, star_dotdict))
     self.assertTrue(model.integration is None)
     max_delay = int(DELAY / model.params["dt"])
     self.assertEqual(model.getMaxDelay(), max_delay)
示例#5
0
 def test_run_network(self):
     DELAY = 13.0
     fhn_net = FitzHughNagumoNetwork(np.random.rand(2, 2),
                                     np.array([[0.0, DELAY], [DELAY, 0.0]]))
     model = MultiModel(fhn_net)
     model.params["sampling_dt"] = 10.0
     # run MultiModel
     model.run()
     # run model instance
     inst_res = fhn_net.run(
         duration=model.params["duration"],
         dt=model.params["sampling_dt"],
         noise_input=join(*[
             noise.as_cubic_splines(model.params["duration"],
                                    model.params["sampling_dt"])
             for noise in fhn_net.noise_input
         ]),
         backend=model.params["backend"],
     )
     for out_var in model.output_vars:
         np.testing.assert_equal(model[out_var], inst_res[out_var].values.T)
示例#6
0
 def test_run_numba_w_bold(self):
     DELAY = 13.0
     fhn_net = FitzHughNagumoNetwork(np.random.rand(2, 2),
                                     np.array([[0.0, DELAY], [DELAY, 0.0]]))
     model = MultiModel(fhn_net)
     model.params["backend"] = "numba"
     model.params["duration"] = 10000
     model.params["dt"] = 0.1
     model.run(bold=True)
     # access outputs
     self.assertTrue(isinstance(model.xr(), xr.DataArray))
     self.assertTrue(isinstance(model.xr("BOLD"), xr.DataArray))
示例#7
0
    def test_multimodel_explore(self):
        start = time.time()

        DELAY = 13.0
        fhn_net = FitzHughNagumoNetwork(np.random.rand(2, 2), np.array([[0.0, DELAY], [DELAY, 0.0]]))
        model = MultiModel(fhn_net)
        parameters = ParameterSpace({"*noise*sigma": [0.0, 0.05], "*epsilon*": [0.5, 0.6]}, allow_star_notation=True)
        search = BoxSearch(model, parameters, filename="test_multimodel.hdf")
        search.run()
        search.loadResults()
        dataarray = search.xr()
        self.assertTrue(isinstance(dataarray, xr.DataArray))
        self.assertTrue(isinstance(dataarray.attrs, dict))
        self.assertListEqual(list(dataarray.attrs.keys()), list(parameters.dict().keys()))

        end = time.time()
        logging.info("\t > Done in {:.2f} s".format(end - start))
 def test_init(self):
     fhn = FitzHughNagumoNetwork(self.SC, self.DELAYS)
     self.assertTrue(isinstance(fhn, FitzHughNagumoNetwork))
     self.assertEqual(len(fhn), self.SC.shape[0])
     self.assertEqual(fhn.initial_state.shape[0], fhn.num_state_variables)
     self.assertEqual(fhn.default_output, "x")