Re: [Tutor] constructing semi-arbitrary functions

2014-02-20 Thread spir
On 02/20/2014 01:56 AM, "André Walker-Loud " wrote: On Feb 19, 2014, at 7:45 PM, André Walker-Loud wrote: OK - I have not seen an email from Peter. So I looked up the thread online, and see I did not receive half the emails on this thread :O My first inclination was to blame my mac mavericks

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread Oscar Benjamin
On 20 February 2014 00:56, "André Walker-Loud " wrote: > On Feb 19, 2014, at 7:45 PM, André Walker-Loud wrote: > >> OK - I have not seen an email from Peter. >> So I looked up the thread online, and see I did not receive half the emails >> on this thread :O >> >> My first inclination was to blam

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread Mark Lawrence
On 20/02/2014 00:56, "André Walker-Loud " wrote: On Feb 19, 2014, at 7:45 PM, André Walker-Loud wrote: OK - I have not seen an email from Peter. So I looked up the thread online, and see I did not receive half the emails on this thread :O My first inclination was to blame my mac mavericks ma

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread André Walker-Loud
On Feb 19, 2014, at 7:45 PM, André Walker-Loud wrote: > OK - I have not seen an email from Peter. > So I looked up the thread online, and see I did not receive half the emails > on this thread :O > > My first inclination was to blame my mac mavericks mail gmail syncing > problem. but logging

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread André Walker-Loud
OK - I have not seen an email from Peter. So I looked up the thread online, and see I did not receive half the emails on this thread :O My first inclination was to blame my mac mavericks mail gmail syncing problem. but logging into gmail, I see no record of the emails there either. I currently

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread eryksun
On Wed, Feb 19, 2014 at 6:59 PM, "André Walker-Loud " wrote: > > Also, since you are chiming in, do you have an opinion in general about > which approach you prefer? The string hacking vs class method (for lack > of better way to describe them)? I've never used iminuit before. I'd ask on a suppo

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread André Walker-Loud
Hi eryksun, Thanks - this is great. Also, since you are chiming in, do you have an opinion in general about which approach you prefer? The string hacking vs class method (for lack of better way to describe them)? Cheers, Andre On Feb 19, 2014, at 4:56 PM, eryksun wrote: > On Wed, Feb 19

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread eryksun
On Wed, Feb 19, 2014 at 2:56 PM, "André Walker-Loud " wrote: > > I also happened to get the string-hack to work (which requires > using global variables). Functions load unassigned names from the global/builtins scopes, so there's no need to declare the g* variables global in chisq_mn. Also, impl

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread André Walker-Loud
Hi eryksun, Indeed, I am using iminuit to interface with Minuit. That is where I am learning to make my own classes to set up my functions to pass into the minimizer. I also happened to get the string-hack to work (which requires using global variables). Instead of just copying (since it works)

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread André Walker-Loud
Hi Oscar, >> Is there a benefit to this method vs a standard linear least squares? > > It's the same except that you're using an analytic solution rather > than a black box solver. OK. Interesting. I usually construct the analytic solution by just differentiating the chi^2, which sets up, I a

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread eryksun
On Wed, Feb 19, 2014 at 7:33 AM, Oscar Benjamin wrote: > I don't really understand why it works that way though. > Looking here > >http://iminuit.github.io/iminuit/api.html#function-sig-label This API is unusual, but co_argcount and co_varnames should be available and defined as per the spec:

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread Dave Angel
On 02/19/2014 07:33 AM, Oscar Benjamin wrote: At the least I don't understand why it needs both the argument names and the number of arguments as independent quantities. Surely len(names) would be the number of arguments... Or am I missing something? In the standard library, the attributes a

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread Oscar Benjamin
On 18 February 2014 17:59, Peter Otten <__pete...@web.de> wrote: > > I don't know if the OP may use it, but there seems to be a version of minuit > that allows to override the function signature: > > """ > forced_parameters: tell Minuit not to do function signature detection and > use this argument

Re: [Tutor] constructing semi-arbitrary functions

2014-02-18 Thread Peter Otten
Oscar Benjamin wrote: > On 17 February 2014 20:13, Peter Otten <__pete...@web.de> wrote: >> André Walker-Loud wrote: >>> >>> The 3rd party minimizer utilizes the .func_code.co_varnames and >>> .func_code.co_argcount to determine the name and number of variables to >>> minimize. eg. >>> >>> =

Re: [Tutor] constructing semi-arbitrary functions

