Example usage for java.lang Math PI

List of usage examples for java.lang Math PI

Introduction

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

Prototype

double PI

To view the source code for java.lang Math PI.

Click Source Link

Document

The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.

Usage

From source file:com.opengamma.analytics.financial.model.option.pricing.fourier.FFTModelGreeks.java

/**
 * //from  ww w  . ja  v a 2  s .c o  m
  * @param forward The forward value of the underlying
  * @param discountFactor 
  * @param t Time to expiry
  * @param isCall true for call 
  * @param ce The Characteristic Exponent (log of characteristic function) of the returns of the underlying
  * @param lowestStrike The lowest strike to return (the actual value will depend on the set up, but is guaranteed to be less than this) 
  * @param highestStrike The highest strike to return (the actual value will depend on the set up, but is guaranteed to be greater than this) 
  * @param minStrikesDisplayed minimum number of strikes returned (actual number depends on set up) 
  * @param limitSigma An estimate of the implied vol used to calculate limits in the numerical routines 
  * @param alpha Regularization factor. Values of 0 or -1 are not allowed. -0.5 is recommended  
  * @param tol Tolerance - smaller values give higher accuracy 
 * @return an array of arrays where is first array is the strikes, the second the prices, the first the derivatives of price wrt the first parameter etc 
 */
//TODO this is cut and paste from FFTPricer - the calculation of the sample size and spacing should be extracted 
public double[][] getGreeks(final double forward, final double discountFactor, final double t,
        final boolean isCall, final MartingaleCharacteristicExponent ce, final double lowestStrike,
        final double highestStrike, final int minStrikesDisplayed, final double limitSigma, final double alpha,
        final double tol) {

    Validate.notNull(ce, "characteristic exponent");
    Validate.isTrue(tol > 0.0, "need tol > 0");
    Validate.isTrue(alpha != 0.0 && alpha != -1.0, "alpha cannot be -1 or 0");

    Validate.isTrue(lowestStrike <= forward, "need lowestStrike <= forward");
    Validate.isTrue(highestStrike >= forward, "need highestStrike >= forward");
    Validate.isTrue(limitSigma > 0.0, "need limitSigma > 0");

    double kMax;
    final double limitSigmaRootT = limitSigma * Math.sqrt(t);
    final double atm = NORMAL.getCDF(limitSigmaRootT / 2.0);

    if (alpha > 0) {
        kMax = -Math.log((2 * atm - 1) * tol) / alpha;
    } else if (alpha < -1.0) {
        kMax = Math.log((2 * atm - 1) * tol) / (1 + alpha);
    } else {
        kMax = -Math.log(2 * (1 - atm) * tol) * Math.max(-1.0 / alpha, 1 / (1 + alpha));
    }

    final EuropeanCallFourierTransform psi = new EuropeanCallFourierTransform(ce);
    final Function1D<ComplexNumber, ComplexNumber> psiFunction = psi.getFunction(t);
    final double xMax = LIMIT_CALCULATOR.solve(psiFunction, alpha, tol);

    double deltaK;
    if (highestStrike == lowestStrike) {
        deltaK = Math.PI / xMax;
    } else {
        deltaK = Math.min(Math.log(highestStrike / lowestStrike) / (minStrikesDisplayed - 1), Math.PI / xMax);
    }

    final double log2 = Math.log(2);
    final int twoPow = (int) Math.ceil(Math.log(kMax / deltaK) / log2);

    final int n = (int) Math.pow(2, twoPow);
    final double delta = 2 * Math.PI / n / deltaK;
    final int m = (int) (xMax * deltaK * n / 2 / Math.PI);

    final int nLowStrikes = (int) Math.ceil(Math.log(forward / lowestStrike) / deltaK);
    final int nHighStrikes = (int) Math.ceil(Math.log(highestStrike / forward) / deltaK);

    return getGreeks(forward, discountFactor, t, isCall, ce, nLowStrikes, nHighStrikes, alpha, delta, n, m);
}

From source file:BackEnd.E_calculation.java

private FazorVektor calc_DE(double tau_real, double tau_image, DPoint Rp, DPoint R0, DPoint R0m, DPoint deltaL)
        throws DelaunayError {
    DPoint R_0 = new DPoint(R0.getX(), R0.getY(), R0.getZ());
    DPoint R_0m = new DPoint(R0.getX(), R0.getY(), R0.getZ());
    R_0.setY(R0.getY() + R0_bundleY); //  bundle korektura pre jeden druhy SMER 
    R_0.setZ(R0.getZ() + Math.cos(beta) * R0_bundleZ); // priemety
    R_0.setX(R0.getX() + Math.sin(beta) * R0_bundleZ);

    R_0m.setY(R0m.getY() - R0_bundleY); //  bundle korektura pre jeden druhy SMER 
    R_0m.setZ(R0m.getZ() + Math.cos(beta) * R0_bundleZ); // priemety
    R_0m.setX(R0m.getX() + Math.sin(beta) * R0_bundleZ);

    //  System.out.println( "R_0= " + R_0 );
    //  System.out.println( "Rp= " + Rp );
    // System.out.println( "deltal= " + deltaL );
    double K = 1 / (4 * Math.PI * constants.getEpsi0() * constants.getEpsi1()); // kontanta

    DPoint R_r = help.substract(Rp, R_0); // rozdiel vektorov Rp a RO
    DPoint R_m = help.substract(Rp, R_0m); // rozdiel vektorov RP a RO mirror
    DPoint R_r_unit = new DPoint(R_r);
    DPoint R_m_unit = new DPoint(R_m);

    R_r_unit.setX(R_r_unit.getX() / get_ABS(R_r));
    R_r_unit.setY(R_r_unit.getY() / get_ABS(R_r));
    R_r_unit.setZ(R_r_unit.getZ() / get_ABS(R_r));

    R_m_unit.setX(R_m_unit.getX() / get_ABS(R_m));
    R_m_unit.setY(R_m_unit.getY() / get_ABS(R_m));
    R_m_unit.setZ(R_m_unit.getZ() / get_ABS(R_m));

    double menovatel_r = Math.pow(get_ABS(R_r), 2);
    double menovatel_m = Math.pow(get_ABS(R_m), 2);
    double DELTA_l = get_ABS(deltaL);
    ////  w  w w . j  a  v a  2s. c o m
    //double DELTA_l = 1; //Rozptie.getKrok();

    FazorVektor deltaE = new FazorVektor(new Complex(0, 0), new Complex(0, 0), new Complex(0, 0));

    deltaE.setX_Real(K * (((tau_real * DELTA_l * R_r_unit.getX()) / menovatel_r)
            - ((tau_real * DELTA_l * R_m_unit.getX()) / menovatel_m)));
    deltaE.setY_Real(K * (((tau_real * DELTA_l * R_r_unit.getY()) / menovatel_r)
            - ((tau_real * DELTA_l * R_m_unit.getY()) / menovatel_m)));
    deltaE.setZ_Real(K * (((tau_real * DELTA_l * R_r_unit.getZ()) / menovatel_r)
            - ((tau_real * DELTA_l * R_m_unit.getZ()) / menovatel_m)));

    deltaE.setX_Imaginary(K * (((tau_image * DELTA_l * R_r_unit.getX()) / menovatel_r)
            - ((tau_image * DELTA_l * R_m_unit.getX()) / menovatel_m)));
    deltaE.setY_Imaginary(K * (((tau_image * DELTA_l * R_r_unit.getY()) / menovatel_r)
            - ((tau_image * DELTA_l * R_m_unit.getY()) / menovatel_m)));
    deltaE.setZ_Imaginary(K * (((tau_image * DELTA_l * R_r_unit.getZ()) / menovatel_r)
            - ((tau_image * DELTA_l * R_m_unit.getZ()) / menovatel_m)));

    return deltaE;
}

From source file:fsm.series.Series_CC.java

public strictfp double getF2Value(double y, int m, int n) {

    double Pi = Math.PI;

    double um = getMu_m(m);
    double un = getMu_m(n);

    double alphaM = (sin(um) - sinh(um)) / (cos(um) - cosh(um));

    double alphaN = (sin(un) - sinh(un)) / (cos(un) - cosh(un));

    double km = um / a;
    double kn = un / a;

    BigDecimal Ymd2;/*from   ww  w.j ava2  s  .com*/
    BigDecimal Yn;

    BigDecimal cosh = new BigDecimal(alphaM * km * km * cosh(km * y));

    BigDecimal sinh = new BigDecimal(-km * km * sinh(km * y));
    BigDecimal sin = new BigDecimal(-km * km * sin(km * y));
    BigDecimal cos = new BigDecimal(alphaM * km * km * cos(km * y));

    Ymd2 = (cos.add(sin).add(sinh).add(cosh));

    BigDecimal coshN = new BigDecimal(-alphaN * -cosh(kn * y));
    BigDecimal sinhN = new BigDecimal(-sinh(kn * y));
    BigDecimal sinN = new BigDecimal(sin(kn * y));
    BigDecimal cosN = new BigDecimal(-alphaN * cos(kn * y));

    Yn = cosN.add(sinN).add(sinhN).add(coshN);

    BigDecimal ans = Ymd2.multiply(Yn);

    return ans.doubleValue();
}

From source file:edu.ucla.stat.SOCR.chart.demo.BarChart3DDemo3.java

/**
 * Creates a chart./*from w  w  w .  ja va 2  s.  c  o  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createBarChart3D(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    CategoryPlot plot = chart.getCategoryPlot();
    CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0));

    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setBaseItemLabelsVisible(true);
    BarRenderer r = (BarRenderer) renderer;
    r.setMaximumBarWidth(0.05);
    r.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());
    setCategorySummary(dataset);
    return chart;

}

From source file:eagle.security.userprofile.impl.UserProfileAnomalyKDEEvaluator.java

@Override
public List<MLCallbackResult> detect(final String user, final String algorithm,
        UserActivityAggModel userActivity, UserProfileKDEModel aModel) {
    List<MLCallbackResult> mlPredictionOutputList = new ArrayList<MLCallbackResult>();
    RealMatrix inputData = userActivity.matrix();

    double[] probabilityEstimation = new double[inputData.getRowDimension()];
    for (int i = 0; i < probabilityEstimation.length; i++)
        probabilityEstimation[i] = 1.0;/*from  w ww.j a  v a2s  . co m*/

    boolean[][] anomalyFeature = new boolean[inputData.getRowDimension()][inputData.getColumnDimension()];

    for (int i = 0; i < anomalyFeature.length; i++) {
        for (int j = 0; j < anomalyFeature[i].length; j++) {
            anomalyFeature[i][j] = false;
        }
    }

    if (aModel == null) {
        LOG.info("No model available for this uer, returning");
        return null;
    }

    Map<String, String> context = new HashMap<String, String>() {
        {
            put(UserProfileConstants.USER_TAG, user);
            put(UserProfileConstants.ALGORITHM_TAG, algorithm);
        }
    };

    for (int i = 0; i < inputData.getRowDimension(); i++) {
        List<String> cmds = JavaConversions.seqAsJavaList(userActivity.cmdTypes());
        if (inputData.getColumnDimension() != cmds.size()) {
            LOG.error("Test data is not with same dimension as training, aborting...");
            return null;
        } else {

            UserCommandStatistics[] listStats = aModel.statistics();

            for (int j = 0; j < inputData.getColumnDimension(); j++) {
                //                    LOG.info("mean for j=" + j + " is:" + listStats[j].getMean());
                //                    LOG.info("stddev for j=" + j + " is:" + listStats[j].getStddev());
                if (listStats[j].isLowVariant()) {
                    //                        LOG.info(listStats[j].getCommandName() + " is low variant for user: " + user);
                    if (inputData.getEntry(i, j) > listStats[j].getMean()) {
                        probabilityEstimation[i] *= Double.NEGATIVE_INFINITY;
                        anomalyFeature[i][j] = true;
                    }
                } else {
                    double stddev = listStats[j].getStddev();
                    //LOG.info("stddev: " + stddev);
                    double mean = listStats[j].getMean();
                    //LOG.info("mean: " + mean);
                    double sqrt2PI = Math.sqrt(2.0 * Math.PI);
                    //LOG.info("sqrt2PI: " + sqrt2PI);
                    double denominatorFirstPart = sqrt2PI * stddev;
                    //LOG.info("denominatorFirstPart: " + denominatorFirstPart);
                    double squareMeanNormal = Math.pow((inputData.getEntry(i, j) - mean), 2);
                    //LOG.info("squareMeanNormal: " + squareMeanNormal);
                    double twoPowStandardDev = Math.pow(stddev, 2);
                    //LOG.info("twoPowStandardDev: " + twoPowStandardDev);
                    double twoTimesTwoPowStandardDev = 2.0 * twoPowStandardDev;
                    //LOG.info("twoTimesTwoPowStandardDev: " + twoTimesTwoPowStandardDev);

                    double tempVal = ((1.00 / denominatorFirstPart)
                            * (Math.exp(-(squareMeanNormal / twoTimesTwoPowStandardDev))));
                    probabilityEstimation[i] *= tempVal;
                    //LOG.info("probabilityEstimation: " + probabilityEstimation[i]);
                    if ((inputData.getEntry(i, j) - mean) > 2 * stddev)
                        anomalyFeature[i][j] = true;
                }
            }

        }
    }

    for (int i = 0; i < probabilityEstimation.length; i++) {
        MLCallbackResult callBackResult = new MLCallbackResult();
        callBackResult.setContext(context);
        //LOG.info("probability estimation for data @" + i + " is: " + probabilityEstimation[i]);
        if (probabilityEstimation[i] < aModel.maxProbabilityEstimate()) {
            callBackResult.setAnomaly(true);
            for (int col = 0; col < anomalyFeature[i].length; col++) {
                //LOG.info("feature anomaly? " + (featureVals[col] == true));
                if (anomalyFeature[i][col] == true) {
                    callBackResult.setFeature(aModel.statistics()[col].getCommandName());
                }
            }
        } else {
            callBackResult.setAnomaly(false);
        }

        callBackResult.setTimestamp(userActivity.timestamp());
        List<String> datapoints = new ArrayList<String>();
        double[] rowVals = userActivity.matrix().getRow(i);
        for (double rowVal : rowVals)
            datapoints.add(rowVal + "");
        callBackResult.setDatapoints(datapoints);
        callBackResult.setId(user);
        callBackResult.setAlgorithm(UserProfileConstants.KDE_ALGORITHM);
        mlPredictionOutputList.add(callBackResult);
    }
    return mlPredictionOutputList;
}

From source file:TriangulatorTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    rotator.setSchedulingBounds(bounds);

    objTrans.addChild(rotator);/* w w w  . j av  a2s. c  o  m*/

    // triangulate the polygon
    GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);

    gi.setCoordinates(m_VertexArray);

    int[] stripCountArray = { 10, 5 };
    int[] countourCountArray = { stripCountArray.length };

    gi.setContourCounts(countourCountArray);
    gi.setStripCounts(stripCountArray);

    Triangulator triangulator = new Triangulator();
    triangulator.triangulate(gi);

    NormalGenerator normalGenerator = new NormalGenerator();
    normalGenerator.generateNormals(gi);

    // create an appearance
    Appearance ap = new Appearance();

    // render as a wireframe
    PolygonAttributes polyAttrbutes = new PolygonAttributes();
    polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE);
    ap.setPolygonAttributes(polyAttrbutes);

    // add both a wireframe and a solid version
    // of the triangulated surface
    Shape3D shape1 = new Shape3D(gi.getGeometryArray(), ap);
    Shape3D shape2 = new Shape3D(gi.getGeometryArray());

    objTrans.addChild(shape1);
    objTrans.addChild(shape2);
    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:com.alvermont.terraj.fracplanet.geom.TriangleMeshFlat.java

/**
 * Create the mesh object/*from  w w w  . j  a va  2  s .c om*/
 */
protected void buildMesh() {
    switch (this.ttype) {
    case TRIANGLE:

        for (int i = 0; i < 3; ++i) {
            addVertex(new SimpleVertex(new SimpleXYZ((float) Math.cos(i * 2.0 * Math.PI / 3.0),
                    (float) Math.sin(i * 2.0 * Math.PI / 3.0), z)));
        }

        addTriangle(new SimpleTriangle(0, 1, 2));

        break;

    case SQUARE:
        addVertex(new SimpleVertex(new SimpleXYZ(0.0f, 0.0f, z)));

        for (int i = 0; i < 4; ++i) {
            addVertex(new SimpleVertex(new SimpleXYZ((float) Math.cos(i * Math.PI / 2.0),
                    (float) Math.sin(i * Math.PI / 2.0), z)));
        }

        for (int i = 0; i < 4; ++i) {
            addTriangle(new SimpleTriangle(0, 1 + i, 1 + (i + 1) % 4));
        }

        break;

    case HEXAGON:
    default:
        addVertex(new SimpleVertex(new SimpleXYZ(0.0f, 0.0f, z)));

        for (int i = 0; i < 6; ++i) {
            addVertex(new SimpleVertex(new SimpleXYZ((float) Math.cos(i * Math.PI / 3.0),
                    (float) Math.sin(i * Math.PI / 3.0), z)));
        }

        for (int i = 0; i < 6; ++i) {
            addTriangle(new SimpleTriangle(0, 1 + i, 1 + (i + 1) % 6));
        }

        break;
    }
}

From source file:org.jfree.experimental.chart.swt.demo.SWTBarChartDemo1.java

/**
 * Creates a sample chart./*from   www.  j  a  va2  s .com*/
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("SWTBarChartDemo1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // the SWTGraphics2D class doesn't handle GradientPaint well, so
    // replace the gradient painter from the default theme with a
    // standard painter...
    renderer.setBarPainter(new StandardBarPainter());

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.JarrowRuddSkewnessKurtosisModel.java

private double getA(final double d2, final double k, final double sigmaT) {
    return Math.exp(-d2 * d2 / 2.) / k / sigmaT / Math.sqrt(2 * Math.PI);
}

From source file:j2se.jfreechart.barchart.BarChart3DDemo1.java

/**
 * Creates a chart./*from w  ww .ja v  a 2  s. com*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createBarChart3D("3D Bar Chart Demo", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    final CategoryPlot plot = chart.getCategoryPlot();
    final CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0));
    final BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    return chart;

}