Example usage for org.apache.commons.math3.distribution PoissonDistribution PoissonDistribution

List of usage examples for org.apache.commons.math3.distribution PoissonDistribution PoissonDistribution

Introduction

In this page you can find the example usage for org.apache.commons.math3.distribution PoissonDistribution PoissonDistribution.

Prototype

public PoissonDistribution(double p) throws NotStrictlyPositiveException 

Source Link

Document

Creates a new Poisson distribution with specified mean.

Usage

From source file:net.openhft.smoothie.MathDecisions.java

/**
 * Computes number of segments, from which probability of doubling (quadrupling, eight-ing)
 * segments array according to Poisson distribution laws exceeds {@link #THRESHOLD} assuming
 * perfectly uniform hash code distribution, for each rounded up average number of entries per
 * segment. In this case we are going to allocate doubled (quadrupled, eight-ed) segments array
 * up front, to avoid even little pause and garbaging previous segments array.
 *///w w w.  j  av  a 2 s  .com
private static void printSegmentsToScaleSegmentsArrayFrom(int min, int max, int refSize) {
    System.out.println("Segments to double (quadruple, eight) segments from:");
    for (int d = 1; d <= 4; d *= 2) {
        for (int i = min; i <= max; i++) {
            PoissonDistribution p = new PoissonDistribution(i / (1.0 * d));
            int cap = cap(i, refSize);
            System.out.printf("%d, ", (long) (THRESHOLD / (1.0 - p.cumulativeProbability(cap))));
        }
        System.out.println();
    }
}

From source file:jasima.core.random.discrete.IntPoisson.java

public IntPoisson(double mean) {
    super();
    setDistribution(new PoissonDistribution(mean));
}

From source file:jasima.core.random.discrete.IntPoisson.java

/**
 * The mean of the Poisson distribution.
 * /*from   ww w  . j a va 2s . co m*/
 * @param mean
 *            The value to use.
 * @throws NotPositiveException
 *             If {@code mean} was {@code <=0}.
 */
public void setMean(double mean) throws NotPositiveException {
    setDistribution(new PoissonDistribution(mean));
}

From source file:DecorateMutationsSNP.java

/**
 * The procedure computes for each edge of the ARG the number of mutations occurred in that period of time (length of the edge) by means of Poisson and Normal distributions
 * @param mu real value that is SNP mutation rate
 * @param arg instance of the class PopulationARG representing the ARG of a single population
 * @throws ErrorTimesInputFileException this exception is thrown if there is an inconsistency in time parameters setting
 * @see PopulationARG/*from  w  w  w  . j a v  a  2s . c  om*/
 */
