本文整理匯總了Java中java.lang.Math.exp方法的典型用法代碼示例。如果您正苦於以下問題:Java Math.exp方法的具體用法?Java Math.exp怎麽用?Java Math.exp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.Math
的用法示例。
在下文中一共展示了Math.exp方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: k
import java.lang.Math; //導入方法依賴的package包/類
@Override
public double k(int[] x, int[] y) {
double d = 0.0;
int p1 = 0, p2 = 0;
while (p1 < x.length && p2 < y.length) {
int i1 = x[p1];
int i2 = y[p2];
if (i1 == i2) {
p1++;
p2++;
} else if (i1 > i2) {
d++;
p2++;
} else {
d++;
p1++;
}
}
d += x.length - p1;
d += y.length - p2;
return Math.exp(-gamma * d);
}
示例2: k
import java.lang.Math; //導入方法依賴的package包/類
@Override
public double k(int[] x, int[] y) {
if (x.length != y.length)
throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));
double d = 0.0;
int p1 = 0, p2 = 0;
while (p1 < x.length && p2 < y.length) {
int i1 = x[p1];
int i2 = y[p2];
if (i1 == i2) {
p1++;
p2++;
} else if (i1 > i2) {
d++;
p2++;
} else {
d++;
p1++;
}
}
d += x.length - p1;
d += y.length - p2;
return Math.exp(-gamma * Math.sqrt(d));
}
示例3: cosh
import java.lang.Math; //導入方法依賴的package包/類
/**
* Cosh double.
*
* @param x a double value
* @return the hyperbolic cosine of the argument
* @throws ArithmeticException the arithmetic exception
*/
static public double cosh(double x) throws ArithmeticException {
double a;
a = x;
if( a < 0.0 ) a = Math.abs(x);
a = Math.exp(a);
return 0.5*(a+1/a);
}
示例4: sinh
import java.lang.Math; //導入方法依賴的package包/類
/**
* Sinh double.
*
* @param x a double value
* @return the hyperbolic sine of the argument
* @throws ArithmeticException the arithmetic exception
*/
static public double sinh(double x) throws ArithmeticException {
double a;
if(x == 0.0) return x;
a = x;
if( a < 0.0 ) a = Math.abs(x);
a = Math.exp(a);
if( x < 0.0 ) return -0.5*(a-1/a);
else return 0.5*(a-1/a);
}
示例5: tanh
import java.lang.Math; //導入方法依賴的package包/類
/**
* Tanh double.
*
* @param x a double value
* @return the hyperbolic tangent of the argument
* @throws ArithmeticException the arithmetic exception
*/
static public double tanh(double x) throws ArithmeticException {
double a;
if( x == 0.0 ) return x;
a = x;
if( a < 0.0 ) a = Math.abs(x);
a = Math.exp(2.0*a);
if(x < 0.0 ) return -( 1.0-2.0/(a+1.0) );
else return ( 1.0-2.0/(a+1.0) );
}
示例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;
}
示例7: igam
import java.lang.Math; //導入方法依賴的package包/類
/**
* Igam double.
*
* @param a double value
* @param x double value
* @return the Incomplete Gamma function. Converted to Java from<BR> Cephes Math Library Release
* 2.2: July, 1992<BR> Copyright 1984, 1987, 1989, 1992 by Stephen L. Moshier<BR> Direct inquiries to 30 Frost
* Street, Cambridge, MA 02140<BR>
* @throws ArithmeticException the arithmetic exception
*/
static public double igam(double a, double x)
throws ArithmeticException {
double ans, ax, c, r;
if( x <= 0 || a <= 0 ) return 0.0;
if( x > 1.0 && x > a ) return 1.0 - igamc(a,x);
/* Compute x**a * exp(-x) / gamma(a) */
ax = a * Math.log(x) - x - lgamma(a);
if( ax < -MAXLOG ) return( 0.0 );
ax = Math.exp(ax);
/* power series */
r = a;
c = 1.0;
ans = 1.0;
do {
r += 1.0;
c *= x/r;
ans += c;
}
while( c/ans > MACHEP );
return( ans * ax/a );
}
示例8: 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;
}
示例9: doNonlinearity
import java.lang.Math; //導入方法依賴的package包/類
private float doNonlinearity(float x) {
if (nonlinearity.equals("relu")) {
return x < 0 ? 0 : x;
} else if (nonlinearity.equals("sigmoid")) {
return (float)(1 / (1 + Math.exp(-x)));
} else {
return x;
}
}
示例10: igamc
import java.lang.Math; //導入方法依賴的package包/類
/**
* Igamc double.
*
* @param a double value
* @param x double value
* @return the Complemented Incomplete Gamma function.Converted to Java from<BR> Cephes Math
* Library Release 2.2: July, 1992<BR> Copyright 1984, 1987, 1989, 1992 by Stephen L. Moshier<BR> Direct inquiries
* to 30 Frost Street, Cambridge, MA 02140<BR>
* @throws ArithmeticException the arithmetic exception
*/
static public double igamc( double a, double x )
throws ArithmeticException {
double big = 4.503599627370496e15;
double biginv = 2.22044604925031308085e-16;
double ans, ax, c, yc, r, t, y, z;
double pk, pkm1, pkm2, qk, qkm1, qkm2;
if( x <= 0 || a <= 0 ) return 1.0;
if( x < 1.0 || x < a ) return 1.0 - igam(a,x);
ax = a * Math.log(x) - x - lgamma(a);
if( ax < -MAXLOG ) return 0.0;
ax = Math.exp(ax);
/* continued fraction */
y = 1.0 - a;
z = x + y + 1.0;
c = 0.0;
pkm2 = 1.0;
qkm2 = x;
pkm1 = x + 1.0;
qkm1 = z * x;
ans = pkm1/qkm1;
do {
c += 1.0;
y += 1.0;
z += 2.0;
yc = y * c;
pk = pkm1 * z - pkm2 * yc;
qk = qkm1 * z - qkm2 * yc;
if( qk != 0 ) {
r = pk/qk;
t = Math.abs( (ans - r)/r );
ans = r;
} else
t = 1.0;
pkm2 = pkm1;
pkm1 = pk;
qkm2 = qkm1;
qkm1 = qk;
if( Math.abs(pk) > big ) {
pkm2 *= biginv;
pkm1 *= biginv;
qkm2 *= biginv;
qkm1 *= biginv;
}
} while( t > MACHEP );
return ans * ax;
}