Skip to content

add AverageLearner1D and AverageLearner2D - #143

Open
basnijholt wants to merge 8 commits into
mainfrom
AverageLearner2D
Open

add AverageLearner1D and AverageLearner2D#143
basnijholt wants to merge 8 commits into
mainfrom
AverageLearner2D

Conversation

@basnijholt

@basnijholtbasnijholt commented Dec 19, 2018

Copy link
Copy Markdown
Member

(original merge request on GitLab)

opened by Bas Nijholt (@basnijholt) at 2018-06-05T21:40:00.078Z

This merge request implements a Learner2D that can learn averages on the points, the AverageLearner2D.

When choosing points the learner can either

  • add more values at an existing points
  • add more triangles

The learner compares the loss of potential new triangles with the standard error of an existing point.

The relative importance of both can be adjusted by a hyperparameter learner.weight.
From the doc-string:

When weight > 1 adding more points to existing points will be
prioritized (making the standard error of a point more important,)
otherwise adding new triangles will be prioritized (making the
loss of a triangle more important.)

All tests that pass for the Learner2D currently pass for the AvererageLearner2D too.

Run with:

importadaptiveadaptive.notebook_extension()
defring(xys, wait=False):
importnumpyasnpfromtimeimportsleepfromrandomimportrandomxy, _=xysifwait:
sleep(random()/100)
x, y=xya=0.2return (np.arctan((x**2+y**2-0.75**2)/a**2)
+10*np.exp(-(x**2+y**2-0.75**2)**2/a**4) * (random() -1/2))
learner=adaptive.AverageLearner2D(ring, bounds=[(-1, 1), (-1, 1)], weight=.1)
runner=adaptive.Runner(learner, goal=lambdal: l.loss() <0.01, log=True)
runner.live_info()

which results in:

>>> print(learner.mean_values_per_point()) 65.2737642585551328

and

learner.plot(tri_alpha=0.5) + learner.plot_std_or_n(which='std')

image

  • Before merging we should observe that this behaves reasonably when the function is heteroscedastic (noise depends on x).
  • Need to verify that δy between neighbouring points is comparable to std(y). This is best to do in 1D learner.
  • write docstring for AverageLearner1D
  • doc-string for AverageLearner2D is from Learner2D for auto complete
  • write doc-strings for properties in reference/adaptive.learner.average1D.html.

@basnijholt
basnijholtforce-pushed the master branch 4 times, most recently from cb83625 to 7ccb583CompareJanuary 25, 2019 15:36
@basnijholtbasnijholt mentioned this pull request Jan 30, 2019
@basnijholt
basnijholtforce-pushed the AverageLearner2D branch 2 times, most recently from 8228cb7 to 79c9edfCompareMarch 5, 2019 16:52
@basnijholtbasnijholt changed the title WIP: AverageLearner2D and AverageLearner1Dadd AverageLearner1D and AverageLearner2DMar 5, 2019
Comment threadadaptive/learner/average_mixin.py Outdated
Comment threadadaptive/learner/average_mixin.py
@basnijholt
basnijholtforce-pushed the AverageLearner2D branch 4 times, most recently from a73c167 to 2696f86CompareMarch 6, 2019 15:10
@basnijholt
basnijholt requested a review from jbwestonMarch 6, 2019 15:10
@basnijholt
basnijholtforce-pushed the AverageLearner2D branch 5 times, most recently from 5f3aeba to 51f4292CompareMarch 7, 2019 13:13
@basnijholtbasnijholt mentioned this pull request Mar 18, 2019
@basnijholt

Copy link
Copy Markdown
MemberAuthor

@anton I have implemented what you suggested in chat:

It's not just that: the two options that make sense are:

  • increase the number of samples in a point by a fixed fraction (e.g. 1.1)
  • add a new point with the number of samples that's comparable to the number of samples in the neighboring points.

The problem now is that once a point has a lot of "seeds", increasing the number of seeds by 10% will give a big loss improvement, probably the biggest, so the number of values at that point will grow very big. Conceptually this shouldn't happen, so I probably made a mistake in the following method:

defloss_per_existing_point(self):
"""Increase the number of seeds by 10%."""iflen(self.data) <4:
return [], []
scale=self.value_scale()
points= []
loss_improvements= []
neighbors=self._get_neighbor_mapping_existing_points()
mean_values_per_neighbor=self._mean_values_per_neighbor(neighbors)
forp, seminself.data_sem.items():
n_neighbors=mean_values_per_neighbor[p]
N=self.n_values(p)
n_more=int(1.1*N) # increase the amount of points by 10%points.append((p, n_more))
# This is the improvement considering we will add# n_more seeds to the stack.sem_improvement= (1/sqrt(N) -1/sqrt(N+n_more)) *semloss_improvement=self.weight*sem_improvement/scale# XXX: Do I need to divide by the scale?loss_improvements.append(loss_improvement)
returnpoints, loss_improvements

@akhmerov

Copy link
Copy Markdown
Contributor

The problem now is that once a point has a lot of "seeds", increasing the number of seeds by 10% will give a big loss improvement, probably the biggest, so the number of values at that point will grow very big.

If you increase the number of points by 10%, the rms at the point drops by 5%; why would this be the biggest loss improvement?

@basnijholt
basnijholtforce-pushed the AverageLearner2D branch 3 times, most recently from b235c4e to 17c9b79CompareMarch 19, 2019 18:20
@basnijholt
basnijholtforce-pushed the AverageLearner2D branch 2 times, most recently from 713d22c to e9da31dCompareMarch 22, 2019 10:17
@basnijholt
basnijholtforce-pushed the AverageLearner2D branch 3 times, most recently from fd30d36 to ddfc9b8CompareMarch 28, 2019 20:18
@basnijholt
basnijholtforce-pushed the AverageLearner2D branch 4 times, most recently from 61afe1d to 8b448a5CompareApril 12, 2019 12:57
@basnijholt

Copy link
Copy Markdown
MemberAuthor

I've noticed that the AverageLearner1D/2D aren't working for BalancingLearners because of the ask(..., tell_pending=False) when using bal_learner.strategy = 'loss_improvements'.

@basnijholt

Copy link
Copy Markdown
MemberAuthor

I've added a cool plotting feature, on hovering over the points it displays extra information:
image

@basnijholt
basnijholtforce-pushed the AverageLearner2D branch 3 times, most recently from b84633f to 7e060e1CompareApril 29, 2019 21:21
@basnijholt
basnijholtforce-pushed the AverageLearner2D branch 3 times, most recently from 081b3a5 to ee808d3CompareMay 13, 2019 17:18
@basnijholt

Copy link
Copy Markdown
MemberAuthor

The failing test test_saving[AverageLearner1D-random_linear_with_peak-learner_kwargs6] is because the y_scale not properly being updated.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@basnijholt@akhmerov