ufoym / agpy

Automatically exported from code.google.com/p/agpy
MIT License
1 stars 0 forks source link

plfit method throws an exception very small input datasets #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Here is the output of an interactive Python session that demonstrates the
problem:
Python 2.6.4 (r264:75706, Oct 27 2009, 06:25:13) 
[GCC 4.4.1] on linux2                            
Type "help", "copyright", "credits" or "license" for more information.
>>> import plfit                                                      
Fortran plfit module loaded successfully.                             
Cython plfit module could not be loaded.                              
>>> import numpy                                                      
>>> b = plfit.plfit(numpy.array([1.32229441, 1.43501644, 81.77759316,
1.91129617, 2.27631398, 2.15192244, 1.91463253, 1.86362888, 1.67958862]),
quiet=True, silent=True, nosmall=True)                                          

Traceback (most recent call last):                                              
  File "<stdin>", line 1, in <module>                                           
  File "/home/amunkres/uoregon/winter2010/cis601/lib/python2.6/site-
    self.plfit(**kwargs)                                                        
  File "/home/amunkres/uoregon/winter2010/cis601/lib/python2.6/site-
    xmin  = xmins[argmin(dat)]                                                  
  File "/home/amunkres/uoregon/winter2010/cis601/lib/python2.6/site-
    return argmin(axis)                                                         
ValueError: attempt to get argmax/argmin of an empty sequence                   
>>> 
I also tried it with fplfit.so renamed so that Python couldn't find it and
load it, to force the use of the pure-Python implementation instead. When
using this dataset with the pure-Python implementation, it threw the same
exception, from the same place in the code.

What is the expected output? What do you see instead?
See above.

What version of the product are you using? On what operating system?
Libraries: SVN revision r116 of agpy, numpy 1.4.0, matplotlib 0.99.1.2
(well, the tar file is named matplotlib-0.99.1.2.tar.gz this number, but
the directory within it is matplotlib-0.99.1.1), scipy 0.7.1
OS: both Arch Linux and CentOS 5.3

Please provide any additional information below.
I examined the values of variables when using the Python implementation,
and found that the list "goodvals" on lines 141-142 had "False" as its
first element. This caused argmin(goodvals) to return 0, and therefore
nmax was 0, and therefore "dat" was an empty list, and therefore the call
to argmin(dat) threw the exception. I don't understand it well enough to
know what the correct behavior here should be, though.
(Note: the example data above that triggers the exception was one instance
of "fakedata" generated by test_pl. The dataset which I was running
test_pl on when it generated the problematic "fakedata" was [82, 74, 40,
35, 16, 6, 1, 1, 1] and finite=True.)

Original issue reported on code.google.com by amunk...@uoregon.edu on 26 Jan 2010 at 12:52

GoogleCodeExporter commented 9 years ago
I had a look at the problem.  It looks like it's a result of having a very small
sample set.  I've added a workaround that will continue through with all data 
even if
the S/N is too low to do anything with it... I'd take any power-law-distribution
results with a sample size of 10 with a brick of salt.

Original comment by keflavich on 28 Feb 2010 at 11:58

GoogleCodeExporter commented 9 years ago
I think my changes fixed the Exception, this ticket just remained open because 
I gave the wrong Status message

Original comment by keflavich on 8 Aug 2011 at 9:38