-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import SciLean.Core.FunctionTransformations | ||
import SciLean.Core.Meta.GenerateRevDeriv | ||
|
||
open ComplexConjugate | ||
|
||
namespace SciLean.Scalar | ||
|
||
variable | ||
{R C} [Scalar R C] | ||
{W} [Vec C W] | ||
{U} [SemiInnerProductSpace C U] | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
-- Exp ------------------------------------------------------------------------- | ||
-------------------------------------------------------------------------------- | ||
|
||
@[fprop] | ||
theorem exp.arg_x.IsDifferentiable_rule | ||
(x : W → C) (hx : IsDifferentiable C x) | ||
: IsDifferentiable C fun w => exp (x w) := sorry_proof | ||
|
||
@[ftrans] | ||
theorem exp.arg_x.ceriv_rule | ||
(x : W → C) (hx : IsDifferentiable C x) | ||
: cderiv C (fun w => exp (x w)) | ||
= | ||
fun w dw => | ||
let xdx := fwdCDeriv C x w dw | ||
let e := exp xdx.1 | ||
xdx.2 * e := sorry_proof | ||
|
||
@[ftrans] | ||
theorem exp.arg_x.fwdCDeriv_rule | ||
(x : W → C) (hx : IsDifferentiable C x) | ||
: fwdCDeriv C (fun w => exp (x w)) | ||
= | ||
fun w dw => | ||
let xdx := fwdCDeriv C x w dw | ||
let e := exp xdx.1 | ||
(e, xdx.2 * e) := | ||
by | ||
unfold fwdCDeriv; ftrans; rfl | ||
|
||
#generate_revDeriv exp x | ||
prop_by unfold HasAdjDiff; constructor; fprop; ftrans; fprop | ||
trans_by unfold revDeriv; ftrans; ftrans | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import SciLean.Core | ||
import SciLean.Core.Functions.Trigonometric | ||
import SciLean.Core.FloatAsReal | ||
import SciLean.Core.Meta.GenerateRevDeriv | ||
|
||
namespace SciLean.ML | ||
|
||
variable {R : Type} [RealScalar R] | ||
|
||
open Scalar RealScalar | ||
|
||
def gelu (x : R) : R := | ||
let c := sqrt (2/pi) | ||
x * (1 + tanh (c * x * (1 + 0.044715 * x^2))) | ||
|
||
#generate_revDeriv gelu x | ||
prop_by unfold gelu; fprop | ||
trans_by | ||
unfold gelu | ||
ftrans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters