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
!99
Resolve "Learner1D's bound check algo in self.ask doesn't take self.data or self.pending_points"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Learner1D's bound check algo in self.ask doesn't take self.data or self.pending_points"
95--take-known-points-into-account-when-asking-bounds
into
master
Overview
37
Commits
2
Pipelines
25
Changes
3
Merged
Jorn Hoofwijk
requested to merge
95--take-known-points-into-account-when-asking-bounds
into
master
6 years ago
Overview
32
Commits
2
Pipelines
25
Changes
3
Expand
Closes
#95 (closed)
currently the tests fail, this should be fixed
add some more tests to check uniformity of the return value
Edited
6 years ago
by
Jorn Hoofwijk
0
0
Merge request reports
Compare
master
version 25
382efaf2
6 years ago
version 24
75e2a740
6 years ago
version 23
0837260d
6 years ago
version 22
bb713e29
6 years ago
version 21
a932f163
6 years ago
version 20
bef41424
6 years ago
version 19
bef41424
6 years ago
version 18
3bd66543
6 years ago
version 17
b9ec5f5b
6 years ago
version 16
465e19da
6 years ago
version 15
0dbfb684
6 years ago
version 14
a6e11211
6 years ago
version 13
37b4ddc7
6 years ago
version 12
6341cff5
6 years ago
version 11
800f6d89
6 years ago
version 10
61e1bf67
6 years ago
version 9
9c015a90
6 years ago
version 8
7b34a038
6 years ago
version 7
d6dfa212
6 years ago
version 6
4f70db6f
6 years ago
version 5
8437e364
6 years ago
version 4
4220fb53
6 years ago
version 3
30e4abfc
6 years ago
version 2
1f4fb5ce
6 years ago
version 1
992151a8
6 years ago
master (base)
and
version 6
latest version
f73a1abc
2 commits,
6 years ago
version 25
382efaf2
2 commits,
6 years ago
version 24
75e2a740
2 commits,
6 years ago
version 23
0837260d
2 commits,
6 years ago
version 22
bb713e29
2 commits,
6 years ago
version 21
a932f163
2 commits,
6 years ago
version 20
bef41424
3 commits,
6 years ago
version 19
bef41424
2 commits,
6 years ago
version 18
3bd66543
2 commits,
6 years ago
version 17
b9ec5f5b
2 commits,
6 years ago
version 16
465e19da
2 commits,
6 years ago
version 15
0dbfb684
2 commits,
6 years ago
version 14
a6e11211
2 commits,
6 years ago
version 13
37b4ddc7
2 commits,
6 years ago
version 12
6341cff5
2 commits,
6 years ago
version 11
800f6d89
2 commits,
6 years ago
version 10
61e1bf67
2 commits,
6 years ago
version 9
9c015a90
19 commits,
6 years ago
version 8
7b34a038
18 commits,
6 years ago
version 7
d6dfa212
14 commits,
6 years ago
version 6
4f70db6f
10 commits,
6 years ago
version 5
8437e364
8 commits,
6 years ago
version 4
4220fb53
7 commits,
6 years ago
version 3
30e4abfc
6 commits,
6 years ago
version 2
1f4fb5ce
5 commits,
6 years ago
version 1
992151a8
3 commits,
6 years ago
3 files
+
128
−
35
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
adaptive/learner/learner1D.py
+
84
−
35
Options
@@ -287,44 +287,93 @@ class Learner1D(BaseLearner):
if
n
==
0
:
return
[],
[]
# Some temporary functions we are gonna need later in ask().
# xs is very similar to np.linspace but doesn't include the bounds
def
xs
(
x_left
,
x_right
,
n
):
if
n
==
1
:
# This is just an optimization
return
[]
else
:
step
=
(
x_right
-
x_left
)
/
n
return
[
x_left
+
step
*
i
for
i
in
range
(
1
,
n
)]
x_scale
=
self
.
_scale
[
0
]
def
finite_loss
(
loss
,
xs
):
# if the loss is infinite, return the distance between the two points
if
math
.
isinf
(
loss
):
return
(
xs
[
1
]
-
xs
[
0
])
/
x_scale
return
loss
# If the bounds have not been chosen yet, we choose them first.
missing_bounds
=
[
b
for
b
in
self
.
bounds
if
b
not
in
self
.
data
and
b
not
in
self
.
pending_points
]
if
missing_bounds
:
loss_improvements
=
[
np
.
inf
]
*
n
# XXX: should check if points are present in self.data or self.pending_points
points
=
np
.
linspace
(
*
self
.
bounds
,
n
+
2
-
len
(
missing_bounds
)).
tolist
()
if
len
(
missing_bounds
)
==
1
:
points
=
points
[
1
:]
if
missing_bounds
[
0
]
==
self
.
bounds
[
1
]
else
points
[:
-
1
]
else
:
def
xs
(
x_left
,
x_right
,
n
):
if
n
==
1
:
# This is just an optimization
return
[]
else
:
step
=
(
x_right
-
x_left
)
/
n
return
[
x_left
+
step
*
i
for
i
in
range
(
1
,
n
)]
# Calculate how many points belong to each interval.
x_scale
=
self
.
_scale
[
0
]
quals
=
[((
-
loss
if
not
math
.
isinf
(
loss
)
else
-
(
x
[
1
]
-
x
[
0
])
/
x_scale
,
x
,
1
))
for
x
,
loss
in
self
.
losses_combined
.
items
()]
heapq
.
heapify
(
quals
)
for
point_number
in
range
(
n
):
quality
,
x
,
n
=
quals
[
0
]
if
abs
(
x
[
1
]
-
x
[
0
])
/
(
n
+
1
)
<=
self
.
_dx_eps
:
# The interval is too small and should not be subdivided
quality
=
np
.
inf
heapq
.
heapreplace
(
quals
,
(
quality
*
n
/
(
n
+
1
),
x
,
n
+
1
))
points
=
list
(
itertools
.
chain
.
from_iterable
(
xs
(
*
x
,
n
)
for
quality
,
x
,
n
in
quals
))
loss_improvements
=
list
(
itertools
.
chain
.
from_iterable
(
itertools
.
repeat
(
-
quality
,
n
-
1
)
for
quality
,
x
,
n
in
quals
))
if
len
(
missing_bounds
)
>=
n
:
# shortcut as we do not need to find any more points
if
add_data
:
self
.
tell_many
(
missing_bounds
[:
n
],
itertools
.
repeat
(
None
))
return
missing_bounds
[:
n
],
[
np
.
inf
]
*
n
quals
=
[(
-
finite_loss
(
loss
,
x
),
x
,
1
)
for
x
,
loss
in
self
.
losses_combined
.
items
()]
if
len
(
missing_bounds
)
==
0
:
pass
# perfect, do nothing
elif
len
(
missing_bounds
)
==
1
:
# add a connection from the bound to the nearest point/pending_point
x1
,
=
missing_bounds
all_x_combined
=
list
(
set
(
self
.
data
.
keys
())
|
self
.
pending_points
)
assert
len
(
all_x_combined
)
>
0
# because at least the other bound should be in here
if
x1
==
self
.
bounds
[
0
]:
# left bound -> find minimum x and connect
other
=
np
.
min
(
all_x_combined
)
x
=
(
x1
,
other
)
quals
.
append
((
-
finite_loss
(
np
.
inf
,
x
),
x
,
1
))
else
:
# right bound -> find maximum x and connect
other
=
np
.
max
(
all_x_combined
)
x
=
(
other
,
x1
)
+4
quals
.
append
((
-
finite_loss
(
np
.
inf
,
x
),
x
,
1
))
elif
len
(
missing_bounds
)
==
2
:
# add the bounds to quals
x1
,
x2
=
missing_bounds
# sort just to be sure
assert
x2
>
x1
all_x_combined
=
list
(
set
(
self
.
data
.
keys
())
|
self
.
pending_points
)
if
len
(
all_x_combined
)
==
0
:
# XXX: shortcut for performance, just return linspace
x
=
x1
,
x2
quals
.
append
((
-
finite_loss
(
np
.
inf
,
x
),
x
,
1
))
else
:
left_interval
=
(
x1
,
np
.
min
(
all_x_combined
))
right_interval
=
(
np
.
max
(
all_x_combined
),
x2
)
quals
.
append
((
-
finite_loss
(
np
.
inf
,
right_interval
),
right_interval
,
1
))
quals
.
append
((
-
finite_loss
(
np
.
inf
,
left_interval
),
left_interval
,
1
))
# Calculate how many points belong to each interval.
heapq
.
heapify
(
quals
)
for
_point_number
in
range
(
n
-
len
(
missing_bounds
)):
quality
,
x
,
n
=
quals
[
0
]
if
abs
(
x
[
1
]
-
x
[
0
])
/
(
n
+
1
)
<=
self
.
_dx_eps
:
# The interval is too small and should not be subdivided
quality
=
np
.
inf
heapq
.
heapreplace
(
quals
,
(
quality
*
n
/
(
n
+
1
),
x
,
n
+
1
))
points
=
list
(
itertools
.
chain
.
from_iterable
(
xs
(
*
x
,
n
)
for
quality
,
x
,
n
in
quals
))
loss_improvements
=
list
(
itertools
.
chain
.
from_iterable
(
itertools
.
repeat
(
-
quality
,
n
-
1
)
for
quality
,
x
,
n
in
quals
))
points
=
missing_bounds
+
points
loss_improvements
=
[
np
.
inf
]
*
len
(
missing_bounds
)
+
loss_improvements
if
add_data
:
self
.
tell_many
(
points
,
itertools
.
repeat
(
None
))
Loading