Skip to content

Instantly share code, notes, and snippets.

@tswedish
Last active May 26, 2020 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tswedish/4870bbe62c4e14d53ba009b3f4755726 to your computer and use it in GitHub Desktop.
Save tswedish/4870bbe62c4e14d53ba009b3f4755726 to your computer and use it in GitHub Desktop.
for x in [-1., 0.5, 3.]:
print('Function Input: {}'.format(x))
print('Function Value: {}'.format(super_complicated_function(x)))
print('Function Symbolic Derivative: {}'.format(d_super_complicated_function(x)))
x_v = Variable(x)
L = super_complicated_function(x_v)
print('Variable Function Output Value: {}'.format(L))
L.backward()
print('Input value: {}'.format(x_v))
print('-'*32)
'''
# Printed Results
Function Input: -1.0
Function Value: -4.459767882269113
Function Symbolic Derivative: 3.504367159953579
Variable Function Output Value: < Variable value: -4.459767882269113, gradient: 0.0 >
Input value: < Variable value: -1.0, gradient: 3.504367159953579 >
--------------------------------
Function Input: 0.5
Function Value: -1.4026444100543694
Function Symbolic Derivative: 1.1084382073126584
Variable Function Output Value: < Variable value: -1.4026444100543694, gradient: 0.0 >
Input value: < Variable value: 0.5, gradient: 1.1084382073126582 >
--------------------------------
Function Input: 3.0
Function Value: 0.004762468816939924
Function Symbolic Derivative: -0.8682732520785479
Variable Function Output Value: < Variable value: 0.004762468816939924, gradient: 0.0 >
Input value: < Variable value: 3.0, gradient: -0.8682732520785479 >
--------------------------------
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment