-
Notifications
You must be signed in to change notification settings - Fork 30
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
Integration of economic model into existing framework #170
Comments
I just wanted to check the concept, which requires alterations on 2 levels:
A dummy model setup, just to verify the concept of handling the variable dimensions: state_2d = "y2" # y2 is a 2D variable, y1 is a 1D variable
state_names = ["y1", "y2"]
stratification_size = 3 # stratification level of 3
split_point = (len(state_names) - 1) * stratification_size
# User would write the integrate function and make sure it works for the envisioned (2D) dimensions
def integrate(t, y1, y2):
"""y1 1x3 ; y2 3x3 """
dy1 = -0.3*y1
dy2 = 0.1*y2
return (dy1, dy2)
# `create_fun` method of the base class should make sure the function returned should do the following
def func(t, y, pars={}):
"""As used by scipy -> flattend in, flattend out"""
# incoming y -> different reshape for 1D vs 2D variables (2)
y_1d, y_2d = np.split(y, [split_point])
y_1d = y_1d.reshape(((len(state_names) - 1), stratification_size)),
y_2d = y_2d.reshape((stratification_size, stratification_size))
dstates = integrate(t, *y_1d, y_2d)
return np.concatenate([np.array(state).flatten() for state in dstates])
# Setup/run model
initial_states = {"y1": [42., 42., 42.],
"y2": np.ones((3, 3))}
time = [0, 5]
initial_states[state_2d] = initial_states[state_2d].flatten() # Handle intial condition (1)
result = solve_ivp(func, time, list(itertools.chain(*initial_states.values())))
# To output: different reshape for 1D vs 2D variables to collect output (3)
output = result["y"]
y_1d, y_2d = np.split(output, [split_point])
y_1d, y_2d.reshape((len(result["t"]), stratification_size, stratification_size)) Note: cfr. remarks of #178 about the usage of the scipy solver. Most of the reshaping (bookkeeping dimensions) is to fit it into the scipy solver. If in practice, the discrete version is always used (and the called method is an update of the states as such), this kind of bookkeeping is probably not required as the |
Currently, I have a working implementation of an economic production model in the notebook
twallema-uncoupled-economic-model.ipynb
on my branchtwallema/uncoupled_economic_model
. I would like to incorporate this model as much as possible using the existing modeling framework of Stijn and Joris. The economic model is in essence, a discrete-time system which can be written as,My economic model has 7 states, which are stratified in 63 economical sectors,
x
: productivity of sector ic
: household consumption of good if
: exogeneous consumption of good id
: total demand for good il
: labor income in sector iO
: total orders made by sector iS
: stock matrix, per sector i, how much stock of good from sector j remainAll states are 63-dimensional vectors, except the last state,
S
, which is a 63x63 matrix. I have so far tried to use a manual definition of the state sizes but I find this complicates the code and is not a modular solution of the problem. Becausereshape
is used, this will only work if some states are square matrices of size [stratification_size * stratification_size]. The state S does not necessarily need to be returned to the end-user. It is not an interesting state but it is needed to calculate the new values of the other states. Maybe the issue can be circumvented by somehow initializing an initial stock matrix S in a place/way so thatintegrate
can load the previous value, perform its calculation of the other states, and then store the new stock matrix S someplace (and repeat the above in an iterative manner).Something like this,
However, I need some pointers or inspiration on how to accomplish this.
@jorisvandenbossche @stijnvanhoey
The text was updated successfully, but these errors were encountered: