예제 #1
0
def test_param_sim_summ():
    lhd = LatinHypercube(dmin, dmax)
    n_points = 10
    lhd.generate_array(n_points)
    summ = lambda x: generate_tsfresh_features(x, MinimalFCParameters())
    graph_dict = core.get_graph_chunked(param_func=lhd.draw,
                                        sim_func=simulator2,
                                        summaries_func=summ,
                                        batch_size=n_points,
                                        chunk_size=2)
    assert len(
        graph_dict["parameters"]) == 5, "Core test failed, dimensions mismatch"
    assert len(graph_dict["trajectories"]
               ) == 5, "Core test failed, dimensions mismatch"
    assert len(
        graph_dict["summarystats"]) == 5, "Core test failed, expected None"

    params, sim, summaries = dask.compute(graph_dict["parameters"],
                                          graph_dict["trajectories"],
                                          graph_dict["summarystats"])

    sim = np.asarray(sim)
    params = np.asarray(params)
    summaries = np.asarray(summaries)

    assert params.shape == (5, 2, 5), "Core test failed, dimensions mismatch"
    assert sim.shape == (5, 2, 1, 2,
                         101), "Core test failed, dimensions mismatch"
    assert summaries.shape == (5, 2, 1,
                               16), "Core test failed, dimensions mismatch"

    fixed_data = np.asarray([simulator2(bound) for p in range(10)])
    print(fixed_data.shape)
    fixed_data = fixed_data.reshape(10, 2, 101)

    fixed_mean = core.get_fixed_mean(fixed_data, summ, chunk_size=2)

    m, = dask.compute(fixed_mean)
    m = np.asarray(m)
    assert m.shape == (1, 16), "Core test failed, dimensions mismatch"

    dist_class = ns.NaiveSquaredDistance()

    dist_func = lambda x: dist_class.compute(x, m)

    dist = core.get_distance(dist_func, graph_dict["summarystats"])

    assert len(dist) == 5, "Core test failed, dimesnion mismatch"

    dist_res, = dask.compute(dist)
    dist_res = np.asarray(dist_res)

    assert dist_res.shape == (5, 2, 1,
                              16), "Core test failed, dimension mismatch"
예제 #2
0
    def compute_fixed_mean(self, chunk_size):
        """
        Computes the mean over summary statistics on fixed data
        
        Parameters
        ----------
        chunk_size : int
            the partition size when splitting the fixed data. For avoiding many individual tasks
            in dask if the data is large 
        
        Returns
        -------
        ndarray
            scaled distance
        """

        stats_mean = core.get_fixed_mean(self.data, self.summaries_function, chunk_size)
        self.fixed_mean = stats_mean.compute()
        del stats_mean
예제 #3
0
 def compute_fixed_mean(self, chunk_size):
     stats_mean = core.get_fixed_mean(self.data, self.summaries_function,
                                      chunk_size)
     self.fixed_mean = stats_mean.compute()
     del stats_mean