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
Commits
9206b46b
Commit
9206b46b
authored
6 years ago
by
Bas Nijholt
Browse files
Options
Downloads
Patches
Plain Diff
LearnerND: create 'tell_pending' which deprecates 'tell(x, None)'
parent
4eb68018
No related branches found
No related tags found
1 merge request
!107
Introduce 'tell_pending' which replaces 'tell(x, None)'
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
adaptive/learner/learnerND.py
+20
-11
20 additions, 11 deletions
adaptive/learner/learnerND.py
with
20 additions
and
11 deletions
adaptive/learner/learnerND.py
+
20
−
11
View file @
9206b46b
...
...
@@ -8,11 +8,12 @@ import numpy as np
from
scipy
import
interpolate
import
scipy.spatial
from
..notebook_integration
import
ensure_holoviews
from
.base_learner
import
BaseLearner
from
.triangulation
import
Triangulation
,
point_in_simplex
,
\
circumsphere
,
simplex_volume_in_embedding
from
..notebook_integration
import
ensure_holoviews
from
.triangulation
import
(
Triangulation
,
point_in_simplex
,
circumsphere
,
simplex_volume_in_embedding
)
from
..utils
import
restore
def
volume
(
simplex
,
ys
=
None
):
...
...
@@ -245,7 +246,7 @@ class LearnerND(BaseLearner):
return
# we already know about the point
if
value
is
None
:
return
self
.
_
tell_pending
(
point
)
return
self
.
tell_pending
(
point
)
self
.
_pending
.
discard
(
point
)
tri
=
self
.
tri
...
...
@@ -263,7 +264,7 @@ class LearnerND(BaseLearner):
simplex
=
tuple
(
sorted
(
simplex
))
return
simplex
in
self
.
tri
.
simplices
def
_
tell_pending
(
self
,
point
,
simplex
=
None
):
def
tell_pending
(
self
,
point
,
*
,
simplex
=
None
):
point
=
tuple
(
point
)
self
.
_pending
.
add
(
point
)
...
...
@@ -309,15 +310,23 @@ class LearnerND(BaseLearner):
heapq
.
heappush
(
self
.
_simplex_queue
,
(
-
subloss
,
simplex
,
subsimplex
))
def
ask
(
self
,
n
=
1
):
def
_
ask
_and_tell_pending
(
self
,
n
=
1
):
xs
,
losses
=
zip
(
*
(
self
.
_ask
()
for
_
in
range
(
n
)))
return
list
(
xs
),
list
(
losses
)
def
ask
(
self
,
n
,
tell_pending
=
True
):
"""
Chose points for learners.
"""
if
not
tell_pending
:
with
restore
(
self
):
return
self
.
_ask_and_tell_pending
(
n
)
else
:
return
self
.
_ask_and_tell_pending
(
n
)
def
_ask_bound_point
(
self
):
# get the next bound point that is still available
new_point
=
next
(
p
for
p
in
self
.
_bounds_points
if
p
not
in
self
.
data
and
p
not
in
self
.
_pending
)
self
.
_
tell_pending
(
new_point
)
self
.
tell_pending
(
new_point
)
return
new_point
,
np
.
inf
def
_ask_point_without_known_simplices
(
self
):
...
...
@@ -330,7 +339,7 @@ class LearnerND(BaseLearner):
p
=
r
*
a
+
b
p
=
tuple
(
p
)
self
.
_
tell_pending
(
p
)
self
.
tell_pending
(
p
)
return
p
,
np
.
inf
def
_pop_highest_existing_simplex
(
self
):
...
...
@@ -350,8 +359,8 @@ class LearnerND(BaseLearner):
# Could not find a simplex, this code should never be reached
assert
self
.
tri
is
not
None
raise
AssertionError
(
""
"
Could not find a simplex to. Yet there should always be a simplex
available if LearnerND.tri() is not None
"
""
"
Could not find a simplex to. Yet there should always be a simplex
"
"
available if LearnerND.tri() is not None
"
)
def
_ask_best_point
(
self
):
...
...
@@ -371,7 +380,7 @@ class LearnerND(BaseLearner):
transform
=
self
.
_transform
))
self
.
_pending_to_simplex
[
point_new
]
=
simplex
self
.
_
tell_pending
(
point_new
,
simplex
)
# O(??)
self
.
tell_pending
(
point_new
,
simplex
=
simplex
)
# O(??)
return
point_new
,
loss
...
...
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