commit x64 compilation from lulu cause the other branch dont seems to compile properly at home

This commit is contained in:
2026-07-17 16:08:20 +02:00
parent c0f3eeb00d
commit 0efa4ee6f7
625 changed files with 117283 additions and 4426 deletions

View File

@ -41,8 +41,8 @@
//
//M*/
#ifndef __OPENCV_ML_HPP__
#define __OPENCV_ML_HPP__
#ifndef OPENCV_ML_HPP
#define OPENCV_ML_HPP
#ifdef __cplusplus
# include "opencv2/core.hpp"
@ -104,7 +104,7 @@ enum SampleTypes
It is used for optimizing statmodel accuracy by varying model parameters, the accuracy estimate
being computed by cross-validation.
*/
class CV_EXPORTS ParamGrid
class CV_EXPORTS_W ParamGrid
{
public:
/** @brief Default constructor */
@ -112,8 +112,8 @@ public:
/** @brief Constructor with parameters */
ParamGrid(double _minVal, double _maxVal, double _logStep);
double minVal; //!< Minimum value of the statmodel parameter. Default value is 0.
double maxVal; //!< Maximum value of the statmodel parameter. Default value is 0.
CV_PROP_RW double minVal; //!< Minimum value of the statmodel parameter. Default value is 0.
CV_PROP_RW double maxVal; //!< Maximum value of the statmodel parameter. Default value is 0.
/** @brief Logarithmic step for iterating the statmodel parameter.
The grid determines the following iteration sequence of the statmodel parameter values:
@ -122,7 +122,15 @@ public:
\f[\texttt{minVal} * \texttt{logStep} ^n < \texttt{maxVal}\f]
The grid is logarithmic, so logStep must always be greater then 1. Default value is 1.
*/
double logStep;
CV_PROP_RW double logStep;
/** @brief Creates a ParamGrid Ptr that can be given to the %SVM::trainAuto method
@param minVal minimum value of the parameter grid
@param maxVal maximum value of the parameter grid
@param logstep Logarithmic step for iterating the statmodel parameter
*/
CV_WRAP static Ptr<ParamGrid> create(double minVal=0., double maxVal=0., double logstep=1.);
};
/** @brief Class encapsulating training data.
@ -190,6 +198,7 @@ public:
CV_WRAP virtual Mat getTestSampleWeights() const = 0;
CV_WRAP virtual Mat getVarIdx() const = 0;
CV_WRAP virtual Mat getVarType() const = 0;
CV_WRAP Mat getVarSymbolFlags() const;
CV_WRAP virtual int getResponseType() const = 0;
CV_WRAP virtual Mat getTrainSampleIdx() const = 0;
CV_WRAP virtual Mat getTestSampleIdx() const = 0;
@ -224,7 +233,24 @@ public:
CV_WRAP virtual void setTrainTestSplitRatio(double ratio, bool shuffle=true) = 0;
CV_WRAP virtual void shuffleTrainTest() = 0;
CV_WRAP static Mat getSubVector(const Mat& vec, const Mat& idx);
/** @brief Returns matrix of test samples */
CV_WRAP Mat getTestSamples() const;
/** @brief Returns vector of symbolic names captured in loadFromCSV() */
CV_WRAP void getNames(std::vector<String>& names) const;
/** @brief Extract from 1D vector elements specified by passed indexes.
@param vec input vector (supported types: CV_32S, CV_32F, CV_64F)
@param idx 1D index vector
*/
static CV_WRAP Mat getSubVector(const Mat& vec, const Mat& idx);
/** @brief Extract from matrix rows/cols specified by passed indexes.
@param matrix input matrix (supported types: CV_32S, CV_32F, CV_64F)
@param idx 1D index vector
@param layout specifies to extract rows (cv::ml::ROW_SAMPLES) or to extract columns (cv::ml::COL_SAMPLES)
*/
static CV_WRAP Mat getSubMatrix(const Mat& matrix, const Mat& idx, int layout);
/** @brief Reads the dataset from a .csv file and returns the ready-to-use training data.
@ -252,6 +278,8 @@ public:
@param missch The character used to specify missing measurements. It should not be a digit.
Although it's a non-numerical value, it surely does not affect the decision of whether the
variable ordered or categorical.
@note If the dataset only contains input variables and no responses, use responseStartIdx = -2
and responseEndIdx = 0. The output variables vector will just contain zeros.
*/
static Ptr<TrainData> loadFromCSV(const String& filename,
int headerLineCount,
@ -301,7 +329,7 @@ public:
/** @brief Returns the number of variables in training samples */
CV_WRAP virtual int getVarCount() const = 0;
CV_WRAP virtual bool empty() const;
CV_WRAP virtual bool empty() const CV_OVERRIDE;
/** @brief Returns true if the model is trained */
CV_WRAP virtual bool isTrained() const = 0;
@ -384,6 +412,17 @@ public:
/** Creates empty model
Use StatModel::train to train the model after creation. */
CV_WRAP static Ptr<NormalBayesClassifier> create();
/** @brief Loads and creates a serialized NormalBayesClassifier from a file
*
* Use NormalBayesClassifier::save to serialize and store an NormalBayesClassifier to disk.
* Load the NormalBayesClassifier from this file again, by calling this function with the path to the file.
* Optionally specify the node for the file containing the classifier
*
* @param filepath path to serialized NormalBayesClassifier
* @param nodeName name of node containing the classifier
*/
CV_WRAP static Ptr<NormalBayesClassifier> load(const String& filepath , const String& nodeName = String());
};
/****************************************************************************************\
@ -663,21 +702,69 @@ public:
the usual %SVM with parameters specified in params is executed.
*/
virtual bool trainAuto( const Ptr<TrainData>& data, int kFold = 10,
ParamGrid Cgrid = SVM::getDefaultGrid(SVM::C),
ParamGrid gammaGrid = SVM::getDefaultGrid(SVM::GAMMA),
ParamGrid pGrid = SVM::getDefaultGrid(SVM::P),
ParamGrid nuGrid = SVM::getDefaultGrid(SVM::NU),
ParamGrid coeffGrid = SVM::getDefaultGrid(SVM::COEF),
ParamGrid degreeGrid = SVM::getDefaultGrid(SVM::DEGREE),
ParamGrid Cgrid = getDefaultGrid(C),
ParamGrid gammaGrid = getDefaultGrid(GAMMA),
ParamGrid pGrid = getDefaultGrid(P),
ParamGrid nuGrid = getDefaultGrid(NU),
ParamGrid coeffGrid = getDefaultGrid(COEF),
ParamGrid degreeGrid = getDefaultGrid(DEGREE),
bool balanced=false) = 0;
/** @brief Trains an %SVM with optimal parameters
@param samples training samples
@param layout See ml::SampleTypes.
@param responses vector of responses associated with the training samples.
@param kFold Cross-validation parameter. The training set is divided into kFold subsets. One
subset is used to test the model, the others form the train set. So, the %SVM algorithm is
@param Cgrid grid for C
@param gammaGrid grid for gamma
@param pGrid grid for p
@param nuGrid grid for nu
@param coeffGrid grid for coeff
@param degreeGrid grid for degree
@param balanced If true and the problem is 2-class classification then the method creates more
balanced cross-validation subsets that is proportions between classes in subsets are close
to such proportion in the whole train dataset.
The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p,
nu, coef0, degree. Parameters are considered optimal when the cross-validation
estimate of the test set error is minimal.
This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only
offers rudimentary parameter options.
This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the
regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and
the usual %SVM with parameters specified in params is executed.
*/
CV_WRAP bool trainAuto(InputArray samples,
int layout,
InputArray responses,
int kFold = 10,
Ptr<ParamGrid> Cgrid = SVM::getDefaultGridPtr(SVM::C),
Ptr<ParamGrid> gammaGrid = SVM::getDefaultGridPtr(SVM::GAMMA),
Ptr<ParamGrid> pGrid = SVM::getDefaultGridPtr(SVM::P),
Ptr<ParamGrid> nuGrid = SVM::getDefaultGridPtr(SVM::NU),
Ptr<ParamGrid> coeffGrid = SVM::getDefaultGridPtr(SVM::COEF),
Ptr<ParamGrid> degreeGrid = SVM::getDefaultGridPtr(SVM::DEGREE),
bool balanced=false);
/** @brief Retrieves all the support vectors
The method returns all the support vector as floating-point matrix, where support vectors are
The method returns all the support vectors as a floating-point matrix, where support vectors are
stored as matrix rows.
*/
CV_WRAP virtual Mat getSupportVectors() const = 0;
/** @brief Retrieves all the uncompressed support vectors of a linear %SVM
The method returns all the uncompressed support vectors of a linear %SVM that the compressed
support vector, used for prediction, was derived from. They are returned in a floating-point
matrix, where the support vectors are stored as matrix rows.
*/
CV_WRAP Mat getUncompressedSupportVectors() const;
/** @brief Retrieves the decision function
@param i the index of the decision function. If the problem solved is regression, 1-class or
@ -705,10 +792,29 @@ public:
*/
static ParamGrid getDefaultGrid( int param_id );
/** @brief Generates a grid for %SVM parameters.
@param param_id %SVM parameters IDs that must be one of the SVM::ParamTypes. The grid is
generated for the parameter with this ID.
The function generates a grid pointer for the specified parameter of the %SVM algorithm.
The grid may be passed to the function SVM::trainAuto.
*/
CV_WRAP static Ptr<ParamGrid> getDefaultGridPtr( int param_id );
/** Creates empty model.
Use StatModel::train to train the model. Since %SVM has several parameters, you may want to
find the best parameters for your problem, it can be done with SVM::trainAuto. */
CV_WRAP static Ptr<SVM> create();
/** @brief Loads and creates a serialized svm from a file
*
* Use SVM::save to serialize and store an SVM to disk.
* Load the SVM from this file again, by calling this function with the path to the file.
*
* @param filepath path to serialized svm
*/
CV_WRAP static Ptr<SVM> load(const String& filepath);
};
/****************************************************************************************\
@ -790,7 +896,16 @@ public:
Returns vector of covariation matrices. Number of matrices is the number of gaussian mixtures,
each matrix is a square floating-point matrix NxN, where N is the space dimensionality.
*/
virtual void getCovs(std::vector<Mat>& covs) const = 0;
CV_WRAP virtual void getCovs(CV_OUT std::vector<Mat>& covs) const = 0;
/** @brief Returns posterior probabilities for the provided samples
@param samples The input samples, floating-point matrix
@param results The optional output \f$ nSamples \times nClusters\f$ matrix of results. It contains
posterior probabilities for each sample from the input
@param flags This parameter will be ignored
*/
CV_WRAP virtual float predict( InputArray samples, OutputArray results=noArray(), int flags=0 ) const CV_OVERRIDE = 0;
/** @brief Returns a likelihood logarithm value and an index of the most probable mixture component
for the given sample.
@ -804,7 +919,7 @@ public:
the sample. First element is an index of the most probable mixture component for the given
sample.
*/
CV_WRAP CV_WRAP virtual Vec2d predict2(InputArray sample, OutputArray probs) const = 0;
CV_WRAP virtual Vec2d predict2(InputArray sample, OutputArray probs) const = 0;
/** @brief Estimate the Gaussian mixture parameters from a samples set.
@ -901,6 +1016,17 @@ public:
can use one of the EM::train\* methods or load it from file using Algorithm::load\<EM\>(filename).
*/
CV_WRAP static Ptr<EM> create();
/** @brief Loads and creates a serialized EM from a file
*
* Use EM::save to serialize and store an EM to disk.
* Load the EM from this file again, by calling this function with the path to the file.
* Optionally specify the node for the file containing the classifier
*
* @param filepath path to serialized EM
* @param nodeName name of node containing the classifier
*/
CV_WRAP static Ptr<EM> load(const String& filepath , const String& nodeName = String());
};
/****************************************************************************************\
@ -1089,6 +1215,17 @@ public:
file using Algorithm::load\<DTrees\>(filename).
*/
CV_WRAP static Ptr<DTrees> create();
/** @brief Loads and creates a serialized DTrees from a file
*
* Use DTree::save to serialize and store an DTree to disk.
* Load the DTree from this file again, by calling this function with the path to the file.
* Optionally specify the node for the file containing the classifier
*
* @param filepath path to serialized DTree
* @param nodeName name of node containing the classifier
*/
CV_WRAP static Ptr<DTrees> load(const String& filepath , const String& nodeName = String());
};
/****************************************************************************************\
@ -1138,11 +1275,33 @@ public:
*/
CV_WRAP virtual Mat getVarImportance() const = 0;
/** Returns the result of each individual tree in the forest.
In case the model is a regression problem, the method will return each of the trees'
results for each of the sample cases. If the model is a classifier, it will return
a Mat with samples + 1 rows, where the first row gives the class number and the
following rows return the votes each class had for each sample.
@param samples Array containing the samples for which votes will be calculated.
@param results Array where the result of the calculation will be written.
@param flags Flags for defining the type of RTrees.
*/
CV_WRAP void getVotes(InputArray samples, OutputArray results, int flags) const;
/** Creates the empty model.
Use StatModel::train to train the model, StatModel::train to create and train the model,
Algorithm::load to load the pre-trained model.
*/
CV_WRAP static Ptr<RTrees> create();
/** @brief Loads and creates a serialized RTree from a file
*
* Use RTree::save to serialize and store an RTree to disk.
* Load the RTree from this file again, by calling this function with the path to the file.
* Optionally specify the node for the file containing the classifier
*
* @param filepath path to serialized RTree
* @param nodeName name of node containing the classifier
*/
CV_WRAP static Ptr<RTrees> load(const String& filepath , const String& nodeName = String());
};
/****************************************************************************************\
@ -1192,6 +1351,17 @@ public:
/** Creates the empty model.
Use StatModel::train to train the model, Algorithm::load\<Boost\>(filename) to load the pre-trained model. */
CV_WRAP static Ptr<Boost> create();
/** @brief Loads and creates a serialized Boost from a file
*
* Use Boost::save to serialize and store an RTree to disk.
* Load the Boost from this file again, by calling this function with the path to the file.
* Optionally specify the node for the file containing the classifier
*
* @param filepath path to serialized Boost
* @param nodeName name of node containing the classifier
*/
CV_WRAP static Ptr<Boost> load(const String& filepath , const String& nodeName = String());
};
/****************************************************************************************\
@ -1247,13 +1417,14 @@ public:
/** Available training methods */
enum TrainingMethods {
BACKPROP=0, //!< The back-propagation algorithm.
RPROP=1 //!< The RPROP algorithm. See @cite RPROP93 for details.
RPROP = 1, //!< The RPROP algorithm. See @cite RPROP93 for details.
ANNEAL = 2 //!< The simulated annealing algorithm. See @cite Kirkpatrick83 for details.
};
/** Sets training method and common parameters.
@param method Default value is ANN_MLP::RPROP. See ANN_MLP::TrainingMethods.
@param param1 passed to setRpropDW0 for ANN_MLP::RPROP and to setBackpropWeightScale for ANN_MLP::BACKPROP
@param param2 passed to setRpropDWMin for ANN_MLP::RPROP and to setBackpropMomentumScale for ANN_MLP::BACKPROP.
@param param1 passed to setRpropDW0 for ANN_MLP::RPROP and to setBackpropWeightScale for ANN_MLP::BACKPROP and to initialT for ANN_MLP::ANNEAL.
@param param2 passed to setRpropDWMin for ANN_MLP::RPROP and to setBackpropMomentumScale for ANN_MLP::BACKPROP and to finalT for ANN_MLP::ANNEAL.
*/
CV_WRAP virtual void setTrainMethod(int method, double param1 = 0, double param2 = 0) = 0;
@ -1340,18 +1511,53 @@ public:
/** @copybrief getRpropDWMax @see getRpropDWMax */
CV_WRAP virtual void setRpropDWMax(double val) = 0;
/** ANNEAL: Update initial temperature.
It must be \>=0. Default value is 10.*/
/** @see setAnnealInitialT */
CV_WRAP double getAnnealInitialT() const;
/** @copybrief getAnnealInitialT @see getAnnealInitialT */
CV_WRAP void setAnnealInitialT(double val);
/** ANNEAL: Update final temperature.
It must be \>=0 and less than initialT. Default value is 0.1.*/
/** @see setAnnealFinalT */
CV_WRAP double getAnnealFinalT() const;
/** @copybrief getAnnealFinalT @see getAnnealFinalT */
CV_WRAP void setAnnealFinalT(double val);
/** ANNEAL: Update cooling ratio.
It must be \>0 and less than 1. Default value is 0.95.*/
/** @see setAnnealCoolingRatio */
CV_WRAP double getAnnealCoolingRatio() const;
/** @copybrief getAnnealCoolingRatio @see getAnnealCoolingRatio */
CV_WRAP void setAnnealCoolingRatio(double val);
/** ANNEAL: Update iteration per step.
It must be \>0 . Default value is 10.*/
/** @see setAnnealItePerStep */
CV_WRAP int getAnnealItePerStep() const;
/** @copybrief getAnnealItePerStep @see getAnnealItePerStep */
CV_WRAP void setAnnealItePerStep(int val);
/** @brief Set/initialize anneal RNG */
void setAnnealEnergyRNG(const RNG& rng);
/** possible activation functions */
enum ActivationFunctions {
/** Identity function: \f$f(x)=x\f$ */
IDENTITY = 0,
/** Symmetrical sigmoid: \f$f(x)=\beta*(1-e^{-\alpha x})/(1+e^{-\alpha x}\f$
/** Symmetrical sigmoid: \f$f(x)=\beta*(1-e^{-\alpha x})/(1+e^{-\alpha x})\f$
@note
If you are using the default sigmoid activation function with the default parameter values
fparam1=0 and fparam2=0 then the function used is y = 1.7159\*tanh(2/3 \* x), so the output
will range from [-1.7159, 1.7159], instead of [0,1].*/
SIGMOID_SYM = 1,
/** Gaussian function: \f$f(x)=\beta e^{-\alpha x*x}\f$ */
GAUSSIAN = 2
GAUSSIAN = 2,
/** ReLU function: \f$f(x)=max(0,x)\f$ */
RELU = 3,
/** Leaky ReLU function: for x>0 \f$f(x)=x \f$ and x<=0 \f$f(x)=\alpha x \f$*/
LEAKYRELU= 4
};
/** Train options */
@ -1379,6 +1585,16 @@ public:
Note that the train method has optional flags: ANN_MLP::TrainFlags.
*/
CV_WRAP static Ptr<ANN_MLP> create();
/** @brief Loads and creates a serialized ANN from a file
*
* Use ANN::save to serialize and store an ANN to disk.
* Load the ANN from this file again, by calling this function with the path to the file.
*
* @param filepath path to serialized ANN
*/
CV_WRAP static Ptr<ANN_MLP> load(const String& filepath);
};
/****************************************************************************************\
@ -1451,11 +1667,11 @@ public:
@param results Predicted labels as a column matrix of type CV_32S.
@param flags Not used.
*/
CV_WRAP virtual float predict( InputArray samples, OutputArray results=noArray(), int flags=0 ) const = 0;
CV_WRAP virtual float predict( InputArray samples, OutputArray results=noArray(), int flags=0 ) const CV_OVERRIDE = 0;
/** @brief This function returns the trained paramters arranged across rows.
/** @brief This function returns the trained parameters arranged across rows.
For a two class classifcation problem, it returns a row matrix. It returns learnt paramters of
For a two class classifcation problem, it returns a row matrix. It returns learnt parameters of
the Logistic Regression as a matrix of type CV_32F.
*/
CV_WRAP virtual Mat get_learnt_thetas() const = 0;
@ -1465,10 +1681,191 @@ public:
Creates Logistic Regression model with parameters given.
*/
CV_WRAP static Ptr<LogisticRegression> create();
/** @brief Loads and creates a serialized LogisticRegression from a file
*
* Use LogisticRegression::save to serialize and store an LogisticRegression to disk.
* Load the LogisticRegression from this file again, by calling this function with the path to the file.
* Optionally specify the node for the file containing the classifier
*
* @param filepath path to serialized LogisticRegression
* @param nodeName name of node containing the classifier
*/
CV_WRAP static Ptr<LogisticRegression> load(const String& filepath , const String& nodeName = String());
};
/****************************************************************************************\
* Auxilary functions declarations *
* Stochastic Gradient Descent SVM Classifier *
\****************************************************************************************/
/*!
@brief Stochastic Gradient Descent SVM classifier
SVMSGD provides a fast and easy-to-use implementation of the SVM classifier using the Stochastic Gradient Descent approach,
as presented in @cite bottou2010large.
The classifier has following parameters:
- model type,
- margin type,
- margin regularization (\f$\lambda\f$),
- initial step size (\f$\gamma_0\f$),
- step decreasing power (\f$c\f$),
- and termination criteria.
The model type may have one of the following values: \ref SGD and \ref ASGD.
- \ref SGD is the classic version of SVMSGD classifier: every next step is calculated by the formula
\f[w_{t+1} = w_t - \gamma(t) \frac{dQ_i}{dw} |_{w = w_t}\f]
where
- \f$w_t\f$ is the weights vector for decision function at step \f$t\f$,
- \f$\gamma(t)\f$ is the step size of model parameters at the iteration \f$t\f$, it is decreased on each step by the formula
\f$\gamma(t) = \gamma_0 (1 + \lambda \gamma_0 t) ^ {-c}\f$
- \f$Q_i\f$ is the target functional from SVM task for sample with number \f$i\f$, this sample is chosen stochastically on each step of the algorithm.
- \ref ASGD is Average Stochastic Gradient Descent SVM Classifier. ASGD classifier averages weights vector on each step of algorithm by the formula
\f$\widehat{w}_{t+1} = \frac{t}{1+t}\widehat{w}_{t} + \frac{1}{1+t}w_{t+1}\f$
The recommended model type is ASGD (following @cite bottou2010large).
The margin type may have one of the following values: \ref SOFT_MARGIN or \ref HARD_MARGIN.
- You should use \ref HARD_MARGIN type, if you have linearly separable sets.
- You should use \ref SOFT_MARGIN type, if you have non-linearly separable sets or sets with outliers.
- In the general case (if you know nothing about linear separability of your sets), use SOFT_MARGIN.
The other parameters may be described as follows:
- Margin regularization parameter is responsible for weights decreasing at each step and for the strength of restrictions on outliers
(the less the parameter, the less probability that an outlier will be ignored).
Recommended value for SGD model is 0.0001, for ASGD model is 0.00001.
- Initial step size parameter is the initial value for the step size \f$\gamma(t)\f$.
You will have to find the best initial step for your problem.
- Step decreasing power is the power parameter for \f$\gamma(t)\f$ decreasing by the formula, mentioned above.
Recommended value for SGD model is 1, for ASGD model is 0.75.
- Termination criteria can be TermCriteria::COUNT, TermCriteria::EPS or TermCriteria::COUNT + TermCriteria::EPS.
You will have to find the best termination criteria for your problem.
Note that the parameters margin regularization, initial step size, and step decreasing power should be positive.
To use SVMSGD algorithm do as follows:
- first, create the SVMSGD object. The algoorithm will set optimal parameters by default, but you can set your own parameters via functions setSvmsgdType(),
setMarginType(), setMarginRegularization(), setInitialStepSize(), and setStepDecreasingPower().
- then the SVM model can be trained using the train features and the correspondent labels by the method train().
- after that, the label of a new feature vector can be predicted using the method predict().
@code
// Create empty object
cv::Ptr<SVMSGD> svmsgd = SVMSGD::create();
// Train the Stochastic Gradient Descent SVM
svmsgd->train(trainData);
// Predict labels for the new samples
svmsgd->predict(samples, responses);
@endcode
*/
class CV_EXPORTS_W SVMSGD : public cv::ml::StatModel
{
public:
/** SVMSGD type.
ASGD is often the preferable choice. */
enum SvmsgdType
{
SGD, //!< Stochastic Gradient Descent
ASGD //!< Average Stochastic Gradient Descent
};
/** Margin type.*/
enum MarginType
{
SOFT_MARGIN, //!< General case, suits to the case of non-linearly separable sets, allows outliers.
HARD_MARGIN //!< More accurate for the case of linearly separable sets.
};
/**
* @return the weights of the trained model (decision function f(x) = weights * x + shift).
*/
CV_WRAP virtual Mat getWeights() = 0;
/**
* @return the shift of the trained model (decision function f(x) = weights * x + shift).
*/
CV_WRAP virtual float getShift() = 0;
/** @brief Creates empty model.
* Use StatModel::train to train the model. Since %SVMSGD has several parameters, you may want to
* find the best parameters for your problem or use setOptimalParameters() to set some default parameters.
*/
CV_WRAP static Ptr<SVMSGD> create();
/** @brief Loads and creates a serialized SVMSGD from a file
*
* Use SVMSGD::save to serialize and store an SVMSGD to disk.
* Load the SVMSGD from this file again, by calling this function with the path to the file.
* Optionally specify the node for the file containing the classifier
*
* @param filepath path to serialized SVMSGD
* @param nodeName name of node containing the classifier
*/
CV_WRAP static Ptr<SVMSGD> load(const String& filepath , const String& nodeName = String());
/** @brief Function sets optimal parameters values for chosen SVM SGD model.
* @param svmsgdType is the type of SVMSGD classifier.
* @param marginType is the type of margin constraint.
*/
CV_WRAP virtual void setOptimalParameters(int svmsgdType = SVMSGD::ASGD, int marginType = SVMSGD::SOFT_MARGIN) = 0;
/** @brief %Algorithm type, one of SVMSGD::SvmsgdType. */
/** @see setSvmsgdType */
CV_WRAP virtual int getSvmsgdType() const = 0;
/** @copybrief getSvmsgdType @see getSvmsgdType */
CV_WRAP virtual void setSvmsgdType(int svmsgdType) = 0;
/** @brief %Margin type, one of SVMSGD::MarginType. */
/** @see setMarginType */
CV_WRAP virtual int getMarginType() const = 0;
/** @copybrief getMarginType @see getMarginType */
CV_WRAP virtual void setMarginType(int marginType) = 0;
/** @brief Parameter marginRegularization of a %SVMSGD optimization problem. */
/** @see setMarginRegularization */
CV_WRAP virtual float getMarginRegularization() const = 0;
/** @copybrief getMarginRegularization @see getMarginRegularization */
CV_WRAP virtual void setMarginRegularization(float marginRegularization) = 0;
/** @brief Parameter initialStepSize of a %SVMSGD optimization problem. */
/** @see setInitialStepSize */
CV_WRAP virtual float getInitialStepSize() const = 0;
/** @copybrief getInitialStepSize @see getInitialStepSize */
CV_WRAP virtual void setInitialStepSize(float InitialStepSize) = 0;
/** @brief Parameter stepDecreasingPower of a %SVMSGD optimization problem. */
/** @see setStepDecreasingPower */
CV_WRAP virtual float getStepDecreasingPower() const = 0;
/** @copybrief getStepDecreasingPower @see getStepDecreasingPower */
CV_WRAP virtual void setStepDecreasingPower(float stepDecreasingPower) = 0;
/** @brief Termination criteria of the training algorithm.
You can specify the maximum number of iterations (maxCount) and/or how much the error could
change between the iterations to make the algorithm continue (epsilon).*/
/** @see setTermCriteria */
CV_WRAP virtual TermCriteria getTermCriteria() const = 0;
/** @copybrief getTermCriteria @see getTermCriteria */
CV_WRAP virtual void setTermCriteria(const cv::TermCriteria &val) = 0;
};
/****************************************************************************************\
* Auxiliary functions declarations *
\****************************************************************************************/
/** @brief Generates _sample_ from multivariate normal distribution
@ -1480,20 +1877,96 @@ public:
*/
CV_EXPORTS void randMVNormal( InputArray mean, InputArray cov, int nsamples, OutputArray samples);
/** @brief Generates sample from gaussian mixture distribution */
CV_EXPORTS void randGaussMixture( InputArray means, InputArray covs, InputArray weights,
int nsamples, OutputArray samples, OutputArray sampClasses );
/** @brief Creates test set */
CV_EXPORTS void createConcentricSpheresTestSet( int nsamples, int nfeatures, int nclasses,
OutputArray samples, OutputArray responses);
/** @brief Artificial Neural Networks - Multi-Layer Perceptrons.
@sa @ref ml_intro_ann
*/
class CV_EXPORTS_W ANN_MLP_ANNEAL : public ANN_MLP
{
public:
/** @see setAnnealInitialT */
CV_WRAP virtual double getAnnealInitialT() const = 0;
/** @copybrief getAnnealInitialT @see getAnnealInitialT */
CV_WRAP virtual void setAnnealInitialT(double val) = 0;
/** ANNEAL: Update final temperature.
It must be \>=0 and less than initialT. Default value is 0.1.*/
/** @see setAnnealFinalT */
CV_WRAP virtual double getAnnealFinalT() const = 0;
/** @copybrief getAnnealFinalT @see getAnnealFinalT */
CV_WRAP virtual void setAnnealFinalT(double val) = 0;
/** ANNEAL: Update cooling ratio.
It must be \>0 and less than 1. Default value is 0.95.*/
/** @see setAnnealCoolingRatio */
CV_WRAP virtual double getAnnealCoolingRatio() const = 0;
/** @copybrief getAnnealCoolingRatio @see getAnnealCoolingRatio */
CV_WRAP virtual void setAnnealCoolingRatio(double val) = 0;
/** ANNEAL: Update iteration per step.
It must be \>0 . Default value is 10.*/
/** @see setAnnealItePerStep */
CV_WRAP virtual int getAnnealItePerStep() const = 0;
/** @copybrief getAnnealItePerStep @see getAnnealItePerStep */
CV_WRAP virtual void setAnnealItePerStep(int val) = 0;
/** @brief Set/initialize anneal RNG */
virtual void setAnnealEnergyRNG(const RNG& rng) = 0;
};
/****************************************************************************************\
* Simulated annealing solver *
\****************************************************************************************/
#ifdef CV_DOXYGEN
/** @brief This class declares example interface for system state used in simulated annealing optimization algorithm.
@note This class is not defined in C++ code and can't be use directly - you need your own implementation with the same methods.
*/
struct SimulatedAnnealingSolverSystem
{
/** Give energy value for a state of system.*/
double energy() const;
/** Function which change the state of system (random perturbation).*/
void changeState();
/** Function to reverse to the previous state. Can be called once only after changeState(). */
void reverseState();
};
#endif // CV_DOXYGEN
/** @brief The class implements simulated annealing for optimization.
@cite Kirkpatrick83 for details
@param solverSystem optimization system (see SimulatedAnnealingSolverSystem)
@param initialTemperature initial temperature
@param finalTemperature final temperature
@param coolingRatio temperature step multiplies
@param iterationsPerStep number of iterations per temperature changing step
@param lastTemperature optional output for last used temperature
@param rngEnergy specify custom random numbers generator (cv::theRNG() by default)
*/
template<class SimulatedAnnealingSolverSystem>
int simulatedAnnealingSolver(SimulatedAnnealingSolverSystem& solverSystem,
double initialTemperature, double finalTemperature, double coolingRatio,
size_t iterationsPerStep,
CV_OUT double* lastTemperature = NULL,
cv::RNG& rngEnergy = cv::theRNG()
);
//! @} ml
}
}
#include <opencv2/ml/ml.inl.hpp>
#endif // __cplusplus
#endif // __OPENCV_ML_HPP__
#endif // OPENCV_ML_HPP
/* End of file. */