use of java.util.function.DoubleUnaryOperator in project j2objc by google.
the class DoubleUnaryOperatorTest method testCompose.
public void testCompose() throws Exception {
DoubleUnaryOperator plusOne = x -> x + 1.0d;
DoubleUnaryOperator twice = x -> 2 * x;
assertEquals(11.0d, plusOne.compose(twice).applyAsDouble(5.0d));
}
use of java.util.function.DoubleUnaryOperator in project gatk-protected by broadinstitute.
the class TestHMM method fromPhredProbabilities.
static TestHMM fromPhredProbabilities(final double... phred) {
final double[] priors = Arrays.copyOfRange(phred, 0, State.values().length);
final double[][] transition = reshape(Arrays.copyOfRange(phred, State.values().length, State.values().length * (State.values().length + 1)), State.values().length);
final double[][] emission = reshape(Arrays.copyOfRange(phred, (State.values().length + 1) * State.values().length, phred.length), State.values().length);
final DoubleUnaryOperator phredToLog = d -> d * -.1 * LN_OF_10;
final double[] logPriorsRaw = DoubleStream.of(priors).map(phredToLog).toArray();
final double logPriorsSum = GATKProtectedMathUtils.logSumExp(logPriorsRaw);
final double[] logPriors = DoubleStream.of(logPriorsRaw).map(d -> d - logPriorsSum).toArray();
final double[][] logEmissionProbs = Stream.of(emission).map(x -> {
final double[] result = DoubleStream.of(x).map(phredToLog).toArray();
final double sum = GATKProtectedMathUtils.logSumExp(result);
return DoubleStream.of(result).map(d -> d - sum).toArray();
}).toArray(double[][]::new);
final double[][] logTransitionProbs = Stream.of(transition).map(x -> {
final double[] result = DoubleStream.of(x).map(phredToLog).toArray();
final double sum = GATKProtectedMathUtils.logSumExp(result);
return DoubleStream.of(result).map(d -> d - sum).toArray();
}).toArray(double[][]::new);
return new TestHMM(logPriors, logEmissionProbs, logTransitionProbs);
}
use of java.util.function.DoubleUnaryOperator in project gatk by broadinstitute.
the class TestHMM method fromPhredProbabilities.
static TestHMM fromPhredProbabilities(final double... phred) {
final double[] priors = Arrays.copyOfRange(phred, 0, State.values().length);
final double[][] transition = reshape(Arrays.copyOfRange(phred, State.values().length, State.values().length * (State.values().length + 1)), State.values().length);
final double[][] emission = reshape(Arrays.copyOfRange(phred, (State.values().length + 1) * State.values().length, phred.length), State.values().length);
final DoubleUnaryOperator phredToLog = d -> d * -.1 * LN_OF_10;
final double[] logPriorsRaw = DoubleStream.of(priors).map(phredToLog).toArray();
final double logPriorsSum = GATKProtectedMathUtils.logSumExp(logPriorsRaw);
final double[] logPriors = DoubleStream.of(logPriorsRaw).map(d -> d - logPriorsSum).toArray();
final double[][] logEmissionProbs = Stream.of(emission).map(x -> {
final double[] result = DoubleStream.of(x).map(phredToLog).toArray();
final double sum = GATKProtectedMathUtils.logSumExp(result);
return DoubleStream.of(result).map(d -> d - sum).toArray();
}).toArray(double[][]::new);
final double[][] logTransitionProbs = Stream.of(transition).map(x -> {
final double[] result = DoubleStream.of(x).map(phredToLog).toArray();
final double sum = GATKProtectedMathUtils.logSumExp(result);
return DoubleStream.of(result).map(d -> d - sum).toArray();
}).toArray(double[][]::new);
return new TestHMM(logPriors, logEmissionProbs, logTransitionProbs);
}
use of java.util.function.DoubleUnaryOperator in project gatk by broadinstitute.
the class MathUtilsUnitTest method testApplyToArray.
@Test
public void testApplyToArray() {
for (final double[] array : testArrays) {
final double[] copy = Arrays.copyOf(array, array.length);
final DoubleUnaryOperator func = Math::exp;
Assert.assertEquals(MathUtils.applyToArray(copy, func), Arrays.stream(copy).map(func).toArray());
//make sure original array was not affected
Assert.assertEquals(array, copy);
}
}
Aggregations