List of usage examples for java.lang Math PI
double PI
To view the source code for java.lang Math PI.
Click Source Link
From source file:bots.mctsbot.ai.bots.util.Gaussian.java
public final static double smallPhi(double x) { return 1.0 / Math.sqrt(2 * Math.PI) * Math.exp(-x * x / 2.0); }
From source file:de.termininistic.serein.examples.benchmarks.functions.multimodal.RastriginFunction.java
@Override public double map(RealVector v) { double fx = Double.NaN; double[] x = v.toArray(); int n = x.length; fx = 10 * n;/* w ww . j a va 2 s . co m*/ for (int i = 0; i < n; i++) { fx += x[i] * x[i] - 10 * Math.cos(2 * Math.PI * x[i]); } return fx; }
From source file:edu.ucsf.valelab.saim.calculations.BenchmarkCalculations.java
/** * Compares two methods to calculate the Saim function * The implementation not using Complex numbers appears to be at least * 10 times faster/* www .j a v a2 s .c om*/ * @throws Exception */ public void test() throws Exception { long nrRuns = 100000000; double wavelength = 488.0; double nSample = 1.36; double dOx = 500.0; double h = 16.0; double angle = Math.toRadians(0.0); SaimFunction sf = new SaimFunction(wavelength, dOx, nSample, false); Complex rTE = sf.getFresnelTE(0); double f = 4.0 * Math.PI * nSample * Math.cos(angle) / wavelength; double phaseDiff = f * h; // method 1 long startTime = System.nanoTime(); double c = rTE.getReal(); double d = rTE.getImaginary(); for (int i = 0; i < nrRuns; i++) { double val = 1 + 2 * c * Math.cos(phaseDiff) - 2 * d * Math.sin(phaseDiff) + c * c + d * d; } long endTime = System.nanoTime(); long took = endTime - startTime; System.out.println("First method: " + nrRuns + " runs took: " + took / 1000000 + " milliseconds"); // method 2 startTime = System.nanoTime(); for (int i = 0; i < nrRuns; i++) { Complex tmp = new Complex(Math.cos(phaseDiff), Math.sin(phaseDiff)); Complex fieldStrength = rTE.multiply(tmp); fieldStrength = fieldStrength.add(1.0); // square of absolute double val = fieldStrength.getReal() * fieldStrength.getReal() + fieldStrength.getImaginary() * fieldStrength.getImaginary(); } endTime = System.nanoTime(); took = endTime - startTime; System.out.println("Second method: " + nrRuns + " runs took: " + took / 1000000 + " milliseconds"); }
From source file:fsm.series.Series_SS.java
@Override public double getMu_m(int m) { return m * Math.PI; }
From source file:ch.unil.genescore.vegas.DistributionMethods.java
public static double normalCumulativeProbabilityUpperTailApprox(double q) { q = Math.abs(q);/*from w w w. jav a 2 s .co m*/ double aa = -(q * q) / 2 - Math.log(q) - 0.5 * Math.log(2 * Math.PI); return (Math.exp(aa)); }
From source file:dnimp.Statistics.java
private double studT(double t, int n) { t = Math.abs(t);//from ww w.ja v a 2 s. c o m double th = Math.atan(t / Math.sqrt(n)); double sth = Math.sin(th); double cth = Math.cos(th); if (n == 1) return 1 - th / (Math.PI / 2.0); if (n % 2 == 1) { return 1 - (th + sth * cth * statCom(cth * cth, 2, n - 3, -1)) / (Math.PI / 2.0); } else { return 1 - sth * statCom(cth * cth, 1, n - 3, -1); } }
From source file:Main.java
public static void cosineSimilarityCW() { Iterator<Integer> ids = CommentWordCount.keySet().iterator(); while (ids.hasNext()) { int com_id = ids.next(); Set<String> words1; words1 = CommentWordCount.get(com_id).keySet(); Iterator<Integer> com_iter = CommentWordCount.keySet().iterator(); while (com_iter.hasNext()) { int id = com_iter.next(); if (com_id < id) { Set<String> words2; words2 = CommentWordCount.get(id).keySet(); Vector<Integer> vecA = new Vector<Integer>(); Vector<Integer> vecB = new Vector<Integer>(); Iterator<String> w1 = words1.iterator(); Iterator<String> w2 = words2.iterator(); HashSet<String> imp = new HashSet<String>(); while (w1.hasNext()) { String s = w1.next(); imp.add(s);/*from w ww . j a va 2 s . c o m*/ } while (w2.hasNext()) { String s = w2.next(); imp.add(s); } for (String s : imp) { if (CommentWordCount.get(com_id).containsKey(s)) { vecA.add(CommentWordCount.get(com_id).get(s)); } else vecA.add(0); if (CommentWordCount.get(id).containsKey(s)) { vecB.add(CommentWordCount.get(id).get(s)); } else vecB.add(0); } //System.out.println("Size : A"+vecA.size()+" Size: B"+vecB.size()+"maxLen:"+maxlength); double similarity; int product = 0; double sumA = 0; double sumB = 0; for (int i = 0; i < vecA.size(); i++) { product += vecA.elementAt(i) * vecB.elementAt(i); sumA += vecA.elementAt(i) * vecA.elementAt(i); sumB += vecB.elementAt(i) * vecB.elementAt(i); } sumA = Math.sqrt(sumA); sumB = Math.sqrt(sumB); similarity = product / (sumA * sumB); similarity = Math.acos(similarity) * 180 / Math.PI; //System.out.println("Result "+com_id+" "+id+" :"+similarity); if (similarity < 75) { //System.out.println("Result "+com_id+" "+id); if (Topic.containsKey(com_id)) { int val = Topic.get(com_id); val++; Topic.put(com_id, val); } else Topic.put(com_id, 1); if (Topic.containsKey(id)) { int val = Topic.get(id); val++; Topic.put(id, val); } else Topic.put(id, 1); } } } } }
From source file:DrawShapes_2008.java
/** * Generates a star Shape from the given location, radii, and points * parameters. The Shape is created by constructing a GeneralPath * that moves between the inner and outer rings. */// w ww. ja v a 2 s . c o m private static Shape generateStar(double x, double y, double innerRadius, double outerRadius, int pointsCount) { GeneralPath path = new GeneralPath(); double outerAngleIncrement = 2 * Math.PI / pointsCount; double outerAngle = 0.0; double innerAngle = outerAngleIncrement / 2.0; x += outerRadius; y += outerRadius; float x1 = (float) (Math.cos(outerAngle) * outerRadius + x); float y1 = (float) (Math.sin(outerAngle) * outerRadius + y); float x2 = (float) (Math.cos(innerAngle) * innerRadius + x); float y2 = (float) (Math.sin(innerAngle) * innerRadius + y); path.moveTo(x1, y1); path.lineTo(x2, y2); outerAngle += outerAngleIncrement; innerAngle += outerAngleIncrement; for (int i = 1; i < pointsCount; i++) { x1 = (float) (Math.cos(outerAngle) * outerRadius + x); y1 = (float) (Math.sin(outerAngle) * outerRadius + y); path.lineTo(x1, y1); x2 = (float) (Math.cos(innerAngle) * innerRadius + x); y2 = (float) (Math.sin(innerAngle) * innerRadius + y); path.lineTo(x2, y2); outerAngle += outerAngleIncrement; innerAngle += outerAngleIncrement; } path.closePath(); return path; }
From source file:Phong.java
/** * Erstellt den Szenegraphen/*from www . j a v a 2 s .com*/ * * @return BranchGroup */ public BranchGroup macheSzene() { BranchGroup objWurzel = new BranchGroup(); // Transformation, 2 Rotationen: Transform3D drehung = new Transform3D(); Transform3D drehung2 = new Transform3D(); drehung.rotX(Math.PI / 4.0d); drehung2.rotY(Math.PI / 5.0d); drehung.mul(drehung2); TransformGroup objDreh = new TransformGroup(drehung); //Loader ObjectFile file = new ObjectFile(ObjectFile.RESIZE); Scene scene = null; try { scene = file.load(ClassLoader.getSystemResource("teapot.obj")); } catch (Exception e) { System.err.println(e); System.exit(1); } objDreh.addChild(scene.getSceneGroup()); DirectionalLight d_Licht = new DirectionalLight(new Color3f(1.0f, 1.0f, 1.0f), new Vector3f(-1.0f, -1.0f, -1.0f)); d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 100.0d)); objDreh.addChild(d_Licht); objWurzel.addChild(objDreh); return objWurzel; }
From source file:ObjectLoader.java
/** * Erstellt den Szenegraphen// w w w .ja v a 2 s. c om * * @return BranchGroup */ public BranchGroup macheSzene() { BranchGroup objWurzel = new BranchGroup(); // Transformation, 2 Rotationen: Transform3D drehung = new Transform3D(); Transform3D drehung2 = new Transform3D(); drehung.rotX(Math.PI / 4.0d); drehung2.rotY(Math.PI / 5.0d); drehung.mul(drehung2); TransformGroup objDreh = new TransformGroup(drehung); //Loader ObjectFile file = new ObjectFile(ObjectFile.RESIZE); Scene scene = null; try { scene = file.load(ClassLoader.getSystemResource("teapot.obj")); } catch (Exception e) { } objDreh.addChild(scene.getSceneGroup()); DirectionalLight d_Licht = new DirectionalLight(new Color3f(1.0f, 0.5f, 0.3f), new Vector3f(-1.0f, -1.0f, -1.0f)); d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 100.0d)); // d_Licht.setColor(new Color3f(1.0f,0.5f,0.3f)); objDreh.addChild(d_Licht); objWurzel.addChild(objDreh); return objWurzel; }