List of usage examples for java.util Arrays fill
public static void fill(Object[] a, Object val)
From source file:juicebox.matrix.InMemoryMatrix.java
public void fill(float value) { Arrays.fill(data, value); // Invalidate bounds lowerValue = Float.NaN; upperValue = Float.NaN; }
From source file:gda.analysis.numerical.straightline.StraightLineFit.java
/** * //from w w w .j a v a2 s .c om * @param data Points on a line are the set data.get(i)[m] where i varies from point to point * on the line * @param x * @return Array of Result of length equal to the length of the data arrays */ public static Results fit(List<double[]> data, long[] dims, double[] x) { int numLines = data.get(0).length; int pointsPerLine = x.length; if (data.size() != pointsPerLine) throw new IllegalArgumentException("data.size() != pointsPerLine"); for (int i = 0; i < pointsPerLine; i++) { if (data.get(i).length != numLines) throw new IllegalArgumentException("data.get(i).length != numLines"); } double xAverage = getXAverage(x); double x1 = getX(x, xAverage); double[] y = new double[pointsPerLine]; double[] slopes = new double[numLines]; double[] offsets = new double[numLines]; short[] fitoks = new short[numLines]; Arrays.fill(fitoks, (short) 0); if (pointsPerLine >= 2) { Arrays.fill(fitoks, (short) 1); for (int line = 0; line < numLines; line++) { for (int point = 0; point < pointsPerLine; point++) { y[point] = data.get(point)[line]; } Result fit2 = fit2(y, x, xAverage, x1); slopes[line] = fit2.getSlope(); offsets[line] = fit2.getOffset(); } } return new Results(offsets, slopes, dims, fitoks); }
From source file:name.martingeisse.stackd.common.cubes.RawCubes.java
/** * Builds an instance of this type, filled uniformly with a single cube type. * @param clusterSize the cluster size/*from w w w . j a v a 2 s . c o m*/ * @param cubeType the cube type to fill the returned object with * @return the cubes object */ public static RawCubes buildUniform(final ClusterSize clusterSize, final byte cubeType) { final byte[] cubes = new byte[clusterSize.getCellCount()]; Arrays.fill(cubes, cubeType); return new RawCubes(cubes); }
From source file:hivemall.common.SpaceEfficientDenseModel.java
public SpaceEfficientDenseModel(int ndims, boolean withCovar) { int size = ndims + 1; this.size = size; this.weights = new short[size]; if (withCovar) { short[] covars = new short[size]; Arrays.fill(covars, HalfFloat.ONE); this.covars = covars; } else {// w w w .j a v a2s . c om this.covars = null; } }
From source file:com.webcohesion.ofx4j.io.tagsoup.TestTagSoupOFXReader.java
/** * tests using sax to parse an OFX doc./*from ww w. jav a2s .c o m*/ */ public void testVersion1() throws Exception { TagSoupOFXReader reader = new TagSoupOFXReader(); final Map<String, String> headers = new HashMap<String, String>(); final Stack<Map<String, Object>> aggregateStack = new Stack<Map<String, Object>>(); TreeMap<String, Object> root = new TreeMap<String, Object>(); aggregateStack.push(root); reader.setContentHandler(new DefaultHandler() { @Override public void onHeader(String name, String value) { LOG.debug(name + ":" + value); headers.put(name, value); } @Override public void onElement(String name, String value) { char[] tabs = new char[aggregateStack.size() * 2]; Arrays.fill(tabs, ' '); LOG.debug(new String(tabs) + name + "=" + value); aggregateStack.peek().put(name, value); } @Override public void startAggregate(String aggregateName) { char[] tabs = new char[aggregateStack.size() * 2]; Arrays.fill(tabs, ' '); LOG.debug(new String(tabs) + aggregateName + " {"); TreeMap<String, Object> aggregate = new TreeMap<String, Object>(); aggregateStack.peek().put(aggregateName, aggregate); aggregateStack.push(aggregate); } @Override public void endAggregate(String aggregateName) { aggregateStack.pop(); char[] tabs = new char[aggregateStack.size() * 2]; Arrays.fill(tabs, ' '); LOG.debug(new String(tabs) + "}"); } }); reader.parse(TestNanoXMLOFXReader.class.getResourceAsStream("example-response.ofx")); assertEquals(9, headers.size()); assertEquals(1, aggregateStack.size()); assertSame(root, aggregateStack.pop()); }
From source file:edu.utexas.cs.tactex.tariffoptimization.OptimizerWrapperApachePowell.java
@Override public TreeMap<Double, TariffSpecification> findOptimum(TariffUtilityEstimate tariffUtilityEstimate, int NUM_RATES, int numEval) { double[] startingVertex = new double[NUM_RATES]; // start from the fixed-rate tariff's offset Arrays.fill(startingVertex, 0.0); PowellOptimizer optimizer = new PowellOptimizer(1e-3, 5); // needed since one optimization found positive // charges (paying customer to consume...) double[][] boundaries = createBoundaries(NUM_RATES); final PointValuePair optimum = optimizer.optimize(new MaxEval(numEval), //new ObjectiveFunction(new MultivariateFunctionMappingAdapter(tariffUtilityEstimate, boundaries[0], boundaries[1])), new ObjectiveFunction(new OptimizerWrapperApacheObjective(tariffUtilityEstimate)), GoalType.MAXIMIZE, new InitialGuess(startingVertex)); TreeMap<Double, TariffSpecification> eval2TOUTariff = new TreeMap<Double, TariffSpecification>(); eval2TOUTariff.put(optimum.getValue(), tariffUtilityEstimate.getCorrespondingSpec(optimum.getKey())); return eval2TOUTariff; }
From source file:edu.oregonstate.eecs.mcplan.domains.sailing.SailingWorlds.java
public static SailingState squareIsland(final int V, final int T, final int dim, final int island_dim) { final String[] spec = new String[dim]; final char[] water = new char[dim]; Arrays.fill(water, 'w'); final char[] island = new char[dim]; Arrays.fill(island, 'w'); final int water_left = (dim - island_dim) / 2; for (int j = 0; j < island_dim; ++j) { island[water_left + j] = 'l'; }//from w ww .j a v a 2s .c o m for (int i = 0; i < dim; ++i) { if (i >= water_left && i < water_left + island_dim) { spec[i] = new String(island); } else { spec[i] = new String(water); } } final SailingTerrain[][] terrain = parse(spec, 1); return new SailingState(terrain, V, T); }
From source file:mase.app.allocation.AllocationProblem.java
@Override public void setup(EvolutionState state, Parameter base) { super.setup(state, base); ParamUtils.autoSetParameters(this, state, base, defaultBase(), false); nulify = new double[numAgents]; Arrays.fill(nulify, Double.NaN); dimensions = state.parameters.getInt(new Parameter("vector.species.genome-size"), null); // calculate types, if not given if (uniqueTypes == null) { int div = numAgents / numUniqueTypes; int rem = numAgents % numUniqueTypes; uniqueTypes = new int[numUniqueTypes]; for (int i = 0; i < numUniqueTypes; i++) { uniqueTypes[i] = div;/*from www. j a v a 2s . c o m*/ if (rem > 0) { uniqueTypes[i]++; rem--; } } } else { state.output.warning("Overriding numTypes with the given types"); } // validate simulation parameters int checkSum = 0; for (int t : uniqueTypes) { checkSum += t; } if (checkSum != numAgents) { state.output .fatal("Optimal allocation " + checkSum + " does not match the number of agents " + numAgents); } if (numClusters > 0 && (clusterSize < 0 || clusterSize > 1)) { state.output.fatal("Invalid cluster size [0,1]: " + clusterSize); } if (minSeparation == -1) { minSeparation = FastMath.sqrt(dimensions) / 3; state.output.warning("Using default min separation sqrt(dimensions)/3: " + minSeparation); } // randomly create target points Random rand = new Random((int) state.job[0]); double[][] unique = new double[uniqueTypes.length][]; if (numClusters == 0) { double[] min = new double[dimensions], max = new double[dimensions]; Arrays.fill(min, 0); Arrays.fill(max, 1); unique = generateDispersedPoints(rand, uniqueTypes.length, minSeparation, min, max); } else { double[] min = new double[dimensions], max = new double[dimensions]; Arrays.fill(min, clusterSize / 2); Arrays.fill(max, 1 - clusterSize / 2); double[][] centers = generateDispersedPoints(rand, numClusters, minSeparation, min, max); int perCluster = uniqueTypes.length / numClusters; int remaining = uniqueTypes.length % numClusters; for (int i = 0; i < centers.length; i++) { for (int j = 0; j < dimensions; j++) { min[j] = centers[i][j] - clusterSize / 2; max[j] = centers[i][j] + clusterSize / 2; } int size = perCluster; if (remaining > 0) { size++; remaining--; } double[][] generated = generateDispersedPoints(rand, size, 0, min, max); System.arraycopy(generated, 0, unique, i * perCluster, generated.length); } } types = new double[numAgents][]; int index = 0; for (int i = 0; i < unique.length; i++) { for (int j = 0; j < uniqueTypes[i]; j++) { types[index++] = unique[i]; } } // debug: print types for (int i = 0; i < types.length; i++) { System.out.println(i + ": " + Arrays.toString(types[i])); } System.out.print(" "); for (int i = 0; i < types.length; i++) { System.out.printf("%6d", i); } System.out.println(); for (int i = 0; i < types.length; i++) { System.out.printf("%2d", i); for (int j = 0; j < types.length; j++) { System.out.printf(" %.3f", DIST.compute(types[i], types[j])); } System.out.println(); } }
From source file:gedi.lfc.gui.LfcMapper.java
@Override public PixelBlockToValuesMap map(ReferenceSequence reference, GenomicRegion region, PixelLocationMapping pixelMapping, PixelBlockToValuesMap data) { double[] counts = new double[2]; PixelBlockToValuesMap re = new PixelBlockToValuesMap(data.getBlocks(), 2, NumericArrayType.Double); for (int i = 0; i < pixelMapping.size(); i++) { NumericArray in = data.getValues(i); Arrays.fill(counts, 0); for (int c = 0; c < in.length(); c++) { int cond = contrast == null ? (c * 2) / in.length() : contrast.getMappedIndex(c); if (cond != -1) counts[cond] += in.getDouble(c); }/*from w w w . ja v a2 s . c o m*/ NumericArray out = re.getValues(i); if (ArrayUtils.max(counts) > 0) { // out.set(0, Math.log(counts[0]/counts[1])/Math.log(2)); BetaDistribution dist = new BetaDistribution(counts[0] + 1, counts[1] + 1); out.set(0, pToLfc(dist.inverseCumulativeProbability(lower))); out.set(1, pToLfc(dist.inverseCumulativeProbability(upper))); } else { out.setDouble(0, Double.NaN); out.setDouble(1, Double.NaN); } } return re; }
From source file:com.ori.outlierserver.model.DataUtil.java
private double[] getOutlierBounderysFromLits(List<Reading> list) { if (list == null) { return null; }//from w w w. j av a 2 s. com if (list.size() == 1) { double[] arrayForOne = new double[4]; Arrays.fill(arrayForOne, list.get(0).getMedian_value()); return arrayForOne; } List<Double> values = new ArrayList<>(); list.stream().forEach((Reading r) -> { values.add(r.getMedian_value()); }); int theSize = values.size(); if (theSize == 1) { return new double[] {}; } Collections.sort(values); boolean isEven = theSize % 2 == 0; double medianValue = findMedianValue(values); List<Double> lowerHalf = new ArrayList<>(); List<Double> upperHalf = new ArrayList<>(); for (Double d : values) { if (d.compareTo(medianValue) == -1) { lowerHalf.add(d); } } for (Double d : values) { if (d.compareTo(medianValue) >= 0) { upperHalf.add(d); } } double medianLow = findMedianValue(lowerHalf); double medianHigh = findMedianValue(upperHalf); double minorFenceDelta = (medianHigh - medianLow) * 1.5; double majorFenceDelta = (medianHigh - medianLow) * 3; return new double[] { medianLow - majorFenceDelta, medianLow - minorFenceDelta, medianHigh + minorFenceDelta, medianHigh + majorFenceDelta }; }