Note that there are some explanatory texts on larger screens.

plurals
  1. POCurve fitting: Find the smoothest function that satisfies a list of constraints
    text
    copied!<p>Consider the set of non-decreasing <a href="http://mathworld.wolfram.com/Surjection.html" rel="nofollow noreferrer">surjective</a> (onto) functions from (-inf,inf) to [0,1]. (Typical <a href="http://mathworld.wolfram.com/DistributionFunction.html" rel="nofollow noreferrer">CDF</a>s satisfy this property.) In other words, for any real number x, 0 &lt;= f(x) &lt;= 1. The <a href="http://en.wikipedia.org/wiki/Logistic_function" rel="nofollow noreferrer">logistic function</a> is perhaps the most well-known example.</p> <p>We are now given some constraints in the form of a list of x-values and for each x-value, a pair of y-values that the function must lie between. We can represent that as a list of {x,ymin,ymax} triples such as</p> <pre><code>constraints = {{0, 0, 0}, {1, 0.00311936, 0.00416369}, {2, 0.0847077, 0.109064}, {3, 0.272142, 0.354692}, {4, 0.53198, 0.646113}, {5, 0.623413, 0.743102}, {6, 0.744714, 0.905966}} </code></pre> <p>Graphically that looks like this:</p> <p><a href="http://yootles.com/outbox/cdffit1.png" rel="nofollow noreferrer">constraints on a cdf http://yootles.com/outbox/cdffit1.png</a></p> <p>We now seek a curve that respects those constraints. For example:</p> <p><a href="http://yootles.com/outbox/cdffit2.png" rel="nofollow noreferrer">fitted cdf http://yootles.com/outbox/cdffit2.png</a></p> <p>Let's first try a simple interpolation through the midpoints of the constraints:</p> <pre><code>mids = ({#1, Mean[{#2,#3}]}&amp;) @@@ constraints f = Interpolation[mids, InterpolationOrder-&gt;0] </code></pre> <p>Plotted, f looks like this:</p> <p><a href="http://yootles.com/outbox/cdffit3.png" rel="nofollow noreferrer">interpolated cdf http://yootles.com/outbox/cdffit3.png</a></p> <p>That function is not surjective. Also, we'd like it to be smoother. We can increase the interpolation order but now it violates the constraint that its range is [0,1]:</p> <p><a href="http://yootles.com/outbox/cdffit4.png" rel="nofollow noreferrer">interpolated cdf with higher interpolation order http://yootles.com/outbox/cdffit4.png</a></p> <p>The goal, then, is to find the <a href="http://mathworld.wolfram.com/SmoothFunction.html" rel="nofollow noreferrer">smoothest function</a> that satisfies the constraints:</p> <ol> <li>Non-decreasing.</li> <li>Tends to 0 as x approaches negative infinity and tends to 1 as x approaches infinity.</li> <li>Passes through a given list of y-error-bars.</li> </ol> <p>The first example I plotted above seems to be a good candidate but I did that with Mathematica's <a href="http://reference.wolfram.com/mathematica/ref/FindFit.html" rel="nofollow noreferrer">FindFit</a> function assuming a <a href="http://mathworld.wolfram.com/LogNormalDistribution.html" rel="nofollow noreferrer">lognormal CDF</a>. That works well in this specific example but in general there need not be a lognormal CDF that satisfies the constraints.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload