All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.thoughtworks.deeplearning.double.layers.Log.scala Maven / Gradle / Ivy

The newest version!
package com.thoughtworks.deeplearning
package double.layers

import cats._
import cats.implicits._

import com.thoughtworks.deeplearning.Layer._

import com.thoughtworks.deeplearning.double.utilities.DoubleMonoidBatch

/**
  * @author 杨博 (Yang Bo) <[email protected]>
  */
final case class Log[Input0 <: Batch](operand: Layer.Aux[Input0, Batch.Aux[Eval[scala.Double], Eval[scala.Double]]])
    extends BufferedLayer.Unary {

  type BufferedBatch = DoubleMonoidBatch with MonoidBatch with UnaryBatch

  type Input = Input0

  override protected def rawForward(input0: Input) = new {
    override final val input = input0
  } with  MonoidBatch with DoubleMonoidBatch with UnaryBatch {

    val value = upstream.value.map(math.log).memoize

    override protected def rawBackward(outputDelta: Eval[scala.Double]): Unit = {
      upstream.backward(outputDelta.map2(upstream.value)(_ / _).memoize)
    }

  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy