princurve icon indicating copy to clipboard operation
princurve copied to clipboard

project_to_curve resets lambda

Open kstreet13 opened this issue 2 years ago • 2 comments

Hi Robrecht!

An astute user recently pointed out some strange behavior in slingshot::predict (https://github.com/kstreet13/slingshot/issues/185) that I'm pretty sure is related to this line: https://github.com/rcannood/princurve/blob/a19b4e7febad05e224f3ba1af36877984ef57a12/src/project_to_curve.cpp#L207

I can see why this is useful in the construction of principal curves. But for projecting points onto existing curves, I think it would be nice to have the option of not starting the new lambda values at 0, but rather at the appropriate index on the old curve.

If this is too niche of an application, I can build a workaround into slingshot::predict, but just wanted to bring it up and see what your thoughts were.

Best, Kelly

kstreet13 avatar May 18 '22 23:05 kstreet13

Hey Kelly! It's nice to hear from you :)

I wouldn't mind implementing additional functionality in princurve to support this use-case, but I'm not sure how exactly you'd expect the project_to_curve function to behave.

Do you have an idea of what you would like to see changed?

Kind regards, Robrecht

rcannood avatar May 19 '22 11:05 rcannood

Awesome, thanks very much!

My understanding of the issue is that whenever we project points onto a curve, the minimum lambda value of the output is 0, regardless of where along the curve those points get projected (say the curve has length 1 and the earliest point in my new dataset projects onto the midpoint of the curve. I would expect that point to have a lambda value of 0.5, but instead it ends up with a value of 0). I think this behavior makes sense for constructing principal curves, but it's a little unintuitive if your only goal is to project points onto a curve.

One possible solution might be to add a logical argument to project_to_curve that toggles this behavior. Whenever it's called by principal_curve, you set it to TRUE, so you get the behavior you need there. But the default is FALSE so that the user-facing function project_to_curve gives lambda values relative to the original curve. I don't know any C++, unfortunately, so let me know if that doesn't make sense for any reason.

Best, Kelly

kstreet13 avatar May 19 '22 21:05 kstreet13