-
Notifications
You must be signed in to change notification settings - Fork 229
1. score_pairs refactor #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
c47797c
e07b11a
8210acd
11b5df6
06b7131
d5cb8b4
2f61e7b
5f68ed2
3d6450b
7bce493
7e6584a
0b58f45
d4d3a9c
60c88a6
8c55970
787a8d1
e14f956
0941a32
b019d85
74df897
c62a4e7
249e0fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,20 +29,22 @@ def __init__(self, preprocessor=None): | |
@abstractmethod | ||
def score_pairs(self, pairs): | ||
""" | ||
.. deprecated:: 0.6.3 Refer to `pair_distance` and `pair_similarity`. | ||
.. deprecated:: 0.7.0 Refer to `pair_distance` and `pair_similarity`. | ||
|
||
.. warning:: | ||
This method will be deleted in 0.6.4. Please refer to `pair_distance` | ||
This method will be removed in 0.8.0. Please refer to `pair_distance` | ||
or `pair_similarity`. This change will occur in order to add learners | ||
that don't necessarly learn a Mahalanobis distance. | ||
that don't necessarily learn a Mahalanobis distance. | ||
|
||
Returns the score between pairs | ||
(can be a similarity, or a distance/metric depending on the algorithm) | ||
|
||
Parameters | ||
---------- | ||
pairs : `numpy.ndarray`, shape=(n_samples, 2, n_features) | ||
3D array of pairs. | ||
pairs : array-like, shape=(n_pairs, 2, n_features) or (n_pairs, 2) | ||
3D Array of pairs to score, with each row corresponding to two points, | ||
for 2D array of indices of pairs if the metric learner uses a | ||
preprocessor. | ||
|
||
Returns | ||
------- | ||
|
@@ -52,27 +54,29 @@ def score_pairs(self, pairs): | |
See Also | ||
-------- | ||
get_metric : a method that returns a function to compute the metric between | ||
two points. The difference with `score_pairs` is that it works on two | ||
1D arrays and cannot use a preprocessor. Besides, the returned function | ||
is independent of the metric learner and hence is not modified if the | ||
metric learner is. | ||
two points. The difference between `pair_score` and `pair_distance` is | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my bad, this is in the "see also" of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's actually of the old
|
||
that it works on two 1D arrays and cannot use a preprocessor. Besides, | ||
the returned function is independent of the metric learner and hence is | ||
not modified if the metric learner is. | ||
""" | ||
|
||
@abstractmethod | ||
def pair_similarity(self, pairs): | ||
def pair_score(self, pairs): | ||
""" | ||
.. versionadded:: 0.6.3 Compute the similarity score bewteen pairs | ||
.. versionadded:: 0.7.0 Compute the similarity score between pairs | ||
|
||
Returns the similarity score between pairs. Depending on the algorithm, | ||
this method can return the learned similarity score between pairs, | ||
or the inverse of the distance learned between two pairs. The more the | ||
score, the more similar the pairs. All learners have access to this | ||
Returns the similarity score between pairs of points. Depending on the | ||
algorithm, this method can return the learned similarity score between | ||
pairs, or the opposite of the distance learned between pairs. The larger | ||
the score, the more similar the pair. All learners have access to this | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: this is a bit heavy. I would recommend simply: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed and kept the last sentence "All learners have access to this method". |
||
method. | ||
|
||
Parameters | ||
---------- | ||
pairs : `numpy.ndarray`, shape=(n_samples, 2, n_features) | ||
3D array of pairs. | ||
pairs : array-like, shape=(n_pairs, 2, n_features) or (n_pairs, 2) | ||
3D Array of pairs to score, with each row corresponding to two points, | ||
for 2D array of indices of pairs if the metric learner uses a | ||
preprocessor. | ||
|
||
Returns | ||
------- | ||
|
@@ -82,7 +86,7 @@ def pair_similarity(self, pairs): | |
See Also | ||
-------- | ||
get_metric : a method that returns a function to compute the metric between | ||
two points. The difference with `pair_similarity` is that it works on two | ||
two points. The difference with `pair_score` is that it works on two | ||
1D arrays and cannot use a preprocessor. Besides, the returned function | ||
is independent of the metric learner and hence is not modified if the | ||
metric learner is. | ||
|
@@ -91,17 +95,18 @@ def pair_similarity(self, pairs): | |
@abstractmethod | ||
def pair_distance(self, pairs): | ||
""" | ||
.. versionadded:: 0.6.3 Compute the distance score between pairs | ||
.. versionadded:: 0.7.0 Compute the distance between pairs | ||
|
||
Returns the distance score between pairs. For Mahalanobis learners, it | ||
returns the pseudo-distance bewtween pairs. It is not available for | ||
learners that does not learn a distance or pseudo-distance, an error | ||
will be shown instead. | ||
Returns the (pseudo) distance between pairs, when available. For metric | ||
learners that do not learn a (pseudo) distance, an error is thrown | ||
instead. | ||
|
||
Parameters | ||
---------- | ||
pairs : `numpy.ndarray`, shape=(n_samples, 2, n_features) | ||
3D array of pairs. | ||
pairs : array-like, shape=(n_pairs, 2, n_features) or (n_pairs, 2) | ||
3D Array of pairs to score, with each row corresponding to two points, | ||
mvargas33 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for 2D array of indices of pairs if the metric learner uses a | ||
preprocessor. | ||
|
||
Returns | ||
------- | ||
|
@@ -170,10 +175,10 @@ def _prepare_inputs(self, X, y=None, type_of_inputs='classic', | |
|
||
@abstractmethod | ||
def get_metric(self): | ||
"""Returns a function that takes as input two 1D arrays and outputs the | ||
learned metric score on these two points. Depending on the algorithm, it | ||
can return the distance or similarity function between pairs. It always | ||
returns what the specific algorithm learns. | ||
"""Returns a function that takes as input two 1D arrays and outputs | ||
the value of the learned metric on these two points. Depending on the | ||
algorithm, it can return a distance or a score function between pairs. | ||
mvargas33 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
It always returns what the specific algorithm learns. | ||
mvargas33 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This function will be independent from the metric learner that learned it | ||
(it will not be modified if the initial metric learner is modified), | ||
|
@@ -206,13 +211,13 @@ def get_metric(self): | |
|
||
See Also | ||
-------- | ||
pair_distance : a method that returns the distance score between several | ||
pair_distance : a method that returns the distance between several | ||
pairs of points. Unlike `get_metric`, this is a method of the metric | ||
learner and therefore can change if the metric learner changes. Besides, | ||
it can use the metric learner's preprocessor, and works on concatenated | ||
arrays. | ||
|
||
pair_similarity : a method that returns the similarity score between | ||
pair_score : a method that returns the similarity score between | ||
several pairs of points. Unlike `get_metric`, this is a method of the | ||
metric learner and therefore can change if the metric learner changes. | ||
Besides, it can use the metric learner's preprocessor, and works on | ||
|
@@ -260,13 +265,13 @@ class MahalanobisMixin(BaseMetricLearner, MetricTransformer, | |
|
||
def score_pairs(self, pairs): | ||
r""" | ||
.. deprecated:: 0.6.3 | ||
.. deprecated:: 0.7.0 | ||
This method is deprecated. Please use `pair_distance` instead. | ||
|
||
.. warning:: | ||
This method will be deleted in 0.6.4. Please refer to `pair_distance` | ||
or `pair_similarity`. This change will occur in order to add learners | ||
that don't necessarly learn a Mahalanobis distance. | ||
This method will be removed in 0.8.0. Please refer to `pair_distance` | ||
or `pair_score`. This change will occur in order to add learners | ||
that don't necessarily learn a Mahalanobis distance. | ||
|
||
Returns the learned Mahalanobis distance between pairs. | ||
|
||
|
@@ -301,15 +306,15 @@ def score_pairs(self, pairs): | |
:ref:`mahalanobis_distances` : The section of the project documentation | ||
that describes Mahalanobis Distances. | ||
""" | ||
dpr_msg = ("score_pairs will be deprecated in release 0.6.3. " | ||
"Use pair_similarity to compute similarities, or " | ||
dpr_msg = ("score_pairs will be deprecated in release 0.7.0. " | ||
"Use pair_score to compute similarity scores, or " | ||
"pair_distances to compute distances.") | ||
warnings.warn(dpr_msg, category=FutureWarning) | ||
return self.pair_distance(pairs) | ||
|
||
def pair_similarity(self, pairs): | ||
def pair_score(self, pairs): | ||
""" | ||
Returns the inverse of the learned Mahalanobis distance between pairs. | ||
Returns the opposite of the learned Mahalanobis distance between pairs. | ||
|
||
Parameters | ||
---------- | ||
|
@@ -321,12 +326,12 @@ def pair_similarity(self, pairs): | |
Returns | ||
------- | ||
scores : `numpy.ndarray` of shape=(n_pairs,) | ||
The inverse of the learned Mahalanobis distance for every pair. | ||
The opposite of the learned Mahalanobis distance for every pair. | ||
|
||
See Also | ||
-------- | ||
get_metric : a method that returns a function to compute the metric between | ||
two points. The difference with `pair_similarity` is that it works on two | ||
two points. The difference with `pair_score` is that it works on two | ||
1D arrays and cannot use a preprocessor. Besides, the returned function | ||
is independent of the metric learner and hence is not modified if the | ||
metric learner is. | ||
|
@@ -517,7 +522,7 @@ def decision_function(self, pairs): | |
pairs = check_input(pairs, type_of_inputs='tuples', | ||
preprocessor=self.preprocessor_, | ||
estimator=self, tuple_size=self._tuple_size) | ||
return self.pair_similarity(pairs) | ||
return self.pair_score(pairs) | ||
|
||
def score(self, pairs, y): | ||
"""Computes score of pairs similarity prediction. | ||
|
@@ -787,8 +792,8 @@ def decision_function(self, triplets): | |
triplets = check_input(triplets, type_of_inputs='tuples', | ||
preprocessor=self.preprocessor_, | ||
estimator=self, tuple_size=self._tuple_size) | ||
return (self.pair_similarity(triplets[:, :2]) - | ||
self.pair_similarity(triplets[:, [0, 2]])) | ||
return (self.pair_score(triplets[:, :2]) - | ||
self.pair_score(triplets[:, [0, 2]])) | ||
|
||
def score(self, triplets): | ||
"""Computes score on input triplets. | ||
|
@@ -872,8 +877,8 @@ def decision_function(self, quadruplets): | |
quadruplets = check_input(quadruplets, type_of_inputs='tuples', | ||
preprocessor=self.preprocessor_, | ||
estimator=self, tuple_size=self._tuple_size) | ||
return (self.pair_similarity(quadruplets[:, :2]) - | ||
self.pair_similarity(quadruplets[:, 2:])) | ||
return (self.pair_score(quadruplets[:, :2]) - | ||
self.pair_score(quadruplets[:, 2:])) | ||
|
||
def score(self, quadruplets): | ||
"""Computes score on input quadruplets | ||
|
Uh oh!
There was an error while loading. Please reload this page.