Re: optimization of rule-based model on discrete variables

2021-06-16 Thread Greg Ewing
On 16/06/21 10:51 pm, Elena wrote: sorry I wrote it wrongly, my bad, I will use f just to predict yi from new coming Xi. Then what do you do with the new yi? -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: optimization of rule-based model on discrete variables

2021-06-16 Thread Elena via Python-list
Il Wed, 16 Jun 2021 11:37:42 +1200, Greg Ewing ha scritto: > On 15/06/21 10:07 pm, Elena wrote: >> After the optimization, I will use f just to predict new Xi. > > So you're going to use f backwards? > > I don't see how that will work. Where are you going to find a new yi to > feed into the inve

Re: optimization of rule-based model on discrete variables

2021-06-15 Thread Greg Ewing
On 15/06/21 10:07 pm, Elena wrote: After the optimization, I will use f just to predict new Xi. So you're going to use f backwards? I don't see how that will work. Where are you going to find a new yi to feed into the inverse of f? I think I don't understand what role g plays in all of this.

Re: optimization of rule-based model on discrete variables

2021-06-15 Thread Elena via Python-list
Il Tue, 15 Jun 2021 01:53:09 +, Martin Di Paola ha scritto: > From what I'm understanding it is an "optimization problem" like the > ones that you find in "linear programming". > > But in your case the variables are not Real (they are Integers) and the > function to minimize g() is not linear

Re: optimization of rule-based model on discrete variables

2021-06-15 Thread Elena via Python-list
Il Tue, 15 Jun 2021 10:40:05 +1200, Greg Ewing ha scritto: > On 15/06/21 12:51 am, Elena wrote: > Hmmm, so the problem breaks down into two parts: > (1) find a vector Y that minimises g (2) find a set of rules that will > allow you to predict each component of Y from its corresponding X values >

Re: optimization of rule-based model on discrete variables

2021-06-14 Thread Martin Di Paola
From what I'm understanding it is an "optimization problem" like the ones that you find in "linear programming". But in your case the variables are not Real (they are Integers) and the function to minimize g() is not linear. You could try/explore CVXPY (https://www.cvxpy.org/) which it's a so

Re: optimization of rule-based model on discrete variables

2021-06-14 Thread Greg Ewing
On 15/06/21 12:51 am, Elena wrote: I see what you mean, so I try to explain it better: Y is a vector say [y1, y2, ... yn], with large (n>>10), where yi = f(Xi) with Xi = [x1i, x2i, ... x10i] 1<=i<=n. All yi and xji assume discrete values. I already have a dataset of X={Xi} and would like to find

Re: optimization of rule-based model on discrete variables

2021-06-14 Thread Richard Damon
On 6/13/21 12:15 PM, Elena via Python-list wrote: > Hi, I have, say 10 variables (x1 ... x10) which can assume discrete finite > values, for instance [0,1 or 2]. > I need to build a set of rules, such as: > > 1) if x1==0 and x2==1 and x10==2 then y = 1 > 2) if x2==1 and x3==1 and x4==2 and x6==0 t

Re: optimization of rule-based model on discrete variables

2021-06-14 Thread Elena via Python-list
Il Mon, 14 Jun 2021 19:39:17 +1200, Greg Ewing ha scritto: > On 14/06/21 4:15 am, Elena wrote: >> Given a dataset of X={(x1... x10)} I can calculate Y=f(X) where f is >> this rule-based function. >> >> I know an operator g that can calculate a real value from Y: e = g(Y) >> g is too complex to be

Re: optimization of rule-based model on discrete variables

2021-06-14 Thread Greg Ewing
On 14/06/21 4:15 am, Elena wrote: Given a dataset of X={(x1... x10)} I can calculate Y=f(X) where f is this rule-based function. I know an operator g that can calculate a real value from Y: e = g(Y) g is too complex to be written analytically. I would like to find a set of rules f able to minim

Re: optimization

2008-12-02 Thread Carl Banks
On Dec 1, 11:41 am, Neal Becker <[EMAIL PROTECTED]> wrote: > I guess I've become accustomed to decent compilers performing > reasonable transformations and so have tended to write code for > clarity. Python isn't that language. It'll do what it can, but a very aggressive optimizing compiler would

Re: optimization

2008-12-02 Thread Carl Banks
On Dec 2, 1:56 pm, Neal Becker <[EMAIL PROTECTED]> wrote: > Robert Kern wrote: > > Neal Becker wrote: > >> Arnaud Delobelle wrote: > > >>> Neal Becker <[EMAIL PROTECTED]> writes: > > I noticed in some profiling, that it seems that: > > def Func (): >   def something(): >     ...

Re: optimization

2008-12-02 Thread Robert Kern
Neal Becker wrote: Robert Kern wrote: Neal Becker wrote: Arnaud Delobelle wrote: Neal Becker <[EMAIL PROTECTED]> writes: I noticed in some profiling, that it seems that: def Func (): def something(): ... It appears that if Func is called many times, this nested func definition will

Re: optimization

2008-12-02 Thread Neal Becker
Robert Kern wrote: > Neal Becker wrote: >> Arnaud Delobelle wrote: >> >>> Neal Becker <[EMAIL PROTECTED]> writes: >>> I noticed in some profiling, that it seems that: def Func (): def something(): ... It appears that if Func is called many times, this nest

Re: optimization

2008-12-02 Thread Duncan Booth
Steven D'Aprano <[EMAIL PROTECTED]> wrote: > Which makes me wonder, is there anything we can do with that code object > from Python code? I can disassemble it: > import dis dis.dis(outer.func_code.co_consts[1]) > 3 0 LOAD_CONST 0 (None) > 3 RETUR

