|
6 | 6 | import numpy as np
|
7 | 7 |
|
8 | 8 | from adaptive.learner.learner2D import Learner2D
|
9 |
| -from adaptive.learner.average_mixin import add_average_mixin |
| 9 | +from adaptive.learner.average_mixin import add_average_mixin, DataPoint |
10 | 10 |
|
11 | 11 |
|
12 | 12 | @add_average_mixin
|
13 | 13 | class AverageLearner2D(Learner2D):
|
14 |
| - def __init__(self, function, bounds, weight=1, loss_per_triangle=None): |
15 |
| - """Same as 'Learner2D', only the differences are in the doc-string. |
16 |
| -
|
17 |
| - Parameters |
18 |
| - ---------- |
19 |
| - function : callable |
20 |
| - The function to learn. Must take a tuple of a tuple of two real |
21 |
| - parameters and a seed and return a real number. |
22 |
| - So ((x, y), seed) → float, e.g.: |
23 |
| - >>> def f(xy_seed): |
24 |
| - ... (x, y), seed = xy_seed |
25 |
| - ... random.seed(xy_seed) |
26 |
| - ... return x * y + random.uniform(-0.5, 0.5) |
27 |
| - weight : float, int, default 1 |
28 |
| - When `weight > 1` adding more points to existing points will be |
29 |
| - prioritized (making the standard error of a point more imporant,) |
30 |
| - otherwise adding new triangles will be prioritized (making the |
31 |
| - loss of a triangle more important.) |
32 |
| -
|
33 |
| - Attributes |
34 |
| - ---------- |
35 |
| - min_values_per_point : int, default 3 |
36 |
| - Minimum amount of values per point. This means that the |
37 |
| - standard error of a point is infinity until there are |
38 |
| - 'min_values_per_point' for a point. |
39 |
| -
|
40 |
| - Methods |
41 |
| - ------- |
42 |
| - mean_values_per_point : callable |
43 |
| - Returns the average numbers of values per (x, y) value. |
44 |
| -
|
45 |
| - Notes |
46 |
| - ----- |
47 |
| - The total loss of the learner is still only determined by the |
48 |
| - max loss of the triangles. |
49 |
| - """ |
| 14 | + """Same as 'Learner2D', only the differences are in the doc-string. |
| 15 | +
|
| 16 | + Parameters |
| 17 | + ---------- |
| 18 | + function : callable |
| 19 | + The function to learn. Must take a tuple of a tuple of two real |
| 20 | + parameters and a seed and return a real number. |
| 21 | + So ((x, y), seed) → float, e.g.: |
| 22 | + >>> def f(xy_seed): |
| 23 | + ... (x, y), seed = xy_seed |
| 24 | + ... random.seed(xy_seed) |
| 25 | + ... return x * y + random.uniform(-0.5, 0.5) |
| 26 | + weight : float, int, default 1 |
| 27 | + When `weight > 1` adding more points to existing points will be |
| 28 | + prioritized (making the standard error of a point more imporant,) |
| 29 | + otherwise adding new triangles will be prioritized (making the |
| 30 | + loss of a triangle more important.) |
| 31 | +
|
| 32 | + Attributes |
| 33 | + ---------- |
| 34 | + min_values_per_point : int, default 3 |
| 35 | + Minimum amount of values per point. This means that the |
| 36 | + standard error of a point is infinity until there are |
| 37 | + 'min_values_per_point' for a point. |
| 38 | +
|
| 39 | + Methods |
| 40 | + ------- |
| 41 | + mean_values_per_point : callable |
| 42 | + Returns the average numbers of values per (x, y) value. |
| 43 | +
|
| 44 | + Notes |
| 45 | + ----- |
| 46 | + The total loss of the learner is still only determined by the |
| 47 | + max loss of the triangles. |
| 48 | + """ |
50 | 49 |
|
| 50 | + def __init__(self, function, bounds, weight=1, loss_per_triangle=None): |
51 | 51 | super().__init__(function, bounds, loss_per_triangle)
|
52 | 52 | self._data = dict() # {point: {seed: value}} mapping
|
53 | 53 | self.pending_points = dict() # {point: {seed}}
|
|
0 commit comments