Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
0a439570
Commit
0a439570
authored
Dec 15, 2017
by
catree
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move SimulatedAnnealingSolver::Impl in cpp file. Fix some typos.
parent
c5ed5077
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
30 deletions
+35
-30
ml.hpp
modules/ml/include/opencv2/ml.hpp
+6
-23
ann_mlp.cpp
modules/ml/src/ann_mlp.cpp
+29
-7
No files found.
modules/ml/include/opencv2/ml.hpp
View file @
0a439570
...
@@ -1920,7 +1920,7 @@ public:
...
@@ -1920,7 +1920,7 @@ public:
class
CV_EXPORTS
SimulatedAnnealingSolver
:
public
Algorithm
class
CV_EXPORTS
SimulatedAnnealingSolver
:
public
Algorithm
{
{
public
:
public
:
SimulatedAnnealingSolver
()
{
init
();
}
;
SimulatedAnnealingSolver
()
{
init
();
}
~
SimulatedAnnealingSolver
();
~
SimulatedAnnealingSolver
();
/** Give energy value for a state of system.*/
/** Give energy value for a state of system.*/
virtual
double
energy
()
=
0
;
virtual
double
energy
()
=
0
;
...
@@ -1947,31 +1947,14 @@ public:
...
@@ -1947,31 +1947,14 @@ public:
* @param ite number of iteration per temperature step ite \> 0
* @param ite number of iteration per temperature step ite \> 0
*/
*/
void
setIterPerStep
(
int
ite
);
void
setIterPerStep
(
int
ite
);
struct
Impl
;
protected
:
protected
:
void
init
();
void
init
();
private
:
struct
Impl
;
Impl
*
impl
;
Impl
*
impl
;
};
};
struct
SimulatedAnnealingSolver
::
Impl
{
RNG
rEnergy
;
double
coolingRatio
;
double
initialT
;
double
finalT
;
int
iterPerStep
;
Impl
()
{
initialT
=
2
;
finalT
=
0.1
;
coolingRatio
=
0.95
;
iterPerStep
=
100
;
refcount
=
1
;
}
int
refcount
;
~
Impl
()
{
refcount
--
;
CV_Assert
(
refcount
==
0
);
}
};
//! @} ml
//! @} ml
}
}
...
...
modules/ml/src/ann_mlp.cpp
View file @
0a439570
...
@@ -42,6 +42,24 @@
...
@@ -42,6 +42,24 @@
namespace
cv
{
namespace
ml
{
namespace
cv
{
namespace
ml
{
struct
SimulatedAnnealingSolver
::
Impl
{
RNG
rEnergy
;
double
coolingRatio
;
double
initialT
;
double
finalT
;
int
iterPerStep
;
Impl
()
{
initialT
=
2
;
finalT
=
0.1
;
coolingRatio
=
0.95
;
iterPerStep
=
100
;
refcount
=
1
;
}
int
refcount
;
~
Impl
()
{
refcount
--
;
CV_Assert
(
refcount
==
0
);
}
};
struct
AnnParams
struct
AnnParams
{
{
...
@@ -135,24 +153,24 @@ void SimulatedAnnealingSolver::setInitialTemperature(double x)
...
@@ -135,24 +153,24 @@ void SimulatedAnnealingSolver::setInitialTemperature(double x)
{
{
CV_Assert
(
x
>
0
);
CV_Assert
(
x
>
0
);
impl
->
initialT
=
x
;
impl
->
initialT
=
x
;
}
;
}
void
SimulatedAnnealingSolver
::
setFinalTemperature
(
double
x
)
void
SimulatedAnnealingSolver
::
setFinalTemperature
(
double
x
)
{
{
CV_Assert
(
x
>
0
);
CV_Assert
(
x
>
0
);
impl
->
finalT
=
x
;
impl
->
finalT
=
x
;
}
;
}
double
SimulatedAnnealingSolver
::
getFinalTemperature
()
double
SimulatedAnnealingSolver
::
getFinalTemperature
()
{
{
return
impl
->
finalT
;
return
impl
->
finalT
;
}
;
}
void
SimulatedAnnealingSolver
::
setCoolingRatio
(
double
x
)
void
SimulatedAnnealingSolver
::
setCoolingRatio
(
double
x
)
{
{
CV_Assert
(
x
>
0
&&
x
<
1
);
CV_Assert
(
x
>
0
&&
x
<
1
);
impl
->
coolingRatio
=
x
;
impl
->
coolingRatio
=
x
;
}
;
}
class
SimulatedAnnealingANN_MLP
:
public
ml
::
SimulatedAnnealingSolver
class
SimulatedAnnealingANN_MLP
:
public
ml
::
SimulatedAnnealingSolver
{
{
...
@@ -169,19 +187,23 @@ public:
...
@@ -169,19 +187,23 @@ public:
SimulatedAnnealingANN_MLP
(
ml
::
ANN_MLP
*
x
,
Ptr
<
ml
::
TrainData
>
d
)
:
nn
(
x
),
data
(
d
)
SimulatedAnnealingANN_MLP
(
ml
::
ANN_MLP
*
x
,
Ptr
<
ml
::
TrainData
>
d
)
:
nn
(
x
),
data
(
d
)
{
{
initVarMap
();
initVarMap
();
};
}
void
changedState
()
void
changedState
()
{
{
index
=
rIndex
.
uniform
(
0
,
nbVariables
);
index
=
rIndex
.
uniform
(
0
,
nbVariables
);
double
dv
=
rVar
.
uniform
(
-
1.0
,
1.0
);
double
dv
=
rVar
.
uniform
(
-
1.0
,
1.0
);
varTmp
=
*
adrVariables
[
index
];
varTmp
=
*
adrVariables
[
index
];
*
adrVariables
[
index
]
=
dv
;
*
adrVariables
[
index
]
=
dv
;
};
}
void
reverseChangedState
()
void
reverseChangedState
()
{
{
*
adrVariables
[
index
]
=
varTmp
;
*
adrVariables
[
index
]
=
varTmp
;
};
}
double
energy
()
{
return
nn
->
calcError
(
data
,
false
,
noArray
());
}
double
energy
()
{
return
nn
->
calcError
(
data
,
false
,
noArray
());
}
protected
:
protected
:
void
initVarMap
()
void
initVarMap
()
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment