Re: [racket-users] help on coding finite state automata

2015-10-14 Thread Matthias Felleisen
On Oct 13, 2015, at 11:52 PM, Nguyen Linh Chi wrote: > Isnt this the reason we should add 0 at the beginning of the list? > > On 13/ott/2015, at 22:38, Matthias Felleisen wrote: > >> >> Welcome to Racket v6.3.0.1. >>> (define r .8) >>>

Re: [racket-users] help on coding finite state automata

2015-10-14 Thread chi
Thanks for answering me many times. I really appreciate. For the question, if we dont accumulate and randomise that way, how can we spawn new automata regarding their fitness? For example, population: a b c d payoff: 5 0 8 3 (sum = 16) relative payoff: 5/16 0/16 8/16 3/16 -> The replacement

Re: [racket-users] help on coding finite state automata

2015-10-14 Thread Matthias Felleisen
This is perfectly clear and obvious in hindsight. Thanks -- Matthias On Oct 14, 2015, at 11:23 AM, chi wrote: > Thanks for answering me many times. I really appreciate. > For the question, if we dont accumulate and randomise that way, how can we > spawn new

Re: [racket-users] help on coding finite state automata

2015-10-13 Thread Linh Chi Nguyen
Matthias you work like a machine, too fast. Anyway, I have no idea what is type or not type. But I have some general remarks: 1. A general automaton can have many states, say, 10 states. so the action in each state can be either cooperate or defect (this is a deterministic automaton, for a

Re: [racket-users] help on coding finite state automata

2015-10-13 Thread Matthias Felleisen
See repo. I special-purposed shuffle for my data rep. On Oct 13, 2015, at 12:39 PM, Alex Knauth wrote: > I've started on that, but shuffle doesn't exist properly yet for generic > collections. I could just use (shuffle (sequence->list )), but, what > would be the

Re: [racket-users] help on coding finite state automata

2015-10-13 Thread Matthias Felleisen
1. Your code is a good example for something that we could use as a benchmark, and working on it has helped me find a couple of problems in drracket and typed racket. Thanks for triggering my activity. I'll stop soon. 2. I figured out that your code was general so you could accommodate more

Re: [racket-users] help on coding finite state automata

2015-10-13 Thread Benjamin Greenman
> > - why you use [i (in-range 10)] in all for loop? what's the difference > with [i 10]. they both produce stream, right? Yes, but `in-range` runs faster because of "types". Here's a little example: #lang racket/base (define N (expt 10 7)) (time (for ([n (in-range N)]) (void))) ;; cpu time:

Re: [racket-users] help on coding finite state automata

2015-10-13 Thread Nguyen Linh Chi
the list 0 isnt a bug. I add it because #:break will break the fitness vector at r < f. For example, Population : a b c d Cumulative fitness .2 .5 .7 1 If the random r = .8, it means that the lottery points to the interval of automaton d. But #:break will breaks at .7, and the associated

Re: [racket-users] help on coding finite state automata

2015-10-13 Thread Matthias Felleisen
Welcome to Racket v6.3.0.1. > (define r .8) > (for/last ([p '(a b c d)][f '(.2 .5 .7 1)] #:break (< r f)) p) 'c Or WORSE: > (define r (random)) > r 0.011105628290672482 > (for/last ([p '(a b c d)][f '(.2 .5 .7 1)] #:break (< r f)) p) #f On Oct 13, 2015, at 3:37 PM, Nguyen Linh Chi

Re: [racket-users] help on coding finite state automata

2015-10-13 Thread Alex Knauth
I've started on that, but shuffle doesn't exist properly yet for generic collections. I could just use (shuffle (sequence->list )), but, what would be the best way of representing this? Generic collections give you the freedom of creating a new type of data structure just for shuffled

Re: [racket-users] help on coding finite state automata

2015-10-13 Thread Nguyen Linh Chi
Hi Mathias, thank you so much for helping me a lot. You can use the code as you want, i still have tons of them on my github. (Just dont use it against me ok :D ) I'd try to see through your list of suggestions. About the automata payoff. There are 2 different things that are always mixed up:

Re: [racket-users] help on coding finite state automata

2015-10-13 Thread Matthias Felleisen
p.s. One more question. Why do you 'reset' the payoff for automata after each round? Shouldn't they carry along their overall, historical payoff? On Oct 13, 2015, at 1:40 PM, Matthias Felleisen wrote: > > 1. Your code is a good example for something that we could

Re: [racket-users] help on coding finite state automata

2015-10-13 Thread Gustavo Massaccesi
:( . I tried few modifications, but I didn't get any improvement. I think that the recalculation of the population is used very seldom, so any change there will not affect the speed too much. Most of the time is used in the matches, but I don't have any suggestion for it (that doesn't include

Re: [racket-users] help on coding finite state automata

2015-10-12 Thread Linh Chi Nguyen
I dont know how the email group work. If someone keeps receiving emails out of interest, please notice me. Thanks Bryan for the suggestion, it's nice to know, however Im not able to afford upgrading now. And Matthias, for your notice of the spawning process ``` (define (randomise-over-fitness

Re: [racket-users] help on coding finite state automata

2015-10-12 Thread Matthias Felleisen
for/last: good point. Based on my previous experience with replacing imperative automata with functional ones, I don't think replacing the list-based population container with a vector per se will speed up things much. But the pairing up of neighbors might be a tad faster. Then again I

Re: [racket-users] help on coding finite state automata

2015-10-12 Thread Matthias Felleisen
I pushed some more changes. -- All automata code is now in the automata modules. -- It is now easy to explore different implementations of automata. 1. Eliminating your last side-effects came for free or possibly a small gain in performance. 2. Replacing your list-based automata with

Re: [racket-users] help on coding finite state automata

2015-10-12 Thread Gustavo Massaccesi
Sorry for not testing before posting, but in this code: (define (randomise-over-fitness accumulated-payoff-percentage population speed) (for/list ([n (in-range speed)]) [define r (random)] (for/and ([p (in-list population)] [a (in-list accumulated-payoff-percentage)]

Re: [racket-users] help on coding finite state automata

2015-10-12 Thread Alex Knauth
What about Alexis King's persistent vectors? > On Oct 12, 2015, at 6:14 PM, Matthias Felleisen wrote: > > > > So I couldn't resist and wrote the vector-based, allocation-minimizing > version of the program. I didn't get that much of a performance gain. > > I might

Re: [racket-users] help on coding finite state automata

2015-10-12 Thread Matthias Felleisen
So I couldn't resist and wrote the vector-based, allocation-minimizing version of the program. I didn't get that much of a performance gain. I might still change the fitness representation (into a vector) or integrate it into 'population' (where it belongs from an SE perspective). I doubt

Re: [racket-users] help on coding finite state automata

2015-10-12 Thread Matthias Felleisen
Take a crack at it. I am pretty sure I have introduced the proper level of representation independence (I can hear Ben laugh all the way now — Typed Racket doesn’t have types) and the typed documentation is pretty solid. (I’ll do types later to validate.) > On Oct 12, 2015, at 7:37 PM,

Re: [racket-users] help on coding finite state automata

2015-10-11 Thread Linh Chi Nguyen
Thank you very much, Im trying to see it. However Im very unfamiliar with module in racket. So far I can only answer you this: about your comment > [define survivors (drop population speed)] > ;; MF: THIS LOOKS LIKE IT MAY "RESURRECT" AUTOM. THAT ARE ALIVE > [define successors

Re: [racket-users] help on coding finite state automata

2015-10-11 Thread Linh Chi Nguyen
ok i've been trying to see through the code. I'm not sure how github works but I pushed the changes in my repo again (https://github.com/ayaderaghul/sample-fsm/blob/master/fsm0.rkt). Basically, I rewrite the automaton module (description and behavior) because previously I made a confusion

Re: [racket-users] help on coding finite state automata

2015-10-11 Thread Linh Chi Nguyen
Sorry for the emails. But I'd like to post that the question of how to require a module then evaluate a command is answered here: https://groups.google.com/forum/#!topic/racket-users/byL7W1yktas by Daniel. Thank you so much for all your help and patience, chi -- You received this message

Re: [racket-users] help on coding finite state automata

2015-10-11 Thread Matthias Felleisen
I have pushed some more cleanups, more speed. I added another question to the “spawning” procedure. > On Oct 10, 2015, at 11:06 PM, Matthias Felleisen wrote: > > I forked, Racket-ized, and gained some speed (~2x). > > > >> On Sep 6, 2015, at 5:21 AM, Nguyen Linh

Re: [racket-users] help on coding finite state automata

2015-10-10 Thread Matthias Felleisen
I forked, Racket-ized, and gained some speed (~2x). > On Sep 6, 2015, at 5:21 AM, Nguyen Linh Chi wrote: > > Dear All, > thanks for all your help, im writing the code to generate a population of > fsm, playing a repeated game and the population evolves over time.

Re: [racket-users] help on coding finite state automata

2015-09-04 Thread Nguyen Linh Chi
Dear mrmyers, I cloned your repo however it's true that i complete have no idea about macro yet. It'd be nice for further reading as i'd work on this problem for long. As soegaard suggests on IRC, to avoid the problem of creating new machines after every interaction, i'd try to make the struct

Re: [racket-users] help on coding finite state automata

2015-09-04 Thread Jens Axel Søgaard
Hi Linh, There are many different representations of finite state machines. If you "just" need to simulate a single machine, a simple and efficient approach is to represent each state as a Racket function (see example below). #lang racket (require racket/generator) ;; The turn-stile example

Re: [racket-users] help on coding finite state automata

2015-09-03 Thread Neil Van Dyke
If your FSM are defined at compile-time, you can write a macro (in `syntax-rules` or `syntax-case`) that transforms FSMs defined in your FSM macro language to efficient Racket code. Even with a macro, there are a few popular ways to do it, but I suggest trying to make your state transitions

Re: [racket-users] help on coding finite state automata

2015-09-03 Thread Michael Titke
On 03/09/2015 16:29, Linh Chi Nguyen wrote: Dear All, I'm a complete newbie in racket and need help in coding finite state machine/automata. Please pardon any of my ignorance. Thanks to this post of Tim Thornton, I see a very good way to code FSM:

Re: [racket-users] help on coding finite state automata

2015-09-03 Thread Paulo Matos
On 03/09/2015 16:34, Neil Van Dyke wrote: If your FSM are defined at compile-time, you can write a macro (in `syntax-rules` or `syntax-case`) that transforms FSMs defined in your FSM macro language to efficient Racket code. Even with a macro, there are a few popular ways to do it, but I suggest