java.lang.Math Java Examples
The following examples show how to use
java.lang.Math.
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: EditDistanceJoiner.java From EditDistanceClusterer with MIT License | 6 votes |
private int filterCandidate(String src, String dst, int srcMatchPos, int dstMatchPos, int len, int[][] distanceBuffer){ int srcRightLen = src.length() - srcMatchPos - len; int dstRightLen = dst.length() - dstMatchPos - len; int leftThreshold = mThreshold - Math.abs(srcRightLen - dstRightLen); int leftDistance = calculateEditDistanceWithThreshold(src, 0, srcMatchPos, dst, 0, dstMatchPos, leftThreshold, distanceBuffer); if (leftDistance > leftThreshold) { return -1; } int rightThreshold = mThreshold - leftDistance; int rightDistance = calculateEditDistanceWithThreshold( src, srcMatchPos + len, src.length() - srcMatchPos - len, dst, dstMatchPos + len, dst.length() - dstMatchPos - len, rightThreshold, distanceBuffer); if (rightDistance > rightThreshold) { return -1; } return leftDistance + rightDistance; }
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: Adap_Sel.java From KEEL with GNU General Public License v3.0 | 6 votes |
public Adap_Sel (MiDataset training, BaseR_Sel base, BaseR_Sel base_t, double porc_radio_nicho, int n_soluciones, double valor_tau, double valor_alfa, int tipo) { int i; tabla = training; base_reglas = base; base_total = base_t; tau = valor_tau; alfa = valor_alfa; tipo_fitness = tipo; cont_soluciones = 0; /* Calculo del radio del nicho */ radio_nicho = (int) (porc_radio_nicho * base_total.n_reglas); maxEC = 0.0; for (i=0; i<tabla.long_tabla; i++) maxEC += Math.pow (tabla.datos[i].ejemplo[tabla.n_var_estado], 2.0); maxEC /= 2.0; ListaTabu = new char[n_soluciones][base_total.n_reglas]; grado_pertenencia = new double[tabla.n_variables]; }
Example #4
Source File: Adap_Sel.java From KEEL with GNU General Public License v3.0 | 6 votes |
double eval_EC_cubr(char[] cromosoma) { int i; double ec, fitness; /* Se calcula la adecuacion de la base de conocimiento codificada en el cromosoma actual, se estudia la posible penalizacion del mismo y se devuelve el valor final */ Decodifica(cromosoma); Cubrimientos_Base(); if (mincb >= tau) { ec = ErrorCuadratico(); fitness = (1 + Math.abs(1.0 - medcb)) * ec * P(cromosoma); } else { fitness = maxEC; } return (fitness); }
Example #5
Source File: LibMatrixCUDA.java From systemds with Apache License 2.0 | 6 votes |
/** * Get threads, blocks and shared memory for a reduce all operation * @param gCtx a valid {@link GPUContext} * @param n size of input array * @return integer array containing {blocks, threads, shared memory} */ private static int[] getKernelParamsForReduceAll(GPUContext gCtx, int n) { final int MAX_THREADS = getMaxThreads(gCtx); final int MAX_BLOCKS = getMaxBlocks(gCtx); final int WARP_SIZE = getWarpSize(gCtx); int threads = (n < MAX_THREADS *2) ? nextPow2((n + 1)/ 2) : MAX_THREADS; int blocks = (n + (threads * 2 - 1)) / (threads * 2); blocks = Math.min(MAX_BLOCKS, blocks); int sharedMemSize = threads * sizeOfDataType; if (threads <= WARP_SIZE) { sharedMemSize *= 2; } return new int[] {blocks, threads, sharedMemSize}; }
Example #6
Source File: CirSim.java From circuitjs1 with GNU General Public License v2.0 | 6 votes |
void readOptions(StringTokenizer st) { int flags = new Integer(st.nextToken()).intValue(); dotsCheckItem.setState((flags & 1) != 0); smallGridCheckItem.setState((flags & 2) != 0); voltsCheckItem.setState((flags & 4) == 0); powerCheckItem.setState((flags & 8) == 8); showValuesCheckItem.setState((flags & 16) == 0); timeStep = new Double (st.nextToken()).doubleValue(); double sp = new Double(st.nextToken()).doubleValue(); int sp2 = (int) (Math.log(10*sp)*24+61.5); //int sp2 = (int) (Math.log(sp)*24+1.5); speedBar.setValue(sp2); currentBar.setValue(new Integer(st.nextToken()).intValue()); CircuitElm.voltageRange = new Double (st.nextToken()).doubleValue(); try { powerBar.setValue(new Integer(st.nextToken()).intValue()); } catch (Exception e) { } setGrid(); }
Example #7
Source File: SolarSystemRenderer.java From opengl with Apache License 2.0 | 6 votes |
public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glClearColor(0.0f,0.0f,0.0f,1.0f); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -4.0f); gl.glRotatef(mAngle, 1, 0, 0); gl.glRotatef(mAngle, 0, 1, 0); mPlanet.draw(gl); mTransY+=.075f; mAngle+=.4; }
Example #8
Source File: SolarSystemRenderer.java From opengl with Apache License 2.0 | 6 votes |
public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glClearColor(0.0f,0.0f,0.0f,1.0f); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -4.0f); gl.glRotatef(mAngle, 1, 0, 0); gl.glRotatef(mAngle, 0, 1, 0); mPlanet.draw(gl); mTransY+=.075f; mAngle+=.4; }
Example #9
Source File: Adap_Tun.java From KEEL with GNU General Public License v3.0 | 6 votes |
public Adap_Tun(MiDataset training, BaseR base, double valor_tau, int tipo) { int i; tabla = training; base_reglas = base; tau = valor_tau; tipo_fitness = tipo; long_regla = 3 * tabla.n_variables; maxEC = 0.0; for (i = 0; i < tabla.long_tabla; i++) { maxEC += Math.pow(tabla.datos[i].ejemplo[tabla.n_var_estado], 2.0); } maxEC /= 2.0; grado_pertenencia = new double[tabla.n_variables]; }
Example #10
Source File: Adap_Sel.java From KEEL with GNU General Public License v3.0 | 6 votes |
double eval_EC_cubr(char[] cromosoma) { int i; double ec, fitness; /* Se calcula la adecuacion de la base de conocimiento codificada en el cromosoma actual, se estudia la posible penalizacion del mismo y se devuelve el valor final */ Decodifica(cromosoma); Cubrimientos_Base(); if (mincb >= tau && min_reglas <= base_reglas.n_reglas) { ec = ErrorCuadratico(); fitness = (1 + Math.abs(1.0 - medcb)) * ec * P(cromosoma); } else { fitness = maxEC; } return (fitness); }
Example #11
Source File: Adap_Tun.java From KEEL with GNU General Public License v3.0 | 6 votes |
void Decodifica (double [] cromosoma) { int i, j; for (i=0; i<base_reglas.n_reglas; i++) { for (j=0; j<tabla.n_var_estado; j++) { base_reglas.BaseReglas[i].Ant[j].x0 = cromosoma[3*(i*tabla.n_var_estado+j)]; base_reglas.BaseReglas[i].Ant[j].x1 = cromosoma[3*(i*tabla.n_var_estado+j)+1]; base_reglas.BaseReglas[i].Ant[j].x2 = cromosoma[3*(i*tabla.n_var_estado+j)+1]; base_reglas.BaseReglas[i].Ant[j].x3 = cromosoma[3*(i*tabla.n_var_estado+j)+2]; base_reglas.BaseReglas[i].Ant[j].y = 1.0; base_reglas.BaseReglas[i].Ant[j].Nombre = "x" + (j+1); base_reglas.BaseReglas[i].Ant[j].Etiqueta = "E" + i + j; base_reglas.BaseReglas[i].Cons[j] = Math.tan (cromosoma[primer_gen_C2+i*(tabla.n_variables)+j]); } base_reglas.BaseReglas[i].Cons[j] = Math.tan (cromosoma[primer_gen_C2+i*(tabla.n_variables)+j]); } }
Example #12
Source File: SnmpStringFixed.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Constructs a new <CODE>SnmpStringFixed</CODE> from the specified <CODE>bytes</CODE> array * with the specified length. * @param l The length of the fixed-string. * @param v The <CODE>bytes</CODE> composing the fixed-string value. * @exception IllegalArgumentException Either the length or the <CODE>byte</CODE> array is not valid. */ public SnmpStringFixed(int l, byte[] v) throws IllegalArgumentException { if ((l <= 0) || (v == null)) { throw new IllegalArgumentException() ; } int length = Math.min(l, v.length); value = new byte[l] ; for (int i = 0 ; i < length ; i++) { value[i] = v[i] ; } for (int i = length ; i < l ; i++) { value[i] = 0 ; } }
Example #13
Source File: Adap_Sel.java From KEEL with GNU General Public License v3.0 | 5 votes |
public Adap_Sel(MiDataset training, BaseR base, BaseR base_t, double porc_radio_nicho, int n_soluciones, double valor_tau, double valor_alfa, int tipo) { int i; tabla = training; base_reglas = base; base_total = base_t; tau = valor_tau; alfa = valor_alfa; tipo_fitness = tipo; cont_soluciones = 0; /* Calculo del radio del nicho */ radio_nicho = (int) (porc_radio_nicho * base_total.n_reglas); maxEC = 0.0; for (i = 0; i < tabla.long_tabla; i++) { maxEC += Math.pow(tabla.datos[i].ejemplo[tabla.n_var_estado], 2.0); } maxEC /= 2.0; ListaTabu = new char[n_soluciones][base_total.n_reglas]; grado_pertenencia = new double[tabla.n_variables]; }
Example #14
Source File: Adap_Tun.java From KEEL with GNU General Public License v3.0 | 5 votes |
public double ErrorCuadratico () { int i; double suma; for (i=0,suma=0.0; i<tabla.long_tabla; i++) suma += Math.pow (tabla.datos[i].ejemplo[tabla.n_var_estado]-base_reglas.FLC_TSK (tabla.datos[i].ejemplo),2.0); return (suma / (double)tabla.long_tabla); }
Example #15
Source File: Adap_Sel.java From KEEL with GNU General Public License v3.0 | 5 votes |
void Error_tra() { int i, j; double suma1, suma2, fuerza; for (j = 0, suma1 = suma2 = 0.0; j < tabla.long_tabla; j++) { fuerza = base_reglas.FLC_TSK(tabla.datos[j].ejemplo); suma1 += Math.pow(tabla.datos[j].ejemplo[tabla.n_var_estado] - fuerza, 2.0); suma2 += Math.abs(tabla.datos[j].ejemplo[tabla.n_var_estado] - fuerza); } EC = suma1 / (double) tabla.long_tabla; EL = suma2 / (double) tabla.long_tabla; }
Example #16
Source File: IVFSKNN.java From KEEL with GNU General Public License v3.0 | 5 votes |
/** * Evaluates a instance to predict its class membership * * @param index Index of the instance in the test set * @param example Instance evaluated * */ private Interval [] computeMembership(double example[], int index) { //prepare votes Interval [] votes = new Interval[nClasses]; for(int k = 0; k < nClasses; k++){ votes[k] = new Interval(0.0, 0.0); } // find the k nearest examples in the training set int [] neighbors = findKNearest(example, K, index); double minExp = 2.0/(minM-1.0); double maxExp = 2.0/(maxM-1.0); for(int neighbor: neighbors){ // compute weighted norm double distance = Util.euclideanDistance(example, trainData[neighbor]); double norm_low = MAX_NORM; double norm_high = MAX_NORM; if(distance!=0.0){ norm_low = 1.0 / Math.pow(distance, minExp); norm_high = 1.0 / Math.pow(distance, maxExp); } Interval norm = new Interval(norm_low, norm_high); for(int k = 0; k < nClasses; k++){ Interval vote = new Interval(norm); vote.timesInterval(membership[neighbor][k]); votes[k].addInterval(vote); } } return votes; }
Example #17
Source File: ReduceTask.java From hadoop-gpu with Apache License 2.0 | 5 votes |
public ShuffleRamManager(Configuration conf) throws IOException { final float maxInMemCopyUse = conf.getFloat("mapred.job.shuffle.input.buffer.percent", 0.70f); if (maxInMemCopyUse > 1.0 || maxInMemCopyUse < 0.0) { throw new IOException("mapred.job.shuffle.input.buffer.percent" + maxInMemCopyUse); } maxSize = (int)Math.min( Runtime.getRuntime().maxMemory() * maxInMemCopyUse, Integer.MAX_VALUE); maxSingleShuffleLimit = (int)(maxSize * MAX_SINGLE_SHUFFLE_SEGMENT_FRACTION); LOG.info("ShuffleRamManager: MemoryLimit=" + maxSize + ", MaxSingleShuffleLimit=" + maxSingleShuffleLimit); }
Example #18
Source File: Vector.java From GiantTrees with GNU General Public License v3.0 | 5 votes |
/** * Returns the angle of a 2-dimensional vector (u,v) with the u-axis * * @param v v-coordinate of the vector * @param u u-coordinate of the vector * @return a value from (-180..180) */ static public double atan2(double v, double u) { if (u==0) { if (v>=0) return 90; else return -90; } if (u>0) return Math.atan(v/u)*180/Math.PI; if (v>=0) return 180 + Math.atan(v/u)*180/Math.PI; return Math.atan(v/u)*180/Math.PI-180; }
Example #19
Source File: ColorUtil.java From closure-stylesheets with Apache License 2.0 | 5 votes |
/** * Convert a color in HSL color space to one in HSB color space. * * @param inputHsl HSL color in a array of three floats, 0 is Hue, 1 is * Saturation and 2 is Lightness * @return HSB color in array of three floats, 0 is Hue, 1 is * Saturation and 2 is Brightness */ static float[] hslToHsb(float[] inputHsl) { float hHsl = inputHsl[H]; float sHsl = inputHsl[S]; float lHsl = inputHsl[L]; float hHsb = hHsl; float bHsb = (2 * lHsl + sHsl * (1 - Math.abs(2 * lHsl - 1))) / 2; float sHsb = 2 * (bHsb - lHsl) / bHsb; float[] hsb = {hHsb, sHsb, bHsb}; return hsb; }
Example #20
Source File: Adap.java From KEEL with GNU General Public License v3.0 | 5 votes |
void Error_tst (MiDataset tabla_tst) { int i, j; double suma1, suma2, fuerza; for (j=0,suma1=suma2=0.0; j<tabla_tst.long_tabla; j++) { fuerza=base_reglas.FLC (tabla_tst.datos[j].ejemplo); suma1 += 0.5 * Math.pow (tabla_tst.datos[j].ejemplo[tabla.n_var_estado]-fuerza,2.0); suma2 += Math.abs (tabla_tst.datos[j].ejemplo[tabla.n_var_estado]-fuerza); } EC = suma1 / (double)tabla_tst.long_tabla; EL = suma2 / (double)tabla_tst.long_tabla; }
Example #21
Source File: SnmpStringFixed.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Constructs a new <CODE>SnmpStringFixed</CODE> from the specified <CODE>Bytes</CODE> array * with the specified length. * @param l The length of the fixed-string. * @param v The <CODE>Bytes</CODE> composing the fixed-string value. * @exception IllegalArgumentException Either the length or the <CODE>Byte</CODE> array is not valid. */ public SnmpStringFixed(int l, Byte[] v) throws IllegalArgumentException { if ((l <= 0) || (v == null)) { throw new IllegalArgumentException() ; } int length = Math.min(l, v.length); value = new byte[l] ; for (int i = 0 ; i < length ; i++) { value[i] = v[i].byteValue() ; } for (int i = length ; i < l ; i++) { value[i] = 0 ; } }
Example #22
Source File: AG.java From KEEL with GNU General Public License v3.0 | 5 votes |
private int ceil (double v) { int valor; valor = (int) Math.round(v); if ((double)valor < v) valor++; return (valor); }
Example #23
Source File: SnmpStringFixed.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Constructs a new <CODE>SnmpStringFixed</CODE> from the specified <CODE>bytes</CODE> array * with the specified length. * @param l The length of the fixed-string. * @param v The <CODE>bytes</CODE> composing the fixed-string value. * @exception IllegalArgumentException Either the length or the <CODE>byte</CODE> array is not valid. */ public SnmpStringFixed(int l, byte[] v) throws IllegalArgumentException { if ((l <= 0) || (v == null)) { throw new IllegalArgumentException() ; } int length = Math.min(l, v.length); value = new byte[l] ; for (int i = 0 ; i < length ; i++) { value[i] = v[i] ; } for (int i = length ; i < l ; i++) { value[i] = 0 ; } }
Example #24
Source File: LibMatrixCUDA.java From systemds with Apache License 2.0 | 5 votes |
/** * Get threads, blocks and shared memory for cumulative scan along columns * @param gCtx a valid {@link GPUContext} * @param rows number of rows in input matrix * @param cols number of columns in input matrix * @return integer array containing {blocks, threads, shared memory} */ private static int[] getKernelParamsForCumScan(GPUContext gCtx, int rows, int cols) { final int MAX_THREADS = getMaxThreads(gCtx); final int WARP_SIZE = getWarpSize(gCtx); final int MAX_BLOCKS_Y = gCtx.getGPUProperties().maxGridSize[1]; int t1 = cols % MAX_THREADS; int t2 = (t1 + WARP_SIZE - 1) / WARP_SIZE; int t3 = t2 * WARP_SIZE; int threads_x = gcd(MAX_THREADS, t3); int blocks_x = Math.max(1, (cols + (threads_x - 1)) / (threads_x)); int block_height = Math.max(8, MAX_THREADS / threads_x); int blocks_y = (rows + block_height - 1) / block_height; int min_loop_length = 128; if(rows <= min_loop_length) { block_height = rows; blocks_y = 1; } if(blocks_y > MAX_BLOCKS_Y) { block_height = Math.max(2 ,2 * rows / MAX_BLOCKS_Y); blocks_y = (rows + block_height - 1) / block_height; } if(LOG.isTraceEnabled()) { LOG.trace("Launch configuration for cumulative aggregate: blocks_x=" + blocks_x + " blocks_y=" + blocks_y + " block_height=" + block_height + " threads_x=" + threads_x); } return new int[] {blocks_x, blocks_y, threads_x, block_height}; }
Example #25
Source File: Statistics.java From systemsgenetics with GNU General Public License v3.0 | 5 votes |
/** * based on https://www.researchgate.net/post/How_do_you_calculate_a_p_value_for_spearmans_rank_correlation * and https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient#Determining_significance * * this is an approximation, so won't give exactly same results as R cor.test(), but with many samples and * when there is a correlation they approximate eachother * * @param spearmanCorrelation Spearman correlation from SpearmansCorrelation() * * @param sampleSize Number of samples used to calculate correlation * * @return Spearman two-tailed p-value from correlation */ public static double calculateSpearmanTwoTailedPvalue(double spearmanCorrelation, int sampleSize){ double z = Math.sqrt((sampleSize-3)/1.06) * atanh(spearmanCorrelation); NormalDistribution normalDistribution = new NormalDistribution(); double p = 2*normalDistribution.cumulativeProbability(-Math.abs(z)); if (Double.isNaN(z)){ p = 0; } if (Double.isNaN(spearmanCorrelation)){ p = 1; } return p; }
Example #26
Source File: Est_evol.java From KEEL with GNU General Public License v3.0 | 5 votes |
/** Calculates the new value of sigma according to the number of mutation with hit*/ public double AdaptacionSigma(double old_sigma, double p, double n) { /* if p<1/5, sigma lowers (c<1 -> sigma*c^(1/n)<sigma) */ if (p < 0.2) { return (old_sigma * Math.pow(c, 1.0 / n)); } /* if p>1/5, sigma increases (c<1 -> sigma/c^(1/n)>sigma)*/ if (p > 0.2) { return (old_sigma / Math.pow(c, 1.0 / n)); } /* if p=1/5, sigma doesn't change*/ return (old_sigma); }
Example #27
Source File: ArcCosine.java From Llunatic with GNU General Public License v3.0 | 5 votes |
public Object acos(Object param) throws ParseException { if (param instanceof Complex) { return ((Complex)param).acos(); } else if (param instanceof Number) { return new Double(Math.acos(((Number)param).doubleValue())); } throw new ParseException("Invalid parameter type"); }
Example #28
Source File: SnmpStringFixed.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Constructs a new <CODE>SnmpStringFixed</CODE> from the specified <CODE>Bytes</CODE> array * with the specified length. * @param l The length of the fixed-string. * @param v The <CODE>Bytes</CODE> composing the fixed-string value. * @exception IllegalArgumentException Either the length or the <CODE>Byte</CODE> array is not valid. */ public SnmpStringFixed(int l, Byte[] v) throws IllegalArgumentException { if ((l <= 0) || (v == null)) { throw new IllegalArgumentException() ; } int length = Math.min(l, v.length); value = new byte[l] ; for (int i = 0 ; i < length ; i++) { value[i] = v[i].byteValue() ; } for (int i = length ; i < l ; i++) { value[i] = 0 ; } }
Example #29
Source File: SolarSystemRenderer.java From opengl with Apache License 2.0 | 5 votes |
public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); /* * Set our projection matrix. This doesn't have to be done * each time we draw, but usually a new projection needs to * be set when the viewport is resized. */ float aspectRatio; float zNear =.1f; float zFar =1000f; float fieldOfView = 30.0f/57.3f; float size; gl.glEnable(GL10.GL_NORMALIZE); aspectRatio=(float)width/(float)height; //h/w clamps the fov to the height, flipping it would make it relative to the width //Set the OpenGL projection matrix gl.glMatrixMode(GL10.GL_PROJECTION); size = zNear * (float)(Math.tan((double)(fieldOfView/2.0f))); gl.glFrustumf(-size, size, -size/aspectRatio, size /aspectRatio, zNear, zFar); //Make the OpenGL modelview matrix the default gl.glMatrixMode(GL10.GL_MODELVIEW); }
Example #30
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)); }