List of usage examples for java.util Arrays fill
public static void fill(Object[] a, Object val)
From source file:net.sf.mzmine.modules.visualization.neutralloss.NeutralLossDataSet.java
public void run() { setStatus(TaskStatus.PROCESSING);/*from w w w .j a v a 2s. co m*/ processedScans = 0; for (int scanNumber : scanNumbers) { // Cancel? if (status == TaskStatus.CANCELED) return; Scan scan = rawDataFile.getScan(scanNumber); // check parent m/z if (!totalMZRange.contains(scan.getPrecursorMZ())) { continue; } // get m/z and intensity values DataPoint scanDataPoints[] = scan.getDataPoints(); // skip empty scans if (scan.getHighestDataPoint() == null) { processedScans++; continue; } // topPeaks will contain indexes to mzValues peaks of top intensity int topPeaks[] = new int[numOfFragments]; Arrays.fill(topPeaks, -1); for (int i = 0; i < scanDataPoints.length; i++) { fragmentsCycle: for (int j = 0; j < numOfFragments; j++) { // Cancel? if (status == TaskStatus.CANCELED) return; if ((topPeaks[j] < 0) || (scanDataPoints[i].getIntensity()) > scanDataPoints[topPeaks[j]].getIntensity()) { // shift the top peaks array for (int k = numOfFragments - 1; k > j; k--) topPeaks[k] = topPeaks[k - 1]; // add the peak to the appropriate place topPeaks[j] = i; break fragmentsCycle; } } } // add the data points for (int i = 0; i < topPeaks.length; i++) { int peakIndex = topPeaks[i]; // if we have a very few peaks, the array may not be full if (peakIndex < 0) break; NeutralLossDataPoint newPoint = new NeutralLossDataPoint(scanDataPoints[peakIndex].getMZ(), scan.getScanNumber(), scan.getParentScanNumber(), scan.getPrecursorMZ(), scan.getPrecursorCharge(), scan.getRetentionTime()); dataSeries.get(0).add(newPoint); } processedScans++; } fireDatasetChanged(); setStatus(TaskStatus.FINISHED); }
From source file:es.udc.gii.common.eaf.algorithm.operator.reproduction.crossover.CrossOverOperator.java
protected int[] getCrossPoints(boolean initEnd, int nPoints, int max) { int[] points; int point, i, maxPoints; if (max - 1 == nPoints) { points = new int[max + 1]; for (i = 0; i <= max; i++) { points[i] = i;//from ww w .ja va2s. c o m } return points; } if (initEnd) { points = new int[nPoints + 2]; Arrays.fill(points, Integer.MAX_VALUE); points[0] = 0; i = 1; maxPoints = points.length - 1; } else { points = new int[nPoints]; Arrays.fill(points, Integer.MAX_VALUE); i = 0; maxPoints = points.length; } while (i < maxPoints) { point = (int) Math.round(EAFRandom.nextDouble() * (max - 2)); if (Arrays.binarySearch(points, point) < 0) { points[i] = point; i++; Arrays.sort(points); } } if (initEnd) { points[points.length - 1] = max; } return points; }
From source file:com.gopivotal.cloudfoundry.test.support.runner.MethodInvoker.java
private String separator(int length) { char[] separator = new char[length]; Arrays.fill(separator, '='); return new String(separator); }
From source file:mase.mason.world.DistanceSensorArcs.java
/** * Very efficient implementation using an ordered TreeMap Should ensure * scalability when large numbers of objects are present, as there is no * need to check angles with objects that are farther than the closest * object in the given cone. Potential limitation (unlikely): if there are * two objects at exactly the same distance but at different angles, only * one of them will be considered, as the distance is used as key in the * TreeMap//from ww w . j a v a 2s. com */ @Override public double[] readValues() { lastDistances = new double[valueCount()]; Arrays.fill(lastDistances, Double.POSITIVE_INFINITY); Arrays.fill(closestObjects, null); if (range < 0.001) { return lastDistances; } double rangeNoiseAbs = Double.isInfinite(range) ? rangeNoise * fieldDiagonal : range * rangeNoise; WorldObject[] candidates = getCandidates(); // TODO: replace treemap with collection-sort Pair<Double, WorldObject>[] distances = new Pair[candidates.length]; int index = 0; for (WorldObject o : candidates) { if (!centerToCenter && o.isInside(ag.getLocation())) { Arrays.fill(lastDistances, 0); Arrays.fill(closestObjects, o); return lastDistances; } double dist = centerToCenter ? ag.getLocation().distance(o.getLocation()) : Math.max(0, ag.distanceTo(o)); if (rangeNoiseAbs > 0) { dist += rangeNoiseAbs * (noiseType == UNIFORM ? state.random.nextDouble() * 2 - 1 : state.random.nextGaussian()); dist = Math.max(dist, 0); } if (dist <= range) { distances[index++] = Pair.of(dist, o); } } if (index < distances.length) { distances = Arrays.copyOf(distances, index); } Arrays.sort(distances, new Comparator<Pair<Double, WorldObject>>() { @Override public int compare(Pair<Double, WorldObject> a, Pair<Double, WorldObject> b) { return Double.compare(a.getLeft(), b.getLeft()); } }); int filled = 0; for (Pair<Double, WorldObject> e : distances) { if (filled == arcStart.length) { break; } double angle = ag.angleTo(e.getRight().getLocation()); if (orientationNoise > 0) { angle += orientationNoise * (noiseType == UNIFORM ? state.random.nextDouble() * 2 - 1 : state.random.nextGaussian()); angle = EmboddiedAgent.normalizeAngle(angle); } for (int a = 0; a < arcStart.length; a++) { if (Double.isInfinite(lastDistances[a]) && ((angle >= arcStart[a] && angle <= arcEnd[a]) || (arcStart[a] > arcEnd[a] && (angle >= arcStart[a] || angle <= arcEnd[a])))) { filled++; lastDistances[a] = e.getKey(); closestObjects[a] = e.getValue(); } } } return lastDistances; }
From source file:com.cloudera.oryx.rdf.common.tree.DecisionForest.java
public DecisionForest(final int numTrees, double fractionOfFeaturesToTry, final int minNodeSize, final double minInfoGainNats, final int suggestedMaxSplitCandidates, final int maxDepth, final double sampleRate, final ExampleSet examples) { Preconditions.checkArgument(numTrees > 1); final int numFeatures = examples.getNumFeatures(); Preconditions.checkArgument(fractionOfFeaturesToTry > 0.0 && fractionOfFeaturesToTry <= 1.0); final int featuresToTry = FastMath.max(1, (int) (fractionOfFeaturesToTry * numFeatures)); Preconditions.checkArgument(numFeatures >= 1); Preconditions.checkArgument(minNodeSize >= 1); Preconditions.checkArgument(minInfoGainNats >= 0.0); Preconditions.checkArgument(suggestedMaxSplitCandidates >= 1); Preconditions.checkArgument(maxDepth >= 1); Preconditions.checkArgument(sampleRate > 0.0 && sampleRate <= 1.0); weights = new double[numTrees]; Arrays.fill(weights, 1.0); evaluations = new double[numTrees]; Arrays.fill(evaluations, Double.NaN); final double[][] perTreeFeatureImportances = new double[numTrees][]; // Going to set an arbitrary upper bound on the training size of about 90% int maxFolds = FastMath.min(numTrees - 1, (int) (0.9 * numTrees)); // Going to set an arbitrary lower bound on the CV size of about 10% int minFolds = FastMath.max(1, (int) (0.1 * numTrees)); final int folds = FastMath.min(maxFolds, FastMath.max(minFolds, (int) (sampleRate * numTrees))); trees = new DecisionTree[numTrees]; ExecutorService executor = Executors.newFixedThreadPool(determineParallelism(trees.length)); try {/*from w w w . j a v a2 s . co m*/ Collection<Future<Object>> futures = Lists.newArrayListWithCapacity(trees.length); for (int i = 0; i < numTrees; i++) { final int treeID = i; futures.add(executor.submit(new Callable<Object>() { @Override public Void call() throws Exception { Collection<Example> allExamples = examples.getExamples(); int totalExamples = allExamples.size(); int expectedTrainingSize = (int) (totalExamples * sampleRate); int expectedCVSize = totalExamples - expectedTrainingSize; List<Example> trainingExamples = Lists.newArrayListWithExpectedSize(expectedTrainingSize); List<Example> cvExamples = Lists.newArrayListWithExpectedSize(expectedCVSize); for (Example example : allExamples) { if (IntMath.mod(IntMath.mod(example.hashCode(), numTrees) - treeID, numTrees) < folds) { trainingExamples.add(example); } else { cvExamples.add(example); } } Preconditions.checkState(!trainingExamples.isEmpty(), "No training examples sampled?"); Preconditions.checkState(!cvExamples.isEmpty(), "No CV examples sampled?"); trees[treeID] = new DecisionTree(numFeatures, featuresToTry, minNodeSize, minInfoGainNats, suggestedMaxSplitCandidates, maxDepth, examples.subset(trainingExamples)); log.info("Finished tree {}", treeID); ExampleSet cvExampleSet = examples.subset(cvExamples); double[] weightEval = Evaluation.evaluateToWeight(trees[treeID], cvExampleSet); weights[treeID] = weightEval[0]; evaluations[treeID] = weightEval[1]; perTreeFeatureImportances[treeID] = trees[treeID].featureImportance(cvExampleSet); log.info("Tree {} eval: {}", treeID, weightEval[1]); return null; } })); } ExecutorUtils.checkExceptions(futures); } finally { ExecutorUtils.shutdownNowAndAwait(executor); } featureImportances = new double[numFeatures]; for (double[] perTreeFeatureImporatance : perTreeFeatureImportances) { for (int i = 0; i < numFeatures; i++) { featureImportances[i] += perTreeFeatureImporatance[i]; } } for (int i = 0; i < numFeatures; i++) { featureImportances[i] /= numTrees; } }
From source file:egat.cli.strategyregret.StrategyRegretCommandHandler.java
protected void processSymmetricGame(MutableSymmetricGame game) throws CommandProcessingException { try {// w ww. jav a2 s . co m Profile profile = null; if (uniform) { Player[] players = game.players().toArray(new Player[0]); Strategy[] strategies = new Strategy[players.length]; Action[] actions = ((Set<Action>) game.getActions()).toArray(new Action[0]); Number[] distribution = new Number[actions.length]; Arrays.fill(distribution, 1.0 / distribution.length); Strategy strategy = Games.createStrategy(actions, distribution); Arrays.fill(strategies, strategy); profile = Games.createProfile(players, strategies); } else { InputStream inputStream = null; inputStream = new FileInputStream(profilePath); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); ProfileHandler handler = new ProfileHandler(); parser.parse(inputStream, handler); profile = handler.getProfile(); } findRegret(profile, game); } catch (NonexistentPayoffException e) { System.err.println(String.format("Could not calculate regret. %s", e.getMessage())); } catch (FileNotFoundException e) { throw new CommandProcessingException(e); } catch (ParserConfigurationException e) { throw new CommandProcessingException(e); } catch (SAXException e) { throw new CommandProcessingException(e); } catch (IOException e) { throw new CommandProcessingException(e); } }
From source file:edu.utah.further.core.api.collections.ArrayUtil.java
/** * @param size/*from w w w . j a va 2 s. c o m*/ * @param fillValue * @return */ public static int[] newIntVector(final int size, final int fillValue) { final int[] a = new int[size]; Arrays.fill(a, fillValue); return a; }
From source file:clus.statistic.RegressionStat.java
public void reset() { m_SumWeight = 0.0; m_NbExamples = 0; Arrays.fill(m_SumWeights, 0.0); Arrays.fill(m_SumValues, 0.0); Arrays.fill(m_SumSqValues, 0.0); }
From source file:IntObjectHashMap.java
/** * Removes all (key,value) associations from the receiver. Implicitly calls * <tt>trimToSize()</tt>./* www . j a va 2 s . co m*/ */ public void clear() { Arrays.fill(state, FREE); Arrays.fill(values, null); this.distinct = 0; this.freeEntries = table.length; // delta trimToSize(); }
From source file:eu.scape_project.bitwiser.utils.SSDeep.java
static void rollReset() { rollState.h1 = 0; rollState.h2 = 0; rollState.h3 = 0; rollState.n = 0; Arrays.fill(rollState.window, (char) 0); }