Example usage for java.util Arrays fill

List of usage examples for java.util Arrays fill

Introduction

In this page you can find the example usage for java.util Arrays fill.

Prototype

public static void fill(Object[] a, Object val) 

Source Link

Document

Assigns the specified Object reference to each element of the specified array of Objects.

Usage

From source file:com.analog.lyric.dimple.factorfunctions.ExchangeableDirichlet.java

public final double[] getAlphaMinusOneArray() // Get parameters as if they were separate
{
    double[] parameterArray = new double[_dimension];
    Arrays.fill(parameterArray, _alpha - 1);
    return parameterArray;
}

From source file:jeffaschenk.tomcat.zuul.util.KeyFileUtils.java

/**
 * Helper method to Obtain the Validated Password from the Command Line.
 *
 * @param prompt - Display Prompt/*from   www  .  jav a  2 s. c  o  m*/
 * @return char[] - Character Array of Validated/Confirmed Entered Data.
 */
private static char[] obtainValidatedPassword(String prompt) {
    char[] initialPassword = readPassword(prompt);
    // Now prompt to confirm entered Password...
    char[] confirmedPassword = readPassword("Please Confirm " + prompt);
    if (Arrays.equals(initialPassword, confirmedPassword)) {
        Arrays.fill(confirmedPassword, ' ');
        return initialPassword;
    } else {
        Arrays.fill(initialPassword, ' ');
        Arrays.fill(confirmedPassword, ' ');
        System.out.println("Passwords do not Match, unable to continue!");
        return null;
    }
}

From source file:nars.predict.RNNBeliefPrediction.java

@Override
protected void train() {
    ///*from   ww w . java  2  s  . c o m*/
    //double[] target = {((data[x(i1)] + data[x(i2)])/2.0)};
    //new Sample(data, target, 2, length, 1, 1);
    TreeMap<Integer, double[]> d = new TreeMap();
    int cc = 0;
    int hd = Math.round(predictionTimeSpanFactor * nar.memory.getDuration() / 2f / downSample);
    for (Concept c : concepts) {
        for (Sentence s : c.beliefs) {
            if (s.isEternal()) {
                continue;
            }
            int o = (int) Math.round(((double) s.getOccurenceTime()) / ((double) downSample));
            if (o > nar.time()) {
                continue; //non-future beliefs
            }
            for (int oc = o - hd; oc <= o + hd; oc++) {
                double[] x = d.get(oc);
                if (x == null) {
                    x = new double[inputSize];
                    d.put(oc, x);
                }
                float freq = 2f * (s.truth.getFrequency() - 0.5f);
                float conf = s.truth.getConfidence();
                if (freq < 0) {
                }
                x[cc] += freq * conf;
            }
        }
        cc++;
    }
    if (d.size() < 2) {
        data = null;
        return;
    }

    data = new SampleSet();
    int first = d.firstKey();
    int last = (int) nar.time();
    if (last - first > maxDataFrames * downSample) {
        first = last - maxDataFrames * downSample;
    }
    int frames = (int) (last - first);
    int bsize = getInputSize() * frames;
    int isize = getPredictionSize() * frames;
    if (actual == null || actual.length != bsize)
        actual = new double[bsize];
    else
        Arrays.fill(actual, 0);

    if (ideal == null || ideal.length != isize)
        ideal = new double[isize];
    else
        Arrays.fill(ideal, 0);

    int idealSize = getPredictionSize();
    int ac = 0, id = 0;
    double[] prevX = null;
    for (int i = first; i <= last; i++) {
        double[] x = d.get(i);
        if (x == null) {
            x = new double[inputSize];
        } else {

            if (normalizeInputVectors) {
                x = normalize(x);
            }
        }
        if (prevX != null) {
            System.arraycopy(prevX, 0, actual, ac, inputSize);
            ac += inputSize;

            System.arraycopy(getTrainedPrediction(x), 0, ideal, id, idealSize);
            id += idealSize;

        }
        prevX = x;
    }

    Sample s = new Sample(actual, ideal, inputSize, idealSize);
    data.add(s);

    //System.out.println(data);

    if (trainer == null) {
        trainer = new GradientDescent();
        trainer.setNet(net);
        trainer.setRnd(rnd);
        trainer.setPermute(true);
        trainer.setTrainingSet(data);
        trainer.setLearningRate(learningrate);
        trainer.setMomentum(momentum);
        trainer.setEpochs(trainIterationsPerCycle);
        trainer.setEarlyStopping(false);
        trainer.setOnline(true);
        trainer.setTargetError(0);
        trainer.clearListener();
    } else {
        //trainer.reset();

    }

    trainer.train();
    //System.out.println("LSTM error: " + trainer.getTrainingError());
}

