cvxgrp / pymde

Minimum-distortion embedding with PyTorch
https://pymde.org
Apache License 2.0
536 stars 27 forks source link

Error when embedding new points #48

Closed actrina closed 2 years ago

actrina commented 2 years ago

Hi.

I'm interested in using PyMDE for some embedding problem. In the training data the method seems to work fine, but I've been trying to use the function of incremental embedding in order to embed new points and I obtain the following error:

This is a part of my code:

g1 = pymde.Graph(adj)
embedding = pymde.preserve_neighbors(g1).embed()
pymde.plot(embedding)

# To add new points into the embedding
anchor_constraint = pymde.Anchored(
    anchors = torch.arange(n_train),
    values = embedding,
)

incremental_mde = pymde.preserve_neighbors(
    g1,
    constraint = anchor_constraint,
    init='random',
    verbose=True)

incremental_mde.embed()

When performing incremental_mde.embed() appears the following error:

_SolverError: Function evaluation returned NaN. File "C:\Users\bioimag\AppData\Local\Temp/ipykernel_17984/3089993745.py", line 12, in incremental_mde.embed()

File "C:\Users\bioimag\anaconda3\envs\embeds03\lib\site-packages\pymde\problem.py", line 496, in embed X_star, solve_stats = optim.lbfgs(

File "C:\Users\bioimag\anaconda3\envs\embeds03\lib\site-packages\pymde\optim.py", line 131, in lbfgs opt.step(value_and_grad)

File "C:\Users\bioimag\anaconda3\envs\embeds03\lib\site-packages\torch\optim\optimizer.py", line 89, in wrapper return func(*args, **kwargs)

File "C:\Users\bioimag\anaconda3\envs\embeds03\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context return func(*args, **kwargs)

File "C:\Users\bioimag\anaconda3\envs\embeds03\lib\site-packages\pymde\lbfgs.py", line 519, in step loss, flat_grad, t, ls_func_evals = _strong_wolfe(

File "C:\Users\bioimag\anaconda3\envs\embeds03\lib\site-packages\pymde\lbfgs.py", line 70, in _strong_wolfe raise SolverError("Function evaluation returned NaN.")

SolverError: Function evaluation returned NaN_.

I saw a similar issue (#9), so I downgraded the pytorch version to the 1.8 version, but it still doesn't work.

Thank you in advance for your help.

akshayka commented 2 years ago

Hi, thanks for reporting this issue!

Would it be possible for you to share the adj object with me (e.g., via a Google Drive link)? That would let me recreate your issue locally and debug it.

Additionally, what version of PyMDE are you using?

actrina commented 2 years ago

Hi. I think I found the error. It was my mistake as I was doing the updating of embedding wrong. I reviewed your example for updating the embeddings and I missed that the new MDE problem should include all the dataset. Thank you again, and sorry for the inconvenience.