Skip to content

[MRG] replace +1 by inf in MMC diag #297

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

Merged

Conversation

wdevazelhes
Copy link
Member

This is a quick fix to a problem that was making fail the following example for diagonal MMC:

In [9]:  from sklearn.datasets import fetch_lfw_pairs 
   ...:  from sklearn.model_selection import cross_validate, train_test_split 
   ...:  from metric_learn import MMC 
   ...:  pairs, y_pairs = [fetch_lfw_pairs()[key] for key in ['pairs', 'target']] 
   ...:  pairs, _, y_pairs, _ = train_test_split(pairs, 2*y_pairs-1) 
   ...:  pairs = pairs.reshape(pairs.shape[0], 2, -1) 
   ...:  mmc = MMC(diagonal=True)
   ...:  mmc.fit(pairs, y_pairs)

what happens is that obj_previous (see here:

obj_previous = obj + 1 # just to get the while-loop started
) was such a big number (of order 10**20) that adding +1 made it stay the same number (see picture) and therefore the strict comparison failed to start the loop and therefore w_previous was unreferenced. Replacing obj_previous +1 by np.inf fixed the pb (it's a quick fix to make it work, but I don't really know if it's the final answer, what if obj_previous == np.inf too ? The comparison will then fail again. Should we detect this case and throw an error ?) I guess for the next release we can merge this as is though, and maybe investigate later ?

image

Copy link
Member

@bellet bellet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The solution sounds good. Personally I don't think it is worth covering the case where the initial objective is infinity with a proper error, as this is very unlikely to happen. Indeed we already check that the data does not contain any inf value, and float64 can handle values as large as 1e300 or so.

@bellet bellet changed the title [MRG] replace +1 by inf [MRG] replace +1 by inf in MMC diag Jun 30, 2020
@perimosocordiae perimosocordiae merged commit 49b811d into scikit-learn-contrib:master Jun 30, 2020
@perimosocordiae
Copy link
Contributor

Thanks, merged.

Sign up for free to 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.

4 participants