more work on constructing tensors and jacobians

temporaryWork
youainti 5 years ago
parent 01a883a004
commit 487eec3b77

@ -2,19 +2,20 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "dense-italic",
"execution_count": 25,
"id": "meaningful-piece",
"metadata": {},
"outputs": [],
"source": [
"import torch\n",
"import numpy\n"
"import numpy\n",
"from torch.autograd.functional import jacobian"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "adult-cargo",
"id": "prescribed-roller",
"metadata": {},
"outputs": [],
"source": [
@ -27,7 +28,7 @@
{
"cell_type": "code",
"execution_count": 3,
"id": "photographic-miniature",
"id": "amateur-taste",
"metadata": {},
"outputs": [],
"source": [
@ -38,7 +39,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "charming-plate",
"id": "accepted-bonus",
"metadata": {},
"outputs": [],
"source": []
@ -46,7 +47,7 @@
{
"cell_type": "code",
"execution_count": 4,
"id": "fitting-horizontal",
"id": "burning-peeing",
"metadata": {},
"outputs": [],
"source": [
@ -56,7 +57,7 @@
{
"cell_type": "code",
"execution_count": 5,
"id": "secret-oasis",
"id": "special-hydrogen",
"metadata": {},
"outputs": [],
"source": [
@ -66,7 +67,7 @@
{
"cell_type": "code",
"execution_count": 6,
"id": "comic-context",
"id": "played-fairy",
"metadata": {},
"outputs": [
{
@ -121,7 +122,7 @@
},
{
"cell_type": "markdown",
"id": "chinese-family",
"id": "scientific-egypt",
"metadata": {},
"source": [
"# Try this\n",
@ -163,7 +164,7 @@
{
"cell_type": "code",
"execution_count": 7,
"id": "exceptional-amount",
"id": "flexible-hotel",
"metadata": {},
"outputs": [],
"source": [
@ -174,7 +175,7 @@
{
"cell_type": "code",
"execution_count": 8,
"id": "biblical-convertible",
"id": "floating-alert",
"metadata": {},
"outputs": [
{
@ -198,7 +199,7 @@
{
"cell_type": "code",
"execution_count": 9,
"id": "classified-crisis",
"id": "historical-elevation",
"metadata": {},
"outputs": [
{
@ -222,7 +223,7 @@
{
"cell_type": "code",
"execution_count": 10,
"id": "charged-locator",
"id": "proud-brake",
"metadata": {},
"outputs": [
{
@ -244,7 +245,7 @@
{
"cell_type": "code",
"execution_count": 11,
"id": "cheap-necessity",
"id": "protective-grave",
"metadata": {},
"outputs": [
{
@ -267,7 +268,7 @@
{
"cell_type": "code",
"execution_count": 12,
"id": "flexible-nightlife",
"id": "coated-guard",
"metadata": {},
"outputs": [
{
@ -292,7 +293,7 @@
{
"cell_type": "code",
"execution_count": 13,
"id": "heavy-duration",
"id": "competitive-acting",
"metadata": {},
"outputs": [],
"source": [
@ -303,7 +304,7 @@
{
"cell_type": "code",
"execution_count": 14,
"id": "quantitative-organ",
"id": "statutory-starter",
"metadata": {},
"outputs": [
{
@ -324,7 +325,7 @@
{
"cell_type": "code",
"execution_count": 16,
"id": "transparent-cartridge",
"id": "engaged-teddy",
"metadata": {},
"outputs": [
{
@ -351,16 +352,124 @@
},
{
"cell_type": "markdown",
"id": "adjusted-saskatchewan",
"id": "stretch-mercury",
"metadata": {},
"source": [
"So, I think I can construct a gradient, and possibly invert it/choose some other solution method."
]
},
{
"cell_type": "markdown",
"id": "disciplinary-opposition",
"metadata": {},
"source": [
"basic transition functions\n",
"$$\n",
"s^i(s,D)\\prime = (1-D^{\\sum s}) s^i + x\\\\\n",
"D\\prime = (1-\\delta)D + D^{\\alpha} +\\gamma D^{\\sum s} +\\Gamma x\n",
"$$"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "missing-robinson",
"metadata": {},
"outputs": [],
"source": [
"def satellite_loss(d,s):\n",
" return d**(s.sum())\n",
"\n",
"def gs(d,s,x):\n",
" return (1-d**(s.sum()))*s + x\n",
"\n",
"#Parameters\n",
"gamma, alpah, Gamma, delta = 0.1, 4000, 0.001, 0.1\n",
"\n",
"def gd(d,s,x):\n",
" return d*(1-delta) + gamma *s.sum()*d**(s.sum()) + Gamma*x"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "driving-wright",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(tensor([7.9941, 6.9961], grad_fn=<AddBackward0>),\n",
" tensor([6., 4.], requires_grad=True),\n",
" tensor([2., 3.], requires_grad=True))"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"D = torch.Tensor([0.5])\n",
"gs(D,b,a),b,a"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "infectious-plaintiff",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(tensor([[-0.1172],\n",
" [-0.0781]]),\n",
" tensor([[1.0031, 0.0041],\n",
" [0.0027, 1.0017]]),\n",
" tensor([[1., 0.],\n",
" [0., 1.]]))"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"jacobian(gs,(D,b,a))"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "proud-dance",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(tensor([[0.9195],\n",
" [0.9195]]),\n",
" tensor([[-0.0006, -0.0006],\n",
" [-0.0006, -0.0006]]),\n",
" tensor([[0.0010, 0.0000],\n",
" [0.0000, 0.0010]]))"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"jacobian(gd,(D,b,a))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "outdoor-functionality",
"id": "satisfied-briefs",
"metadata": {},
"outputs": [],
"source": []

Loading…
Cancel
Save