Example usage for java.lang Math log

List of usage examples for java.lang Math log

Introduction

In this page you can find the example usage for java.lang Math log.

Prototype

@HotSpotIntrinsicCandidate
public static double log(double a) 

Source Link

Document

Returns the natural logarithm (base e) of a double value.

Usage

From source file:com.itemanalysis.psychometrics.rasch.RatingScaleItem.java

/**
 * PROX estimate of item difficulty. This is called to produce a starting rho for the
 * JMLE routine.//from   www  . j av a  2  s.c om
 *
 * @param maxItemScore
 * @param adjustedItemScore
 */
public void prox(double maxItemScore, double adjustedItemScore) {
    if (!fixedParameter) {
        double p = adjustedItemScore / maxItemScore;
        double q = 1.0 - p;
        difficulty = Math.log(q / p);
        proposalDifficulty = difficulty;
    }

}

From source file:electrical_parameters.Basic.java

/**
 * create Ln_real and Ln_imag matrices//ww w.j  a  va 2 s  .com
 */
public void calcLn() {
    //init matrix
    this.Ln = initMatrix(this.Dik);
    for (int i = 0; i < this.rows; i++) {
        for (int j = 0; j < this.cols; j++) {
            if (i == j) {
                this.Ln.setEntry(i, j, Math.log(this.Dg / this.GMR[i]));
            } else {
                this.Ln.setEntry(i, j, Math.log(this.Dg / this.Dik.getEntry(i, j)));
            }
        }
    }
}

From source file:de.tudarmstadt.ukp.dkpro.wsd.linkbased.algorithm.WikipediaRelatednessMethod.java

private Double computeWikipediaLinkMeasure(String candidate) {
    logger.info("Computing score for " + candidate);

    double relatedness = 0;
    //start with -1 because a sense own value will be zero
    int counter = -1;
    int maxIncomingLinks;
    int minIncomingLinks;
    int numberOfSenses = ((LinkDatabaseInventoryResource) inventory).getNumberOfSenses();
    for (String otherCandidate : possibleCandidates) {
        maxIncomingLinks = Math.max(incomingLinksList.get(candidate).size(),
                incomingLinksList.get(otherCandidate).size());
        minIncomingLinks = Math.min(incomingLinksList.get(candidate).size(),
                incomingLinksList.get(otherCandidate).size());
        counter++;/*from w ww . ja  v  a2  s. c  o m*/
        relatedness += (Math.log(maxIncomingLinks)
                - Math.log(countIncomingSharedLinks(candidate, otherCandidate)))
                / (Math.log(numberOfSenses) - Math.log(minIncomingLinks));
    }

    //Formula by Milne & Witten
    //      relatedness (a, b ) =
    //         log(max ( A , B ))  log( A  B )
    //         log( W )  log(min( A , B ))

    return relatedness / counter;
}

From source file:eu.amidst.core.exponentialfamily.EF_InverseGamma.java

/**
 * {@inheritDoc}//from  w  ww  . j  a v a 2 s .co m
 */
@Override
public void updateNaturalFromMomentParameters() {
    double m0 = this.getMomentParameters().get(0);
    double m1 = this.getMomentParameters().get(1);
    // Coordinate ascent until convergence
    double newalpha = 2.0, alpha = 0.0;
    double newbeta = 2.0, beta = 0.0;
    while (Math.abs(newalpha - alpha) > DELTA || Math.abs(newbeta - beta) > DELTA) {
        alpha = newalpha;
        beta = newbeta;
        newalpha = Utils.invDigamma(Math.log(beta) - m0);
        newbeta = newalpha / m1;
    }
    this.naturalParameters.set(0, newalpha);
    this.naturalParameters.set(1, newbeta);
}

From source file:gda.device.detector.countertimer.TfgScalerWithLogValues.java

protected double[] appendLogValues(double[] output) {
    Double[] logs = new Double[2];
    // find which col is which I0, It and Iref
    Double[] values = getI0ItIRef(output);

    // NOTE Assumes that the order of the data (time, I0, It, Iref...)
    // for dark current does not change.
    logs[0] = Math.log(values[0] / values[1]);
    logs[1] = Math.log(values[1] / values[2]);

    // always return a numerical value
    if (logs[0].isInfinite() || logs[0].isNaN()) {
        logs[0] = 0.0;// w  w w .j  a  v  a 2s .c om
    }
    if (logs[1].isInfinite() || logs[1].isNaN()) {
        logs[1] = 0.0;
    }

    // append to output array
    output = correctCounts(output, values);
    output = ArrayUtils.add(output, logs[0]);
    output = ArrayUtils.add(output, logs[1]);
    return output;
}

