@@ -1406,13 +1406,14 @@ class CV_EXPORTS_W ANN_MLP : public StatModel
1406
1406
/* * Available training methods */
1407
1407
enum TrainingMethods {
1408
1408
BACKPROP=0 , // !< The back-propagation algorithm.
1409
- RPROP=1 // !< The RPROP algorithm. See @cite RPROP93 for details.
1409
+ RPROP = 1 , // !< The RPROP algorithm. See @cite RPROP93 for details.
1410
+ ANNEAL = 2 // !< The simulated annealing algorithm. See @cite Kirkpatrick83 for details.
1410
1411
};
1411
1412
1412
1413
/* * Sets training method and common parameters.
1413
1414
@param method Default value is ANN_MLP::RPROP. See ANN_MLP::TrainingMethods.
1414
- @param param1 passed to setRpropDW0 for ANN_MLP::RPROP and to setBackpropWeightScale for ANN_MLP::BACKPROP
1415
- @param param2 passed to setRpropDWMin for ANN_MLP::RPROP and to setBackpropMomentumScale for ANN_MLP::BACKPROP.
1415
+ @param param1 passed to setRpropDW0 for ANN_MLP::RPROP and to setBackpropWeightScale for ANN_MLP::BACKPROP and to initialT for ANN_MLP::ANNEAL.
1416
+ @param param2 passed to setRpropDWMin for ANN_MLP::RPROP and to setBackpropMomentumScale for ANN_MLP::BACKPROP and to finalT for ANN_MLP::ANNEAL .
1416
1417
*/
1417
1418
CV_WRAP virtual void setTrainMethod (int method, double param1 = 0 , double param2 = 0 ) = 0;
1418
1419
@@ -1499,6 +1500,34 @@ class CV_EXPORTS_W ANN_MLP : public StatModel
1499
1500
/* * @copybrief getRpropDWMax @see getRpropDWMax */
1500
1501
CV_WRAP virtual void setRpropDWMax (double val) = 0;
1501
1502
1503
+ /* * ANNEAL: Update initial temperature.
1504
+ It must be \>=0. Default value is 10.*/
1505
+ /* * @see setAnnealInitialT */
1506
+ CV_WRAP double getAnnealInitialT () const ;
1507
+ /* * @copybrief getAnnealInitialT @see getAnnealInitialT */
1508
+ CV_WRAP void setAnnealInitialT (double val);
1509
+
1510
+ /* * ANNEAL: Update final temperature.
1511
+ It must be \>=0 and less than initialT. Default value is 0.1.*/
1512
+ /* * @see setAnnealFinalT */
1513
+ CV_WRAP double getAnnealFinalT () const ;
1514
+ /* * @copybrief getAnnealFinalT @see getAnnealFinalT */
1515
+ CV_WRAP void setAnnealFinalT (double val);
1516
+
1517
+ /* * ANNEAL: Update cooling ratio.
1518
+ It must be \>0 and less than 1. Default value is 0.95.*/
1519
+ /* * @see setAnnealCoolingRatio */
1520
+ CV_WRAP double getAnnealCoolingRatio () const ;
1521
+ /* * @copybrief getAnnealCoolingRatio @see getAnnealCoolingRatio */
1522
+ CV_WRAP void setAnnealCoolingRatio (double val);
1523
+
1524
+ /* * ANNEAL: Update iteration per step.
1525
+ It must be \>0 . Default value is 10.*/
1526
+ /* * @see setAnnealItePerStep */
1527
+ CV_WRAP int getAnnealItePerStep () const ;
1528
+ /* * @copybrief getAnnealItePerStep @see getAnnealItePerStep */
1529
+ CV_WRAP void setAnnealItePerStep (int val);
1530
+
1502
1531
/* * possible activation functions */
1503
1532
enum ActivationFunctions {
1504
1533
/* * Identity function: \f$f(x)=x\f$ */
@@ -1838,6 +1867,111 @@ CV_EXPORTS void randMVNormal( InputArray mean, InputArray cov, int nsamples, Out
1838
1867
CV_EXPORTS void createConcentricSpheresTestSet ( int nsamples, int nfeatures, int nclasses,
1839
1868
OutputArray samples, OutputArray responses);
1840
1869
1870
+ /* * @brief Artificial Neural Networks - Multi-Layer Perceptrons.
1871
+
1872
+ @sa @ref ml_intro_ann
1873
+ */
1874
+ class CV_EXPORTS_W ANN_MLP_ANNEAL : public ANN_MLP
1875
+ {
1876
+ public:
1877
+ /* * @see setAnnealInitialT */
1878
+ CV_WRAP virtual double getAnnealInitialT () const ;
1879
+ /* * @copybrief getAnnealInitialT @see getAnnealInitialT */
1880
+ CV_WRAP virtual void setAnnealInitialT (double val);
1881
+
1882
+ /* * ANNEAL: Update final temperature.
1883
+ It must be \>=0 and less than initialT. Default value is 0.1.*/
1884
+ /* * @see setAnnealFinalT */
1885
+ CV_WRAP virtual double getAnnealFinalT () const ;
1886
+ /* * @copybrief getAnnealFinalT @see getAnnealFinalT */
1887
+ CV_WRAP virtual void setAnnealFinalT (double val);
1888
+
1889
+ /* * ANNEAL: Update cooling ratio.
1890
+ It must be \>0 and less than 1. Default value is 0.95.*/
1891
+ /* * @see setAnnealCoolingRatio */
1892
+ CV_WRAP virtual double getAnnealCoolingRatio () const ;
1893
+ /* * @copybrief getAnnealCoolingRatio @see getAnnealCoolingRatio */
1894
+ CV_WRAP virtual void setAnnealCoolingRatio (double val);
1895
+
1896
+ /* * ANNEAL: Update iteration per step.
1897
+ It must be \>0 . Default value is 10.*/
1898
+ /* * @see setAnnealItePerStep */
1899
+ CV_WRAP virtual int getAnnealItePerStep () const ;
1900
+ /* * @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();
1910
+
1911
+ };
1912
+
1913
+ /* ***************************************************************************************\
1914
+ * Simulated annealing solver *
1915
+ \****************************************************************************************/
1916
+
1917
+ /* * @brief The class implements simulated annealing for optimization.
1918
+ @cite Kirkpatrick83 for details
1919
+ */
1920
+ class CV_EXPORTS SimulatedAnnealingSolver : public Algorithm
1921
+ {
1922
+ 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. */
1932
+ int run ();
1933
+ /* * Set intial temperature of simulated annealing procedure.
1934
+ *@param x new initial temperature. x\>0
1935
+ */
1936
+ void setInitialTemperature (double x);
1937
+ /* * Set final temperature of simulated annealing procedure.
1938
+ *@param x new final temperature value. 0\<x\<initial temperature
1939
+ */
1940
+ void setFinalTemperature (double x);
1941
+ double getFinalTemperature ();
1942
+ /* * Set setCoolingRatio of simulated annealing procedure : T(t) = coolingRatio * T(t-1).
1943
+ * @param x new cooling ratio value. 0\<x\<1
1944
+ */
1945
+ void setCoolingRatio (double x);
1946
+ /* * Set number iteration per temperature step.
1947
+ * @param ite number of iteration per temperature step ite \> 0
1948
+ */
1949
+ void setIterPerStep (int ite);
1950
+ struct Impl ;
1951
+ protected :
1952
+ void init ();
1953
+ Impl* impl;
1954
+ };
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
+
1974
+
1841
1975
// ! @} ml
1842
1976
1843
1977
}
0 commit comments