Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9229#discussion_r56207952
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/ann/Layer.scala ---
    @@ -294,89 +248,13 @@ private[ann] object ActivationFunction {
     }
     
     /**
    - * Implements SoftMax activation function
    - */
    -private[ann] class SoftmaxFunction extends ActivationFunction {
    -  override def eval(x: BDM[Double], y: BDM[Double]): Unit = {
    -    var j = 0
    -    // find max value to make sure later that exponent is computable
    -    while (j < x.cols) {
    -      var i = 0
    -      var max = Double.MinValue
    -      while (i < x.rows) {
    -        if (x(i, j) > max) {
    -          max = x(i, j)
    -        }
    -        i += 1
    -      }
    -      var sum = 0.0
    -      i = 0
    -      while (i < x.rows) {
    -        val res = Math.exp(x(i, j) - max)
    -        y(i, j) = res
    -        sum += res
    -        i += 1
    -      }
    -      i = 0
    -      while (i < x.rows) {
    -        y(i, j) /= sum
    -        i += 1
    -      }
    -      j += 1
    -    }
    -  }
    -
    -  override def crossEntropy(
    -    output: BDM[Double],
    -    target: BDM[Double],
    -    result: BDM[Double]): Double = {
    -    def m(o: Double, t: Double): Double = o - t
    -    ActivationFunction(output, target, result, m)
    -    -Bsum( target :* Blog(output)) / output.cols
    -  }
    -
    -  override def derivative(x: BDM[Double], y: BDM[Double]): Unit = {
    -    def sd(z: Double): Double = (1 - z) * z
    -    ActivationFunction(x, y, sd)
    -  }
    -
    -  override def squared(output: BDM[Double], target: BDM[Double], result: 
BDM[Double]): Double = {
    -    throw new UnsupportedOperationException("Sorry, squared error is not 
defined for SoftMax.")
    -  }
    -}
    -
    -/**
      * Implements Sigmoid activation function
      */
     private[ann] class SigmoidFunction extends ActivationFunction {
    -  override def eval(x: BDM[Double], y: BDM[Double]): Unit = {
    -    def s(z: Double): Double = Bsigmoid(z)
    -    ActivationFunction(x, y, s)
    -  }
     
    -  override def crossEntropy(
    -    output: BDM[Double],
    -    target: BDM[Double],
    -    result: BDM[Double]): Double = {
    -    def m(o: Double, t: Double): Double = o - t
    -    ActivationFunction(output, target, result, m)
    -    -Bsum(target :* Blog(output)) / output.cols
    -  }
    +  override def eval: (Double) => Double = x => 1.0 / (1 + Math.exp(-x))
    --- End diff --
    
    Use `math` instead. `Math` is deprecated.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to