@@ -1528,6 +1528,9 @@ class CV_EXPORTS_W ANN_MLP : public StatModel
1528
1528
/* * @copybrief getAnnealItePerStep @see getAnnealItePerStep */
1529
1529
CV_WRAP void setAnnealItePerStep (int val);
1530
1530
1531
+ /* * @brief Set/initialize anneal RNG */
1532
+ void setAnnealEnergyRNG (const RNG& rng);
1533
+
1531
1534
/* * possible activation functions */
1532
1535
enum ActivationFunctions {
1533
1536
/* * Identity function: \f$f(x)=x\f$ */
@@ -1875,101 +1878,102 @@ class CV_EXPORTS_W ANN_MLP_ANNEAL : public ANN_MLP
1875
1878
{
1876
1879
public:
1877
1880
/* * @see setAnnealInitialT */
1878
- CV_WRAP virtual double getAnnealInitialT () const ;
1881
+ CV_WRAP virtual double getAnnealInitialT () const = 0 ;
1879
1882
/* * @copybrief getAnnealInitialT @see getAnnealInitialT */
1880
- CV_WRAP virtual void setAnnealInitialT (double val);
1883
+ CV_WRAP virtual void setAnnealInitialT (double val) = 0 ;
1881
1884
1882
1885
/* * ANNEAL: Update final temperature.
1883
1886
It must be \>=0 and less than initialT. Default value is 0.1.*/
1884
1887
/* * @see setAnnealFinalT */
1885
- CV_WRAP virtual double getAnnealFinalT () const ;
1888
+ CV_WRAP virtual double getAnnealFinalT () const = 0 ;
1886
1889
/* * @copybrief getAnnealFinalT @see getAnnealFinalT */
1887
- CV_WRAP virtual void setAnnealFinalT (double val);
1890
+ CV_WRAP virtual void setAnnealFinalT (double val) = 0 ;
1888
1891
1889
1892
/* * ANNEAL: Update cooling ratio.
1890
1893
It must be \>0 and less than 1. Default value is 0.95.*/
1891
1894
/* * @see setAnnealCoolingRatio */
1892
- CV_WRAP virtual double getAnnealCoolingRatio () const ;
1895
+ CV_WRAP virtual double getAnnealCoolingRatio () const = 0 ;
1893
1896
/* * @copybrief getAnnealCoolingRatio @see getAnnealCoolingRatio */
1894
- CV_WRAP virtual void setAnnealCoolingRatio (double val);
1897
+ CV_WRAP virtual void setAnnealCoolingRatio (double val) = 0 ;
1895
1898
1896
1899
/* * ANNEAL: Update iteration per step.
1897
1900
It must be \>0 . Default value is 10.*/
1898
1901
/* * @see setAnnealItePerStep */
1899
- CV_WRAP virtual int getAnnealItePerStep () const ;
1902
+ CV_WRAP virtual int getAnnealItePerStep () const = 0 ;
1900
1903
/* * @copybrief getAnnealItePerStep @see getAnnealItePerStep */
1901
- CV_WRAP virtual void setAnnealItePerStep (int val);
1902
-
1903
-
1904
- /* * @brief Creates empty model
1905
-
1906
- Use StatModel::train to train the model, Algorithm::load\<ANN_MLP\>(filename) to load the pre-trained model.
1907
- Note that the train method has optional flags: ANN_MLP::TrainFlags.
1908
- */
1909
- // CV_WRAP static Ptr<ANN_MLP> create();
1904
+ CV_WRAP virtual void setAnnealItePerStep (int val) = 0;
1910
1905
1906
+ /* * @brief Set/initialize anneal RNG */
1907
+ virtual void setAnnealEnergyRNG (const RNG& rng) = 0;
1911
1908
};
1912
1909
1910
+
1913
1911
/* ***************************************************************************************\
1914
1912
* Simulated annealing solver *
1915
1913
\****************************************************************************************/
1916
1914
1915
+ /* * @brief The class defines interface for system state used in simulated annealing optimization algorithm.
1916
+
1917
+ @cite Kirkpatrick83 for details
1918
+ */
1919
+ class CV_EXPORTS SimulatedAnnealingSolverSystem
1920
+ {
1921
+ protected:
1922
+ inline SimulatedAnnealingSolverSystem () {}
1923
+ public:
1924
+ virtual ~SimulatedAnnealingSolverSystem () {}
1925
+
1926
+ /* * Give energy value for a state of system.*/
1927
+ virtual double energy () const = 0;
1928
+ /* * Function which change the state of system (random pertubation).*/
1929
+ virtual void changeState () = 0;
1930
+ /* * Function to reverse to the previous state. Can be called once only after changeState(). */
1931
+ virtual void reverseState () = 0;
1932
+ };
1933
+
1917
1934
/* * @brief The class implements simulated annealing for optimization.
1935
+ *
1918
1936
@cite Kirkpatrick83 for details
1919
1937
*/
1920
1938
class CV_EXPORTS SimulatedAnnealingSolver : public Algorithm
1921
1939
{
1922
1940
public:
1923
- SimulatedAnnealingSolver () { init (); };
1924
- ~SimulatedAnnealingSolver ();
1925
- /* * Give energy value for a state of system.*/
1926
- virtual double energy () =0;
1927
- /* * Function which change the state of system (random pertubation).*/
1928
- virtual void changedState () = 0;
1929
- /* * Function to reverse to the previous state.*/
1930
- virtual void reverseChangedState () = 0;
1931
- /* * Simulated annealing procedure. */
1941
+ SimulatedAnnealingSolver (const Ptr<SimulatedAnnealingSolverSystem>& system);
1942
+ inline ~SimulatedAnnealingSolver () { release (); }
1943
+
1944
+ /* * Simulated annealing procedure. */
1932
1945
int run ();
1933
- /* * Set intial temperature of simulated annealing procedure.
1934
- *@param x new initial temperature. x\>0
1946
+ /* * Set/initialize RNG (energy).
1947
+ @param rng new RNG
1948
+ */
1949
+ void setEnergyRNG (const RNG& rng);
1950
+ /* * Set initial temperature of simulated annealing procedure.
1951
+ @param x new initial temperature. x\>0
1935
1952
*/
1936
1953
void setInitialTemperature (double x);
1937
1954
/* * Set final temperature of simulated annealing procedure.
1938
- * @param x new final temperature value. 0\<x\<initial temperature
1955
+ @param x new final temperature value. 0\<x\<initial temperature
1939
1956
*/
1940
1957
void setFinalTemperature (double x);
1958
+ /* * Get final temperature of simulated annealing procedure. */
1941
1959
double getFinalTemperature ();
1942
1960
/* * Set setCoolingRatio of simulated annealing procedure : T(t) = coolingRatio * T(t-1).
1943
- * @param x new cooling ratio value. 0\<x\<1
1961
+ @param x new cooling ratio value. 0\<x\<1
1944
1962
*/
1945
1963
void setCoolingRatio (double x);
1946
1964
/* * Set number iteration per temperature step.
1947
- * @param ite number of iteration per temperature step ite \> 0
1965
+ @param ite number of iteration per temperature step ite \> 0
1948
1966
*/
1949
1967
void setIterPerStep (int ite);
1950
- struct Impl ;
1951
- protected :
1952
- void init ();
1968
+
1969
+ void release ();
1970
+ SimulatedAnnealingSolver (const SimulatedAnnealingSolver&);
1971
+ SimulatedAnnealingSolver& operator =(const SimulatedAnnealingSolver&);
1972
+
1973
+ struct Impl ; friend struct Impl ;
1974
+ protected:
1953
1975
Impl* impl;
1954
1976
};
1955
- struct SimulatedAnnealingSolver ::Impl
1956
- {
1957
- RNG rEnergy;
1958
- double coolingRatio;
1959
- double initialT;
1960
- double finalT;
1961
- int iterPerStep;
1962
- Impl ()
1963
- {
1964
- initialT = 2 ;
1965
- finalT = 0.1 ;
1966
- coolingRatio = 0.95 ;
1967
- iterPerStep = 100 ;
1968
- refcount = 1 ;
1969
- }
1970
- int refcount;
1971
- ~Impl () { refcount--;CV_Assert (refcount==0 ); }
1972
- };
1973
1977
1974
1978
1975
1979
// ! @} ml
0 commit comments