[SciPy-User] SciPy-User Digest, Vol 130, Issue 23

The Helmbolds helmrp at yahoo.com
Fri Jun 27 16:12:34 EDT 2014


If the matrix is not too large, the straightforward series expansion, for judiciously chosen n can be a remarkably good approximation:

    EXP = I     # the identity matrix
    k = 1
    for k in range(n):    # or 
         EXP = EXP*M / k


>________________________________
> From: "scipy-user-request at scipy.org" <scipy-user-request at scipy.org>
>To: scipy-user at scipy.org 
>Sent: Friday, June 27, 2014 10:00 AM
>Subject: SciPy-User Digest, Vol 130, Issue 23
>  
>
>Send SciPy-User mailing list submissions to
>    scipy-user at scipy.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>    http://mail.scipy.org/mailman/listinfo/scipy-user
>or, via email, send a message with subject or body 'help' to
>    scipy-user-request at scipy.org
>
>You can reach the person managing the list at
>    scipy-user-owner at scipy.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of SciPy-User digest..."
>
>
>Today's Topics:
>
>   1. Re: Faster approach to calculate the matrix exponential
>      (Pauli Virtanen)
>   2. Re: Faster approach to calculate the matrix exponential
>      (Stephan Hoyer)
>   3. Re: Faster approach to calculate the matrix exponential
>      (Michael Kreim)
>   4. Re: Faster approach to calculate the matrix exponential
>      (Troels Emtek?r Linnet)
>
>
>----------------------------------------------------------------------
>
>Message: 1
>Date: Thu, 26 Jun 2014 20:22:17 +0300
>From: Pauli Virtanen <pav at iki.fi>
>Subject: Re: [SciPy-User] Faster approach to calculate the matrix
>    exponential
>To: scipy-user at scipy.org
>Message-ID: <lohks9$8rf$1 at ger.gmane.org>
>Content-Type: text/plain; charset=ISO-8859-1
>
>26.06.2014 14:07, Troels Emtek?r Linnet kirjoitti:
>> Using the scripy method does not sound viable.
>> 
>> It was discussed here,  post 2
>> 
>> http://thread.gmane.org/gmane.science.nmr.relax.devel/6446/match=eliminating+86+bottleneck+numeric+r1rho
>
>That link doesn't load currently.
>
>Nevertheless, using the Scipy implementation inside for loops is faster
>than using the eig() based approach, with a crossover (on my machine)
>when the inner matrix size is bigger than 16x16. This comparison applies
>to Scipy 0.14.0 --- the implementation in earlier Scipy versions is less
>efficient.
>
>Benchmark:
>"""
>from scipy.linalg import expm
>
>def matrix_exponential_scipy(A, dtype=None):
>    B = np.empty(A.shape, dtype=A.dtype)
>    for i in range(A.shape[0]):
>        for j in range(A.shape[1]):
>            for k in range(A.shape[2]):
>                for l in range(A.shape[3]):
>                    for m in range(A.shape[4]):
>                        B[i,j,k,l,m] = expm(A[i,j,k,l,m])
>    return B
>
>import numpy as np
>
>N = 18
>A = np.random.rand(3, 4, 5, 3, 2, N, N)
>
>start_1 = time.time()
>B_1 = matrix_exponential_scipy(A)
>end_1 = time.time()
>
>start_2 = time.time()
>B_2 = matrix_exponential_rank_NE_NS_NM_NO_ND_x_x(A)
>end_2 = time.time()
>
>print("Scipy:", end_1 - start_1)
>print("Numpy:", end_2 - start_2)
>"""
>#-> ('Scipy:', 0.3015120029449463)
>#-> ('Numpy:', 0.31020593643188477)
>
>
>-- 
>Pauli Virtanen
>
>
>
>------------------------------
>
>Message: 2
>Date: Thu, 26 Jun 2014 11:04:54 -0700
>From: Stephan Hoyer <shoyer at gmail.com>
>Subject: Re: [SciPy-User] Faster approach to calculate the matrix
>    exponential
>To: SciPy Users List <scipy-user at scipy.org>
>Message-ID:
>    <CAEQ_TvdDYFZOZimHrCGbkPJwXGS=RCw5U-5h6-k0D9MA5Zgccw at mail.gmail.com>
>Content-Type: text/plain; charset="utf-8"
>
>On Thu, Jun 26, 2014 at 5:32 AM, Charles R Harris <charlesr.harris at gmail.com
>> wrote:
>>
>> Are you solving a differential equation? If so, an explicit solution may
>> not be the best way to go.
>>
>
>I agree.
>
>My experience with solving very similar quantum mechanics problems is that
>using an ODE integrator like zofe (via scipy.integrate.ode) can be much
>faster than solving the propagator exactly..
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20140626/ec2d91f3/attachment-0001.html
>
>------------------------------
>
>Message: 3
>Date: Thu, 26 Jun 2014 20:46:23 +0200
>From: Michael Kreim <michael at perfect-kreim.de>
>Subject: Re: [SciPy-User] Faster approach to calculate the matrix
>    exponential
>To: SciPy Users List <scipy-user at scipy.org>
>Message-ID: <53AC6A7F.2060001 at perfect-kreim.de>
>Content-Type: text/plain; charset=UTF-8; format=flowed
>
>Am 26.06.2014 10:31, schrieb Troels Emtek?r Linnet:
>> Do any of you know any faster approach to calculate the matrix exponential ?
>
>Am 26.06.2014 20:04, schrieb Stephan Hoyer:
>>
>> On Thu, Jun 26, 2014 at 5:32 AM, Charles R Harris
>> <charlesr.harris at gmail.com <mailto:charlesr.harris at gmail.com>> wrote:
>>
>>     Are you solving a differential equation? If so, an explicit solution
>>     may not be the best way to go.
>>
>>
>> I agree.
>>
>> My experience with solving very similar quantum mechanics problems is
>> that using an ODE integrator like zofe (via scipy.integrate.ode) can be
>> much faster than solving the propagator exactly..
>>
>
>Hi,
>
>I never used Python for my numerical Problems, but I worked with some 
>PDEs of the d/dt p = Ap type in the recent time (but not from quantum 
>mechanics).
>
>I agree with Stephan and Charles that it my be worth trying to solve the 
>ODE using any suitable ODE solver. In Matlab I made the experience that 
>it is very problem depended if the ode solver or the matrix exponential 
>method is faster.
>
>Also you can have a look at expokit which is a very good implementation 
>of matrix exponential solvers (using Krylov subspace methods):
>http://www.maths.uq.edu.au/expokit/
>Unfortunately there is no Python implementation but maybe you can call 
>the fortran or C++ version from python.
>
>And you can have a look at operator splitting methods. If it is possible 
>to split your problem in two (or more) sub problems, then these methods 
>often speed up the numerical computations. The problem usually lies in 
>finding a suitable splitting. The implementation is not very 
>complicated, if you have numerical methods for the sub problems.
>
>
>Cheers,
>
>Michael
>
>
>
>------------------------------
>
>Message: 4
>Date: Fri, 27 Jun 2014 10:57:01 +0200
>From: Troels Emtek?r Linnet <tlinnet at gmail.com>
>Subject: Re: [SciPy-User] Faster approach to calculate the matrix
>    exponential
>To: SciPy Users List <scipy-user at scipy.org>
>Message-ID:
>    <CA+CBx2PHnrSSYQg6URYN7Ro1KT5nmQefdbtmHtGiem2XzMnQiA at mail.gmail.com>
>Content-Type: text/plain; charset=UTF-8
>
>Dear Gregor, Charles, Eric, Pauli, Stephan and Michael.
>
>Thank you for your valuable input!
>This saves me alot of time.
>
>It seems that the Gmane mail archive have some issues. Another mail server:
>http://www.mail-archive.com/relax-devel@gna.org/msg06311.html
>And then "Next message".
>
>I have also discussed this at our own mailing list:
>http://www.mail-archive.com/relax-users@gna.org/msg01634.html
>
>What I read from your comments is:
>Look into ODE integrator like zofe (scipy.integrate.ode)
>
>It also becomes clear for me, that I should sit down with theory to grasp, why
>I actually do:
>
>1) matrix exponential
>2) matrix power
>
>in all the numerical models.
>Then I would be able to select which best method to apply.
>
>Best
>Troels
>
>Troels Emtek?r Linnet
>
>
>2014-06-26 20:46 GMT+02:00 Michael Kreim <michael at perfect-kreim.de>:
>> Am 26.06.2014 10:31, schrieb Troels Emtek?r Linnet:
>>> Do any of you know any faster approach to calculate the matrix exponential ?
>>
>> Am 26.06.2014 20:04, schrieb Stephan Hoyer:
>>  >
>>  > On Thu, Jun 26, 2014 at 5:32 AM, Charles R Harris
>>  > <charlesr.harris at gmail.com <mailto:charlesr.harris at gmail.com>> wrote:
>>  >
>>  >     Are you solving a differential equation? If so, an explicit solution
>>  >     may not be the best way to go.
>>  >
>>  >
>>  > I agree.
>>  >
>>  > My experience with solving very similar quantum mechanics problems is
>>  > that using an ODE integrator like zofe (via scipy.integrate.ode) can be
>>  > much faster than solving the propagator exactly..
>>  >
>>
>> Hi,
>>
>> I never used Python for my numerical Problems, but I worked with some
>> PDEs of the d/dt p = Ap type in the recent time (but not from quantum
>> mechanics).
>>
>> I agree with Stephan and Charles that it my be worth trying to solve the
>> ODE using any suitable ODE solver. In Matlab I made the experience that
>> it is very problem depended if the ode solver or the matrix exponential
>> method is faster.
>>
>> Also you can have a look at expokit which is a very good implementation
>> of matrix exponential solvers (using Krylov subspace methods):
>> http://www.maths.uq.edu.au/expokit/
>> Unfortunately there is no Python implementation but maybe you can call
>> the fortran or C++ version from python.
>>
>> And you can have a look at operator splitting methods. If it is possible
>> to split your problem in two (or more) sub problems, then these methods
>> often speed up the numerical computations. The problem usually lies in
>> finding a suitable splitting. The implementation is not very
>> complicated, if you have numerical methods for the sub problems.
>>
>>
>> Cheers,
>>
>> Michael
>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
>------------------------------
>
>_______________________________________________
>SciPy-User mailing list
>SciPy-User at scipy.org
>http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
>End of SciPy-User Digest, Vol 130, Issue 23
>*******************************************
>
>
>    
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20140627/48fe43cc/attachment.html>


More information about the SciPy-User mailing list