mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
ml: fix SimulatedAnnealingSolver interface
This commit is contained in:
committed by
Alexander Alekhin
parent
0a439570a0
commit
aef3019152
@@ -1528,6 +1528,9 @@ public:
|
||||
/** @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$ */
|
||||
@@ -1875,86 +1878,104 @@ class CV_EXPORTS_W ANN_MLP_ANNEAL : public ANN_MLP
|
||||
{
|
||||
public:
|
||||
/** @see setAnnealInitialT */
|
||||
CV_WRAP virtual double getAnnealInitialT() const;
|
||||
CV_WRAP virtual double getAnnealInitialT() const = 0;
|
||||
/** @copybrief getAnnealInitialT @see getAnnealInitialT */
|
||||
CV_WRAP virtual void setAnnealInitialT(double val);
|
||||
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;
|
||||
CV_WRAP virtual double getAnnealFinalT() const = 0;
|
||||
/** @copybrief getAnnealFinalT @see getAnnealFinalT */
|
||||
CV_WRAP virtual void setAnnealFinalT(double val);
|
||||
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;
|
||||
CV_WRAP virtual double getAnnealCoolingRatio() const = 0;
|
||||
/** @copybrief getAnnealCoolingRatio @see getAnnealCoolingRatio */
|
||||
CV_WRAP virtual void setAnnealCoolingRatio(double val);
|
||||
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;
|
||||
CV_WRAP virtual int getAnnealItePerStep() const = 0;
|
||||
/** @copybrief getAnnealItePerStep @see getAnnealItePerStep */
|
||||
CV_WRAP virtual void setAnnealItePerStep(int val);
|
||||
|
||||
|
||||
/** @brief Creates empty model
|
||||
|
||||
Use StatModel::train to train the model, Algorithm::load\<ANN_MLP\>(filename) to load the pre-trained model.
|
||||
Note that the train method has optional flags: ANN_MLP::TrainFlags.
|
||||
*/
|
||||
// CV_WRAP static Ptr<ANN_MLP> create();
|
||||
CV_WRAP virtual void setAnnealItePerStep(int val) = 0;
|
||||
|
||||
/** @brief Set/initialize anneal RNG */
|
||||
virtual void setAnnealEnergyRNG(const RNG& rng) = 0;
|
||||
};
|
||||
|
||||
|
||||
/****************************************************************************************\
|
||||
* Simulated annealing solver *
|
||||
\****************************************************************************************/
|
||||
|
||||
/** @brief The class defines interface for system state used in simulated annealing optimization algorithm.
|
||||
|
||||
@cite Kirkpatrick83 for details
|
||||
*/
|
||||
class CV_EXPORTS SimulatedAnnealingSolverSystem
|
||||
{
|
||||
protected:
|
||||
inline SimulatedAnnealingSolverSystem() {}
|
||||
public:
|
||||
virtual ~SimulatedAnnealingSolverSystem() {}
|
||||
|
||||
/** Give energy value for a state of system.*/
|
||||
virtual double energy() const = 0;
|
||||
/** Function which change the state of system (random pertubation).*/
|
||||
virtual void changeState() = 0;
|
||||
/** Function to reverse to the previous state. Can be called once only after changeState(). */
|
||||
virtual void reverseState() = 0;
|
||||
};
|
||||
|
||||
/** @brief The class implements simulated annealing for optimization.
|
||||
*
|
||||
@cite Kirkpatrick83 for details
|
||||
*/
|
||||
class CV_EXPORTS SimulatedAnnealingSolver : public Algorithm
|
||||
{
|
||||
public:
|
||||
SimulatedAnnealingSolver() { init(); }
|
||||
~SimulatedAnnealingSolver();
|
||||
/** Give energy value for a state of system.*/
|
||||
virtual double energy() =0;
|
||||
/** Function which change the state of system (random pertubation).*/
|
||||
virtual void changedState() = 0;
|
||||
/** Function to reverse to the previous state.*/
|
||||
virtual void reverseChangedState() = 0;
|
||||
/** Simulated annealing procedure. */
|
||||
SimulatedAnnealingSolver(const Ptr<SimulatedAnnealingSolverSystem>& system);
|
||||
inline ~SimulatedAnnealingSolver() { release(); }
|
||||
|
||||
/** Simulated annealing procedure. */
|
||||
int run();
|
||||
/** Set intial temperature of simulated annealing procedure.
|
||||
*@param x new initial temperature. x\>0
|
||||
/** Set/initialize RNG (energy).
|
||||
@param rng new RNG
|
||||
*/
|
||||
void setEnergyRNG(const RNG& rng);
|
||||
/** Set initial temperature of simulated annealing procedure.
|
||||
@param x new initial temperature. x\>0
|
||||
*/
|
||||
void setInitialTemperature(double x);
|
||||
/** Set final temperature of simulated annealing procedure.
|
||||
*@param x new final temperature value. 0\<x\<initial temperature
|
||||
@param x new final temperature value. 0\<x\<initial temperature
|
||||
*/
|
||||
void setFinalTemperature(double x);
|
||||
/** Get final temperature of simulated annealing procedure. */
|
||||
double getFinalTemperature();
|
||||
/** Set setCoolingRatio of simulated annealing procedure : T(t) = coolingRatio * T(t-1).
|
||||
* @param x new cooling ratio value. 0\<x\<1
|
||||
@param x new cooling ratio value. 0\<x\<1
|
||||
*/
|
||||
void setCoolingRatio(double x);
|
||||
/** Set number iteration per temperature step.
|
||||
* @param ite number of iteration per temperature step ite \> 0
|
||||
@param ite number of iteration per temperature step ite \> 0
|
||||
*/
|
||||
void setIterPerStep(int ite);
|
||||
|
||||
protected:
|
||||
void init();
|
||||
void release();
|
||||
SimulatedAnnealingSolver(const SimulatedAnnealingSolver&);
|
||||
SimulatedAnnealingSolver& operator=(const SimulatedAnnealingSolver&);
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
struct Impl; friend struct Impl;
|
||||
protected:
|
||||
Impl* impl;
|
||||
};
|
||||
|
||||
|
||||
//! @} ml
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user