Mistake in fit_praxis documentation

Using the Multiple Run Fitter, praxis, etc..
Post Reply
kidd
Posts: 11
Joined: Sat Oct 02, 2010 7:18 am

Mistake in fit_praxis documentation

Post by kidd » Mon Oct 25, 2010 10:24 am

the example in the tutorial have error
"bad stack access : expecting (double*)..." how can dissolve it, i need to run the example to check how it works

ted
Site Admin
Posts: 5334
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Mistake in fit_praxis documentation

Post by ted » Mon Oct 25, 2010 10:33 am

There are lots of tutorials. Which one do you mean? At what point in that tutorial did you encounter the error message?

kidd
Posts: 11
Joined: Sat Oct 02, 2010 7:18 am

Re: Mistake in fit_praxis documentation

Post by kidd » Tue Oct 26, 2010 6:40 am

here : http://www.neuron.yale.edu/neuron/stati ... fit_praxis
this is a new help for fit_praxis. the 'Hoc example' have this error :

Code: Select all

bad stack access: expecting (double *); really (Object **)
nrniv: interpreter stack type error

ted
Site Admin
Posts: 5334
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Mistake in fit_praxis documentation

Post by ted » Tue Oct 26, 2010 9:43 am

http://www.neuron.yale.edu/phpBB/postin ... =23&t=2089
is not a tutorial. It is the Programmer's Reference entry on fit_praxis (which is why I changed the "Subject" of this discussion thread to "Mistake in fit_praxis documentation").

And the hoc example, which I reproduce here

Code: Select all

objref vec
vec = new Vector(2) // vec.x[0] is x, vec.x[1] is y
func efun() {local x, y
  x = $&2[0]  y = $&2[1]
  return (x+y - 5)^2 + 5*(x-y - 15)^2
}
attr_praxis(1e-5, .5, 0)
e = fit_praxis(vec.size(), "efun", vec)
printf("e=%g x=%g y=%g\n", e, vec.x[0], vec.x[1])

objref paxis
paxis = new Vector()
for i=0, 1 {
  pval = pval_praxis(i, paxis)
  printf("%d  %10g      %10g %10g\n", i, pval, paxis.x[0], paxis.x[1])
}
to make sure we are talking about the same thing, does not generate an error message. It works fine.

Which suggests that you are referring to something else. Exactly what code did you try, that generated the error message that you report?

kidd
Posts: 11
Joined: Sat Oct 02, 2010 7:18 am

Re: Mistake in fit_praxis documentation

Post by kidd » Tue Oct 26, 2010 2:16 pm

this is the same code i used and this have the same error...! i copy-paste it in notepad++ and saved it as .hoc . should i do something else?

ted
Site Admin
Posts: 5334
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Mistake in fit_praxis documentation

Post by ted » Tue Oct 26, 2010 3:42 pm

Runs fine for me under Linux and WinXP.
kidd wrote:i copy-paste it in notepad++ and saved it as .hoc
Question time.
1. Exactly what are you doing to run the example? Do you double click on the hoc file?
2. Is anything else in that hoc file, aside from the code listed above?
3. This

Code: Select all

bad stack access: expecting (double *); really (Object **)
nrniv: interpreter stack type error
isn't everything that NEURON is printing on your computer. Can you please show all of the messages that NEURON prints, starting with the very first line?

ashutosh

Re: Mistake in fit_praxis documentation

Post by ashutosh » Wed Oct 27, 2010 1:20 am

Hi,

I was having the same problem and thought I should chime in with some details.

I am referring to the documentation found here:http://www.neuron.yale.edu/neuron/stati ... fit_praxis
I executed the following in Mac OSX 10.6.

With NEURON 7.1, I run the following code, which is the hoc example given for fit_praxis:

Code: Select all

objref vec
vec = new Vector(2) // vec.x[0] is x, vec.x[1] is y
func efun() {local x, y
  x = $&2[0]  y = $&2[1]
  return (x+y - 5)^2 + 5*(x-y - 15)^2
}
attr_praxis(1e-5, .5, 0)
e = fit_praxis(vec.size(), "efun", vec)
printf("e=%g x=%g y=%g\n", e, vec.x[0], vec.x[1])

objref paxis
paxis = new Vector()
for i=0, 1 {
  pval = pval_praxis(i, paxis)
  printf("%d  %10g      %10g %10g\n", i, pval, paxis.x[0], paxis.x[1])
}
The output:

Code: Select all

	0 
bad stack access: expecting (double *); really (Object **)
nrniv: interpreter stack type error
 in test.hoc near line 8
 e = fit_praxis(vec.size(), "efun", vec)
                                        ^
        fit_praxis(2, "efun", Vector[0])
I run the same hoc code in NEURON 7.2 alpha downloaded from here: http://www.neuron.yale.edu/ftp/neuron/versions/alpha/
The output:

Code: Select all

	0 
e=0 x=10 y=-5
	14 
0          10        0.707107  -0.707107
1     2.02959       -0.748803  -0.662792
I also tried executing the following python version (saved as test.py):

Code: Select all

from neuron import h
v = h.Vector(2)
def efun(v):
  return (v.x[0]+v.x[1] - 5)**2 + 5*(v.x[0]-v.x[1] - 15)**2
h.attr_praxis(1e-5, .5, 0)
e = h.fit_praxis(efun, v)
print "e=%g x=%g y=%g\n"%(e, v.x[0], v.y[0])
Output with NEURON 7.1: nrniv -python test.py

Code: Select all

bad stack access: expecting (double); really (Object *)
nrniv: interpreter stack type error
 near line 0
 objref hoc_obj_[2]
                   ^
        fit_praxis(..., ...)
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    e = h.fit_praxis(efun, v)
RuntimeError: hoc error
>>>
Output with NEURON 7.2 alpha:

Code: Select all

bad stack access: expecting (double); really (Object *)
/Applications/NEURON-7.2/nrn/umac/bin/nrniv: interpreter stack type error
 near line 0
 objref hoc_obj_[2]
                   ^
        fit_praxis(..., ...)
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    e = h.fit_praxis(efun, v)
RuntimeError: hoc error
>>>
Typo. Should v.y[0] in the python example read v.x[1]?

Many thanks,
Ashutosh

ashutosh

Re: Mistake in fit_praxis documentation

Post by ashutosh » Wed Oct 27, 2010 2:11 am

Update. I modified the python code as follows:

Code: Select all

from neuron import h

v = h.Vector(2)
#def efun(v):
 # return (v.x[0]+v.x[1] - 5)**2 + 5*(v.x[0]-v.x[1] - 15)**2
#DECLARING THE FUNCTION USING HOC
h('func efun() {local x, y \
  x = $&2[0]  y = $&2[1] \
  return (x+y - 5)^2 + 5*(x-y - 15)^2\
}')
h.attr_praxis(1e-5, .5, 0)
#CALLING THE min = fit_praxis(n, "funname", Vector) FORM OF THE FUNCTION
e = h.fit_praxis(2,"efun",v)
print "e=%g x=%g y=%g\n"%(e, v.x[0], v.x[1])
It works with NEURON 7.2:

Code: Select all

e=0 x=10 y=-5

>>>
I get an error in NEURON 7.1:

Code: Select all

bad stack access: expecting (double *); really (Object *)
nrniv: interpreter stack type error
 near line 0
 func efun() {local x, y   x = $&2[0]  y = $&2[1]   return (x+y - 5)^2 + 5*(x-y - 15)^2}
                                                                                        ^
        fit_praxis(2, "efun", ...)
Traceback (most recent call last):
  File "test.py", line 11, in <module>
    e = h.fit_praxis(2,"efun",v)
RuntimeError: hoc error
>>>

