File tree Expand file tree Collapse file tree 2 files changed +35
-30
lines changed Expand file tree Collapse file tree 2 files changed +35
-30
lines changed Original file line number Diff line number Diff line change @@ -1920,7 +1920,7 @@ class CV_EXPORTS_W ANN_MLP_ANNEAL : public ANN_MLP
1920
1920
class CV_EXPORTS SimulatedAnnealingSolver : public Algorithm
1921
1921
{
1922
1922
public:
1923
- SimulatedAnnealingSolver () { init (); };
1923
+ SimulatedAnnealingSolver () { init (); }
1924
1924
~SimulatedAnnealingSolver ();
1925
1925
/* * Give energy value for a state of system.*/
1926
1926
virtual double energy () =0;
@@ -1947,31 +1947,14 @@ class CV_EXPORTS SimulatedAnnealingSolver : public Algorithm
1947
1947
* @param ite number of iteration per temperature step ite \> 0
1948
1948
*/
1949
1949
void setIterPerStep (int ite);
1950
- struct Impl ;
1951
- protected :
1950
+
1951
+ protected:
1952
1952
void init ();
1953
+
1954
+ private:
1955
+ struct Impl ;
1953
1956
Impl* impl;
1954
1957
};
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
-
1975
1958
// ! @} ml
1976
1959
1977
1960
}
Original file line number Diff line number Diff line change 42
42
43
43
namespace cv { namespace ml {
44
44
45
+ struct SimulatedAnnealingSolver ::Impl
46
+ {
47
+ RNG rEnergy;
48
+ double coolingRatio;
49
+ double initialT;
50
+ double finalT;
51
+ int iterPerStep;
52
+ Impl ()
53
+ {
54
+ initialT = 2 ;
55
+ finalT = 0.1 ;
56
+ coolingRatio = 0.95 ;
57
+ iterPerStep = 100 ;
58
+ refcount = 1 ;
59
+ }
60
+ int refcount;
61
+ ~Impl () { refcount--;CV_Assert (refcount==0 ); }
62
+ };
45
63
46
64
struct AnnParams
47
65
{
@@ -135,24 +153,24 @@ void SimulatedAnnealingSolver::setInitialTemperature(double x)
135
153
{
136
154
CV_Assert (x>0 );
137
155
impl->initialT = x;
138
- };
156
+ }
139
157
140
158
void SimulatedAnnealingSolver::setFinalTemperature (double x)
141
159
{
142
160
CV_Assert (x>0 );
143
161
impl->finalT = x;
144
- };
162
+ }
145
163
146
164
double SimulatedAnnealingSolver::getFinalTemperature ()
147
165
{
148
166
return impl->finalT ;
149
- };
167
+ }
150
168
151
169
void SimulatedAnnealingSolver::setCoolingRatio (double x)
152
170
{
153
171
CV_Assert (x>0 && x<1 );
154
172
impl->coolingRatio = x;
155
- };
173
+ }
156
174
157
175
class SimulatedAnnealingANN_MLP : public ml ::SimulatedAnnealingSolver
158
176
{
@@ -169,19 +187,23 @@ class SimulatedAnnealingANN_MLP : public ml::SimulatedAnnealingSolver
169
187
SimulatedAnnealingANN_MLP (ml::ANN_MLP *x, Ptr<ml::TrainData> d) : nn(x), data(d)
170
188
{
171
189
initVarMap ();
172
- };
190
+ }
191
+
173
192
void changedState ()
174
193
{
175
194
index = rIndex.uniform (0 , nbVariables);
176
195
double dv = rVar.uniform (-1.0 , 1.0 );
177
196
varTmp = *adrVariables[index];
178
197
*adrVariables[index] = dv;
179
- };
198
+ }
199
+
180
200
void reverseChangedState ()
181
201
{
182
202
*adrVariables[index] = varTmp;
183
- };
203
+ }
204
+
184
205
double energy () { return nn->calcError (data, false , noArray ()); }
206
+
185
207
protected:
186
208
void initVarMap ()
187
209
{
You can’t perform that action at this time.
0 commit comments