I use lisp largley to write code for evloving Neural Networks which can be a very time consuming task. I'm currently running Alegro LISP in a Win 95 environment, and my programs take days (sometimes weeks) to run. Is there any way to speed things up a bit?
Oh, and does anyone know whether Alegro LISP would work under Linux or would I need a different version?
* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful
Tony <tonyNOtoS...@chice.force9.co.uk.invalid> writes: > I use lisp largley to write code for evloving Neural > Networks which can be a very time consuming task. I'm > currently running Alegro LISP in a Win 95 environment, and > my programs take days (sometimes weeks) to run. Is there any > way to speed things up a bit?
Maybe by using better data structures and algorithms? :}
Cheers
-- Marco Antoniotti =========================================== PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26 http://www.parades.rm.cnr.it/~marcoxa
> Tony <tonyNOtoS...@chice.force9.co.uk.invalid> writes:
> > I use lisp largley to write code for evloving Neural > > Networks which can be a very time consuming task. I'm > > currently running Alegro LISP in a Win 95 environment, and > > my programs take days (sometimes weeks) to run. Is there any > > way to speed things up a bit?
> Maybe by using better data structures and algorithms? :}
:-)
One problem with neural networks is that they're inherenly both massively parallel and quite analog. Doing them efficiently on a mostly-sequential, definitely-digital computer can be a pain, even where possible.
Then again, analog VLSI, while efficient for these computations, has quite a long develop-compile-test cycle :-)
-- Arvid
colonel Uzi Semtex security ammunition arrangements Waco, Texas CIA
Arvid Grøtting <arv...@pc-arvidg.infotek.no> writes: > * Marco Antoniotti > > Tony <tonyNOtoS...@chice.force9.co.uk.invalid> writes:
> > > I use lisp largley to write code for evloving Neural > > > Networks which can be a very time consuming task. I'm > > > currently running Alegro LISP in a Win 95 environment, and > > > my programs take days (sometimes weeks) to run. Is there any > > > way to speed things up a bit?
> > Maybe by using better data structures and algorithms? :}
> :-)
> One problem with neural networks is that they're inherenly both > massively parallel and quite analog. Doing them efficiently on a > mostly-sequential, definitely-digital computer can be a pain, even > where possible.
> Then again, analog VLSI, while efficient for these computations, has > quite a long develop-compile-test cycle :-)
Of course. But then again, what are the main data strutcures you are using?
Cheers
-- Marco Antoniotti =========================================== PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26 http://www.parades.rm.cnr.it/~marcoxa
The networks are stored as lists containing structures defining the connections, my algorithms are probably not perfect (with regards to optomising speed) the real problem lies with LISP itself, If I define a simple algorithm in say C for example, and run them back to back, the C program will on average take about half the time the LISP one needs to run. I'm currently just running from the editor into toploop, but was hoping that the file could be compiled into an .exe or something to speed it up. With regards to my data structures, a reccurent network of 10 nodes, with an average connectivity of say 5, evolving with a population of about 30 using a SAGA style GA for about 100,000 generations, meas that the node summing section allone has been executed 150,000,000 times Thus it takes ages.
* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful
Tony wrote: > The networks are stored as lists containing structures > defining the connections,
Consider using arrays and declarations (there are lots of examples if you watch this newsgroup).
> I'm currently just running from the editor into > toploop, but was hoping that the file could be compiled into > an .exe or something to speed it up.
In article <18dae34d.4d4aa...@usw-ex0110-076.remarq.com>, Tony <tonyNOtoS...@chice.force9.co.uk.invalid> wrote:
> I use lisp largley to write code for evloving Neural > Networks which can be a very time consuming task. I'm > currently running Alegro LISP in a Win 95 environment, and > my programs take days (sometimes weeks) to run. Is there any > way to speed things up a bit?
If you have ACL 4.3 or greater then you should try profiling to determine where your bottlenecks are. See:
Some of the data is contained in simple-vectors, other bits in arrays, within the structures, but the use of arrays is wastefull in this situation as the ultimate size is unknown.
* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful
> If I define a simple algorithm in say > C for example, and run them back to back, the C program will > on average take about half the time the LISP one needs to > run.
Well, that's about right, or it was the last time I ran similar tests. You can (or could, at that time) get a 100% speedup by going to ACL/Linux, at which point you'll be slightly faster than a g++ implementation of a lispy algorithm, but maybe not as fast as a gcc implementation of same. Shouldn't be a lot of difference, though.
> I'm currently just running from the editor into > toploop, but was hoping that the file could be compiled into > an .exe or something to speed it up.
Well, if you're not compiling before you run, you could see a dramatic speedup by compiling. However, I wouldn't expect you to benchmark as well against a C implementation if you weren't compiling somehow. What version of Allegro are you using? ACL 3.x compiles automatically, but it doesn't optimize as well as more recent versions. If that's what you're using you should switch to something newer, and then make sure you compile.
* Tony <TonyNOToS...@chice.force9.co.uk.invalid> | Some of the data is contained in simple-vectors, other bits | in arrays, within the structures, but the use of arrays is | wastefull in this situation as the ultimate size is unknown.
well, you _could_ use adjustable vectors with fill pointers if such is your concern. Common Lisp knows that the tradeoff that people made with lists carried a performance penalty. look at VECTOR-PUSH and VECTOR-POP for ways to deal with unknown sizes and still get O(1) access times.
Tony wrote: > I use lisp largley to write code for evloving Neural > Networks which can be a very time consuming task. I'm > currently running Alegro LISP in a Win 95 environment, and > my programs take days (sometimes weeks) to run. Is there any > way to speed things up a bit?
> Oh, and does anyone know whether Alegro LISP would work > under Linux or would I need a different version?
> * Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful
Tony <TonyNOToS...@chice.force9.co.uk.invalid> writes: > The networks are stored as lists containing structures > defining the connections,
How many connections? Do you always run through all the connections (DOLIST) or do you occasionally need to access the i-th connection to do something with it?
> my algorithms are probably not > perfect (with regards to optomising speed) the real problem > lies with LISP itself, If I define a simple algorithm in say > C for example, and run them back to back, the C program will > on average take about half the time the LISP one needs to > run.
Do you use 'lists' in C as well? Or do you 'malloc' an array to represent your connections?
> I'm currently just running from the editor into > toploop, but was hoping that the file could be compiled into > an .exe or something to speed it up. > With regards to my data structures, a reccurent network of > 10 nodes, with an average connectivity of say 5, evolving > with a population of about 30 using a SAGA style GA for > about 100,000 generations, meas that the node summing > section allone has been executed 150,000,000 times Thus it > takes ages.
Apologies, but this does not mean much to me. Not being a NN expert I can only surmise the graph structure of the net, but not much beyond it. If you posted some code, the newsgroup could be more helpful.
Cheers
-- Marco Antoniotti =========================================== PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26 http://www.parades.rm.cnr.it/~marcoxa
> Tony <TonyNOToS...@chice.force9.co.uk.invalid> writes:
> > The networks are stored as lists containing structures > > defining the connections,
> How many connections? Do you always run through all the connections > (DOLIST) or do you occasionally need to access the i-th connection to > do something with it?
> > my algorithms are probably not > > perfect (with regards to optomising speed) the real problem > > lies with LISP itself, If I define a simple algorithm in say > > C for example, and run them back to back, the C program will > > on average take about half the time the LISP one needs to > > run.
> Do you use 'lists' in C as well? Or do you 'malloc' an array to > represent your connections?
You can do lists fine in STL if you go to C++, and they support inserts, deletion and searches fairly well.
In article <3885D4F7.3D3C6...@raytheon.com>, Robert Posey <mu...@raytheon.com> wrote:
>Marco Antoniotti wrote: >> Do you use 'lists' in C as well? Or do you 'malloc' an array to >> represent your connections?
>You can do lists fine in STL if you go to C++, and they support >inserts, deletion and searches fairly well.
If memory serves, STL's lists are doubly-linked. They're also a pain in the *ss to use with heterogeneous data.
-- Chuck -- Chuck Fry -- Jack of all trades, master of none chu...@chucko.com (text only please) chuck...@home.com (MIME enabled) Lisp bigot, car nut, photographer, sometime guitarist and mountain biker The addresses above are real. All spammers will be reported to their ISPs.
I've just put up some LISP code for a Dynamic Reccurent Neural Net, so you can see how my data structures work. My code is probably horrible to look at, but I've semi documented it so it shouldn't be to bad. Anyway Let me know if you think it can be speeded up at all? Also if you think it can be improved. Anyway it's all on my home page at... www.chice.force9.co.uk
* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful
Robert Posey <mu...@raytheon.com> writes: > Marco Antoniotti wrote:
> > Tony <TonyNOToS...@chice.force9.co.uk.invalid> writes:
> > > The networks are stored as lists containing structures > > > defining the connections,
> > How many connections? Do you always run through all the connections > > (DOLIST) or do you occasionally need to access the i-th connection to > > do something with it?
> > > my algorithms are probably not > > > perfect (with regards to optomising speed) the real problem > > > lies with LISP itself, If I define a simple algorithm in say > > > C for example, and run them back to back, the C program will > > > on average take about half the time the LISP one needs to > > > run.
> > Do you use 'lists' in C as well? Or do you 'malloc' an array to > > represent your connections?
> You can do lists fine in STL if you go to C++, and they support > inserts, deletion and searches fairly well.
Why go C++/STL when you can have the real thing? :)
Apart from that, one of the most common pifalls of Lisp vs C comparisons is that the data structures used in C are different from those used in Lisp. If I use a 'malloc-ed' array in C, I am bound to get better performance than a list in Lisp, especially if you access the i-th element out of an ordered traversal.
I bet that using lists with C++/STL would result in larger code and slower as well w.r.t. an equivalent C/C++ array based implementation (not to speak of any comparison with Lisp).
Cheers
-- Marco Antoniotti =========================================== PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26 http://www.parades.rm.cnr.it/~marcoxa
* Tony wrote: > I've just put up some LISP code for a Dynamic Reccurent > Neural Net, so you can see how my data structures work.
Here's a rewrite of the start of it. It uses arrays pervasively, and doesn't have global variables but rather passes the activity array in to various functions. I gave up slightly before the end as I ran out of time.
CMUCL should run this kind of code really well (albeit I haven't even tried compiling it other than the Y function so it might be buggy and / or need better declarations.
;; Code for a list based Reccurent Neural Network ;; We will need a global list of length = no_of_nodes, which gives the current activation levels of ;; every node in the network. This list will be updated and accessed by future functions.
;; Starting with the functions to create a single neurone/node ;; I need a to create a structure to hold the weights and any other information about the node.
;(defstruct node ; weights_list ;a list of weights, including the bias weight ; input_list) ;a list of input locations pointing to positions in *structure* including the bias node
;; I now need to crate a set of functions to calculate the output of the neurone. ;; function a takes the weights and the input and sums w1*i1+..+wn*in ;; returning the value of a for the given node.
;; Now we need a sygmoid function to work out y given a as input
;(defun y (a) ; (/ 1 (+ (exp (- a)) 1)))
(declaim (inline y))
(defun y (a) ;; I can't get allegro to compile this well (but I haven't tried ;; very hard). CMUCL does really well. (declare (type single-float a)) (/ 1.0s0 (+ (exp (- a)) 1.0s0)))
;; Right, now that we have functions to work out the output of a given node, we now need to update ;; the *structure* with this new output value, and go through for each node
(defun full-pass (node-list activity) (declare (type (simple-array fixnum (*)) activity)) (loop for i of-type fixnum upfrom 0 for n of-type node in node-list do (setf (aref activity i) (run-node n activity))))
[snip] Tim> (defun y (a) Tim> ;; I can't get allegro to compile this well (but I haven't tried Tim> ;; very hard). CMUCL does really well. Tim> (declare (type single-float a)) Tim> (/ 1.0s0 (+ (exp (- a)) 1.0s0)))
A common typo: 1.0s0 is a short-float, not a single-float. This doesn't matter to CMUCL since short-float and single-float are the same, but it might matter to others.
Marco Antoniotti <marc...@parades.rm.cnr.it> writes: > Why go C++/STL when you can have the real thing? :)
> Apart from that, one of the most common pifalls of Lisp vs C > comparisons is that the data structures used in C are different from > those used in Lisp. If I use a 'malloc-ed' array in C, I am bound to > get better performance than a list in Lisp, especially if you access > the i-th element out of an ordered traversal.
> I bet that using lists with C++/STL would result in larger code and > slower as well w.r.t. an equivalent C/C++ array based implementation > (not to speak of any comparison with Lisp).
Not sure I buy that one. In C++/STL you can build a linked list structure where the data is part of the cell: ----------------------------------------- ------- | data | more data | and so forth | next* | -> | data ... ----------------------------------------- -------
In LISP, my understanding is that lists are held together with cons cells:
--------------- --------------- | data* | next* | -> | data* | next* | --------------- --------------- | --------------------------------- | data | more data | and so forth | ---------------------------------
So once you get your hands on the list cell in C++ you have the data. In LISP you have one more pointer deference to do.
Can you tell me your rationale for the LISP speedup?
Matt -- Matthew.R.Wette at jpl.nasa.gov -- I speak for myself, not for JPL.
* Raymond Toy wrote: > A common typo: 1.0s0 is a short-float, not a single-float. This > doesn't matter to CMUCL since short-float and single-float are the > same, but it might matter to others.
Are there any common platforms where short and single floats are different? (I'm not trying to deny it was a mistake, I can never remember what the syntax for a short-float is though...)
>>>>> "Tim" == Tim Bradshaw <t...@cley.com> writes:
Tim> * Raymond Toy wrote: >> A common typo: 1.0s0 is a short-float, not a single-float. This >> doesn't matter to CMUCL since short-float and single-float are the >> same, but it might matter to others.
Tim> Are there any common platforms where short and single floats are Tim> different? (I'm not trying to deny it was a mistake, I can never Tim> remember what the syntax for a short-float is though...)
Tim Bradshaw <t...@cley.com> writes: > * Raymond Toy wrote:
> > A common typo: 1.0s0 is a short-float, not a single-float. This > > doesn't matter to CMUCL since short-float and single-float are the > > same, but it might matter to others.
> Are there any common platforms where short and single floats are > different? (I'm not trying to deny it was a mistake, I can never > remember what the syntax for a short-float is though...)
[I posted this from work already, but it looks like it didn't make it out.]
In Macintosh Common Lisp, as of version 4.1, a short-float is an IEEE single precision quantity (32 bits). The rest of the float types (single-float, double-float, long-float) are IEEE double precision.
Matt Wette <Matthew.R.We...@jpl.nasa.gov> writes: > Marco Antoniotti <marc...@parades.rm.cnr.it> writes:
> > Why go C++/STL when you can have the real thing? :)
> > Apart from that, one of the most common pifalls of Lisp vs C > > comparisons is that the data structures used in C are different from > > those used in Lisp. If I use a 'malloc-ed' array in C, I am bound to > > get better performance than a list in Lisp, especially if you access > > the i-th element out of an ordered traversal.
> > I bet that using lists with C++/STL would result in larger code and > > slower as well w.r.t. an equivalent C/C++ array based implementation > > (not to speak of any comparison with Lisp).
> Not sure I buy that one. In C++/STL you can build a linked list > structure where the data is part of the cell: > ----------------------------------------- ------- > | data | more data | and so forth | next* | -> | data ... > ----------------------------------------- -------
Hum. This is only the case when the data type is primitive or has a copy constructor, and that means that you'll end up copying the data value(s) into the list, and possibly also when doing a read access. In some cases you may want to use a list of pointers instead, in which case you end up with a similar list structure to what LISP uses...
So, the speedup for LISP is actually quite plausible.
On 19 Jan 2000 22:52:20 +0000, Tim Bradshaw <t...@cley.com> wrote:
>* Raymond Toy wrote:
>> A common typo: 1.0s0 is a short-float, not a single-float. This >> doesn't matter to CMUCL since short-float and single-float are the >> same, but it might matter to others.
>Are there any common platforms where short and single floats are >different? (I'm not trying to deny it was a mistake, I can never >remember what the syntax for a short-float is though...)
In Corman Lisp (1.3 and later), a short float fits into a tagged word, like a fixnum, and is 30 bits. A single float is an IEEE 32-bit float. A double-float is IEEE 64-bits. Of course the short float is efficient to pass and store (no boxing) but the math operators all convert it to/from 32-bits for operations. It basically just rounds off the last two bits of the mantissa to get from 32-bits to 30.
<Matthew.R.We...@jpl.nasa.gov> wrote: >So once you get your hands on the list cell in C++ you have the data. >In LISP you have one more pointer deference to do.
>Can you tell me your rationale for the LISP speedup?
Well, if the data is a fixnum or something else small it will be stored in the cell, not a pointer (for many versions of lisp). Also, you can certainly link structs together in Lisp, which does just what you are doing in C++ (stores data and pointer in the same heap object).
Hoever, I don't think the issue of a pointer dereference is worth thinking about. In my experience Lisp is much faster than C++ for list management for several reasons.
Memory management: lisp systems are optimized to allocate small pieces for lists, unlike "new" or "malloc" which are usually far slower than CONS. Also, CONS will often be inlined, even further speeding things up. (I have never seen new or malloc inlined in C or C++). A good garbage collector should be able to free large numbers of list elements much faster than calling free() on each one explicitly.
Because lisp is designed and optimized for list processing, operations which traverse and alter list structures tend to be highly optimized and inlined. Many standard lisp benchmarks stress these operations, and compiler vendors have responded by using every possible trick to make lists as fast as possible.
Of course in C++ you could write your own memory management functions, and write your own macros for handling lists, and approach the efficiency of lisp if you spend enough time on it. I think of this as basically the "I can build Lisp in C++, therefore C++ can do anything Lisp can do" argument.