Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PE_CBL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Stefano Serafin
PE_CBL
Commits
40a747ed
Commit
40a747ed
authored
4 months ago
by
Stefano Serafin
Browse files
Options
Downloads
Patches
Plain Diff
added ability to randomize true system states (besides observations and coordinates)
parent
9cf5a3ed
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
observations.py
+27
-9
27 additions, 9 deletions
observations.py
with
27 additions
and
9 deletions
observations.py
+
27
−
9
View file @
40a747ed
...
...
@@ -39,7 +39,7 @@ def decode_observations(observation_files):
return
observations
,
ocoords
def
random_sort_observations
(
observations
,
ocoords
):
def
random_sort_observations
(
observations
,
ocoords
,
truths
=
None
):
# Check that input arrays have consistent dimensions
assert
(
observations
.
shape
==
ocoords
.
shape
),
\
...
...
@@ -50,14 +50,32 @@ def random_sort_observations(observations,ocoords):
shuffled_obs
=
np
.
zeros
(
observations
.
shape
)
+
np
.
nan
shuffled_coords
=
np
.
zeros
(
observations
.
shape
)
+
np
.
nan
# Randomize observation order, differently at each time
indices
=
np
.
arange
(
nobs
)
for
i
in
range
(
nassim
):
np
.
random
.
shuffle
(
indices
)
shuffled_obs
[
i
,:]
=
observations
[
i
,
indices
]
shuffled_coords
[
i
,:]
=
ocoords
[
i
,
indices
]
return
shuffled_obs
,
shuffled_coords
# Randomize arrays, differently at each time
if
truths
is
None
:
indices
=
np
.
arange
(
nobs
)
for
i
in
range
(
nassim
):
np
.
random
.
shuffle
(
indices
)
shuffled_obs
[
i
,:]
=
observations
[
i
,
indices
]
shuffled_coords
[
i
,:]
=
ocoords
[
i
,
indices
]
return
shuffled_obs
,
shuffled_coords
else
:
# Check that truths array has consistent dimensions
assert
(
truths
.
shape
==
ocoords
.
shape
),
\
f
'
observation and coordinate arrays must have the same size
'
# Preallocate truths array
shuffled_truths
=
np
.
zeros
(
ocoords
.
shape
)
+
np
.
nan
# Randomize arrays, differently at each time
indices
=
np
.
arange
(
nobs
)
for
i
in
range
(
nassim
):
np
.
random
.
shuffle
(
indices
)
shuffled_obs
[
i
,:]
=
observations
[
i
,
indices
]
shuffled_coords
[
i
,:]
=
ocoords
[
i
,
indices
]
shuffled_truths
[
i
,:]
=
truths
[
i
,
indices
]
return
shuffled_obs
,
shuffled_coords
,
shuffled_truths
if
__name__
==
'
__main__
'
:
...
...
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