You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
2.5 KiB
Plaintext
131 lines
2.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "inappropriate-technician",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import torch\n",
|
|
"from torch.autograd.functional import jacobian\n",
|
|
"import numpy as np"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "rubber-accreditation",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"a = torch.tensor([2., 3.], requires_grad=True)\n",
|
|
"b = torch.tensor([6., 4.], requires_grad=True)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"id": "adverse-efficiency",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def C(a,b):\n",
|
|
" return a*torch.exp(b)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 35,
|
|
"id": "biblical-finance",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def D(a,b):\n",
|
|
" return a@b * jacobian(C,(a,b))[0].inverse()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 36,
|
|
"id": "native-congress",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"tensor([[0.0025, -0.0000],\n",
|
|
" [0.0000, 0.0183]])"
|
|
]
|
|
},
|
|
"execution_count": 36,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"jacobian(C,(a,b))[0].inverse()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 37,
|
|
"id": "residential-sight",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"(tensor([[[0.0149, 0.0099],\n",
|
|
" [0.0000, 0.0000]],\n",
|
|
" \n",
|
|
" [[0.0000, 0.0000],\n",
|
|
" [0.1099, 0.0733]]]),\n",
|
|
" tensor([[[0.0050, 0.0074],\n",
|
|
" [0.0000, 0.0000]],\n",
|
|
" \n",
|
|
" [[0.0000, 0.0000],\n",
|
|
" [0.0366, 0.0549]]]))"
|
|
]
|
|
},
|
|
"execution_count": 37,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"jacobian(D,(a,b))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "still-province",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.8.8"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|