Esempio n. 1
0
def test_encodeSplines():
    x = np.arange(100)

    assert np.allclose(encodeSplines(x, start=-1, end=50).sum(2), 1)
    assert np.allclose(encodeSplines(x, start=-1, end=120).sum(2), 1)
    assert np.allclose(encodeSplines(x, start=10, end=120).sum(2), 1)
    assert np.allclose(encodeSplines(x).sum(2), 1)
Esempio n. 2
0
def test_EncodeSplines_comparison():
    x = np.random.normal(size=(100, 3, 2))

    x1t = encodeSplines(x[..., 0])
    x2t = encodeSplines(x[..., 1])

    es = EncodeSplines()
    es.fit(x)
    x_all = es.transform(x)

    assert np.allclose(x_all[..., 0, :], x1t)
    assert np.allclose(x_all[..., 1, :], x2t)
    assert np.allclose(x_all[..., 1, :].sum(-1), 1)

    assert es.data_min_[0] == x[..., 0].min()
    assert es.data_max_[1] == x[..., 1].max()
Esempio n. 3
0
    def transform(self, x):
        # impute missing values and rescale the distances
        xnew = self.minmax_scaler.transform(self.funct_transform.transform(self.imp.transform(x)))

        # convert distances to spline bases
        dist = {"dist_" + k: encodeSplines(xnew[:, i, np.newaxis], start=0, end=1, warn=False)
                for i, k in enumerate(self.POS_FEATURES)}
        return dist
Esempio n. 4
0
    def transform(self, x):
        # impute missing values and rescale the distances
        xnew = self.preproc_pipeline.transform(self.imp.transform(x))

        # convert distances to spline bases
        dist = {
            "dist_" + k: encodeSplines(xnew[:, i, np.newaxis], start=0, end=1)
            for i, k in enumerate(self.POS_FEATURES)
        }
        return dist
Esempio n. 5
0
def encodeSplines_common(x, pos_range, n_bases, spline_order):
    x_processed = {
        k: fill_nan(
            encodeSplines(v,
                          n_bases=n_bases,
                          spline_order=spline_order,
                          start=pos_range[k]["min"],
                          end=pos_range[k]["max"]))
        for k, v in x.items()
    }
    return x_processed