Search in sources :

Example 71 with Description

use of com.facebook.presto.spi.function.Description in project presto by prestodb.

the class MathFunctions method inverseBetaCdf.

@Description("inverse of Beta cdf given a, b parameters and probability")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double inverseBetaCdf(@SqlType(StandardTypes.DOUBLE) double a, @SqlType(StandardTypes.DOUBLE) double b, @SqlType(StandardTypes.DOUBLE) double p) {
    checkCondition(p >= 0 && p <= 1, INVALID_FUNCTION_ARGUMENT, "p must be in the interval [0, 1]");
    checkCondition(a > 0, INVALID_FUNCTION_ARGUMENT, "a must be > 0");
    checkCondition(b > 0, INVALID_FUNCTION_ARGUMENT, "b must be > 0");
    BetaDistribution distribution = new BetaDistribution(null, a, b, BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    return distribution.inverseCumulativeProbability(p);
}
Also used : BetaDistribution(org.apache.commons.math3.distribution.BetaDistribution) DecimalOperators.modulusScalarFunction(com.facebook.presto.type.DecimalOperators.modulusScalarFunction) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 72 with Description

use of com.facebook.presto.spi.function.Description in project presto by prestodb.

the class MathFunctions method binomialCdf.

@Description("Binomial cdf given numberOfTrials, successProbability, and a value")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double binomialCdf(@SqlType(StandardTypes.INTEGER) long numberOfTrials, @SqlType(StandardTypes.DOUBLE) double successProbability, @SqlType(StandardTypes.INTEGER) long value) {
    checkCondition(successProbability >= 0 && successProbability <= 1, INVALID_FUNCTION_ARGUMENT, "successProbability must be in the interval [0, 1]");
    checkCondition(numberOfTrials > 0, INVALID_FUNCTION_ARGUMENT, "numberOfTrials must be greater than 0");
    BinomialDistribution distribution = new BinomialDistribution(null, (int) numberOfTrials, successProbability);
    return distribution.cumulativeProbability((int) value);
}
Also used : BinomialDistribution(org.apache.commons.math3.distribution.BinomialDistribution) DecimalOperators.modulusScalarFunction(com.facebook.presto.type.DecimalOperators.modulusScalarFunction) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 73 with Description

use of com.facebook.presto.spi.function.Description in project presto by prestodb.

the class MathFunctions method betaCdf.

@Description("Beta cdf given the a, b parameters and value")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double betaCdf(@SqlType(StandardTypes.DOUBLE) double a, @SqlType(StandardTypes.DOUBLE) double b, @SqlType(StandardTypes.DOUBLE) double value) {
    checkCondition(value >= 0 && value <= 1, INVALID_FUNCTION_ARGUMENT, "value must be in the interval [0, 1]");
    checkCondition(a > 0, INVALID_FUNCTION_ARGUMENT, "a must be > 0");
    checkCondition(b > 0, INVALID_FUNCTION_ARGUMENT, "b must be > 0");
    BetaDistribution distribution = new BetaDistribution(null, a, b, BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    return distribution.cumulativeProbability(value);
}
Also used : BetaDistribution(org.apache.commons.math3.distribution.BetaDistribution) DecimalOperators.modulusScalarFunction(com.facebook.presto.type.DecimalOperators.modulusScalarFunction) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 74 with Description

use of com.facebook.presto.spi.function.Description in project presto by prestodb.

the class MathFunctions method inverseBinomialCdf.

@Description("inverse of Binomial cdf given numberOfTrials, successProbability parameters and p")
@ScalarFunction
@SqlType(StandardTypes.INTEGER)
public static long inverseBinomialCdf(@SqlType(StandardTypes.INTEGER) long numberOfTrials, @SqlType(StandardTypes.DOUBLE) double successProbability, @SqlType(StandardTypes.DOUBLE) double p) {
    checkCondition(p >= 0 && p <= 1, INVALID_FUNCTION_ARGUMENT, "p must be in the interval [0, 1]");
    checkCondition(successProbability >= 0 && successProbability <= 1, INVALID_FUNCTION_ARGUMENT, "successProbability must be in the interval [0, 1]");
    checkCondition(numberOfTrials > 0, INVALID_FUNCTION_ARGUMENT, "numberOfTrials must be greater than 0");
    BinomialDistribution distribution = new BinomialDistribution(null, (int) numberOfTrials, successProbability);
    return distribution.inverseCumulativeProbability(p);
}
Also used : BinomialDistribution(org.apache.commons.math3.distribution.BinomialDistribution) DecimalOperators.modulusScalarFunction(com.facebook.presto.type.DecimalOperators.modulusScalarFunction) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 75 with Description

use of com.facebook.presto.spi.function.Description in project presto by prestodb.

the class MathFunctions method inversePoissonCdf.

@Description("Inverse of Poisson cdf given lambda (mean) parameter and probability")
@ScalarFunction
@SqlType(StandardTypes.INTEGER)
public static long inversePoissonCdf(@SqlType(StandardTypes.DOUBLE) double lambda, @SqlType(StandardTypes.DOUBLE) double p) {
    checkCondition(p >= 0 && p < 1, INVALID_FUNCTION_ARGUMENT, "p must be in the interval [0, 1)");
    checkCondition(lambda > 0, INVALID_FUNCTION_ARGUMENT, "lambda must be greater than 0");
    PoissonDistribution distribution = new PoissonDistribution(lambda);
    return distribution.inverseCumulativeProbability(p);
}
Also used : PoissonDistribution(org.apache.commons.math3.distribution.PoissonDistribution) DecimalOperators.modulusScalarFunction(com.facebook.presto.type.DecimalOperators.modulusScalarFunction) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Aggregations

Description (com.facebook.presto.spi.function.Description)105 SqlType (com.facebook.presto.spi.function.SqlType)103 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)101 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)41 SqlNullable (com.facebook.presto.spi.function.SqlNullable)37 OGCGeometry.createFromEsriGeometry (com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry)20 GeometryUtils.jsonFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry)20 GeometryUtils.wktFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry)20 Geometry (org.locationtech.jts.geom.Geometry)20 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)19 PrestoException (com.facebook.presto.spi.PrestoException)18 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)15 Slice (io.airlift.slice.Slice)15 SqlScalarFunction (com.facebook.presto.metadata.SqlScalarFunction)14 Constraint (com.facebook.presto.type.Constraint)14 DecimalOperators.modulusScalarFunction (com.facebook.presto.type.DecimalOperators.modulusScalarFunction)13 Point (com.esri.core.geometry.Point)10 SliceUtf8.lengthOfCodePoint (io.airlift.slice.SliceUtf8.lengthOfCodePoint)7 SliceUtf8.offsetOfCodePoint (io.airlift.slice.SliceUtf8.offsetOfCodePoint)7 Envelope (com.esri.core.geometry.Envelope)6