Пример #1
0
 def _cross_validate(
     self,
     search_space: SearchSpace,
     obs_feats: List[ObservationFeatures],
     obs_data: List[ObservationData],
     cv_test_points: List[ObservationFeatures],
 ) -> List[ObservationData]:
     """Make predictions at cv_test_points using only the data in obs_feats
     and obs_data.
     """
     Xs_train, Ys_train, Yvars_train, candidate_metadata = _convert_observations(
         observation_data=obs_data,
         observation_features=obs_feats,
         outcomes=self.outcomes,
         parameters=self.parameters,
     )
     search_space_digest = extract_search_space_digest(
         search_space=search_space, param_names=self.parameters
     )
     X_test = np.array(
         [[obsf.parameters[p] for p in self.parameters] for obsf in cv_test_points]
     )
     # Use the model to do the cross validation
     f_test, cov_test = self._model_cross_validate(
         Xs_train=Xs_train,
         Ys_train=Ys_train,
         Yvars_train=Yvars_train,
         X_test=X_test,
         search_space_digest=search_space_digest,
         metric_names=self.outcomes,
     )
     # Convert array back to ObservationData
     return array_to_observation_data(f=f_test, cov=cov_test, outcomes=self.outcomes)
Пример #2
0
 def _cross_validate(
     self,
     search_space: SearchSpace,
     obs_feats: List[ObservationFeatures],
     obs_data: List[ObservationData],
     cv_test_points: List[ObservationFeatures],
 ) -> List[ObservationData]:
     """Make predictions at cv_test_points using only the data in obs_feats
     and obs_data.
     """
     Xs_train, Ys_train, Yvars_train = _convert_observations(
         observation_data=obs_data,
         observation_features=obs_feats,
         outcomes=self.outcomes,
         parameters=self.parameters,
     )
     X_test = [[obsf.parameters[param] for param in self.parameters]
               for obsf in cv_test_points]
     # Use the model to do the cross validation
     f_test, cov_test = self.model.cross_validate(Xs_train=Xs_train,
                                                  Ys_train=Ys_train,
                                                  Yvars_train=Yvars_train,
                                                  X_test=X_test)
     # Convert array back to ObservationData
     return array_to_observation_data(f=f_test,
                                      cov=cov_test,
                                      outcomes=self.outcomes)
Пример #3
0
 def _predict(
     self, observation_features: List[ObservationFeatures]
 ) -> List[ObservationData]:
     X = observation_features_to_array(self.parameters, observation_features)
     f, cov = self._model_predict(X=X)
     # Convert arrays to observations
     return array_to_observation_data(f=f, cov=cov, outcomes=self.outcomes)
Пример #4
0
 def _predict(
     self, observation_features: List[ObservationFeatures]
 ) -> List[ObservationData]:
     # Convert observations to array
     X = [[of.parameters[param] for param in self.parameters]
          for of in observation_features]
     f, cov = self.model.predict(X=X)
     # Convert arrays to observations
     return array_to_observation_data(f=f, cov=cov, outcomes=self.outcomes)