List of usage examples for java.lang Double NEGATIVE_INFINITY
double NEGATIVE_INFINITY
To view the source code for java.lang Double NEGATIVE_INFINITY.
Click Source Link
From source file:edu.rice.cs.bioinfo.programs.phylonet.algos.network.NetworkPseudoLikelihoodFromGTT_SingleTreePerLocus.java
protected double calculateFinalLikelihood(double[][] probs, List tripletFrequencies) { int index = 0; double totalProb = 0; for (Object o : tripletFrequencies) { double[] freqs = (double[]) o; for (int i = 0; i < 3; i++) { if (probs[index][i] == 0) return Double.NEGATIVE_INFINITY; totalProb += freqs[i] * Math.log(probs[index][i]); //totalProb *= Math.pow(probs[index][i],freqs[i]); }/*from ww w . j a v a 2 s .co m*/ index++; } return totalProb; }
From source file:mase.spec.SafeHybridExchanger.java
private double fitnessDifference(MetaPopulation reference, MetaPopulation other, EvolutionState state) { // search foreign of reference in other Foreign f = null;/*from w w w . j a v a 2 s . c om*/ for (Foreign fOther : other.foreigns) { if (fOther.origin == reference) { f = fOther; break; } } if (f == null || f.inds == null) { return Double.POSITIVE_INFINITY; } // pick individuals from the reference population, using the same method used to pick the foreign individuals Individual[] refInds = pickIndividuals(reference.inds, f.inds.length, foreignMode, state); if (differenceMode == DifferenceMode.mean) { double refFit = 0; for (Individual i : refInds) { refFit += i.fitness.fitness(); } double foreignFit = 0; for (Individual i : f.inds) { foreignFit += i.fitness.fitness(); } return refFit == 0 ? Double.POSITIVE_INFINITY : Math.abs(refFit - foreignFit) / Math.abs(refFit); } else if (differenceMode == DifferenceMode.max) { double refFit = Double.NEGATIVE_INFINITY; for (Individual i : refInds) { refFit = Math.max(refFit, i.fitness.fitness()); } double foreignFit = Double.NEGATIVE_INFINITY; for (Individual i : f.inds) { foreignFit = Math.max(foreignFit, i.fitness.fitness()); } return refFit == 0 ? Double.POSITIVE_INFINITY : Math.abs(refFit - foreignFit) / Math.abs(refFit); } else if (differenceMode == DifferenceMode.utest) { double[] refFits = new double[refInds.length]; double[] forFits = new double[f.inds.length]; for (int i = 0; i < refFits.length; i++) { refFits[i] = refInds[i].fitness.fitness(); } for (int i = 0; i < forFits.length; i++) { forFits[i] = f.inds[i].fitness.fitness(); } MannWhitneyUTest test = new MannWhitneyUTest(); return test.mannWhitneyU(refFits, forFits) / (refFits.length * forFits.length); } else { return Double.NaN; } }
From source file:org.jax.bham.test.HaplotypeAssociationTestGraphPanel.java
/** * Gets the index of the interval with the highest value that falls * under the given Java2D coordinates/* w ww. j a v a 2s . c o m*/ * @param x * the Java2D X coordinate * @param y * the Java2D Y coordinate * @return * the interval index */ private int getMaximalIntervalIndex(int x, int y) { int clickIndex = -1; int[] chromosomes = this.getSelectedChromosomes(); if (chromosomes.length == 1) { RealValuedBasePairInterval[] selectedValuesList = this.chromosomeToNegLogValueMap.get(chromosomes[0]); if (selectedValuesList != null) { Point2D clickedGraphPoint = JFreeChartUtil.java2DPointToGraphPoint(new Point(x, y), this.chartPanel); // exhaustive search for the maximum clicked index (this could // be a binary search, but this seems to perform OK for now) double graphX = clickedGraphPoint.getX(); int valueCount = selectedValuesList.length; double biggestClickedValue = Double.NEGATIVE_INFINITY; for (int i = 0; i < valueCount; i++) { RealValuedBasePairInterval currValue = selectedValuesList[i]; if (currValue.getStartInBasePairs() < graphX && currValue.getEndInBasePairs() > graphX && currValue.getRealValue() > biggestClickedValue) { biggestClickedValue = currValue.getRealValue(); clickIndex = i; } } // if we didn't click on anything grab the nearest item // (again this could and should be faster) if (clickIndex == -1 && valueCount >= 1) { clickIndex = 0; double nearestDistance = Math.min( Math.abs(selectedValuesList[0].getStartInBasePairs() - graphX), Math.abs(selectedValuesList[0].getEndInBasePairs() - graphX)); for (int i = 1; i < valueCount; i++) { BasePairInterval currValue = selectedValuesList[i]; double currDistance = Math.min(Math.abs(currValue.getStartInBasePairs() - graphX), Math.abs(currValue.getEndInBasePairs() - graphX)); if (currDistance < nearestDistance) { nearestDistance = currDistance; clickIndex = i; } } } } } return clickIndex; }
From source file:com.clust4j.algo.KMedoids.java
@Override protected KMedoids fit() { synchronized (fitLock) { if (null != labels) // already fit return this; final LogTimer timer = new LogTimer(); final double[][] X = data.getData(); final double nan = Double.NaN; // Corner case: K = 1 or all singular if (1 == k) { labelFromSingularK(X);//from ww w.jav a 2 s . com fitSummary.add(new Object[] { iter, converged, tss, // tss tss, // avg per cluster tss, // wss nan, // bss (none) timer.wallTime() }); sayBye(timer); return this; } // We do this in KMedoids and not KMeans, because KMedoids uses // real points as medoids and not means for centroids, thus // the recomputation of distances is unnecessary with the dist mat dist_mat = Pairwise.getDistance(X, getSeparabilityMetric(), true, false); info("distance matrix computed in " + timer.toString()); // Initialize labels medoid_indices = init_centroid_indices; ClusterAssignments clusterAssignments; MedoidReassignmentHandler rassn; int[] newMedoids = medoid_indices; // Cost vars double bestCost = Double.POSITIVE_INFINITY, maxCost = Double.NEGATIVE_INFINITY, avgCost = Double.NaN, wss_sum = nan; // Iterate while the cost decreases: boolean convergedFromCost = false; // from cost or system changes? boolean configurationChanged = true; while (configurationChanged && iter < maxIter) { /* * 1. In each cluster, make the point that minimizes * the sum of distances within the cluster the medoid */ try { clusterAssignments = assignClosestMedoid(newMedoids); } catch (IllegalClusterStateException ouch) { exitOnBadDistanceMetric(X, timer); return this; } /* * 1.5 The entries are not 100% equal, so we can (re)assign medoids... */ try { rassn = new MedoidReassignmentHandler(clusterAssignments); } catch (IllegalClusterStateException ouch) { exitOnBadDistanceMetric(X, timer); return this; } /* * 1.75 This happens in the case of bad kernels that cause * infinities to propagate... we can't segment the input * space and need to just return a single cluster. */ if (rassn.new_clusters.size() == 1) { this.k = 1; warn("(dis)similarity metric cannot partition space without propagating Infs. Returning one cluster"); labelFromSingularK(X); fitSummary.add(new Object[] { iter, converged, tss, // tss tss, // avg per cluster tss, // wss nan, // bss (none) timer.wallTime() }); sayBye(timer); return this; } /* * 2. Reassign each point to the cluster defined by the * closest medoid determined in the previous step. */ newMedoids = rassn.reassignedMedoidIdcs; /* * 2.5 Determine whether configuration changed */ boolean lastIteration = VecUtils.equalsExactly(newMedoids, medoid_indices); /* * 3. Update the costs */ converged = lastIteration || (convergedFromCost = FastMath.abs(wss_sum - bestCost) < tolerance); double tmp_wss_sum = rassn.new_clusters.total_cst; double tmp_bss = tss - tmp_wss_sum; // Check whether greater than max if (tmp_wss_sum > maxCost) maxCost = tmp_wss_sum; if (tmp_wss_sum < bestCost) { bestCost = wss_sum = tmp_wss_sum; labels = rassn.new_clusters.assn; // will be medoid idcs until encoded at end med_to_wss = rassn.new_clusters.costs; centroids = rassn.centers; medoid_indices = newMedoids; bss = tmp_bss; // get avg cost avgCost = wss_sum / (double) k; } if (converged) { reorderLabelsAndCentroids(); } /* * 3.5 If this is the last one, it'll show the wss and bss */ fitSummary.add(new Object[] { iter, converged, tss, avgCost, wss_sum, bss, timer.wallTime() }); iter++; configurationChanged = !converged; } if (!converged) warn("algorithm did not converge"); else info("algorithm converged due to " + (convergedFromCost ? "cost minimization" : "harmonious state")); // wrap things up, create summary.. sayBye(timer); return this; } }
From source file:com.clust4j.algo.NNHSTests.java
License:asdf
@Test public void testKernelDensitiesAndNorms() { /*//w w w. j a va 2 s . co m * These are the numbers the sklearn code produces (though numpy rounds up more than java) */ // Test where dist > h first double dist = 5.0, h = 1.3; assertTrue(PartialKernelDensity.LOG_GAUSSIAN.getDensity(dist, h) == -7.396449704142011); assertTrue(PartialKernelDensity.LOG_TOPHAT.getDensity(dist, h) == Double.NEGATIVE_INFINITY); assertTrue(PartialKernelDensity.LOG_EPANECHNIKOV.getDensity(dist, h) == Double.NEGATIVE_INFINITY); assertTrue(PartialKernelDensity.LOG_EXPONENTIAL.getDensity(dist, h) == -3.846153846153846); assertTrue(PartialKernelDensity.LOG_LINEAR.getDensity(dist, h) == Double.NEGATIVE_INFINITY); assertTrue(PartialKernelDensity.LOG_COSINE.getDensity(dist, h) == Double.NEGATIVE_INFINITY); // Test where dist < h second dist = 1.3; h = 5.0; assertTrue(PartialKernelDensity.LOG_GAUSSIAN.getDensity(dist, h) == -0.033800000000000004); assertTrue(PartialKernelDensity.LOG_TOPHAT.getDensity(dist, h) == 0.0); assertTrue(PartialKernelDensity.LOG_EPANECHNIKOV.getDensity(dist, h) == -0.06999337182053497); assertTrue(PartialKernelDensity.LOG_EXPONENTIAL.getDensity(dist, h) == -0.26); assertTrue(PartialKernelDensity.LOG_LINEAR.getDensity(dist, h) == -0.3011050927839216); assertTrue(PartialKernelDensity.LOG_COSINE.getDensity(dist, h) == -0.08582521637384073); /* * Now test Kernel norms... */ h = 1.3; int d = 5; assertTrue(NearestNeighborHeapSearch.logKernelNorm(h, d, PartialKernelDensity.LOG_GAUSSIAN) == -5.906513988360818); assertTrue(NearestNeighborHeapSearch.logKernelNorm(h, d, PartialKernelDensity.LOG_TOPHAT) == -2.972672434613881); assertTrue(NearestNeighborHeapSearch.logKernelNorm(h, d, PartialKernelDensity.LOG_EPANECHNIKOV) == -1.7199094661185133); assertTrue(NearestNeighborHeapSearch.logKernelNorm(h, d, PartialKernelDensity.LOG_EXPONENTIAL) == -7.760164177395928); assertTrue(NearestNeighborHeapSearch.logKernelNorm(h, d, PartialKernelDensity.LOG_LINEAR) == -1.1809129653858264); assertTrue(NearestNeighborHeapSearch.logKernelNorm(h, d, PartialKernelDensity.LOG_COSINE) == -1.588674327991151); }
From source file:com.rapidminer.gui.plotter.charts.DeviationChartPlotter.java
private int prepareData() { // calculate min and max int columns = this.dataTable.getNumberOfColumns(); double[] min = new double[columns]; double[] max = new double[columns]; for (int c = 0; c < columns; c++) { min[c] = Double.POSITIVE_INFINITY; max[c] = Double.NEGATIVE_INFINITY; }//from w ww. j a v a2 s .c o m synchronized (dataTable) { Iterator<DataTableRow> i = dataTable.iterator(); while (i.hasNext()) { DataTableRow row = i.next(); for (int c = 0; c < dataTable.getNumberOfColumns(); c++) { double value = row.getValue(c); min[c] = MathFunctions.robustMin(min[c], value); max[c] = MathFunctions.robustMax(max[c], value); } } } synchronized (dataTable) { this.dataset = new YIntervalSeriesCollection(); if (colorColumn >= 0 && dataTable.isNominal(colorColumn)) { for (int v = 0; v < dataTable.getNumberOfValues(colorColumn); v++) { String valueName = dataTable.mapIndex(colorColumn, v); YIntervalSeries series = new YIntervalSeries(valueName); boolean first = true; List<String> domainValues = new LinkedList<String>(); for (int column = 0; column < dataTable.getNumberOfColumns(); column++) { if (!dataTable.isSpecial(column) && column != colorColumn) { Iterator<DataTableRow> i = this.dataTable.iterator(); double sum = 0.0d; double squaredSum = 0.0d; int counter = 0; while (i.hasNext()) { DataTableRow row = i.next(); if (row.getValue(colorColumn) != v) { continue; } double value = row.getValue(column); sum += value; squaredSum += value * value; counter++; } double mean = sum / counter; double deviation = Math.sqrt(squaredSum / counter - mean * mean); if (isLocalNormalized()) { mean = (mean - min[column]) / (max[column] - min[column]); deviation = (deviation - min[column]) / (max[column] - min[column]); } series.add(column, mean, mean - deviation, mean + deviation); domainValues.add(dataTable.getColumnName(column)); } } if (first) { this.domainAxisMap = new String[domainValues.size()]; domainValues.toArray(this.domainAxisMap); } first = false; dataset.addSeries(series); } return dataTable.getNumberOfValues(colorColumn); } else { YIntervalSeries series = new YIntervalSeries(dataTable.getName()); List<String> domainValues = new LinkedList<String>(); for (int column = 0; column < dataTable.getNumberOfColumns(); column++) { if (!dataTable.isSpecial(column) && column != colorColumn) { Iterator<DataTableRow> i = this.dataTable.iterator(); double sum = 0.0d; double squaredSum = 0.0d; int counter = 0; while (i.hasNext()) { DataTableRow row = i.next(); double value = row.getValue(column); sum += value; squaredSum += value * value; counter++; } double mean = sum / counter; double deviation = Math.sqrt(squaredSum / counter - mean * mean); if (isLocalNormalized()) { mean = (mean - min[column]) / (max[column] - min[column]); // deviation = (deviation - min[column]) / (max[column] - min[column]); } series.add(column, mean, mean - deviation, mean + deviation); domainValues.add(dataTable.getColumnName(column)); } } dataset.addSeries(series); this.domainAxisMap = new String[domainValues.size()]; domainValues.toArray(this.domainAxisMap); return 0; } } }
From source file:ch.epfl.leb.sass.models.fluorophores.commands.internal.FluorophoreReceiverIT.java
/** * Test of generateFluorophoresRandom3D method, of class FluorophoreReceiver. *///from w ww. j av a2s .c o m @Test public void testGenerateFluorophoresRandom3D() { GenerateFluorophoresRandom3D.Builder fluorBuilder = new GenerateFluorophoresRandom3D.Builder(); fluorBuilder.numFluors(25); // Number of fluorophores fluorBuilder.zLow(0); fluorBuilder.zHigh(5.0); // Create the set of fluorophores. fluorBuilder.camera(camera).psfBuilder(psfBuilder).fluorDynamics(fluorDynamics).illumination(illumination); FluorophoreCommand fluorCommand = fluorBuilder.build(); List<Fluorophore> fluorophores = fluorCommand.generateFluorophores(); assertEquals(25, fluorophores.size()); double minZ = Double.POSITIVE_INFINITY; double maxZ = Double.NEGATIVE_INFINITY; for (Fluorophore f : fluorophores) { if (f.getZ() < minZ) minZ = f.getZ(); if (f.getZ() > maxZ) maxZ = f.getZ(); } assertTrue(maxZ <= 5.0); assertTrue(minZ >= 0.0); }
From source file:FibonacciHeap.java
/** * Deletes a node from the heap given the reference to the node. The trees * in the heap will be consolidated, if necessary. This operation may fail * to remove the correct element if there are nodes with key value * -Infinity./*www. jav a2s .c o m*/ * * <p>Running time: O(log n) amortized</p> * * @param x node to remove from heap */ public void delete(FibonacciHeapNode<T> x) { // make x as small as possible decreaseKey(x, Double.NEGATIVE_INFINITY); // remove the smallest, which decreases n also removeMin(); }
From source file:com.inform.jamps.solver.gurobi.GurobiVariable.java
@Override public String toString() { final StringBuilder sb = new StringBuilder(200); switch (type) { case BINARY:/*from w w w . jav a 2s .c o m*/ sb.append("Binary "); break; case CONTINUOUS: sb.append("Continuous "); break; case INTEGER: sb.append("Integer "); break; case SEMI_CONTINUOUS: sb.append("Semi-Continuous "); break; case SEMI_INTEGER: sb.append("Semi-Integer "); break; default: break; } sb.append(name); if (lowerBound > Double.NEGATIVE_INFINITY || upperBound < Double.POSITIVE_INFINITY) { if (Precision.equals(lowerBound, Double.NEGATIVE_INFINITY)) { sb.append(" (,"); } else { sb.append(" ["); sb.append(lowerBound); sb.append(','); } if (Precision.equals(upperBound, Double.POSITIVE_INFINITY)) { sb.append(')'); } else { sb.append(' '); sb.append(upperBound); sb.append(']'); } } else { sb.append(" (unbounded)"); } return sb.toString(); }
From source file:com.clust4j.algo.NearestNeighbors.java
@Override protected NearestNeighbors fit() { synchronized (fitLock) { if (null != res) return this; // CORNER! If k == m, we can't do kNeighbors + 1.. int nNeighbors = FastMath.min(kNeighbors + 1, m); //kNeighbors + 1; final LogTimer timer = new LogTimer(); // We can do parallel here! Neighborhood initRes = null;//from w w w .j a v a2s .c o m if (parallel) { try { initRes = ParallelNNSearch.doAll(fit_X, this, nNeighbors); } catch (RejectedExecutionException r) { warn("parallel neighborhood search failed; falling back to serial query"); } } // Gets here in serial mode or if parallel failed... if (null == initRes) initRes = new Neighborhood(tree.query(fit_X, nNeighbors, DUAL_TREE_SEARCH, SORT)); info("queried " + this.alg + " for nearest neighbors in " + timer.toString()); double[][] dists = initRes.getDistances(); int[][] indices = initRes.getIndices(); int i, j, ni = indices[0].length; // Set up sample range int[] sampleRange = VecUtils.arange(m); boolean allInRow, bval; boolean[] dupGroups = new boolean[m]; boolean[][] sampleMask = new boolean[m][ni]; for (i = 0; i < m; i++) { allInRow = true; for (j = 0; j < ni; j++) { bval = indices[i][j] != sampleRange[i]; sampleMask[i][j] = bval; allInRow &= bval; } dupGroups[i] = allInRow; // duplicates in row? } // Comment from SKLEARN: // Corner case: When the number of duplicates are more // than the number of neighbors, the first NN will not // be the sample, but a duplicate. // In that case mask the first duplicate. // sample_mask[:, 0][dup_gr_nbrs] = False for (i = 0; i < m; i++) if (dupGroups[i]) sampleMask[i][0] = false; // Build output indices int k = 0; int[] indOut = new int[m * (nNeighbors - 1)]; double[] distOut = new double[m * (nNeighbors - 1)]; for (i = 0; i < m; i++) { double minDist = Double.POSITIVE_INFINITY, maxDist = Double.NEGATIVE_INFINITY; for (j = 0; j < ni; j++) { if (sampleMask[i][j]) { indOut[k] = indices[i][j]; distOut[k] = dists[i][j]; minDist = FastMath.min(dists[i][j], minDist); maxDist = FastMath.max(dists[i][j], maxDist); k++; } } fitSummary.add(new Object[] { i, minDist, maxDist, timer.wallTime() }); } res = new Neighborhood(MatUtils.reshape(distOut, m, nNeighbors - 1), MatUtils.reshape(indOut, m, nNeighbors - 1)); sayBye(timer); return this; } }