ELIFE-ASU / Neet

Simulating and analyzing dynamical network models
https://neet.readthedocs.io/en/stable
Other
4 stars 10 forks source link

Fix rounding error in StateSpace._unsafe_encode #152

Closed dglmoore closed 5 years ago

dglmoore commented 5 years ago

Numpy arrays use different integer types than Python proper. When they overflow, they don't covert to larger integer types. Instead they convert to floats. This makes sense give numpy is written in C, but it's a problem for us as we encode states of type numpy.ndarray. Specifically, encoded += place * x will change the type of encoded from long to np.float64 if x is a numpy integer/float type and place * x overlows. When we get to the return statement of StateSpace._unsafe_encode and convert the result to a long, the value gets rounded.

We fixed this by changing

encoded += place * x

to

encoded += place * long(x)

and getting rid of the redundant conversion at the end.

codecov-io commented 5 years ago

Codecov Report

Merging #152 into master will increase coverage by 0.47%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #152      +/-   ##
==========================================
+ Coverage   90.38%   90.85%   +0.47%     
==========================================
  Files          16       16              
  Lines        1383     1389       +6     
==========================================
+ Hits         1250     1262      +12     
+ Misses        133      127       -6
Impacted Files Coverage Δ
neet/boolean/examples.py 100% <100%> (ø) :arrow_up:
neet/statespace.py 100% <100%> (ø) :arrow_up:
neet/boolean/logicnetwork.py 96.73% <0%> (+3.26%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0785122...6310706. Read the comment docs.