|
4 | 4 | from tdamapper.utils.vptree_flat import VPTree |
5 | 5 |
|
6 | 6 |
|
7 | | -class ProximityNetCover: |
| 7 | +def proximity_net(X, proximity): |
8 | 8 | ''' |
9 | | - This class serves as a blueprint for proximity-based cover algorithm |
10 | | - and implements proximity-net in the `ProximityNetCover.apply` method. |
11 | | - Subclasses are expected to override the methods `ProximityNetCover.fit` |
12 | | - and `ProximityNetCover.search`. |
| 9 | + Compute proximity-net for a given proximity function. |
| 10 | + Returns a generator where each item is a subset of ids |
| 11 | + of points from `X`. |
| 12 | +
|
| 13 | + :param X: A dataset. |
| 14 | + :type X: `numpy.ndarray` or list-like. |
| 15 | + :param proximity: A proximity function. |
| 16 | + :type proximity: `tdamapper.cover.Proximity`. |
13 | 17 | ''' |
| 18 | + covered_ids = set() |
| 19 | + proximity.fit(X) |
| 20 | + for i, xi in enumerate(X): |
| 21 | + if i not in covered_ids: |
| 22 | + neigh_ids = proximity.search(xi) |
| 23 | + covered_ids.update(neigh_ids) |
| 24 | + if neigh_ids: |
| 25 | + yield neigh_ids |
14 | 26 |
|
15 | | - def __init__(self): |
16 | | - pass |
17 | 27 |
|
18 | | - def apply(self, X): |
19 | | - ''' |
20 | | - Compute proximity-net for a given open cover. |
21 | | - Returns a generator where each item is a subset of ids |
22 | | - of points from `X`. |
23 | | -
|
24 | | - :param X: A dataset. |
25 | | - :type X: `numpy.ndarray` or list-like. |
26 | | - ''' |
27 | | - covered_ids = set() |
28 | | - self.fit(X) |
29 | | - for i, xi in enumerate(X): |
30 | | - if i not in covered_ids: |
31 | | - neigh_ids = self.search(xi) |
32 | | - covered_ids.update(neigh_ids) |
33 | | - if neigh_ids: |
34 | | - yield neigh_ids |
| 28 | +class Proximity: |
| 29 | + ''' |
| 30 | + This class serves as a blueprint for proximity functions used inside |
| 31 | + `tdamapper.cover.proximity_net`. Subclasses are expected to override |
| 32 | + the methods `fit` and `search`. |
| 33 | + ''' |
35 | 34 |
|
36 | 35 | def fit(self, X): |
| 36 | + self.__X = X |
37 | 37 | return self |
38 | 38 |
|
39 | 39 | def search(self, x): |
40 | | - return [] |
| 40 | + return [i for i, _ in enumerate(self.__X)] |
| 41 | + |
| 42 | + |
| 43 | +class ProximityNetCover(Proximity): |
| 44 | + ''' |
| 45 | + This class serves as a blueprint for cover algorithm based on proximity-net. |
| 46 | + ''' |
| 47 | + |
| 48 | + def __init__(self): |
| 49 | + pass |
| 50 | + |
| 51 | + def apply(self, X): |
| 52 | + return proximity_net(X, self) |
41 | 53 |
|
42 | 54 |
|
43 | 55 | class BallCover(ProximityNetCover): |
|
0 commit comments