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
6e796da0
Commit
6e796da0
authored
2 years ago
by
Hu Zhao
Browse files
Options
Downloads
Patches
Plain Diff
test: add test for init error check of active learning
parent
c44d5541
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
tests/test_active_learning.py
+106
-0
106 additions, 0 deletions
tests/test_active_learning.py
with
106 additions
and
0 deletions
tests/test_active_learning.py
0 → 100644
+
106
−
0
View file @
6e796da0
import
pytest
import
numpy
as
np
from
psimpy.inference.active_learning
import
ActiveLearning
from
psimpy.simulator.run_simulator
import
RunSimulator
from
psimpy.simulator.mass_point_model
import
MassPointModel
from
psimpy.sampler.latin
import
LHS
from
psimpy.sampler.saltelli
import
Saltelli
from
psimpy.emulator.robustgasp
import
ScalarGaSP
,
PPGaSP
from
scipy.stats
import
uniform
,
norm
from
scipy
import
optimize
from
beartype.roar
import
BeartypeCallHintParamViolation
@pytest.mark.parametrize
(
"
run_sim_obj, prior, likelihood, lhs_sampler, scalar_gasp, optimizer
"
,
[
(
MassPointModel
(),
uniform
.
pdf
,
norm
.
pdf
,
LHS
(
1
),
ScalarGaSP
(
1
),
optimize
.
brute
),
(
RunSimulator
(
MassPointModel
.
run
,
[
'
coulomb_friction
'
]),
None
,
norm
.
pdf
,
LHS
(
1
),
ScalarGaSP
(
1
),
optimize
.
brute
),
(
RunSimulator
(
MassPointModel
.
run
,
[
'
coulomb_friction
'
]),
uniform
.
pdf
,
None
,
LHS
(
1
),
ScalarGaSP
(
1
),
optimize
.
brute
),
(
RunSimulator
(
MassPointModel
.
run
,
[
'
coulomb_friction
'
]),
uniform
.
pdf
,
norm
.
pdf
,
Saltelli
(
1
),
ScalarGaSP
(
1
),
optimize
.
brute
),
(
RunSimulator
(
MassPointModel
.
run
,
[
'
coulomb_friction
'
]),
uniform
.
pdf
,
norm
.
pdf
,
LHS
(
1
),
PPGaSP
(
1
),
optimize
.
brute
),
(
RunSimulator
(
MassPointModel
.
run
,
[
'
coulomb_friction
'
]),
uniform
.
pdf
,
norm
.
pdf
,
LHS
(
1
),
ScalarGaSP
(
1
),
None
)
]
)
def
test_ActiveLearning_init_TypeError
(
run_sim_obj
,
prior
,
likelihood
,
lhs_sampler
,
scalar_gasp
,
optimizer
):
ndim
=
1
bounds
=
np
.
array
([[
0
,
1
]])
data
=
np
.
array
([
1
,
2
,
3
])
n0
=
20
nt
=
100
with
pytest
.
raises
(
BeartypeCallHintParamViolation
):
_
=
ActiveLearning
(
ndim
,
bounds
,
data
,
run_sim_obj
,
prior
,
likelihood
,
n0
,
nt
,
lhs_sampler
,
scalar_gasp
,
optimizer
=
optimizer
)
@pytest.mark.parametrize
(
"
run_sim_obj, lhs_sampler, scalar_gasp
"
,
[
(
RunSimulator
(
MassPointModel
.
run
,
[
'
coulomb_friction
'
,
'
turbulent_friction
'
]),
LHS
(
1
),
ScalarGaSP
(
1
)
),
(
RunSimulator
(
MassPointModel
.
run
,
[
'
coulomb_friction
'
]),
LHS
(
2
),
ScalarGaSP
(
1
)),
(
RunSimulator
(
MassPointModel
.
run
,
[
'
coulomb_friction
'
]),
LHS
(
1
),
ScalarGaSP
(
3
))
]
)
def
test_ActiveLearning_init_RuntimeError
(
run_sim_obj
,
lhs_sampler
,
scalar_gasp
):
ndim
=
1
bounds
=
np
.
array
([[
0
,
1
]])
data
=
np
.
array
([
1
,
2
,
3
])
prior
=
uniform
.
pdf
likelihood
=
norm
.
pdf
n0
=
20
nt
=
100
with
pytest
.
raises
(
RuntimeError
):
_
=
ActiveLearning
(
ndim
,
bounds
,
data
,
run_sim_obj
,
prior
,
likelihood
,
n0
,
nt
,
lhs_sampler
,
scalar_gasp
)
@pytest.mark.parametrize
(
"
scalar_gasp_mean, indicator
"
,
[
(
'
cubic
'
,
'
entropy
'
),
(
'
linear
'
,
'
divergence
'
)
]
)
def
test_ActiveLearning_init_NotImplementedError
(
scalar_gasp_mean
,
indicator
):
ndim
=
1
bounds
=
np
.
array
([[
0
,
1
]])
data
=
np
.
array
([
1
,
2
,
3
])
run_sim_obj
=
RunSimulator
(
MassPointModel
.
run
,
[
'
coulomb_friction
'
])
lhs_sampler
=
LHS
(
1
)
scalar_gasp
=
ScalarGaSP
(
1
)
prior
=
uniform
.
pdf
likelihood
=
norm
.
pdf
n0
=
20
nt
=
100
with
pytest
.
raises
(
NotImplementedError
):
_
=
ActiveLearning
(
ndim
,
bounds
,
data
,
run_sim_obj
,
prior
,
likelihood
,
n0
,
nt
,
lhs_sampler
,
scalar_gasp
,
scalar_gasp_mean
=
scalar_gasp_mean
,
indicator
=
indicator
)
def
test_ActiveLearning_init_ValueError
():
ndim
=
1
bounds
=
np
.
array
([[
0
,
1
]])
data
=
np
.
array
([
1
,
2
,
3
])
run_sim_obj
=
RunSimulator
(
MassPointModel
.
run
,
[
'
coulomb_friction
'
])
lhs_sampler
=
LHS
(
1
)
scalar_gasp
=
ScalarGaSP
(
1
)
prior
=
uniform
.
pdf
likelihood
=
norm
.
pdf
n0
=
20
nt
=
100
kwgs_optimizer
=
{
"
NS
"
:
50
}
with
pytest
.
raises
(
ValueError
):
_
=
ActiveLearning
(
ndim
,
bounds
,
data
,
run_sim_obj
,
prior
,
likelihood
,
n0
,
nt
,
lhs_sampler
,
scalar_gasp
,
kwgs_optimizer
=
kwgs_optimizer
)
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