Search in sources :

Example 6 with DoubleUnaryOperator

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));
}
Also used : TestCase(junit.framework.TestCase) Comparator(java.util.Comparator) BinaryOperator(java.util.function.BinaryOperator) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator)

Example 7 with DoubleUnaryOperator

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);
}
Also used : java.util(java.util) GATKProtectedMathUtils(org.broadinstitute.hellbender.utils.GATKProtectedMathUtils) Stream(java.util.stream.Stream) Pair(org.apache.commons.math3.util.Pair) Utils(org.broadinstitute.hellbender.utils.Utils) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Collectors(java.util.stream.Collectors) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) DoubleStream(java.util.stream.DoubleStream) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator)

Example 8 with DoubleUnaryOperator

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);
}
Also used : java.util(java.util) GATKProtectedMathUtils(org.broadinstitute.hellbender.utils.GATKProtectedMathUtils) Stream(java.util.stream.Stream) Pair(org.apache.commons.math3.util.Pair) Utils(org.broadinstitute.hellbender.utils.Utils) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Collectors(java.util.stream.Collectors) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) DoubleStream(java.util.stream.DoubleStream) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator)

Example 9 with DoubleUnaryOperator

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);
    }
}
Also used : DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

DoubleUnaryOperator (java.util.function.DoubleUnaryOperator)9 Comparator (java.util.Comparator)4 BinaryOperator (java.util.function.BinaryOperator)4 TestCase (junit.framework.TestCase)4 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 DoubleStream (java.util.stream.DoubleStream)2 Stream (java.util.stream.Stream)2 ArrayUtils (org.apache.commons.lang3.ArrayUtils)2 Pair (org.apache.commons.math3.util.Pair)2 GATKProtectedMathUtils (org.broadinstitute.hellbender.utils.GATKProtectedMathUtils)2 Utils (org.broadinstitute.hellbender.utils.Utils)2 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)2 Test (org.testng.annotations.Test)2 IAST (org.matheclipse.core.interfaces.IAST)1 IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)1 IEvaluator (org.matheclipse.core.interfaces.IEvaluator)1 IExpr (org.matheclipse.core.interfaces.IExpr)1 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)1 ISymbol (org.matheclipse.core.interfaces.ISymbol)1