dgalant | 1 Oct 08:48
Picon

Finding all the roots in an interval

I can't help but to jump in with an old and probably obscure
reference to a paper

BUSH JONES, W. G. WALLER and ARNOLD FELDMAN,
"Root isolation using function values"

(Google the title)

which gives a rather neat solution to this problem.
No, it is not foolproof, but it would be successful
for the problem you have stated. Not Python, but Fortran
program given.

David Galant
dgalant <at> zahav.net.il
Gael Varoquaux | 1 Oct 09:12
Favicon
Gravatar

Re: All the roots of a function in an interval

Hi Anne,

Thanks a lot for your reply, enlightening as usual.

On Sat, Sep 29, 2007 at 03:51:30PM -0400, Anne Archibald wrote:
> The easiest and most reliable method here is to simply sample the
> function at equispaced points the nearest distance apart they can be;
> then every sign change gives you an interval bracketing a root.

I did exactly as you suggested. It is indeed the best solution.
Unfortunately it is slowish, and cannot be well implemented with arrays.
Here is the code I got to, just in case it can be of some use for
somebody later on:

def find_x(m_K, m_Rb, delta_x):
    """ Returns the 2D array of x for which:
        m_K * sin(k_Rb * x) - m_Rb * sin(k_K *(x + delta_x)) == 0
        with delta_x a 1D array.
    """
    delta_x = c_[delta_x]
    f = lambda x, delta_x: m_K*sin(k_Rb*x) - m_Rb*sin(k_K*(x + delta_x))
    interval = linspace(-5*Delta_x, 5*Delta_x, 150)
    scan = f(interval, delta_x)
    sign_changes_mask = (scan[:, 1:]*scan[:, :-1])<0
    min_num_x = (sign_changes_mask.sum(axis=-1)).min()
    x = empty((len(delta_x), min_num_x))
    indexes = arange(len(interval))
    for index, this_delta_x in enumerate(delta_x.flat):
        #this_x = _find_x(m_K, m_Rb, this_delta_x)
        # Keep only the min_num_x inner most solutions:
(Continue reading)

Gael Varoquaux | 1 Oct 09:22
Favicon
Gravatar

Re: Finding all the roots in an interval

On Mon, Oct 01, 2007 at 08:48:32AM +0200, dgalant wrote:
> I can't help but to jump in with an old and probably obscure
> reference to a paper

> BUSH JONES, W. G. WALLER and ARNOLD FELDMAN,
> "Root isolation using function values"

It's probably the solution to the problem I was having. I can't read the
paper unfortunately, as being in a physics departement I don't have
access to this publication. It is interesting to see that it is quoted
in a paper on maximum likelihood parameter estimation, which is exactly
the context in which I stumbled on this problem.

As I stated in my answer to Anne, I might shift totally my strategy and
no longer have to find these roots, because both the analytic
calculations, and the root finding numerical problem, get much more
complicated as I add more physics in my problem.

Thanks for the reference, though, it is useful to know where this problem
has been discussed.

Cheers,

Gaël
LB | 1 Oct 11:49
Picon

Re: Pb with numpy.histogram

> I think histogram has had this weird behavior since the numeric era and a
> lot of code may break if we fix it. Basically, histogram discards the lower
> than range values as outliers but puts the higher than range values into the
> last bin.
I think this should be clearly explained in the doc string. The
current doc string says
"Values outside of this range are allocated to the closest bin".
This is wrong, can leads to bug and should be fixed.

numpy.histogram's behavior seems still weirds to me, and I don't see
why values
lower than range should always be discarded as outliers.
If the real problem is cosistency with older versions from the numeric
era,
what about adding a new keyword to the function, says "discard", which
could be
used to decide what to do with values outside the range :
   - 'low'    	=> values lower than the range are discarded, values
higher are added to the last bin
   - 'up'	=> values higher than the range are discarded, values lower
are added to the first bin
   - 'out'	=> values out of the range are discarded
   - None	=> values outside of this range are allocated to the closest
bin

For compatibility reason, a default value of 'low' could be used.

> I'm generally using my own histograming routines, I could send them your way
> if you're interested.
Thanks, I will check the code you've put in the sandbow at home.
(Continue reading)

massimo sandal | 1 Oct 16:51
Picon
Favicon

Re: Pb with numpy.histogram

