Skip to content
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

Polynomial fit returns infinity and NaN as parameters #1060

Open
StevanOgnjanovic opened this issue Jan 18, 2024 · 0 comments
Open

Polynomial fit returns infinity and NaN as parameters #1060

StevanOgnjanovic opened this issue Jan 18, 2024 · 0 comments

Comments

@StevanOgnjanovic
Copy link

As already posted on stackoverflow (https://stackoverflow.com/q/77803357/19921514) I'm having issues with 6th order polynomial fit of 100 datapoints.

I'm using Svd decomposition to get the most acurate results, but on some datasets, this results in the polynomial parameters being infinity and NaN. On other datasets the fit works as expected.

Here's the code:
double[] PolFitCoeff = Fit.Polynomial(XValues, YValues, 6, MathNet.Numerics.LinearRegression.DirectRegressionMethod.Svd);

and a few datasets:

double[] XWorking1 = new double[] {370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470};
double[] YWorking1 = new double[] {-0.00227, 0, 0, 0.004547, 0, 0.010239, 0.007965, 0.002276, 0.007967, 0.002276, 0.002277, 0.001139, 0.00114, 0.025087, 0.01027, 0.044447, 0.157399, 0.143755, 0.142648, 0.138106, 0.135882, 0.132488, 0.133655, 0.131388, 0.133708, 0.144043, 0.166937, 0.221899, 0.334092, 0.549274, 0.926127, 1.543659, 2.490492, 3.847829, 5.696928, 8.066181, 10.973218, 14.358651, 18.197052, 22.374146, 26.828288, 31.416559, 36.102365, 40.708982, 45.16626, 49.463491, 53.530264, 57.321396, 60.836134, 64.075579, 67.014809, 69.689847, 72.089191, 74.240713, 76.18411, 77.900317, 79.423356, 80.750665, 81.92438, 82.95304, 83.853657, 84.637438, 85.315547, 85.909902, 86.418319, 86.882287, 87.275151, 87.604113, 87.904226, 88.152034, 88.380633, 88.574051, 88.744981, 88.895262, 89.031792, 89.143631, 89.240092, 89.320935, 89.402605, 89.472717, 89.527454, 89.598758, 89.644623, 89.689571, 89.720099, 89.763308, 89.801347, 89.833788, 89.859346, 89.882605, 89.906439, 89.940542, 89.942621, 89.975916, 89.994124, 90.010484, 90.058304, 90.05887, 90.057483, 90.071175, 90.089125};
double[] XWorking2 = new double[] {353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453};
double[] YWorking2 = new double[] {-2.75759524458215E-05, 8.82744009754321E-06, 5.40915272797923E-05, 3.75544539582394E-05, 1.98865362625465E-05, 1.32638308596289E-05, 1.87948519794849E-05, 4.97612015229139E-05, 5.75202786636269E-05, 2.76631906945453E-05, 6.75159658656986E-05, 8.74759856273634E-05, 4.87199929134556E-05, 8.19705725644494E-05, 0.000131830246954611, 0.000107493398021457, 0.000134093566279347, 0.000154031639650182, 0.000200584243165729, 0.00024276768462815, 0.000292696555715455, 0.000370278806637968, 0.000507548959635451, 0.000696925108804524, 0.000848325774817128, 0.00101057506480742, 0.00128081439834991, 0.00170673955890091, 0.0021450925433506, 0.00274776437474421, 0.00355134787259316, 0.00447104532303219, 0.00557349898328843, 0.00690208613991011, 0.00845707959564937, 0.010241833150862, 0.012287329319398, 0.0145353736128952, 0.0169943597652841, 0.01963496316142, 0.0225242224152523, 0.0255717274284043, 0.0287432528361527, 0.0319952150013279, 0.0352825133923142, 0.0385402961856969, 0.0417595661343778, 0.0449535755736095, 0.0479951431227533, 0.0508119761601612, 0.0535037276547127, 0.0560799171731777, 0.0584931552699401, 0.0606595397433995, 0.0626391522587842, 0.0644290601093262, 0.0660031850685414, 0.0673912219231121, 0.0686259970138369, 0.069722172672137, 0.070612231250209, 0.0714604171728813, 0.0722775522216351, 0.0729267901245575, 0.0734496512690242, 0.0739106361218835, 0.0743721929136665, 0.0747896735359017, 0.0751280940518256, 0.0754099382754536, 0.0757062989689115, 0.0759867322633067, 0.0762673100829459, 0.0765239818239271, 0.0767863419756437, 0.0770477434166765, 0.0772557202155063, 0.0774793847905566, 0.077687548982008, 0.0779263076457929, 0.0781845847083027, 0.0783634165529564, 0.0784971903404137, 0.078626804476334, 0.078803424497818, 0.0789734275919643, 0.0791337594891459, 0.0792016018575865, 0.0792757610721576, 0.0794037729989908, 0.0794377290961222, 0.0795123238226576, 0.0795988794698434, 0.0796303502161205, 0.0797138160046204, 0.0798762316963929, 0.0799921074276644, 0.0801081854005132, 0.0802696642166181, 0.0804052511542033, 0.0805767834679051};
double[] XNotWorking = new double[] {420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520};
double[] YNotWorking = new double[] {3.0244883406976, 2.83295966596341, 2.66178772393115, 2.49536986054521, 2.35247588199072, 2.19841374699224, 2.06936371068534, 1.94447612701576, 1.81831456842034, 1.69769200302452, 1.58251936763242, 1.47521907858038, 1.35135675658379, 1.25090839300155, 1.14067148661186, 1.03486600913928, 0.940885459333528, 0.841598797944357, 0.757820203011102, 0.681046307555002, 0.604403396323645, 0.540025064033112, 0.478340422261197, 0.426974657986113, 0.380669495238637, 0.344752920421447, 0.308383765576425, 0.272432523054477, 0.257553728541763, 0.234062303492469, 0.223253270206317, 0.210696726465545, 0.202538266655753, 0.203759268701798, 0.198306955613973, 0.203629801021742, 0.212560116373918, 0.220336224892702, 0.232028290678333, 0.245959346305367, 0.259218171633184, 0.2777450536022, 0.299094726645395, 0.316459804412063, 0.336837522082181, 0.361473822363433, 0.380590389468502, 0.404441363493798, 0.429219686796428, 0.45268891421585, 0.475338033132888, 0.499594235650765, 0.522422547413789, 0.547349852935894, 0.572580202632931, 0.599658563792795, 0.627115230055263, 0.656437694235189, 0.683296196948674, 0.712500622293025, 0.746534480082464, 0.777474719140242, 0.812042697632694, 0.849618263659198, 0.888244565260653, 0.928551592890494, 0.970491986073818, 1.00849410234163, 1.04626154346002, 1.09104901197512, 1.12398319460137, 1.15910129489684, 1.1959450891667, 1.227494518776, 1.2569215613004, 1.28414396566287, 1.30865735634816, 1.33254240407815, 1.35255778946778, 1.37179321554218, 1.3880305032149, 1.40317688705949, 1.41412136847739, 1.42757192488658, 1.43922979047245, 1.45122451456189, 1.46340435861582, 1.47171825187438, 1.48166055117652, 1.49385044441323, 1.50595310332654, 1.51876982551541, 1.52990961265142, 1.54201881038538, 1.55440258816695, 1.56705411648325, 1.57994676788576, 1.59261608906482, 1.60416093621065, 1.61493837998244, 1.62469252781368};
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

No branches or pull requests

1 participant