MeLOn
gp.h
Go to the documentation of this file.
1 /**********************************************************************************
2 * Copyright (c) 2020 Process Systems Engineering (AVT.SVT), RWTH Aachen University
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License 2.0 which is available at
6 * http://www.eclipse.org/legal/epl-2.0.
7 *
8 * SPDX-License-Identifier: EPL-2.0
9 *
10 * @file gp.h
11 *
12 * @brief File containing declaration of the Gaussian process class.
13 *
14 **********************************************************************************/
15 
16 #pragma once
17 
18 #include <vector> // std::vector
19 #include <cmath> // std::tanh std::pow
20 #include <string> // std::stoi
21 #include <utility> // std::pair, std::make_pair
22 #include <memory> // std::shared_ptr, std::unique_ptr, std::make_shared, std::make_unique, std::dynamic_pointer_cast
23 #include <algorithm> // std::min_element, std::max_element, std::max
24 
25 #include "vectorarithmetics.h"
26 #include "matern.h"
27 #include "exceptions.h"
28 #include "MeLOn.h"
29 #include "gpData.h"
30 #include "gpParser.h"
31 
32 namespace melon {
33 
40  template<typename T>
41  class GaussianProcess : public MelonModel<T> {
42  private:
43 
44  std::shared_ptr<const GPData> _data;
45  std::unique_ptr<kernel::StationaryKernel<double, T>> _kernel;
46  std::unique_ptr<Scaler<T>> _inputScaler;
47  std::unique_ptr<Scaler<T>> _predictionScaler;
48  std::unique_ptr<Scaler<double>> _parameterScaler;
55  void _set_data_object(std::shared_ptr<const ModelData> modelData) override;
56 
62  void _set_kernel(std::shared_ptr<const GPData> data);
63 
77  template <typename RandomAccessIterator>
78  std::vector<T> _calculate_covariance_vector(std::vector<T> input, RandomAccessIterator& internalVariables, const bool fullSpace, std::vector<T>& constraints);
79 
93  template <typename RandomAccessIterator>
94  T _calculate_prediction(std::vector<T> covarianceVector, RandomAccessIterator& internalVariables, const bool fullSpace, std::vector<T>& constraints);
95 
109  template <typename RandomAccessIterator>
110  T _calculate_variance(std::vector<T> covarianceVector, RandomAccessIterator& internalVariables, const bool fullSpace, std::vector<T>& constraints);
111 
112  public:
113 
117  GaussianProcess() : MelonModel<T>(std::make_shared<GpParserFactory>()) {};
118 
124  GaussianProcess(std::string modelName) : GaussianProcess() { MelonModel<T>::load_model(modelName, MODEL_FILE_TYPE::JSON); };
125 
133  GaussianProcess(std::string modelPath, std::string modelName) : GaussianProcess() { MelonModel<T>::load_model(modelPath, modelName, MODEL_FILE_TYPE::JSON); };
134 
140  GaussianProcess(std::shared_ptr<const GPData> modelData) : GaussianProcess() { MelonModel<T>::load_model(modelData); };
141 
149  T calculate_prediction_reduced_space(std::vector<T> input);
150 
158  T calculate_variance_reduced_space(std::vector<T> input);
159 
171  T calculate_prediction_full_space(std::vector<T> input, std::vector<T> internalVariables, std::vector<T>& constraints);
172 
184  T calculate_variance_full_space(std::vector<T> input, std::vector<T> internalVariables, std::vector<T>& constraints);
185 
197  std::pair<T, T> calculate_prediction_and_variance_full_space(std::vector<T> input, std::vector<T> internalVariables, std::vector<T>& constraints);
198 
204  int get_input_dimension();
205 
212 
219 
226 
233 
245  void get_full_space_variables_prediction(unsigned int& variableNumber, std::vector<std::string>& variableNames, std::vector<std::pair<double, double>>& variableBounds);
246 
253 
265  void get_full_space_variables_variance(unsigned int& variableNumber, std::vector<std::string>& variableNames, std::vector<std::pair<double, double>>& variableBounds);
266 
273 
285  void get_full_space_variables_prediction_and_variance(unsigned int& variableNumber, std::vector<std::string>& variableNames, std::vector<std::pair<double, double>>& variableBounds);
286 
292  std::vector<double> get_observations();
293 
299  std::vector<double> get_normalized_observations() { return _data->Y; }
300 
301  };
302 
303 
305  // Set data object containing model parameters
306  template<typename T>
307  void GaussianProcess<T>::_set_data_object(std::shared_ptr<const ModelData> modelData) {
308 
309  // Downcast the ModelData pointer to a GPData pointer
310  _data = std::dynamic_pointer_cast<const GPData>(modelData);
311  if(_data == nullptr){
312  throw(MelonException(" Error while loading Gaussian process: Incorrect type of passed data object. The data object must be of type GPData."));
313  }
314 
315  _set_kernel(_data);
316 
317  _inputScaler = ScalerFactory<T>::create_scaler(_data->inputScalerData);
318  _predictionScaler = ScalerFactory<T>::create_scaler(_data->predictionScalerData);
319  _parameterScaler = ScalerFactory<double>::create_scaler(_data->predictionScalerData); // this scaler is used for double values only
320  }
321 
322 
324  // Function for setting the kernel of the Gaussian process
325  template<typename T>
326  void GaussianProcess<T>::_set_kernel(std::shared_ptr<const GPData> data) {
327  using namespace kernel;
328  const int INF = 999;
329 
330  switch(_data->matern) {
331  case 1:
332  _kernel = std::make_unique<Matern12<double, T>>(_data->kernelData);
333  break;
334  case 3:
335  _kernel = std::make_unique<Matern32<double, T>>(_data->kernelData);
336  break;
337  case 5:
338  _kernel = std::make_unique<Matern52<double, T>>(_data->kernelData);
339  break;
340  case INF:
341  _kernel = std::make_unique<MaternInf<double, T>>(_data->kernelData);
342  break;
343  default:
344  throw(MelonException(" Encountered a fatal error while setting kernel: Unkown kernel."));
345  }
346  }
347 
348 
350  // Get the dimension of the input
351  template<typename T>
354  throw MelonException(" Error: No Gaussian process loaded.");
355  }
356 
357  return _data->DX;
358  }
359 
360 
362  // Get the number of trainig data points
363  template<typename T>
366  throw MelonException(" Error: No Gaussian process loaded.");
367  }
368 
369  return _data->nX;
370  }
371 
372 
374  // Get the minimum of trainig data outputs
375  template<typename T>
378  throw MelonException(" Error: No Gaussian process loaded.");
379  }
380 
381  using std::min_element;
382 
383  double minimum_scaled = *min_element(_data->Y.begin(), _data->Y.end());
384 
385  double result = _parameterScaler->descale({ minimum_scaled }).front();
386 
387  return result;
388  }
389 
391  // Get the maximum of trainig data outputs
392  template<typename T>
395  throw MelonException(" Error: No Gaussian process loaded.");
396  }
397 
398  using std::max_element;
399 
400  double maximum_scaled = *max_element(_data->Y.begin(), _data->Y.end());
401 
402  double result = _parameterScaler->descale({maximum_scaled}).front();
403 
404  return result;
405  }
406 
407 
409  // Get the observations based on which the Gaussian process was trained and is evaluated
410  template<typename T>
411  std::vector<double> GaussianProcess<T>::get_observations() {
413  throw MelonException(" Error: No Gaussian process loaded.");
414  }
415 
416  std::vector<double> _Y;
417  for (auto y : _data->Y) {
418  _Y.push_back(_parameterScaler->descale({ y }).front());
419  }
420  return _Y;
421  }
422 
423 
425  // Calculates the prediction of the Gaussian process at a given point in reduced space mode (only network inputs are given)
426  template <typename T>
428  std::vector<T> dummyConstraints;
429  typename std::vector<T>::iterator dummyIterator;
430  try {
432  throw MelonException(" Error while calculating Gaussian process prediction: No model was loaded yet.");
433  }
434 
435  std::vector<T> covarianceVector = _calculate_covariance_vector(input, dummyIterator, false, dummyConstraints);
436  return _calculate_prediction(covarianceVector, dummyIterator, false, dummyConstraints);
437  }
438  catch (const std::exception& e) {
439  throw(MelonException(" Encountered a fatal error while calculating Gaussian process prediction. Terminating.", e));
440  }
441  catch (...) {
442  throw(MelonException(" Encountered a fatal error while calculating Gaussian process prediction. Terminating."));
443  }
444  }
445 
446 
448  // Calculates the variance of the Gaussian process at a given point in reduced space mode (only network inputs are given)
449  template <typename T>
451  std::vector<T> dummyConstraints;
452  std::vector<T> dummInternalVariables;
453  typename std::vector<T>::iterator dummyIterator;
454  try {
456  throw MelonException(" Error while calculating Gaussian process variance: No model was loaded yet.");
457  }
458 
459  std::vector<T> covarianceVector = _calculate_covariance_vector(input, dummyIterator, false, dummyConstraints);
460  return _calculate_variance(covarianceVector, dummyIterator, false, dummyConstraints);
461  }
462  catch (const std::exception& e) {
463  throw(MelonException(" Encountered a fatal error while calculating Gaussian process variance. Terminating.", e));
464  }
465  catch (...) {
466  throw(MelonException(" Encountered a fatal error while calculating Gaussian process variance. Terminating."));
467  }
468  }
469 
470 
472  // Calculates the prediction of the Gaussian process at a given point in full space mode (values for all internal variables are given and a set of constraints is returned)
473  template <typename T>
474  T GaussianProcess<T>::calculate_prediction_full_space(std::vector<T> input, std::vector<T> internalVariables, std::vector<T>& constraints) {
475  try {
477  throw MelonException(" Error while calculating Gaussian process prediction: No model was loaded yet.");
478  }
479 
480  auto internalVariablesIterator = internalVariables.begin();
481  std::vector<T> covarianceVector = _calculate_covariance_vector(input, internalVariablesIterator, true, constraints);
482  return _calculate_prediction(covarianceVector, internalVariablesIterator, true, constraints);
483  }
484  catch (const std::exception& e) {
485  throw(MelonException(" Encountered a fatal error while calculating Gaussian process prediction. Terminating.", e));
486  }
487  catch (...) {
488  throw(MelonException(" Encountered a fatal error while calculating Gaussian process prediction. Terminating."));
489  }
490  }
491 
492 
494  // Calculates the variance of the Gaussian process at a given point in full space mode (values for all internal variables are given and a set of constraints is returned)
495  template <typename T>
496  T GaussianProcess<T>::calculate_variance_full_space(std::vector<T> input, std::vector<T> internalVariables, std::vector<T>& constraints) {
497  try {
499  throw MelonException(" Error while calculating Gaussian process variance: No model was loaded yet.");
500  }
501 
502  auto internalVariablesIterator = internalVariables.begin();
503  std::vector<T> covarianceVector = _calculate_covariance_vector(input, internalVariablesIterator, true, constraints);
504  return _calculate_variance(covarianceVector, internalVariablesIterator, true, constraints);
505  }
506  catch (const std::exception& e) {
507  throw(MelonException(" Encountered a fatal error while calculating Gaussian process variance. Terminating.", e));
508  }
509  catch (...) {
510  throw(MelonException(" Encountered a fatal error while calculating Gaussian process variance. Terminating."));
511  }
512  }
513 
514 
516  // Calculates the prediction and the variance of the Gaussian process at a given point in full space mode (values for all internal variables are given and a set of constraints is returned)
517  template <typename T>
518  std::pair<T,T> GaussianProcess<T>::calculate_prediction_and_variance_full_space(std::vector<T> input, std::vector<T> internalVariables, std::vector<T>& constraints) {
519  try {
521  throw MelonException(" Error while calculating Gaussian process prediction and variance: No model was loaded yet.");
522  }
523 
524  auto internalVariablesIterator = internalVariables.begin();
525  std::vector<T> covarianceVector = _calculate_covariance_vector(input, internalVariablesIterator, true, constraints);
526  T prediction = _calculate_prediction(covarianceVector, internalVariablesIterator, true, constraints);
527  T variance = _calculate_variance(covarianceVector, internalVariablesIterator, true, constraints);
528  return std::make_pair(prediction, variance);
529  }
530  catch (const std::exception& e) {
531  throw(MelonException(" Encountered a fatal error while calculating Gaussian process prediction and variance. Terminating.", e));
532  }
533  catch (...) {
534  throw(MelonException(" Encountered a fatal error while calculating Gaussian process prediction and variance. Terminating."));
535  }
536  }
537 
538 
540  // Calculates the covariance vector of the Gaussian process for a given point
541  template <typename T>
542  template <typename RandomAccessIterator>
543  std::vector<T> GaussianProcess<T>::_calculate_covariance_vector(std::vector<T> input, RandomAccessIterator& internalVariables, const bool fullSpace, std::vector<T>& constraints) {
544 
545  // ---------------------------------------------------------------------------------
546  // 0: Check input dimensions
547  // ---------------------------------------------------------------------------------
548 
549  if (input.size() != _data->DX) {
550  throw MelonException(" Error while calculating covariance vector: Incorrect input dimension. In reduced space mode evaluation the size of the variables vector must be equal to the input dimension of the gaussian process.");
551  }
552 
553  // ---------------------------------------------------------------------------------
554  // 1: Normalize inputs
555  // ---------------------------------------------------------------------------------
556 
557  std::vector<T> normalizedInput = _inputScaler->scale(input);
558  if (fullSpace) {
559  MelonModel<T>::_set_constraints(constraints, normalizedInput, internalVariables);
560  }
561 
562  // ---------------------------------------------------------------------------------
563  // 2: Calculate covariance vector
564  // ---------------------------------------------------------------------------------
565 
566  std::vector<T> covarianceVector(_data->nX, 0);
567  for (std::vector<int>::size_type h = 0; h != _data->nX; h++) { // h the row of X, column of the covariance function between X and X_test
568  T distance = _kernel->calculate_distance(_data->X[h], normalizedInput);
569  if (fullSpace) {
570  MelonModel<T>::_set_constraints(constraints, distance, internalVariables);
571  }
572 
573  covarianceVector.at(h) = _kernel->evaluate_kernel(distance);
574  if (fullSpace) {
575  MelonModel<T>::_set_constraints(constraints, covarianceVector.at(h), internalVariables);
576  }
577  }
578 
579  return covarianceVector;
580  }
581 
582 
584  // Calculates the prediction of the Gaussian process for a given point
585  template <typename T>
586  template <typename RandomAccessIterator>
587  T GaussianProcess<T>::_calculate_prediction(std::vector<T> covarianceVector, RandomAccessIterator& internalVariables, const bool fullSpace, std::vector<T>& constraints) {
588 
589  // result_scaled = meanfunction + k_x_x * invK * (Y - meanfunction);
590  std::vector<double> result_scaled;
591  std::vector<double> observationDeviations = _data->Y - _data->meanfunction;
592  result_scaled = _data->invK * observationDeviations;
593  T predictionDeviation = dot_product(covarianceVector, result_scaled);
594 
595  T result_scaled_t = predictionDeviation + _data->meanfunction;
596  if (fullSpace) {
597  MelonModel<T>::_set_constraints(constraints, result_scaled_t, internalVariables);
598  }
599 
600  // denormalization: result = MeanOfOutput + stdOfOutput * reslut_scaled
601  T result = _predictionScaler->descale({ result_scaled_t }).front();
602  if (fullSpace) {
603  MelonModel<T>::_set_constraints(constraints, result, internalVariables);
604  }
605 
606  return result;
607  };
608 
609 
611  // Calculates the variance of the Gaussian process for a given point
612  template <typename T>
613  template <typename RandomAccessIterator>
614  T GaussianProcess<T>::_calculate_variance(std::vector<T> covarianceVector, RandomAccessIterator& internalVariables, const bool fullSpace, std::vector<T>& constraints) {
615 
616  // transpose the covariance function between X and X_test
617  std::vector<T> ki_v = _data->invK * covarianceVector;
618  T ki = dot_product(covarianceVector, ki_v);
619  T normalizedResult = _data->K.at(0).at(0) - ki;
620  if (fullSpace) {
621  MelonModel<T>::_set_constraints(constraints, normalizedResult, internalVariables);
622  }
623 
624  T result = normalizedResult * pow(_data->stdOfOutput, 2); // scaling variance
625  using std::max;
626  result = max(result, 1e-16); // Variance is always nonnegative. However, due to numerical issues in GP training (e.g., poor coditioning of K and inverse of K), we need max operator here.
627  if (fullSpace) {
628  MelonModel<T>::_set_constraints(constraints, result, internalVariables);
629  }
630 
631  return result;
632  }
633 
634 
636  // Get the number of internal variables used in the calculation of the prediction
637  template <typename T>
640  throw MelonException(" Error: No Gaussian process loaded.");
641  }
642 
643  unsigned int variableNumber;
644  std::vector<std::string> dummyVariableNames;
645  std::vector<std::pair<double, double>> dummyVariableBounds;
646 
647  get_full_space_variables_prediction(variableNumber, dummyVariableNames, dummyVariableBounds);
648 
649  return variableNumber;
650  }
651 
652 
654  // Get the properties of internal variables used in the calculation of the prediction
655  template <typename T>
656  void GaussianProcess<T>::get_full_space_variables_prediction(unsigned int& variableNumber, std::vector<std::string>& variableNames, std::vector<std::pair<double,double>>& variableBounds) {
658  throw MelonException(" Error: No Gaussian process loaded.");
659  }
660 
661  const double MAX_BOUND = 10e6;
662  variableNumber = 0;
663  variableNames.clear();
664  variableBounds.clear();
665 
666  variableNumber += _data->DX;
667  for (size_t i = 0; i < _data->DX; i++) {
668  variableNames.push_back("normalized_input_" + std::to_string(i));
669  variableBounds.push_back(std::make_pair(-1, 1));
670  }
671 
672  variableNumber += 2*_data->nX;
673  for (size_t i = 0; i < _data->nX; i++) {
674  variableNames.push_back("squared_distance_" + std::to_string(i));
675  variableBounds.push_back(std::make_pair(0., MAX_BOUND));
676 
677  variableNames.push_back("covariance_" + std::to_string(i));
678  variableBounds.push_back(std::make_pair(0., MAX_BOUND));
679  }
680 
681  variableNumber += 1;
682  variableNames.push_back("normalized_prediction");
683  variableBounds.push_back(std::make_pair(-MAX_BOUND, MAX_BOUND));
684 
685  variableNumber += 1;
686  variableNames.push_back("prediction");
687  variableBounds.push_back(std::make_pair(-MAX_BOUND, MAX_BOUND));
688  }
689 
690 
692  // Get the number of internal variables used in the calculation of the variance
693  template <typename T>
696  throw MelonException(" Error: No Gaussian process loaded.");
697  }
698 
699  unsigned int variableNumber;
700  std::vector<std::string> dummyVariableNames;
701  std::vector<std::pair<double, double>> dummyVariableBounds;
702 
703  get_full_space_variables_variance(variableNumber, dummyVariableNames, dummyVariableBounds);
704 
705  return variableNumber;
706  }
707 
708 
710  // Get the properties of internal variables used in the calculation of the variance
711  template <typename T>
712  void GaussianProcess<T>::get_full_space_variables_variance(unsigned int& variableNumber, std::vector<std::string>& variableNames, std::vector<std::pair<double, double>>& variableBounds) {
714  throw MelonException(" Error: No Gaussian process loaded.");
715  }
716 
717  const double MAX_BOUND = 10e6;
718  variableNumber = 0;
719  variableNames.clear();
720  variableBounds.clear();
721 
722  variableNumber += _data->DX;
723  for (size_t i = 0; i < _data->DX; i++) {
724  variableNames.push_back("normalized_input_" + std::to_string(i));
725  variableBounds.push_back(std::make_pair(-1, 1));
726  }
727 
728  variableNumber += 2 * _data->nX;
729  for (size_t i = 0; i < _data->nX; i++) {
730  variableNames.push_back("squared_distance_" + std::to_string(i));
731  variableBounds.push_back(std::make_pair(0., MAX_BOUND));
732 
733  variableNames.push_back("covariance_" + std::to_string(i));
734  variableBounds.push_back(std::make_pair(0., MAX_BOUND));
735  }
736 
737  variableNumber += 1;
738  variableNames.push_back("normalized_variance");
739  variableBounds.push_back(std::make_pair(0.0, MAX_BOUND));
740 
741  variableNumber += 1;
742  variableNames.push_back("variance");
743  variableBounds.push_back(std::make_pair(1e-16, MAX_BOUND));
744  }
745 
746 
748  // Get the number of internal variables used in the calculation of the prediction
749  template <typename T>
752  throw MelonException(" Error: No Gaussian process loaded.");
753  }
754 
755  unsigned int variableNumber;
756  std::vector<std::string> dummyVariableNames;
757  std::vector<std::pair<double, double>> dummyVariableBounds;
758 
759  get_full_space_variables_prediction_and_variance(variableNumber, dummyVariableNames, dummyVariableBounds);
760 
761  return variableNumber;
762  }
763 
764 
766  // Get the properties of internal variables used in the calculation of prediction and variance
767  template <typename T>
768  void GaussianProcess<T>::get_full_space_variables_prediction_and_variance(unsigned int& variableNumber, std::vector<std::string>& variableNames, std::vector<std::pair<double, double>>& variableBounds) {
770  throw MelonException(" Error: No Gaussian process loaded."); }
771 
772  const double MAX_BOUND = 10e6;
773  variableNumber = 0;
774  variableNames.clear();
775  variableBounds.clear();
776 
777  variableNumber += _data->DX;
778  for (size_t i = 0; i < _data->DX; i++) {
779  variableNames.push_back("normalized_input_" + std::to_string(i));
780  variableBounds.push_back(std::make_pair(-1, 1));
781  }
782 
783  variableNumber += 2 * _data->nX;
784  for (size_t i = 0; i < _data->nX; i++) {
785  variableNames.push_back("squared_distance_" + std::to_string(i));
786  variableBounds.push_back(std::make_pair(0., MAX_BOUND));
787 
788  variableNames.push_back("covariance_" + std::to_string(i));
789  variableBounds.push_back(std::make_pair(0., MAX_BOUND));
790  }
791 
792  variableNumber += 1;
793  variableNames.push_back("normalized_prediction");
794  variableBounds.push_back(std::make_pair(-MAX_BOUND, MAX_BOUND));
795 
796  variableNumber += 1;
797  variableNames.push_back("prediction");
798  variableBounds.push_back(std::make_pair(-MAX_BOUND, MAX_BOUND));
799 
800  variableNumber += 1;
801  variableNames.push_back("normalized_variance");
802  variableBounds.push_back(std::make_pair(0.0, MAX_BOUND));
803 
804  variableNumber += 1;
805  variableNames.push_back("variance");
806  variableBounds.push_back(std::make_pair(1e-16, MAX_BOUND));
807  }
808 }
809 
melon::GaussianProcess::calculate_prediction_full_space
T calculate_prediction_full_space(std::vector< T > input, std::vector< T > internalVariables, std::vector< T > &constraints)
Calculates the prediction of the Gaussian process at a given point in full space mode (values for all...
Definition: gp.h:487
melon::GaussianProcess::get_full_space_variables_variance
void get_full_space_variables_variance(unsigned int &variableNumber, std::vector< std::string > &variableNames, std::vector< std::pair< double, double >> &variableBounds)
Get the properties of internal variables used in the calculation of the variance.
Definition: gp.h:725
exceptions.h
melon::GaussianProcess::get_full_space_variables_prediction
void get_full_space_variables_prediction(unsigned int &variableNumber, std::vector< std::string > &variableNames, std::vector< std::pair< double, double >> &variableBounds)
Get the properties of internal variables used in the calculation of the prediction.
Definition: gp.h:669
melon::MelonModel
Definition: MeLOn.h:45
melon::GaussianProcess::calculate_variance_full_space
T calculate_variance_full_space(std::vector< T > input, std::vector< T > internalVariables, std::vector< T > &constraints)
Calculates the variance of the Gaussian process at a given point in full space mode (values for all i...
Definition: gp.h:509
vectorarithmetics.h
melon::GaussianProcess::GaussianProcess
GaussianProcess()
Default Constructor.
Definition: gp.h:130
melon::dot_product
auto dot_product(const std::vector< T > &v1, const std::vector< U > &v2)
Overloaded operator for vector class allowing the calulation of dot product of two vectors.
Definition: vectorarithmetics.h:168
MeLOn.h
melon::GaussianProcess::get_number_of_full_space_variables_prediction
unsigned int get_number_of_full_space_variables_prediction()
Get the number of internal variables used in the calculation of the prediction.
Definition: gp.h:651
melon::GaussianProcess::get_number_of_full_space_variables_variance
unsigned int get_number_of_full_space_variables_variance()
Get the number of internal variables used in the calculation of the variance.
Definition: gp.h:707
gpData.h
melon::GaussianProcess::get_maximum_of_training_data_outputs
double get_maximum_of_training_data_outputs()
Get the maximum value of the training data outputs.
Definition: gp.h:406
melon::GaussianProcess::get_observations
std::vector< double > get_observations()
Get the observations based on which the Gaussian process was trained and is evaluated.
Definition: gp.h:424
melon::GaussianProcess::_kernel
std::unique_ptr< kernel::StationaryKernel< double, T > > _kernel
Definition: gp.h:58
melon::GaussianProcess::_set_data_object
void _set_data_object(std::shared_ptr< const ModelData > modelData) override
Sets data object containing model parameters.
Definition: gp.h:320
melon::GaussianProcess::get_normalized_observations
std::vector< double > get_normalized_observations()
Returns the the normalized values of the observations based on which the Gaussian process was trained...
Definition: gp.h:312
melon::GaussianProcess::get_number_of_full_space_variables_prediction_and_variance
unsigned int get_number_of_full_space_variables_prediction_and_variance()
Get the number of internal variables used in the calculation of prediction and variance.
Definition: gp.h:763
melon::GaussianProcess::get_input_dimension
int get_input_dimension()
Get the dimesnion of the input.
Definition: gp.h:365
melon::MelonModel::_modelLoaded
bool _modelLoaded
Definition: MeLOn.h:94
gpParser.h
melon::GaussianProcess::_calculate_variance
T _calculate_variance(std::vector< T > covarianceVector, RandomAccessIterator &internalVariables, const bool fullSpace, std::vector< T > &constraints)
Calculates the variance of the Gaussian process for a given point.
Definition: gp.h:627
melon::GaussianProcess::_inputScaler
std::unique_ptr< Scaler< T > > _inputScaler
Definition: gp.h:59
melon::GaussianProcess::_predictionScaler
std::unique_ptr< Scaler< T > > _predictionScaler
Definition: gp.h:60
melon::MelonModel::load_model
void load_model(std::string modelName, MODEL_FILE_TYPE fileType)
Loads new model from file.
Definition: MeLOn.h:127
melon::GaussianProcess::_calculate_covariance_vector
std::vector< T > _calculate_covariance_vector(std::vector< T > input, RandomAccessIterator &internalVariables, const bool fullSpace, std::vector< T > &constraints)
Calculates the covariance vector of the Gaussian process for a given point.
Definition: gp.h:556
melon::GaussianProcess::_calculate_prediction
T _calculate_prediction(std::vector< T > covarianceVector, RandomAccessIterator &internalVariables, const bool fullSpace, std::vector< T > &constraints)
Calculates the prediction of the Gaussian process for a given point.
Definition: gp.h:600
matern.h
melon::GaussianProcess::calculate_prediction_and_variance_full_space
std::pair< T, T > calculate_prediction_and_variance_full_space(std::vector< T > input, std::vector< T > internalVariables, std::vector< T > &constraints)
Calculates the prediction and the variance of the Gaussian process at a given point in full space mod...
Definition: gp.h:531
melon::GaussianProcess::get_full_space_variables_prediction_and_variance
void get_full_space_variables_prediction_and_variance(unsigned int &variableNumber, std::vector< std::string > &variableNames, std::vector< std::pair< double, double >> &variableBounds)
Get the properties of internal variables used in the calculation of prediction and variance.
Definition: gp.h:781
melon::GaussianProcess::calculate_prediction_reduced_space
T calculate_prediction_reduced_space(std::vector< T > input)
Calculates the prediction of the Gaussian process at a given point in reduced space mode (only networ...
Definition: gp.h:440
MelonException
This class defines the exceptions thrown by FeedForwardNet.
Definition: exceptions.h:32
melon::JSON
@ JSON
Definition: modelParser.h:46
melon::GaussianProcess::_set_kernel
void _set_kernel(std::shared_ptr< const GPData > data)
Function for setting the kernel of the Gaussian process.
Definition: gp.h:339
melon::MelonModel::MelonModel
MelonModel(std::shared_ptr< ModelParserFactory > parserFactory)
Constructor.
Definition: MeLOn.h:102
melon::GaussianProcess::_parameterScaler
std::unique_ptr< Scaler< double > > _parameterScaler
Definition: gp.h:61
melon::GaussianProcess::_data
std::shared_ptr< const GPData > _data
Definition: gp.h:57
melon::GaussianProcess::calculate_variance_reduced_space
T calculate_variance_reduced_space(std::vector< T > input)
Calculates the variance of the Gaussian process at a given point in reduced space mode (only network ...
Definition: gp.h:463
melon
Definition: kernel.h:21
melon::ScalerFactory::create_scaler
static std::unique_ptr< Scaler< T > > create_scaler(const std::shared_ptr< const ScalerData > scalerData)
Factory function for creating a instance of a scaler object.
Definition: scaler.h:221
melon::MelonModel::_set_constraints
void _set_constraints(std::vector< T > &constraints, std::vector< T > &constraintEvaluation, RandomAccessIterator &constraintValue)
Sets constraints required for fullspace opimization.
Definition: MeLOn.h:178
melon::GaussianProcess::get_number_of_training_data_points
int get_number_of_training_data_points()
Get the number of training data points.
Definition: gp.h:377
melon::GaussianProcess::get_minimum_of_training_data_outputs
double get_minimum_of_training_data_outputs()
Get the minimum value of the training data outputs.
Definition: gp.h:389