algorithm, optimization, or other problem?

Jesus Rivero (Neurogeek) jrivero at corvus.com.ve
Tue Feb 21 14:05:48 EST 2006


Hello,

If the parameters that are received by functions in order to calculate
weights, th's and dot's products , are equal to each other in different
cycles (and i bet more than often they will) i suggest you replace those
functions with memoizable functions. That also would ease work inside
the loop. Take into account other suggestions people have made and
review memoization in Python.


Regards.

Jesus (Neurogeek)







Bas wrote:

>Hi,
>
>as the others have already said, move all the invariants out of the
>loop. It is also not useful to randomly draw a vector out of random
>array. Some other small things:
>
>for i in range(len(x)): do something with x[i]
>should probably be replaced by
>for xi in x: do something with xi
>this saves an array index operation, don't know if this works for a
>numeric array
>
>You use the y**2 twice. A good compiler might notice this, but Python
>is interpreted...
>
>use += instead of + for w, the calculation can be done in place, this
>might save the creation of a new array/variable
>
>I am not sure what you are doing with x, bit it seems that you are
>transposing it a few times to many. Mightbe you can declare x as the
>transpose of what you do now, thereby saving the transpose in the loop?
>
>so my guess (not tested):
>
>x=random((1000,100))    # 1000 input vectors,  declared differently
>for xx in x:
>             y=dot(xx,w)
>             y2 = y*y
>             w+=ETA*(y*xx-y2*w);
>             th+= INV_TAU*(y2-th); 
>
>
>Hope it helps,
>Bas
>
>  
>




More information about the Python-list mailing list