forum.alglib.net

ALGLIB forum
It is currently Sun Dec 22, 2024 9:09 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: logisticfit4 not giving expected results
PostPosted: Thu Nov 01, 2018 2:46 pm 
Offline

Joined: Thu Nov 01, 2018 2:06 pm
Posts: 3
I'm evaluating alglib (C++) for possible use in an embedded application that needs to do some 4PL curve fit calculations. The OS is QNX (Posix) and the CPU is x86-64. I have successfully built the library and run the test_c.cpp checks so I think it is functional. I also ran the example attached to logisticfit4 and it gave the expected results.

However, when I input some sample project data, I'm not getting the expected results. I will attach the test program and the csv file containing the input data. For this data, MATLAB and the ZunZun online 4PL calculator give almost identical results very different from Alglib:

Param Alglib MATLAB ZunZun
a 0.0850 0.0988 0.0986
b 10 31.9422 31.9155
c 22.4659 17.535 17.535
d 5.42989 1.0139 1.0140

Here is the output I get when I run my test with Alglib:

a = 0.0850456
b = 10
c = 22.4659
d = 5.42989
iterations = 118
RMS error = 0.0469343
Avg error = 0.0303365
Avg relative error = 0.192896
Max error = 0.1581
R squared = 0.960512

I tried to use logisticfit45x() to affect the results but I don't understand how to use the controls and the results didn't improve. Can you tell me what I'm doing wrong?


Attachments:
File comment: Source file to read the CSV file and calculate the 4PL fit parameters
main.cpp [2.45 KiB]
Downloaded 716 times
File comment: CSV file with x in the first column and y in the second column
sensor8lowedit.csv [2.88 KiB]
Downloaded 677 times
Top
 Profile  
 
 Post subject: Re: logisticfit4 not giving expected results
PostPosted: Thu Nov 01, 2018 5:38 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
Hi!

I confirm the bug, and I think that I know the reason behind it (unable to test it at my work PC, already out of office, but I am pretty sure).

For stability reasons ALGLIB puts constraints on parameters being fitted and relaxes them several times. However, when logistic fitting functionality was developed it was thought that constraining B to be in [0.1,10] range is good enough option. It is exponent, after all - no one imagined that actual data will need an exponent equal to 30! So, relaxing this constraint should help to solve the problem.

You can do so yourself as follows (I do not give you line numbers because your trial is customized with license boilerplate, line numbers are different from that of the publicly available ALGLIB):
1) find a line with comment "Relax constraints, run optimization one more time" in the interpolation.cpp. It is the only such line in the file.
2) below this line find bndl.ptr.p_double[1] = 0.1; and replace 0.1 by 0.01
3) below this line find bndu.ptr.p_double[1] = 10.0; and replace 10.0 by 100.0

Does it help?


Top
 Profile  
 
 Post subject: Re: logisticfit4 not giving expected results
PostPosted: Thu Nov 01, 2018 5:59 pm 
Offline

Joined: Thu Nov 01, 2018 2:06 pm
Posts: 3
Yes, that worked. Thank you for the quick response. The output is now as expected:

a = 0.0985619
b = 31.9155
c = 17.535
d = 1.01404
iterations = 140
RMS error = 0.0112002
Avg error = 0.00489951
Avg relative error = 0.019207
Max error = 0.0658847
R squared = 0.997751

I do have a comment about limiting b, even to 0.01 to 100. According to https://www.myassays.com/four-parameter-logistic-regression.html, b is the slope of the curve at c (the inflection point). I can imagine cases where the slope could be outside of 0.01-100, although it is a matter of units (e.g. using kg vs. g). But I would think to be on the safe side you would allow 0.001 to 1000.


Top
 Profile  
 
 Post subject: Re: logisticfit4 not giving expected results
PostPosted: Fri Nov 02, 2018 10:06 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
1) I am a bit concerned about robustness here. It is easy to ruin entire optimization session by making step in a wrong place (too large/small b and/or c). In your case relaxing bounds worked fine, but I still have to think about how to make it robust in the general case.

2) is it possible to use your data as a part of our test suite? :-) of course, I can generate something synthetic like that... but generally it is a matter of good taste to include cases which failed in the tests :)


Top
 Profile  
 
 Post subject: Re: logisticfit4 not giving expected results
PostPosted: Fri Nov 02, 2018 1:38 pm 
Offline

Joined: Thu Nov 01, 2018 2:06 pm
Posts: 3
Yes, that is fine


Top
 Profile  
 
 Post subject: Re: logisticfit4 not giving expected results
PostPosted: Fri Nov 02, 2018 2:40 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
Thank you, Eric!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 37 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group