@ -3,7 +3,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 1,
"execution_count": 1,
"id": "similar-ebony ",
"id": "geographic-wilderness ",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
@ -15,22 +15,22 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 2,
"execution_count": 2,
"id": "spread-hygien e",
"id": "major-glucos e",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"output_type": "stream",
"text": [
"text": [
"tensor([[[6., 1., 0 .]],\n",
"tensor([[[4., 9., 6 .]],\n",
"\n",
"\n",
" [[2., 0 ., 4.]],\n",
" [[0., 5 ., 4.]],\n",
"\n",
"\n",
" [[7., 6 ., 9.]],\n",
" [[3., 1 ., 9.]],\n",
"\n",
"\n",
" [[3., 6., 9 .]],\n",
" [[6., 4., 8 .]],\n",
"\n",
"\n",
" [[9., 1., 2.]]] )\n"
" [[8., 7., 6.]]], grad_fn=<CatBackward> )\n"
]
]
}
}
],
],
@ -39,8 +39,8 @@
"constellations = states -1 #determined by debris tracking\n",
"constellations = states -1 #determined by debris tracking\n",
"max_start_state = 10\n",
"max_start_state = 10\n",
"\n",
"\n",
"stocks = torch.randint(max_start_state,(batch_size,1,constellations),dtype=torch.float32)\n",
"stocks = torch.randint(max_start_state,(batch_size,1,constellations), dtype=torch.float32, requires_grad=True )\n",
"debris = torch.randint(max_start_state,(batch_size,1,1),dtype=torch.float32)\n",
"debris = torch.randint(max_start_state,(batch_size,1,1), dtype=torch.float32, requires_grad=True )\n",
"\n",
"\n",
"s = c.States(stocks, debris)\n",
"s = c.States(stocks, debris)\n",
"\n",
"\n",
@ -50,13 +50,13 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 3,
"execution_count": 3,
"id": "attended-making ",
"id": "recognized-ability ",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
"data": {
"data": {
"text/plain": [
"text/plain": [
"tensor([6.3344e-07, 4.6190e-07] )"
"tensor([5.6433e-07, 6.7631e-07], grad_fn=<MulBackward0> )"
]
]
},
},
"execution_count": 3,
"execution_count": 3,
@ -65,14 +65,14 @@
}
}
],
],
"source": [
"source": [
"constellation_collision_risk = 1e-6 * torch.rand(constellations)\n",
"constellation_collision_risk = 1e-6 * torch.rand(constellations, requires_grad=True )\n",
"constellation_collision_risk"
"constellation_collision_risk"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 4,
"execution_count": 4,
"id": "strategic-american ",
"id": "elect-float ",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
@ -80,14 +80,14 @@
"launch_debris = 0.05\n",
"launch_debris = 0.05\n",
"debris_autocatalysis_rate = 1.4\n",
"debris_autocatalysis_rate = 1.4\n",
"\n",
"\n",
"benefit_weight0 = torch.tensor([1.0,-0.02])\n",
"benefit_weight0 = torch.tensor([1.0,-0.02], requires_grad=True )\n",
"benefit_weight1 = torch.tensor([0.0,1.0])"
"benefit_weight1 = torch.tensor([0.0,1.0], requires_grad=True )"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 5,
"execution_count": 5,
"id": "hired-consent ",
"id": "compressed-individual ",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
@ -102,122 +102,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 6,
"execution_count": 6,
"id": "copyrighted-tackle",
"id": "tracked-bachelor",
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "__init__() missing 1 required positional argument: 'launch_cost'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-6-54bb8ddad0e2>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mlaunch_cost\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m ea0 = c.LinearProfit(\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;36m0\u001b[0m \u001b[0;31m#constellation index\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m,\u001b[0m\u001b[0;36m0.95\u001b[0m \u001b[0;31m#discount\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m,\u001b[0m\u001b[0mbenefit_weight0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mTypeError\u001b[0m: __init__() missing 1 required positional argument: 'launch_cost'"
]
}
],
"source": [
"launch_cost = 5\n",
"ea0 = c.LinearProfit(\n",
" 0 #constellation index\n",
" ,0.95 #discount\n",
" ,benefit_weight0\n",
" ,launch_cost #launch_cost\n",
" )\n",
"ea1 = c.LinearProfit(\n",
" 1 #constellation index\n",
" ,0.95 #discount\n",
" ,benefit_weight1\n",
" ,launch_cost #launch_cost\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "accepted-namibia",
"metadata": {},
"outputs": [],
"source": [
"enn = nns.EstimandNN(batch_size\n",
" ,states\n",
" ,choices\n",
" ,constellations\n",
" ,12)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "revolutionary-eight",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[[0.0000],\n",
" [0.0000]],\n",
"\n",
" [[0.0000],\n",
" [0.0021]],\n",
"\n",
" [[0.1109],\n",
" [0.0835]],\n",
"\n",
" [[0.0884],\n",
" [0.1051]],\n",
"\n",
" [[0.0000],\n",
" [0.0000]]], grad_fn=<ReluBackward0>)"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"launch_decisions = enn.forward(s.values).choices\n",
"launch_decisions"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "abroad-mobile",
"metadata": {},
"outputs": [],
"source": [
"w = torch.tensor([[1.0,0],[0,-0.2]])\n",
"ww = torch.tensor([1.0, -0.2])"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "seasonal-companion",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"torch.Size([5, 1, 2])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stocks.size()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "jewish-zoning",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
@ -240,10 +125,6 @@
" self.benefit_weights = benefit_weights\n",
" self.benefit_weights = benefit_weights\n",
" self.launch_cost = launch_cost\n",
" self.launch_cost = launch_cost\n",
" self.deorbit_cost = deorbit_cost\n",
" self.deorbit_cost = deorbit_cost\n",
"\n",
" def __str__(self):\n",
" return \"LinearProfit\\n Benefit weights:\\t{}\\n launch cost:\\t{}\\n Deorbit cost:\\t{}\".format(self.benefit_weights, self.launch_cost, self.deorbit_cost)\n",
"\n",
" \n",
" \n",
" def _period_benefit(self,stocks,debris,launches):\n",
" def _period_benefit(self,stocks,debris,launches):\n",
" # multiply benefits times stocks\n",
" # multiply benefits times stocks\n",
@ -260,177 +141,380 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 1 7,
"execution_count": 7,
"id": "surgical-diversity ",
"id": "confidential-philippines ",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"def test(stocks,launches):\n",
"launch_cost = 5\n",
" # multiply benefits times stocks\n",
"ea0 = LinearProfit(\n",
" # sum across constellations\n",
" batch_size\n",
" # reshape to standard dimensions\n",
" ,0 #constellation index\n",
" # subtract launch costs. \n",
" ,0.95 #discount\n",
" profit = torch.tensordot(ww,stocks, [[0],[1]])[:,0] - (launch_cost * launch_decisions)[:,0,0]\n",
" ,benefit_weight0\n",
" return profit.view(batch_size,1)"
" ,launch_cost #launch_cost\n",
" )"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 1 8,
"execution_count": 8,
"id": "western-sixth ",
"id": "religious-georgia ",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"t = LinearProfit(batch_size #batch_size\n",
"enn = nns.EstimandNN(batch_size\n",
" ,0 #constellation index\n",
" ,states\n",
" ,0.95 #discount\n",
" ,choices\n",
" ,benefit_weight0\n",
" ,constellations\n",
" ,launch_cost #launch_cost\n",
" ,12)"
" )"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 1 9,
"execution_count": 9,
"id": "conscious-debut ",
"id": "painful-republican ",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
"data": {
"data": {
"text/plain": [
"text/plain": [
"<__main__.LinearProfit at 0x7f0664fad4c0>"
"tensor([[[0.],\n",
" [0.]],\n",
"\n",
" [[0.],\n",
" [0.]],\n",
"\n",
" [[0.],\n",
" [0.]],\n",
"\n",
" [[0.],\n",
" [0.]],\n",
"\n",
" [[0.],\n",
" [0.]]], grad_fn=<ReluBackward0>)"
]
]
},
},
"execution_count": 19,
"execution_count": 9,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
],
],
"source": [
"source": [
"t"
"launch_decisions = enn.forward(s.values).choices\n",
"launch_decisions"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 2 0,
"execution_count": 1 0,
"id": "eight-cheat ",
"id": "equal-raising ",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [],
{
"data": {
"text/plain": [
"tensor([[5.8800],\n",
" [1.9600],\n",
" [6.3054],\n",
" [2.4978],\n",
" [8.8200]], grad_fn=<ViewBackward>)"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source": [
"t._period_benefit(s.stocks,s.debris,launch_decisions)"
"def test(stocks,launches):\n",
" # multiply benefits times stocks\n",
" # sum across constellations\n",
" # reshape to standard dimensions\n",
" # subtract launch costs. \n",
" profit = torch.tensordot(benefit_weight0,stocks, [[0],[1]])[:,0] - (launch_cost * launch_decisions)[:,0,0]\n",
" return profit.view(batch_size,1)"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 25,
"execution_count": 11,
"id": "juvenile-barcelona",
"id": "divine-editor",
"metadata": {
"metadata": {},
"tags": []
},
"outputs": [],
"outputs": [],
"source": [
"source": [
"def f(stocks, debris, launches):\n",
"t = LinearProfit(batch_size #batch_size\n",
" return torch.autograd.functional.jacobian(t._period_benefit\n",
" ,0 #constellation index\n",
" ,(stocks,debris,launches)\n",
" ,0.95 #discount\n",
" ,create_graph=True\n",
" ,benefit_weight0\n",
" )\n",
" ,launch_cost #launch_cost\n",
"def ff(stocks, debris, launches):\n",
" )"
" return torch.autograd.functional.jacobian(f\n",
" ,(stocks,debris,launches)\n",
" ,create_graph=True\n",
" )"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 30 ,
"execution_count": 12 ,
"id": "freelance-publicity ",
"id": "japanese-captain ",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
"data": {
"data": {
"text/plain": [
"text/plain": [
"torch.Size([5, 1, 5, 1, 2, 5, 1, 2])"
"tensor([[3.9200],\n",
" [0.0000],\n",
" [2.9400],\n",
" [5.8800],\n",
" [7.8400]], grad_fn=<ViewBackward>)"
]
]
},
},
"execution_count": 30,
"execution_count": 12 ,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
],
],
"source": []
"source": [
"test(stocks,launch_decisions)"
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 55 ,
"execution_count": 13 ,
"id": "vocational-operator ",
"id": "determined-difference ",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
"data": {
"data": {
"text/plain": [
"text/plain": [
"tensor([[[6.0000, 1.0000],\n",
"tensor([[3.9200],\n",
" [2.0000, 0.0000],\n",
" [0.0000],\n",
" [7.0000, 6.0000],\n",
" [2.9400],\n",
" [3.0000, 6.0000],\n",
" [5.8800],\n",
" [9.0000, 1.0000]],\n",
" [7.8400]], grad_fn=<ViewBackward>)"
"\n",
" [[4.8000, 0.8000],\n",
" [1.6000, 0.0000],\n",
" [5.6000, 4.8000],\n",
" [2.4000, 4.8000],\n",
" [7.2000, 0.8000]]])"
]
]
},
},
"execution_count": 55 ,
"execution_count": 13,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
],
],
"source": [
"source": [
"torch.tensordot(torch.tensor([[1.0,-0.2],[0,1]]),stocks, [[0],[1]] )"
"t._period_benefit(s.stocks,s.debris,launch_decisions )"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 48 ,
"execution_count": 1 4,
"id": "nuclear-alberta ",
"id": "tribal-least ",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
"data": {
"data": {
"text/plain": [
"text/plain": [
"torch.Size([5, 1, 2])"
"(tensor([[[[[0.9800, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]]]],\n",
" \n",
" \n",
" \n",
" [[[[0.0000, 0.0000]],\n",
" \n",
" [[0.9800, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]]]],\n",
" \n",
" \n",
" \n",
" [[[[0.0000, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]],\n",
" \n",
" [[0.9800, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]]]],\n",
" \n",
" \n",
" \n",
" [[[[0.0000, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]],\n",
" \n",
" [[0.9800, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]]]],\n",
" \n",
" \n",
" \n",
" [[[[0.0000, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]],\n",
" \n",
" [[0.0000, 0.0000]],\n",
" \n",
" [[0.9800, 0.0000]]]]], grad_fn=<ViewBackward>),\n",
" tensor([[[[[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]]]],\n",
" \n",
" \n",
" \n",
" [[[[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]]]],\n",
" \n",
" \n",
" \n",
" [[[[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]]]],\n",
" \n",
" \n",
" \n",
" [[[[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]]]],\n",
" \n",
" \n",
" \n",
" [[[[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]],\n",
" \n",
" [[0.]]]]]),\n",
" tensor([[[[[-5.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]]]],\n",
" \n",
" \n",
" \n",
" [[[[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-5.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]]]],\n",
" \n",
" \n",
" \n",
" [[[[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-5.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]]]],\n",
" \n",
" \n",
" \n",
" [[[[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-5.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]]]],\n",
" \n",
" \n",
" \n",
" [[[[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-0.],\n",
" [ 0.]],\n",
" \n",
" [[-5.],\n",
" [ 0.]]]]]))"
]
]
},
},
"execution_count": 48,
"execution_count": 1 4,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
],
],
"source": [
"source": [
"stocks.shape"
"#in this case, the debris isn't tracked because it isn't included, and launch_decisions has a similar issue.\n",
"torch.autograd.functional.jacobian(t._period_benefit, (s.stocks,s.debris,launch_decisions), create_graph=True)"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
"id": "immune-machinery",
"id": "statutory-lyric",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "naked-health",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": []
"source": []