I am trying to create a pareto distribution prediction function:
const paretoDistributionPrediction = (numberOfPeople, personAtIndex) => {
let prediction = '?'
if (numberOfPeople === 2) {
prediction = personAtIndex === 1 ? 80 : 20;
}
return prediction + "%";
}
paretoDistributionPrediction(2, 1)
The perfect shape that gives the results I want is a cycloid rotated 45deg to fit without its cups in a square.
The right side of the square is always divided in equal parts by numberOfPeople. From the interaction with the cycloid curve, the lines perpendicularly divide the bottom side of the square. Then I want to know how much is in percentage a division from the bottom side of the square for personAtIndex (index of an item in numberOfPeople).
After the right side of the square is divided in equal parts by horizontal lines, how to find out the size of the corresponded division on the bottom side of the square after the incident lines have perpendicular intersected with the cycloid curve?
In the first drawing you can see how I reached the conclusion that a cycloid is the shape that will give an 80 20 ratio output.
Bellow images are expected outputs for paretoDistributionPrediction=f function: f(2,1)=80%, f(2,2)=20%, f(3,1)=68%,f(3,2)=23%,f(3,3)=9%,f(4,1)=58%,f(4,2)=22%,f(4,4)=7%.





A solution
A cycloid that conforms to the description of the question is given by the parametric coordinates:
I'll describe later how I derived those equations and computed the parameters.
Now, regardless of the actual curve that is used, if it defined parametrically, the mathematics involved for determining the parameters of the distributions involve getting the value of
ythat corresponds to a certainxon the curve - it means solve the equationy(t) = yto get the parametertand then use that parameter to computex(t).For the case of the cycloid, as well as most other curves, the solution of the equation
y(t) = ycannot be derived in closed form, so it has to be computed numerically. The numerical method I have chosen is Newton's method; it requires the derivative ofy(t),y'(t), which I implemented in the functionyd(t).With these, the solution to the problem in question is this:
also as jsFiddle
The cycloid
The standard equation of the cycloid is
These equations give a cycloid that passes through the point
(0, 0),(PI*r, 2*r)- the maximum,(2*PI*r, 0).To make it symmetrical with respect to the origin (more precisely with respect to the
yaxis), we have to subtractPI * rfromxThis curve passes through
(-PI*r, 0),(0, 2*r)- the maximum, and(PI*r, 0).The next step is to rotate the cycloid by
-3*PI/4, that is 145 degrees clockwise. This gives the equations:These would allow one to compute
rsuch that the cycloid passes through the points (1, 0) and (0, -1); due to symmetry, only one condition has to be verified. This givesr = 0.43077140606812125(see below on how I computedranddr, for an outline of the method to deriver).The problem with this curve is that it doesn't pass through the point
(0.8, -0.5), which would make it verify the 80:20 ratio of Pareto fame. Thexvalue that corresponds toy = -0.5(50%) isx = 0.7094, which would make it 71:29. This can be seen in the snippet below (get the cursor near the cycloid to get other ratio values).also as jsFiddle
To address this issue, I added a translation of the cycloid, after the rotation. To keep symmetry, the translation has to be along the
x = -yline; this would add adrto x, while,y = y - dr. With this new parameter, the equations of the cycloid are:Now we have two equations to solve for the two unknowns,
randdr: the first equation comes again from the condition that the cycloid passes through the pointx=1, y=0, while the second is to verify the 80:20 ration, that is that the cycloid passes through the pointx=0.8, y=-0.5.With these, we get the values of the parameters
r = 0.3107954365513382, dr = 0.22339354437585907(see below how). Here's the cycloid in this case:also as jsFiddle
Computing
randdrThis is of little consequence for the rest of the discussion, but I'll give the code and description for the sake of completeness.
I computed the values of
randdr, from the equationsx(t) = 0, y(t) = 1andx(t) = 0.5andy(t) = -0.8as described in the previous section. For any pair of values forranddrwe can compute four values oftthat the four equations above:x(t1) = 0,y(t2) = 1,x(t3) = 0.5,y(t4) = -0.8. Computing the fourts is done as described in the first section, by using Newton's method.Now, the first two equations of the four above should come together, that is for the same
t:t1 = t2; the same goes for the last two, we intend to find theranddrthat givet3 = t4. This means we have our two equations as:This system is also solved using Newton's method, with the difference that the differentials are computed numerically.
For the method to be convergent, one has to start with good initial values; fortunately, there is the cycloid graphic above, where we could play with the values of parameters with visual feedback, such that we obtained good initial values.
Here's the code:
also as jsFiddle
Note In the code in the first section, I used
-yinstead ofy, to simplify computation. Graphically it would mean flipping the chart along x axis, or moving the action from quadrant 4 to quadrant 1.