List of usage examples for java.lang Math log1p
public static double log1p(double x)
From source file:Main.java
public static void main(String[] args) { double x = 123456.7; double y = -123.45; // call log1p and print the result System.out.println("Math.log1p(" + x + ")=" + Math.log1p(x)); // call log1p and print the result System.out.println("Math.log1p(" + y + ")=" + Math.log1p(y)); }
From source file:bide.prior.PriorBeta.java
public static double logPdf(double x, double alpha, double beta) { double z = recomputeZ(alpha, beta); double logX = Math.log(x); double log1mX = Math.log1p(-x); return ((alpha - 1) * logX + (beta - 1) * log1mX - z); }
From source file:bide.prior.PriorBeta.java
public static double pdf(double x, double alpha, double beta) { double z = recomputeZ(alpha, beta); double logX = Math.log(x); double log1mX = Math.log1p(-x); return Math.exp((alpha - 1) * logX + (beta - 1) * log1mX - z); }
From source file:edu.umd.umiacs.clip.tools.scor.BM25Scorer.java
protected final float idf(float df) { return (float) Math.log1p((N - df + 0.5) / (df + 0.5)); }
From source file:beast.math.distributions.BetaDistribution.java
/** * probability density function of the distribution * * @param x argument//from w w w.j a v a 2 s.co m * @return pdf value */ public double pdf(double x) { recomputeZ(); if (x < 0 || x > 1) { return 0; } else if (x == 0) { if (alpha < 1) { // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime // exceptions is bad. Better to return NaN and let the calling code deal with it. return Double.NaN; // throw MathRuntimeException.createIllegalArgumentException( // "Cannot compute beta density at 0 when alpha = {0,number}", alpha); } return 0; } else if (x == 1) { if (beta < 1) { // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime // exceptions is bad. Better to return NaN and let the calling code deal with it. return Double.NaN; // throw MathRuntimeException.createIllegalArgumentException( // "Cannot compute beta density at 1 when beta = %.3g", beta); } return 0; } else { double logX = Math.log(x); double log1mX = Math.log1p(-x); return Math.exp((alpha - 1) * logX + (beta - 1) * log1mX - z); } }
From source file:beast.math.distributions.BetaDistribution.java
/** * the natural log of the probability density function of the distribution * * @param x argument/* www . j a v a2s .c om*/ * @return log pdf value */ public double logPdf(double x) { recomputeZ(); if (x < 0 || x > 1) { return 0; } else if (x == 0) { if (alpha < 1) { // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime // exceptions is bad. Better to return NaN and let the calling code deal with it. return Double.NaN; // throw MathRuntimeException.createIllegalArgumentException( // "Cannot compute beta density at 0 when alpha = {0,number}", alpha); } return 0; } else if (x == 1) { if (beta < 1) { // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime // exceptions is bad. Better to return NaN and let the calling code deal with it. return Double.NaN; // throw MathRuntimeException.createIllegalArgumentException( // "Cannot compute beta density at 1 when beta = %.3g", beta); } return 0; } else { double logX = Math.log(x); double log1mX = Math.log1p(-x); return (alpha - 1) * logX + (beta - 1) * log1mX - z; } }
From source file:dr.math.distributions.BetaDistribution.java
/** * the natural log of the probability density function of the distribution * * @param x argument// ww w . j av a 2 s. com * @return log pdf value */ public double logPdf(double x) { recomputeZ(); if (x < 0 || x > 1) { return Double.NEGATIVE_INFINITY; } else if (x == 0) { if (alpha < 1) { // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime // exceptions is bad. Better to return NaN and let the calling code deal with it. return Double.NaN; // throw MathRuntimeException.createIllegalArgumentException( // "Cannot compute beta density at 0 when alpha = {0,number}", alpha); } if (alpha == 1) { return 0; } return Double.NEGATIVE_INFINITY; } else if (x == 1) { if (beta < 1) { // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime // exceptions is bad. Better to return NaN and let the calling code deal with it. return Double.NaN; // throw MathRuntimeException.createIllegalArgumentException( // "Cannot compute beta density at 1 when beta = %.3g", beta); } if (beta == 1) { return 0; } return Double.NEGATIVE_INFINITY; } else { double logX = Math.log(x); double log1mX = Math.log1p(-x); return (alpha - 1) * logX + (beta - 1) * log1mX - z; } }
From source file:edu.cornell.med.icb.goby.modes.TallyBasesMode.java
/** * Run the tally bases mode.//from w w w . ja v a 2 s . c o m * * @throws java.io.IOException error reading / writing */ @Override public void execute() throws IOException { if (basenames.length != 2) { System.err.println("Exactly two basenames are supported at this time."); System.exit(1); } final CountsArchiveReader[] archives = new CountsArchiveReader[basenames.length]; int i = 0; for (final String basename : basenames) { archives[i++] = new CountsArchiveReader(basename, alternativeCountArhive); } final CountsArchiveReader archiveA = archives[0]; final CountsArchiveReader archiveB = archives[1]; // keep only common reference sequences between the two input count archives. final ObjectSet<String> identifiers = new ObjectOpenHashSet<String>(); identifiers.addAll(archiveA.getIdentifiers()); identifiers.retainAll(archiveB.getIdentifiers()); // find the optimal offset A vs B: final int offset = offsetString.equals("auto") ? optimizeOffset(archiveA, archiveB, identifiers) : Integer.parseInt(offsetString); System.out.println("offset: " + offset); final RandomAccessSequenceCache cache = new RandomAccessSequenceCache(); if (cache.canLoad(genomeCacheFilename)) { try { cache.load(genomeCacheFilename); } catch (ClassNotFoundException e) { System.err.println("Cannot load cache from disk. Consider deleting the cache and rebuilding."); e.printStackTrace(); System.exit(1); } } else { Reader reader = null; try { if (genomeFilename.endsWith(".fa") || genomeFilename.endsWith(".fasta")) { reader = new FileReader(genomeFilename); cache.loadFasta(reader); } else if (genomeFilename.endsWith(".fa.gz") || genomeFilename.endsWith(".fasta.gz")) { reader = new InputStreamReader(new GZIPInputStream(new FileInputStream(genomeFilename))); cache.loadFasta(reader); } else { System.err.println("The format of the input file is not supported at this time."); System.exit(1); } } finally { IOUtils.closeQuietly(reader); } } System.out.println("Will use genome cache basename: " + genomeCacheFilename); cache.save(genomeCacheFilename); final Random random = new Random(new Date().getTime()); final double delta = cutoff; final int countThreshold = 30; final PrintStream output = new PrintStream(outputFilename); writeHeader(output, windowSize); for (final String referenceSequenceId : identifiers) { if (isReferenceIncluded(referenceSequenceId)) { final int referenceIndex = cache.getReferenceIndex(referenceSequenceId); if (referenceIndex != -1) { // sequence in cache. System.out.println("Processing sequence " + referenceSequenceId); final double sumA = getSumOfCounts(archiveA.getCountReader(referenceSequenceId)); final double sumB = getSumOfCounts(archiveB.getCountReader(referenceSequenceId)); final int referenceSize = cache.getSequenceSize(referenceIndex); // process this sequence: final AnyTransitionCountsIterator iterator = new AnyTransitionCountsIterator( archiveA.getCountReader(referenceSequenceId), new OffsetCountsReader(archiveB.getCountReader(referenceSequenceId), offset)); while (iterator.hasNextTransition()) { iterator.nextTransition(); final int position = iterator.getPosition(); final int countA = iterator.getCount(0); final int countB = iterator.getCount(1); if (countA + countB >= countThreshold) { final double foldChange = Math.log1p(countA) - Math.log1p(countB) - Math.log(sumA) + Math.log(sumB); if (foldChange >= delta || foldChange <= -delta) { if (random.nextDouble() < sampleRate) { tallyPosition(cache, referenceIndex, position, foldChange, windowSize, referenceSize, referenceSequenceId, output, countA, countB, sumA, sumB); } } } } iterator.close(); } } output.flush(); } output.close(); }
From source file:de.tudarmstadt.lt.ltbot.prefetch.DecesiveValuePrioritizer.java
int getPrecedenceCost(double val, int schedulingConstants_priority) { // cost should be in [0,_maxPrecedence], lower values are better, try to squash values into this range int cost = _maxPrecedence; switch (schedulingConstants_priority) { case SchedulingConstants.HIGHEST: return 1; // 2^0 case SchedulingConstants.HIGH: return 4; // 2^2 case SchedulingConstants.MEDIUM: return 8; // 2^3 case SchedulingConstants.NORMAL: cost = 64; // 2^6 }/*from w w w . j a va 2 s. c o m*/ // --> squeeze [_assignmentBoundaries[SchedulingConstants.NORMAL], _maxvalue] into [64, _maxPrecedence] // [A, B] --> [a, b] // newval = (val - A)*(b-a)/(B-A) + a double B = Math.min(Integer.MAX_VALUE, _maxvalue); // use maxvalue as maximum if specified and below Integer.maxvalue if (val >= B) return _maxPrecedence; // take log of A, B and val to make computation numerically more stable B = Math.log1p(B); double A = Math.log1p(_assignmentBoundaries[SchedulingConstants.MEDIUM]); val = Math.log1p(val); // assert val >= A : "Value is smaller than lower boundary. That should not happen."; double a = cost; double b = _maxPrecedence; cost = (int) Math.ceil((val - A) * (b - a) / (B - A) + a); return cost; }
From source file:com.jaeksoft.searchlib.learning.StandardLearner.java
@Override public void classify(String data, FieldMap sourceFieldMap, int maxRank, double minScore, Collection<LearnerResultItem> collector) throws IOException, SearchLibException { rwl.r.lock();/*from www . java2 s. co m*/ try { Collection<TargetField> targetFields = checkIndex(sourceFieldMap); TreeMap<String, LearnerResultItem> targetMap = new TreeMap<String, LearnerResultItem>(); fieldClassify(FIELD_SOURCE_DATA, null, data, targetMap); for (TargetField targetField : targetFields) fieldClassify(targetField.getBoostedName(), targetField.getBoost(), data, targetMap); for (LearnerResultItem learnerResultItem : targetMap.values()) { learnerResultItem.score = learnerResultItem.score / learnerResultItem.count * Math.log1p(learnerResultItem.count); if (learnerResultItem.score > minScore) collector.add(learnerResultItem); } } finally { rwl.r.unlock(); } }