- 11.7k
- 1
- 27
- 59
I need to optimize the following function:
$$ \max_{a',\ m'} f(a, m, e, m', a') $$$$ \max_{a',\ m'}\ f(a, m, e, m', a') $$
I have approximated \$f\$ with a grid \$F\$ — it, which has a shape \$(nA, nM, nE, nM, nA)\$. Now, I want to interpolate over the last two dimensions (the oneones I need to maximize over), and then maximize.
The following is the only code I could come up with. It looks to be too complicated and to inefficient to be the best way to do this. For example, there should be a way such that I do not need to iterate over all the given states (dimensions 0–2). I'm open for any input to improve it.
ThisThe following code block is part of a way more complex project.the one I pasted code from different parts in my first update, in orderwant comments on. It looks to makebe too complicated and to inefficient to be the code reproducable. Please refrain from commenting that structure, as it is messy on purpose (in orderbest way to make it as short as possible)do this. For example, there should be a way such that I appreciate comments ondo not need to iterate over all the following codegiven states (the interpolation and maximization itselfdimensions 0–2). I'm open for any input to improve it.
AdditionalThis is part of a way more complex project. The next code block is added in order to runmake the code reproducable. Please refrain from commenting structure and code in this block, as it followsis messy on purpose (in order to make it as short as possible).
I reduced state size here to the minimum that makes sense, and pasted the matrix V0
atin the end - its creationlast code block, as it would be too complicatedmuch code to add all thecreation code here. Maximizer does for now returnsreturn (0,1)
for all states, this should be correct — I think (do not judge the following, poor code already sad about having been conglomerated).
And finally, the matrix V0
with shape (5,5,2,5,5)
, can be set with V0 =
the following before running code:
I need to optimize
$$ \max_{a',\ m'} f(a, m, e, m', a') $$
I have approximated \$f\$ with a grid \$F\$ — it has shape \$(nA, nM, nE, nM, nA)\$. Now, I want to interpolate over the last two dimensions (the one I need to maximize over), and then maximize.
The following is the only code I could come up with. It looks to be too complicated and to inefficient to be the best way to do this. For example, there should be a way such that I do not need to iterate over all the given states (dimensions 0–2). I'm open for any input to improve it.
This is part of a way more complex project. I pasted code from different parts in my first update, in order to make the code reproducable. Please refrain from commenting that structure, as it is messy on purpose (in order to make it as short as possible). I appreciate comments on the following code (the interpolation and maximization itself).
Additional code to run it follows. I reduced state size to the minimum that makes sense, and pasted the matrix V0
at the end - its creation would be too complicated to add all the code here. Maximizer for now returns (0,1)
for all states, this should be correct — I think (do not judge the following, poor code already sad about having been conglomerated).
And finally, the matrix V0
with shape (5,5,2,5,5)
:
I need to optimize the following function:
$$ \max_{a',\ m'}\ f(a, m, e, m', a') $$
I have approximated \$f\$ with a grid \$F\$, which has a shape \$(nA, nM, nE, nM, nA)\$. Now, I want to interpolate over the last two dimensions (the ones I need to maximize over), and then maximize.
The following code block is the one I want comments on. It looks to be too complicated and to inefficient to be the best way to do this. For example, there should be a way such that I do not need to iterate over all the given states (dimensions 0–2). I'm open for any input to improve it.
This is part of a way more complex project. The next code block is added in order to make the code reproducable. Please refrain from commenting structure and code in this block, as it is messy on purpose (in order to make it as short as possible).
I reduced state size here to the minimum that makes sense, and pasted the matrix V0
in the last code block, as it would be too much code to add creation code here. Maximizer does for now return (0,1)
for all states, this should be correct — I think (do not judge the following, poor code already sad about having been conglomerated).
And finally, the matrix V0
with shape (5,5,2,5,5)
, can be set with V0 =
the following before running code:
Update 2
This is part of a way more complex project. I pasted code from different parts in my first update, in order to make the code reproducable. Please refrain from commenting that structure, as it is messy on purpose (in order to make it as short as possible). I appreciate comments on the following code (the interpolation and maximization itself). This is part of a way more complex project. I pasted code from different parts in my first update, in order to make the code reproducable. Please refrain from commenting that structure, as it is messy on purpose (in order to make it as short as possible). I appreciate comments on the following code (the interpolation and maximization itself).
Update
additionalAdditional code to run it follows. I reduced state size to the minimum that makes sense, and pasted the matrix V0
at the end - its creation would be too complicated to add all the code here. Maximizer for now returns (0,1)
for all states, this should be correct — I think (do not judge the following, poor code already sad about having been conglomerated).
andAnd finally, the matrix V0
with shape (5,5,2,5,5)
:
Update 2
This is part of a way more complex project. I pasted code from different parts in my first update, in order to make the code reproducable. Please refrain from commenting that structure, as it is messy on purpose (in order to make it as short as possible). I appreciate comments on the following code (the interpolation and maximization itself).
Update
additional code to run it follows. I reduced state size to the minimum that makes sense, and pasted the matrix V0
at the end - its creation would be too complicated to add all the code here. Maximizer for now returns (0,1)
for all states, this should be correct — I think (do not judge the following, poor code already sad about having been conglomerated)
and finally, the matrix V0
with shape (5,5,2,5,5)
:
This is part of a way more complex project. I pasted code from different parts in my first update, in order to make the code reproducable. Please refrain from commenting that structure, as it is messy on purpose (in order to make it as short as possible). I appreciate comments on the following code (the interpolation and maximization itself).
Additional code to run it follows. I reduced state size to the minimum that makes sense, and pasted the matrix V0
at the end - its creation would be too complicated to add all the code here. Maximizer for now returns (0,1)
for all states, this should be correct — I think (do not judge the following, poor code already sad about having been conglomerated).
And finally, the matrix V0
with shape (5,5,2,5,5)
:
Update 2
This is part of a way more complex project. I pasted code from different parts in my first update, in order to make the code reproducable. Please refrain from commenting that structure, as it is messy on purpose (in order to make it as short as possible). I appreciate comments on the following code (the interpolation and maximization itself).
additional code to run it follows. I reduced state size to the minimum that makes sense, and pasted the matrix V0
at the end - its creation would be too complicated to add all the code here. Maximizer for now returns (0,1)
for all states, this should be correct — I think. (do not judge the following, poor code already sad about having been conglomerated)
additional code to run it follows. I reduced state size to the minimum that makes sense, and pasted the matrix V0
at the end - its creation would be too complicated to add all the code here. Maximizer for now returns (0,1)
for all states, this should be correct — I think.
Update 2
This is part of a way more complex project. I pasted code from different parts in my first update, in order to make the code reproducable. Please refrain from commenting that structure, as it is messy on purpose (in order to make it as short as possible). I appreciate comments on the following code (the interpolation and maximization itself).
additional code to run it follows. I reduced state size to the minimum that makes sense, and pasted the matrix V0
at the end - its creation would be too complicated to add all the code here. Maximizer for now returns (0,1)
for all states, this should be correct — I think (do not judge the following, poor code already sad about having been conglomerated)