Example usage for java.lang Math pow

List of usage examples for java.lang Math pow

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double pow(double a, double b) 

Source Link

Document

Returns the value of the first argument raised to the power of the second argument.

Usage

From source file:com.opengamma.analytics.financial.model.interestrate.curve.PriceIndexCurve.java

/**
 * Build a simple price index curve from known index and annual zero-coupon swap rates. The inflation coupon reference are exact month are not interpolated.
 * No seasonality is used. The price index are interpolated linearly.
 * @param nodeTimeKnown The time to the known price index. Those time will typically be negative (the price index are published after month end).
 * @param indexKnown The value of the known index. The first one in the list is the one used in the swaps used for curve construction.
 * @param nodeTimeOther The time to the price index reference for the swaps.
 * @param rate The zero-coupon swaps rates.
 * @return The price index curve.//from   w  ww.j av a 2  s  .  c  o  m
 */
public static PriceIndexCurve fromStartOfMonth(final double[] nodeTimeKnown, final double[] indexKnown,
        final double[] nodeTimeOther, final double[] rate) {
    final int nbNode = nodeTimeKnown.length + nodeTimeOther.length;
    final double[] nodeTime = new double[nbNode];
    System.arraycopy(nodeTimeKnown, 0, nodeTime, 0, nodeTimeKnown.length);
    System.arraycopy(nodeTimeOther, 0, nodeTime, nodeTimeKnown.length, nodeTimeOther.length);
    final double[] indexValue = new double[nbNode];
    System.arraycopy(indexKnown, 0, indexValue, 0, nodeTimeKnown.length);
    final double[] nbYear = new double[nodeTimeOther.length];
    for (int loopperiod = 0; loopperiod < nodeTimeOther.length; loopperiod++) {
        nbYear[loopperiod] = Math.round(nodeTimeOther[loopperiod] - nodeTimeKnown[0]);
        indexValue[nodeTimeKnown.length + loopperiod] = indexKnown[0]
                * Math.pow(1 + rate[loopperiod], nbYear[loopperiod]);
    }
    final InterpolatedDoublesCurve curve = InterpolatedDoublesCurve.from(nodeTime, indexValue,
            new LinearInterpolator1D());
    return new PriceIndexCurve(curve);
}

From source file:com.oculusinfo.binning.io.impl.ZipResourcePyramidSourceTest.java

@Test
public void test() {

    ZipArchiveOutputStream zos = null;//from  w w  w .  ja v  a  2s  .c o m
    File archive;
    String filename = "";
    try {
        archive = File.createTempFile("test.", ".zip", null);
        archive.deleteOnExit();
        filename = archive.getAbsolutePath();
        zos = new ZipArchiveOutputStream(archive);

        for (int z = 0; z < 3; z++) {
            for (int x = 0; x < Math.pow(2, z); x++) {
                for (int y = 0; y < Math.pow(2, z); y++) {
                    ZipArchiveEntry entry = new ZipArchiveEntry(getDummyFile(),
                            "test/tiles/" + z + "/" + x + "/" + y + ".dummy");
                    zos.putArchiveEntry(entry);
                }
            }
        }

        ZipArchiveEntry entry = new ZipArchiveEntry(getDummyFile(), "test/metadata.json");
        zos.putArchiveEntry(entry);

        zos.closeArchiveEntry();
        zos.close();
        zos = null;
    } catch (IOException e) {
        fail(e.getMessage());
    }

    try {
        ZipResourcePyramidSource src = new ZipResourcePyramidSource(filename, "dummy");

        TileIndex tileDef = new TileIndex(0, 0, 0, 1, 1);
        InputStream is = src.getSourceTileStream("test", tileDef);
        Assert.assertTrue(is != null);

        tileDef = new TileIndex(2, 3, 3, 1, 1);
        is = src.getSourceTileStream("test", tileDef);
        Assert.assertTrue(is != null);

        is = src.getSourceMetaDataStream("test");
        Assert.assertTrue(is != null);

    } catch (IOException e) {
        fail(e.getMessage());
    }

}

From source file:com.galenframework.specs.RangeValue.java

@Override
public String toString() {
    if (precision > 0) {
        int d = (int) Math.pow(10, precision);

        int firstPart = (int) Math.floor(value / d);
        int secondPart = Math.abs(value % d);

        StringBuilder builder = new StringBuilder();
        builder.append(Integer.toString(firstPart));
        builder.append('.');

        String digits = Integer.toString(secondPart);
        for (int i = digits.length(); i < precision; i++) {
            builder.append('0');
        }//from www . j a v a  2s.  c  o  m
        builder.append(digits);
        return builder.toString();
    } else {
        return Integer.toString(value);
    }
}

From source file:com.oculusinfo.binning.io.impl.ZipResourcePyramidStreamSourceTest.java

@Test
public void test() {

    ZipArchiveOutputStream zos = null;//from  w  ww  .  jav  a  2s .com
    File archive;
    String filename = "";
    try {
        archive = File.createTempFile("test.", ".zip", null);
        archive.deleteOnExit();
        filename = archive.getAbsolutePath();
        zos = new ZipArchiveOutputStream(archive);

        for (int z = 0; z < 3; z++) {
            for (int x = 0; x < Math.pow(2, z); x++) {
                for (int y = 0; y < Math.pow(2, z); y++) {
                    ZipArchiveEntry entry = new ZipArchiveEntry(getDummyFile(),
                            "test/tiles/" + z + "/" + x + "/" + y + ".dummy");
                    zos.putArchiveEntry(entry);
                }
            }
        }

        ZipArchiveEntry entry = new ZipArchiveEntry(getDummyFile(), "test/metadata.json");
        zos.putArchiveEntry(entry);

        zos.closeArchiveEntry();
        zos.close();
        zos = null;
    } catch (IOException e) {
        fail(e.getMessage());
    }

    try {
        ZipResourcePyramidStreamSource src = new ZipResourcePyramidStreamSource(filename, "dummy");

        TileIndex tileDef = new TileIndex(0, 0, 0, 1, 1);
        InputStream is = src.getTileStream("test", tileDef);
        Assert.assertTrue(is != null);

        tileDef = new TileIndex(2, 3, 3, 1, 1);
        is = src.getTileStream("test", tileDef);
        Assert.assertTrue(is != null);

        is = src.getMetaDataStream("test");
        Assert.assertTrue(is != null);

    } catch (IOException e) {
        fail(e.getMessage());
    }

}

From source file:com.davidbracewell.math.distribution.NormalDistribution.java

@Override
public double probability(double x) {
    return 1d / Math.sqrt(TWO_PI * var) * Math.exp(-Math.pow(x - mean, 2) / (2 * var));
}

From source file:br.upe.ecomp.doss.problem.movingpeaks.Peak.java

public double getFitness(double[] currentPosition) {
    double difference = 0;
    for (int i = 0; i < peakPosition.length; i++) {
        difference += Math.pow(currentPosition[i] - peakPosition[i], 2);
    }/* ww w. ja  v  a 2s .c o m*/
    return heigth / (1 + width * difference);
}

From source file:com.ibm.bi.dml.runtime.controlprogram.parfor.opt.CostFunction.java

/**
 * /*www. j  a  v a2 s.  com*/
 * @param in
 * @return
 */
public double estimate(double in) {
    double costs = 0;

    //compute the estimate for arbitrary orders of F
    if (_params != null)
        for (int i = 0; i < _params.length; i++) {
            //test
            double v1 = in;
            double v2 = Math.pow(in, i);
            if (i > 1 && Math.abs(Math.sqrt(v2) - v1) > 1.0) //issue if larger than 1ms or 1byte
            {
                LOG.error("Numerical stability issue: " + v1 + " vs " + v2);
                continue;
            }
            //end test

            costs += _params[i] * Math.pow(in, i);
        }

    costs = correctEstimate(costs);

    return costs;
}

From source file:com.sangupta.passcode.HashStream.java

public int generate(int n, int base, boolean inner) {
    int value = n;
    int k = (int) Math.ceil(Math.log(n) / Math.log(base));
    int r = (int) Math.pow(base, k) - n;

    while (value >= n) {
        List<Integer> chunk = this.shift(base, k);

        if (chunk == null) {
            return inner ? n : 0;
        }//from w w  w .j  a  va  2s  .co  m

        value = this.evaluate(chunk, base);
        if (value >= n) {
            if (r == 1d) {
                continue;
            }

            this.push(r, value - n);
            value = this.generate(n, r, true);
        }
    }

    return value;
}

From source file:amplify.NTPClient.java

/**
 * Process <code>TimeInfo</code> object and print its details.
 *
 * @param info <code>TimeInfo</code> object.
 *//* www . ja v a  2  s . c  o  m*/