From source file:fingerprints.helper.BloomFilter.java

/**
 * You must specify the number of bits in the Bloom Filter, and also you should specify the number of items you
 * expect to add./*from   w w w .  jav  a  2  s .com*/
 *
 * The latter is used to choose some optimal internal values to minimize the false-positive rate (which can be
 * estimated with expectedFalsePositiveRate()).
 *
 * @param bisetSize The number of bits in the bit array (often called 'm' in the context of bloom filters).
 * @param expectedPatterns The typical number of items you expect to be added to the SimpleBloomFilter (often called
 * 'n').
 */
public BloomFilter(int bisetSize, int expectedPatterns) {
    this.bitSetSize = bisetSize;
    this.expectedPatterns = expectedPatterns;
    // k = ceil(-log_2(false prob.))
    double falsePositiveProbability = (bisetSize / expectedPatterns);
    this.k = (int) Math.ceil((falsePositiveProbability) * Math.log(2.0));
    bitSet = new BitSet(bisetSize);
}

From source file:io.druid.query.aggregation.HyperloglogAggregatorFactory.java

@Override
public Object finalizeComputation(Object object) {
    final TIntByteHashMap ibMap = (TIntByteHashMap) object;
    final int[] keys = ibMap.keys();
    final int count = keys.length;

    double registerSum = 0;
    double zeros = 0.0;

    for (int key : keys) {
        int val = ibMap.get(key);

        registerSum += 1.0 / (1 << val);

        if (val == 0) {
            zeros++;//from   w w  w. j  av a 2  s .  c  o m
        }
    }

    registerSum += (HyperloglogAggregator.m - count);
    zeros += HyperloglogAggregator.m - count;

    double estimate = HyperloglogAggregator.alphaMM * (1.0 / registerSum);

    if (estimate <= (5.0 / 2.0) * (HyperloglogAggregator.m)) {
        // Small Range Estimate
        return Math.round(HyperloglogAggregator.m * Math.log(HyperloglogAggregator.m / zeros));
    } else {
        return Math.round(estimate);
    }
}

From source file:hu.ppke.itk.nlpg.purepos.cli.PurePos.java

public static void tag(String encoding, String modelPath, String inputPath, String analyzer, boolean noStemming,
        int maxGuessed, int maxresnum, int beamTheta, boolean useBeamSearch, String outPath) throws Exception {
    Scanner input = createScanner(encoding, inputPath, analyzer.equals(PRE_MA));
    ///*from  w w w. j  a v a  2s.c  o  m*/
    //      Configuration conf;
    //      if (configFile != null) {
    //         ConfigurationReader reader = new ConfigurationReader();
    //         conf = reader.read(new File(configFile));
    //         Util.LEMMA_MAPPER = new StringMapper(conf.getLemmaMappings());
    //      } else {
    //         conf = new Configuration(new LinkedList<StringMapping>(), new LinkedList<StringMapping>());
    //      }

    ITagger t = createTagger(modelPath, analyzer, noStemming, maxGuessed, Math.log(beamTheta), useBeamSearch,
            Util.CONFIGURATION);

    PrintStream output;
    if (outPath == null) {
        output = new PrintStream(System.out, true, encoding);
    } else {
        output = new PrintStream(new File(outPath), encoding);
    }
    System.err.println("Tagging:");
    t.tag(input, output, maxresnum);
}

From source file:gov.nih.nci.calims2.business.inventory.container.CoordinateHelper.java

private static int getMaximumLength(LayoutLabelType labelType, int maximum) {
    if (labelType == LayoutLabelType.DIGITS) {
        int length = (int) Math.floor(Math.log(maximum) / Math.log(DIGIT_BASE)) + 1;
        return (length > 1) ? length : 2;
    }/*from  w  w  w  .  j a  va 2 s .com*/
    return (int) Math.floor(Math.log(maximum) / Math.log(LETTER_BASE)) + 1;
}

From source file:be.ugent.maf.cellmissy.analysis.doseresponse.impl.SigmoidFitterImpl.java

@Override
public void fitNoConstrain(List<DoseResponsePair> dataToFit, SigmoidFittingResultsHolder resultsHolder,
        int standardHillslope) {
    //initial parameter values for fitting: lowest y, highest y, middle x and standard hillslope
    double[] yValues = AnalysisUtils.generateYValues(dataToFit);
    double[] xValues = AnalysisUtils.generateXValues(dataToFit);

    double initialTop = yValues[0];
    double initialBottom = yValues[0];
    double initialLogEC50;
    double maxX = xValues[0];
    double minX = xValues[0];
    for (int i = 0; i < yValues.length; i++) {
        if (yValues[i] < initialBottom) {
            initialBottom = yValues[i];/*w w w .j av  a  2 s . c  o  m*/
        } else if (yValues[i] > initialTop) {
            initialTop = yValues[i];
        }
        if (xValues[i] < minX) {
            minX = xValues[i];
        } else if (xValues[i] > maxX) {
            maxX = xValues[i];
        }
    }
    initialLogEC50 = (maxX + minX) / 2;
    final double[] initialGuesses = new double[] { initialBottom, initialTop, initialLogEC50,
            standardHillslope };

    //add all datapoint to collection with standard weight 1.0
    Collection<WeightedObservedPoint> observations = new ArrayList<>();
    for (int i = 0; i < xValues.length; i++) {
        observations.add(new WeightedObservedPoint(1.0, xValues[i], yValues[i]));
    }

    final ParametricUnivariateFunction function = new ParametricUnivariateFunction() {
        /**
         * @param conc The concentration of the drug, log transformed
         * @param paramaters The fitted parameters (bottom, top, logEC50 and
         * hillslope)
         * @return The velocity
         */
        @Override
        public double value(double conc, double[] parameters) {
            double bottom = parameters[0];
            double top = parameters[1];
            double logEC50 = parameters[2];
            double hillslope = parameters[3];

            return (bottom + (top - bottom) / (1 + Math.pow(10, (logEC50 - conc) * hillslope)));
        }

        @Override
        public double[] gradient(double conc, double[] parameters) {
            double bottom = parameters[0];
            double top = parameters[1];
            double logEC50 = parameters[2];
            double hillslope = parameters[3];

            return new double[] { 1 - (1 / ((Math.pow(10, (logEC50 - conc) * hillslope)) + 1)),
                    1 / ((Math.pow(10, (logEC50 - conc) * hillslope)) + 1),
                    (hillslope * Math.log(10) * Math.pow(10, hillslope * (logEC50 + conc)) * (bottom - top))
                            / (Math.pow(Math.pow(10, hillslope * conc) + Math.pow(10, hillslope * logEC50), 2)),
                    (Math.log(10) * (logEC50 - conc) * (bottom - top)
                            * Math.pow(10, (logEC50 + conc) * hillslope))
                            / Math.pow((Math.pow(10, logEC50 * hillslope) + Math.pow(10, hillslope * conc)), 2)

            };

        }

    };

    //set up the fitter with the observations and function created above
    DoseResponseAbstractCurveFitter fitter = new DoseResponseAbstractCurveFitter() {

        @Override
        protected LeastSquaresProblem getProblem(Collection<WeightedObservedPoint> observations) {
            // Prepare least-squares problem.
            final int len = observations.size();
            final double[] target = new double[len];
            final double[] weights = new double[len];

            int i = 0;
            for (final WeightedObservedPoint obs : observations) {
                target[i] = obs.getY();
                weights[i] = obs.getWeight();
                ++i;
            }

            final AbstractCurveFitter.TheoreticalValuesFunction model = new AbstractCurveFitter.TheoreticalValuesFunction(
                    function, observations);

            // build a new least squares problem set up to fit a secular and harmonic curve to the observed points
            return new LeastSquaresBuilder().maxEvaluations(Integer.MAX_VALUE).maxIterations(Integer.MAX_VALUE)
                    .start(initialGuesses).target(target).weight(new DiagonalMatrix(weights))
                    .model(model.getModelFunction(), model.getModelFunctionJacobian()).build();
        }
    };

    OptimumImpl bestFit = fitter.performRegression(observations);
    //get the best-fit parameters
    double[] params = bestFit.getPoint().toArray();
    double bottom = params[0];
    double top = params[1];
    double logEC50 = params[2];
    double hillslope = params[3];

    //set the fields of the fitting results holder
    resultsHolder.setBottom(bottom);
    resultsHolder.setTop(top);
    resultsHolder.setLogEC50(logEC50);
    resultsHolder.setHillslope(hillslope);
    //no parameters were constrained
    resultsHolder.setConstrainedParameters(new ArrayList<String>());
    //TEST: what is the effect of the singularity threshold argument?
    resultsHolder.setCovariances(bestFit.getCovariances(0).getData());
}