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
6cbd36fd
Commit
6cbd36fd
authored
Apr 10, 2012
by
Maria Dimashova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed likelihood computing
parent
411467ea
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
8 deletions
+9
-8
em.cpp
modules/ml/src/em.cpp
+9
-8
No files found.
modules/ml/src/em.cpp
View file @
6cbd36fd
...
...
@@ -511,26 +511,27 @@ void EM::computeProbabilities(const Mat& sample, int& label, Mat* probs, double*
if
(
!
probs
&&
!
logLikelihood
)
return
;
Mat
buf
,
*
sampleProbs
=
probs
?
probs
:
&
buf
;
Mat
expL_Lmax
(
L
.
size
(),
CV_64FC1
);
double
maxLVal
=
L
.
at
<
double
>
(
label
);
for
(
int
i
=
0
;
i
<
L
.
cols
;
i
++
)
expL_Lmax
.
at
<
double
>
(
i
)
=
std
::
exp
(
L
.
at
<
double
>
(
i
)
-
maxLVal
);
double
partSum
=
0
,
// sum_j!=q (exp(L_ij - L_iq))
factor
;
// 1/(1 + partExpSum)
double
partSum
=
0
;
// sum_j!=q (exp(L_ij - L_iq))
for
(
int
clusterIndex
=
0
;
clusterIndex
<
nclusters
;
clusterIndex
++
)
if
(
clusterIndex
!=
label
)
partSum
+=
expL_Lmax
.
at
<
double
>
(
clusterIndex
);
factor
=
1.
/
(
1
+
partSum
);
sampleProbs
->
create
(
1
,
nclusters
,
CV_64FC1
);
expL_Lmax
*=
factor
;
expL_Lmax
.
copyTo
(
*
sampleProbs
);
if
(
probs
)
{
probs
->
create
(
1
,
nclusters
,
CV_64FC1
);
double
factor
=
1.
/
(
1
+
partSum
);
expL_Lmax
*=
factor
;
expL_Lmax
.
copyTo
(
*
probs
);
}
if
(
logLikelihood
)
{
double
logWeightProbs
=
std
::
log
(
weights
.
dot
(
*
sampleProbs
))
;
double
logWeightProbs
=
std
::
log
(
(
1
+
partSum
)
*
std
::
exp
(
maxLVal
))
-
0.5
*
dim
*
CV_LOG2PI
;
*
logLikelihood
=
logWeightProbs
;
}
}
...
...
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