Example usage for java.lang Math floor

List of usage examples for java.lang Math floor

Introduction

In this page you can find the example usage for java.lang Math floor.

Prototype

public static double floor(double a) 

Source Link

Document

Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.

Usage

From source file:edu.msu.cme.rdp.readseq.utils.ResampleSeqFile.java

public static void selectOne(File infile, int num_of_seqs, int subregion_length, File outfile)
        throws IOException {

    IndexedSeqReader reader = new IndexedSeqReader(infile);
    PrintStream out = new PrintStream(new FileOutputStream(outfile));
    Object[] seqIdSet = reader.getSeqIdSet().toArray();
    HashSet<Integer> selectedIndexSet = randomSelectIndices(seqIdSet, num_of_seqs);
    // get the  seq
    Sequence seq;//w  w  w . j av a 2  s  . c  o  m
    if (subregion_length == 0) {
        for (int index : selectedIndexSet) {
            seq = reader.readSeq((String) seqIdSet[index]);
            out.println(">" + seqIdSet[index] + "\t" + seq.getDesc() + "\n" + seq.getSeqString());
        }
    } else {
        for (int index : selectedIndexSet) {
            seq = reader.readSeq((String) seqIdSet[index]);
            if (seq.getSeqString().length() >= subregion_length) {
                int rdmIndex = (int) (Math
                        .floor(Math.random() * (seq.getSeqString().length() - subregion_length)));
                out.println(">" + seqIdSet[index] + "\t" + seq.getDesc() + "\n"
                        + seq.getSeqString().substring(rdmIndex, (rdmIndex + subregion_length)));
            }
        }
    }

    reader.close();
    out.close();
}

From source file:datafu.pig.hash.lsh.p_stable.AbstractStableDistributionFunction.java

/**
 * Compute the LSH for a given vector.//w w  w . ja  va  2s . c  om
 */
public long apply(RealVector vector) {
    /*
     * The hash is just floor(<v, a>/w)
     */
    double ret = b;

    for (int i = 0; i < dim; ++i) {
        ret += vector.getEntry(i) * a[i];
    }
    return (long) Math.floor(ret / w);
}

From source file:etymology.util.EtyMath.java

public static double avgLnGamma(double value) {
    int floor = (int) Math.floor(value);
    double diff = Math.abs(value - floor);
    if (diff <= 0.01) {
        return lnFactorial(floor - 1);
    }// ww w  .j av  a 2 s .c  o  m

    int ceil = (int) Math.ceil(value);
    diff = Math.abs(ceil - value);
    if (diff <= 0.01) {
        return lnFactorial(ceil - 1);
    }

    double logFactCeil = lnFactorial(ceil);
    double logFactFloor = lnFactorial(floor);
    double overFloor = value - floor;
    return (overFloor * logFactFloor) + (1 - overFloor) * logFactCeil;
}

From source file:no.met.jtimeseries.marinogram.MarinogramWindPlot.java

