MeLOn
Loading...
Searching...
No Matches
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
32namespace 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) const;
79
93 template <typename RandomAccessIterator>
94 T _calculate_prediction(std::vector<T> covarianceVector, RandomAccessIterator& internalVariables, const bool fullSpace, std::vector<T>& constraints) const;
95
109 template <typename RandomAccessIterator>
110 T _calculate_variance(std::vector<T> covarianceVector, RandomAccessIterator& internalVariables, const bool fullSpace, std::vector<T>& constraints) const;
111
112 public:
113
117 GaussianProcess() : MelonModel<T>(std::make_shared<GpParserFactory>()) {};
118
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) const;
150
158 T calculate_variance_reduced_space(std::vector<T> input) const;
159
171 T calculate_prediction_full_space(std::vector<T> input, std::vector<T> internalVariables, std::vector<T>& constraints) const;
172
184 T calculate_variance_full_space(std::vector<T> input, std::vector<T> internalVariables, std::vector<T>& constraints) const;
185
197 std::pair<T, T> calculate_prediction_and_variance_full_space(std::vector<T> input, std::vector<T> internalVariables, std::vector<T>& constraints) const;
198
204 int get_input_dimension() const;
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) const;
246
253
265 void get_full_space_variables_variance(unsigned int& variableNumber, std::vector<std::string>& variableNames, std::vector<std::pair<double, double>>& variableBounds) const;
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) const;
286
292 std::vector<double> get_observations() const;
293
299 std::vector<double> get_normalized_observations() const { return _data->Y; }
300
304 const GPData& data() const { return *_data; };
305
310
314 const Scaler<T>& inputScaler() const { return *_inputScaler; };
315
319 const Scaler<T>& predictionScaler() const { return *_predictionScaler; };
320
324 const Scaler<T>& parameterScaler() const { return *_parameterScaler; };
325 };
326
327
329 // Set data object containing model parameters
330 template<typename T>
331 void GaussianProcess<T>::_set_data_object(std::shared_ptr<const ModelData> modelData) {
332
333 // Downcast the ModelData pointer to a GPData pointer
334 _data = std::dynamic_pointer_cast<const GPData>(modelData);
335 if(_data == nullptr){
336 throw(MelonException(" Error while loading Gaussian process: Incorrect type of passed data object. The data object must be of type GPData."));
337 }
338
339 _set_kernel(_data);
340
341 _inputScaler = ScalerFactory<T>::create_scaler(_data->inputScalerData);
342 _predictionScaler = ScalerFactory<T>::create_scaler(_data->predictionScalerData);
343 _parameterScaler = ScalerFactory<double>::create_scaler(_data->predictionScalerData); // this scaler is used for double values only
344 }
345
346
348 // Function for setting the kernel of the Gaussian process
349 template<typename T>
350 void GaussianProcess<T>::_set_kernel(std::shared_ptr<const GPData> data) {
351 using namespace kernel;
352 const int INF = 999;
353
354 switch(_data->matern) {
355 case 1:
356 _kernel = std::make_unique<Matern12<double, T>>(_data->kernelData);
357 break;
358 case 3:
359 _kernel = std::make_unique<Matern32<double, T>>(_data->kernelData);
360 break;
361 case 5:
362 _kernel = std::make_unique<Matern52<double, T>>(_data->kernelData);
363 break;
364 case INF:
365 _kernel = std::make_unique<MaternInf<double, T>>(_data->kernelData);
366 break;
367 default:
368 throw(MelonException(" Encountered a fatal error while setting kernel: Unkown kernel."));
369 }
370 }
371
372
374 // Get the dimension of the input
375 template<typename T>
378 throw MelonException(" Error: No Gaussian process loaded.");
379 }
380
381 return _data->DX;
382 }
383
384
386 // Get the number of trainig data points
387 template<typename T>
390 throw MelonException(" Error: No Gaussian process loaded.");
391 }
392
393 return _data->nX;
394 }
395
396
398 // Get the minimum of trainig data outputs
399 template<typename T>
402 throw MelonException(" Error: No Gaussian process loaded.");
403 }
404
405 using std::min_element;
406
407 double minimum_scaled = *min_element(_data->Y.begin(), _data->Y.end());
408
409 double result = _parameterScaler->descale({ minimum_scaled }).front();
410
411 return result;
412 }
413
415 // Get the maximum of trainig data outputs
416 template<typename T>
419 throw MelonException(" Error: No Gaussian process loaded.");
420 }
421
422 using std::max_element;
423
424 double maximum_scaled = *max_element(_data->Y.begin(), _data->Y.end());
425
426 double result = _parameterScaler->descale({maximum_scaled}).front();
427
428 return result;
429 }
430
431
433 // Get the observations based on which the Gaussian process was trained and is evaluated
434 template<typename T>
435 std::vector<double> GaussianProcess<T>::get_observations() const {
437 throw MelonException(" Error: No Gaussian process loaded.");
438 }
439
440 std::vector<double> _Y;
441 for (auto y : _data->Y) {
442 _Y.push_back(_parameterScaler->descale({ y }).front());
443 }
444 return _Y;
445 }
446
447
449 // Calculates the prediction of the Gaussian process at a given point in reduced space mode (only network inputs are given)
450 template <typename T>
452 std::vector<T> dummyConstraints;
453 typename std::vector<T>::iterator dummyIterator;
454 try {
456 throw MelonException(" Error while calculating Gaussian process prediction: No model was loaded yet.");
457 }
458
459 std::vector<T> covarianceVector = _calculate_covariance_vector(input, dummyIterator, false, dummyConstraints);
460 return _calculate_prediction(covarianceVector, dummyIterator, false, dummyConstraints);
461 }
462 catch (const std::exception& e) {
463 throw(MelonException(" Encountered a fatal error while calculating Gaussian process prediction. Terminating.", e));
464 }
465 catch (...) {
466 throw(MelonException(" Encountered a fatal error while calculating Gaussian process prediction. Terminating."));
467 }
468 }
469
470
472 // Calculates the variance of the Gaussian process at a given point in reduced space mode (only network inputs are given)
473 template <typename T>
475 std::vector<T> dummyConstraints;
476 std::vector<T> dummInternalVariables;
477 typename std::vector<T>::iterator dummyIterator;
478 try {
480 throw MelonException(" Error while calculating Gaussian process variance: No model was loaded yet.");
481 }
482
483 std::vector<T> covarianceVector = _calculate_covariance_vector(input, dummyIterator, false, dummyConstraints);
484 return _calculate_variance(covarianceVector, dummyIterator, false, dummyConstraints);
485 }
486 catch (const std::exception& e) {
487 throw(MelonException(" Encountered a fatal error while calculating Gaussian process variance. Terminating.", e));
488 }
489 catch (...) {
490 throw(MelonException(" Encountered a fatal error while calculating Gaussian process variance. Terminating."));
491 }
492 }
493
494
495
497 // 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)
498 template <typename T>
499 T GaussianProcess<T>::calculate_prediction_full_space(std::vector<T> input, std::vector<T> internalVariables, std::vector<T>& constraints) const {
500 try {
502 throw MelonException(" Error while calculating Gaussian process prediction: No model was loaded yet.");
503 }
504
505 auto internalVariablesIterator = internalVariables.begin();
506 std::vector<T> covarianceVector = _calculate_covariance_vector(input, internalVariablesIterator, true, constraints);
507 return _calculate_prediction(covarianceVector, internalVariablesIterator, true, constraints);
508 }
509 catch (const std::exception& e) {
510 throw(MelonException(" Encountered a fatal error while calculating Gaussian process prediction. Terminating.", e));
511 }
512 catch (...) {
513 throw(MelonException(" Encountered a fatal error while calculating Gaussian process prediction. Terminating."));
514 }
515 }
516
517
519 // 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)
520 template <typename T>
521 T GaussianProcess<T>::calculate_variance_full_space(std::vector<T> input, std::vector<T> internalVariables, std::vector<T>& constraints) const {
522 try {
524 throw MelonException(" Error while calculating Gaussian process variance: No model was loaded yet.");
525 }
526
527 auto internalVariablesIterator = internalVariables.begin();
528 std::vector<T> covarianceVector = _calculate_covariance_vector(input, internalVariablesIterator, true, constraints);
529 return _calculate_variance(covarianceVector, internalVariablesIterator, true, constraints);
530 }
531 catch (const std::exception& e) {
532 throw(MelonException(" Encountered a fatal error while calculating Gaussian process variance. Terminating.", e));
533 }
534 catch (...) {
535 throw(MelonException(" Encountered a fatal error while calculating Gaussian process variance. Terminating."));
536 }
537 }
538
539
541 // 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)
542 template <typename T>
543 std::pair<T,T> GaussianProcess<T>::calculate_prediction_and_variance_full_space(std::vector<T> input, std::vector<T> internalVariables, std::vector<T>& constraints) const {
544 try {
546 throw MelonException(" Error while calculating Gaussian process prediction and variance: No model was loaded yet.");
547 }
548
549 auto internalVariablesIterator = internalVariables.begin();
550 std::vector<T> covarianceVector = _calculate_covariance_vector(input, internalVariablesIterator, true, constraints);
551 T prediction = _calculate_prediction(covarianceVector, internalVariablesIterator, true, constraints);
552 T variance = _calculate_variance(covarianceVector, internalVariablesIterator, true, constraints);
553 return std::make_pair(prediction, variance);
554 }
555 catch (const std::exception& e) {
556 throw(MelonException(" Encountered a fatal error while calculating Gaussian process prediction and variance. Terminating.", e));
557 }
558 catch (...) {
559 throw(MelonException(" Encountered a fatal error while calculating Gaussian process prediction and variance. Terminating."));
560 }
561 }
562
563
565 // Calculates the covariance vector of the Gaussian process for a given point
566 template <typename T>
567 template <typename RandomAccessIterator>
568 std::vector<T> GaussianProcess<T>::_calculate_covariance_vector(std::vector<T> input, RandomAccessIterator& internalVariables, const bool fullSpace, std::vector<T>& constraints) const {
569
570 // ---------------------------------------------------------------------------------
571 // 0: Check input dimensions
572 // ---------------------------------------------------------------------------------
573
574 if (input.size() != _data->DX) {
575 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.");
576 }
577
578 // ---------------------------------------------------------------------------------
579 // 1: Normalize inputs
580 // ---------------------------------------------------------------------------------
581
582 std::vector<T> normalizedInput = _inputScaler->scale(input);
583 if (fullSpace) {
584 MelonModel<T>::_set_constraints(constraints, normalizedInput, internalVariables);
585 }
586
587 // ---------------------------------------------------------------------------------
588 // 2: Calculate covariance vector
589 // ---------------------------------------------------------------------------------
590
591 std::vector<T> covarianceVector(_data->nX, 0);
592 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
593 T distance = _kernel->calculate_distance(_data->X[h], normalizedInput);
594 if (fullSpace) {
595 MelonModel<T>::_set_constraints(constraints, distance, internalVariables);
596 }
597
598 covarianceVector.at(h) = _kernel->evaluate_kernel(distance);
599 if (fullSpace) {
600 MelonModel<T>::_set_constraints(constraints, covarianceVector.at(h), internalVariables);
601 }
602 }
603
604 return covarianceVector;
605 }
606
607
609 // Calculates the prediction of the Gaussian process for a given point
610 template <typename T>
611 template <typename RandomAccessIterator>
612 T GaussianProcess<T>::_calculate_prediction(std::vector<T> covarianceVector, RandomAccessIterator& internalVariables, const bool fullSpace, std::vector<T>& constraints) const {
613
614 // result_scaled = meanfunction + k_x_x * invK * (Y - meanfunction);
615 std::vector<double> result_scaled;
616 std::vector<double> observationDeviations = _data->Y - _data->meanfunction;
617 result_scaled = _data->invK * observationDeviations;
618 T predictionDeviation = dot_product(covarianceVector, result_scaled);
619
620 T result_scaled_t = predictionDeviation + _data->meanfunction;
621 if (fullSpace) {
622 MelonModel<T>::_set_constraints(constraints, result_scaled_t, internalVariables);
623 }
624
625 // denormalization: result = MeanOfOutput + stdOfOutput * reslut_scaled
626 T result = _predictionScaler->descale({ result_scaled_t }).front();
627 if (fullSpace) {
628 MelonModel<T>::_set_constraints(constraints, result, internalVariables);
629 }
630
631 return result;
632 };
633
634
636 // Calculates the variance of the Gaussian process for a given point
637 template <typename T>
638 template <typename RandomAccessIterator>
639 T GaussianProcess<T>::_calculate_variance(std::vector<T> covarianceVector, RandomAccessIterator& internalVariables, const bool fullSpace, std::vector<T>& constraints) const {
640
641 // transpose the covariance function between X and X_test
642 std::vector<T> ki_v = _data->invK * covarianceVector;
643 T ki = dot_product(covarianceVector, ki_v);
644 T normalizedResult = _data->K.at(0).at(0) - ki;
645 if (fullSpace) {
646 MelonModel<T>::_set_constraints(constraints, normalizedResult, internalVariables);
647 }
648
649 T result = normalizedResult * pow(_data->stdOfOutput, 2); // scaling variance
650 using std::max;
651 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.
652 if (fullSpace) {
653 MelonModel<T>::_set_constraints(constraints, result, internalVariables);
654 }
655
656 return result;
657 }
658
660 // Get the number of internal variables used in the calculation of the prediction
661 template <typename T>
664 throw MelonException(" Error: No Gaussian process loaded.");
665 }
666
667 unsigned int variableNumber;
668 std::vector<std::string> dummyVariableNames;
669 std::vector<std::pair<double, double>> dummyVariableBounds;
670
671 get_full_space_variables_prediction(variableNumber, dummyVariableNames, dummyVariableBounds);
672
673 return variableNumber;
674 }
675
676
678 // Get the properties of internal variables used in the calculation of the prediction
679 template <typename T>
680 void GaussianProcess<T>::get_full_space_variables_prediction(unsigned int& variableNumber, std::vector<std::string>& variableNames, std::vector<std::pair<double,double>>& variableBounds) const {
682 throw MelonException(" Error: No Gaussian process loaded.");
683 }
684
685 const double MAX_BOUND = 10e6;
686 variableNumber = 0;
687 variableNames.clear();
688 variableBounds.clear();
689
690 variableNumber += _data->DX;
691 for (size_t i = 0; i < _data->DX; i++) {
692 variableNames.push_back("normalized_input_" + std::to_string(i));
693 variableBounds.push_back(std::make_pair(-1, 1));
694 }
695
696 variableNumber += 2*_data->nX;
697 for (size_t i = 0; i < _data->nX; i++) {
698 variableNames.push_back("squared_distance_" + std::to_string(i));
699 variableBounds.push_back(std::make_pair(0., MAX_BOUND));
700
701 variableNames.push_back("covariance_" + std::to_string(i));
702 variableBounds.push_back(std::make_pair(0., MAX_BOUND));
703 }
704
705 variableNumber += 1;
706 variableNames.push_back("normalized_prediction");
707 variableBounds.push_back(std::make_pair(-MAX_BOUND, MAX_BOUND));
708
709 variableNumber += 1;
710 variableNames.push_back("prediction");
711 variableBounds.push_back(std::make_pair(-MAX_BOUND, MAX_BOUND));
712 }
713
714
716 // Get the number of internal variables used in the calculation of the variance
717 template <typename T>
720 throw MelonException(" Error: No Gaussian process loaded.");
721 }
722
723 unsigned int variableNumber;
724 std::vector<std::string> dummyVariableNames;
725 std::vector<std::pair<double, double>> dummyVariableBounds;
726
727 get_full_space_variables_variance(variableNumber, dummyVariableNames, dummyVariableBounds);
728
729 return variableNumber;
730 }
731
732
734 // Get the properties of internal variables used in the calculation of the variance
735 template <typename T>
736 void GaussianProcess<T>::get_full_space_variables_variance(unsigned int& variableNumber, std::vector<std::string>& variableNames, std::vector<std::pair<double, double>>& variableBounds) const {
738 throw MelonException(" Error: No Gaussian process loaded.");
739 }
740
741 const double MAX_BOUND = 10e6;
742 variableNumber = 0;
743 variableNames.clear();
744 variableBounds.clear();
745
746 variableNumber += _data->DX;
747 for (size_t i = 0; i < _data->DX; i++) {
748 variableNames.push_back("normalized_input_" + std::to_string(i));
749 variableBounds.push_back(std::make_pair(-1, 1));
750 }
751
752 variableNumber += 2 * _data->nX;
753 for (size_t i = 0; i < _data->nX; i++) {
754 variableNames.push_back("squared_distance_" + std::to_string(i));
755 variableBounds.push_back(std::make_pair(0., MAX_BOUND));
756
757 variableNames.push_back("covariance_" + std::to_string(i));
758 variableBounds.push_back(std::make_pair(0., MAX_BOUND));
759 }
760
761 variableNumber += 1;
762 variableNames.push_back("normalized_variance");
763 variableBounds.push_back(std::make_pair(0.0, MAX_BOUND));
764
765 variableNumber += 1;
766 variableNames.push_back("variance");
767 variableBounds.push_back(std::make_pair(1e-16, MAX_BOUND));
768 }
769
770
772 // Get the number of internal variables used in the calculation of the prediction
773 template <typename T>
776 throw MelonException(" Error: No Gaussian process loaded.");
777 }
778
779 unsigned int variableNumber;
780 std::vector<std::string> dummyVariableNames;
781 std::vector<std::pair<double, double>> dummyVariableBounds;
782
783 get_full_space_variables_prediction_and_variance(variableNumber, dummyVariableNames, dummyVariableBounds);
784
785 return variableNumber;
786 }
787
788
790 // Get the properties of internal variables used in the calculation of prediction and variance
791 template <typename T>
792 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) const {
794 throw MelonException(" Error: No Gaussian process loaded."); }
795
796 const double MAX_BOUND = 10e6;
797 variableNumber = 0;
798 variableNames.clear();
799 variableBounds.clear();
800
801 variableNumber += _data->DX;
802 for (size_t i = 0; i < _data->DX; i++) {
803 variableNames.push_back("normalized_input_" + std::to_string(i));
804 variableBounds.push_back(std::make_pair(-1, 1));
805 }
806
807 variableNumber += 2 * _data->nX;
808 for (size_t i = 0; i < _data->nX; i++) {
809 variableNames.push_back("squared_distance_" + std::to_string(i));
810 variableBounds.push_back(std::make_pair(0., MAX_BOUND));
811
812 variableNames.push_back("covariance_" + std::to_string(i));
813 variableBounds.push_back(std::make_pair(0., MAX_BOUND));
814 }
815
816 variableNumber += 1;
817 variableNames.push_back("normalized_prediction");
818 variableBounds.push_back(std::make_pair(-MAX_BOUND, MAX_BOUND));
819
820 variableNumber += 1;
821 variableNames.push_back("prediction");
822 variableBounds.push_back(std::make_pair(-MAX_BOUND, MAX_BOUND));
823
824 variableNumber += 1;
825 variableNames.push_back("normalized_variance");
826 variableBounds.push_back(std::make_pair(0.0, MAX_BOUND));
827
828 variableNumber += 1;
829 variableNames.push_back("variance");
830 variableBounds.push_back(std::make_pair(1e-16, MAX_BOUND));
831 }
832}
833
This class defines the exceptions thrown by FeedForwardNet.
Definition exceptions.h:32
This class represents a Gaussian process, to be used in the MAiNGO solver.
Definition gp.h:41
int get_input_dimension() const
Get the dimesnion of the input.
Definition gp.h:376
std::unique_ptr< Scaler< T > > _predictionScaler
Definition gp.h:47
void get_full_space_variables_prediction_and_variance(unsigned int &variableNumber, std::vector< std::string > &variableNames, std::vector< std::pair< double, double > > &variableBounds) const
Get the properties of internal variables used in the calculation of prediction and variance.
Definition gp.h:792
double get_minimum_of_training_data_outputs() const
Get the minimum value of the training data outputs.
Definition gp.h:400
const GPData & data() const
Getter for member variable _data.
Definition gp.h:304
void get_full_space_variables_prediction(unsigned int &variableNumber, std::vector< std::string > &variableNames, std::vector< std::pair< double, double > > &variableBounds) const
Get the properties of internal variables used in the calculation of the prediction.
Definition gp.h:680
std::unique_ptr< kernel::StationaryKernel< double, T > > _kernel
Definition gp.h:45
T _calculate_variance(std::vector< T > covarianceVector, RandomAccessIterator &internalVariables, const bool fullSpace, std::vector< T > &constraints) const
Calculates the variance of the Gaussian process for a given point.
Definition gp.h:639
double get_maximum_of_training_data_outputs() const
Get the maximum value of the training data outputs.
Definition gp.h:417
GaussianProcess()
Default Constructor.
Definition gp.h:117
const Scaler< T > & inputScaler() const
Getter for member variable _inputScaler.
Definition gp.h:314
const Scaler< T > & parameterScaler() const
Getter for member variable _parameterScaler.
Definition gp.h:324
void get_full_space_variables_variance(unsigned int &variableNumber, std::vector< std::string > &variableNames, std::vector< std::pair< double, double > > &variableBounds) const
Get the properties of internal variables used in the calculation of the variance.
Definition gp.h:736
unsigned int get_number_of_full_space_variables_prediction_and_variance() const
Get the number of internal variables used in the calculation of prediction and variance.
Definition gp.h:774
GaussianProcess(std::shared_ptr< const GPData > modelData)
Constructor.
Definition gp.h:140
T calculate_variance_reduced_space(std::vector< T > input) const
Calculates the variance of the Gaussian process at a given point in reduced space mode (only network ...
Definition gp.h:474
T _calculate_prediction(std::vector< T > covarianceVector, RandomAccessIterator &internalVariables, const bool fullSpace, std::vector< T > &constraints) const
Calculates the prediction of the Gaussian process for a given point.
Definition gp.h:612
std::shared_ptr< const GPData > _data
Definition gp.h:44
std::vector< double > get_normalized_observations() const
Returns the the normalized values of the observations based on which the Gaussian process was trained...
Definition gp.h:299
void _set_data_object(std::shared_ptr< const ModelData > modelData) override
Sets data object containing model parameters.
Definition gp.h:331
T calculate_variance_full_space(std::vector< T > input, std::vector< T > internalVariables, std::vector< T > &constraints) const
Calculates the variance of the Gaussian process at a given point in full space mode (values for all i...
Definition gp.h:521
int get_number_of_training_data_points() const
Get the number of training data points.
Definition gp.h:388
T calculate_prediction_reduced_space(std::vector< T > input) const
Calculates the prediction of the Gaussian process at a given point in reduced space mode (only networ...
Definition gp.h:451
T calculate_prediction_full_space(std::vector< T > input, std::vector< T > internalVariables, std::vector< T > &constraints) const
Calculates the prediction of the Gaussian process at a given point in full space mode (values for all...
Definition gp.h:499
unsigned int get_number_of_full_space_variables_variance() const
Get the number of internal variables used in the calculation of the variance.
Definition gp.h:718
std::vector< T > _calculate_covariance_vector(std::vector< T > input, RandomAccessIterator &internalVariables, const bool fullSpace, std::vector< T > &constraints) const
Calculates the covariance vector of the Gaussian process for a given point.
Definition gp.h:568
std::unique_ptr< Scaler< T > > _inputScaler
Definition gp.h:46
const kernel::StationaryKernel< double, T > & kernel() const
Getter for member variable _kernel.
Definition gp.h:309
std::vector< double > get_observations() const
Get the observations based on which the Gaussian process was trained and is evaluated.
Definition gp.h:435
std::unique_ptr< Scaler< double > > _parameterScaler
Definition gp.h:48
GaussianProcess(std::string modelPath, std::string modelName)
Constructor.
Definition gp.h:133
const Scaler< T > & predictionScaler() const
Getter for member variable _predictionScaler.
Definition gp.h:319
GaussianProcess(std::string modelName)
Constructor.
Definition gp.h:124
unsigned int get_number_of_full_space_variables_prediction() const
Get the number of internal variables used in the calculation of the prediction.
Definition gp.h:662
std::pair< T, T > calculate_prediction_and_variance_full_space(std::vector< T > input, std::vector< T > internalVariables, std::vector< T > &constraints) const
Calculates the prediction and the variance of the Gaussian process at a given point in full space mod...
Definition gp.h:543
void _set_kernel(std::shared_ptr< const GPData > data)
Function for setting the kernel of the Gaussian process.
Definition gp.h:350
This class is a factory class for creating child instances of GpParser.
Definition gpParser.h:50
Definition MeLOn.h:32
void load_model(std::string modelName, MODEL_FILE_TYPE fileType)
Loads new model from file.
Definition MeLOn.h:114
void _set_constraints(std::vector< T > &constraints, std::vector< T > &constraintEvaluation, RandomAccessIterator &constraintValue) const
Sets constraints required for fullspace opimization.
Definition MeLOn.h:165
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:208
Abstract class defining scaling algorithm.
Definition scaler.h:65
Definition kernel.h:58
Definition kernel.h:21
@ JSON
Definition modelParser.h:33
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:155
struct containing all information regarding the Gaussian process
Definition gpData.h:31