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

Wrong results when nan values occur in inflow driven calculations #4

Open
cardosan opened this issue Apr 12, 2016 · 2 comments
Open

Comments

@cardosan
Copy link
Contributor

Hi Stephan,
when there are nan value in the inflow array it gives wrong results (see below).
converting all the nan to 0 in the stock by cohort array this is solved, at least for the inflow driven calculations

TestDSM = DynamicStockModel(t =  np.arange(1,11,1),
                            i =  [np.nan,np.nan,np.nan,np.nan,np.nan,1,2,3,4,np.nan], 
                            lt = {'Type': 'Normal', 'Mean': np.array([5]), 'StdDev': np.array([1.5]) })
​
In [5]:

Stock_by_cohort, ExitFlag = TestDSM.compute_s_c_inflow_driven()
print(Stock_by_cohort)
[[        nan  0.          0.          0.          0.          0.          0.
   0.          0.          0.        ]
 [        nan         nan  0.          0.          0.          0.          0.
   0.          0.          0.        ]
 [        nan         nan         nan  0.          0.          0.          0.
   0.          0.          0.        ]
 [        nan         nan         nan         nan  0.          0.          0.
   0.          0.          0.        ]
 [        nan         nan         nan         nan         nan  0.          0.
   0.          0.          0.        ]
 [        nan         nan         nan         nan         nan  1.          0.
   0.          0.          0.        ]
 [        nan         nan         nan         nan         nan  0.99240268
   2.          0.          0.          0.        ]
 [        nan         nan         nan         nan         nan  0.9564087
   1.98480535  3.          0.          0.        ]
 [        nan         nan         nan         nan         nan  0.84706865
   1.9128174   2.97720803  4.          0.        ]
 [        nan         nan         nan         nan         nan  0.63410331
   1.6941373   2.86922609  3.9696107          nan]]
In [6]:

S, ExitFlag   = TestDSM.compute_stock_total()
print(S)
[ nan  nan  nan  nan  nan  nan  nan  nan  nan  nan]
cardosan added a commit to cardosan/dynamic_stock_model that referenced this issue Apr 12, 2016
All nan in inflow driven calculations are changed to zeros for both inflow and outflow by cohort computations . Fixes stefanpauliuk#4

P.S: maybe the same prob with nan occurs also in stock driven calculations. Do not know since I am not using it
@stefanpauliuk
Copy link
Owner

Hi Cardosan,

thanks for checking this! Indeed, the dynamic stock model class uses summation and does not check whether any or the inputs is NaN, in which case also NaN is returned as result.

Currently I am of the opinion that there should be no such check as the user of the class is responsible for inserting proper numbers. Compare, for example np.dot, which also accepts NaN values.
Will hear with some Python friends about what to do.

Thanks again!

Stefan

@cardosan
Copy link
Contributor Author

Hey Stephan,
I also actually dunno what is the best way to follow but also if you think that this check should not be done would be good to specify that nan values should not appear in the inflow array in the documentation.

Like I was using the class to calculate stocks for several wood products and countries coming from international statistics and several prod either are not consumed in some countries or their production started only recently and it gave me quite some trouble to discover that this was the reason why the results were very strange.
Cheers
Giuseppe (my real name :) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants