Similar function to gamma distribution

666 Views Asked by At

I'm searching for a function which looks similar to the gamma distribution in the following image (the blue one). It doesn't have to be exactly a gamma function. enter image description here

I need this for a programming project as weighting function. I.e. I have two parameters, minVal and maxVal. Between these two values the weight should be 1 (or near one). If x is lower than 'minVal' the weight decrease should be steep, if bigger than maxVal the weight should also decrease, but not as steep as below min.

Here a few examples for different minVal and maxVal (minVal and maxVal may be of any value, i.e. very small/large). There is no restriction for the integral of the function. Function Graphs

The best thing would be to have something like:

float getWeight(float x, float min, float max) {
    return fancyFunction(x,min,max);
}

The fancyFunction can be anything which can be calculated by a Java programm.

Thanks!!

1

There are 1 best solutions below

0
On BEST ANSWER

found a solution. It is a combination of exponential and gamma function:

private static double getWeight(double x, double minVal, double maxVal) {
    if (x == 0)
        return minVal > 0 ? 0 : 1;
    if (x < minVal)
        return (Math.exp(x * 8 / minVal) - 1) / Math.exp(8);
    else if (x > maxVal)
        return 1 / Gamma.gamma((1 / (maxVal - minVal)) * (x + maxVal - 2 * minVal));
    else
        return 1;
}

Here are some plots: 0.05 to 0.15 1 to 3 100 to 500