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
0f1f7b0b
Commit
0f1f7b0b
authored
Apr 06, 2012
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed a few VS2010 warnings in EM
parent
2291faed
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
9 deletions
+9
-9
em.cpp
modules/ml/src/em.cpp
+8
-8
test_emknearestkmeans.cpp
modules/ml/test/test_emknearestkmeans.cpp
+1
-1
No files found.
modules/ml/src/em.cpp
View file @
0f1f7b0b
...
...
@@ -44,7 +44,7 @@
namespace
cv
{
const
float
minEigenValue
=
1.e-3
;
const
float
minEigenValue
=
1.e-3
f
;
EM
::
Params
::
Params
(
int
nclusters
,
int
covMatType
,
int
startStep
,
const
cv
::
TermCriteria
&
termCrit
,
const
cv
::
Mat
*
probs
,
const
cv
::
Mat
*
weights
,
...
...
@@ -124,7 +124,7 @@ int EM::predict(const cv::Mat& sample, cv::Mat* _probs, double* _likelihood) con
CV_Assert
(
sample
.
type
()
==
CV_32FC1
);
int
label
;
float
likelihood
;
float
likelihood
=
0.
f
;
computeProbabilities
(
sample
,
label
,
_probs
,
_likelihood
?
&
likelihood
:
0
);
if
(
_likelihood
)
*
_likelihood
=
static_cast
<
double
>
(
likelihood
);
...
...
@@ -254,7 +254,7 @@ void preprocessProbability(cv::Mat& probs)
{
cv
::
max
(
probs
,
0.
,
probs
);
const
float
uniformProbability
=
1.
/
probs
.
cols
;
const
float
uniformProbability
=
(
float
)(
1.
/
probs
.
cols
)
;
for
(
int
y
=
0
;
y
<
probs
.
rows
;
y
++
)
{
cv
::
Mat
sampleProbs
=
probs
.
row
(
y
);
...
...
@@ -395,7 +395,7 @@ void EM::computeLogWeightDivDet()
for
(
int
di
=
0
;
di
<
covsEigenValues
[
clusterIndex
].
cols
;
di
++
)
logDetCov
+=
std
::
log
(
covsEigenValues
[
clusterIndex
].
at
<
float
>
(
covMatType
!=
EM
::
COV_MAT_SPHERICAL
?
di
:
0
));
logWeightDivDet
.
at
<
float
>
(
clusterIndex
)
=
logWeights
.
at
<
float
>
(
clusterIndex
)
-
0.5
*
logDetCov
;
logWeightDivDet
.
at
<
float
>
(
clusterIndex
)
=
logWeights
.
at
<
float
>
(
clusterIndex
)
-
0.5
f
*
logDetCov
;
}
}
...
...
@@ -421,7 +421,7 @@ bool EM::doTrain(const cv::TermCriteria& termCrit)
if
(
startStep
==
EM
::
START_M_STEP
)
mStep
();
double
trainLikelihood
,
prevTrainLikelihood
;
double
trainLikelihood
,
prevTrainLikelihood
=
0.
;
for
(
int
iter
=
0
;
;
iter
++
)
{
eStep
();
...
...
@@ -489,7 +489,7 @@ void EM::computeProbabilities(const cv::Mat& sample, int& label, cv::Mat* probs,
Lval
+=
w
*
val
*
val
;
}
CV_DbgAssert
(
!
logWeightDivDet
.
empty
());
Lval
=
logWeightDivDet
.
at
<
float
>
(
clusterIndex
)
-
0.5
*
Lval
;
Lval
=
logWeightDivDet
.
at
<
float
>
(
clusterIndex
)
-
0.5
f
*
Lval
;
L
.
at
<
float
>
(
clusterIndex
)
=
Lval
;
if
(
Lval
>
L
.
at
<
float
>
(
label
))
...
...
@@ -508,7 +508,7 @@ void EM::computeProbabilities(const cv::Mat& sample, int& label, cv::Mat* probs,
if
(
clusterIndex
!=
label
)
partExpSum
+=
expL
.
at
<
float
>
(
clusterIndex
);
}
factor
=
1.
/
(
1
+
partExpSum
);
factor
=
1.
f
/
(
1
+
partExpSum
);
cv
::
exp
(
L
-
L
.
at
<
float
>
(
label
),
expL
);
...
...
@@ -522,7 +522,7 @@ void EM::computeProbabilities(const cv::Mat& sample, int& label, cv::Mat* probs,
if
(
likelihood
)
{
// note likelihood = log (sum_j exp(L_ij)) - 0.5 * dims * ln2Pi
*
likelihood
=
std
::
log
(
partExpSum
+
expL
.
at
<
float
>
(
label
))
-
0.5
*
dim
*
CV_LOG2PI
;
*
likelihood
=
std
::
log
(
partExpSum
+
expL
.
at
<
float
>
(
label
))
-
(
float
)(
0.5
*
dim
*
CV_LOG2PI
)
;
}
}
...
...
modules/ml/test/test_emknearestkmeans.cpp
View file @
0f1f7b0b
...
...
@@ -490,7 +490,7 @@ protected:
Mat
firstResult
(
samples
.
rows
,
1
,
CV_32FC1
);
for
(
int
i
=
0
;
i
<
samples
.
rows
;
i
++
)
firstResult
.
at
<
float
>
(
i
)
=
em
.
predict
(
samples
.
row
(
i
)
);
firstResult
.
at
<
float
>
(
i
)
=
(
float
)
em
.
predict
(
samples
.
row
(
i
)
);
// Write out
string
filename
=
tempfile
()
+
".xml"
;
...
...
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