Skip to content

Commit

Permalink
rufff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenthall committed Nov 14, 2024
1 parent 61fd2f7 commit 8f45b79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 1 addition & 2 deletions HARK/algos/tests/test_vbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
)

block_2 = DBlock( # has no control variable
block_2 = DBlock( # has no control variable
**{
"name": "vbi_test_1",
"shocks": {
Expand All @@ -36,7 +36,6 @@
)



class test_vbi(unittest.TestCase):
# def setUp(self):
# pass
Expand Down
14 changes: 10 additions & 4 deletions HARK/algos/vbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def negated_value(a): # old! (should be negative)
# negative, for minimization later
return -srv_function(pre_states, dr)

if len(controls) == 0:
if len(controls) == 0:
# if no controls, no optimization is necessary
pass
elif len(controls) == 1:
Expand All @@ -123,14 +123,18 @@ def negated_value(a): # old! (should be negative)
lower_bound = -1e-6 ## a really low number!
feq = block.dynamics[controls[0]].lower_bound
if feq is not None:
lower_bound = feq(*[pre_states[var] for var in signature(feq).parameters])
lower_bound = feq(
*[pre_states[var] for var in signature(feq).parameters]
)

## get upper bound
## assumes only one control currently
upper_bound = 1e-12 # a very high number
feq = block.dynamics[controls[0]].upper_bound
if feq is not None:
upper_bound = feq(*[pre_states[var] for var in signature(feq).parameters])
upper_bound = feq(
*[pre_states[var] for var in signature(feq).parameters]
)

bounds = ((lower_bound, upper_bound),)

Expand Down Expand Up @@ -160,7 +164,9 @@ def negated_value(a): # old! (should be negative)
0, srv_function(pre_states, dr_best)
)
elif len(controls) > 1:
raise Exception(f"Value backup iteration is not yet implemented for stages with {len(controls)} > 1 control variables.")
raise Exception(
f"Value backup iteration is not yet implemented for stages with {len(controls)} > 1 control variables."
)

# use the xarray interpolator to create a decision rule.
dr_from_data = {
Expand Down

0 comments on commit 8f45b79

Please sign in to comment.