1
\$\begingroup\$

I am making a game where there are objects that will be for sale. The objects have a reputation score, which is the amount of sales they get each week. This is calculated up front and remains the same for the entire release period. The release period is also created up front and represents a period of time in weeks.

In my example Object#1 has a sales score of 10,000 and a release period 8 weeks. This means it will sell 80,000 copies at 10k/week.

My aim is to take this flat line, and curve it, so it has rising sales at the start, a smoothed peak of sales in the middle, and lower sales at the end tailing off, like a gamma probability distribution curve. The total sales across the period will be the 80,000, but the distribution of weekly sales will change.

gamma probability distribution curve

I am looking to create this distribution shape from the flat sales total. I'd ideally like to keep the sales volume the same, but as long as I have that curve, it doesn't matter too much. I have looked at the Wikipedia entries etc, but they are all about the maths side of distribution, and calculating distribution from figures, I am just looking to fake that distribution from a median figure.

The idea is once I have this algorithm (or a good tutorial), I can play with it to create other unique distributions, adding variety to object releases, to help make things feel less procedural.

(Any help with improving title and tags greatly appreciated).

Edit -----

I realised I missed out a chunk about looking for help with the programming. I have read a lot of math algorithms but converting what I am learning into code is proving more difficult. Ideally I'd like links/references to solutions for this from a C# perspective, to help me see my way past issues like the one below.

I have a function in math: BetaCDF(x,a,b) = (x>=1)?1:(x<=0)?0:sum[k=1:b] ( Gamma(a+k-1)/(Gamma(a)*Gamma(k)) * xa * (1-x)(k-1) )

that i am trying to convert into a function. I have everything covered except for the sum. I need to sum b times the function on the right, however I cannot figure out how to do this in Unity C#. The function currently looks like this:

public static double BetaCDF(double x, double a, double b) {
    double k;
    return ((x >= 1) ? 1 : (x <= 0) ? 0 : Sum(k = 1,b )(Gamma(a + k - 1) / (Gamma(a) * Gamma(k)) * Math.Pow(x, a) * Math.Pow(1 - x, k - 1)));
}
\$\endgroup\$
1
\$\begingroup\$

You can use curve fitting programs to trace the line and guess a curve (also called regression). plot.ly can graph plotted points and has an analyze>curve fit tool that can build an equation from that.

These kind of curves are Gaussian (probability distribution) curves: https://en.wikipedia.org/wiki/Gaussian_function (perhaps more specifically a Hubbert curve: https://en.wikipedia.org/wiki/Hubbert_curve)

You can get also crude approximations using 6+order polynomial functions over a limited domain, but that will likely look sloppy

\$\endgroup\$
  • \$\begingroup\$ Thanks for the links, those answers help greatly, although are still very much in the mathematical realm. I am trying to improve my understanding of the equations from a programming perspective. For example, in trying to convert some mathematical equations I am testing, but I cannot figure out how to turn BetaCDF(x,a,b) = (x>=1)?1:(x<=0)?0:sum[k=1:b] ( Gamma(a+k-1)/(Gamma(a)*Gamma(k)) * x**a * (1-x)**(k-1) ) into a c# statement because of the sum function. The remainder of the function is: \$\endgroup\$ – SoulRider Oct 21 '16 at 19:43
  • \$\begingroup\$ editing original to advise this as I missed out the programming focus originally. \$\endgroup\$ – SoulRider Oct 21 '16 at 19:45
  • \$\begingroup\$ if you look at the gaussian function article, you will see a simple f(x) function at the top of the article. You should be able to incorporate that easily. Anyway, for a sum function, simply make a second function that will take your list (b) and just add them all together. Most languages even provide one built in \$\endgroup\$ – CobaltHex Oct 21 '16 at 20:28
  • \$\begingroup\$ Unfortunately there is no Sum function in the mono implementation used by Unity. \$\endgroup\$ – SoulRider Oct 21 '16 at 20:41
  • \$\begingroup\$ linq should have one. (or if you use Javascript, which has reducers, accumulators, etc). However, Sum is super easy: literally just `int sum(List<int> li) { int ac = 0; foreach (var i in li) ac += i; return ac; } \$\endgroup\$ – CobaltHex Oct 21 '16 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.