java.lang.Math.tanh()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(153)

本文整理了Java中java.lang.Math.tanh()方法的一些代码示例,展示了Math.tanh()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Math.tanh()方法的具体详情如下:
包路径:java.lang.Math
类名称:Math
方法名:tanh

Math.tanh介绍

[英]Returns the closest double approximation of the hyperbolic tangent of the argument. The absolute value is always less than 1. The returned result is within 2.5 ulps (units in the last place) of the real result. If the real result is within 0.5ulp of 1 or -1, it should return exactly +1 or -1.

Special cases:

  • tanh(+0.0) = +0.0
  • tanh(-0.0) = -0.0
  • tanh(+infinity) = +1.0
  • tanh(-infinity) = -1.0
  • tanh(NaN) = NaN
    [中]返回参数双曲正切的最接近的双近似值。绝对值始终小于1。返回的结果与实际结果相差2.5 ulps(最后一位为单位)。如果实际结果在1或-1的0.5ulp范围内,则应精确返回+1或-1。
    特殊情况:
    *tanh(+0.0)=+0.0
    *tanh(-0.0)=-0.0
    *tanh(+无穷大)=+1.0
    *tanh(-无穷大)=-1.0
    *tanh(NaN)=NaN

代码示例

代码示例来源:origin: h2oai/h2o-2

@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]);
 }
}

代码示例来源:origin: h2oai/h2o-2

class ASTTanh extends ASTUniPrefixOp { @Override String opStr(){ return "tanh";  } @Override ASTOp make() {return new ASTTanh ();} @Override double op(double d) { return Math.tanh(d);}}

代码示例来源:origin: apache/incubator-druid

@Override
 protected ExprEval eval(double param)
 {
  return ExprEval.of(Math.tanh(param));
 }
}

代码示例来源:origin: stackoverflow.com

Random random = new Random();
double[] array = new double[10000000];
for (int i = 0; i < array.length; i++) {
  array[i] = Math.tanh(random.nextDouble());
}

代码示例来源:origin: plantuml/plantuml

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);
  }
});

代码示例来源:origin: plantuml/plantuml

public BigDecimal eval(List<? extends Number> parameters) {
    assertNotNull(parameters.get(0));
    double d = Math.tanh(parameters.get(0).doubleValue());
    return new BigDecimal(d, mc);
  }
});

代码示例来源:origin: h2oai/h2o-3

private static double HyperTanFunction(double x) {
 return Math.tanh(x);
}

代码示例来源:origin: h2oai/h2o-2

private static double HyperTanFunction(double x) {
 return Math.tanh(x);
}

代码示例来源:origin: h2oai/h2o-2

private static double HyperTanFunction(double x) {
 return Math.tanh(x);
}

代码示例来源:origin: EngineHub/WorldEdit

public static double tanh(RValue x) throws EvaluationException {
  return Math.tanh(x.getValue());
}

代码示例来源:origin: stanfordnlp/CoreNLP

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;
}

代码示例来源:origin: stanfordnlp/CoreNLP

hlCache[i] = sigmoid(layerCache[i]);
} else {
 hlCache[i] = Math.tanh(layerCache[i]);

代码示例来源:origin: deeplearning4j/nd4j

/**
 * 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 */

代码示例来源:origin: spotbugs/spotbugs

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);

代码示例来源:origin: prestodb/presto

@Test
public void testTanh()
{
  for (double doubleValue : DOUBLE_VALUES) {
    assertFunction("tanh(" + doubleValue + ")", DOUBLE, Math.tanh(doubleValue));
    assertFunction("tanh(REAL '" + doubleValue + "')", DOUBLE, Math.tanh((float) doubleValue));
  }
  assertFunction("tanh(NULL)", DOUBLE, null);
}

代码示例来源:origin: prestodb/presto

@Description("hyperbolic tangent")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double tanh(@SqlType(StandardTypes.DOUBLE) double num)
{
  return Math.tanh(num);
}

代码示例来源:origin: deeplearning4j/nd4j

double eps = Math.tanh(x.doubleValue());
MathContext mc = new MathContext(err2prec(0.5 * x.ulp().doubleValue() / eps));

代码示例来源:origin: stanfordnlp/CoreNLP

/**
 * 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;
}

代码示例来源:origin: guoguibing/librec

double distance = Math.sqrt(1 - Math.tanh(itemCorrs.get(posItemIdx, negItemIdx) * simFilter));
double itemWeightValue = itemWeights.get(negItemIdx);

代码示例来源:origin: com.h2database/h2

break;
case TANH:
  result = ValueDouble.get(Math.tanh(v0.getDouble()));
  break;
case SECURE_RAND:

相关文章