Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
lbmpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
lbmpy
Commits
f58babba
Commit
f58babba
authored
10 months ago
by
Helen Schottenhamml
Browse files
Options
Downloads
Patches
Plain Diff
Fix flake warnings.
parent
09e7f670
No related branches found
No related tags found
1 merge request
!175
Welford algorithm extension
Pipeline
#68741
passed
10 months ago
Stage: pretest
Stage: test
Stage: docs
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lbmpy/flow_statistics.py
+9
-8
9 additions, 8 deletions
src/lbmpy/flow_statistics.py
tests/test_welford.py
+7
-3
7 additions, 3 deletions
tests/test_welford.py
with
16 additions
and
11 deletions
src/lbmpy/flow_statistics.py
+
9
−
8
View file @
f58babba
...
...
@@ -14,8 +14,8 @@ def welford_assignments(field, mean_field, sum_of_squares_field=None, sum_of_cub
the sum of squares / sum of cubes is given.
The mean value is directly updated in the mean vector field.
The variance / covariance must be retrieved in a post-processing step. Let :math `M_{2,n}` denote the value of the
sum of
squares after the first :math `n` samples. According to Welford the biased sample variance
The variance / covariance must be retrieved in a post-processing step. Let :math `M_{2,n}` denote the value of the
sum of
squares after the first :math `n` samples. According to Welford the biased sample variance
:math `\sigma_n^2` and the unbiased sample variance :math `s_n^2` are given by
.. math ::
...
...
@@ -78,7 +78,7 @@ def welford_assignments(field, mean_field, sum_of_squares_field=None, sum_of_cub
if
welford_sum_of_cubes_field
is
not
None
:
assert
welford_sum_of_squares_field
is
not
None
#
##
actual assignments
# actual assignments
counter
=
sp
.
Symbol
(
'
counter
'
)
delta
=
sp
.
symbols
(
f
"
delta_:
{
dim
}
"
)
...
...
@@ -108,11 +108,12 @@ def welford_assignments(field, mean_field, sum_of_squares_field=None, sum_of_cub
for
k
in
range
(
dim
):
idx
=
(
i
*
dim
+
j
)
*
dim
+
k
main_assignments
.
append
(
ps
.
Assignment
(
welford_sum_of_cubes_field
.
at_index
(
idx
),
welford_sum_of_cubes_field
.
at_index
(
idx
)
-
delta
[
k
]
/
counter
*
welford_sum_of_squares_field
(
i
*
dim
+
j
)
-
delta
[
j
]
/
counter
*
welford_sum_of_squares_field
(
k
*
dim
+
i
)
-
delta
[
i
]
/
counter
*
welford_sum_of_squares_field
(
j
*
dim
+
k
)
+
delta2
[
i
]
*
(
2
*
delta
[
j
]
-
delta2
[
j
])
*
delta
[
k
]
welford_sum_of_cubes_field
.
at_index
(
idx
),
welford_sum_of_cubes_field
.
at_index
(
idx
)
-
delta
[
k
]
/
counter
*
welford_sum_of_squares_field
(
i
*
dim
+
j
)
-
delta
[
j
]
/
counter
*
welford_sum_of_squares_field
(
k
*
dim
+
i
)
-
delta
[
i
]
/
counter
*
welford_sum_of_squares_field
(
j
*
dim
+
k
)
+
delta2
[
i
]
*
(
2
*
delta
[
j
]
-
delta2
[
j
])
*
delta
[
k
]
))
return
main_assignments
This diff is collapsed.
Click to expand it.
tests/test_welford.py
+
7
−
3
View file @
f58babba
...
...
@@ -40,7 +40,7 @@ def test_welford(order, dim):
# set random seed
np
.
random
.
seed
(
42
)
n
=
int
(
1e4
)
x
=
np
.
random
.
normal
(
size
=
n
*
dim
).
reshape
(
n
,
dim
)
x
=
np
.
random
.
normal
(
size
=
n
*
dim
).
reshape
(
n
,
dim
)
analytical_mean
=
np
.
zeros
(
dim
)
analytical_covariance
=
np
.
zeros
(
dim
**
2
)
...
...
@@ -53,13 +53,17 @@ def test_welford(order, dim):
# calculate analytical covariances
for
i
in
range
(
dim
):
for
j
in
range
(
dim
):
analytical_covariance
[
i
*
dim
+
j
]
=
(
np
.
sum
((
x
[:,
i
]
-
analytical_mean
[
i
])
*
(
x
[:,
j
]
-
analytical_mean
[
j
])))
/
n
analytical_covariance
[
i
*
dim
+
j
]
\
=
(
np
.
sum
((
x
[:,
i
]
-
analytical_mean
[
i
])
*
(
x
[:,
j
]
-
analytical_mean
[
j
])))
/
n
# calculate analytical third-order central moments
for
i
in
range
(
dim
):
for
j
in
range
(
dim
):
for
k
in
range
(
dim
):
analytical_third_order_moments
[(
i
*
dim
+
j
)
*
dim
+
k
]
=
(
np
.
sum
((
x
[:,
i
]
-
analytical_mean
[
i
])
*
(
x
[:,
j
]
-
analytical_mean
[
j
])
*
(
x
[:,
k
]
-
analytical_mean
[
k
])))
/
n
analytical_third_order_moments
[(
i
*
dim
+
j
)
*
dim
+
k
]
\
=
(
np
.
sum
((
x
[:,
i
]
-
analytical_mean
[
i
])
*
(
x
[:,
j
]
-
analytical_mean
[
j
])
*
(
x
[:,
k
]
-
analytical_mean
[
k
])))
/
n
# Time loop
counter
=
1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment