Ejemplo n.º 1
0
 def __init__(self,
              x,
              y,
              x0,
              h_mean,
              h_cov,
              h_cov_dia,
              fve=0.85,
              binning=True,
              bin_weight=True,
              ker_fun='Epan',
              bw_select='Partition',
              dtype='f4'):
     self.__Check_Input(x, y, x0, h_mean, h_cov, h_cov_dia, fve, binning,
                        bin_weight, ker_fun, bw_select, dtype)
     self.__num_fun = len(x)
     self.__d = x0.shape[-1]
     self.__grid_shape = np.asarray(x0.shape[:-1])
     self.__bin_width = np.ptp(x0.reshape(-1, self.__d),
                               0) / (self.__grid_shape - 1)
     self.__n_train = lpr.Partition_Data_Size(len(x))
     x0_min = x0.reshape(-1, self.__d).min(0)
     x0_max = x0.reshape(-1, self.__d).max(0)
     self.__grid = tuple(
         np.linspace(x0_min.take(i), x0_max.take(i), x0.shape[i])
         for i in range(self.__d))
     self.__Main(x, y, x0, h_mean, h_cov, h_cov_dia, fve, binning,
                 bin_weight, ker_fun, bw_select, dtype)
     self.__Standardize_Output()
Ejemplo n.º 2
0
    def __init__(self,
                 X_data,
                 h_mean,
                 h_cov,
                 binning=True,
                 bin_weight=True,
                 ker_fun='Gaussian'):

        num_grid = X_data.time_grid.shape[0]
        tran_size = X_data.obs_tran.shape[0]
        num_pts = X_data.tran_time_pts.shape[1]

        x = X_data.tran_time_pts.reshape(tran_size, num_pts, 1)
        y = X_data.obs_tran
        x0 = X_data.time_grid.reshape(num_grid, 1)

        self.__Check_Input(x, y, x0, h_mean, h_cov, binning, bin_weight,
                           ker_fun)
        self.__num_fun, self.__num_pt, self.__d = tran_size, num_pts, 1
        self.__grid_shape = np.asarray(x0.shape[:-1])
        self.__bin_width = np.ptp(x0.reshape(-1, self.__d),
                                  0) / (self.__grid_shape - 1)
        self.__n_train = lpr.Partition_Data_Size(self.__num_fun *
                                                 self.__num_pt -
                                                 np.isnan(y).sum())
        x0_min = x0.reshape(-1, self.__d).min(0)
        x0_max = x0.reshape(-1, self.__d).max(0)
        self.__grid = tuple(
            np.linspace(x0_min.take(i), x0_max.take(i), x0.shape[i])
            for i in range(self.__d))
        self.__Main(x, y, x0, h_mean, h_cov, binning, bin_weight, ker_fun)
        self.__Standardize_Output()
Ejemplo n.º 3
0
 def __CV_Cov_Partition(self, x, y, x0, h, ker_fun):
     grid_shape, d = np.asarray(x0.shape[:-1]), x0.shape[-1]
     n_grid = np.prod(self.__grid_shape)
     x_displacement = (
         (x - x0.reshape(-1, d).min(axis=0)) / self.__bin_width +
         np.ones(self.__d) / 2).astype(np.int32)
     x_p = np.sum(x_displacement *
                  np.append(grid_shape[::-1].cumprod()[-2::-1], 1),
                  axis=2)
     xx_p = (x_p.repeat(x_p.shape[1], 1) * n_grid +
             np.tile(x_p, x_p.shape[1]))
     xx_p = np.delete(xx_p, np.arange(0, self.__num_pt**2,
                                      self.__num_pt + 1), 1)
     yy = np.einsum('ij,ik->ijk', y, y).reshape(self.__num_fun, -1)
     yy = np.delete(yy, np.arange(0, self.__num_pt**2, self.__num_pt + 1),
                    1)
     non_nan_value = ~np.isnan(yy).reshape(-1)
     n_real_val = non_nan_value.sum()
     xx_p = np.compress(non_nan_value, xx_p.reshape(-1))
     yy = np.compress(non_nan_value, yy.reshape(-1))
     n_train = lpr.Partition_Data_Size(n_real_val)
     random_order = np.random.permutation(n_real_val)
     train_xx, test_xx = np.split(
         xx_p.reshape(-1).take(random_order), [n_train])
     train_yy, test_yy = np.split(
         yy.reshape(-1).take(random_order), [n_train])
     bin_xx = np.bincount(train_xx, minlength=n_grid**2)
     bin_yy = np.bincount(train_xx, train_yy, minlength=n_grid**2)
     bin_xx = bin_xx.reshape(np.tile(self.__grid_shape, 2))
     bin_yy = bin_yy.reshape(np.tile(self.__grid_shape, 2))
     ssq = np.zeros(h.shape[0])
     for i in range(h.shape[0]):
         fit_y = lpr.Lpr_For_Bin([bin_yy, bin_xx],
                                 np.tile(self.__bin_width, 2),
                                 h.take(i, 0),
                                 ker_fun=ker_fun)
         ssq[i] = ((test_yy - fit_y[test_xx])**2).sum()
         if np.isnan(fit_y).any():
             ssq[i] = np.nan
     h_opt = h.take(np.nanargmin(ssq), 0)
     return ([h_opt, xx_p, yy])