Skip to content

Commit 0a43957

Browse files
committed
Move SimulatedAnnealingSolver::Impl in cpp file. Fix some typos.
1 parent c5ed507 commit 0a43957

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

modules/ml/include/opencv2/ml.hpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,7 @@ class CV_EXPORTS_W ANN_MLP_ANNEAL : public ANN_MLP
19201920
class CV_EXPORTS SimulatedAnnealingSolver : public Algorithm
19211921
{
19221922
public:
1923-
SimulatedAnnealingSolver() { init(); };
1923+
SimulatedAnnealingSolver() { init(); }
19241924
~SimulatedAnnealingSolver();
19251925
/** Give energy value for a state of system.*/
19261926
virtual double energy() =0;
@@ -1947,31 +1947,14 @@ class CV_EXPORTS SimulatedAnnealingSolver : public Algorithm
19471947
* @param ite number of iteration per temperature step ite \> 0
19481948
*/
19491949
void setIterPerStep(int ite);
1950-
struct Impl;
1951-
protected :
1950+
1951+
protected:
19521952
void init();
1953+
1954+
private:
1955+
struct Impl;
19531956
Impl* impl;
19541957
};
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-
19751958
//! @} ml
19761959

19771960
}

modules/ml/src/ann_mlp.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@
4242

4343
namespace cv { namespace ml {
4444

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+
};
4563

4664
struct AnnParams
4765
{
@@ -135,24 +153,24 @@ void SimulatedAnnealingSolver::setInitialTemperature(double x)
135153
{
136154
CV_Assert(x>0);
137155
impl->initialT = x;
138-
};
156+
}
139157

140158
void SimulatedAnnealingSolver::setFinalTemperature(double x)
141159
{
142160
CV_Assert(x>0);
143161
impl->finalT = x;
144-
};
162+
}
145163

146164
double SimulatedAnnealingSolver::getFinalTemperature()
147165
{
148166
return impl->finalT;
149-
};
167+
}
150168

151169
void SimulatedAnnealingSolver::setCoolingRatio(double x)
152170
{
153171
CV_Assert(x>0 && x<1);
154172
impl->coolingRatio = x;
155-
};
173+
}
156174

157175
class SimulatedAnnealingANN_MLP : public ml::SimulatedAnnealingSolver
158176
{
@@ -169,19 +187,23 @@ class SimulatedAnnealingANN_MLP : public ml::SimulatedAnnealingSolver
169187
SimulatedAnnealingANN_MLP(ml::ANN_MLP *x, Ptr<ml::TrainData> d) : nn(x), data(d)
170188
{
171189
initVarMap();
172-
};
190+
}
191+
173192
void changedState()
174193
{
175194
index = rIndex.uniform(0, nbVariables);
176195
double dv = rVar.uniform(-1.0, 1.0);
177196
varTmp = *adrVariables[index];
178197
*adrVariables[index] = dv;
179-
};
198+
}
199+
180200
void reverseChangedState()
181201
{
182202
*adrVariables[index] = varTmp;
183-
};
203+
}
204+
184205
double energy() { return nn->calcError(data, false, noArray()); }
206+
185207
protected:
186208
void initVarMap()
187209
{

0 commit comments

Comments
 (0)