openGPMP
Open Source Mathematics Package
regularizers.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  *
3  * Project
4  * _____ _____ __ __ _____
5  * / ____| __ \| \/ | __ \
6  * ___ _ __ ___ _ __ | | __| |__) | \ / | |__) |
7  * / _ \| '_ \ / _ \ '_ \| | |_ | ___/| |\/| | ___/
8  *| (_) | |_) | __/ | | | |__| | | | | | | |
9  * \___/| .__/ \___|_| |_|\_____|_| |_| |_|_|
10  * | |
11  * |_|
12  *
13  * Copyright (C) Akiel Aries, <akiel@akiel.org>, et al.
14  *
15  * This software is licensed as described in the file LICENSE, which
16  * you should have received as part of this distribution. The terms
17  * among other details are referenced in the official documentation
18  * seen here : https://akielaries.github.io/openGPMP/ along with
19  * important files seen in this project.
20  *
21  * You may opt to use, copy, modify, merge, publish, distribute
22  * and/or sell copies of the Software, and permit persons to whom
23  * the Software is furnished to do so, under the terms of the
24  * LICENSE file. As this is an Open Source effort, all implementations
25  * must be of the same methodology.
26  *
27  *
28  *
29  * This software is distributed on an AS IS basis, WITHOUT
30  * WARRANTY OF ANY KIND, either express or implied.
31  *
32  ************************************************************************/
33 
34 #ifndef REGULARIZERS_HPP
35 #define REGULARIZERS_HPP
36 
37 #include <vector>
38 
39 namespace gpmp {
40 
41 namespace ml {
42 
43 class Regularize {
44  public:
51  static double l1_regularization(const std::vector<double> &weights,
52  double lambda);
53 
60  static double l2_regularization(const std::vector<double> &weights,
61  double lambda);
62 
70  static double elastic_net_regularization(const std::vector<double> &weights,
71  double lambda1,
72  double lambda2);
73 
80  static double dropout_regularization(double dropout_rate, int num_neurons);
81 
91  static bool early_stopping(double current_val_loss,
92  double &best_val_loss,
93  int patience,
94  int epoch);
95 
101  static std::vector<double>
102  ensemble_predictions(const std::vector<std::vector<double>> &predictions);
103 
109  static void max_norm_regularization(std::vector<double> &weights,
110  double max_norm);
111 
117  static void weight_decay_regularization(std::vector<double> &weights,
118  double lambda);
119 
128  static std::vector<std::vector<double>>
129  batch_normalization(const std::vector<std::vector<double>> &input_data,
130  double epsilon = 1e-5,
131  double scale = 1.0,
132  double shift = 0.0);
133 
141  static std::vector<std::vector<double>>
142  data_augmentation(const std::vector<std::vector<double>> &input_data,
143  int augmentation_factor);
144 };
145 
146 } // namespace ml
147 
148 } // namespace gpmp
149 
150 #endif
static double l2_regularization(const std::vector< double > &weights, double lambda)
Computes L2 regularization penalty (Ridge regression)
static std::vector< double > ensemble_predictions(const std::vector< std::vector< double >> &predictions)
Combines predictions from multiple models using ensembling.
static void max_norm_regularization(std::vector< double > &weights, double max_norm)
Applies max norm regularization to the weights.
static std::vector< std::vector< double > > data_augmentation(const std::vector< std::vector< double >> &input_data, int augmentation_factor)
Applies data augmentation to the input data.
static std::vector< std::vector< double > > batch_normalization(const std::vector< std::vector< double >> &input_data, double epsilon=1e-5, double scale=1.0, double shift=0.0)
Applies batch normalization to the input data.
static double elastic_net_regularization(const std::vector< double > &weights, double lambda1, double lambda2)
Computes Elastic Net regularization penalty.
static double l1_regularization(const std::vector< double > &weights, double lambda)
Computes L1 regularization penalty (Lasso regression)
static double dropout_regularization(double dropout_rate, int num_neurons)
Computes Dropout regularization penalty.
static void weight_decay_regularization(std::vector< double > &weights, double lambda)
Applies weight decay regularization to the weights.
static bool early_stopping(double current_val_loss, double &best_val_loss, int patience, int epoch)
Performs early stopping based on validation loss.
The source C++ openGPMP namespace.