Example usage for org.apache.commons.math.util FastMath exp

List of usage examples for org.apache.commons.math.util FastMath exp

Introduction

In this page you can find the example usage for org.apache.commons.math.util FastMath exp.

Prototype

public static double exp(double x) 

Source Link

Document

Exponential function.

Usage

From source file:cz.paulrz.montecarlo.single.ExpOrnsteinUhlenbeckProcess.java

/**
 * Constructor of the process/*from   ww  w  .java 2  s.c o  m*/
 * 
 * @param x0 Starting point
 * @param theta Theta parameter
 * @param mu Mu parameter
 * @param sigma Sigma parameter
 */
public ExpOrnsteinUhlenbeckProcess(double x0, double theta, double mu, double sigma) {
    super(x0, new EulerDiscretization());
    this.theta = theta;
    this.mu = mu;
    expMu = FastMath.exp(mu);
    this.sigma = sigma;
    halfsigmasquare = 0.5 * sigma * sigma;
}

From source file:com.polytech4A.cuttingstock.core.solver.SimulatedAnnealing.java

/**
 * Simulate Annealing Algorithm./*from w  w  w  .  j  av  a 2  s . c  o m*/
 *
 * @param solution First Solution of the Algorithm, it's also best solution for beginning.
 * @return bestsolution Found.
 */
public Solution simulateAnnealing(Solution solution) {
    Solution bestSolution = solution;
    Result bestCost = simplex.minimize(solution);
    Solution randomSolution;
    Result randomSolutionCost;
    Solution currentSolution = solution;
    Result currentCost = bestCost.clone();
    int step = (int) nbIterations / 100;
    int progress = 10;
    logger.info("First Cost = " + bestCost);
    double deltaF;
    for (int j = 0; j < 100; j++) {
        for (int i = 0; i < step; i++) {
            randomSolution = generateBetterNeighbour(currentSolution);
            randomSolutionCost = randomSolution.getCost();
            deltaF = currentCost.getCost() - randomSolutionCost.getCost();
            if (deltaF >= 0) {
                currentSolution = randomSolution;
                currentCost = randomSolutionCost;
                if (currentCost.getCost() < bestCost.getCost()) {
                    bestSolution = currentSolution;
                    bestCost = currentCost;
                }
            } else {
                Random random = new Random(System.currentTimeMillis());
                double p = random.nextDouble();
                double exp = FastMath.exp((-deltaF) / temperature);
                if (p <= exp) {
                    currentSolution = randomSolution;
                    currentCost = randomSolutionCost;
                }
            }
        }
        temperature *= mu;
        if (j % progress == 0) {
            int pourcent = j / progress;
            pourcent *= 10;
            StringBuffer stbf = new StringBuffer();
            stbf.append("CSV;").append(temperature).append(";temperature;").append(bestCost.getCost())
                    .append(";bestcost;").append(pourcent).append("%...");
            logger.info(stbf.toString());
        }
    }
    logger.info("Best Cost :" + bestCost);
    return bestSolution;
}

From source file:org.onebusaway.nyc.vehicle_tracking.impl.inference.CategoricalDist.java

private void initializeDistribution() {
    final double[] entriesToProbs = _entriesToLogProbs.values();
    double[] probVector = new double[entriesToProbs.length];
    for (int i = 0; i < probVector.length; ++i) {
        probVector[i] = FastMath.exp(entriesToProbs[i] - _logCumulativeProb);
    }//from ww  w  .  j  ava  2  s.  com
    _entries = _entriesToLogProbs.keys();
    for (int i = 0; i < _entries.length; ++i) {
        _objIdx.add(i);
    }
    if (_sort) {
        probVector = handleSort(probVector);
    }
    _emd = new MultinomialDistribution(VectorFactory.getDefault().copyArray(probVector), 1);
}

From source file:org.onebusaway.nyc.vehicle_tracking.impl.inference.CategoricalDist.java

public double getCummulativeProb() {
    return FastMath.exp(_logCumulativeProb);
}

From source file:org.onebusaway.nyc.vehicle_tracking.impl.inference.CategoricalDist.java

public double density(T thisState) {
    return FastMath.exp(_entriesToLogProbs.get(thisState));
}

From source file:org.onebusaway.nyc.vehicle_tracking.impl.particlefilter.Particle.java

public double getWeight() {
    return FastMath.exp(_logWeight);
}

From source file:org.onebusaway.nyc.vehicle_tracking.impl.particlefilter.ParticleFilter.java

/**
 * Finds the most likely/occurring trip & phase combination among the
 * particles, then chooses the particle with highest likelihood of that pair. <br>
 * //from ww w .  ja va2s .c om
 * FIXME violates generic particle contract by assuming data is of type
 * VehicleState
 * 
 * @param particles
 */
private void computeBestState(Multiset<Particle> particles) {
    /**
     * We choose the "most likely" particle over the entire distribution w.r.t
     * the inferred trip.
     */
    final TObjectDoubleMap<String> tripPhaseToProb = new TObjectDoubleHashMap<String>();

    final HashMultimap<String, Particle> particlesIdMap = HashMultimap.create();
    final SortedSet<Particle> bestParticles = new TreeSet<Particle>();
    String bestId = null;

    if (!_maxLikelihoodParticle) {
        double highestTripProb = Double.MIN_VALUE;
        int index = 0;
        for (final Multiset.Entry<Particle> pEntry : particles.entrySet()) {
            final Particle p = pEntry.getElement();
            p.setIndex(index++);

            final double w = FastMath.exp(p.getLogWeight() + FastMath.log(pEntry.getCount()));

            if (Double.isInfinite(w))
                continue;

            final VehicleState vs = p.getData();
            final String tripId = vs.getBlockState() == null ? "NA"
                    : vs.getBlockState().getBlockLocation().getActiveTrip().getTrip().toString();
            final String phase = vs.getJourneyState().toString();
            final String id = tripId + "." + phase;

            final double newProb = tripPhaseToProb.adjustOrPutValue(id, w, w);

            particlesIdMap.put(id, p);

            /**
             * Check most likely new trip & phase pairs, then find the most likely
             * particle(s) within those.
             */
            if (bestId == null || newProb > highestTripProb) {
                bestId = id;
                highestTripProb = newProb;
            }
        }
        bestParticles.addAll(particlesIdMap.get(bestId));
    } else {
        bestParticles.addAll(particles);
    }

    /**
     * after we've found the best trip & phase pair, we choose the highest
     * likelihood particle among those.
     */
    final Particle bestParticle = bestParticles.first();

    _mostLikelyParticle = bestParticle.cloneParticle();

}

From source file:org.onebusaway.nyc.vehicle_tracking.impl.particlefilter.SensorModelResult.java

/**
 * Returns, and lazily computes, the non-log probability. <br>
 * XXX Note that this "compute-on-demand" approach is not thread-safe.
 * /*w  w  w  .  ja  v a  2s . c o m*/
 * @return non-log probability
 */
public double getProbability() {
    if (this.refresh) {
        this.probability = FastMath.exp(logProbability);
        this.refresh = false;
    }
    return this.probability;
}