Пример #1
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
Пример #2
0
    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()
Пример #3
0
    def setUpClass(cls):
        ds = Dataset("hcp")
        model = ALNModel(Cmat=ds.Cmat, Dmat=ds.Dmat)
        model.params.duration = 11 * 1000  # ms
        model.params.dt = 0.2
        parameters = ParameterSpace(
            {
                "mue_ext_mean": np.linspace(0, 3, 2),
                "mui_ext_mean": np.linspace(0, 3, 2),
                "b": [0.0, 10.0],
            },
            kind="grid",
        )
        search = BoxSearch(
            model=model,
            parameterSpace=parameters,
            filename=f"test_exploration_utils_{randomString(20)}.hdf")

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

        search.loadResults()

        cls.model = model
        cls.search = search
        cls.ds = ds
Пример #4
0
    def test_single_node(self):
        start = time.time()

        model = ALNModel()
        parameters = ParameterSpace({"mue_ext_mean": np.linspace(0, 3, 2), "mui_ext_mean": np.linspace(0, 3, 2)})
        search = BoxSearch(model, parameters, filename="test_single_nodes.hdf")
        search.run()
        search.loadResults()

        for i in search.dfResults.index:
            search.dfResults.loc[i, "max_r"] = np.max(
                search.results[i]["rates_exc"][:, -int(1000 / model.params["dt"]) :]
            )

        end = time.time()
        logging.info("\t > Done in {:.2f} s".format(end - start))
Пример #5
0
    def test_circle_exploration(self):
        def explore_me(traj):
            pars = search.getParametersFromTraj(traj)
            # let's calculate the distance to a circle
            computation_result = abs((pars["x"] ** 2 + pars["y"] ** 2) - 1)
            result_dict = {"distance": computation_result}
            search.saveOutputsToPypet(result_dict, traj)

        parameters = ParameterSpace({"x": np.linspace(-2, 2, 2), "y": np.linspace(-2, 2, 2)})
        search = BoxSearch(evalFunction=explore_me, parameterSpace=parameters, filename="test_circle_exploration.hdf")
        search.run()
        search.loadResults(pypetShortNames=False)

        for i in search.dfResults.index:
            search.dfResults.loc[i, "distance"] = search.results[i]["distance"]

        search.dfResults
Пример #6
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))
Пример #7
0
    def test_single_node(self):
        logging.info("\t > BoxSearch: Testing ALN single node ...")
        start = time.time()

        aln = ALNModel()
        parameters = ParameterSpace({
            "mue_ext_mean": np.linspace(0, 3, 2),
            "mui_ext_mean": np.linspace(0, 3, 2)
        })
        search = BoxSearch(aln, parameters)
        search.run()
        search.loadResults()

        for i in search.dfResults.index:
            search.dfResults.loc[i, "max_r"] = np.max(
                search.results[i]["rates_exc"][:,
                                               -int(1000 / aln.params["dt"]):])

        end = time.time()
        logging.info("\t > Done in {:.2f} s".format(end - start))
Пример #8
0
    def test_circle_exploration(self):
        def explore_me(traj):
            pars = search.getParametersFromTraj(traj)
            # let's calculate the distance to a circle
            computation_result = abs((pars["x"] ** 2 + pars["y"] ** 2) - 1)
            result_dict = {"scalar_result": computation_result, "list_result": [1, 2, 3, 4], "array_result": np.ones(3)}
            search.saveToPypet(result_dict, traj)

        parameters = ParameterSpace({"x": np.linspace(-2, 2, 2), "y": np.linspace(-2, 2, 2)})
        search = BoxSearch(evalFunction=explore_me, parameterSpace=parameters, filename="test_circle_exploration.hdf")
        search.run()
        search.loadResults(pypetShortNames=False)

        # call the result dataframe
        search.dfResults

        # test integrity of dataframe
        for i in search.dfResults.index:
            self.assertEqual(search.dfResults.loc[i, "scalar_result"], search.results[i]["scalar_result"])
            self.assertListEqual(search.dfResults.loc[i, "list_result"], search.results[i]["list_result"])
            np.testing.assert_array_equal(search.dfResults.loc[i, "array_result"], search.results[i]["array_result"])