package Ġfw cd . minim l . graph Ċ Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . Assert . assertThat Ċ import Ġfw cd . minim l . graph . variable Ċ import Ġfw cd . minim l . math . scalar Of Int Ċ import Ġfw cd . minim l . math . scalar Of Ċ import Ġfw cd . minim l . math . approx Equals Ċ Ċ class ĠUnary Element wise Test Ġ{ Ċ ĉ @ Test Ċ ĉ fun Ġtest Negative () Ġ{ Ċĉ ĉ val Ġx Ġ= Ġvariable ( scalar Of ( 5 . 8 ), Ġname Ġ= Ġ" x ") Ċĉ ĉ val Ġneg Ġ= Ġ- x Ċĉ ĉ assertThat ( neg . forward (), Ġapprox Equals ( scalar Of (- 5 . 8 ))) Ċĉ ĉ neg . backward () Ċĉ ĉ assertThat ( x . gradient !! , Ġapprox Equals ( scalar Of Int (- 1 ))) Ċ ĉ } ĊĉĊ ĉ @ Test Ċ ĉ fun Ġtest Re ci pro cal () Ġ{ Ċĉ ĉ val Ġx Ġ= Ġvariable ( scalar Of ( 5 . 8 ), Ġname Ġ= Ġ" x ") Ċĉ ĉ val Ġrec Ġ= Ġx . reci pro cal () Ċĉ ĉ assertThat ( rec . forward (), Ġapprox Equals ( scalar Of ( 0 . 1 7 2 4 1 3 7 9 3 1 0 3 4 4 8 3 ))) Ċĉ ĉ rec . backward () Ċĉ ĉ assertThat ( x . gradient !! , Ġapprox Equals ( scalar Of (- 0 . 0 2 9 7 ))) Ċ ĉ } ĊĉĊ ĉ @ Test Ċ ĉ fun Ġtest Sig moid () Ġ{ Ċĉ ĉ val Ġx Ġ= Ġvariable ( scalar Of ( 4 . 5 ), Ġname Ġ= Ġ" x ") Ċĉ ĉ val Ġsig Ġ= Ġx . sigmoid () Ċĉ ĉ assertThat ( sig . forward (), Ġapprox Equals ( scalar Of ( 0 . 9 8 9 ))) Ċĉ ĉ sig . backward () Ċĉ ĉ assertThat ( x . gradient !! , Ġapprox Equals ( scalar Of ( 0 . 0 1 0 9 ))) Ċ ĉ } ĊĉĊ ĉ @ Test Ċ ĉ fun Ġtest T anh () Ġ{ Ċĉ ĉ val Ġx Ġ= Ġvariable ( scalar Of ( 0 . 7 ), Ġname Ġ= Ġ" x ") Ċĉ ĉ val Ġth Ġ= Ġx . tanh () Ċĉ ĉ assertThat ( th . forward (), Ġapprox Equals ( scalar Of ( 0 . 6 0 4 4 ))) Ċĉ ĉ th . backward () Ċĉ ĉ assertThat ( x . gradient !! , Ġapprox Equals ( scalar Of ( 0 . 6 3 4 7 ))) Ċ ĉ } ĊĉĊ ĉ @ Test Ċ ĉ fun Ġtest Sin () Ġ{ Ċĉ ĉ val Ġx Ġ= Ġvariable ( scalar Of ( 9 . 3 ), Ġname Ġ= Ġ" x ") Ċĉ ĉ val Ġs Ġ= Ġx . sin () Ċĉ ĉ assertThat ( s . forward (), Ġapprox Equals ( scalar Of ( 0 . 1 2 4 5 ))) Ċĉ ĉ s . backward () Ċĉ ĉ assertThat ( x . gradient !! , Ġapprox Equals ( scalar Of (- 0 . 9 9 2 2 ))) Ċ ĉ } ĊĉĊ ĉ @ Test Ċ ĉ fun Ġtest Cos () Ġ{ Ċĉ ĉ val Ġx Ġ= Ġvariable ( scalar Of ( 7 . 7 ), Ġname Ġ= Ġ" x ") Ċĉ ĉ val Ġc Ġ= Ġx . cos () Ċĉ ĉ assertThat ( c . forward (), Ġapprox Equals ( scalar Of ( 0 . 1 5 3 3 7 3 ))) Ċĉ ĉ c . backward () Ċĉ ĉ assertThat ( x . gradient !! , Ġapprox Equals ( scalar Of (- 0 . 9 8 8 2 ))) Ċ ĉ } ĊĉĊ ĉ @ Test Ċ ĉ fun Ġtest Tan () Ġ{ Ċĉ ĉ val Ġx Ġ= Ġvariable ( scalar Of ( 2 . 1 ), Ġname Ġ= Ġ" x ") Ċĉ ĉ val Ġt Ġ= Ġx . tan () Ċĉ ĉ assertThat ( t . forward (), Ġapprox Equals ( scalar Of (- 1 . 7 0 9 8 4 6 ))) Ċĉ ĉ t . backward () Ċĉ ĉ assertThat ( x . gradient !! , Ġapprox Equals ( scalar Of ( 3 . 9 2 3 6 ))) Ċ ĉ } ĊĉĊ ĉ @ Test Ċ ĉ fun Ġtest Log () Ġ{ Ċĉ ĉ val Ġx Ġ= Ġvariable ( scalar Of ( 2 . 1 ), Ġname Ġ= Ġ" x ") Ċĉ ĉ val Ġl Ġ= Ġx . log () Ċĉ ĉ assertThat ( l . forward (), Ġapprox Equals ( scalar Of ( 0 . 7 4 1 9 3 7 3 4 4 7 2 9 3 7 7 3 ))) Ċĉ ĉ l . backward () Ċĉ ĉ assertThat ( x . gradient !! , Ġapprox Equals ( scalar Of ( 0 . 4 7 6 2 ))) Ċ ĉ } ĊĉĊ ĉ @ Test Ċ ĉ fun Ġtest Exp () Ġ{ Ċĉ ĉ val Ġx Ġ= Ġvariable ( scalar Of ( 2 . 1 ), Ġname Ġ= Ġ" x ") Ċĉ ĉ val Ġe Ġ= Ġx . exp () Ċĉ ĉ assertThat ( e . forward (), Ġapprox Equals ( scalar Of ( 8 . 1 6 6 1 6 9 9 1 2 5 6 7 6 5 ))) Ċĉ ĉ e . backward () Ċĉ ĉ assertThat ( x . gradient !! , Ġapprox Equals ( scalar Of ( 8 . 1 6 6 1 6 9 9 1 2 5 6 7 6 5 ))) Ċ ĉ } Ċ } Ċ