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
0d791189
Commit
0d791189
authored
Oct 12, 2015
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5486 from amroamroamro:fix_ml_randMVNormal
parents
0f1fdd88
13a0a37e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
4 deletions
+11
-4
inner_functions.cpp
modules/ml/src/inner_functions.cpp
+11
-4
No files found.
modules/ml/src/inner_functions.cpp
View file @
0d791189
...
...
@@ -151,21 +151,28 @@ static void Cholesky( const Mat& A, Mat& S )
average row vector, <cov> - symmetric covariation matrix */
void
randMVNormal
(
InputArray
_mean
,
InputArray
_cov
,
int
nsamples
,
OutputArray
_samples
)
{
// check mean vector and covariance matrix
Mat
mean
=
_mean
.
getMat
(),
cov
=
_cov
.
getMat
();
int
dim
=
(
int
)
mean
.
total
();
int
dim
=
(
int
)
mean
.
total
();
// dimensionality
CV_Assert
(
mean
.
rows
==
1
||
mean
.
cols
==
1
);
CV_Assert
(
cov
.
rows
==
dim
&&
cov
.
cols
==
dim
);
mean
=
mean
.
reshape
(
1
,
1
);
// ensure a row vector
// generate n-samples of the same dimension, from ~N(0,1)
_samples
.
create
(
nsamples
,
dim
,
CV_32F
);
Mat
samples
=
_samples
.
getMat
();
rand
u
(
samples
,
0.
,
1.
);
rand
n
(
samples
,
Scalar
::
all
(
0
),
Scalar
::
all
(
1
)
);
// decompose covariance using Cholesky: cov = U'*U
// (cov must be square, symmetric, and positive semi-definite matrix)
Mat
utmat
;
Cholesky
(
cov
,
utmat
);
int
flags
=
mean
.
cols
==
1
?
0
:
GEMM_3_T
;
// transform random numbers using specified mean and covariance
for
(
int
i
=
0
;
i
<
nsamples
;
i
++
)
{
Mat
sample
=
samples
.
row
(
i
);
gemm
(
sample
,
utmat
,
1
,
mean
,
1
,
sample
,
flags
)
;
sample
=
sample
*
utmat
+
mean
;
}
}
...
...
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