Skip to content

Commit

Permalink
Updated inverse distributions & documentation
Browse files Browse the repository at this point in the history
Added argument checking to the inverse  reporters for the normal, lognormal and student's-t distributions, and corrected the documentation for the lognormal reporters.
  • Loading branch information
cstaelin committed Jun 20, 2019
1 parent 8d1ebea commit 3f0487d
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -28,10 +28,10 @@ NETLOGO_JAR := "$(shell find "$(NETLOGO)"/app -name netlogo-*.jar)"
JAVAC := "$(JAVA_HOME)/bin/javac"
SRCS := $(wildcard src/*.java)

StatsExtension.zip: stats.jar Jama-1.0.3.jar colt.jar README.md license.md Makefile src manifest.txt StatsExtension-v2.1.pdf StatsExample.nlogo
StatsExtension.zip: stats.jar Jama-1.0.3.jar colt.jar README.md license.md Makefile src manifest.txt StatsExtension-v2.1.1.pdf StatsExample.nlogo
rm -rf stats
mkdir stats
cp -rp stats.jar Jama-1.0.3.jar colt.jar README.md license.md Makefile src manifest.txt StatsExtension-v2.1.pdf StatsExample.nlogo stats
cp -rp stats.jar Jama-1.0.3.jar colt.jar README.md license.md Makefile src manifest.txt StatsExtension-v2.1.1.pdf StatsExample.nlogo stats
zip -rv StatsExtension.zip stats
rm -rf stats

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -29,7 +29,7 @@ This package contains the NetLogo **stats extension**, which provides NetLogo wi

## Installation

First, [download the latest version of the extension](https://github.com/cstaelin/Stats-Extension/releases). Note that the latest version (2.1.0) of this extension was compiled against NetLogo 6.1. If you are using NetLogo version 6.0 you should downloard stats version 2.0.0, and if you are using one of the NetLogo 5 versions you should download stats version 1.4.0.
First, [download the latest version of the extension](https://github.com/cstaelin/Stats-Extension/releases). Note that the latest version (2.1.1) of this extension was compiled against NetLogo 6.1. If you are using NetLogo version 6.0 you should downloard stats version 2.0.0, and if you are using one of the NetLogo 5 versions you should download stats version 1.4.0.

Unzip the archive, rename the extracted directory to **stats**, and move the **stats** directory to the **extensions** directory inside your NetLogo application folder. The NetLogo application will normally be in the Applications folder on the Mac, or under C:\Program Files on Windows, and the **extensions** directory is in the **app** subdirectory of the NetLogo application. Or you can place the pathdir directory in the same directory holding the NetLogo model in which you want to use this extension.

Expand Down
Binary file added StatsExtension-v2.1.1.pdf
Binary file not shown.
Binary file removed StatsExtension-v2.1.pdf
Binary file not shown.
9 changes: 8 additions & 1 deletion src/DescripPrims.java
Expand Up @@ -127,7 +127,7 @@ public Object report(Argument args[], Context context)
throw new ExtensionException(e.getMessage());
}
if (n < 0) {
throw new ExtensionException("The number of quantiles must"
throw new ExtensionException("The number of quantiles must be"
+ " greater or equal to zero.");
}
double incr = 1.0 / n;
Expand Down Expand Up @@ -800,6 +800,13 @@ public Object report(Argument args[], Context context)
} catch (LogoException e) {
throw new ExtensionException(e.getMessage());
}
if (a <= 0.0 ) {
return 0.0;
}
if (a >= 1.0) {
throw new ExtensionException("The area parameter in lognormal-inverse "
+ " must be less than 1.0.");
}
return Math.exp(m + Distributions.getNormalInverse(a, 0, 1) * s);
}
}
Expand Down
18 changes: 14 additions & 4 deletions src/Distributions.java
Expand Up @@ -79,12 +79,17 @@ public static double getNormalArea(double x, double mean, double sd)
}

/* ---------------------------------------------------------------------- */
public static double getStudentTInverse(double x, int df)
public static double getStudentTInverse(double area, int df)
throws ExtensionException {
// Returns the value, t, for which the area under the Student-t
// probability density function (integrated from minus infinity to t)
// is equal to x.
double a = 2.0 * (1.0 - x);
// is equal to area.
if (area <= 0.0 || area >= 1.0) {
throw new ExtensionException("The area parameter in student-inverse "
+ " must be greater than 0.0 and less than 1.0.");
}
double a = 2.0 * (1.0 - area);

try {
return Probability.studentTInverse(a, df);
} catch (IllegalArgumentException | ArithmeticException ex) {
Expand All @@ -99,7 +104,12 @@ public static double getNormalInverse(double area, double mean, double sd)
// standard deviation, to the left of which lies the given area.
// normal.Inverse returns the value in terms of standard deviations
// from the mean, so we need to adjust it for the given mean and
// standard deviation.
// standard deviation. Note that the area must be strictly greater than
// zero and strictly less than 1.0.
if (area <= 0.0 || area >= 1.0) {
throw new ExtensionException("The area parameter in normal-inverse "
+ " must be greater than 0.0 and less than 1.0.");
}
try {
double x = Probability.normalInverse(area);
return (x + mean) * sd;
Expand Down
2 changes: 1 addition & 1 deletion src/StatsExtension.java
@@ -1,5 +1,5 @@
/*
* Stats extension, v.2.1.0 , May 2019
* Stats extension, v.2.1.1 , June 2019
* Versions 2.1.0 and above are compiled against NetLogo V6.1 and Java 1.8.
*//*
Expand Down
Binary file modified stats.jar
Binary file not shown.

0 comments on commit 3f0487d

Please sign in to comment.