def _weights(self, index, dists, sigma_sq, y_desired):

        dists = [dist(self.fmodel.dataset.get_y(idx), y_desired)
                 for idx in index] # could be optimized

        w = np.fromiter((gaussian_kernel(d/self.fmodel.dim_y, sigma_sq)
                         for d in dists), np.float)

        # We eliminate the outliers # TODO : actually reduce w and index
        wsum = w.sum()
        if wsum == 0:
            return 1.0/len(dists)*np.ones((len(dists),))
        else:
            eps = wsum * 1e-15 / self.fmodel.dim_y
            return np.fromiter((w_i/wsum if w_i > eps else 0.0 for w_i in w), np.float)
Example #2
0
    def _weights(self, index, dists, sigma_sq, y_desired):

        dists = [
            dist(self.fmodel.dataset.get_y(idx), y_desired) for idx in index
        ]  # could be optimized

        w = np.fromiter((gaussian_kernel(d / self.fmodel.dim_y, sigma_sq)
                         for d in dists), np.float)

        # We eliminate the outliers # TODO : actually reduce w and index
        wsum = w.sum()
        if wsum == 0:
            return 1.0 / len(dists) * np.ones((len(dists), ))
        else:
            eps = wsum * 1e-15 / self.fmodel.dim_y
            return np.fromiter((w_i / wsum if w_i > eps else 0.0 for w_i in w),
                               np.float)
    def _guess_x(self, y_desired, **kwargs):
        """Choose the relevant neighborhood to feed the inverse model, based
        on the minimum spread of the corresponding neighborhood in S.
        for each (x, y) with y neighbor of y_desired,
            1. find the neighborhood of x, (xi, yi)_k.
            2. compute the standart deviation of the error between yi and y_desired.
            3. select the neighborhood of minimum standart deviation

        TODO : Implement another method taking the spread in M too.
        """
        k = kwargs.get('k', self.k)
        _, indexes = self.fmodel.dataset.nn_y(y_desired, k = k)
        min_std, min_xi = float('inf'), None
        for i in indexes:
            xi = self.fmodel.dataset.get_x(i)
            _, indexes_xi = self.fmodel.dataset.nn_x(xi, k = k)
            std_xi = np.std([dist(self.fmodel.dataset.get_y(j), y_desired) for j in indexes_xi])
            if std_xi < min_std:
                min_std, min_xi = std_xi, xi
            #print(std_xi, tuple(yi))
        return [min_xi]
Example #4
0
    def _guess_x(self, y_desired, **kwargs):
        """Choose the relevant neighborhood to feed the inverse model, based
        on the minimum spread of the corresponding neighborhood in S.
        for each (x, y) with y neighbor of y_desired,
            1. find the neighborhood of x, (xi, yi)_k.
            2. compute the standart deviation of the error between yi and y_desired.
            3. select the neighborhood of minimum standart deviation

        TODO : Implement another method taking the spread in M too.
        """
        k = kwargs.get('k', self.k)
        _, indexes = self.fmodel.dataset.nn_y(y_desired, k=k)
        min_std, min_xi = float('inf'), None
        for i in indexes:
            xi = self.fmodel.dataset.get_x(i)
            _, indexes_xi = self.fmodel.dataset.nn_x(xi, k=k)
            std_xi = np.std([
                dist(self.fmodel.dataset.get_y(j), y_desired)
                for j in indexes_xi
            ])
            if std_xi < min_std:
                min_std, min_xi = std_xi, xi
            #print(std_xi, tuple(yi))
        return [min_xi]