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
6d7da716
Commit
6d7da716
authored
6 years ago
by
Bas Nijholt
Browse files
Options
Downloads
Patches
Plain Diff
simplifications
parent
0e0dd5da
No related branches found
No related tags found
No related merge requests found
Pipeline
#13088
passed
6 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
adaptive/learner/learner1D.py
+9
-11
9 additions, 11 deletions
adaptive/learner/learner1D.py
with
9 additions
and
11 deletions
adaptive/learner/learner1D.py
+
9
−
11
View file @
6d7da716
...
...
@@ -121,11 +121,13 @@ def _get_neighbors_from_list(xs):
return
sortedcontainers
.
SortedDict
(
neighbors
)
def
_get_interval
(
x
,
neighbors
,
nn_neighbors
):
def
_get_interval
s
(
x
,
neighbors
,
nn_neighbors
):
n
=
nn_neighbors
index
=
neighbors
.
bisect_left
(
x
)
return
[
neighbors
.
iloc
[
i
]
for
i
in
range
(
index
-
n
-
1
,
index
+
2
+
n
)
if
0
<=
i
<
len
(
neighbors
)]
points
=
[
neighbors
.
iloc
[
i
]
for
i
in
range
(
index
-
n
-
1
,
index
+
2
+
n
)
if
0
<=
i
<
len
(
neighbors
)]
intervals
=
zip
(
points
,
points
[
1
:])
return
list
(
intervals
)
class
Learner1D
(
BaseLearner
):
...
...
@@ -243,9 +245,8 @@ class Learner1D(BaseLearner):
return
0
# we need to compute the loss for this interval
interval
=
(
x_left
,
x_right
)
return
self
.
loss_per_interval
(
interval
,
self
.
_scale
,
self
.
data
,
self
.
neighbors
)
(
x_left
,
x_right
)
,
self
.
_scale
,
self
.
data
,
self
.
neighbors
)
def
_update_interpolated_loss_in_interval
(
self
,
x_left
,
x_right
):
...
...
@@ -281,8 +282,7 @@ class Learner1D(BaseLearner):
# (x_left, x), (x, x_right) and the nn_neighbors nearest
# neighboring intervals. Since the addition of the
# point 'x' could change their loss.
points
=
_get_interval
(
x
,
self
.
neighbors
,
self
.
nn_neighbors
)
for
ival
in
zip
(
points
,
points
[
1
:]):
for
ival
in
_get_intervals
(
x
,
self
.
neighbors
,
self
.
nn_neighbors
):
self
.
_update_interpolated_loss_in_interval
(
*
ival
)
# Since 'x' is in between (x_left, x_right),
...
...
@@ -429,10 +429,8 @@ class Learner1D(BaseLearner):
# The the losses for the "real" intervals.
self
.
losses
=
{}
for
x_left
,
x_right
in
intervals
:
self
.
losses
[
x_left
,
x_right
]
=
(
self
.
_get_loss_in_interval
(
x_left
,
x_right
)
if
x_right
-
x_left
>=
self
.
_dx_eps
else
0
)
for
ival
in
intervals
:
self
.
losses
[
ival
]
=
self
.
_get_loss_in_interval
(
*
ival
)
# List with "real" intervals that have interpolated intervals inside
to_interpolate
=
[]
...
...
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