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

com.thoughtworks.deeplearning.double.layers.Substract.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 Substract[Input0 <: Batch](
    operand1: Layer.Aux[Input0, Batch.Aux[Eval[scala.Double], Eval[scala.Double]]],
    operand2: Layer.Aux[Input0, Batch.Aux[Eval[scala.Double], Eval[scala.Double]]]
) extends BufferedLayer.Binary {

  type BufferedBatch = DoubleMonoidBatch with MonoidBatch with BinaryBatch

  type Input = Input0

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

      val value = upstream1.value.map2(upstream2.value)(_ - _)

      override protected def rawBackward(delta: Eval[scala.Double]): Unit = {
        upstream1.backward(delta)
        upstream2.backward(delta.map(-_))
      }

    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy