Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodiff #77

Merged
merged 30 commits into from
Mar 12, 2022
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e10f137
Begin initialising autodiff submodule
JHay0112 Jan 29, 2022
9d1a758
Start implementing normal(ish) function behaviour
JHay0112 Feb 5, 2022
4a01a26
Merge branch 'autodiff' of https://github.com/JHay0112/jmath into aut…
JHay0112 Feb 5, 2022
1803d8d
Functions mostly working classicly, order broken
JHay0112 Feb 5, 2022
84b271f
Start work on differentiation code
JHay0112 Feb 5, 2022
a58f194
Refined approach, still needs tweaked
JHay0112 Feb 22, 2022
0a94dc4
Another broken implementation
JHay0112 Feb 25, 2022
2227270
IT WORKS! (Mostly)
JHay0112 Feb 27, 2022
fe31db8
Power handling
JHay0112 Feb 27, 2022
cad346e
Implement some common derivatives
JHay0112 Mar 3, 2022
890ea13
Slightly more flexible function def
JHay0112 Mar 3, 2022
08b5f0c
Analyse function
JHay0112 Mar 3, 2022
c74e87d
Support multiple diff levels
JHay0112 Mar 3, 2022
f18f25a
Clean up input setting
JHay0112 Mar 3, 2022
8b50bc7
Predefine common variables
JHay0112 Mar 7, 2022
8fd5456
Extend to include uppercase
JHay0112 Mar 7, 2022
c7ec0d3
Seperate auto-differentiation package
JHay0112 Mar 10, 2022
3ae09bb
Rebuild docs to match
JHay0112 Mar 10, 2022
bba1958
Fix broken function derivatives
JHay0112 Mar 11, 2022
65c3bf1
Add some more commonly needed derivatives
JHay0112 Mar 11, 2022
f2d8614
Minor tweaks
JHay0112 Mar 11, 2022
94bea30
Multi-layer differentiability
JHay0112 Mar 11, 2022
570d32f
Clarify derivative definition
JHay0112 Mar 11, 2022
fb475c3
Crappy function printing
JHay0112 Mar 11, 2022
48f480f
Tack this on too
JHay0112 Mar 11, 2022
b27b2e0
Short hand differentiation
JHay0112 Mar 11, 2022
527c5aa
Start writing tests
JHay0112 Mar 11, 2022
19fb46f
Minor differentiator tweaks
JHay0112 Mar 12, 2022
762d257
Trigonometric tests
JHay0112 Mar 12, 2022
382e19f
More autodiff tests!
JHay0112 Mar 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Analyse function
  • Loading branch information
JHay0112 committed Mar 3, 2022
commit 08b5f0c9f7718ecaad4ade1fe6891f02056f6544
32 changes: 31 additions & 1 deletion jmath/approximation/autodiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# - Imports

import operator as op
import inspect
from ..uncertainties import Uncertainty
from typing import Union, Callable, Tuple

Expand Down Expand Up @@ -241,4 +242,33 @@ def differentiate(self, wrt: 'Variable') -> int:
if wrt == self or wrt == self.id:
return 1
else:
return 0
return 0

# - Functions

def analyse(f: Callable) -> Function:
'''
Automatically analyses the given function and produces a Function object.

Parameters
----------

f
The function to analyse

Returns
-------

Function
A differentiable function object representing the given function.
'''
# Get the list of parameters from the function
names = inspect.getargspec(f)[0]
# Convert these into variables for the function
vars = tuple(Variable(name) for name in names)
# Pass these to the function
f = f(*vars)
# Register the input variables
f.register(*vars)
# And return
return f