List of usage examples for java.util Arrays fill
public static void fill(Object[] a, Object val)
From source file:edu.stevens.cpe.reservior.readout.CMAES.java
public double[] train(int numberWeightsToTrain) { this.epoch = 0; //Number of weights to evolve final double[] start = new double[numberWeightsToTrain]; Arrays.fill(start, startValue); final double[] lower = new double[numberWeightsToTrain]; Arrays.fill(lower, lowerBound); final double[] upper = new double[numberWeightsToTrain]; Arrays.fill(upper, upperBound); //Set to 1/3 the initial search volume final double[] sigma = new double[numberWeightsToTrain]; Arrays.fill(sigma, insigma);/*ww w.ja v a 2 s .c om*/ int lambda = 4 + (int) (3. * Math.log(numberWeightsToTrain)); int maxEvals = CMAESOptimizer.DEFAULT_MAXITERATIONS; double stopValue = .01; boolean isActive = true; //Chooses the covariance matrix update method. int diagonalOnly = 0; int checkFeasable = 0; final CMAESOptimizer optimizer = new CMAESOptimizer(lambda, sigma, CMAESOptimizer.DEFAULT_MAXITERATIONS, stopValue, isActive, diagonalOnly, checkFeasable, new MersenneTwister(), false); final PointValuePair result = optimizer.optimize(maxEvals, fitnessFuntion, GoalType.MINIMIZE, start, lower, upper); logger.info(Arrays.toString(result.getPoint())); logger.info("Best weights: " + Arrays.toString(bestWeights)); updateReadoutWeights(result.getPoint()); logger.info("done training."); return bestWeights; }
From source file:edu.harvard.i2b2.crc.dao.setfinder.PatientSetCollectionSpringDao.java
/** * Call this function at the end. i.e. after loading all patient with * addPatient function, finally call this function to clear session *//*from w ww .j a v a 2 s .c o m*/ public void flush() { InsertStatementSetter batchSetter = new InsertStatementSetter(patientSetColl, batchDataIndex); jdbcTemplate.batchUpdate(insert_sql, batchSetter); Arrays.fill(patientSetColl, null); batchDataIndex = 0; setIndex = 0; }
From source file:net.nicholaswilliams.java.licensing.TestObjectSerializer.java
@Test public void testWriteObject4() throws Exception { MockTestObject2 object = new MockTestObject2(); object.aString = "another test string"; Arrays.fill(object.password, 'b'); byte[] data = this.serializer.writeObject(object); assertNotNull("The array should not be null.", data); assertTrue("The array shoudl not be empty.", data.length > 0); ByteArrayInputStream bytes = new ByteArrayInputStream(data); ObjectInputStream stream = new ObjectInputStream(bytes); Object input = stream.readObject(); assertNotNull("The object should not be null.", input); assertEquals("The object is not the right kind of object.", MockTestObject2.class, input.getClass()); MockTestObject2 actual = (MockTestObject2) input; assertFalse("The objects should not be the same object.", actual == object); assertEquals("The object is not correct.", object, actual); }
From source file:com.bbva.arq.devops.ae.mirrorgate.jenkins.plugin.listener.MirrorGateListenerHelperTest.java
@Test public void sendBuildFromItemResponseOK() { when(service.publishBuildData(any())).thenReturn(responseOk); when(service.sendBuildDataToExtraEndpoints(any(), any())).thenReturn(responseOk); 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.milaboratory.core.alignment.ScoringMatrixIO.java
/** * Reads BLAST AminoAcid substitution matrix from InputStream * * @param stream InputStream//from w ww .j a va2 s .co m * @param alphabet alphabet * @param xChars alphabet letters * @return BLAST AminoAcid substitution matrix * @throws java.io.IOException */ public static int[] readAABlastMatrix(InputStream stream, Alphabet alphabet, char... xChars) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(stream)); String line; //Creating xValues array int[] xValues = new int[xChars.length]; for (int i = 0; i < xValues.length; ++i) if ((xValues[i] = alphabet.codeFromSymbol(xChars[i])) == -1) throw new IllegalArgumentException("XChar not from this alphabet."); //~AminoAcidAlphabet. IntArrayList mappings = new IntArrayList(30); int alSize = alphabet.size(); int[] matrix = new int[alSize * alSize]; Arrays.fill(matrix, Integer.MIN_VALUE); String[] cells; while ((line = br.readLine()) != null) { //Processing comment if (line.startsWith("#")) continue; //Processing header if (line.startsWith(" ")) { String[] letters = line.trim().split("\\s+"); for (int i = 0; i < letters.length; ++i) mappings.add(getAACode(letters[i], alphabet)); continue; } //Processing line with values cells = line.trim().split("\\s+"); //Parsing letter in the first column for (int from : getVals(getAACode(cells[0], alphabet), xValues)) { for (int i = 1; i < cells.length; ++i) for (int to : getVals(mappings.get(i - 1), xValues)) matrix[from * alSize + to] = Integer.parseInt(cells[i]); } } //Checking for matrix fullness for (int val : matrix) if (val == Integer.MIN_VALUE) throw new IllegalArgumentException("Some letters are missing in matrix."); return matrix; }
From source file:com.gc.iotools.stream.reader.TeeReaderWriter.java
/** * <p>// ww w .j a v a 2 s . c o m * Creates a <code>TeeInputStreamWriter</code> and saves its argument, the * input stream <code>source</code> and the output stream * <code>destination</code> for later use. * </p> * <p> * This constructor allow to specify multiple <code>Writer</code> to which * the data will be copied. * </p> * * @since 1.2.7 * @param source * The underlying <code>Reader</code> * @param closeStreams * if <code>true</code> the <code>destination</code> will be * closed when the {@link #close()} method is invoked. If * <code>false</code> the close method on the underlying * streams will not be called (it must be invoked externally). * @param destinations * Data read from <code>source</code> are also written to this * <code>Writer</code>. */ public TeeReaderWriter(final Reader source, final boolean closeStreams, final Writer... destinations) { this.source = source; if (destinations == null) { throw new IllegalArgumentException("Destinations Writer can't be null"); } if (destinations.length == 0) { throw new IllegalArgumentException("At least one destination Writer must be specified"); } for (final Writer destination : destinations) { if (destination == null) { throw new IllegalArgumentException("One of the Writers in the array is null"); } } this.writeTime = new long[destinations.length]; this.destinations = destinations; this.closeStreams = closeStreams; this.copyEnabled = new boolean[destinations.length]; Arrays.fill(this.copyEnabled, true); }
From source file:dk.nodes.webservice.parser.JSONStringer.java
JSONStringer(int indentSpaces) { char[] indentChars = new char[indentSpaces]; Arrays.fill(indentChars, ' '); indent = new String(indentChars); }
From source file:kishida.cnn.layers.ConvolutionLayer.java
private void localNormalization(float[] result) { final int n = 5; final int k = 2; final float a = 0.0001f; final float b = 0.75f; // result??????????? final float[] sigma = new float[n]; for (int x = 0; x < outputWidth; ++x) { for (int y = 0; y < outputHeight; ++y) { int xy = x * outputHeight + y; Arrays.fill(sigma, 0); int lp = 0; for (; lp < n / 2; ++lp) { sigma[lp] = result[lp * outputWidth * outputHeight + xy] * result[lp * outputWidth * outputHeight + xy]; }/*from w ww.j av a2 s .c om*/ for (int ch = 0; ch < outputChannels; ++ch) { sigma[lp % 5] = lp >= outputChannels ? 0 : result[lp * outputWidth * outputHeight + xy] * result[lp * outputWidth * outputHeight + xy]; lp = lp + 1; float sum = FloatUtil.floatSum(sigma); result[ch * outputWidth * outputHeight + xy] = result[ch * outputWidth * outputHeight + xy] / (float) Math.pow(k + a * sum, b); } } } }
From source file:com.linkedin.pinot.core.io.writer.impl.v2.FixedBitSingleValueWriter.java
/** * @param row//from ww w . j a v a 2s .c o m * @param col * @param val */ public void setInt(int row, int val) { try { assert val >= minValue && val <= maxValue && row == currentRow + 1; int index = row % uncompressedSize; uncompressedData[index] = val; if (index == uncompressedSize - 1 || row == numRows - 1) { BitPacking.fastpack(uncompressedData, 0, compressedData, 0, numBits); for (int i = 0; i < compressedSize; i++) { byteBuffer.putInt(compressedData[i]); } int[] out = new int[uncompressedSize]; BitPacking.fastunpack(compressedData, 0, out, 0, numBits); Arrays.fill(uncompressedData, 0); } currentRow = row; } catch (Exception e) { LOGGER.error("Failed to set row:{} val:{} ", row, val, e); throw e; } }
From source file:com.opengamma.analytics.math.statistics.leastsquare.NonLinearLeastSquare.java
/** * Use this when the model is in the ParameterizedFunction form and analytic parameter sensitivity is not available but a measurement error is. * @param x Set of measurement points/*w w w . j av a 2s . c o m*/ * @param y Set of measurement values * @param sigma y Set of measurement errors * @param func The model in ParameterizedFunction form (i.e. takes measurement points and a set of parameters and returns a model value) * @param startPos Initial value of the parameters * @return A LeastSquareResults object */ public LeastSquareResults solve(final DoubleMatrix1D x, final DoubleMatrix1D y, final double sigma, final ParameterizedFunction<Double, DoubleMatrix1D, Double> func, final DoubleMatrix1D startPos) { Validate.notNull(x, "x"); Validate.notNull(y, "y"); Validate.notNull(sigma, "sigma"); final int n = x.getNumberOfElements(); Validate.isTrue(y.getNumberOfElements() == n, "y wrong length"); final double[] sigmas = new double[n]; Arrays.fill(sigmas, sigma); return solve(x, y, new DoubleMatrix1D(sigmas), func, startPos); }