b45ch1 / algopy

AlgoPy is a Research Prototype for Algorithmic Differentation in Python
79 stars 14 forks source link

Directly evaluate nth derivatives of some numpy and scipy univariate functions that operate elementwise. #28

Closed argriffing closed 11 years ago

argriffing commented 11 years ago

This adds a couple of files, so I made this a separate branch that I'm trying to merge. The idea is that this reorganization removes a bunch of junk that was cluttering your algorithms.py file. The new module called "nthderiv" basically adds a new keyword argument 'n' to a bunch of numpy and scipy.special functions, where n specifies the nth derivative.

Some of these functions are used in my dumb forward mode and pullback implementations in algorithms.py. Presumably these forward and pullback implementations could be rewritten more efficiently in the future, in a way that does not use the direct evaluation of the nth derivative of the numpy and scipy.special functions.

b45ch1 commented 11 years ago

Your changes look very nice :), but I'm still on Scipy 0.11.0 (which comes with Ubutnu 12.04). When I run the unittest I get the following error.

======================================================================
ERROR: Failure: AttributeError ('module' object has no attribute 'erfi')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home/swalter/projects/algopy/algopy/__init__.py", line 66, in <module>
    import utpm
  File "/home/swalter/projects/algopy/algopy/utpm/__init__.py", line 29, in <module>
    from utpm import *
  File "/home/swalter/projects/algopy/algopy/utpm/utpm.py", line 18, in <module>
    from algorithms import RawAlgorithmsMixIn, broadcast_arrays_shape
  File "/home/swalter/projects/algopy/algopy/utpm/algorithms.py", line 28, in <module>
    from algopy import nthderiv
  File "/home/swalter/projects/algopy/algopy/nthderiv/__init__.py", line 5, in <module>
    from nthderiv import *
  File "/home/swalter/projects/algopy/algopy/nthderiv/nthderiv.py", line 320, in <module>
    @basecase(scipy.special.erfi)
AttributeError: 'module' object has no attribute 'erfi'

I believe I'm not the only one who is still using such an antique scipy version ;). Would it be possible to add some conditionals that exclude the new scipy functions (and their unit test)?

argriffing commented 11 years ago

I added a fallback erfi implementation, and I've tested after having uninstalled mpmath and sympy.

It is possible that there are more compatibility issues with non-development scipy, but I'm too lazy to deal with virtual machines or alternate scipy environments to check this.

argriffing commented 11 years ago

I've run the tests under a non-devel scipy (0.10.1) and it does not give errors, but numdifftools is spamming a few extra warnings.