David Huard ha scritto:
> Hi LB,
> 
> I think histogram has had this weird behavior since the numeric era and 
> a lot of code may break if we fix it. 
 > Basically, histogram discards the
 > lower than range values as outliers but puts the higher than range
 > values into the last bin.
 >
 > I'm generally using my own histograming routines, I could send them your
 > way if you're interested.

I'm not a SciPy developer so my weight on the discussion is next to 
zero, but I personally think that other people code breaking is not a 
good reason to keep a buggy function.

We don't want code that relies on bugs like they were features: we're 
not Microsoft, aren't we? ;)

People should be informed before updating, of course, and maybe an 
oldhistogram() function could be maintained to allow for easy updating, 
but if histogram() behavour is so flawed that people is forced to 
rewrite their own routines, please fix it.

m.

--

-- 
Massimo Sandal
University of Bologna
Department of Biochemistry "G.Moruzzi"
(Continue reading)

David Huard | 1 Oct 16:57
Picon

Re: Pb with numpy.histogram



2007/10/1, LB <berthe.loic <at> gmail.com>:
> I think histogram has had this weird behavior since the numeric era and a
> lot of code may break if we fix it. Basically, histogram discards the lower
> than range values as outliers but puts the higher than range values into the
> last bin.
I think this should be clearly explained in the doc string. The
current doc string says
"Values outside of this range are allocated to the closest bin".
This is wrong, can leads to bug and should be fixed.

You're right. In fact, it said so at some point but it seems it has been edited out.
 

numpy.histogram's behavior seems still weirds to me, and I don't see
why values
lower than range should always be discarded as outliers.
If the real problem is cosistency with older versions from the numeric
era,
what about adding a new keyword to the function, says "discard", which
could be
used to decide what to do with values outside the range :
   - 'low'      => values lower than the range are discarded, values
higher are added to the last bin
   - 'up'       => values higher than the range are discarded, values lower
are added to the first bin
   - 'out'      => values out of the range are discarded
   - None       => values outside of this range are allocated to the closest
bin

For compatibility reason, a default value of 'low' could be used.

Good idea. Better yet would be to raise a deprecation warning and change the function in the next or second next release, and ideally replace it with something written in C to speed things up. The final decision is up to someone else than me, though.

Cheers,

David

_______________________________________________
SciPy-user mailing list
SciPy-user <at> scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-user
Tim | 1 Oct 18:45
Picon

plotting a surface

Hello,
I have some code written in IDL but would very much like to switch to IDl
for the next projects because the synatx seems friendlier to me.

One question though: 

How do I conceive surface plots in matplotlib or any other plotting module?

Many tutorials state that this isn't possible, so far.

Is that right?

tutorials with remarks about surface plotting:

1) http://xweb.geos.ed.ac.uk/~hcp/notes_python.pdf
cf. An Introduction to matplotlib
3.1 Surface plots
Matplotlib has no equivalent of R’s persp or IDL’s surface.
This section left blank.

2) matplotlib does not yet have equivalents for all IDL 2-D plotting capability
(e.g., surface plots)

cf. http://dae.iaa.csic.es/~eperez/Python-IDL-comparison.pdf
"Appendix B: Why would I switch from IDL to Python (or not)?" page 3

3) no real equivalent python command in
http://cfa-www.harvard.edu/~jbattat/computer/python/science/idl-numpy.html

Thanks in adavnce for your comments on that!

Tim

_______________________________________________
SciPy-user mailing list
SciPy-user <at> scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-user
Alan G Isaac | 1 Oct 19:28
Picon
Favicon
Gravatar

Re: plotting a surface

http://www.american.edu/econ/notes/soft.htm#pyplot

fwiw,
Alan Isaac
Alan G Isaac | 1 Oct 20:09
Picon
Favicon
Gravatar

Hodrick-Prescott filter

I'm looking for a Hodrick-Prescott filter.
http://en.wikipedia.org/wiki/Hodrick-Prescott_filter#External_links
Is there one in SciPy, or can someone post one?

Thank you,
Alan Isaac
Andy Fraser | 1 Oct 20:47

Re: plotting a surface

>>>>> "Tim" == Tim  <timmichelsen <at> gmx-topmail.de> writes:

    Tim> [...] One question though:

    Tim> How do I conceive surface plots in matplotlib or any other
    Tim> plotting module?  [...]

My solution is to:

   1. Write the data to a file.
   2. Open a pipe to gnuplot.
   3. Write gnuplot commands including "splot" to the pipe

It isn't pretty, but it works, and it gives me access to anything that
gnuplot can do.

Andy

Gmane