Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
psimpy
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
mbd
psimpy
Commits
a43c3bc5
Commit
a43c3bc5
authored
2 years ago
by
Hu Zhao
Browse files
Options
Downloads
Patches
Plain Diff
docs: implement example for PPGaSP
parent
af7933c3
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/examples/emulator/robustgasp/plot_ppgasp.py
+109
-0
109 additions, 0 deletions
docs/examples/emulator/robustgasp/plot_ppgasp.py
with
109 additions
and
0 deletions
docs/examples/emulator/robustgasp/plot_ppgasp.py
0 → 100644
+
109
−
0
View file @
a43c3bc5
"""
PPGaSP: GP emulation for multi-output functions
===============================================
"""
# %% md
#
# This example shows how to apply Gaussian process emulation to a multi-output
# function using class :class:`.PPGaSP`.
#
# The multi-output function that we are going to look at is the `DIAMOND`
# (diplomatic and military operations in a non-warfighting domain) computer model.
# It is used as a testbed to illustrate the `PP GaSP` emulator in the `R` package
# `RobustGaSP`, see :cite:t:`Gu2019` for more detail.
#
# The simulator has :math:`13` input parameters and :math:`5` outputs. Namely,
# :math:`\mathbf{y}=f(\mathbf{x})` where :math:`\mathbf{x}=(x_1,\ldots,x_{13})^T`
# and :math:`\mathbf{y}=(y_1,\ldots,y_5)^T`.
#
# The training and testing data are provided in the folder '.../tests/data/'.
# We first load the training and testing data. You may need to modify ``dir_data```
# according to where you save them.
import
numpy
as
np
import
os
dir_data
=
os
.
path
.
abspath
(
'
../../../../tests/data/
'
)
humanityX
=
np
.
genfromtxt
(
os
.
path
.
join
(
dir_data
,
'
humanityX.csv
'
),
delimiter
=
'
,
'
)
humanityY
=
np
.
genfromtxt
(
os
.
path
.
join
(
dir_data
,
'
humanityY.csv
'
),
delimiter
=
'
,
'
)
print
(
f
"
Number of training data points:
"
,
humanityX
.
shape
[
0
])
print
(
f
"
Input dimension:
"
,
humanityX
.
shape
[
1
])
print
(
f
"
Output dimension:
"
,
humanityY
.
shape
[
1
])
humanityXt
=
np
.
genfromtxt
(
os
.
path
.
join
(
dir_data
,
'
humanityXt.csv
'
),
delimiter
=
'
,
'
)
humanityYt
=
np
.
genfromtxt
(
os
.
path
.
join
(
dir_data
,
'
humanityYt.csv
'
),
delimiter
=
'
,
'
)
print
(
f
"
Number of testing data points:
"
,
humanityXt
.
shape
[
0
])
# %% md
# ``humanityX`` and ``humanitY`` are the training data, corresponding to ``design``
# and ``response`` respectively. ``humanityXt`` are testing input data, at which
# we are going to make predictions once the emulator is trained. ``humanityYt``
# are the true outputs at ``humanityXt``, which is then used to validate the
# performance of the trained emulator.
# %% md
#
# To build a `PP GaSP` emulator for the above simulator, first import class
# :class:`.PPGaSP` by
from
psimpy.emulator
import
PPGaSP
# %% md
#
# Then, create an instance of :class:`.PPGaSP`. The parameter ``ndim``
# (dimension of function input ``x``) must be specified. Optional parameters, such
# as ``method``, ``kernel_type``, etc., can be set up if desired. Here, we leave
# all the optional parameters to their default values.
emulator
=
PPGaSP
(
ndim
=
humanityX
.
shape
[
1
])
# %% md
#
# Next, we train the `PP GaSP` emulator based on the training data using
# :py:meth:`.PPGaSP.train` method.
emulator
.
train
(
design
=
humanityX
,
response
=
humanityY
)
# %% md
#
# With the trained emulator, we can make predictions for any arbitrary set of
# input points using :py:meth:`PPGaSP.predict` method.
# Here, we make predictions at testing input points ``humanityXt``.
predictions
=
emulator
.
predict
(
humanityXt
)
# %% md
#
# We can validate the performance of the trained emulator based on the true outputs
# ``humanityYt``.
import
matplotlib.pyplot
as
plt
fig
,
ax
=
plt
.
subplots
(
5
,
1
,
figsize
=
(
6
,
15
))
for
i
in
range
(
humanityY
.
shape
[
1
]):
ax
[
i
].
set_xlabel
(
f
'
Actual $y_
{
i
+
1
}
$
'
)
ax
[
i
].
set_ylabel
(
f
'
Emulator-predicted $y_
{
i
+
1
}
$
'
)
ax
[
i
].
set_xlim
(
np
.
min
(
humanityYt
[:,
i
]),
np
.
max
(
humanityYt
[:,
i
]))
ax
[
i
].
set_ylim
(
np
.
min
(
humanityYt
[:,
i
]),
np
.
max
(
humanityYt
[:,
i
]))
_
=
ax
[
i
].
plot
([
np
.
min
(
humanityYt
[:,
i
]),
np
.
max
(
humanityYt
[:,
i
])],
[
np
.
min
(
humanityYt
[:,
i
]),
np
.
max
(
humanityYt
[:,
i
])])
_
=
ax
[
i
].
errorbar
(
humanityYt
[:,
i
],
predictions
[:,
i
,
0
],
predictions
[:,
i
,
3
],
fmt
=
'
.
'
,
linestyle
=
''
,
label
=
'
prediction and std
'
)
_
=
ax
[
i
].
legend
()
plt
.
tight_layout
()
# %%md
#
# We can also draw any number of samples at testing input ``humanityXt`` using
# :py:meth:`.PPGaSPsample()` method.
samples
=
emulator
.
sample
(
humanityXt
,
nsamples
=
10
)
print
(
"
Shape of samples:
"
,
samples
.
shape
)
\ No newline at end of file
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