2014-02-18 Thread Oscar Benjamin
On 18 February 2014 00:51, "André Walker-Loud " wrote: >> >> BTW if you're trying to fit the coefficients of a polynomial then a >> general purpose optimisation function is probably not what you want to >> use. I would probably solve (in a least squares sense and after >> suitable scaling) the Van

Re: [Tutor] constructing semi-arbitrary functions

2014-02-18 Thread spir
On 02/17/2014 08:23 PM, "André Walker-Loud " wrote: Hello python tutors, I am utilizing a 3rd party numerical minimization routine. This routine requires an input function, which takes as arguments, only the variables with which to solve for. But I don’t want to define all possible input fun

Re: [Tutor] constructing semi-arbitrary functions

2014-02-18 Thread spir
On 02/18/2014 12:02 AM, Oscar Benjamin wrote: On 17 February 2014 22:15, "André Walker-Loud " wrote: This particular case is easily solved: def f_lambda(x,pars): return lambda x: poly(x,*pars) You let the closure take care of pars and return a function that takes exactly one argument x.

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud
Hi Oscar, On Feb 17, 2014, at 7:03 PM, Oscar Benjamin wrote: > On 17 February 2014 22:15, "André Walker-Loud " > wrote: >>> This particular case is easily solved: >>> >>> def f_lambda(x,pars): >>>return lambda x: poly(x,*pars) >>> >>> You let the closure take care of pars and return a fu

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud
Hi Oscar, On Feb 17, 2014, at 6:02 PM, Oscar Benjamin wrote: > On 17 February 2014 22:15, "André Walker-Loud " > wrote: >>> This particular case is easily solved: >>> >>> def f_lambda(x,pars): >>>return lambda x: poly(x,*pars) >>> >>> You let the closure take care of pars and return a fun

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 22:15, "André Walker-Loud " wrote: >> This particular case is easily solved: >> >> def f_lambda(x,pars): >> return lambda x: poly(x,*pars) >> >> You let the closure take care of pars and return a function that takes >> exactly one argument x. > > Hi Oscar, > > This is the o

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 22:15, "André Walker-Loud " wrote: >> This particular case is easily solved: >> >> def f_lambda(x,pars): >> return lambda x: poly(x,*pars) >> >> You let the closure take care of pars and return a function that takes >> exactly one argument x. > > Hi Oscar, > > This is the o

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud
> This particular case is easily solved: > > def f_lambda(x,pars): > return lambda x: poly(x,*pars) > > You let the closure take care of pars and return a function that takes > exactly one argument x. Hi Oscar, This is the opposite of what I am trying to do. In the example, x represents t

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 21:18, "André Walker-Loud " wrote: > > What I am trying to avoid is having to write a special case for each order of > polynomial I want. I tried the following > > def poly(x,pars): > val = 0. > for i,ci in enumerate(pars): > val += x**i * ci > return val

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Dave Angel
Peter Otten <__pete...@web.de> Wrote in message: > André Walker-Loud wrote: > >> Hello python tutors, >> >> I am utilizing a 3rd party numerical minimization routine. This routine >> requires an input function, which takes as arguments, only the variables >> with which to solve for. But I do

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Steven D'Aprano
On Mon, Feb 17, 2014 at 07:58:00PM +, Oscar Benjamin wrote: > The "right" solution is to change the interface of the third party > function. It is poorly designed and should not be inspecting those function > attributes or it should at least provide an option for you to provide that > informat

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud
Hi Oscar, Let me clear up my description of one point - I don’t want to pick on the third party software guys. > The "right" solution is to change the interface of the third party function. > It is poorly designed and should not be inspecting those function attributes > or it should at least p

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 20:13, Peter Otten <__pete...@web.de> wrote: > André Walker-Loud wrote: >> >> The 3rd party minimizer utilizes the .func_code.co_varnames and >> .func_code.co_argcount to determine the name and number of variables to >> minimize. eg. >> >> = >> METHOD 2: use strings, e

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Peter Otten
André Walker-Loud wrote: > Hello python tutors, > > I am utilizing a 3rd party numerical minimization routine. This routine > requires an input function, which takes as arguments, only the variables > with which to solve for. But I don’t want to define all possible input > functions, in a gian

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On Feb 17, 2014 7:24 PM, ""André Walker-Loud "" wrote: > > Question 1: > Is there a better way to accomplish (my hopefully clear) goals? I'm not sure that there is given the constraints you're under from the third party function. > Question 2: > In method 1, is there a way t

[Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud
Hello python tutors, I am utilizing a 3rd party numerical minimization routine. This routine requires an input function, which takes as arguments, only the variables with which to solve for. But I don’t want to define all possible input functions, in a giant switch, but rather, if I know I am