kidd
Posts: 11
Joined: Sat Oct 02, 2010 7:18 am

Re: Mistake in fit_praxis documentation

Post by kidd » Wed Oct 27, 2010 2:34 am

hi
1. yes i double click the hoc file and i run it with Neuron 7.1 under winXp.
2.no , just the following code

Code: Select all

objref vec
vec = new Vector(2) // vec.x[0] is x, vec.x[1] is y
func efun() {local x, y
  x = $&2[0]  y = $&2[1]
  return (x+y - 5)^2 + 5*(x-y - 15)^2
}
attr_praxis(1e-5, .5, 0)
e = fit_praxis(vec.size(), "efun", vec)
printf("e=%g x=%g y=%g\n", e, vec.x[0], vec.x[1])

objref paxis
paxis = new Vector()
for i=0, 1 {
  pval = pval_praxis(i, paxis)
  printf("%d  %10g      %10g %10g\n", i, pval, paxis.x[0], paxis.x[1])
}
and the output :

Code: Select all

NEURON -- Release 7.1 (359:7f113b76a94b) 2009-10-26
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2008
See http://www.neuron.yale.edu/credits.html

loading membrane mechanisms from nrnmech.dll
Additional mechanisms from files
 spines.mod synampa.mod vmax.mod
        0 
bad stack access: expecting (double *); really (Object **)
nrniv: interpreter stack type error
 in C:/.../Example/new.hoc near line 8
 e = fit_praxis(vec.size(), "efun", vec)
                                        ^
fit_praxis(2"efun"Vector[0]        , , )

ted
Site Admin
Posts: 5334
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Mistake in fit_praxis documentation

Post by ted » Wed Oct 27, 2010 9:55 am

Switch to NEURON 7.2 and the example code will work without a problem.
Reference:
NEURON's source code repository
changeset 401:cc3ce3310b54
"allow Vector arg for fit_praxis and pval_praxis instead of pointer to double array"
http://www.neuron.yale.edu/hg/neuron/nr ... 3ce3310b54

ashutosh

Re: Mistake in fit_praxis documentation

Post by ashutosh » Wed Oct 27, 2010 5:40 pm

Should I get NEURON 7.2 from a different place other than http://www.neuron.yale.edu/ftp/neuron/versions/alpha/ ? Because I still get the error with the python code in the example as mentioned above...

hines
Site Admin
Posts: 1517
Joined: Wed May 18, 2005 3:32 pm

Re: Mistake in fit_praxis documentation

Post by hines » Fri Oct 29, 2010 9:28 am

Sorry about the confusion. And thanks for noticing the v.y[0] error in the python version.
The option of passing a Vector instead of a double array pointer was introduced last February
http://www.neuron.yale.edu/hg/neuron/nr ... 3ce3310b54
which is why it works for 7.2 but not for 7.1. Unfortunately the change was incomplete from the efun point of view since the user's callback function still required a pointer to a double array.
That has been fixed for use from python a couple weeks ago
http://www.neuron.yale.edu/hg/neuron/nr ... c461bbfca6
but the optional "after_quad_statement" arg still does not allow a python callback and at present only accepts a hoc statement string (which must include the trailing '\n') I guess not much of a problem if you are not using it.

What is causing all my difficulty with this is that the principle values and axes seem often wildly incorrect, though that does not seem to affect the adequacy of the minimum found by fit_praxis. I've been doing experiments with quadratic functions and during the fit process, praxis does indeed compute correct principal values/directions, but then loses it as it homes in on the exact minimum.
My experiments show that the netlib version and an independently translated c version suffer from this and I'm not yet certain what to do about it. The bottom line is that if you need the Hessian at the minimum, you must compute it yourself.

Getting back to using fit_praxis with a Vector arg, which OS version is needed or can you guys use the hg repository or is a tar.gz file sufficient. Let me know by email <michael dot hines at yale dot edu> and I'll create the proper installer and put it in the alpha directory.

Post Reply