List of usage examples for java.lang Math floor
public static double floor(double a)
From source file:org.nabucco.alfresco.enhScriptEnv.common.script.converter.general.NumberConverter.java
protected Object convertNumber(final Object value, final Class<?> expectedClass) { if (!(value instanceof Number)) { throw new IllegalArgumentException("value must be a " + Number.class); }//from w w w .j a v a2 s. c o m final Number resultNumber; if (expectedClass.isAssignableFrom(Number.class)) { final double doubleValue = ((Number) value).doubleValue(); if (doubleValue == Math.floor(doubleValue)) { resultNumber = Long.valueOf(Math.round(Math.floor(doubleValue))); } else { resultNumber = Double.valueOf(doubleValue); } } else if (Integer.class.equals(expectedClass) || int.class.equals(expectedClass)) { resultNumber = Integer.valueOf(((Number) value).intValue()); } else if (Long.class.equals(expectedClass) || long.class.equals(expectedClass)) { resultNumber = Long.valueOf(((Number) value).longValue()); } else if (Float.class.equals(expectedClass) || float.class.equals(expectedClass)) { resultNumber = Float.valueOf(((Number) value).floatValue()); } else if (Double.class.equals(expectedClass) || double.class.equals(expectedClass)) { resultNumber = Double.valueOf(((Number) value).doubleValue()); } else if (Byte.class.equals(expectedClass) || byte.class.equals(expectedClass)) { resultNumber = Byte.valueOf(((Number) value).byteValue()); } else { resultNumber = Short.valueOf(((Number) value).shortValue()); } return resultNumber; }
From source file:es.udc.gii.common.eaf.algorithm.operator.reproduction.mutation.de.mutationStrategy.CurrentToPBestMutationStrategy.java
@Override public Individual getMutatedIndividual(EvolutionaryAlgorithm algorithm, Individual target) { BestIndividualSpecification bestSpec = new BestIndividualSpecification(); List<Individual> individuals, best_p_individuals, listInd; List<Integer> index_list; Individual best_p;/*from w ww . j av a 2 s . co m*/ double[] base; int n, random_p_pos, randomPos; double auxGeneValue, x1, x2, x3, x4; double F; individuals = new ArrayList<>(); individuals.addAll(algorithm.getPopulation().getIndividuals()); //Si hay archivo y no est creado se crea: if (this.archive && algorithm.getPopulation().getArchive() == null) { algorithm.getPopulation().setArchive(new ArrayList<Individual>()); } //Si hay archivo --> se aaden los elementos del archivo: if (this.archive) { individuals.addAll(algorithm.getPopulation().getArchive()); } base = ((Individual) target).getChromosomeAt(0); //Se escoge x_p_best = un aleatorio de los 100*p% individuos de la poblacion: n = (int) (this.p * individuals.size()); best_p_individuals = bestSpec.get(individuals, n, algorithm.getComparator()); random_p_pos = (int) Math.floor(EAFRandom.nextDouble() * best_p_individuals.size()); best_p = best_p_individuals.get(random_p_pos); F = this.getFPlugin().get(algorithm); //se eligen los vectores diferenciales: listInd = new ArrayList<>(); index_list = new ArrayList<>(); index_list.add(individuals.indexOf(target)); for (int i = 0; i < this.getDiffVector() * 2; i++) { do { //Si es una posicin par 0, 2, ... es decir, el primer elemento de la resta, //Se elige de la posicin de individuos de la poblacin sin archivo: if (!archive || i % 2 == 0) { randomPos = EAFRandom.nextInt(algorithm.getPopulation().getSize()); } else { randomPos = EAFRandom.nextInt(individuals.size()); } } while (index_list.contains(randomPos)); listInd.add(individuals.get(randomPos)); index_list.add(randomPos); } if (base != null) { //Recorremos el numero de genes: for (int i = 0; i < base.length; i++) { auxGeneValue = base[i]; for (int j = 0; j < this.getDiffVector(); j += 2) { x1 = listInd.get(j).getChromosomeAt(0)[i]; x2 = listInd.get(j + 1).getChromosomeAt(0)[i]; auxGeneValue += F * (x1 - x2); } x3 = best_p.getChromosomeAt(0)[i]; x4 = base[i]; auxGeneValue += F * (x3 - x4); base[i] = auxGeneValue; } } Individual mutatedIndividual = new Individual(); mutatedIndividual.setChromosomeAt(0, base); return mutatedIndividual; }
From source file:org.adempiere.webui.apps.graph.WPerformanceIndicator.java
private JFreeChart createChart() { JFreeChart chart = null;//from w ww .jav a 2 s . co m // Set Text StringBuffer text = new StringBuffer(m_goal.getName()); if (m_goal.isTarget()) text.append(": ").append(m_goal.getPercent()).append("%"); else text.append(": ").append(s_format.format(m_goal.getMeasureActual())); m_text = text.toString(); // ToolTip text = new StringBuffer(); if (m_goal.getDescription() != null) text.append(m_goal.getDescription()).append(": "); text.append(s_format.format(m_goal.getMeasureActual())); if (m_goal.isTarget()) text.append(" ").append(Msg.getMsg(Env.getCtx(), "of")).append(" ") .append(s_format.format(m_goal.getMeasureTarget())); setTooltiptext(text.toString()); // DefaultValueDataset data = new DefaultValueDataset((float) m_goal.getPercent()); MeterPlot plot = new MeterPlot(data); MColorSchema colorSchema = m_goal.getColorSchema(); int rangeLo = 0; int rangeHi = 0; for (int i = 1; i <= 4; i++) { switch (i) { case 1: rangeHi = colorSchema.getMark1Percent(); break; case 2: rangeHi = colorSchema.getMark2Percent(); break; case 3: rangeHi = colorSchema.getMark3Percent(); break; case 4: rangeHi = colorSchema.getMark4Percent(); break; } if (rangeHi == 9999) rangeHi = (int) Math.floor(rangeLo * 1.5); if (rangeLo < rangeHi) { plot.addInterval(new MeterInterval("Normal", //label new Range(rangeLo, rangeHi), //range colorSchema.getColor(rangeHi), new BasicStroke(7.0f), new Color(-13091716))); rangeLo = rangeHi; } } plot.setRange(new Range(0, rangeLo)); plot.setDialBackgroundPaint(new Color(-13091716)); plot.setUnits(""); plot.setDialShape(DialShape.CHORD);//CIRCLE); plot.setNeedlePaint(Color.white); plot.setTickSize(2000); plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 8)); plot.setValueFont(new Font("SansSerif", Font.BOLD, 8)); plot.setNoDataMessageFont(new Font("SansSerif", Font.BOLD, 8)); plot.setTickLabelPaint(Color.white); plot.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); chart = new JFreeChart(m_text, new Font("SansSerif", Font.BOLD, 9), plot, false); return chart; }
From source file:edu.harvard.iq.dataverse.util.SumStatCalculator.java
private static double calculateMedian(double[] values) { double[] sorted = new double[values.length]; System.arraycopy(values, 0, sorted, 0, values.length); logger.fine("made an extra copy of the vector;"); Arrays.sort(sorted);//ww w . j av a2 s . com logger.fine("sorted double vector for median calculations;"); if (sorted.length == 0) { return Double.NaN; } if (sorted.length == 1) { return sorted[0]; // always return single value for n = 1 } double n = sorted.length; double pos = (n + 1) / 2; double fpos = Math.floor(pos); int intPos = (int) fpos; double dif = pos - fpos; double lower = sorted[intPos - 1]; double upper = sorted[intPos]; return lower + dif * (upper - lower); }
From source file:es.udc.gii.common.eaf.benchmark.multiobjective.wfg.Wfg_Objective.java
protected double s_decept(double y, double A, double B, double C) { double tmp1 = Math.floor(y - A + B) * (1.0 - C + (A - B) / B) / (A - B); double tmp2 = Math.floor(A + B - y) * (1.0 - C + (1.0 - A - B) / B) / (1.0 - A - B); return correct_to_01(1.0 + (Math.abs(y - A) - B) * (tmp1 + tmp2 + 1.0 / B), EPSILON); }
From source file:gdsc.smlm.ij.results.PSFImagePeakResults.java
private void addPeak(int peak, int origX, int origY, float origValue, double chiSquared, float noise, float[] params, float[] paramsDev) { float x = (params[3] - bounds.x) * scale; float y = (params[4] - bounds.y) * scale; // Check bounds if (x < 0 || x > xlimit || y < 0 || y > ylimit) return;/* w w w . j av a2s .co m*/ checkAndUpdateToFrame(peak); // Initialise for a free Gaussian function: // f(x,y) = A exp(-(a(x-x0)(x-x0) + 2b(x-x0)(y-y0) + c(y-y0)(y-y0))) // See: http://en.wikipedia.org/wiki/Gaussian_function#Two-dimensional_Gaussian_function final float amplitude = ((displayFlags & DISPLAY_SIGNAL) != 0) ? PeakResult.getAmplitude(params) : 1; final double[] psfParams; if (fixedWidth) { psfParams = fixedParams; } else { // Precalculate multiplication factors final double t, sx, sy; if (calculatedPrecision && nmPerPixel > 0) { t = 0.0; final double N = params[Gaussian2DFunction.SIGNAL] / gain; final double s = (params[Gaussian2DFunction.X_SD] + params[Gaussian2DFunction.Y_SD]) * 0.5 * nmPerPixel; final double precision = PeakResult.getPrecision(nmPerPixel, s, N, noise / gain, emCCD); sx = sy = (precision / nmPerPixel); } else { t = params[Gaussian2DFunction.ANGLE]; sx = params[Gaussian2DFunction.X_SD]; sy = params[Gaussian2DFunction.Y_SD]; } psfParams = setPSFParameters(t, sx, sy, new double[5]); } final double a = psfParams[0]; final double b = psfParams[1]; final double c = psfParams[2]; final double width = psfParams[3]; final double height = psfParams[4]; // Use 0.5 offset to centre the value in the middle of each pixel x -= 0.5 / scale; y -= 0.5 / scale; int xmin = (int) Math.floor(x - width * scale); int xmax = (int) Math.ceil(x + width * scale); int ymin = (int) Math.floor(y - height * scale); int ymax = (int) Math.ceil(y + height * scale); // Clip range xmin = FastMath.max(xmin, 0); xmax = (int) FastMath.min(xmax, xlimit); ymin = FastMath.max(ymin, 0); ymax = (int) FastMath.min(ymax, ylimit); // Compute Gaussian PSF final int[] index = new int[(xmax - xmin + 1) * (ymax - ymin + 1)]; final float[] value = new float[index.length]; int i = 0; for (int y0 = ymin; y0 <= ymax; y0++) for (int x0 = xmin; x0 <= xmax; x0++) { int ii = y0 * imageWidth + x0; index[i] = ii; final float dx = (x0 - x) / scale; final float dy = (y0 - y) / scale; value[i] = (float) (amplitude * FastMath.exp(a * dx * dx + b * dx * dy + c * dy * dy)); i++; } // Now add the values to the configured indices synchronized (data) { size++; while (i-- > 0) { data[index[i]] += value[i]; } } }
From source file:eu.matejkormuth.rpgdavid.starving.Region.java
public int getMinXFloor() { return (int) Math.floor(this.minVector.getX()); }
From source file:com.rapidminer.gui.viewer.metadata.model.DateTimeAttributeStatisticsModel.java
@Override public void updateStatistics(final ExampleSet exampleSet) { final String days = WHITESPACE + I18N.getMessage(I18N.getGUIBundle(), "gui.label.attribute_statistics.statistics.days.label"); final String hours = WHITESPACE + I18N.getMessage(I18N.getGUIBundle(), "gui.label.attribute_statistics.statistics.hours.label"); long minMilliseconds = (long) exampleSet.getStatistics(getAttribute(), Statistics.MINIMUM); long maxMilliseconds = (long) exampleSet.getStatistics(getAttribute(), Statistics.MAXIMUM); long difference = maxMilliseconds - minMilliseconds; String dura = ""; if (getAttribute().getValueType() == Ontology.DATE) { // days/* www .j a v a 2 s . c o m*/ dura += com.rapidminer.tools.Tools.formatIntegerIfPossible( Math.floor(difference / (H_IN_D * M_IN_H * S_IN_M * MS_IN_S)), 3) + days; } else if (getAttribute().getValueType() == Ontology.TIME) { // hours dura += com.rapidminer.tools.Tools .formatIntegerIfPossible(Math.floor(difference / (M_IN_H * S_IN_M * MS_IN_S)), 3) + hours; } else if (getAttribute().getValueType() == Ontology.DATE_TIME) { // days + hours + minutes + seconds dura += com.rapidminer.tools.Tools.formatIntegerIfPossible( Math.floor(difference / (H_IN_D * M_IN_H * S_IN_M * MS_IN_S)), 3) + SHORT_DAY; dura += WHITESPACE; double leftoverMilliSeconds = difference % (H_IN_D * M_IN_H * S_IN_M * MS_IN_S); dura += com.rapidminer.tools.Tools.formatIntegerIfPossible( Math.floor(leftoverMilliSeconds / (M_IN_H * S_IN_M * MS_IN_S)), 3) + SHORT_HOUR; dura += WHITESPACE; leftoverMilliSeconds = leftoverMilliSeconds % (M_IN_H * S_IN_M * MS_IN_S); dura += com.rapidminer.tools.Tools.formatIntegerIfPossible( Math.floor(leftoverMilliSeconds / (S_IN_M * MS_IN_S)), 3) + SHORT_MINUTE; dura += WHITESPACE; leftoverMilliSeconds = leftoverMilliSeconds % (S_IN_M * MS_IN_S); dura += com.rapidminer.tools.Tools.formatIntegerIfPossible(Math.floor(leftoverMilliSeconds / MS_IN_S), 3) + SHORT_SECOND; } String minResult = null; String maxResult = null; if (getAttribute().getValueType() == Ontology.DATE) { minResult = FORMAT_DATE.format(new Date(minMilliseconds)); maxResult = FORMAT_DATE.format(new Date(maxMilliseconds)); } else if (getAttribute().getValueType() == Ontology.TIME) { minResult = FORMAT_TIME.format(new Date(minMilliseconds)); maxResult = FORMAT_TIME.format(new Date(maxMilliseconds)); } else if (getAttribute().getValueType() == Ontology.DATE_TIME) { minResult = FORMAT_DATE_TIME.format(new Date(minMilliseconds)); maxResult = FORMAT_DATE_TIME.format(new Date(maxMilliseconds)); } missing = exampleSet.getStatistics(getAttribute(), Statistics.UNKNOWN); from = minResult; until = maxResult; duration = dura; fireStatisticsChangedEvent(); }
From source file:com.twitter.graphjet.bipartite.edgepool.PowerLawDegreeEdgePoolTest.java
@Test public void testGetPoolForEdgeNumber() throws Exception { assertEquals(0, PowerLawDegreeEdgePool.getPoolForEdgeNumber(0)); assertEquals(0, PowerLawDegreeEdgePool.getPoolForEdgeNumber(1)); assertEquals(1, PowerLawDegreeEdgePool.getPoolForEdgeNumber(2)); for (int i = 0; i < 1000; i++) { assertEquals((int) Math.floor(Math.log(i + 2) / Math.log(2.0) - 1.0), PowerLawDegreeEdgePool.getPoolForEdgeNumber(i)); }/*from ww w.j av a2 s. c o m*/ }