當前位置: 首頁>>代碼示例>>Java>>正文


Java Math.pow方法代碼示例

本文整理匯總了Java中java.lang.Math.pow方法的典型用法代碼示例。如果您正苦於以下問題:Java Math.pow方法的具體用法?Java Math.pow怎麽用?Java Math.pow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.Math的用法示例。


在下文中一共展示了Math.pow方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: k

import java.lang.Math; //導入方法依賴的package包/類
@Override
public double k(double[] x, double[] y) {
    if (x.length != y.length)
        throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));
    
    //Inner product
    double xx = 0;
    double yy = 0;
    double xy = 0;
    for (int i = 0; i < x.length; i++){
        xx += x[i] * x[i];
        yy += y[i] * y[i];
        xy += x[i] * y[i];
    }
    
    double m = constant * Math.sqrt(-2.0 * xy + xx + yy);
    return 1.0 / Math.pow(1.0 + m * m, omega);

}
 
開發者ID:takun2s,項目名稱:smile_1.5.0_java7,代碼行數:20,代碼來源:PearsonKernel.java

示例2: k

import java.lang.Math; //導入方法依賴的package包/類
@Override
public double k(int[] x, int[] y) {
    double dot = 0.0;

    for (int p1 = 0, p2 = 0; p1 < x.length && p2 < y.length; ) {
        int i1 = x[p1];
        int i2 = y[p2];
        if (i1 == i2) {
            dot++;
            p1++;
            p2++;
        } else if (i1 > i2) {
            p2++;
        } else {
            p1++;
        }
    }

    return Math.pow(scale * dot + offset, degree);
}
 
開發者ID:takun2s,項目名稱:smile_1.5.0_java7,代碼行數:21,代碼來源:BinarySparsePolynomialKernel.java

示例3: RandomCircleSet

import java.lang.Math; //導入方法依賴的package包/類
public RandomCircleSet(int kappa, int numAlter, int numFeature, int size) {
this.kappa = kappa;
this.numAlter = numAlter;
this.numFeature = numFeature;
mu = (int)Math.ceil((double)numFeature/(double)kappa);
this.size = size;
counter = 0;

long a, f;
a = (long)Math.pow(2, numAlter);
f = (long)Math.pow(2, numFeature);
long s = 1;
for(long i=1; i<=kappa; i++) {
    s *= (a-i);
    s *= (f-i);
    s /= i;
}
System.out.println("The RandomCircleSet iterator generate " + size + " out of " + s + " possibilities.");
   }
 
開發者ID:uraplutonium,項目名稱:teabag-ml,代碼行數:20,代碼來源:RandomCircleSet.java

示例4: clickedOn

import java.lang.Math; //導入方法依賴的package包/類
/**
 * checks if pt is on root and calls itself recursivly to check root's children
 * @param pt the point we want to check the location of
 * @param root the message we want to check if the point is on
 * @return root if pt is on it, null otherwise
 * @author Paul Best
 */
public Message clickedOn(Point pt, Message root){
    Message answer;
    for(int i = 0; i<root.getChildren().size();i++){
        answer = clickedOn(pt,root.getChildren().get(i));
        if(answer!=null){
            return  answer;
        }
    }
    if(Math.pow(Math.pow(pt.x/mScaleFactor-(root.getGoval().getX()+mPosX/mScaleFactor),2)+Math.pow(pt.y/mScaleFactor-(root.getGoval().getY()+mPosY/mScaleFactor),2),0.5)<root.getGoval().getRay()){
        return root;
    }
    else{
        return null;
    }
}
 
開發者ID:jkobject,項目名稱:PiPle,代碼行數:23,代碼來源:Window.java

示例5: getBoard

import java.lang.Math; //導入方法依賴的package包/類
public String getBoard(){
    String result="";
    int counter=2;
    int sum=0;
    ArrayList<Integer> triplets = new ArrayList<Integer>();
    for(int x=0; x<WIDTH; x++){
        for(int y=HEIGHT-1;y>=0;y--){
            Tile t=allTiles[x][y];
            sum+=(Math.pow(4,counter)*t.getState());
            if(counter==0){
                triplets.add(sum);
                sum=0;
                counter=3;
            }
            counter--;
        }
    }
    if(counter!=2){
        triplets.add(sum);
    }
    for(int i:triplets){
        result+=charTable.toCharArray()[i];
    }
    return result;
}
 
開發者ID:hanss314,項目名稱:GOLAD,代碼行數:26,代碼來源:MyWorld.java

示例6: stirf

import java.lang.Math; //導入方法依賴的package包/類
/**
     * Stirf double.
     *
     * @param x the x
     * @return the double
     * @throws ArithmeticException the arithmetic exception
     */
/* Gamma function computed by Stirling's formula.
     * The polynomial STIR is valid for 33 <= x <= 172.

    Cephes Math Library Release 2.2:  July, 1992
    Copyright 1984, 1987, 1989, 1992 by Stephen L. Moshier
    Direct inquiries to 30 Frost Street, Cambridge, MA 02140
    */
    static private double stirf(double x) throws ArithmeticException {
        double STIR[] = {
                7.87311395793093628397E-4,
                -2.29549961613378126380E-4,
                -2.68132617805781232825E-3,
                3.47222221605458667310E-3,
                8.33333333333482257126E-2,
        };
        double MAXSTIR = 143.01608;

        double w = 1.0/x;
        double  y = Math.exp(x);

        w = 1.0 + w * polevl( w, STIR, 4 );

        if( x > MAXSTIR ) {
	       /* Avoid overflow in Math.pow() */
            double v = Math.pow( x, 0.5 * x - 0.25 );
            y = v * (v / y);
        } else {
            y = Math.pow( x, x - 0.5 ) / y;
        }
        y = SQTPI * y * w;
        return y;
    }
 
開發者ID:RudyB,項目名稱:Optics-Simulator,代碼行數:40,代碼來源:SpecialFunction.java

示例7: pseries

import java.lang.Math; //導入方法依賴的package包/類
/**
 * Pseries double.
 *
 * @param a the a
 * @param b the b
 * @param x the x
 * @return the double
 * @throws ArithmeticException the arithmetic exception
 */
static private  double pseries( double a, double b, double x )
        throws ArithmeticException {
    double s, t, u, v, n, t1, z, ai;

    ai = 1.0 / a;
    u = (1.0 - b) * x;
    v = u / (a + 1.0);
    t1 = v;
    t = u;
    n = 2.0;
    s = 0.0;
    z = MACHEP * ai;
    while( Math.abs(v) > z ) {
        u = (n - b) * x / n;
        t *= u;
        v = t / (a + n);
        s += v;
        n += 1.0;
    }
    s += t1;
    s += ai;

    u = a * Math.log(x);
    if( (a+b) < MAXGAM && Math.abs(u) < MAXLOG ) {
        t = gamma(a+b)/(gamma(a)*gamma(b));
        s = s * t * Math.pow(x,a);
    } else {
        t = lgamma(a+b) - lgamma(a) - lgamma(b) + u + Math.log(s);
        if( t < MINLOG ) 	s = 0.0;
        else  	            s = Math.exp(t);
    }
    return s;
}
 
開發者ID:RudyB,項目名稱:Optics-Simulator,代碼行數:43,代碼來源:SpecialFunction.java

示例8: computeSpearmanCorrelation

import java.lang.Math; //導入方法依賴的package包/類
public static double computeSpearmanCorrelation(double[] rank_0, double[] rank_1)
{
	double rho = -1;
	double num = 0;
	double den = 0;
	for(int i = 0; i < rank_0.length; i++)
		num += Math.pow((rank_0[i] - rank_1[i]),2);
	den = rank_0.length * (Math.pow(rank_0.length, 2) - 1);
	if(den == 0)
		return rho;
	rho = 1 - 6*num/den;
	return rho;
}
 
開發者ID:cgraywang,項目名稱:TextHIN,代碼行數:14,代碼來源:SimilarityMeasures.java

示例9: series_2

