Java Randomness Test Suite

JRandTest at SourceForge

com.fasteasytrade.JRandTest.Tests
Class Base

java.lang.Object
  extended bycom.fasteasytrade.JRandTest.Tests.Base
Direct Known Subclasses:
BinaryRankTestFor6x8Matrices, BirthdaySpacings, Count16Bits, Count1Bit, Count2Bits, Count3Bits, Count4Bits, Count8Bits, CountThe1s, MinimumDistance, MonteCarlo, Overlapping20TuplesBitstream, OverlappingPairsSparseOccupancy, Run, Squeeze

public class Base
extends Object

Base class for all test classes.

Contains common methods and handle input/output list of listeners.

Author:
Zur Aougav

Nested Class Summary
 class Base.point
           
 
Field Summary
static DecimalFormat df
           
 int DIM
           
 double PI
           
(package private)  RandomStream rs
           
 long UNIMAX
           
(package private)  Vector vecOutputDestinations
           
 
Constructor Summary
Base()
           
 
Method Summary
 double ABS(double a)
           
 int ABS(int a)
           
private  double AD(double z)
          c.d.f of Anderson-Darling statistic (a quick algorithm) Used by KStest
 void addOutputDestination(OutputDestination od)
          register output destination in vector of output destinations. printf and puts willwrite data to all destinations.
static double avg(double[] data)
           
 double chisq(int df, double x)
          p.d.f of Chi-square
 double Chisq(int df, double x)
          c.d.f of Chi-square
static double chitest(double[] data, double expected)
           
 boolean closeInputStream()
          open registered RandomStream.
 String d4(double d)
          Returns double as string 10.4: zzzzz.dddd.
 double d4d_d(double d)
           
 String d4d(double d)
           
 double exp(double a)
           
 double exp(int a)
           
 double G(double z)
          gamma(z) when 2z is a integer
 void help()
          help method to be implemented by each test class.
 boolean isOpen()
          checks if input random stream is open.
 double KStest(double[] x, int dim)
          KStest This test is based on a modified Kolmogorov-Smirnov method.
 double log(double a)
           
 double MAX(double a, double b)
           
 int MAX(int a, int b)
           
 double MIN(double a, double b)
           
 int MIN(int a, int b)
           
 boolean openInputStream()
          open registered RandomStream.
 double phi(double x)
          p.d.f of Standard Normal
 double Phi(double x)
          c.d.f of Standard Normal
 double[] Poisson_fit(double lambda, int[] obs, int no_obs)
          computes the statistic of goodness of fit to a Poisson distribution
 double Poisson(double lambda, int k)
          p.d.f of Poisson distribution
 double pow(double a, double b)
           
 void printf(String s)
          printf on all output destinations registered into vector output destinations.
 void puts(String s)
          puts - use printf
 void qsort(Base.point[] arr, int dim)
          Bubble sort array of points (of class point),
 void qsort(double[] arr, int dim)
          Bubble sort array
 void qsort(int[] arr, int dim)
          Bubble sort array
static double r2_double(double[] data)
           
 double read32BitsAsDouble()
          read one int from registered input random stream and divide it by (2^32 - 1).
 byte readByte()
          read one byte from registered input random stream.
 int readInt()
          read one byte from registered input random stream.
 long readLong()
          read one long from registered input random stream.
 void registerInput(RandomStream rs)
          register RandomStream interface.
 void removeOutputDestination(OutputDestination od)
          unregister output destination from vector of output destinations.
 void showbit(int n)
          show the bit-pattern of an integer 32 bits
 double SIGN(double a)
           
 int SIGN(int a)
           
 double sqrt(double a)
           
 double sqrt(int a)
           
static double stdev(double[] data, double avg)
          Returns double Standard Deviation
 void test(String filename)
          test method to be implemented by each test class.
 int uni()
          Use readInt method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PI

public final double PI
See Also:
Constant Field Values

DIM

public final int DIM
See Also:
Constant Field Values

UNIMAX

public final long UNIMAX
See Also:
Constant Field Values

df

public static DecimalFormat df

vecOutputDestinations

Vector vecOutputDestinations

rs

RandomStream rs
Constructor Detail

Base

public Base()
Method Detail

MAX

public double MAX(double a,
                  double b)

MAX

public int MAX(int a,
               int b)

MIN

public double MIN(double a,
                  double b)

MIN

public int MIN(int a,
               int b)

ABS

public double ABS(double a)

ABS

public int ABS(int a)

SIGN

public double SIGN(double a)

SIGN

public int SIGN(int a)

pow

public double pow(double a,
                  double b)

sqrt

public double sqrt(double a)

sqrt