From source file:com.net2plan.libraries.GraphTheoryMetrics.java

private void computeSPDistanceMetrics() {
    diameter = 0;/*from  ww  w. j a va  2  s. c  o  m*/
    averageSPLength = 0;
    heterogeneity = 0;

    Graph<Node, Link> aux_graph = getGraph_JUNG();
    Transformer<Link, Double> aux_nev = getCostTransformer();

    /* Compute network diameter using nave Floyd-Warshall algorithm */
    double[][] costMatrix = new double[N][N];
    for (int n = 0; n < N; n++) {
        Arrays.fill(costMatrix[n], Double.MAX_VALUE);
        costMatrix[n][n] = 0;
    }

    for (Link edge : aux_graph.getEdges()) {
        int a_e = edge.getOriginNode().getIndex();
        int b_e = edge.getDestinationNode().getIndex();
        double newCost = aux_nev.transform(edge);
        if (newCost < costMatrix[a_e][b_e])
            costMatrix[a_e][b_e] = newCost;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            if (i == k)
                continue;

            for (int j = 0; j < N; j++) {
                if (j == k || j == i)
                    continue;

                double newValue = costMatrix[i][k] + costMatrix[k][j];
                if (newValue < costMatrix[i][j])
                    costMatrix[i][j] = newValue;
            }
        }
    }

    int numPaths = 0;
    double sum = 0;
    double M = 0.0;
    double S = 0.0;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            double dist_ij = costMatrix[i][j];
            if (dist_ij < Double.MAX_VALUE) {
                sum += dist_ij;
                numPaths++;

                double tmpM = M;
                M += (dist_ij - tmpM) / numPaths;
                S += (dist_ij - tmpM) * (dist_ij - M);

                if (dist_ij > diameter)
                    diameter = dist_ij;
            }

            double dist_ji = costMatrix[j][i];
            if (dist_ji < Double.MAX_VALUE) {
                sum += dist_ji;
                numPaths++;

                double tmpM = M;
                M += (dist_ji - tmpM) / numPaths;
                S += (dist_ji - tmpM) * (dist_ji - M);

                if (dist_ji > diameter)
                    diameter = dist_ji;
            }
        }
    }

    if (numPaths == 0)
        return;

    averageSPLength = numPaths == 0 ? 0 : sum / numPaths;
    heterogeneity = averageSPLength == 0 ? 0 : Math.sqrt(S / numPaths) / averageSPLength;
}

From source file:com.testtubebaby.artemismain.core.ComponentManager.java

void deleteAllEntities() {
    for (Component[] e : compTable) {
        Arrays.fill(e, null);
    }
}

From source file:com.jaeksoft.searchlib.result.collector.JoinDocCollector.java

@Override
public void setForeignDocId(int pos, int joinResultPos, int foreignDocId, float foreignScore) {
    int[] foreignDocIds = foreignDocIdsArray[pos];
    if (foreignDocIds == null) {
        foreignDocIds = new int[joinResultSize];
        Arrays.fill(foreignDocIds, -1);
    }//from   w  w w  .  java 2 s  .co  m
    foreignDocIds[joinResultPos] = foreignDocId;
    foreignDocIdsArray[pos] = foreignDocIds;
}

From source file:org.terracotta.offheapstore.paging.TableStealingFromStorageIT.java

