pafoster / pyitlib

A library of information-theoretic methods for data analysis and machine learning, implemented in Python and NumPy.
MIT License
90 stars 17 forks source link

Windows `int` type issue #12

Open Kaketo opened 1 year ago

Kaketo commented 1 year ago

I have a problem running the package on the Windows system (on Mac and Linux it works like a charm).

from pyitlib import discrete_random_variable as drv
drv.entropy(np.array([1.5,1.4,0.2]))

throws

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[7], line 2
      1 from pyitlib import discrete_random_variable as drv
----> 2 drv.entropy(np.array([1.5,1.4,0.2]))

File ~\Envs\multi-label-cs-group-fs\lib\site-packages\pyitlib\discrete_random_variable.py:3843, in entropy(X, base, fill_value, estimator, Alphabet_X, keep_dims)
   3840 if not (np.isscalar(base) and np.isreal(base) and base > 0):
   3841     raise ValueError("arg base not a positive real-valued scalar")
-> 3843 S, fill_value = _map_observations_to_integers((X, Alphabet_X),
   3844                                               (fill_value_X,
   3845                                                fill_value_Alphabet_X))
   3846 X, Alphabet_X = S
   3848 H = np.empty(X.shape[:-1])

File ~\Envs\multi-label-cs-group-fs\lib\site-packages\pyitlib\discrete_random_variable.py:4695, in _map_observations_to_integers(Symbol_matrices, Fill_values)
   4692         assert(not np.any(A == FILL_VALUE))
   4693         A[A == f] = FILL_VALUE
-> 4695 assert(np.all([A.dtype == 'int' for A in Symbol_matrices]))
   4696 return Symbol_matrices, FILL_VALUE

AssertionError:

It seems that the default int on my machine is np.int32 not np.int64, because when I changed the assert in the source code of _map_observations_to_integers function

Maybe You have a suggestion on how to cover this bug in my code?

rzijp commented 12 months ago

Ran into the same issue