Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better automation of for loops over 'time varying' values #890

Open
sbenthall opened this issue Dec 22, 2020 · 6 comments
Open

better automation of for loops over 'time varying' values #890

sbenthall opened this issue Dec 22, 2020 · 6 comments
Milestone

Comments

@sbenthall
Copy link
Contributor

Time varying values are currently implemented as lists indexed by t.

This is to denote differently aged agents.

In some cases, there is a separate control flow for handling the time-varying values and the non varying values.

It would perhaps improve readability to have a more general, consistent way of handling time-varying values.

For example, if these time-varying values were arrays and not lists, it would be possible to perform vectorized operations on them, rather than use a (slower) for loop iteration.

@sbenthall sbenthall added this to the 1.0.0 milestone Dec 22, 2020
@mnwhite
Copy link
Contributor

mnwhite commented Dec 22, 2020 via email

@sbenthall
Copy link
Contributor Author

I thought you were on a break from HARK work @mnwhite ...

@sbenthall
Copy link
Contributor Author

Since vectorization is not an option, it might be possible to use something like the following:

def apply_or_map(value, func):
    if timy_varying(value):
       return map(value, func)
    else:
       return func(value)

That would allow the code to be refactor in a way that operations could be written just once, rather than repeated over both the time varying and non-time varying cases.

I've notived this while working on this part of the code, but maybe there are other places as well.

https://github.com/econ-ark/HARK/blob/master/HARK/ConsumptionSaving/ConsPortfolioModel.py#L242-L262

@sbenthall
Copy link
Contributor Author

Here is another example where the handling of time-varying and non-time-varying cases could be consolidated.

https://github.com/econ-ark/HARK/blob/master/HARK/ConsumptionSaving/ConsPortfolioModel.py#L277-L286

@sbenthall
Copy link
Contributor Author

Note there is a lack of parallelism here.

If RiskyDstn is not time varying, it is a scalar (float).

If it's an infinite horizon model with no age variation, then the solution is a single element list.

It would probably be best if these were the same structure (i.e., list or not, in the singleton case), for consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants