|
| 1 | +/* |
| 2 | + * Copyright (C) 2019 Swift Navigation Inc. |
| 3 | + * Contact: Swift Navigation <[email protected]> |
| 4 | + * |
| 5 | + * This source is subject to the license found in the file 'LICENSE' which must |
| 6 | + * be distributed together with this source. All other rights reserved. |
| 7 | + * |
| 8 | + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, |
| 9 | + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED |
| 10 | + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | + */ |
| 12 | + |
| 13 | +#ifndef ALBATROSS_SRC_MODELS_NULL_MODEL_HPP_ |
| 14 | +#define ALBATROSS_SRC_MODELS_NULL_MODEL_HPP_ |
| 15 | + |
| 16 | +namespace albatross { |
| 17 | + |
| 18 | +class NullModel; |
| 19 | + |
| 20 | +template <> struct Fit<NullModel> { |
| 21 | + template <typename Archive> |
| 22 | + void serialize(Archive &archive, const std::uint32_t){}; |
| 23 | + |
| 24 | + bool operator==(const Fit<NullModel> &other) const { return true; } |
| 25 | +}; |
| 26 | + |
| 27 | +class NullModel : public ModelBase<NullModel> { |
| 28 | + |
| 29 | +public: |
| 30 | + NullModel(){}; |
| 31 | + NullModel(const ParameterStore ¶m_store) : params_(param_store){}; |
| 32 | + |
| 33 | + std::string get_name() const { return "null_model"; }; |
| 34 | + |
| 35 | + /* |
| 36 | + * The Gaussian Process Regression model derives its parameters from |
| 37 | + * the covariance functions. |
| 38 | + */ |
| 39 | + ParameterStore get_params() const override { return params_; } |
| 40 | + |
| 41 | + void unchecked_set_param(const std::string &name, |
| 42 | + const Parameter ¶m) override { |
| 43 | + params_[name] = param; |
| 44 | + } |
| 45 | + |
| 46 | + // If the implementing class doesn't have a fit method for this |
| 47 | + // FeatureType but the CovarianceFunction does. |
| 48 | + template <typename FeatureType> |
| 49 | + Fit<NullModel> _fit_impl(const std::vector<FeatureType> &features, |
| 50 | + const MarginalDistribution &targets) const { |
| 51 | + return {}; |
| 52 | + } |
| 53 | + |
| 54 | + template <typename FeatureType> |
| 55 | + auto fit_from_prediction(const std::vector<FeatureType> &features, |
| 56 | + const JointDistribution &prediction) const { |
| 57 | + const NullModel m(*this); |
| 58 | + FitModel<NullModel, Fit<NullModel>> fit_model(m, Fit<NullModel>()); |
| 59 | + return fit_model; |
| 60 | + } |
| 61 | + |
| 62 | + template <typename FeatureType> |
| 63 | + JointDistribution |
| 64 | + _predict_impl(const std::vector<FeatureType> &features, |
| 65 | + const Fit<NullModel> &fit, |
| 66 | + PredictTypeIdentity<JointDistribution> &&) const { |
| 67 | + const Eigen::Index n = static_cast<Eigen::Index>(features.size()); |
| 68 | + const Eigen::VectorXd mean = Eigen::VectorXd::Zero(n); |
| 69 | + const Eigen::MatrixXd cov = 1.e4 * Eigen::MatrixXd::Identity(n, n); |
| 70 | + return JointDistribution(mean, cov); |
| 71 | + } |
| 72 | + |
| 73 | + template <typename FeatureType> |
| 74 | + MarginalDistribution |
| 75 | + _predict_impl(const std::vector<FeatureType> &features, |
| 76 | + const Fit<NullModel> &fit, |
| 77 | + PredictTypeIdentity<MarginalDistribution> &&) const { |
| 78 | + const Eigen::Index en = static_cast<Eigen::Index>(features.size()); |
| 79 | + const Eigen::VectorXd mean = Eigen::VectorXd::Zero(en); |
| 80 | + const Eigen::VectorXd diag = 1.e4 * Eigen::VectorXd::Ones(en); |
| 81 | + return MarginalDistribution(mean, diag.asDiagonal()); |
| 82 | + } |
| 83 | + |
| 84 | +private: |
| 85 | + ParameterStore params_; |
| 86 | +}; |
| 87 | + |
| 88 | +} // namespace albatross |
| 89 | + |
| 90 | +#endif /* THIRD_PARTY_ALBATROSS_INCLUDE_ALBATROSS_SRC_MODELS_NULL_MODEL_HPP_ \ |
| 91 | + */ |
0 commit comments