<div dir="ltr"><div>Hi Maniteja,<br><br></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 6, 2015 at 1:12 PM, Maniteja Nandana <span dir="ltr"><<a href="mailto:maniteja.modesty067@gmail.com" target="_blank">maniteja.modesty067@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">Hello everyone,</span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"><br></span></div><div style="font-size:12.8000001907349px">I am writing this mail to enquire about implementing numerical differentiation package in scipy.</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">There have been discussions before (Issue <a href="https://github.com/scipy/scipy/issues/2035" target="_blank">#2035</a>) and some PRs (PR <a href="https://github.com/scipy/scipy/pull/2835" target="_blank">#2835</a>) to include tools to compute derivatives in scipy.</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">According to the comments made in them, as far as I can understand, I see that there are some ways to do derivatives on the computer with varying  generality and accuracy ( by <a href="https://github.com/scipy/scipy/issues/2035#issuecomment-23628615" target="_blank">Alex Griffing</a> ) :</div><div><ol><li><span style="font-size:12.8000001907349px">1st order derivatives of special functions</span></li><li><span style="font-size:12.8000001907349px">derivatives of univariate functions</span></li><li><span style="font-size:12.8000001907349px">symbolic differentiation</span></li><li><span style="font-size:12.8000001907349px">numerical derivatives - finite differences</span></li><li><span style="font-size:12.8000001907349px">automatic or algorithmic differentiation</span></li></ol></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">Clearly, as suggested in the thread, the 1st option is already done in functions like <i>jv</i> and <i>jvp</i> in <b>scipy.special. </b></span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"><br></span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">I think everyone agreed that symbolic derivatives is out of scope of scipy. </span></div></div></div></blockquote><div><br></div><div>Definitely, symbolic anything is out of scipy for scipy:)<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"></span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">Though I would like to hear more about the univariate functions.</span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"><br></span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">Coming to finite differences, the modules described there, <b>statsmodels </b>and <b>numdifftools, </b>they vary in aspects of speed and accuracy, in terms of approaches followed as mentioned in <a href="https://github.com/scipy/scipy/pull/2835#issuecomment-52372036" target="_blank">Joseph Perktold comment</a></span></div><div><ul><li><span style="font-size:12.8000001907349px"><b>Statsmodels </b>used complex step derivatives, which are for first order derivatives and have only truncation error, </span><span style="font-size:12.8000001907349px">no roundoff error since there is no subtraction.</span></li><li><span style="font-size:12.8000001907349px"><b>Numdifftools </b>uses adaptive step-size to calculate finite differences, but will suffer from dilemma to choose small step-size to reduce truncation error but at the same time avoid subtractive cancellation at too small values</span></li></ul><div><span style="font-size:12.8000001907349px">I have read the papers used by both the implementations:</span></div><div><span style="font-size:12.8000001907349px"> <b>Statsmodels </b><a href="https://drive.google.com/file/d/0BwUeCS0FJLRucXdCc1JOTEY0cGc/view?usp=sharing" target="_blank">Statistical applications of the complex-step method of numerical differentiation, Ridout, M.S.</a></span></div><div><span style="font-size:12.8000001907349px"> <b>Numdifftools </b>The pdf attached in the github repository <a href="https://drive.google.com/file/d/0BwUeCS0FJLRuYW1MNlp2enJCaHM/view?usp=sharing" target="_blank">DERIVEST.pdf</a></span></div><div><br></div><div><span style="font-size:12.8000001907349px">Just pointing out in this platform, I think there is an error in equation 13 in DERIVEST, It should be </span></div><div><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><br></span></div><div><span style="color:rgb(80,0,80);font-size:12.8000001907349px">f'-0() = 2f'-delta/2() - f'-delta(),  instead of </span><span style="color:rgb(80,0,80);font-size:12.8000001907349px">f'-0() = 2f'-delta() - f'-delta/2()</span></div><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><div><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><br></span></div>as also correctly mentioned in the matlab code that followed the equation</span></div></div></div></blockquote><div><br></div><div>You may want to let the author know, he'll probably appreciate it.<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div><font color="#500050"><span style="font-size:12.8000001907349px"></span></font><div><span style="font-size:12.8000001907349px">As much as my understanding from the discussions goes, the statsmodels implementation uses elegant broadcasting. Though I get the idea seeing the code, I would really appreciate some examples that clearly explain this.</span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">Also the complex-step method is only for first order derivatives and that function is analytic, so that Cauchy-Riemann equations are valid. So, is it possible to differentiate any function with this ?</span><br><br></div><div><span style="font-size:12.8000001907349px">Also as I was discussing with Christoph Deil, the API implementation issue of whether to use classes, as in numdifftools or as functions, as in statsmodels came to the fore. Though I am not an expert in it, I would love to hear some suggestions on it.</span></div></div></div></div></blockquote><div><br></div><div>It will be important to settle on a clean API. There's no general preference for classes or functions in Scipy, the pros/cons have to be looked at in detail for this functionality. The scope of the scipy.diff project is quite large, so starting a document (as I think you've already discussed with Christoph?) outlining the API that can be reviewed will be a lot more efficient than trying to do it by email alone.<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"></span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">Though at this point AD seems ahead of time, it is powerful in forward and reverse methods, moreover complex-step is somewhat similar to it. The packages <b>ad </b>and <b>algopy </b>use AD. Also, there were concerns with interfacing these methods with C/ Fortran functions. </span><span style="font-size:12.8000001907349px">It would also be great if there could be suggestions regarding whether to implement these methods.</span><span style="font-size:12.8000001907349px"> </span></div></div></div></blockquote><div><br></div><div>It's been around for a while so not sure about "ahead of its time", but yes it can be powerful. It's a large topic though, should be out of scope for this GSoC project. Good finite difference methods will be challenging enough:) That doesn't mean that AD is out of scope for Scipy necessarily, but that's for another time to discuss.<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div style="font-size:12.8000001907349px"></div><div style="font-size:12.8000001907349px">At the same time, it would be really helpful if any new methods or packages to be looked into could be suggested.</div></div></div></blockquote><div><br></div><div>I think what's in numdifftools and statsmodels is a good base to build on. What could be very useful in addition though is an indepent reference implementation of the methods you're working on. This could be Matlab/R/Julia functions or some package written by the author of a paper you're using. I don't have concrete suggestions now - you have a large collection of papers - but you could already check the papers you're using.<br><br></div><div>Cheers,<br></div><div>Ralf<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div style="font-size:12.8000001907349px"></div><div style="font-size:12.8000001907349px">Waiting in anticipation for your feedback and response. Happy to learn :)</div><div><span style="font-size:12.8000001907349px">Thanks for reading along my lengthy mail. Please do correct if I did some mistake.</span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">I have attached the documents I have related to these issues, most importantly <b>The Complex-Step Derivative Approximation by </b></span><span style="font-size:12.8000001907349px"><b>JOAQUIM R. R. A. MARTINS</b></span></div><div><span style="font-size:12.8000001907349px"><b><br></b></span></div><div><span style="font-size:12.8000001907349px"><b><a href="https://drive.google.com/folderview?id=0BwUeCS0FJLRufnJaVko3MGpJX0Nud3R0dHgyc2JBYUgxVkhBTkNvbkhFQWZucmhWSzlaVVk&usp=sharing" target="_blank">Numerical differentiation</a></b></span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">Cheers,</span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">Maniteja.</span></div><span class=""><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">______________________________</span><span style="font-size:12.8000001907349px">_________________</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">SciPy-Dev mailing list</span><br></div><div style="font-size:12.8000001907349px"><a href="mailto:SciPy-Dev@scipy.org" style="font-size:12.8000001907349px" target="_blank">SciPy-Dev@scipy.org</a><br style="font-size:12.8000001907349px"><a href="http://mail.scipy.org/mailman/listinfo/scipy-dev" style="font-size:12.8000001907349px" target="_blank">http://mail.scipy.org/mailman/listinfo/scipy-dev</a></div></span></div></div>
</blockquote></div><br></div></div></div></div>