Ejemplo n.º 1
0
    def predict(self):
        pred_seq_y = np.zeros_like(self.test_y_data)
        # initialization
        outx_table = data_processing.image_to_table(
            self.test_y_data[0, :, :],
            (self.G_lats - self.G_lats.mean()) / self.G_lats.std(),
            (self.G_lons - self.G_lons.mean()) / self.G_lons.std(),
            (((self.yday_list[0]) % 365) / 365))
        for var, data in self.test_xm_data.items():
            xm_img = data_processing.resolution_downward(
                data[0, :, :], self.M_lats, self.M_lons, self.G_lats,
                self.G_lons)
            outx_table = np.concatenate(
                (outx_table, xm_img.reshape(np.prod(xm_img.shape))), 1)

        for var, data in self.test_xme_data.items():
            xme_img = data_processing.resolution_downward(
                data[0, :, :], self.Mete_lats, self.Mete_lons, self.G_lats,
                self.G_lons)
            outx_table = np.concatenate(
                (outx_table, xme_img.reshape(np.prod(xme_img.shape))), 1)
        # predict step by step
        for i, day in enumerate(self.yday_list):
            pred_y_flat = self.model.predict_on_batch(outx_table)
            prev_g_image = pred_y_flat.reshape(self.test_y_data.shape[1:])
            if i != len(self.yday_list) - 1:
                outx_table = data_processing.image_to_table(
                    prev_g_image,
                    (self.G_lats - self.G_lats.mean()) / self.G_lats.std(),
                    (self.G_lons - self.G_lons.mean()) / self.G_lons.std(),
                    ((day + 1 % 365) / 365))
                for var, data in self.test_xm_data.items():
                    xm_img = data_processing.resolution_downward(
                        data[i + 1, :, :], self.M_lats, self.M_lons,
                        self.G_lats, self.G_lons)
                    outx_table = np.concatenate(
                        (outx_table, xm_img.reshape(np.prod(xm_img.shape))), 1)

                for var, data in self.test_xme_data.items():
                    xme_img = data_processing.resolution_downward(
                        data[i + 1, :, :], self.Mete_lats, self.Mete_lons,
                        self.G_lats, self.G_lons)
                    outx_table = np.concatenate(
                        (outx_table, xme_img.reshape(np.prod(xme_img.shape))),
                        1)
            pred_seq_y[i, :, :] = prev_g_image
        seq_RMSE_mat, seq_R2_mat = self._evaluate(pred_seq_y, self.test_y_data)
        np.save('seq_RMSE_mat', seq_RMSE_mat)
        np.save('seq_R2_mat', seq_R2_mat)
        pred_seq_y.dump('seq_pred_y')
        self.test_y_data.dump('true_y')
Ejemplo n.º 2
0
    def _generator(self, xg_data, xm_data, xme_data, yg_data, day_list):
        while True:
            for i, day in enumerate(day_list):
                permutation = np.random.permutation(np.prod(yg_data[i].shape))
                outx_table = data_processing.image_to_table(
                    xg_data[i, :, :],
                    (self.G_lats - self.G_lats.mean()) / self.G_lats.std(),
                    (self.G_lons - self.G_lons.mean()) / self.G_lons.std(),
                    (day % 365) / 365)
                for var, data in xm_data.items():
                    xm_img = data_processing.resolution_downward(
                        data[i, :, :], self.M_lats, self.M_lons, self.G_lats,
                        self.G_lons)
                    outx_table = np.concatenate(
                        (outx_table, xm_img.reshape(
                            (np.prod(xm_img.shape), 1))), 1)

                for var, data in xme_data.items():
                    xme_img = data_processing.resolution_downward(
                        data[i, :, :], self.Mete_lats, self.Mete_lons,
                        self.G_lats, self.G_lons)
                    outx_table = np.concatenate(
                        (outx_table,
                         xme_img.reshape((np.prod(xme_img.shape), 1))), 1)
                outy = yg_data[i].reshape((np.prod(yg_data[i].shape), 1))
                yield outx_table[permutation], outy[permutation]
