List of usage examples for com.google.common.primitives Doubles max
public static double max(double... array)
From source file:br.usp.lti.cdds.metaheuristics.RoulleteSelection.java
public static Solution select(ArrayList<Solution> solutionSet) { double[] prob = new double[solutionSet.size()]; for (int i = 0; i < prob.length; i++) { prob[i] = solutionSet.get(i).getFitness(); }//ww w . j a v a 2 s . c o m double min = Doubles.min(prob); double max = Doubles.max(prob); double sum = 0; for (int i = 0; i < prob.length; i++) { prob[i] = (max - prob[i]) / (max - min); sum += prob[i]; } for (int i = 0; i < prob.length; i++) { prob[i] = prob[i] / sum; } //prepare roullete int[] roullete = new int[100]; int roulletepos = 0; for (int i = 0; i < prob.length; i++) { double roulletepart = Math.round(prob[i] * 100.0); for (int k = 0; k < roulletepart && roulletepos < roullete.length; k++) { roullete[roulletepos++] = i; } } int truepos; //do{ Random rdn = new Random(); int selected = rdn.nextInt(roullete.length); truepos = roullete[selected]; //}while(truepos==previousSelected); return solutionSet.get(truepos); }
From source file:ummisco.gama.opengl.scene.FieldDrawer.java
@Override protected void _draw(final FieldObject demObj) { try {/*from w ww . ja v a 2s. c om*/ gl.pushMatrix(); if (demObj.getObject() == null) { drawFromImage(demObj); return; } final double altFactor = MoreObjects.firstNonNull(demObj.getAttributes().getHeight(), 1.0); final double maxZ = Doubles.max(demObj.getObject()); if (demObj.getAttributes().grayScaled) { gl.disableTextures(); } if (demObj.getAttributes().triangulated) { drawAsTriangles(demObj, altFactor, maxZ); } else { drawAsRectangles(demObj, altFactor, maxZ); } if (demObj.getAttributes().withText && demObj.getObject() != null) { drawLabels(demObj, altFactor); } } finally { gl.popMatrix(); } }
From source file:inflor.core.transforms.LogrithmicTransform.java
public void optimize(double[] data) { min = Doubles.min(data); max = Doubles.max(data); }
From source file:com.github.rinde.rinsim.scenario.measure.LoadRequirement.java
@Override public boolean apply(@Nullable Scenario scenario) { assert scenario != null; final List<Double> loads = newArrayList( relative ? Metrics.measureRelativeLoad(scenario) : Metrics.measureLoad(scenario)); final int toAdd = desiredLoadList.size() - loads.size(); for (int j = 0; j < toAdd; j++) { loads.add(0d);//from w w w. j a v a 2 s. c o m } final double[] deviations = abs(subtract(Doubles.toArray(desiredLoadList), Doubles.toArray(loads))); final double mean = StatUtils.mean(deviations); final double max = Doubles.max(deviations); return max <= maxMax && mean <= maxMean; }
From source file:inflor.core.plots.CategoryResponseChart.java
public JFreeChart createChart(FCSFrame dataFrame) { CategoryXYZDataSet categoryData = new CategoryXYZDataSet(); double zMin = Double.MAX_VALUE; double zMax = 1; if (dataFrame.getKeywords().containsKey(FCSUtilities.KEY_MERGE_MAP)) { String[] mergeMap = dataFrame.getKeywordValue(FCSUtilities.KEY_MERGE_MAP) .split(NodeUtilities.DELIMITER_REGEX); FCSDimension dim = dataFrame.getDimension(axisName); double[] transformedData = transform.transform(dim.getData()); int perFileSize = dim.getData().length / mergeMap.length; for (int i = 0; i < mergeMap.length; i++) { double[] unMergedData = new double[perFileSize]; for (int j = 0; j < unMergedData.length; j++) { unMergedData[j] = transformedData[i * unMergedData.length + j]; }/*from w w w .j a v a 2 s .com*/ double tMin = transform.getMinTranformedValue(); double tMax = transform.getMaxTransformedValue(); Histogram1D hist = new Histogram1D(unMergedData, tMin, tMax, ChartingDefaults.BIN_COUNT); double[] x = hist.getNonZeroX(); double[] y = new double[x.length]; for (int j = 0; j < y.length; j++) { y[j] = i; } double[] z = hist.getNonZeroY(); double currentZMin = Doubles.min(z); double currentZMax = Doubles.max(z); if (currentZMin < zMin) { zMin = currentZMin; } else if (currentZMax > zMax) { zMax = currentZMax; } categoryData.addCategoricalSeries(mergeMap[i], x, z); } } else { FCSDimension dim = dataFrame.getDimension(axisName); double[] transformedData = transform.transform(dim.getData()); Histogram1D hist = new Histogram1D(transformedData, transform.getMinTranformedValue(), transform.getMaxTransformedValue(), ChartingDefaults.BIN_COUNT); double[] x = hist.getNonZeroX(); double[] y = new double[x.length]; for (int j = 0; j < y.length; j++) { y[j] = 0; } double[] z = hist.getNonZeroY(); double currentZMin = Doubles.min(z); double currentZMax = Doubles.max(z); if (currentZMin < zMin) { zMin = currentZMin; } else if (currentZMax > zMax) { zMax = currentZMax; } categoryData.addCategoricalSeries(dataFrame.getDisplayName(), x, z); } ValueAxis domainAxis = PlotUtils.createAxis(axisName, transform); NumberAxis rangeAxis = new CategoricalNumberAxis("", categoryData.getLabelMap()); // Renderer configuration XYBlockRenderer renderer = new XYBlockRenderer(); double xWidth = (transform.getMaxTransformedValue() - transform.getMinTranformedValue()) / ChartingDefaults.BIN_COUNT; renderer.setBlockWidth(xWidth); renderer.setBlockHeight(0.5); renderer.setBlockAnchor(RectangleAnchor.LEFT); PaintScale paintScale = PlotUtils.createPaintScale(zMax, ChartingDefaults.DEFAULT_COLOR_SCHEME); renderer.setPaintScale(paintScale); // Add to panel. XYPlot responsePlot = new XYPlot(categoryData, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart(responsePlot); chart.removeLegend(); return chart; }
From source file:com.davidbracewell.math.linear.DenseVector.java
@Override public double max() { return Doubles.max(map); }
From source file:com.davidbracewell.math.linear.SparseVector.java
@Override public double max() { return Doubles.max(map.values().elements()); }
From source file:controller.ClassificationController.java
public static void classify(String classifier, FeatureModel featureModel) { //scaling of features float[][] features_scaled = Util.deepcopy(featureModel.getFeatures()); double[][] scaling = (double[][]) Util.load(classifier.replace("[model]", "[scaling]")); double[] mean = scaling[0]; double[] std = scaling[1]; for (float[] feature : features_scaled) { for (int j = 0; j < feature.length; j++) { feature[j] = (float) ((feature[j] - mean[j]) / std[j]); }// w ww.j a v a 2s . co m } //load classifier 1 for arousals ClassificationController svmArousal = new ClassificationController(); svmArousal.svmLoadModel(classifier.replace("[model]", "[arousal]")); //load classifier 2 for sleep stages ClassificationController svm = new ClassificationController(); svm.svmLoadModel(classifier); //load indices indicating the features of the feature vector of classifier 2 String dir = System.getProperty("user.dir"); String filename = "sparse_features.jo"; String fullPath = dir + File.separator + "Classifiers" + File.separator + filename; double[] fidx = (double[]) Util.load(fullPath); float[] kcPercentage = featureModel.getKcPercentage(); double[] output; int N1flag = 0; int Wflag = 0; for (int i = 0; i < featureModel.getNumberOfEpochs(); i++) { //get unscaled features float[] features_unscaled = featureModel.getFeatureVector(i); //use only subset of feature vector as stored in sparse_features.jo array float[] f1 = new float[fidx.length]; for (int j = 0; j < f1.length; j++) { //use scaled features here f1[j] = features_scaled[i][(int) (fidx[j] - 1)]; } output = svm.svmPredict(Util.floatToDouble(f1)); int classLabel = Doubles.indexOf(output, Doubles.max(output)); double W = features_unscaled[18]; double N2 = features_unscaled[1]; //(skewness) double N3 = features_unscaled[49]; //cepstrum double MA1 = features_unscaled[3]; //max value of high passed epoch double MA2 = features_unscaled[9]; //energy in HF wavelet band double KC = kcPercentage[i]; //hand selected features for arousals boolean MA3 = MA1 > 40 & MA2 > 0.4; double[] MAtmp = svmArousal.svmPredict(Util.floatToDouble(features_scaled[i])); boolean MA = (MAtmp[1] > MAtmp[0]) | MA3; //convert SVM labels to SleepPilot labels (4 is REM) if (classLabel == 4) { classLabel = 5; } if (classLabel == 5 & MA) { classLabel = 1; } if (classLabel == 2 & KC == 0 & MA) { classLabel = 1; } //adjust classifier output to be consistent with SleepPilots K-complex detector if (classLabel == 3 & KC <= 20) { classLabel = 2; } if (classLabel == 2 & KC > 20 & !MA) { classLabel = 3; } //set artefacts and arousals to zero (standard) featureModel.setArtefact(i, 0); featureModel.setArousal(i, 0); if (classLabel != 0 & MA) { featureModel.setArtefact(i, 1); featureModel.setArousal(i, 1); } if (classLabel != 0 & MA1 > 80) { featureModel.setArtefact(i, 1); } //REM is always after N3, at least in non-pathological cases if (classLabel == 3) { N1flag += 1; } if (classLabel == 5 & N1flag < 2) { classLabel = 1; } featureModel.setPredictProbabilities(i, output.clone()); featureModel.setLabel(i, classLabel); System.out.println("Predicted Class Label: " + classLabel); } featureModel.setClassificationDone(true); }
From source file:edu.cmu.lti.oaqa.baseqa.answer.collective_score.scorers.EditDistanceCollectiveAnswerScorer.java
@Override public Map<String, Double> score(JCas jcas, Answer answer) { Map<Answer, Double> neighbor2distance = distances.row(answer); ImmutableMap.Builder<String, Double> builder = ImmutableMap.builder(); for (int topLimit : topLimits) { double[] distances = answers.subList(0, Math.min(answers.size(), topLimit)).stream() .mapToDouble(neighbor -> neighbor2distance.getOrDefault(neighbor, 0.0)).toArray(); builder.put("edit-distance-min-" + topLimit, Doubles.min(distances)); builder.put("edit-distance-max-" + topLimit, Doubles.max(distances)); builder.put("edit-distance-avg-" + topLimit, DoubleStream.of(distances).average().orElse(0.0)); }/*from w ww. ja va2 s .co m*/ return builder.build(); }
From source file:com.mgmtp.perfload.perfalyzer.binning.PerfMonBinningStrategy.java
private void writeAggregatedLine(final WritableByteChannel destChannel) throws IOException { double[] allValues = binManager.flatValuesStream().toArray(); StrBuilder sb = new StrBuilder(); String min = intNumberFormat.format(Doubles.min(allValues)); String max = intNumberFormat.format(Doubles.max(allValues)); switch (typeConfig) { case CPU://w ww . j ava2 s .c o m case IO: case JAVA: String mean = intNumberFormat.format(StatUtils.mean(allValues)); appendEscapedAndQuoted(sb, DELIMITER, min, mean, max); break; case MEM: case SWAP: Percentile percentile = new Percentile(); percentile.setData(allValues); String q10 = intNumberFormat.format(percentile.evaluate(10d)); String q50 = intNumberFormat.format(percentile.evaluate(50d)); String q90 = intNumberFormat.format(percentile.evaluate(90d)); appendEscapedAndQuoted(sb, DELIMITER, min, q10, q50, q90, max); break; default: throw new IllegalStateException("Invalid perfMon data type"); } writeLineToChannel(destChannel, sb.toString(), Charsets.UTF_8); }