public static void decoratingWithMutations(double mu, PopulationARG arg) throws ErrorTimesInputFileException {

    //For each leaf of arg create a set of mutations in the node
    for (int j = 0; j < arg.getExtantUnits(); j++) {
        arg.getNodeSet().get(j).setLeaf(true);
        arg.getNodeSet().get(j).setMutation_set(new TreeSet<Double>());
    }

    Iterator<Integer> it_edges = arg.getGraphEdges().keySet().iterator();
    double lamda = 0;

    //System.out.println("------- SNPs Decoration of Population "+arg.getId_pop()+" ------------ ");

    //For each edge in the ARG, compute the number of mutations and decorate the solids
    while (it_edges.hasNext()) {

        Integer keyE = it_edges.next();

        if (arg.getGraphEdges().get(keyE).getId_fath() != -1) {

            double density = arg.getGraphEdges().get(keyE).computeDensity();
            double time = arg.getGraphEdges().get(keyE).getTime();

            //*** if time is negative then throw the exception that 
            //there is probably an error in how the time parameters are specified in the input file ***//
            if (time <= 0) {
                throw new ErrorTimesInputFileException();
            }

            //System.out.println("Time: "+arg.getGraphEdges().get(keyE).getTime());
            double n = arg.getG() * density;
            double p = mu * arg.getN() * time;

            //******* Compute the # of mutations by Poisson Distribution ******
            lamda = n * p;

            PoissonDistribution Prand = new PoissonDistribution(lamda);
            int randomPois = Prand.sample();

            arg.getGraphEdges().get(keyE).setnMut(randomPois);

            if (randomPois == 0)
                GenerateAdmixturePopulations
                        .setNum_edges_without_mut(GenerateAdmixturePopulations.getNum_edges_without_mut() + 1);
            else
                GenerateAdmixturePopulations.setNum_edges_more_than_one_mut(
                        GenerateAdmixturePopulations.getNum_edges_more_than_one_mut() + 1);

            //For each mutation we assign a position
            for (int i = 0; i < arg.getGraphEdges().get(keyE).getnMut(); i++) {

                //maps the real solids in (0,1) in an interval (0,densityTotal)
                //by creating a new list of segments.

                double start = 0;

                ArrayList<Interval> tempSegs = new ArrayList<Interval>();

                for (int j = 0; j < arg.getGraphEdges().get(keyE).getSegments().size(); j++) {

                    double lengthInt = arg.getGraphEdges().get(keyE).getSegments().get(j).getEnd()
                            - arg.getGraphEdges().get(keyE).getSegments().get(j).getStart();
                    tempSegs.add(new Interval(start, start + lengthInt));
                    start = start + lengthInt;
                }

                double x = Math.random() * arg.getGraphEdges().get(keyE).getDensity();
                boolean found = false;
                int index = 0;

                while (!found && index < tempSegs.size()) {
                    if (x >= tempSegs.get(index).getStart() && x < tempSegs.get(index).getEnd()) {
                        found = true;
                    } else {
                        index++;
                    }
                }

                double offset = x - tempSegs.get(index).getStart();
                double posMutation = arg.getGraphEdges().get(keyE).getSegments().get(index).getStart() + offset;
                arg.getGraphEdges().get(keyE).getSegments().get(index).getPosMutations().add(posMutation);

                //add the mutation to the set of the all mutations
                GenerateAdmixturePopulations.getAllMutations().add(new Double(posMutation));

                //Create the mutation object
                Mutation mut = new Mutation();
                mut.setPositionID(posMutation);
                mut.setIDfather(arg.getGraphEdges().get(keyE).getId_fath());
                mut.setIDson(arg.getGraphEdges().get(keyE).getId_son());
                mut.setSegment(arg.getGraphEdges().get(keyE).getSegments().get(index));
                mut.setLeaves(computeLeaves(arg.getGraphEdges().get(keyE).getId_son(), arg));
                mut.setID_original_pop(arg.getId_pop());

                arg.getSNPpositionsList().add(posMutation);
                arg.getMutationSet().put(posMutation, mut);
                GenerateAdmixturePopulations.getAllmutationSet().put(mut.getPositionID(), mut);

                //For each leaf (in the set), that has the mutation mut, add mut to the leaf 
                TreeSet<Integer> leaves = mut.getLeaves();
                Iterator<Integer> it_leaves = leaves.iterator();

                while (it_leaves.hasNext()) {
                    int l = it_leaves.next();
                    arg.getNodeSet().get(l).getMutation_set().add(mut.getPositionID());
                }
            } //end of computing the exact position of each mutation 
        } //end if the edge has a father   

    } //end while for each edge of the ARG   
    //System.out.println("------- End of SNPs Decoration of Population "+arg.getId_pop()+" ------------ ");
}

From source file:mastodon.algorithms.MHLinearAlgorithm.java

protected void initialize() {
    if (minPrunedSpeciesCount == maxPrunedSpeciesCount) {
        stub = "MH Cons.";
    } else {/*from  ww  w  . ja  va 2  s. c  o  m*/
        stub = "MH Lin.";
    }

    pruningFreq = new HashMap<Integer, Integer>();
    for (int i = 0; i < bts.getTaxaCount(); i++) {
        pruningFreq.put(i, 0);
    }

    currPrunedSpeciesCount = minPrunedSpeciesCount;
    maxScorePruning = new HashMap<BitSet, double[]>();
    currPruning = new BitSet();

    for (int i = 0; i < currPrunedSpeciesCount; i++) {
        int choice = 0;
        do {
            choice = (int) (Random.nextDouble() * bts.getTaxaCount());
        } while (currPruning.get(choice));
        currPruning.set(choice);
    }
    prevPruning = (BitSet) currPruning.clone();

    prevScore = bts.pruneFast(currPruning);
    bts.unPrune();
    maxScore = prevScore.clone();
    maxScorePruning.put(prevPruning, maxScore);

    double mean = 1.0; //needed when pruning 1 taxon (can't have a mean of 0 in PoissonDistribution())
    if (currPrunedSpeciesCount > 1) {
        mean = 0.5 * (currPrunedSpeciesCount - 1);
    }
    pd = new PoissonDistribution(mean);

    setupIterations();

    iterationCounter = 0;
}

From source file:mastodon.algorithms.SALinearAlgorithm.java