public static void processResponse(TimeInfo info) {
    NtpV3Packet message = info.getMessage();
    int stratum = message.getStratum();
    String refType;
    if (stratum <= 0)
        refType = "(Unspecified or Unavailable)";
    else if (stratum == 1)
        refType = "(Primary Reference; e.g., GPS)"; // GPS, radio clock, etc.
    else
        refType = "(Secondary Reference; e.g. via NTP or SNTP)";
    // stratum should be 0..15...
    System.out.println(" Stratum: " + stratum + " " + refType);
    int version = message.getVersion();
    int li = message.getLeapIndicator();
    System.out.println(" leap=" + li + ", version=" + version + ", precision=" + message.getPrecision());

    System.out.println(" mode: " + message.getModeName() + " (" + message.getMode() + ")");
    int poll = message.getPoll();
    // poll value typically btwn MINPOLL (4) and MAXPOLL (14)
    System.out.println(
            " poll: " + (poll <= 0 ? 1 : (int) Math.pow(2, poll)) + " seconds" + " (2 ** " + poll + ")");
    double disp = message.getRootDispersionInMillisDouble();
    System.out.println(" rootdelay=" + numberFormat.format(message.getRootDelayInMillisDouble())
            + ", rootdispersion(ms): " + numberFormat.format(disp));

    int refId = message.getReferenceId();
    String refAddr = NtpUtils.getHostAddress(refId);
    String refName = null;
    if (refId != 0) {
        if (refAddr.equals("127.127.1.0")) {
            refName = "LOCAL"; // This is the ref address for the Local Clock
        } else if (stratum >= 2) {
            // If reference id has 127.127 prefix then it uses its own reference clock
            // defined in the form 127.127.clock-type.unit-num (e.g. 127.127.8.0 mode 5
            // for GENERIC DCF77 AM; see refclock.htm from the NTP software distribution.
            if (!refAddr.startsWith("127.127")) {
                try {
                    InetAddress addr = InetAddress.getByName(refAddr);
                    String name = addr.getHostName();
                    if (name != null && !name.equals(refAddr))
                        refName = name;
                } catch (UnknownHostException e) {
                    // some stratum-2 servers sync to ref clock device but fudge stratum level higher... (e.g. 2)
                    // ref not valid host maybe it's a reference clock name?
                    // otherwise just show the ref IP address.
                    refName = NtpUtils.getReferenceClock(message);
                }
            }
        } else if (version >= 3 && (stratum == 0 || stratum == 1)) {
            refName = NtpUtils.getReferenceClock(message);
            // refname usually have at least 3 characters (e.g. GPS, WWV, LCL, etc.)
        }
        // otherwise give up on naming the beast...
    }
    if (refName != null && refName.length() > 1)
        refAddr += " (" + refName + ")";

    TimeStamp refNtpTime = message.getReferenceTimeStamp();

    // Originate Time is time request sent by client (t1)
    TimeStamp origNtpTime = message.getOriginateTimeStamp();

    long destTime = info.getReturnTime();
    long localDestTime = System.currentTimeMillis();

    // Receive Time is time request received by server (t2)
    TimeStamp rcvNtpTime = message.getReceiveTimeStamp();

    // Transmit time is time reply sent by server (t3)
    TimeStamp xmitNtpTime = message.getTransmitTimeStamp();

    // Destination time is time reply received by client (t4)
    TimeStamp destNtpTime = TimeStamp.getNtpTime(destTime);

    info.computeDetails(); // compute offset/delay if not already done
    Long offsetValue = info.getOffset();
    Long delayValue = info.getDelay();
    String delay = (delayValue == null) ? "N/A" : delayValue.toString();
    String offset = (offsetValue == null) ? "N/A" : offsetValue.toString();
    clockOffset = offsetValue != null ? offsetValue.longValue() : 0L;

    System.out.println(" Reference Identifier:\t" + refAddr);
    System.out.println(" Reference Timestamp:\t" + refNtpTime + "  " + refNtpTime.toDateString());
    System.out.println(" Originate Timestamp:\t" + origNtpTime + "  " + origNtpTime.toDateString());
    System.out.println(" Receive Timestamp:\t" + rcvNtpTime + "  " + rcvNtpTime.toDateString());
    System.out.println(" Transmit Timestamp:\t" + xmitNtpTime + "  " + xmitNtpTime.toDateString());
    System.out.println(" Destination Timestamp:\t" + destNtpTime + "  " + destNtpTime.toDateString());
    System.out.println(" Roundtrip delay(ms)=" + delay + ", clock offset(ms)=" + offset); // offset in ms
}

From source file:com.mapr.synth.samplers.ForeignKeySampler.java

private void setup() {
    base = new Multinomial<>();
    for (int i = 0; i < size; i++) {
        base.add(i, Math.pow(i + 1.0, -skew));
    }/*ww w  .j a v a2 s .  c  o m*/
}