splinter icon indicating copy to clipboard operation
splinter copied to clipboard

Penalized B-spline dies while building

Open yrzhanov opened this issue 2 years ago • 7 comments

Hello, The library compiles on Windows 10 VS 2019 fine, example compiles and runs correctly. However, when I try to use it in my code the program dies when P-spline is being built. I use the following code: DataTable samples; DenseVector x(1); // Data is added to data table: for all i: x(0) = dataX[i]; samples.addSample(x, (double)dataY[i]);

BSpline pspline = BSpline::Builder(samples)
	.degree(3)
	.smoothing(BSpline::Smoothing::PSPLINE)
	.alpha(0.03)
	.build();

Where the data is: X Y 0 5375.00 -1.7169 1 5425.00 -1.8601 2 5426.00 -1.5700 3 5475.00 -1.1063 4 5525.00 -1.6225 5 5526.00 -1.5294 6 5575.00 -1.0975 7 5576.00 -0.9168 8 5625.00 -1.6232 9 5626.00 -1.1228 10 5675.00 -1.6983 11 5676.00 -0.9332 12 5725.00 -1.3473 13 5775.00 -1.9296 14 5776.00 -1.2617 15 5825.00 -0.9127 16 5875.00 -1.1056 17 5876.00 -1.0418 18 5925.00 -1.0078 19 5975.00 -1.0539 20 5976.00 -0.7310 21 6025.00 -1.0621 22 6026.00 -0.7609 23 6075.00 -0.7966 24 6125.00 -0.8065 25 6175.00 -1.3996 CrashStack

The call stack is shown on the attached PNG. Could you please advise how to find the problem?

Thank you, Yuri Rzhanov

yrzhanov avatar Jun 19 '22 17:06 yrzhanov

This could be due to the different versions of Eigen - SPLINTER uses 3.2.8, and my libraries are compiled with 3.3.7. However, SPLINTER does not compile with newer Eigen, as line 122 in bsplinebasis.cpp uses InnerIterator which has been made private: 2>F:\D\VariousCodes\splinter\src\bsplinebasis.cpp(122,9): error C2248: 'Eigen::SparseCompressedBase<Eigen::SparseMatrix<double,0,int>>::InnerIterator::InnerIterator': cannot access private member declared in class 'Eigen::SparseCompressedBase<Eigen::SparseMatrix<double,0,int>>::InnerIterator'

Could you please advise how to adapt SPLINTER for newer version of Eigen? Thank you, Yuri

yrzhanov avatar Jun 19 '22 20:06 yrzhanov

Just checked - same data cause no problems when other libraries compiled with later version of Eigen are not present. Is it possible to modify the code so it will work with Eigen 3.3.7? Thank you, Yuri

yrzhanov avatar Jun 19 '22 20:06 yrzhanov

It should definitely be possible to make the code work with Eigen 3.3.7 or a later version. Since I have not read the release notes of the newer Eigen versions, I am not sure how much work it would require. That said, past updates have not required many modifications.

I have noted that, if we ever get around to preparing a new release of SPLINTER, we should consider updating to a newer Eigen version.

bgrimstad avatar Jun 21 '22 07:06 bgrimstad

Thank you for replying. I tried to recompile OpenCV and PCL with Eigen 3.2.8, but the program still crashes. So meanwhile the only way for me is to write a file with data, spawn another process that calculates a spline and writes the result. My program waits for the completion, reads the output and keeps going. Which is awfully awkward. Looks like the only problem is to replace in SPLINTER the InnerIterator that I mentioned above with non-private member of SparseCompressedBase.

yrzhanov avatar Jun 21 '22 13:06 yrzhanov

I tried forking your repo to integrate with more recent Eigen. The patch I made to deal with the constructor issue I dropped the k argument and changed matrix to vector. Based on the type I assumed that the column vector only needs to be iterated in a single dimension.

https://github.com/bgrimstad/splinter/commit/5d71820e421ab6957a35be4e2838b1c20b9db3c2

Let me know if this isn't appropriate. The tests continued to pass but I don't know if this code is covered by tests.

bowie7070 avatar Jul 07 '22 09:07 bowie7070

Thank you so much for your efforts. Yes, for our purpose it’s a single dimension. I will give the new version a try right now.

Cheers,

Yuri

From: bowie7070 @.> Sent: Thursday, July 7, 2022 5:16 AM To: bgrimstad/splinter @.> Cc: yrzhanov @.>; Author @.> Subject: Re: [bgrimstad/splinter] Penalized B-spline dies while building (Issue #132)

CAUTION: This email originated from outside of the University System. Do not click links or open attachments unless you recognize the sender and know the content is safe.

I tried forking your repo to integrate with more recent Eigen. The patch I made to deal with the constructor issue I dropped the k argument and changed matrix to vector. Based on the type I assumed that the column vector only needs to be iterated in a single dimension.

https://github.com/bgrimstad/splinter/commit/5d71820e421ab6957a35be4e2838b1c20b9db3c2 5d71820

— Reply to this email directly, view it on GitHub https://github.com/bgrimstad/splinter/issues/132#issuecomment-1177295710 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABCLEFA3Q4EPDAJJQMCVOCDVS2N5BANCNFSM5ZGV2ZOA . You are receiving this because you authored the thread. https://github.com/notifications/beacon/ABCLEFACDBRTA4LKJK2VO53VS2N5BA5CNFSM5ZGV2ZOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOIYWBWXQ.gif Message ID: @.*** @.***> >

yrzhanov avatar Jul 07 '22 12:07 yrzhanov

Hello Bjarne,

Thank you and your colleague for fixing the problem – it took just a single line change – and of course understanding what this line does. Now SPLINTER works with the latest Eigen.

I wonder if there is a way to easily detect extremums of the P-spline (points where first derivative is zero)? I don’t have deep understanding how P-spline works (unlike B-spline).

Thank you,

Yuri  

From: Bjarne Grimstad @.> Sent: Tuesday, June 21, 2022 3:08 AM To: bgrimstad/splinter @.> Cc: yrzhanov @.>; Author @.> Subject: Re: [bgrimstad/splinter] Penalized B-spline dies while building (Issue #132)

CAUTION: This email originated from outside of the University System. Do not click links or open attachments unless you recognize the sender and know the content is safe.

It should definitely be possible to make the code work with Eigen 3.3.7 or a later version. Since I have not read the release notes of the newer Eigen versions, I am not sure how much work it would require. That said, past updates have not required many modifications.

I have noted that, if we ever get around to preparing a new release of SPLINTER, we should consider updating to a newer Eigen version.

— Reply to this email directly, view it on GitHub https://github.com/bgrimstad/splinter/issues/132#issuecomment-1161346255 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABCLEFDQGOU2ZHXWVLTW74TVQFS6FANCNFSM5ZGV2ZOA . You are receiving this because you authored the thread. https://github.com/notifications/beacon/ABCLEFET33PJKDCXJZIO7UDVQFS6FA5CNFSM5ZGV2ZOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOIU4LZTY.gif Message ID: @.*** @.***> >

yrzhanov avatar Jul 13 '22 16:07 yrzhanov