Sigmoid fitting

How do I fit a set of points to a sigmoid funtion in arduino?

It's not clear what you mean. Do you mean you have a graph of a sigmoid function (and there are many functions whose graph is sigmoidal of course, meaning it is every where differentiable with a non-negative derivative, and has exactly one inflection) and you want to know what points it passes through? Or you have a bunch of points and you want to fit a sigmoidal curve to them? Or what?

What's this got to do with Arduino?- other than perhaps the Arduino being the place your code runs... Your requirement is very very unclear.

you are right, I was a bit unclear. So I have a bunch of points in an array and I want to fit a sigmoidal curve to them so I can find the inflection point. And, yes I need to run this in arduino

So what's the algorithm that you want to use and need help with to code? Or to put it another way, how would you do it with pencil and paper?

There are many functions whose output is sigmoidal; which one do you intend to use?

My point is, this isn't an "Arduino problem" as such, just because you want the code to run in an Arduino. Seems more like a maths problem to me- you need to know how to do this in principle first- the code is surely the second step to the process.

1 Like

But that all said, do you actually need to find the curve that fits? There's probably a numerical method to analyse the pairs of points and find the two between which the point of inflection sits. Undergrad applied maths was 45y ago for me, so I can't recall if there is such a technique without having to know the curve's equation.

Assuming there is such a technique, the coding would be pretty trivial I think.

So my question to you is basically, do you a) require help with coding a technique you already have in your head/hands to find the point of inflection or b) do you require help with determining the technique in the first place?

Is there a second part of your project that uses your calculated result to do something Arduino related? Because given the stated problem, you could just as easily use a PC.

Reading wiki and other sources a bit further, I am reminded that the inflection point is where x' changes sign and so x"=0, and there must surely be a numerical method for that?

If the sigmoid function is given in library form, the y-intercept is the constant (solve for x=0). Plug in the (x,y) pairs (x value and compare y returns within the margin of error for your approximation of Euler's Constant) to determine if the pair is a solution of the function. If you do not have the function given, you would need a Computer Algebra System, as most microcontrollers are good at arithmetic, but algebra is a higher order, and usually requires a PC at minimum.

If he had the function it would be easy: but according to #3 he has an array of points and needs to fit a function to that. But the reason behind that is that he needs the point of inflection in fact, so I'm speculating there must be a numerical method to find the point, given an array of pairs, without necessarily knowing the function.

But where the Arduino comes in, other than as a place to run some code (and as you say @Perehama , not an optimum place for that) is not yet known to us.

Easiest would be just to plot the graph and assess the point of inflection with Eyeball, Mk1....

It is unclear to me in #3 if he has it or not. I read ambiguity in the following phrase.

So, addressing the ambiguity, if the function is given, simple. If not, next to impossible. I am assuming this is for a class as the real world doesn't present these sorts of challenges, so I have to assume the instructor would not present an impossible task.

I read it that he wants to fit a curve to given points, then for some reason as yet unknown to us, find the point of inflection.

Reads to me like some kind of class assignment too @Perehama , and I'm keen to know why it's an Arduino project. Perhaps (more speculation....) the co-ords of the point of inflection then feed into some other part of the task which does need an Arduino, as wondered by @wildbill in #6.

So that we know what you are talking about, please post an example of the list of points, and the formula for the sigmoid function you have in mind (there are many).

I asked that in #4 2 hours ago :wink:

You forgot to ask for an example of the data.

So i have a bunch of points tha came from a sensor, those points are "shaped like a sigmoid function", I dont have any funtion! I would like to fit those points to a sigmoid funtion so the i could find the infletion point using the second derivative. For reasons... i need this to be done in arduino, actualy Im using a esp32 but with arduino code, neverdeless, All this so that only the infletion point is send to wi-fi to a computer.
My ideia was to fit the points to a sigmoid to then find the inflexion point, but if you guys have a better ideia how to do in another way, i am listening.
The formula is of a inverted sigmoid: 1/(1+e^x)

If you do the fitting by hand, you can do the arithmetic for additional points, including x = 0, in the esp32, but you need a formula before you code the arithmetic. If you can't solve the algebra by hand, you need a computer algebra system. You cannot code a decent CAS in the esp32. I would use the form m ((e ^ x)/(e ^ x + 1) + b.

1 Like

There are no adjustable parameters in that function.

1 Like

I'm pretty sure there's a numerical method for that, given the pairs, without having to know the function. But as @jremington points out in #17, you can't adjust the formula you gave to fit the points. It's not like you were trying a least-squares fit of a straight line to some points, where you have an infinite number of choices for m and c. Your points either fit on the equation or they don't.

I think you need to find x" by a numerical method and see where it's 0.

1 Like

since A1 and A2 are pretty far off the grid, you might want to use points that get within a reasonable margin of error as approximates. Calculus is one order up from Algebra, but not too hard to do by hand.

1 Like