Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
adaptive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Quantum Tinkerer
adaptive
Merge requests
!106
add an 'AverageLearner' test that checks the std, mean, and npoints
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
add an 'AverageLearner' test that checks the std, mean, and npoints
average_learner_tests
into
master
Overview
8
Commits
1
Pipelines
5
Changes
1
All threads resolved!
Hide all comments
Merged
Bas Nijholt
requested to merge
average_learner_tests
into
master
6 years ago
Overview
8
Commits
1
Pipelines
5
Changes
1
All threads resolved!
Hide all comments
Expand
0
0
Merge request reports
Compare
master
version 5
a4c8af0b
6 years ago
version 4
80ca6dc8
6 years ago
version 3
da3465bb
6 years ago
version 2
500de48f
6 years ago
version 1
500de48f
6 years ago
master (base)
and
version 2
latest version
4dc4400a
1 commit,
6 years ago
version 5
a4c8af0b
1 commit,
6 years ago
version 4
80ca6dc8
1 commit,
6 years ago
version 3
da3465bb
1 commit,
6 years ago
version 2
500de48f
1 commit,
6 years ago
version 1
500de48f
1 commit,
6 years ago
1 file
+
22
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
adaptive/tests/test_average_learner.py
+
22
−
0
Options
# -*- coding: utf-8 -*-
import
random
import
numpy
as
np
from
..learner
import
AverageLearner
@@ -17,3 +21,21 @@ def test_only_returns_new_points():
assert
learner
.
ask
(
1
)[
0
][
0
]
==
3
assert
learner
.
ask
(
1
)[
0
][
0
]
==
4
assert
learner
.
ask
(
1
)[
0
][
0
]
==
10
def
test_avg_std_and_npoints
():
learner
=
AverageLearner
(
lambda
x
:
x
,
atol
=
None
,
rtol
=
0.01
)
for
i
in
range
(
5000
):
# This will add 5000 points at random values of n.
# It could try to readd already evaluated points.
value
=
random
.
random
()
# With 10% chance None is added to simulate asking that point.
learner
.
tell
(
random
.
randint
(
0
,
2
*
5000
),
value
if
value
<
0.9
else
None
)
if
i
>
2
and
i
%
10
==
0
:
# We need more than two points for 'learner.std' to be defined.
values
=
np
.
array
(
list
(
learner
.
data
.
values
()))
std
=
np
.
sqrt
(
sum
((
values
-
values
.
mean
())
**
2
)
/
(
len
(
values
)
-
1
))
assert
learner
.
npoints
==
len
(
learner
.
data
)
assert
abs
(
learner
.
sum_f
-
values
.
sum
())
<
1e-11
assert
abs
(
learner
.
std
-
std
)
<
1e-14
Loading