protected void initialize() {
    if (minPrunedSpeciesCount == maxPrunedSpeciesCount) {
        stub = "SA Cons.";
    } else {//w  ww  .ja v a 2 s  .c  om
        stub = "SA Lin.";
    }

    pruningFreq = new HashMap<Integer, Integer>();
    for (int i = 0; i < bts.getTaxaCount(); i++) {
        pruningFreq.put(i, 0);
    }

    currTemp = initTemp;

    currPrunedSpeciesCount = minPrunedSpeciesCount;
    maxScorePruning = new HashMap<BitSet, double[]>();
    currPruning = new BitSet();

    for (int i = 0; i < currPrunedSpeciesCount; i++) {
        int choice = 0;
        do {
            choice = (int) (Random.nextDouble() * bts.getTaxaCount());
        } while (currPruning.get(choice));
        currPruning.set(choice);
    }
    prevPruning = (BitSet) currPruning.clone();

    prevScore = bts.pruneFast(currPruning);
    bts.unPrune();
    maxScore = prevScore.clone();
    maxScorePruning.put(prevPruning, maxScore);

    double mean = 1.0; //needed when pruning 1 taxon (can't have a mean of 0 in PoissonDistribution())
    if (currPrunedSpeciesCount > 1) {
        mean = 0.5 * (currPrunedSpeciesCount - 1);
    }
    pd = new PoissonDistribution(mean);

    setupIterations();
    coolingRate = Math.pow(finalTemp / initTemp, 1.0 / stepIterations[currPrunedSpeciesCount - 1]);

    iterationCounter = 0;
}

From source file:me.datamining.cluster.STING.java

/**
 * //w  w  w .  j a  va  2s .  c  o  m
 * @param value
 * @param lambda
 * @return
 */
public static double pissonPDF(double value, double lambda) {
    if (lambda == 0) {
        return 0;
    }
    PoissonDistribution pdf = new PoissonDistribution(lambda);
    //TODO: fix needs to take in double
    return pdf.probability((int) value);
}

From source file:com.ibm.og.util.Distributions.java

/**
 * Creates a poisson distribution.//from   w ww. j a  v a 2  s  .  c o  m
 * 
 * @param average the average value generated by this distribution
 * @return a poisson distribution instance
 * @throws IllegalArgumentException if average is negative
 */
public static Distribution poisson(final double average) {
    checkArgument(average >= 0.0, "average must be >= 0.0 [%s]", average);
    final String s = String.format("PoissonDistribution [average=%s]", average);
    return new IntegerDistributionAdapter(new PoissonDistribution(average), s);
}

From source file:mastodon.algorithms.MHBisectionAlgorithm.java

protected void choosePruningCount() {
    if (iterationCounter % stepIterations == 0) {
        System.out.println(currPrunedSpeciesCount);
        System.out.println(maxScore[0] + " " + maxScore[1]);

        if (iterationCounter > 0) {
            if (maxScore[0] < minMapScore) {
                kLeft = currPrunedSpeciesCount;
            } else {
                kRight = currPrunedSpeciesCount;
            }//from www  . ja  v a  2  s .c o  m
            currPrunedSpeciesCount = (int) ((kRight + kLeft) / 2);
        }

        maxScore = new double[2];
        maxScorePruning = new HashMap<BitSet, double[]>();
        currPruning = new BitSet();

        for (int i = 0; i < currPrunedSpeciesCount; i++) {
            int choice = 0;
            do {
                choice = (int) (Random.nextDouble() * bts.getTaxaCount());
            } while (currPruning.get(choice));
            currPruning.set(choice);
        }
        prevPruning = (BitSet) currPruning.clone();
        prevScore = bts.pruneFast(currPruning);
        bts.unPrune();

        maxScorePruning.put(prevPruning, prevScore);

        double mean = 1.0; //needed when pruning 1 taxon (can't have a mean of 0 in PoissonDistribution())
        if (currPrunedSpeciesCount > 1) {
            mean = 0.5 * (currPrunedSpeciesCount - 1);
        }
        pd = new PoissonDistribution(mean);
    }
}

From source file:mastodon.algorithms.MHLinearAlgorithm.java

protected void choosePruningCount() {
    int position = 0;
    for (int i = 0; i < stepIterations.length; i++) {
        position += stepIterations[i];//from   w ww  .  j a v  a  2s .  c  o  m
        if (iterationCounter < position) {
            if (i + 1 != currPrunedSpeciesCount) {
                currPrunedSpeciesCount = i + 1;
                double mean = 1.0; //needed when pruning 1 taxon (can't have a mean of 0 in PoissonDistribution())
                if (currPrunedSpeciesCount > 1) {
                    mean = 0.5 * (currPrunedSpeciesCount - 1);
                }
                pd = new PoissonDistribution(mean);
            }
            break;
        }
    }
}