List of usage examples for java.lang Math tanh
public static double tanh(double x)
From source file:Main.java
public static void main(String[] args) { double x = 45; double y = -180; // convert them in radians x = Math.toRadians(x);//from www. j av a 2 s . com y = Math.toRadians(y); // print the hyperbolic tangent of these doubles System.out.println("Math.tanh(" + x + ")=" + Math.tanh(x)); System.out.println("Math.tanh(" + y + ")=" + Math.tanh(y)); }
From source file:conceptor.Util.java
static void tanh(DenseMatrix64F x) { double[] d = x.data; for (int i = 0; i < x.elements; i++) { d[i] = Math.tanh(d[i]); }//from w w w . ja v a 2 s. c o m }
From source file:com.wwidesigner.geometry.calculation.DefaultHoleCalculator.java
public TransferMatrix calcTransferMatrix_2010(Hole hole, boolean isOpen, double waveNumber, PhysicalParameters parameters) { double radius = mFudgeFactor * hole.getDiameter() / 2; double boreRadius = hole.getBoreDiameter() / 2; Complex Zs = null;/*from w ww. j av a 2 s .com*/ Complex Za = null; // double Z0 = parameters.calcZ0(boreRadius); double Z0h = parameters.calcZ0(radius); double delta = radius / boreRadius; double tm = (radius * delta / 8.) * (1. + 0.207 * delta * delta * delta); double te = hole.getHeight() + tm; double ta = 0.; // Complex Gamma = Complex.I.multiply(wave_number); if (isOpen) // open { double kb = waveNumber * radius; double ka = waveNumber * boreRadius; double xhi = 0.25 * kb * kb; ta = (-0.35 + 0.06 * Math.tanh(2.7 * hole.getHeight() / radius)) * radius * delta * delta * delta * delta; Complex Zr = Complex.I.multiply(waveNumber * 0.61 * radius).add(xhi); Complex Zo = (Zr.multiply(Math.cos(waveNumber * te)).add(Complex.I.multiply(Math.sin(waveNumber * te)))) .divide(Complex.I.multiply(Zr).multiply(Math.sin(waveNumber * te)) .add(Math.cos(waveNumber * te))); double ti = radius * (0.822 - 0.10 * delta - 1.57 * delta * delta + 2.14 * delta * delta * delta - 1.6 * delta * delta * delta * delta + 0.50 * delta * delta * delta * delta * delta) * (1. + (1. - 4.56 * delta + 6.55 * delta * delta) * (0.17 * ka + 0.92 * ka * ka + 0.16 * ka * ka * ka - 0.29 * ka * ka * ka * ka)); Zs = Complex.I.multiply(waveNumber * ti).add(Zo).multiply(Z0h); } else { ta = (-0.12 - 0.17 * Math.tanh(2.4 * hole.getHeight() / radius)) * radius * delta * delta * delta * delta; Zs = Complex.valueOf(0, -Z0h / Math.tan(waveNumber * te)); } Za = Complex.I.multiply(Z0h * waveNumber * ta); Complex Za_Zs = Za.divide(Zs); TransferMatrix result = new TransferMatrix(Za_Zs.divide(2.).add(1.), Za.multiply(Za_Zs.divide(4.).add(1.)), Complex.ONE.divide(Zs), Za_Zs.divide(2.0).add(1.)); assert result.determinant() == Complex.ONE; return result; }
From source file:com.opengamma.analytics.math.TrigonometricFunctionUtils.java
public static double tanh(final double x) { return Math.tanh(x); }
From source file:gr.iit.demokritos.cru.cps.ai.MachineLearningComponents.java
public static Vec CalculateUserProfile(double[] LastN, double[] LastS, double[] LastR, double[] LastE, double[] w, int D, double visionary, double constructive, ArrayList<User> group) { double OldCreativityX = visionary; //!!!!!!!!!!!!!!get old user's X,Y double OldCreativityY = constructive; try {//from w ww .j a v a 2 s .c om Vec UserVec = UserCreativity(LastN, LastS, LastR, LastE, w, D); Vec AverageGroupVec = new Vec(0, 0); int NumberOfGroups = group.size(); for (int i = 0; i < NumberOfGroups; i++) { //!!!!!!!!!!!!!!!get last metrics of each group double x = (Double) group.get(i).getUps().get(0).getProperty_value(); double y = (Double) group.get(i).getUps().get(1).getProperty_value(); AverageGroupVec.x += x / NumberOfGroups; AverageGroupVec.y += y / NumberOfGroups; } double x = UserVec.x; double y = UserVec.y; //if the group's metrics are greater, change the UserVector to include the group's achievments if (UserVec.x < AverageGroupVec.x) { double k = 1 / 2 + 1 / 2 + Math.tanh(2 * ((AverageGroupVec.x - UserVec.x) - 1)); x = UserVec.x + k * (AverageGroupVec.x - UserVec.x); } if (UserVec.y < AverageGroupVec.y) { double k = 1 / 2 + 1 / 2 + Math.tanh(2 * ((AverageGroupVec.x - UserVec.x) - 1)); y = UserVec.y + k * (AverageGroupVec.y - UserVec.y); } UserVec = new Vec(x, y); Vec Creativity = new Vec(UserVec.x / D + (D - 1) * OldCreativityX / D, UserVec.y / D + (D - 1) * OldCreativityY / D); return Creativity; } catch (MWException ex) { Logger.getLogger(MachineLearningComponents.class.getName()).log(Level.SEVERE, null, ex); return new Vec(0, 0); } }
From source file:com.duy.pascal.interperter.libraries.math.MathLib.java
@PascalMethod(description = "") public double Tanh(double d) { return Math.tanh(d); }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java
/** * Returns the hyperbolic tangent of the number. * //from w w w. j a va2s .co m * @param a the number * @return the hyperbolic tangent of the number * @see Math#tanh(double) */ public static Number tanh(Number a) { return Math.tanh(a.doubleValue()); }
From source file:msi.gaml.operators.Maths.java
@operator(value = "tanh", can_be_const = true) @doc(value = "Returns the value (in the interval [-1,1]) of the hyperbolic tangent of the operand (which can be any real number, expressed in decimal degrees).", masterDoc = true, examples = { @example(value = "tanh(0)", equals = "0.0"), @example(value = "tanh(100)", equals = "1.0") }) public static Double tanh(final Double rv) { return Math.tanh(rv); }
From source file:msi.gaml.operators.Maths.java
@operator(value = "tanh", can_be_const = true, category = { IOperatorCategory.ARITHMETIC }) @doc(value = "the hyperbolic tangent of the operand (which has to be expressed in decimal degrees).") public static Double tanh(final Integer rv) { return Math.tanh(rv); }
From source file:edu.cmu.tetrad.search.FastIca.java
private TetradMatrix icaDeflation(TetradMatrix X, int numComponents, double tolerance, int function, double alpha, int maxIterations, boolean verbose, TetradMatrix wInit) { if (verbose && function == LOGCOSH) { TetradLogger.getInstance().log("info", "Deflation FastIca using lgcosh approx. to neg-entropy function"); }/* w ww .jav a2s. c om*/ if (verbose && function == EXP) { TetradLogger.getInstance().log("info", "Deflation FastIca using exponential approx. to neg-entropy function"); } int p = X.columns(); TetradMatrix W = new TetradMatrix(numComponents, numComponents); for (int i = 0; i < numComponents; i++) { if (verbose) { TetradLogger.getInstance().log("fastIcaDetails", "Component " + (i + 1)); } TetradVector w = wInit.getRow(i); if (i > 0) { TetradVector t = w.like(); for (int u = 0; u < i; u++) { double k = 0.0; for (int j = 0; j < numComponents; j++) { k += w.get(j) * W.get(u, j); } for (int j = 0; j < numComponents; j++) { t.set(j, t.get(j) + k * W.get(u, j)); } } for (int j = 0; j < numComponents; j++) { w.set(j, w.get(j) - t.get(j)); } } double rms = rms(w); for (int j = 0; j < numComponents; j++) { w.set(j, w.get(j) / rms); } int it = 0; double _tolerance = Double.POSITIVE_INFINITY; if (function == LOGCOSH) { while (_tolerance > tolerance && ++it <= maxIterations) { TetradVector wx = X.transpose().times(w); TetradVector gwx0 = new TetradVector(p); for (int j = 0; j < p; j++) { gwx0.set(j, Math.tanh(alpha * wx.get(j))); } TetradMatrix gwx = new TetradMatrix(numComponents, p); for (int _i = 0; _i < numComponents; _i++) { for (int j = 0; j < p; j++) { gwx.set(_i, j, gwx0.get(j)); } } TetradMatrix xgwx = new TetradMatrix(numComponents, p); for (int _i = 0; _i < numComponents; _i++) { for (int j = 0; j < p; j++) { xgwx.set(_i, j, X.get(_i, j) * gwx0.get(j)); } } TetradVector v1 = new TetradVector(numComponents); for (int k = 0; k < numComponents; k++) { v1.set(k, mean(xgwx.getRow(k))); } TetradVector g_wx = new TetradVector(p); for (int k = 0; k < p; k++) { double tmp1 = Math.tanh(alpha * wx.get(k)); g_wx.set(k, alpha * (1.0 - tmp1 * tmp1)); } TetradVector v2 = w.copy(); double meanGwx = mean(g_wx); v2 = v2.scalarMult(meanGwx); TetradVector w1 = v1.copy(); // w1.assign(v2, PlusMult.plusMult(-1)); w1 = w1.minus(v2); if (i > 0) { TetradVector t = w1.like(); for (int u = 0; u < i; u++) { double k = 0.0; for (int j = 0; j < numComponents; j++) { k += w1.get(j) * W.get(u, j); } for (int j = 0; j < numComponents; j++) { t.set(j, t.get(j) + k * W.get(u, j)); } } for (int j = 0; j < numComponents; j++) { w1.set(j, w1.get(j) - t.get(j)); } } double _rms = rms(w1); for (int k = 0; k < numComponents; k++) { w1.set(k, w1.get(k) / _rms); } _tolerance = 0.0; for (int k = 0; k < numComponents; k++) { _tolerance += w1.get(k) * w.get(k); } _tolerance = Math.abs(Math.abs(_tolerance) - 1.0); if (verbose) { TetradLogger.getInstance().log("fastIcaDetails", "Iteration " + it + " tol = " + _tolerance); } w = w1; } } else if (function == EXP) { while (_tolerance > tolerance && ++it <= maxIterations) { TetradVector wx = X.transpose().times(w); TetradVector gwx0 = new TetradVector(p); for (int j = 0; j < p; j++) { gwx0.set(j, wx.get(j) * Math.exp(-(wx.get(j) * wx.get(j)) / 2)); } TetradMatrix gwx = new TetradMatrix(numComponents, p); for (int _i = 0; _i < numComponents; _i++) { for (int j = 0; j < p; j++) { gwx.set(_i, j, gwx0.get(j)); } } TetradMatrix xgwx = new TetradMatrix(numComponents, p); for (int _i = 0; _i < numComponents; _i++) { for (int j = 0; j < p; j++) { xgwx.set(_i, j, X.get(_i, j) * gwx0.get(j)); } } TetradVector v1 = new TetradVector(numComponents); for (int k = 0; k < numComponents; k++) { v1.set(k, mean(xgwx.getRow(k))); } TetradVector g_wx = new TetradVector(p); for (int j = 0; j < p; j++) { g_wx.set(j, (1.0 - wx.get(j) * wx.get(j)) * Math.exp(-(wx.get(j) * wx.get(j)) / 2)); } TetradVector v2 = w.copy(); double meanGwx = mean(g_wx); TetradVector w1 = v2.scalarMult(meanGwx).minus(v2); // TetradVector w1 = v1.copy(); // w1.assign(v2, PlusMult.plusMult(-1)); if (i > 0) { TetradVector t = w1.like(); for (int u = 0; u < i; u++) { double k = 0.0; for (int j = 0; j < numComponents; j++) { k += w1.get(j) * W.get(u, j); } for (int j = 0; j < numComponents; j++) { t.set(j, t.get(j) + k * W.get(u, j)); } } for (int j = 0; j < numComponents; j++) { w1.set(j, w1.get(j) - t.get(j)); } } double _rms = rms(w1); for (int k = 0; k < numComponents; k++) { w1.set(k, w1.get(k) / _rms); } _tolerance = 0.0; for (int k = 0; k < numComponents; k++) { _tolerance += w1.get(k) * w.get(k); } _tolerance = Math.abs(Math.abs(_tolerance) - 1.0); if (verbose) { TetradLogger.getInstance().log("fastIcaDetails", "Iteration " + it + " tol = " + _tolerance); } w = w1; } } W.assignRow(i, w); } return W; }