Search in sources :

Example 71 with Sum

use of org.apache.commons.math3.stat.descriptive.summary.Sum in project repseqio by repseqio.

the class ExportCloneSequencesActionTest method randomRoundTest.

@Test
public void randomRoundTest() throws Exception {
    double value = 12.34;
    double sum = 0.0;
    RandomGenerator random = new Well19937c(1232434);
    for (int i = 0; i < 100000; i++) sum += ExportCloneSequencesAction.randomizedRound(value, random);
    assertEquals(value, sum / 100000, 0.1);
}
Also used : Well19937c(org.apache.commons.math3.random.Well19937c) RandomGenerator(org.apache.commons.math3.random.RandomGenerator) Test(org.junit.Test)

Example 72 with Sum

use of org.apache.commons.math3.stat.descriptive.summary.Sum in project opennars by opennars.

the class HyperassociativeMap method align.

public void align() {
    // refresh all nodes
    /*
        if (!coordinates.keySet().equals(graph.vertexSet())) {
            final Map<N, ArrayRealVector> newCoordinates = new HashMap<N, ArrayRealVector>();
            for (final N node : graph.vertexSet()) {
                if (coordinates.containsKey(node)) {
                    newCoordinates.put(node, coordinates.get(node));
                } else {
                    newCoordinates.put(node, randomCoordinates(dimensions));
                }
            }
            coordinates = Collections.synchronizedMap(newCoordinates);
        }
        */
    totalMovement = DEFAULT_TOTAL_MOVEMENT;
    maxMovement = DEFAULT_MAX_MOVEMENT;
    ArrayRealVector center;
    if (threadExecutor == null) {
        center = processLocally();
    } else {
        // align all nodes in parallel
        final List<Future<ArrayRealVector>> futures = submitFutureAligns();
        // all the points
        try {
            center = waitAndProcessFutures(futures);
        } catch (InterruptedException caught) {
            // LOGGER.warn("waitAndProcessFutures was unexpectedly interrupted", caught);
            throw new RuntimeException("Unexpected interruption. Get should block indefinitely", caught);
        }
    }
    // LOGGER.debug("maxMove: " + maxMovement + ", Average Move: " + getAverageMovement());
    // divide each coordinate of the sum of all the points by the number of
    // nodes in order to calculate the average point, or center of all the
    // points
    int numVertices = graph.vertexSet().size();
    center.mapDivideToSelf(numVertices);
    recenterNodes(center);
}
Also used : ArrayRealVector(org.apache.commons.math3.linear.ArrayRealVector)

Aggregations

RealMatrix (org.apache.commons.math3.linear.RealMatrix)22 Collectors (java.util.stream.Collectors)15 java.util (java.util)12 Array2DRowRealMatrix (org.apache.commons.math3.linear.Array2DRowRealMatrix)12 List (java.util.List)11 IntStream (java.util.stream.IntStream)11 Logger (org.apache.logging.log4j.Logger)11 ArrayList (java.util.ArrayList)9 LogManager (org.apache.logging.log4j.LogManager)9 IOException (java.io.IOException)8 Map (java.util.Map)8 TooManyEvaluationsException (org.apache.commons.math3.exception.TooManyEvaluationsException)8 UserException (org.broadinstitute.hellbender.exceptions.UserException)8 ParamUtils (org.broadinstitute.hellbender.utils.param.ParamUtils)8 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)8 Test (org.testng.annotations.Test)8 File (java.io.File)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 Arrays (java.util.Arrays)6 Nonnull (javax.annotation.Nonnull)6