import java.lang.Math; //導入方法依賴的package包/類
void series_2(int n){
double sum = 1;
for(int i=1; i<n; i++)
{
    if(n > 1){

    sum += 1/Math.pow(2,i);
    }else{
        sum = 1;
        break;
    }
}

System.out.println("Sum for "+n+" terms: "+sum);
}
 
開發者ID:nvzard,項目名稱:Java-Lab-Programs,代碼行數:16,代碼來源:series.java

示例10: getChunk

import java.lang.Math; //導入方法依賴的package包/類
public static long getChunk(int chunk, int num) {
	// Get rid of numbers before
	num %= Math.pow(10, chunk * 5);
	// Get rid of numbers after chunk
	num /= Math.pow(10, (chunk - 1) * 5);

	return num;
}
 
開發者ID:walldaniel,項目名稱:SchoolProjects,代碼行數:9,代碼來源:test.java

示例11: calculateVariance

import java.lang.Math; //導入方法依賴的package包/類
public static double calculateVariance(int [] population, int n){

        double mean = calculateMean(population,n);

        double sum = 0;
        for(int i : population){
            double temp = (double) i - mean;
            sum += Math.pow(temp,2);
        }

        return sum/n;
    }
 
開發者ID:BaReinhard,項目名稱:Hacktoberfest-Mathematics,代碼行數:13,代碼來源:Variance.java

示例12: norm

import java.lang.Math; //導入方法依賴的package包/類
public double norm(double[] v, int p) {
    int nLen = v.length;    // get the length of the vector
    double sum = 0;         // the sum of the powers
    for (int i = 0; i < nLen; i++) {        // sum up the powers
        sum += Math.pow(v[i], (double)p);
    }
    return Math.pow(sum, (double)1/p);
}
 
開發者ID:Driveron,項目名稱:Notes,代碼行數:9,代碼來源:Norm.java

示例13: main

import java.lang.Math; //導入方法依賴的package包/類
public static void main(String[] args) {
    double number = 4.321;
    number = Math.pow(number, 4.0);
    System.out.println(number);
}
 
開發者ID:PacktPublishing,項目名稱:Java-Programming-for-Beginners,代碼行數:6,代碼來源:TheMathLib.java

示例14: CircleSet

import java.lang.Math; //導入方法依賴的package包/類
public CircleSet(int kappa, int numAlter, int numFeature) {
this.kappa = kappa;
this.numAlter = numAlter;
this.numFeature = numFeature;

int a, f;
a = (int)Math.pow(2, numAlter);
f = (int)Math.pow(2, numFeature);
int s = 1;
for(int i=1; i<=kappa; i++) {
    s *= (a-i);
    s *= (f-i);
    s /= i;
}
size = s;

System.out.println("!!!!!!!! THERE ARE " + size + " POSSIBILITIES !!!!!!!!");

circleSet = new Circle[kappa];
for(int i=0; i<kappa; i++)
    circleSet[i] = new Circle(numAlter, numFeature);

featPermunationiter = new BCPPermutation(kappa, numFeature);
for(int i=0; i<kappa; i++) {
    for(int j=0; j<numFeature; j++) {
	circleSet[i].removeFeature(j);
    }
}
    
alterCombinationiter = new BCPCombination(kappa, numAlter);
System.out.println("alterCombinationiter.size():" + alterCombinationiter.size());
int[][] firstAlterCombination = alterCombinationiter.iterator().next();
for(int i=0; i<kappa; i++) {
    for(int j=0; j<numAlter; j++) {
	System.out.println("i:" + i + " j:" + j);
	if(firstAlterCombination[i][j] == 1)
	    circleSet[i].addAlter(j);
	else
	    circleSet[i].removeAlter(j);
    }
}
   }
 
開發者ID:uraplutonium,項目名稱:teabag-ml,代碼行數:43,代碼來源:CircleSet.java

示例15: size

import java.lang.Math; //導入方法依賴的package包/類
@Override
   public int size() {
return (int)Math.pow(2, numElement)-1;
   }
 
開發者ID:uraplutonium,項目名稱:teabag-ml,代碼行數:5,代碼來源:BinaryCartesianProduct.java


注:本文中的java.lang.Math.pow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。