private XYPlot createPlot(TimeZone timezone, boolean plotWindDirection, boolean plotWindSpeed) {
    ChartPlotter plotter = new ChartPlotter();
    // default setting
    plotter.setHeight(this.getHeight());
    plotter.setWidth(this.getWidth());
    plotter.setPlotDefaultProperties("", "");
    Color windSpeedColor = new Color(0, 0, 0);
    Color windDirectionColor = new Color(0, 0, 0);
    // plot style
    PlotStyle.Builder currentStyleBuilder = new PlotStyle.Builder("Wind");
    PlotStyle plotStyle;/*from  ww  w .ja  va 2 s  .c o  m*/
    NumberPhenomenon windDirection = getLocationForecastDataModel()
            .getPhenomenen(PhenomenonName.WindDirectionDegree.toString(), NumberPhenomenon.class);
    NumberPhenomenon windSpeed = getLocationForecastDataModel()
            .getPhenomenen(PhenomenonName.WindSpeedMPS.toString(), NumberPhenomenon.class);
    if (windSpeed == null || windDirection == null) {
        return null;
    }

    double tick = (windSpeed.getMaxValue() - windSpeed.getMinValue()) / 3;
    tick = Math.ceil(tick);
    double lowBound = Math.floor(windSpeed.getMinValue() / (tick)) * (tick);
    //The minimum scale is 0
    lowBound = lowBound < 0 ? 0 : lowBound;
    lowBound = lowBound - tick / 2;
    double upperBound = lowBound + tick * 6;

    // reference the range axis
    NumberAxis leftNumberAxis = new NumberAxis();
    leftNumberAxis.setLabel(messages.getString("parameter.wind") + " (m/s)");
    leftNumberAxis.setLabelPaint(windSpeedColor);
    leftNumberAxis.setTickLabelPaint(windSpeedColor);
    //int tickUnit = (int) Math.ceil((upperBound - lowBound) / 6);
    leftNumberAxis.setTickUnit(new NumberTickUnit(tick));
    leftNumberAxis.setLowerBound(lowBound);
    leftNumberAxis.setUpperBound(upperBound);

    NumberAxis rightNumberAxis = new NumberAxis();
    rightNumberAxis.setLabel(messages.getString("label.knots"));
    rightNumberAxis.setLabelPaint(windSpeedColor);
    rightNumberAxis.setTickLabelPaint(windSpeedColor);
    lowBound = lowBound / KNOT;
    upperBound = upperBound / KNOT;
    rightNumberAxis.setLowerBound(lowBound);
    rightNumberAxis.setUpperBound(upperBound);
    rightNumberAxis.setTickUnit(new NumberTickUnit(tick / KNOT));
    NumberFormat formatter = new DecimalFormat("#0.0");
    rightNumberAxis.setNumberFormatOverride(formatter);

    List<Date> shortTermTimeList = this.getShortTermTime(windDirection.getTime().get(0));

    // set thte plot current speed color to be transparent if show current
    // speed is false
    if (!plotWindSpeed) {
        windSpeedColor = new Color(0, 0, 0, 0);
    }

    // plot style
    plotStyle = currentStyleBuilder.spline(SplineStyle.HYBRID).stroke(new BasicStroke(2.0f))
            .seriesColor(windSpeedColor).numberAxis(leftNumberAxis).nonNegative(true).build();

    // Draw the current direction even if plotCurrentSpeed is false (but
    // with transparent in such a case)
    // for the purpose to keep the same background grid and tick label on
    // the y-axis
    // no matter the wave height is shown or not
    plotter.addLineChart(TimeBase.SECOND, windSpeed, plotStyle);

    plotter.getPlot().setRangeAxis(1, rightNumberAxis);
    plotter.getPlot().setOutlineVisible(true);

    Date minDate = shortTermTimeList.get(0);
    Date maxDate = shortTermTimeList.get(shortTermTimeList.size() - 1);
    plotter.setDomainRange(minDate, maxDate);
    plotter.setDomainDateFormat(timezone, "HH");
    // set domain range after (must) plot all the data
    plotter.addHourBasedDomainGridLines();
    // invisible domain axis
    plotter.getPlot().getDomainAxis().setTickLabelsVisible(false);
    // add markers
    plotter.addDomainMarkers(shortTermTimeList, timezone, locale);

    if (plotWindDirection) {
        List<Date> symbolTimes = Utility.filterMinimumHourInterval(windDirection.getTime(), 2, 1);
        InListFromDateFilter symbolTimesFilter = new InListFromDateFilter(symbolTimes);
        windDirection.filter(symbolTimesFilter);
        windSpeed = null;
        if (plotWindSpeed) {
            windSpeed = getLocationForecastDataModel().getPhenomenen(PhenomenonName.WindSpeedMPS.toString(),
                    NumberPhenomenon.class);
            windSpeed.filter(symbolTimesFilter);
            windSpeed = windSpeed.scaling(1 / KNOT);
        }

        plotStyle = currentStyleBuilder.seriesColor(windDirectionColor).build();
        // when plot wind direction, the arrow should be rotated 180 degree
        windDirection = windDirection.transform(180);
        plotter.addArrowDirectionPlot(windDirection, windSpeed, 2, plotStyle);
        // transform back after plot
        windDirection = windDirection.transform(180);
    }
    plotter.getPlot().setRangeZeroBaselineVisible(false);

    return plotter.getPlot();

}

