-
Notifications
You must be signed in to change notification settings - Fork 89
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
Implement Delay and Smooth functions #18
Comments
This is mostly implemented, some of the weird cases (Smooth3I, for example) aren't fully elaborated yet. After we implement subscripts, it may make sense to rework the implicit stocks in a delay or smooth function to use the subscript syntax, just for ease of use. |
Now that there is some meat on the subscripting bones, we can address delays using subscripted functions, and hopefully get some of the benefits of array mathematics. What we essentially need to do is add a dimension to a copy of the delayed variable. |
Just to have a quick record, here's the basic algorithm of the delay function. First define the result that will be delayed: inval = xr.DataArray(data=[1,2,3], coords={'Dim1':['A','B','C']})
Now create an empty delay structure to track values through the delay sequence: order = 4
a = xr.DataArray(data=np.tile(0, [len(inval), order]),
coords={'Dim1':['A','B','C'], '_delay': range(order)})
Now work out the derivative for the delayed stock. delay = 8
ddt = (a/(delay/order)).shift(**{'_delay': 1}).fillna(inval) - (a/(delay/order))
I haven't done any optimization here, so in the future, that work remains to be done. |
A few other tests we should implement and try:
|
Existing tests pass as of 2a41b2f, so closing this issue. If we find bugs we'll open another. |
A delay function must essentially create a number of hidden 'stocks' in the background of the model (one for each order of the delay). This requires some intelligent construction in the translation functions, and a clever ability to handle these delays.
Additionally, some types of analysis won't be quite as easy when delay stocks are hidden, (mostly things that modify the model step-at-a-time) so we'll need to think about that some as well.
The text was updated successfully, but these errors were encountered: