## News:

Beta test the new forum at https://simutrans.forum/
SimuTranslator

## Sigmoid functions

Started by jamespetts, December 04, 2012, 12:20:24 AM

0 Members and 1 Guest are viewing this topic.

#### jamespetts

A while ago now, Moblet suggested that a number of dynamics (such as increasing way vehicle maintenance cost with usage) be simulated using sigmoid functions. I am keen to implement those suggestions at some time in the future, but also keen in the shorter term to use a sigmoid function to map the number of passengers who have certain journey time tolerances: for example, suppose a tolerance range of 5 minutes to 3 hours (180 minutes). The present linear function means that any given journey time tolerance is equally likely to be at 5 minutes or 180 minutes as at any given point in the middle of the range. A sigmoid function would mean a significantly greater possibility of the number being in the middle of the range than towards the extremities.

I must confess, I am a long way from being the world's greatest mathematician. A brief search on Google has not yielded any formulae of which I can make any sense. Can anyone point me in the right direction for the right sort of sigmoid function? I should be most grateful.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

#### sdog

You want the number of passengers still waiting after time t to follow a sigmoid function?

Else what you described sounds more like a standard distribution of wait times. If a Gauss bell curve is your probability density function, it would be consistent with a sigmoid function as cumulative density function.

A Gauss function has the form  s(x) = c exp(-0.5x^2),
where c is a constant factor norming it (the integral of s(x) from -infty to +infty) c=1/sqrt(2 pi).

When you integrate over this function from -infinity to x' you get a the cumulative density, which in turn is a sigmoid curve. It is assymptotic to 0  at the left side and 1 for increasing x'.
(Thats where the norming factor c from before comes to play, it ensures that 1 is not exceeded, ie not more pax aborted they journey than started it in the first place.)

In case this is what you were looking for, the WP article is rather good:

http://en.wikipedia.org/wiki/Normal_distribution

(Also a very important topic for ones general understanding of our world.)

#### jamespetts

Yes, you are correct that, in this context, it's a bell curve that I'm actually after (this is for journey time tolerances, incidentally, not waiting times).

I am afraid that my very limited understanding of anything more than basic mathematics is making your description hard to follow. What exactly is "the integral of s(x) from -infinity to +infinity"? In practical terms, how would one write code to calculate this value? Is there an exp function in a C++ mathematics library somewhere? Is there a way of doing this without any floating point values? Or is "c" just one divided by the square root of twice pi (which is 0.39894228040143267793994605993438; and therefore not an integer value)?

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

#### sdog

Don't worry too much about the implementation at first. It's not gonna be very difficult. Let the concepts sink in at first. As a second step you can look at discrete distributions.

Yes, there is an exp function, it is so fundamental any language with floats has it. You don't have to worry about numerical integration. You can get the formula for the latter, or rather see it differently:

If you have a couple of people with a random journey time tolerance, just letting time run integrates them. The integral is the number of people who left after a time, wait a little longer and you get the next integral value. So what it does is it just sums up the number of people. (Perhaps you remember from your school days calculus the definition of Rieman integrals.) The nice thing is when you go to discrete distributions, you get rid of the integrals and reach sums.

#### ӔO

I don't really know how to do bell curves, but I do know you can get a close approximation with an, I think, quadratic formula.
http://www.wolframalpha.com/input/?i=2%28x-2%29%28x-1%29%28x%2B1%29%28x%2B2%29%2B6
My Sketchup open project sources
various projects rolled up: http://dl.dropbox.com/u/17111233/Roll_up.rar

Colour safe chart:

#### sdog

Don't get yourself too much distracted by the exponential function in the normal distribution. It is only an example.

The statisitical process you have, with Yes/No decissions of single passengers, independent of others follows a,discrete, binomial distribution. When you look at the plots, you might notice a similarity.

http://en.wikipedia.org/wiki/Binomial_distribution

#### kierongreen

Random number plus different random number gives you a simple bell shaped distribution. A simple example is rolling two dice (or one dice twice) and adding the values - 6 or 7 is more likely than 1 or 12.

#### jamespetts

Thank you all for your help. Kieron - that is especially helpful, as that strikes me as the simplest and least computationally expensive way of producing a bell curve for distribution purposes.

The task on which I shall have to embark fairly soon of having usage related vehicle and way maintenance costs will require a true sigmoid function, rather than a bell curve, where I shall have to calculate value x (the adjusted maintenance cost) from value y (a value representing usage, such as km travelled since the last overhaul) and value b (the base maintenance cost). Any thoughts on how best to achieve this would be most welcome.