From source file:classes.MyVisitor.java

public boolean isInt(Double variable) {
    if ((variable == Math.floor(variable)) && !Double.isInfinite(variable)) {
        return true;
    }//from   ww w .j a v a 2 s . co m
    return false;
}

From source file:com.hm.cal.date.JulianDay.java

/**
 * Returns this Julian Day set to midnight.
 *
 * @return This Julian Day at midnight./*  w  ww.j ava 2 s  .co m*/
 */
public JulianDay atMidnight() {
    return new JulianDay(Math.floor(_jday - 0.5) + 0.5);
}

From source file:cat.tv3.eng.rec.recomana.lupa.visualization.ClustersToJson.java

public static double truncate(double value, int places) {
    double multiplier = Math.pow(10, places);
    return Math.floor(multiplier * value) / multiplier;
}

From source file:com.comphenix.xp.SampleRange.java

private int sampleIntReduced(Random rnd) {
    double value = sampleDouble(rnd);

    // Probability of adding the fraction
    double fraction = value - Math.floor(value);
    double toAdd = rnd.nextDouble() < fraction ? Math.signum(value) : 0;

    return (int) value + (int) toAdd;
}

From source file:gdsc.smlm.ij.plugins.LoadLocalisations.java

private boolean getZDepth(List<LocalisationModel> localisations) {
    double min = localisations.get(0).getZ();
    double max = min;
    for (LocalisationModel l : localisations) {
        if (min > l.getZ())
            min = l.getZ();//w w  w  .j  a  v  a  2  s.com
        if (max < l.getZ())
            max = l.getZ();
    }

    maxz = FastMath.min(maxz, max);
    minz = FastMath.max(minz, min);

    String msg = String.format("%d localisations with %.2f <= z <= %.2f", localisations.size(), min, max);

    min = Math.floor(min);
    max = Math.ceil(max);

    GenericDialog gd = new GenericDialog(TITLE);
    gd.addMessage(msg);
    gd.addCheckbox("Limit Z-depth", limitZ);
    gd.addSlider("minZ", min, max, minz);
    gd.addSlider("maxZ", min, max, maxz);
    gd.showDialog();
    if (gd.wasCanceled() || gd.invalidNumber()) {
        return false;
    }
    limitZ = gd.getNextBoolean();
    minz = gd.getNextNumber();
    maxz = gd.getNextNumber();
    return true;
}

From source file:edu.pitt.csb.stability.StabilitySearch.java

/**
 * Constructor using default subsize and numsubs from huge package in R
 *
 * @param data//from w  ww .  j av a 2  s  .c  o  m
 * @param gs
 */
public StabilitySearch(DataSet data, DataGraphSearch gs) {
    this.data = data;
    this.gs = gs;
    this.numSamps = data.getNumRows();
    this.numSubs = 20;
    this.numVars = data.getNumColumns();
    this.subSize = (int) Math.floor(.8 * numSamps);
    if (numSamps > 144)
        subSize = (int) Math.floor(10.0 * Math.sqrt(numSamps));
    this.cpss = false;

    this.samps = subSampleNoReplacement(false);//numSamps, numSubs, subSize);
    this.thetaMat = DoubleFactory2D.dense.make(numVars, numVars, 0.0);
    //this(data, gs, 20, subSize);
}