mlpack 3.4.2
diagonal_constraint.hpp
Go to the documentation of this file.
1
12#ifndef MLPACK_METHODS_GMM_DIAGONAL_CONSTRAINT_HPP
13#define MLPACK_METHODS_GMM_DIAGONAL_CONSTRAINT_HPP
14
15#include <mlpack/prereqs.hpp>
16
17namespace mlpack {
18namespace gmm {
19
24{
25 public:
27 static void ApplyConstraint(arma::mat& covariance)
28 {
29 // Save the diagonal only.
30 covariance = arma::diagmat(arma::clamp(covariance.diag(), 1e-10, DBL_MAX));
31 }
32
38 static void ApplyConstraint(arma::vec& diagCovariance)
39 {
40 // Although the covariance is already diagonal, clamp it to ensure each
41 // value is at least 1e-10.
42 diagCovariance = arma::clamp(diagCovariance, 1e-10, DBL_MAX);
43 }
44
46 template<typename Archive>
47 static void serialize(Archive& /* ar */, const unsigned int /* version */) { }
48};
49
50} // namespace gmm
51} // namespace mlpack
52
53#endif
Force a covariance matrix to be diagonal.
static void ApplyConstraint(arma::mat &covariance)
Force a covariance matrix to be diagonal.
static void ApplyConstraint(arma::vec &diagCovariance)
Apply the diagonal constraint to the given diagonal covariance matrix (which is represented as a vect...
static void serialize(Archive &, const unsigned int)
Serialize the constraint (which holds nothing, so, nothing to do).
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.