@Test
@Ignore/*from  w ww .ja va  2  s .  c o m*/
public void testSelfStealingIsStable() throws IOException {
    PageSource source = new UpfrontAllocatingPageSource(new HeapBufferSource(), MEGABYTES.toBytes(2),
            MEGABYTES.toBytes(1));

    OffHeapHashMap<Integer, byte[]> selfStealer = new WriteLockedOffHeapClockCache<>(source, true,
            new SplitStorageEngine<>(new IntegerStorageEngine(), new OffHeapBufferHalfStorageEngine<>(source,
                    KILOBYTES.toBytes(16), ByteArrayPortability.INSTANCE, false, true)));

    // failing seed value
    //long seed = 1302292028471110000L;

    long seed = System.nanoTime();
    System.err.println("Random Seed = " + seed);
    Random rndm = new Random(seed);
    int payloadSize = rndm.nextInt(KILOBYTES.toBytes(1));
    System.err.println("Payload Size = " + payloadSize);

    List<Long> sizes = new ArrayList<>();
    List<Long> tableSizes = new ArrayList<>();

    int terminalKey = 0;
    for (int key = 0; true; key++) {
        int size = selfStealer.size();
        byte[] payload = new byte[payloadSize];
        Arrays.fill(payload, (byte) key);
        selfStealer.put(key, payload);
        sizes.add((long) selfStealer.size());
        tableSizes.add(selfStealer.getTableCapacity());
        if (size >= selfStealer.size()) {
            terminalKey = key;
            selfStealer.remove(terminalKey);
            break;
        }
    }

    System.err.println("Terminal Key = " + terminalKey);

    int shrinkCount = 0;
    for (int key = terminalKey; key < 10 * terminalKey; key++) {
        byte[] payload = new byte[payloadSize];
        Arrays.fill(payload, (byte) key);
        long preTableSize = selfStealer.getTableCapacity();
        selfStealer.put(key, payload);
        if (rndm.nextBoolean()) {
            selfStealer.remove(rndm.nextInt(key));
        }
        long postTableSize = selfStealer.getTableCapacity();
        if (preTableSize > postTableSize) {
            shrinkCount++;
        }
        sizes.add((long) selfStealer.size());
        tableSizes.add(postTableSize);
    }

    if (shrinkCount != 0) {
        Map<String, List<? extends Number>> data = new HashMap<>();
        data.put("actual size", sizes);
        data.put("table size", tableSizes);

        JFreeChart chart = ChartFactory.createXYLineChart("Cache Size", "operations", "size",
                new LongListXYDataset(data), PlotOrientation.VERTICAL, true, false, false);
        File plotOutput = new File("target/TableStealingFromStorageTest.testSelfStealingIsStable.png");
        ChartUtilities.saveChartAsPNG(plotOutput, chart, 640, 480);
        fail("Expected no shrink events after reaching equilibrium : saw " + shrinkCount + " [plot in "
                + plotOutput + "]");
    }
}

From source file:com.bbva.arq.devops.ae.mirrorgate.jenkins.plugin.listener.MirrorGateListenerHelperTest.java

@Test
public void sendBuildFromItemResponseError() {
    when(service.publishBuildData(any())).thenReturn(responseError);
    when(service.sendBuildDataToExtraEndpoints(any(), any())).thenReturn(responseError);

    Job[] jobs = new Job[new Random().nextInt(10)];
    Arrays.fill(jobs, createMockingJob());

    helper.sendBuildFromItem(createMockingItem(jobs));

    verify(service, times(jobs.length)).publishBuildData(any());
}

From source file:com.lightboxtechnologies.io.IOUtilsTest.java

@Test
public void testReadFull() throws IOException {
    final byte[] expected = new byte[100];
    Arrays.fill(expected, (byte) 1);

    final InputStream in = new ByteArrayInputStream(expected);
    final byte[] actual = new byte[100];
    final int count = IOUtils.read(in, actual);

    assertEquals(expected.length, count);
    assertArrayEquals(expected, actual);
}

From source file:com.fishbeans.stream.StreamReceiver.java

private static String repeatSymbol(final char aChar, final int count) {
    char[] buffer = new char[count];
    Arrays.fill(buffer, aChar);

    return new String(buffer);
}