public double sqrt(int a)

exp

public double exp(double a)

exp

public double exp(int a)

log

public double log(double a)

qsort

public void qsort(double[] arr,
                  int dim)
Bubble sort array

Parameters:
arr - is a double array
dim - only first dim entries are sorted in array arr. So part of the array can be sorted.

qsort

public void qsort(int[] arr,
                  int dim)
Bubble sort array

Parameters:
arr - is an int array
dim - only first dim entries are sorted in array arr. So part of the array can be sorted.

qsort

public void qsort(Base.point[] arr,
                  int dim)
Bubble sort array of points (of class point),

Parameters:
arr - is a point array
dim - only first dim entries are sorted in array arr. So part of the array can be sorted.

d4d_d

public double d4d_d(double d)
Returns:
double with 4 decimal places (as in C "%.4f")

d4d

public String d4d(double d)
Returns:
double with 4 decimal places (as in C "%.4f")

d4

public String d4(double d)
Returns double as string 10.4: zzzzz.dddd.

Parameters:
d - double number
Returns:
String with 4 decimal places (as in C "%10.4f")

G

public double G(double z)
gamma(z) when 2z is a integer


phi

public double phi(double x)
p.d.f of Standard Normal


Phi

public double Phi(double x)
c.d.f of Standard Normal


chisq

public double chisq(int df,
                    double x)
p.d.f of Chi-square


Chisq

public double Chisq(int df,
                    double x)
c.d.f of Chi-square


Poisson

public double Poisson(double lambda,
                      int k)
p.d.f of Poisson distribution


chitest

public static double chitest(double[] data,
                             double expected)

stdev

public static double stdev(double[] data,
                           double avg)
Returns double Standard Deviation

Parameters:
data - array of doubles
avg - avg of data array

r2_double

public static double r2_double(double[] data)

Poisson_fit

public double[] Poisson_fit(double lambda,
                            int[] obs,
                            int no_obs)
computes the statistic of goodness of fit to a Poisson distribution

Returns:
vector of 3 doubles: (1) degree of freedom, (2) chi_fit (3) piValue used by Birthday Spacings Test from diehard

avg

public static double avg(double[] data)
Parameters:
data - input array of doubles
Returns:
avg of all enties in data array

printf

public void printf(String s)
printf on all output destinations registered into vector output destinations. Support multiple output destinations.


puts

public void puts(String s)
puts - use printf


showbit

public void showbit(int n)
show the bit-pattern of an integer 32 bits


addOutputDestination

public void addOutputDestination(OutputDestination od)
register output destination in vector of output destinations. printf and puts willwrite data to all destinations.

Parameters:
od - register this OutputDestination interface

removeOutputDestination

public void removeOutputDestination(OutputDestination od)
unregister output destination from vector of output destinations.

Parameters:
od - OutputDestination interface to be removed

registerInput

public void registerInput(RandomStream rs)
register RandomStream interface.

Supports only one random stream.

Parameters:
rs - register radom stream interface

isOpen

public boolean isOpen()
checks if input random stream is open.

random stream isOpen method is used to return boolean.

Returns:
true if input random stream is open, else false.

openInputStream

public boolean openInputStream()
open registered RandomStream.

Returns:
boolean as true for success, else false.

closeInputStream

public boolean closeInputStream()
open registered RandomStream.

Returns:
boolean as true for success, else false.

readByte

public byte readByte()
read one byte from registered input random stream.

Returns:
one byte, 8 bits

readInt

public int readInt()
read one byte from registered input random stream.

Returns:
a uniform random number, 32 bits

readLong

public long readLong()
read one long from registered input random stream.

Returns:
a uniform random long number, 64 bits

uni

public int uni()
Use readInt method.


read32BitsAsDouble

public double read32BitsAsDouble()
read one int from registered input random stream and divide it by (2^32 - 1).

Returns:
double number netween 0 and 1.

KStest

public double KStest(double[] x,
                     int dim)
KStest

This test is based on a modified Kolmogorov-Smirnov method.

The test-statistic is (FN(X)-X)**2/(X*(1-X)) (Anderson-Darling) where X is a uniform under null hypothesis. FN(X) is the empirical distribution of X.


AD

private double AD(double z)
c.d.f of Anderson-Darling statistic (a quick algorithm)

Used by KStest


help

public void help()
help method to be implemented by each test class.


test

public void test(String filename)
          throws Exception
test method to be implemented by each test class.

Parameters:
filename - is the filename to be read or the algorithm name.
Throws:
Exception

Java Randomness Test Suite

JRandTest at SourceForge

JRandTest at SourceForge
Copyright © 2005 Zur Aougav. All Rights Reserved.