Ejemplo n.º 3
0
    def _flatten(self, xg_data, xm_data, xme_data, yg_data, day_list):
        permut = np.random.permutation(np.prod(xg_data.shape))
        x = np.zeros((np.prod(xg_data.shape),
                      4 + len(self.merra_var) + len(self.mete_var)))
        y = np.zeros((np.prod(xg_data.shape), 1))
        for i, day in enumerate(day_list):
            outx_table = data_processing.image_to_table(
                xg_data[i, :, :],
                (self.G_lats - self.G_lats.mean()) / self.G_lats.std(),
                (self.G_lons - self.G_lons.mean()) / self.G_lons.std(),
                (day % 365) / 365)
            for var, data in xm_data.items():
                if var in self.merra_var:
                    xm_img = data_processing.resolution_downward(
                        data[i, :, :], self.M_lats, self.M_lons, self.G_lats,
                        self.G_lons)
                    outx_table = np.concatenate(
                        (outx_table, xm_img.reshape(
                            (np.prod(xm_img.shape), 1))), 1)

            for var, data in xme_data.items():
                if var in self.mete_var:
                    xme_img = data_processing.resolution_downward(
                        data[i, :, :], self.Mete_lats, self.Mete_lons,
                        self.G_lats, self.G_lons)
                    outx_table = np.concatenate(
                        (outx_table,
                         xme_img.reshape((np.prod(xme_img.shape), 1))), 1)
            outy = yg_data[i].reshape((np.prod(yg_data[i].shape), 1))
            x[i * np.prod(yg_data[i].shape):(i + 1) *
              np.prod(yg_data[i].shape)] = outx_table
            y[i * np.prod(yg_data[i].shape):(i + 1) *
              np.prod(yg_data[i].shape)] = outy
        return x[permut], y[permut]
Ejemplo n.º 4
0
 def predict(self):
     pred_y = self.model.predict(self.test_x_data)
     pred_y = pred_y.reshape(self.test_y_data_3d.shape)
     RMSE_mat, R2_mat = self.evaluate(pred_y, self.test_y_data_3d)
     np.save('RMSE_mat', RMSE_mat)
     np.save('R2_mat', R2_mat)
     # TODO step-by-step predict
     pred_seq_y = np.zeros_like(self.test_y_data_3d)
     prev_image = self.test_x_data_3d[0, :, :]
     for i in range(len(self.test_index[1:])):
         input_x_data = data_processing.image_to_table(
             prev_image, self.G_lats, self.G_lons,
             (self.test_index[i + 1] % 365) / 365)
         pred_seq_sub_y = self.model.predict_on_batch(input_x_data)
         prev_image = pred_seq_sub_y.reshape(prev_image.shape)
         pred_seq_y[i, :, :] = prev_image
     seq_RMSE_mat, seq_R2_mat = self.evaluate(pred_seq_y,
                                              self.test_y_data_3d)
     np.save('seq_RMSE_mat', seq_RMSE_mat)
     np.save('seq_R2_mat', seq_R2_mat)
     np.save('seq_pred_y', pred_seq_y)
     np.save('true_y', self.test_y_data_3d)
 def predict(self):
     if self.split_type == 'random_split':
         pred_y = self.model.predict(self.test_x_data)
         pred_y = pred_y.reshape(self.test_y_data_3d.shape)
         RMSE_mat, R2_mat = self.evaluate(pred_y, self.test_y_data_3d)
         np.save('RMSE_mat', RMSE_mat)
         np.save('R2_mat', R2_mat)
     else:
         pred_y = self.model.predict(self.test_x_data)
         pred_y = pred_y.reshape(self.test_y_data_3d.shape)
         RMSE_mat, R2_mat = self.evaluate(pred_y, self.test_y_data_3d)
         np.save('RMSE_mat', RMSE_mat)
         np.save('R2_mat', R2_mat)
         # TODO step-by-step predict
         test_xg_data = self.g_data[self.test_index, :, :]
         test_xm_data = self.m_data[self.test_index, :, :]
         pred_seq_y = np.zeros_like(self.test_y_data_3d)
         prev_g_image = test_xg_data[0,:,:]
         prev_m_image = test_xm_data[0,:,:]
         for i in range(len(self.test_index[1:])):
             m_list = np.zeros((np.prod(prev_g_image.shape), 1))
             input_x_data = data_processing.image_to_table(prev_g_image, self.G_lats, self.G_lons,
                                                           (self.test_index[i + 1] % 365) / 365)
             m_list[:, 0] = data_processing.resolution_downward(prev_m_image, self.M_lats, self.M_lons,
                                                                self.G_lats, self.G_lons).\
                 reshape(np.prod(prev_g_image.shape))
             input_x_data = np.concatenate((input_x_data, m_list), 1)
             pred_seq_sub_y = self.model.predict_on_batch(input_x_data)
             prev_g_image = pred_seq_sub_y.reshape(prev_g_image.shape)
             prev_m_image = test_xm_data[i+1,:,:]
             pred_seq_y[i, :, :] = prev_g_image
         seq_RMSE_mat, seq_R2_mat = self.evaluate(pred_seq_y, self.test_y_data_3d)
         np.save('seq_RMSE_mat', seq_RMSE_mat)
         np.save('seq_R2_mat', seq_R2_mat)
         pred_seq_y.dump('seq_pred_y')
         self.test_y_data_3d.dump('true_y')