sahilm89 / lhsmdu

This is an implementation of Deutsch and Deutsch, "Latin hypercube sampling with multidimensional uniformity", Journal of Statistical Planning and Inference 142 (2012) , 763-772
MIT License
79 stars 16 forks source link

numpy.AxisError: axis -1 is out of bounds for array of dimension 0 after package update #8

Closed MatthiVH closed 4 years ago

MatthiVH commented 4 years ago

Hi S,

I updated the lhsmdu-package today and tested the code from the 'basics'-section you provided, but I immediately got the following error (it never happened with the previous install of your package I had installed):

Traceback (most recent call last): File "C:\Program Files\Python 3.5\lib\site-packages\IPython\core\interactiveshell.py", line 3326, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in runfile('C:/Users/myvhove/Documents/CE_70/Python/LHS_MDU_test.py', wdir='C:/Users/myvhove/Documents/CE_70/Python') File "C:\Program Files\JetBrains\PyCharm 2019.2.3\helpers\pydev_pydev_bundle\pydev_umd.py", line 197, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "C:\Program Files\JetBrains\PyCharm 2019.2.3\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:/Users/myvhove/Documents/CE_70/Python/LHS_MDU_test.py", line 6, in k = lhsmdu.sample(2, 20) # Latin Hypercube Sampling with multi-dimensional uniformity File "C:\Program Files\Python 3.5\lib\site-packages\lhsmdu__init.py", line 109, in sample matrixOfStrata = eliminateRealizationsToStrata(distance_1D, matrixOfRealizations, numSamples) File "C:\Program Files\Python 3.5\lib\site-packages\lhsmdu__init.py", line 45, in eliminateRealizationsToStrata realizations = sort(averageDistance.keys()) File "<array_function internals>", line 6, in sort File "C:\Program Files\Python 3.5\lib\site-packages\numpy\core\fromnumeric.py", line 970, in sort a.sort(axis=axis, kind=kind, order=order) numpy.AxisError: axis -1 is out of bounds for array of dimension 0

The problem is in the sample-function: k = lhsmdu.sample(2, 20) # Latin Hypercube Sampling with multi-dimensional uniformity


sahilm89 commented 4 years ago

Checking this out now. I think it may have to do with the differences in numpy sort functions between Python 2 and 3. I'll fix it and post a patch.

MatthiVH commented 4 years ago

Great! Had to go to the 0.1-version again to be able to work with it. I'm indeed working in Python 3.

sahilm89 commented 4 years ago

Okay. This is fixed. Turns out it had to do with the dict_object difference between Python2 and Python3. Hmmm, I guess I just need to make a Python3 unit test and add it in.

MatthiVH commented 4 years ago

Will you give a sign once the fixed version is available for usage?

sahilm89 commented 4 years ago

I've already uploaded a patch. Could you see if it works for you? S

sahilm89 commented 4 years ago

Hi M,

Are you still having trouble with the repo, or did the patch solve it?

Best, S

MatthiVH commented 4 years ago

Now, it works. Thanks! It is indeed much much much faster, especially when n becomes high (e.g., 1000).

sahilm89 commented 4 years ago

Yeah, it's improved efficiency is helping my own work as well. Thanks for raising the issue, I wouldn't have spent time optimizing it without it! Closing the issue now.

Cheers, S