Java Code Examples for java.lang.Math#sqrt()
The following examples show how to use
java.lang.Math#sqrt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SquareRoot.java From Llunatic with GNU General Public License v3.0 | 6 votes |
/** * Calculates the square root of the parameter. The parameter must * either be of type Double or Complex. * * @return The square root of the parameter. */ public Object sqrt(Object param) throws ParseException { if (param instanceof Complex) return ((Complex)param).sqrt(); if (param instanceof Number) { double value = ((Number)param).doubleValue(); // a value less than 0 will produce a complex result if (value < 0.0) { return (new Complex(value).sqrt()); } else { return new Double(Math.sqrt(value)); } } throw new ParseException("Invalid parameter type"); }
Example 2
Source File: PrimeFactorization.java From Java with MIT License | 6 votes |
public static void pfactors(int n){ while (n%2==0) { System.out.print(2 + " "); n /= 2; } for (int i=3; i<= Math.sqrt(n); i+=2) { while (n%i == 0) { System.out.print(i + " "); n /= i; } } if(n > 2) System.out.print(n); }
Example 3
Source File: MODENARProcess.java From KEEL with GNU General Public License v3.0 | 6 votes |
private double DistanceEuclidea(Chromosome chromo_a,Chromosome chromo_b) { double DistEuclidea,lb_a,ub_a,lb_b,ub_b; double suma_lb_ub = 0,suma = 0, resta_lb,resta_ub; for(int i=0; i< chromo_a.getGenes().size();i++){ lb_a = chromo_a.getGenes().get(i).getL(); ub_a = chromo_a.getGenes().get(i).getU(); lb_b = chromo_b.getGenes().get(i).getL(); ub_b = chromo_b.getGenes().get(i).getU(); resta_lb = lb_a - lb_b; resta_ub = ub_a - ub_b; suma_lb_ub = resta_lb + resta_ub; suma = suma + Math.pow(suma_lb_ub,2);//aplicando la sumatoria del cuadrado } DistEuclidea = Math.sqrt(suma); return DistEuclidea; }
Example 4
Source File: Utils.java From KEEL with GNU General Public License v3.0 | 5 votes |
/** * Returns the correlation coefficient of two double vectors. * * @param y1 double vector 1 * @param y2 double vector 2 * @param n the length of two double vectors * @return the correlation coefficient */ public static final double correlation(double y1[],double y2[],int n) { int i; double av1 = 0.0, av2 = 0.0, y11 = 0.0, y22 = 0.0, y12 = 0.0, c; if (n <= 1) { return 1.0; } for (i = 0; i < n; i++) { av1 += y1[i]; av2 += y2[i]; } av1 /= (double) n; av2 /= (double) n; for (i = 0; i < n; i++) { y11 += (y1[i] - av1) * (y1[i] - av1); y22 += (y2[i] - av2) * (y2[i] - av2); y12 += (y1[i] - av1) * (y2[i] - av2); } if (y11 * y22 == 0.0) { c=1.0; } else { c = y12 / Math.sqrt(Math.abs(y11 * y22)); } return c; }
Example 5
Source File: SpliceStddevSamp.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@Override public K terminate() { if (result == null) { if (count > 1) { result = new Double(Math.sqrt(variance/(count-1))); } } return (K) result; }
Example 6
Source File: SDLActivity.java From simpleSDL with MIT License | 5 votes |
/** * This method is called by SDL using JNI. */ public static boolean isTablet() { DisplayMetrics metrics = new DisplayMetrics(); Activity activity = (Activity)getContext(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); double dWidthInches = metrics.widthPixels / (double)metrics.xdpi; double dHeightInches = metrics.heightPixels / (double)metrics.ydpi; double dDiagonal = Math.sqrt((dWidthInches * dWidthInches) + (dHeightInches * dHeightInches)); // If our diagonal size is seven inches or greater, we consider ourselves a tablet. return (dDiagonal >= 7.0); }
Example 7
Source File: Est_evol.java From KEEL with GNU General Public License v3.0 | 5 votes |
public Est_evol (BaseR base_r, Adap fun, MiDataset t, int n_gen, int m, int l, int n_sigm, int n_alf, int Omeg_x, int Omeg_sigma, int Omeg_alfa, int Delt_x, int Delt_sigma, int Delt_alfa) { int i; base_reglas = base_r; fun_adap = fun; tabla = t; n_gen_ee = n_gen; Mu = m; Landa = l; n_sigma = n_sigm; n_alfa = n_alf; Omega_x = Omeg_x; Omega_sigma = Omeg_sigma; Omega_alfa = Omeg_alfa; Delta_x = Delt_x; Delta_sigma = Delt_sigma; Delta_alfa = Delt_alfa; n_total = tabla.n_variables + n_sigma + n_alfa; Tau_0 = 1.0 / Math.sqrt (2 * tabla.n_variables); Tau = 1.0 / Math.sqrt (2 * Math.sqrt(tabla.n_variables)); Tau_1 = 1.0 / Math.sqrt(tabla.n_variables); nl_alfa = tabla.n_variables + 1 - n_sigma; nm_alfa = tabla.n_variables - 1; Z = new double[tabla.n_variables]; indices_seleccion = new int[Landa]; indices_recombinacion = new int[(int) Adap.Maximo(Delta_x, Adap.Maximo (Delta_sigma,Delta_alfa))]; ind_mayor = new int[tabla.long_tabla]; indices_ep = new int[tabla.long_tabla]; Padres = new Structure[Mu]; Hijos = new Structure[Landa]; for (i=0; i<Mu; i++) Padres[i] = new Structure(n_total); for (i=0; i<Landa; i++) Hijos[i] = new Structure(n_total); }
Example 8
Source File: AG.java From KEEL with GNU General Public License v3.0 | 5 votes |
/** Generates a normal value with hope 0 and tipical deviation "desv */ private double ValorNormal (double desv) { double u1, u2; /* we generate 2 uniform values [0,1] */ u1 = Randomize.Rand (); u2 = Randomize.Rand (); /* we calcules a normal value with the uniform values */ return (desv * Math.sqrt (-2 * Math.log(u1)) * Math.sin (2*Math.PI*u2)); }
Example 9
Source File: Est_evol.java From KEEL with GNU General Public License v3.0 | 5 votes |
/** Generates a normal value with hope 0 and tipical deviation "desv */ public double ValorNormal(double desv) { double u1, u2; /* we generate 2 uniform values [0,1] */ u1 = Randomize.Rand(); u2 = Randomize.Rand(); /* we calcules a normal value with the uniform values */ return (desv * Math.sqrt( -2.0 * Math.log(u1)) * Math.sin(2.0 * Math.PI * u2)); }
Example 10
Source File: Vector3.java From openchemlib-js with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Computes the euclidean distance between two Vector3s. * @param that The other Vector3 to calculate the distance to. * @return The distance between the two vectors. */ public double distance(Vector3 that) { return Math.sqrt( (x-that.x)*(x-that.x) + (y-that.y)*(y-that.y) + (z-that.z)*(z-that.z) ); }
Example 11
Source File: GuassLegendre.java From Java with MIT License | 5 votes |
static double[] update(double a, double b, double t, double p) { double values[] = new double[4]; values[0] = (a + b) / 2; values[1] = Math.sqrt(a * b); values[2] = t - p * Math.pow(a - values[0], 2); values[3] = 2 * p; return values; }
Example 12
Source File: Est_evol.java From KEEL with GNU General Public License v3.0 | 5 votes |
/** Generates a normal value with hope 0 and tipical deviation "desv */ public double ValorNormal(double desv) { double u1, u2; /* we generate 2 uniform values [0,1] */ u1 = Randomize.Rand(); u2 = Randomize.Rand(); /* we calcules a normal value with the uniform values */ return (desv * Math.sqrt( -2.0 * Math.log(u1)) * Math.sin(2.0 * PI * u2)); }
Example 13
Source File: Moments.java From OpenCV-android with Apache License 2.0 | 4 votes |
protected void completeState() { double cx = 0, cy = 0; double mu20, mu11, mu02; double inv_m00 = 0.0; if( Math.abs(this.m00) > 0.00000001 ) { inv_m00 = 1. / this.m00; cx = this.m10 * inv_m00; cy = this.m01 * inv_m00; } // mu20 = m20 - m10*cx mu20 = this.m20 - this.m10 * cx; // mu11 = m11 - m10*cy mu11 = this.m11 - this.m10 * cy; // mu02 = m02 - m01*cy mu02 = this.m02 - this.m01 * cy; this.mu20 = mu20; this.mu11 = mu11; this.mu02 = mu02; // mu30 = m30 - cx*(3*mu20 + cx*m10) this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10); mu11 += mu11; // mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20 this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20; // mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02 this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02; // mu03 = m03 - cy*(3*mu02 + cy*m01) this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01); double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00)); double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00; this.nu20 = this.mu20*s2; this.nu11 = this.mu11*s2; this.nu02 = this.mu02*s2; this.nu30 = this.mu30*s3; this.nu21 = this.mu21*s3; this.nu12 = this.mu12*s3; this.nu03 = this.mu03*s3; }
Example 14
Source File: Moments.java From MOAAP with MIT License | 4 votes |
protected void completeState() { double cx = 0, cy = 0; double mu20, mu11, mu02; double inv_m00 = 0.0; if( Math.abs(this.m00) > 0.00000001 ) { inv_m00 = 1. / this.m00; cx = this.m10 * inv_m00; cy = this.m01 * inv_m00; } // mu20 = m20 - m10*cx mu20 = this.m20 - this.m10 * cx; // mu11 = m11 - m10*cy mu11 = this.m11 - this.m10 * cy; // mu02 = m02 - m01*cy mu02 = this.m02 - this.m01 * cy; this.mu20 = mu20; this.mu11 = mu11; this.mu02 = mu02; // mu30 = m30 - cx*(3*mu20 + cx*m10) this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10); mu11 += mu11; // mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20 this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20; // mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02 this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02; // mu03 = m03 - cy*(3*mu02 + cy*m01) this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01); double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00)); double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00; this.nu20 = this.mu20*s2; this.nu11 = this.mu11*s2; this.nu02 = this.mu02*s2; this.nu30 = this.mu30*s3; this.nu21 = this.mu21*s3; this.nu12 = this.mu12*s3; this.nu03 = this.mu03*s3; }
Example 15
Source File: Moments.java From sudokufx with Apache License 2.0 | 4 votes |
protected void completeState() { double cx = 0, cy = 0; double mu20, mu11, mu02; double inv_m00 = 0.0; if( Math.abs(this.m00) > 0.00000001 ) { inv_m00 = 1. / this.m00; cx = this.m10 * inv_m00; cy = this.m01 * inv_m00; } // mu20 = m20 - m10*cx mu20 = this.m20 - this.m10 * cx; // mu11 = m11 - m10*cy mu11 = this.m11 - this.m10 * cy; // mu02 = m02 - m01*cy mu02 = this.m02 - this.m01 * cy; this.mu20 = mu20; this.mu11 = mu11; this.mu02 = mu02; // mu30 = m30 - cx*(3*mu20 + cx*m10) this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10); mu11 += mu11; // mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20 this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20; // mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02 this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02; // mu03 = m03 - cy*(3*mu02 + cy*m01) this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01); double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00)); double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00; this.nu20 = this.mu20*s2; this.nu11 = this.mu11*s2; this.nu02 = this.mu02*s2; this.nu30 = this.mu30*s3; this.nu21 = this.mu21*s3; this.nu12 = this.mu12*s3; this.nu03 = this.mu03*s3; }
Example 16
Source File: Est_mu_landa.java From KEEL with GNU General Public License v3.0 | 4 votes |
public Est_mu_landa(BaseR base_r, Adap fun, MiDataset t, int gen_ee, int m, int l, int n_sigm, int n_alf, int Omeg_x, int Omeg_sigma, int Omeg_alfa, int Delt_x, int Delt_sigma, int Delt_alfa) { int i; base_reglas = base_r; fun_adap = fun; tabla = t; n_gen_ee = gen_ee; Mu = m; Landa = l; n_sigma = n_sigm; n_alfa = n_alf; Omega_x = Omeg_x; Omega_sigma = Omeg_sigma; Omega_alfa = Omeg_alfa; Delta_x = Delt_x; Delta_sigma = Delt_sigma; Delta_alfa = Delt_alfa; n_total = tabla.n_variables + n_sigma + n_alfa; Tau_0 = 1.0 / Math.sqrt(2 * tabla.n_variables); Tau = 1.0 / Math.sqrt(2 * Math.sqrt(tabla.n_variables)); Tau_1 = 1.0 / Math.sqrt(tabla.n_variables); nl_alfa = tabla.n_variables + 1 - n_sigma; nm_alfa = tabla.n_variables - 1; Z = new double[tabla.n_variables]; indices_seleccion = new int[Landa]; indices_recombinacion = new int[ (int) Adap.Maximo(Delta_x, Adap.Maximo(Delta_sigma, Delta_alfa))]; ind_mayor = new int[tabla.long_tabla]; Padres = new Structure[Mu]; Hijos = new Structure[Landa]; for (i = 0; i < Mu; i++) { Padres[i] = new Structure(n_total); } for (i = 0; i < Landa; i++) { Hijos[i] = new Structure(n_total); } }
Example 17
Source File: Moments.java From OpenCV-Android-Object-Detection with MIT License | 4 votes |
protected void completeState() { double cx = 0, cy = 0; double mu20, mu11, mu02; double inv_m00 = 0.0; if( Math.abs(this.m00) > 0.00000001 ) { inv_m00 = 1. / this.m00; cx = this.m10 * inv_m00; cy = this.m01 * inv_m00; } // mu20 = m20 - m10*cx mu20 = this.m20 - this.m10 * cx; // mu11 = m11 - m10*cy mu11 = this.m11 - this.m10 * cy; // mu02 = m02 - m01*cy mu02 = this.m02 - this.m01 * cy; this.mu20 = mu20; this.mu11 = mu11; this.mu02 = mu02; // mu30 = m30 - cx*(3*mu20 + cx*m10) this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10); mu11 += mu11; // mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20 this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20; // mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02 this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02; // mu03 = m03 - cy*(3*mu02 + cy*m01) this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01); double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00)); double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00; this.nu20 = this.mu20*s2; this.nu11 = this.mu11*s2; this.nu02 = this.mu02*s2; this.nu30 = this.mu30*s3; this.nu21 = this.mu21*s3; this.nu12 = this.mu12*s3; this.nu03 = this.mu03*s3; }
Example 18
Source File: Moments.java From faceswap with Apache License 2.0 | 4 votes |
protected void completeState() { double cx = 0, cy = 0; double mu20, mu11, mu02; double inv_m00 = 0.0; if( Math.abs(this.m00) > 0.00000001 ) { inv_m00 = 1. / this.m00; cx = this.m10 * inv_m00; cy = this.m01 * inv_m00; } // mu20 = m20 - m10*cx mu20 = this.m20 - this.m10 * cx; // mu11 = m11 - m10*cy mu11 = this.m11 - this.m10 * cy; // mu02 = m02 - m01*cy mu02 = this.m02 - this.m01 * cy; this.mu20 = mu20; this.mu11 = mu11; this.mu02 = mu02; // mu30 = m30 - cx*(3*mu20 + cx*m10) this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10); mu11 += mu11; // mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20 this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20; // mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02 this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02; // mu03 = m03 - cy*(3*mu02 + cy*m01) this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01); double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00)); double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00; this.nu20 = this.mu20*s2; this.nu11 = this.mu11*s2; this.nu02 = this.mu02*s2; this.nu30 = this.mu30*s3; this.nu21 = this.mu21*s3; this.nu12 = this.mu12*s3; this.nu03 = this.mu03*s3; }
Example 19
Source File: Moments.java From real_time_circle_detection_android with MIT License | 4 votes |
protected void completeState() { double cx = 0, cy = 0; double mu20, mu11, mu02; double inv_m00 = 0.0; if( Math.abs(this.m00) > 0.00000001 ) { inv_m00 = 1. / this.m00; cx = this.m10 * inv_m00; cy = this.m01 * inv_m00; } // mu20 = m20 - m10*cx mu20 = this.m20 - this.m10 * cx; // mu11 = m11 - m10*cy mu11 = this.m11 - this.m10 * cy; // mu02 = m02 - m01*cy mu02 = this.m02 - this.m01 * cy; this.mu20 = mu20; this.mu11 = mu11; this.mu02 = mu02; // mu30 = m30 - cx*(3*mu20 + cx*m10) this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10); mu11 += mu11; // mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20 this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20; // mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02 this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02; // mu03 = m03 - cy*(3*mu02 + cy*m01) this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01); double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00)); double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00; this.nu20 = this.mu20*s2; this.nu11 = this.mu11*s2; this.nu02 = this.mu02*s2; this.nu30 = this.mu30*s3; this.nu21 = this.mu21*s3; this.nu12 = this.mu12*s3; this.nu03 = this.mu03*s3; }
Example 20
Source File: Moments.java From ml-authentication with Apache License 2.0 | 4 votes |
protected void completeState() { double cx = 0, cy = 0; double mu20, mu11, mu02; double inv_m00 = 0.0; if( Math.abs(this.m00) > 0.00000001 ) { inv_m00 = 1. / this.m00; cx = this.m10 * inv_m00; cy = this.m01 * inv_m00; } // mu20 = m20 - m10*cx mu20 = this.m20 - this.m10 * cx; // mu11 = m11 - m10*cy mu11 = this.m11 - this.m10 * cy; // mu02 = m02 - m01*cy mu02 = this.m02 - this.m01 * cy; this.mu20 = mu20; this.mu11 = mu11; this.mu02 = mu02; // mu30 = m30 - cx*(3*mu20 + cx*m10) this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10); mu11 += mu11; // mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20 this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20; // mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02 this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02; // mu03 = m03 - cy*(3*mu02 + cy*m01) this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01); double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00)); double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00; this.nu20 = this.mu20*s2; this.nu11 = this.mu11*s2; this.nu02 = this.mu02*s2; this.nu30 = this.mu30*s3; this.nu21 = this.mu21*s3; this.nu12 = this.mu12*s3; this.nu03 = this.mu03*s3; }