Re: optimization

2008-12-02 Thread Steven D'Aprano
On Mon, 01 Dec 2008 19:06:24 -0600, Robert Kern wrote: > As Neal has observed, there is a performance hit for creating functions > inside of another function. True, but it's not a big hit, and I believe it is constant time regardless of the size of the function. The inner function has been (m

Re: optimization

2008-12-02 Thread Steven D'Aprano
On Mon, 01 Dec 2008 18:11:16 -0600, Robert Kern wrote about nested functions: > I, for one, find that significantly less clear. I only expect functions > to be defined inside of functions if they are going to use lexical > scoping for some reason. If I read your code, I'd probably waste a good >

Re: optimization

2008-12-01 Thread Robert Kern
[EMAIL PROTECTED] wrote: Robert Kern: I only expect functions to be defined inside of functions if they are going to use lexical scoping for some reason.< There are other reasons to nest functions. One of them is to represent logical nesting of some functionality. Is that any different than

Re: optimization

2008-12-01 Thread bearophileHUGS
Robert Kern: >I only expect functions to be defined inside of functions if they are going to >use lexical scoping for some reason.< There are other reasons to nest functions. One of them is to represent logical nesting of some functionality. So you will find some exceptions to your self-created r

Re: optimization

2008-12-01 Thread Robert Kern
Neal Becker wrote: Arnaud Delobelle wrote: Neal Becker <[EMAIL PROTECTED]> writes: I noticed in some profiling, that it seems that: def Func (): def something(): ... It appears that if Func is called many times, this nested func definition will cause significant overhead. Is this tru

Re: optimization

2008-12-01 Thread Neal Becker
Arnaud Delobelle wrote: > Neal Becker <[EMAIL PROTECTED]> writes: > >> I noticed in some profiling, that it seems that: >> >> def Func (): >> def something(): >> ... >> >> It appears that if Func is called many times, this nested func >> definition will cause significant overhead. Is this

Re: optimization

2008-12-01 Thread Arnaud Delobelle
Neal Becker <[EMAIL PROTECTED]> writes: > I noticed in some profiling, that it seems that: > > def Func (): > def something(): > ... > > It appears that if Func is called many times, this nested func > definition will cause significant overhead. Is this true? I guess > I've become accustom

Re: optimization

2008-12-01 Thread Terry Reedy
[EMAIL PROTECTED] wrote: Neal> I noticed in some profiling, that it seems that: Neal> def Func (): Neal> def something(): Neal> ... Neal> It appears that if Func is called many times, this nested func Neal> definition will cause significant overhead. Is this true?

Re: optimization

2008-12-01 Thread skip
Neal> I noticed in some profiling, that it seems that: Neal> def Func (): Neal> def something(): Neal> ... Neal> It appears that if Func is called many times, this nested func Neal> definition will cause significant overhead. Is this true? I Neal> guess I've b

Re: Optimization: Picking random keys from a dictionary and mutating values

2008-05-29 Thread Carl Banks
On May 28, 7:41 pm, blaine <[EMAIL PROTECTED]> wrote: > Hey everyone, > Just a friendly question about an efficient way to do this. Friendly advance reminder: in many optimization problems, the objective function is far more expensive to calculate than the optimizing procedure. Your time is usu

Re: Optimization: Picking random keys from a dictionary and mutating values

2008-05-28 Thread Raymond Hettinger
On May 28, 4:41 pm, blaine <[EMAIL PROTECTED]> wrote: > 1.  Whats a good way to get the keys? I'm using a loop with > random.choice() at the moment. Why not keep a separate list of keys and use random.sample()? Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Optimization problem

2007-03-18 Thread mkPyVS
I would suggest taking a look at the python package networkx. It is a wonderfully created path optimization and presentation package which has a fair amount of extensabilty. Basic lowest cost path solutions should be able to solve your algorithmic needs here in polynomial time (Typically N**P time

Re: Optimization of __len__() in cgi.py

2006-08-16 Thread Bob Kline
Georg Brandl wrote: > Post a RFE to the Python Tracker at > http://sourceforge.net/tracker/?group_id=5470&atid=355470 > > If you want, assign it to me (gbrandl). Done, thanks. Bob -- http://mail.python.org/mailman/listinfo/python-list

Re: Optimization of __len__() in cgi.py

2006-08-16 Thread Bob Kline
Sybren Stuvel wrote: > FieldStorage.__nonzero__ tried first if it exists. You might want to > use that for more optimization. Excellent suggestion! It would be nice if this were adopted to supplement the original optimization, rather than replace it. Bob -- http://mail.python.org/mailman/listin

Re: Optimization of __len__() in cgi.py

2006-08-16 Thread Bob Kline
Marc 'BlackJack' Rintsch wrote: >> def keys(self): >> return {}.fromkeys([i.name for i in self.list]).keys() > > This does not maintain the order of `self.list`. Don't know if there's > code relying on this. Such code would be flying in the face of an implication that the order of th

Re: Optimization of __len__() in cgi.py

2006-08-16 Thread Georg Brandl
Bob Kline wrote: > I have a suggestion for speeding up the performance of code like this: > > fields = cgi.FieldStorage() > if fields: ... > > which, as it turns out, invokes FieldStorage.__len__(), which in turn > calls FieldStorage.keys(), which builds a list of keys by hand, taking > several m

Re: Optimization of __len__() in cgi.py

2006-08-16 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Bob Kline wrote: > I have a suggestion for speeding up the performance of code like this: > > fields = cgi.FieldStorage() > if fields: ... > > which, as it turns out, invokes FieldStorage.__len__(), which in turn > calls FieldStorage.keys(), which builds a list of keys by