@Override protected void fprop(long seed, boolean training) { for( int o = 0; o < _a.length; o++ ) { _a[o] = 0; for( int i = 0; i < _previous._a.length; i++ ) _a[o] += _w[i * _a.length + o] * _previous._a[i]; _a[o] += _b[o]; _a[o] = (float)Math.tanh(_a[o]); } }
class ASTTanh extends ASTUniPrefixOp { @Override String opStr(){ return "tanh"; } @Override ASTOp make() {return new ASTTanh ();} @Override double op(double d) { return Math.tanh(d);}}
@Override protected ExprEval eval(double param) { return ExprEval.of(Math.tanh(param)); } }
Random random = new Random(); double[] array = new double[10000000]; for (int i = 0; i < array.length; i++) { array[i] = Math.tanh(random.nextDouble()); }
public BigDecimal eval(List<? extends Number> parameters) { assertNotNull(parameters.get(0)); /** Formula: coth(x) = 1 / tanh(x) */ double one = 1; double d = Math.tanh(parameters.get(0).doubleValue()); return new BigDecimal((one / d), mc); } });
public BigDecimal eval(List<? extends Number> parameters) { assertNotNull(parameters.get(0)); double d = Math.tanh(parameters.get(0).doubleValue()); return new BigDecimal(d, mc); } });
private static double HyperTanFunction(double x) { return Math.tanh(x); }
private static double HyperTanFunction(double x) { return Math.tanh(x); }
private static double HyperTanFunction(double x) { return Math.tanh(x); }
public static double tanh(RValue x) throws EvaluationException { return Math.tanh(x.getValue()); }
public double[] hiddenLayerOutput(double[][] inputLayerWeights, int[] nodeCliqueFeatures, SeqClassifierFlags aFlag, double[] featureVal) { int layerOneSize = inputLayerWeights.length; if (layerOneCache == null || layerOneSize != layerOneCache.length) layerOneCache = new double[layerOneSize]; for (int i = 0; i < layerOneSize; i++) { double[] ws = inputLayerWeights[i]; double lOneW = 0; for (int m = 0; m < nodeCliqueFeatures.length; m++) { double dotProd = ws[nodeCliqueFeatures[m]]; if (featureVal != null) dotProd *= featureVal[m]; lOneW += dotProd; } layerOneCache[i] = lOneW; } if (!aFlag.useHiddenLayer) return layerOneCache; // transform layer one through hidden if (hiddenLayerCache == null || layerOneSize != hiddenLayerCache.length) hiddenLayerCache = new double[layerOneSize]; for (int i = 0; i < layerOneSize; i++) { if (aFlag.useSigmoid) { hiddenLayerCache[i] = sigmoid(layerOneCache[i]); } else { hiddenLayerCache[i] = Math.tanh(layerOneCache[i]); } } return hiddenLayerCache; }
hlCache[i] = sigmoid(layerCache[i]); } else { hlCache[i] = Math.tanh(layerCache[i]);
/** * The hyperbolic tangent. * * @param x The argument. * @return The tanh(x) = sinh(x)/cosh(x). */ static public BigDecimal tanh(final BigDecimal x) { if (x.compareTo(BigDecimal.ZERO) < 0) { return tanh(x.negate()).negate(); } else if (x.compareTo(BigDecimal.ZERO) == 0) { return BigDecimal.ZERO; } else { BigDecimal xhighpr = scalePrec(x, 2); /* tanh(x) = (1-e^(-2x))/(1+e^(-2x)) . */ BigDecimal exp2x = exp(xhighpr.multiply(new BigDecimal(-2))); /* The error in tanh x is err(x)/cosh^2(x). */ double eps = 0.5 * x.ulp().doubleValue() / Math.pow(Math.cosh(x.doubleValue()), 2.0); MathContext mc = new MathContext(err2prec(Math.tanh(x.doubleValue()), eps)); return BigDecimal.ONE.subtract(exp2x).divide(BigDecimal.ONE.add(exp2x), mc); } } /* BigDecimalMath.tanh */
a = Math.sqrt(1.0); a = Math.tan(0.0); a = Math.tanh(0.0); a = Math.toDegrees(0.0); a = Math.toDegrees(1.0);
@Description("hyperbolic tangent") @ScalarFunction @SqlType(StandardTypes.DOUBLE) public static double tanh(@SqlType(StandardTypes.DOUBLE) double num) { return Math.tanh(num); }
double eps = Math.tanh(x.doubleValue()); MathContext mc = new MathContext(err2prec(0.5 * x.ulp().doubleValue() / eps));
/** * Applies tanh to each of the entries in the matrix. Returns a new matrix. */ public static SimpleMatrix elementwiseApplyTanh(SimpleMatrix input) { SimpleMatrix output = new SimpleMatrix(input); for (int i = 0; i < output.numRows(); ++i) { for (int j = 0; j < output.numCols(); ++j) { output.set(i, j, Math.tanh(output.get(i, j))); } } return output; }
double distance = Math.sqrt(1 - Math.tanh(itemCorrs.get(posItemIdx, negItemIdx) * simFilter)); double itemWeightValue = itemWeights.get(negItemIdx);
break; case TANH: result = ValueDouble.get(Math.tanh(v0.getDouble())); break; case SECURE_RAND: