Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pareto distribution #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/java/blang/distributions/Generators.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.apache.commons.math3.distribution.GammaDistribution;
import org.apache.commons.math3.distribution.PoissonDistribution;
import org.apache.commons.math3.distribution.TDistribution;
import org.apache.commons.math3.distribution.ParetoDistribution;

import bayonet.math.NumericalUtils;
import blang.types.DenseSimplex;
Expand All @@ -28,6 +29,14 @@ public static double halfstudentt(Random random, double nu, double sigma) {
double t = studentt(random, nu);
return Math.abs(t) * sigma;
}

/** */
public static double pareto(Random random, double scale, double shape)
{
double result = new ParetoDistribution(generator(random), scale, shape).sample();
return result;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify to

return new ParetoDistribution(generator(random), scale, shape).sample();

I think this pattern in this file is an artifact of some past debugging session. They could actually all be simplified.

}

/** */
public static double chisquared(Random random, int nu)
{
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/blang/distributions/Pareto.bl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package blang.distributions
// Pareto distribution
// support: (scale, \infty)

model Pareto {
random RealVar realization
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments for each random/param (see other built-in examples)


param RealVar scale, shape

laws {
logf(realization, scale, shape) {
if (scale <= 0) return NEGATIVE_INFINITY
if (shape <= 0) return NEGATIVE_INFINITY
if (realization < scale) return NEGATIVE_INFINITY
return log(shape) + shape * log(scale) - (shape + 1) * log(realization)
}
}

generate(rand) {
rand.pareto(scale, shape)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import blang.distributions.StudentT
import blang.distributions.HalfStudentT
import blang.distributions.ChiSquared
import blang.distributions.YuleSimon
import blang.distributions.Pareto

class BuiltInDistributions {

Expand All @@ -51,6 +52,7 @@ class BuiltInDistributions {
documentClass(StudentT)
documentClass(HalfStudentT)
documentClass(ChiSquared)
documentClass(Pareto)
]

section("Multivariate") [
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/blang/Examples.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import blang.validation.internals.fixtures.DynamicNormalMixture
import blang.distributions.NegativeBinomialMeanParam
import blang.distributions.GammaMeanParam
import blang.distributions.YuleSimon
import blang.distributions.Pareto

class Examples {

Expand Down Expand Up @@ -125,6 +126,15 @@ class Examples {
realRealizationSquared
)

public val pareto = add(
new Pareto.Builder()
.setScale(fixedReal(2.1))
.setShape(fixedReal(1.5))
.setRealization(latentReal)
.build,
realRealizationSquared
)


public val bern = add(
new Bernoulli.Builder()
Expand Down