-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from arnaudbergeron/l2_loss
L2 loss
- Loading branch information
Showing
18 changed files
with
479 additions
and
166 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,5 +52,9 @@ coverage.xml | |
*.log | ||
*.pot | ||
|
||
.vscode | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
.vscode |
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,149 @@ | ||
from __future__ import annotations | ||
|
||
import sympy as sp | ||
import torch | ||
|
||
SP_TO_TORCH = { | ||
sp.sin: torch.sin, | ||
sp.cos: torch.cos, | ||
sp.tan: torch.tan, | ||
sp.exp: torch.exp, | ||
sp.log: torch.log, | ||
sp.asin: torch.asin, | ||
sp.acos: torch.acos, | ||
sp.atan: torch.atan, | ||
sp.sinh: torch.sinh, | ||
sp.cosh: torch.cosh, | ||
sp.tanh: torch.tanh, | ||
sp.asinh: torch.asinh, | ||
sp.acosh: torch.acosh, | ||
sp.atanh: torch.atanh, | ||
sp.Mul: torch.mul, | ||
sp.Add: torch.add, | ||
sp.Pow: torch.pow, | ||
sp.Abs: torch.abs, | ||
sp.cot: lambda x: torch.divide(1, torch.tan(x)), | ||
sp.acot: lambda x: torch.atan(torch.divide(1, x)), | ||
sp.sec: lambda x: torch.divide(1, torch.cos(x)), | ||
sp.asec: lambda x: torch.acos(torch.divide(1, x)), | ||
sp.csc: lambda x: torch.divide(1, torch.sin(x)), | ||
sp.acsc: lambda x: torch.asin(torch.divide(1, x)), | ||
sp.coth: lambda x: torch.divide(1, torch.tanh(x)), | ||
sp.acoth: lambda x: torch.atanh(torch.divide(1, x)), | ||
sp.sech: lambda x: torch.divide(1, torch.cosh(x)), | ||
sp.asech: lambda x: torch.log( | ||
torch.add(torch.divide(1, x), torch.sqrt(torch.sub(torch.pow(torch.divide(1, x), 2), 1))) | ||
), | ||
sp.csch: lambda x: torch.divide(1, torch.sinh(x)), | ||
sp.acsch: lambda x: torch.log( | ||
torch.add(torch.divide(1, x), torch.sqrt(torch.add(torch.pow(torch.divide(1, x), 2), 1))) | ||
), | ||
} | ||
|
||
DIFFERENTIAL_FUNCTIONS = [ | ||
sp.sin, | ||
sp.cos, | ||
sp.tan, | ||
sp.exp, | ||
sp.log, | ||
sp.asin, | ||
sp.acos, | ||
sp.atan, | ||
sp.sinh, | ||
sp.cosh, | ||
sp.tanh, | ||
sp.asinh, | ||
sp.acosh, | ||
sp.atanh, | ||
sp.cot, | ||
sp.acot, | ||
sp.sec, | ||
sp.asec, | ||
sp.csc, | ||
sp.acsc, | ||
sp.coth, | ||
sp.acoth, | ||
sp.sech, | ||
sp.asech, | ||
sp.csch, | ||
sp.acsch, | ||
] | ||
|
||
OPERATIONS = [ | ||
("multiplication", "arithmetic"), | ||
("addition", "arithmetic"), | ||
("subtraction", "arithmetic"), | ||
("division", "arithmetic"), | ||
("differential", "differential"), | ||
# ("integration", "integration"), | ||
("exponent", "exponent"), | ||
] | ||
|
||
VARIABLES = ["x", "y", "z", "beta", "gamma"] | ||
|
||
DEFAULT_DICT = { | ||
")": 0, | ||
sp.acsc: 1, | ||
sp.acot: 2, | ||
sp.asech: 3, | ||
sp.core.containers.Tuple: 4, | ||
"/": 5, | ||
sp.sech: 6, | ||
"END": 7, | ||
sp.exp: 8, | ||
"7": 9, | ||
"0": 10, | ||
sp.asin: 11, | ||
"5": 12, | ||
sp.core.function.Derivative: 13, | ||
"8": 14, | ||
sp.asec: 15, | ||
sp.core.add.Add: 16, | ||
sp.core.power.Pow: 17, | ||
sp.csch: 18, | ||
"START": 19, | ||
sp.csc: 20, | ||
"PAD": 21, | ||
sp.sin: 22, | ||
",": 23, | ||
sp.acsch: 24, | ||
sp.core.relational.Equality: 25, | ||
"(": 26, | ||
"2": 27, | ||
sp.Symbol("x"): 28, | ||
sp.coth: 29, | ||
sp.Symbol("y"): 30, | ||
sp.log: 31, | ||
sp.cos: 32, | ||
"6": 33, | ||
sp.core.mul.Mul: 34, | ||
sp.acos: 35, | ||
"9": 36, | ||
sp.Function("f"): 37, | ||
"-": 38, | ||
sp.sqrt: 39, | ||
sp.cosh: 40, | ||
sp.tan: 41, | ||
sp.tanh: 42, | ||
sp.Symbol("z"): 43, | ||
"4": 44, | ||
"3": 45, | ||
sp.cot: 46, | ||
sp.asinh: 47, | ||
sp.atan: 48, | ||
sp.acosh: 49, | ||
"1": 50, | ||
sp.atanh: 51, | ||
".": 52, | ||
sp.sinh: 53, | ||
sp.acoth: 54, | ||
sp.sec: 55, | ||
sp.Symbol("beta"): 56, | ||
sp.Symbol("gamma"): 57, | ||
sp.Symbol("delta"): 58, | ||
sp.Symbol("a"): 59, | ||
sp.Symbol("b"): 60, | ||
sp.Symbol("c"): 61, | ||
sp.Symbol("d"): 62, | ||
sp.Symbol("epsilon"): 63, | ||
} |
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
Oops, something went wrong.