Re: [racket-users] Paper from my first year in graduate school - Racket Simulation

2021-12-22 Thread Nguyen Linh Chi
Hello Stephen,
sure the code is available. Actually it is quite straightforward if people
like to recreate the simulation.
you just need to program finite automata to print out strategy and let
those strategies match up and look for points after each match up.

The population of automata then evolve in a differential equation style. so
the population moves a little closer to strategies that scores more.
after a long time of evolution, the population might settle down in an
equilibrium point. since the algrorithm is stochastic, after a while, the
population can move out of that equilibrium and on the way to another
(might be better) one

let me know if that clarifies
cheers

Vào 23:59, T.4, 22 Th12, 2021 Stephen De Gabrielle 
đã viết:

> Hi
>
> is the code available ?
>
> https://github.com/ayaderaghul
>
> s.
>
>
> On Tue, Dec 21, 2021 at 9:59 PM Linh Chi Nguyen 
> wrote:
>
>> Hey,
>>
>> all the simulations for my paper (published in Bio-inspired EAI
>> International Conference 2016) back then when I was a first year graduate
>> student are in Racket ! This morning I discover that it has 624 downloads
>> and counting. I am so proud of my graduate time <3
>>
>> https://eudl.eu/doi/10.4108/eai.3-12-2015.2262403
>>
>> Have fun and keep inspiring <3
>>
>> regards,
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/racket-users/c4b31aac-8ad9-4a14-8d34-b46b71f4a5dfn%40googlegroups.com
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CALHGW2JKb8DjX7_u1vHExb0yTS0KOfgqBZmC%3DjVhACjBUNR9mg%40mail.gmail.com.


Re: [racket-users] the effect of redacted information in multiple party conflict

2021-04-08 Thread Nguyen Linh Chi
hello friends, let me share that exercise 1 is up here, i would like to
kindly share it with you, as a commitment to keep me working on game theory
and racket and java, and python etc

https://github.com/ayaderaghul/game-n-code/blob/main/README.md

On Tue, 30 Mar 2021 at 08:23, Nguyen Linh Chi 
wrote:

> actually, inspired by https://beautifulracket.com/, and jesse's book i
> revived an intention to write a book on game theory and racket code
> simulation library/package
> drop me a line for any request, (for example, make the example and library
> more fun to learn)
>
> On Tue, 30 Mar 2021 at 08:19, Nguyen Linh Chi 
> wrote:
>
>> git repo: https://github.com/ayaderaghul/shdm
>> https://github.com/ayaderaghul/shd
>>
>> * for historical note:
>> if you check the git repo, you would see similar code structure to a
>> paper i presented at racketcon a few years ago, but the simulation was for
>> the prisonel dilemma game,
>> i still feel grateful and keep fond memories of the supportive vibe of
>> the racket community that fall
>>
>> On Sun, 28 Mar 2021 at 09:52, Linh Chi Nguyen 
>> wrote:
>>
>>> dear friends and colleagues,
>>>
>>> sometimes i would like to send the result of my academic endeavour to
>>> this group. since simulation and game theory has become some sort of blood
>>> and bones to me.
>>>
>>> i remember years ago, i already pasted some of the result on this list,
>>> but academia takes century to produce a paper. i attach here my work on
>>> game theory and simulation using racket (there were the days that i slept
>>> at the school lab and code racket like eating rice)
>>>
>>> cheers,
>>> have a good day,
>>> let me know of good news from your side, and please speak up if you see
>>> something deserved to be said
>>> chi
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Racket Users" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/racket-users/Vt6x2PqOBOg/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> racket-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/racket-users/e0196138-e368-4a36-96c2-96eba298c130n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/racket-users/e0196138-e368-4a36-96c2-96eba298c130n%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>>
>>
>>
>> --
>> *Nguyen Linh Chi*
>> Github: https://github.com/ayaderaghul
>> LinkedIn: https://www.linkedin.com/in/linh-chi-n-371139180/
>>
>
>
> --
> *Nguyen Linh Chi*
> Github: https://github.com/ayaderaghul
> LinkedIn: https://www.linkedin.com/in/linh-chi-n-371139180/
>


-- 
*Nguyen Linh Chi*
Github: https://github.com/ayaderaghul
LinkedIn: https://www.linkedin.com/in/linh-chi-n-371139180/

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CALHGW2%2BhwOrQcaiXsya9-GffJFg2LxKhvASrspDy4nynhx%2BxdA%40mail.gmail.com.


Re: [racket-users] the effect of redacted information in multiple party conflict

2021-03-29 Thread Nguyen Linh Chi
actually, inspired by https://beautifulracket.com/, and jesse's book i
revived an intention to write a book on game theory and racket code
simulation library/package
drop me a line for any request, (for example, make the example and library
more fun to learn)

On Tue, 30 Mar 2021 at 08:19, Nguyen Linh Chi 
wrote:

> git repo: https://github.com/ayaderaghul/shdm
> https://github.com/ayaderaghul/shd
>
> * for historical note:
> if you check the git repo, you would see similar code structure to a paper
> i presented at racketcon a few years ago, but the simulation was for the
> prisonel dilemma game,
> i still feel grateful and keep fond memories of the supportive vibe of the
> racket community that fall
>
> On Sun, 28 Mar 2021 at 09:52, Linh Chi Nguyen 
> wrote:
>
>> dear friends and colleagues,
>>
>> sometimes i would like to send the result of my academic endeavour to
>> this group. since simulation and game theory has become some sort of blood
>> and bones to me.
>>
>> i remember years ago, i already pasted some of the result on this list,
>> but academia takes century to produce a paper. i attach here my work on
>> game theory and simulation using racket (there were the days that i slept
>> at the school lab and code racket like eating rice)
>>
>> cheers,
>> have a good day,
>> let me know of good news from your side, and please speak up if you see
>> something deserved to be said
>> chi
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Racket Users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/racket-users/Vt6x2PqOBOg/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> racket-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/racket-users/e0196138-e368-4a36-96c2-96eba298c130n%40googlegroups.com
>> <https://groups.google.com/d/msgid/racket-users/e0196138-e368-4a36-96c2-96eba298c130n%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>
>
> --
> *Nguyen Linh Chi*
> Github: https://github.com/ayaderaghul
> LinkedIn: https://www.linkedin.com/in/linh-chi-n-371139180/
>


-- 
*Nguyen Linh Chi*
Github: https://github.com/ayaderaghul
LinkedIn: https://www.linkedin.com/in/linh-chi-n-371139180/

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CALHGW2LjerajwNaTK%3De1%3D0n%3DMbpNgVaup3Mj-pPcK1%2B3jbt%3DbQ%40mail.gmail.com.


Re: [racket-users] the effect of redacted information in multiple party conflict

2021-03-29 Thread Nguyen Linh Chi
git repo: https://github.com/ayaderaghul/shdm
https://github.com/ayaderaghul/shd

* for historical note:
if you check the git repo, you would see similar code structure to a paper
i presented at racketcon a few years ago, but the simulation was for the
prisonel dilemma game,
i still feel grateful and keep fond memories of the supportive vibe of the
racket community that fall

On Sun, 28 Mar 2021 at 09:52, Linh Chi Nguyen 
wrote:

> dear friends and colleagues,
>
> sometimes i would like to send the result of my academic endeavour to this
> group. since simulation and game theory has become some sort of blood and
> bones to me.
>
> i remember years ago, i already pasted some of the result on this list,
> but academia takes century to produce a paper. i attach here my work on
> game theory and simulation using racket (there were the days that i slept
> at the school lab and code racket like eating rice)
>
> cheers,
> have a good day,
> let me know of good news from your side, and please speak up if you see
> something deserved to be said
> chi
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Racket Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/racket-users/Vt6x2PqOBOg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/e0196138-e368-4a36-96c2-96eba298c130n%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/e0196138-e368-4a36-96c2-96eba298c130n%40googlegroups.com?utm_medium=email_source=footer>
> .
>


-- 
*Nguyen Linh Chi*
Github: https://github.com/ayaderaghul
LinkedIn: https://www.linkedin.com/in/linh-chi-n-371139180/

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CALHGW2Ke-dd4iqe8Gx-6Sne_mJmFkm%2BaWcC%3DujZHqrs44a3_Yw%40mail.gmail.com.


Re: [racket-users] generate sentences

2017-03-01 Thread Nguyen Linh Chi
Thanks for pointing me to ELIZA.
https://en.m.wikipedia.org/wiki/ELIZA

It's interesting.
^^ i dont doubt that people would develop sentiments toward a chatbot that
just simply speak random.

Not to say that, if i'm the one that makes the program, i would have
affection toward it also.

It's a puzzling emotion. But we have it, so.

Also, it can be irrational, but if it helps in psychological treatment,
then it helps. It's just that these methods (placebo, nocebo, hynotise,
telepathy..) are in the minority (such as some surreal deviations of born
autistic individuals). So it wont work on the majority.


On Mar 1, 2017 10:24, "Nguyen Linh Chi" <nguyenlinhch...@gmail.com> wrote:

Sorry but can i just ask this question, because this is out of my thinking
capacity (i have very little knowledge of computer stuff)

The program of lab 7 is to generate pseudo-natural sentences. It's not
interactive in the sense that i cannot talk to it. I can only tell it to
say-something and it says something based on its data history.

I was wondering, in which way i can make a program that response to what i
say. like a chatbot. what is the simplest version of a chat bot.

should i give it conversations, telling which sentence is the initiator,
which is the responder?
then storing the sentences by breaking them down using the same structure
as a writing style (so a sentence is the smallest unit of a writing style).

when i say something, the program will try to comprehend my sentence by
comparing it with its database. if it finds a roughly similar sentence, it
get the responder sentence to respond to me.

i dont know. just asking, if anyone has any idea or simple solution for
beginner?





On Feb 26, 2017 21:47, "Nguyen Linh Chi" <nguyenlinhch...@gmail.com> wrote:

Oh my goodness, it is real.

I was really thinking that if i truly tried to generate such a paper,
probably they would not notice.

On Feb 26, 2017 02:01, "Matthew Butterick" <m...@mbtype.com> wrote:

>
> On Feb 25, 2017, at 1:33 PM, Linh Chi Nguyen <nguyenlinhch...@gmail.com>
> wrote:
>
> anyway, when being asked to say-something, the machine generates quite
> good sentences. i have this secret hope [0] that if i feed it enough game
> theory literature, somehow it can generate something of value for my phd
> thesis =)) because i'm so stuck.
>
>
>
> The champion in this category is SCIgen [1], which AFAIK has not been
> ported to Racket. [2]
>
>
> [1] https://pdos.csail.mit.edu/archive/scigen/
>
> [2] https://github.com/strib/scigen
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] generate sentences

2017-03-01 Thread Nguyen Linh Chi
Sorry but can i just ask this question, because this is out of my thinking
capacity (i have very little knowledge of computer stuff)

The program of lab 7 is to generate pseudo-natural sentences. It's not
interactive in the sense that i cannot talk to it. I can only tell it to
say-something and it says something based on its data history.

I was wondering, in which way i can make a program that response to what i
say. like a chatbot. what is the simplest version of a chat bot.

should i give it conversations, telling which sentence is the initiator,
which is the responder?
then storing the sentences by breaking them down using the same structure
as a writing style (so a sentence is the smallest unit of a writing style).

when i say something, the program will try to comprehend my sentence by
comparing it with its database. if it finds a roughly similar sentence, it
get the responder sentence to respond to me.

i dont know. just asking, if anyone has any idea or simple solution for
beginner?





On Feb 26, 2017 21:47, "Nguyen Linh Chi" <nguyenlinhch...@gmail.com> wrote:

Oh my goodness, it is real.

I was really thinking that if i truly tried to generate such a paper,
probably they would not notice.

On Feb 26, 2017 02:01, "Matthew Butterick" <m...@mbtype.com> wrote:

>
> On Feb 25, 2017, at 1:33 PM, Linh Chi Nguyen <nguyenlinhch...@gmail.com>
> wrote:
>
> anyway, when being asked to say-something, the machine generates quite
> good sentences. i have this secret hope [0] that if i feed it enough game
> theory literature, somehow it can generate something of value for my phd
> thesis =)) because i'm so stuck.
>
>
>
> The champion in this category is SCIgen [1], which AFAIK has not been
> ported to Racket. [2]
>
>
> [1] https://pdos.csail.mit.edu/archive/scigen/
>
> [2] https://github.com/strib/scigen
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] generate sentences

2017-02-23 Thread Nguyen Linh Chi
Wow, it's really a good curriculum.
Just have to drop in to say something, im not doing this exercise for some
course, there is no teacher.

I was just massively sad and when i got up i need to do something that
makes some sense. After lots of thinking, i just assume that there is this
kind of exercise for beginner somewhere.

To all racket students: a well-structured school is a fortunate thing. You
get a well-packaged sense of purpose. People are broken, mostly because
after family and school, reality hits. With lessons of survival, betrayal,
responsibility, rejection.. we realise that life is apathetically vast and
the universe is just "radically indifferent" about everything. These
useless ponderings would eat away our meaningness. And doctors start to
have to prescribe antidepressants.

So do exercises when you still know that there are good teachers around
pushing you :)
Have a good day,

On Feb 21, 2017 16:23, "Nguyen Linh Chi" <nguyenlinhch...@gmail.com> wrote:

> Thank you Matthias,
>
> It seems that you all have developed a well structured path of programming
> experience for beginners. Great! Coding can be somewhat therapeutic, i
> start to think so.
>
> I'll check (and complain later :)
>
> Good day everyone !
>
> On Feb 21, 2017 15:32, "Matthias Felleisen" <matth...@ccs.neu.edu> wrote:
>
>>
>> Dear Linh Chi,
>>
>> the exercise is basically Lab 7 from the last instance of the
>> Northeastern beginners course:
>>
>>  http://www.ccs.neu.edu/course/cs2500f16/lab7.html
>>
>> If you work through this lab, you will get a performant solution based on
>> lists. Once you have that, it should be fairly obvious how to replace the
>> ‘table’ with a hashtable in this solution, though you have to bump the
>> language to ASL and include the 2htdp/abstraction teachpack to get the
>> style your teacher wants.
>>
>> For help with the solution, consider working through Part III of the text
>> book:
>>
>>   http://www.ccs.neu.edu/home/matthias/HtDP2e/
>>
>> For your own learning experience, it might be best if you followed the
>> design recipe and then ask questions about specific problems with function
>> design. People on the list will gladly help then.
>>
>> — Matthias
>>
>>
>>
>>
>>
>> > On Feb 21, 2017, at 3:55 AM, Linh Chi Nguyen <nguyenlinhch...@gmail.com>
>> wrote:
>> >
>> > hello,
>> > i'm doing this exercise and would appreciate any comments. i want to
>> create a machine to scan a text, then split the text into elements (storing
>> in a hash table). then we connect these hash keys in a probabilistic way,
>> so that if we start from a word, we can jump to other words in a
>> probabilistic way. hence, we can generate a sentence that is sufficiently
>> independent from our bias. the point is, if these probability makes sense
>> (for example, it is real statistics from real high quality text, i.e. from
>> famous writers), i hope that the machine can generate one or two sentences
>> that is entertaining.
>> >
>> > (require 2htdp/batch-io)
>> > (require racket/hash)
>> >
>> > (define input (read-file "sample.txt"))
>> > (define data (remove-duplicates (string-split input)))
>> >
>> > to make it very easy at first, i dont use the frequency of the elements
>> (words mostly) just yet. i just make a hash table that take each element as
>> a key, the associated value will be a dispatching rule. to begin with, the
>> dispatching rule is simple: the current key will be connected to two other
>> keys, with probability. for example: the element "run" is connected to
>> "instead." with probability .48 and "helmets" with probability .08.
>> >
>> > (hash "run" (hash 0.48 "instead." 0.08 "helmets"))
>> >
>> >
>> > (struct state (word dispatch) #:transparent)
>> >
>> > (define (random-member lst)
>> >  (list-ref lst (random (length lst
>> >
>> > (define (make-sample-machine lst)
>> >  (define l (length lst))
>> >  (define (make-transition)
>> >(hash (round-2 (random)) (random-member lst)
>> >  (round-2 (random)) (random-member lst)))
>> >  (foldl (lambda (word h) (hash-union h (hash word (make-transition
>> > (hash) lst))
>> >
>> > (define (round-n x n)
>> >  (/ (round (* x (expt 10 n))) (expt 10 n)))
>> > (define (round-2 x)
>> >  (round-n x 2))
>> >
>> > (define m (make-samp

Re: [racket-users] generate sentences

2017-02-21 Thread Nguyen Linh Chi
Thank you Matthias,

It seems that you all have developed a well structured path of programming
experience for beginners. Great! Coding can be somewhat therapeutic, i
start to think so.

I'll check (and complain later :)

Good day everyone !

On Feb 21, 2017 15:32, "Matthias Felleisen"  wrote:

>
> Dear Linh Chi,
>
> the exercise is basically Lab 7 from the last instance of the Northeastern
> beginners course:
>
>  http://www.ccs.neu.edu/course/cs2500f16/lab7.html
>
> If you work through this lab, you will get a performant solution based on
> lists. Once you have that, it should be fairly obvious how to replace the
> ‘table’ with a hashtable in this solution, though you have to bump the
> language to ASL and include the 2htdp/abstraction teachpack to get the
> style your teacher wants.
>
> For help with the solution, consider working through Part III of the text
> book:
>
>   http://www.ccs.neu.edu/home/matthias/HtDP2e/
>
> For your own learning experience, it might be best if you followed the
> design recipe and then ask questions about specific problems with function
> design. People on the list will gladly help then.
>
> — Matthias
>
>
>
>
>
> > On Feb 21, 2017, at 3:55 AM, Linh Chi Nguyen 
> wrote:
> >
> > hello,
> > i'm doing this exercise and would appreciate any comments. i want to
> create a machine to scan a text, then split the text into elements (storing
> in a hash table). then we connect these hash keys in a probabilistic way,
> so that if we start from a word, we can jump to other words in a
> probabilistic way. hence, we can generate a sentence that is sufficiently
> independent from our bias. the point is, if these probability makes sense
> (for example, it is real statistics from real high quality text, i.e. from
> famous writers), i hope that the machine can generate one or two sentences
> that is entertaining.
> >
> > (require 2htdp/batch-io)
> > (require racket/hash)
> >
> > (define input (read-file "sample.txt"))
> > (define data (remove-duplicates (string-split input)))
> >
> > to make it very easy at first, i dont use the frequency of the elements
> (words mostly) just yet. i just make a hash table that take each element as
> a key, the associated value will be a dispatching rule. to begin with, the
> dispatching rule is simple: the current key will be connected to two other
> keys, with probability. for example: the element "run" is connected to
> "instead." with probability .48 and "helmets" with probability .08.
> >
> > (hash "run" (hash 0.48 "instead." 0.08 "helmets"))
> >
> >
> > (struct state (word dispatch) #:transparent)
> >
> > (define (random-member lst)
> >  (list-ref lst (random (length lst
> >
> > (define (make-sample-machine lst)
> >  (define l (length lst))
> >  (define (make-transition)
> >(hash (round-2 (random)) (random-member lst)
> >  (round-2 (random)) (random-member lst)))
> >  (foldl (lambda (word h) (hash-union h (hash word (make-transition
> > (hash) lst))
> >
> > (define (round-n x n)
> >  (/ (round (* x (expt 10 n))) (expt 10 n)))
> > (define (round-2 x)
> >  (round-n x 2))
> >
> > (define m (make-sample-machine data))
> >
> > data of the machine looks like this:
> >
> > '#hash(("spread" . #hash((0.9 . "right") (0.21 . "deep")))
> >   ("instead" . #hash((0.64 . "then") (0.19 . "dark")))
> >   ("through" . #hash((0.3 . "meadow") (0.95 . "white,")))
> >   ("their" . #hash((0.56 . "instead") (0.98 . "valley,")))
> >
> > now i try to generate a sentence of 10 words, i guess it is some kind of
> loops, but when it write the function, it is super slow.
> >
> > the idea is that, we randomise to choose the first word, then this first
> word has an associated dispatching rule. we use the probability in this
> rule to randomise for the next word..
> >
> > is it because i use too much randomisation that the function is super
> slow?
> >
> > (define (accumulate lst)
> >  (define total (apply + lst))
> >  (let absolute->relative ([elements lst] [so-far #i0.0])
> >(cond
> > [(empty? elements) '()]
> > [else (define nxt (+ so-far (round-2 (/ (first elements) total
> >   (cons nxt (absolute->relative (rest elements) nxt))])))
> >
> > (define (randomise accumulated-lst)
> >  (define r (random))
> >  (for/last ([p (in-naturals)] [% (in-list accumulated-lst)] #:final (< r
> %)) p))
> >
> > (define (generate-text m n)
> >  (define l (hash-count m))
> >  (define r (random l))
> >  (match-define (cons first-word dispatch) (hash-iterate-pair m r))
> >  (cons first-word
> >(let generate ([count-down n] [next-batch dispatch])
> >  (cond
> >   [(zero? count-down) '()]
> >   [else
> >(define proba (hash-keys dispatch))
> >(define next-word (hash-iterate-key m (randomise (accumulate
> proba
> >(define next-dispatch (hash-ref m next-word))
> >(cons next-word (generate (- n 1) 

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 automaton is 
falsely identified as automaton c.

(Hm, right?)

On 13/ott/2015, at 20:21, Nguyen Linh Chi <nguyenlinhch...@gmail.com> wrote:

> 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: round and cycle. In 
> each cycle, automata are matched in pair and play a game for r rounds per 
> match. At the end of each cycle, there is a replacement period (respawning 
> the fittest). In what im doing, the payoff after r rounds is transformed into 
> the fitness, and the strongest automata (biggest payoff) survive. In some 
> sense they already carry on their relative payoff with them just because they 
> survive.
> 
> Make the automaton carrying their absolute payoff history over cycles would 
> be intereting to see. I've never thought of that and the coding effort is 
> also a reason i havent tried.
> 
> On 13/ott/2015, at 19:59, Matthias Felleisen <matth...@ccs.neu.edu> wrote:
> 
>> 
>> 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 <matth...@ccs.neu.edu> wrote:
>> 
>>> 
>>> 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 
>>> situations than the ones you explored. My interest diverges from yours. To 
>>> me it is now just a cute benchmark. You will be able to use my insights to 
>>> speed up your performance: 
>>> 
>>> -- factor the program into separate modules/files, 
>>> -- make the modules independent of the representations, 
>>> -- change automata and population representations to use vectors instead of 
>>> lists, 
>>> -- avoid mutation, 
>>> -- eliminate all situations where you use (append l (list x)); instead use 
>>> cons and reverse the result at the end. 
>>> 
>>> That way you can run the program 6 times faster. 
>>> 
>>> 3. Otherwise I think your program needs real testing and I think there are 
>>> two bugs: 
>>> 
>>> a: I created a pull request for this one: 
>>> 
>>> 
>>> (define (accumulated-payoff-percentages payoff-list)
>>> (define payoff-sum (apply + payoff-list))
>>> (define-values (accumulated _)
>>>   (for/fold ([accumulated (list 0)] ;; change to '(); otherwise you get a 
>>> list that's too long; your other for loop accidentally compensates for this 
>>> bug 
>>>  [init 0])
>>> ([y (in-list payoff-list)])
>>> [define next-init (+ init (/ y payoff-sum))]
>>> (values (cons next-init accumulated) next-init)))
>>> (reverse accumulated))
>>> 
>>> b: I don't know how to fix this one properly: 
>>> 
>>> (define (randomise-over-fitness population fitness speed)
>>> (for/list ([n (in-range speed)])
>>> [define r (random)]
>>> (define candidate
>>>   (for/and ([p (in-vector population)]
>>>  [f (in-list fitness)]
>>>  #:break (< r f))
>>> p))
>>> candidate))
>>> 
>>> replace last line with something like this: 
>>> (or candidate (vector-ref population 0
>>> 
>>> Otherwise there is a non-0 chance otherwise that you get a boolean value 
>>> eventually. I am not sure which default value you want to throw in. 
>>> 
>>> 4. You're right:
>>> 
>>> -- I re-created the match-pair function when I looked over my code. 
>>> -- using in-list and in-vector and in-range speeds up for loops. 
>>> -- types are irrelevant to your project. They helped me. 
>>> 
>>> I have pushed the last changes for now. Can we have your permission to use 
>>> t

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: round and cycle. In each 
cycle, automata are matched in pair and play a game for r rounds per match. At 
the end of each cycle, there is a replacement period (respawning the fittest). 
In what im doing, the payoff after r rounds is transformed into the fitness, 
and the strongest automata (biggest payoff) survive. In some sense they already 
carry on their relative payoff with them just because they survive.

Make the automaton carrying their absolute payoff history over cycles would be 
intereting to see. I've never thought of that and the coding effort is also a 
reason i havent tried.

On 13/ott/2015, at 19:59, Matthias Felleisen  wrote:

> 
> 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 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 
>> situations than the ones you explored. My interest diverges from yours. To 
>> me it is now just a cute benchmark. You will be able to use my insights to 
>> speed up your performance: 
>> 
>> -- factor the program into separate modules/files, 
>> -- make the modules independent of the representations, 
>> -- change automata and population representations to use vectors instead of 
>> lists, 
>> -- avoid mutation, 
>> -- eliminate all situations where you use (append l (list x)); instead use 
>> cons and reverse the result at the end. 
>> 
>> That way you can run the program 6 times faster. 
>> 
>> 3. Otherwise I think your program needs real testing and I think there are 
>> two bugs: 
>> 
>> a: I created a pull request for this one: 
>> 
>> 
>> (define (accumulated-payoff-percentages payoff-list)
>>   (define payoff-sum (apply + payoff-list))
>>   (define-values (accumulated _)
>> (for/fold ([accumulated (list 0)] ;; change to '(); otherwise you get a 
>> list that's too long; your other for loop accidentally compensates for this 
>> bug 
>>[init 0])
>>   ([y (in-list payoff-list)])
>>   [define next-init (+ init (/ y payoff-sum))]
>>   (values (cons next-init accumulated) next-init)))
>>   (reverse accumulated))
>> 
>> b: I don't know how to fix this one properly: 
>> 
>> (define (randomise-over-fitness population fitness speed)
>> (for/list ([n (in-range speed)])
>>   [define r (random)]
>>   (define candidate
>> (for/and ([p (in-vector population)]
>>[f (in-list fitness)]
>>#:break (< r f))
>>   p))
>>   candidate))
>> 
>> replace last line with something like this: 
>>   (or candidate (vector-ref population 0
>> 
>> Otherwise there is a non-0 chance otherwise that you get a boolean value 
>> eventually. I am not sure which default value you want to throw in. 
>> 
>> 4. You're right:
>> 
>> -- I re-created the match-pair function when I looked over my code. 
>> -- using in-list and in-vector and in-range speeds up for loops. 
>> -- types are irrelevant to your project. They helped me. 
>> 
>> I have pushed the last changes for now. Can we have your permission to use 
>> this code for a benchmark in our research world? Thanks. 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> On Oct 13, 2015, at 12:00 PM, Linh Chi Nguyen  
>> wrote:
>> 
>>> 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 probabilistic one, they can even randomise 
>>> between cooperate or defect, but the case of deterministic and 
>>> probabilistic should be separated far).
>>> 
>>> it means that, even for a 2 state automaton, it can happen that both state 
>>> use the same cooperate action.
>>> 
>>> 
>>> other small notices
>>> - the all defect automaton start with defecting and always defecting so its 
>>> code is : defect defect defect... not cooperate defect defect... (same for 
>>> the all cooperates one)
>>> 
>>> - i'm considering to add a mutation phase at the end of each cycle (ie 
>>> choose some random automaton and mutate their code) but im working very 
>>> slow.
>>> 
>>> - why dont you define a (match-pair ...) function separately? you 

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 #:mutable. Hope that'd
be good.

Thanks for great advice,
Chi

On 4 September 2015 at 12:00, Jens Axel Søgaard <jensa...@soegaard.net>
wrote:

> 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 from Wikipedia.
> ;;
> https://en.wikipedia.org/wiki/Finite-state_machine#Example:_coin-operated_turnstile
>
> ;; Current State  Input   Next State   Output
> ;;   LOCKED   coinUNLOCKED unlock turnstile so customer can
> push through
> ;;   LOCKED   push  LOCKED none (custome can't move through)
> ;; UNLOCKED   coinUNLOCKED none
> ;; UNLOCKED   push  LOCKED when customer is through, lock
> turnstile
>
> (define inputs '(coin push push push coin coin push))
> (define get-input (sequence->generator inputs))
>
> (define (LOCKED)
>   (match (get-input)
> ['coin(displayln "turnstile is unlocked")
>   (UNLOCKED)]
> ['push(displayln "you can't move through locked turnstile")
>   (LOCKED)]
> [_(DONE)]))
>
> (define (UNLOCKED)
>   (match (get-input)
> ['coin(displayln "no need to pay when the turnstile is unlocked")
>   (UNLOCKED)]
> ['push(displayln "customer goes through, turnstile is locked")
>   (LOCKED)]
> [_(DONE)]))
>
> (define (DONE)
>   (displayln "no more inputs"))
>
> (LOCKED) ; start turnstile in a locked state
>
>
>
>
> 2015-09-03 16:29 GMT+02:00 Linh Chi Nguyen <nguyenlinhch...@gmail.com>:
>
>> 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:
>> http://timthornton.net/blog/id/538fa6f2f09a16ba0674813d
>>
>> I'd summarise it as following:
>> A finite state automaton has a number of states and each state has a name
>> plus many transition rules. He structures it in racket as following:
>>
>> (struct automaton (current-state states))
>> (struct state (name actions))
>> (struct action (event result))
>>
>> A simple automaton can be like this:
>> (define simple-fsm (fsm 'A
>> (list (fstate 'A (list (action 0 'A)
>>(action 1 'B)))
>>   (fstate 'B (list (action 0 'B)
>>(action 1 'A))
>>
>> The automaton is in state A which has 2 transition rules:
>> - if event 1 happens, the automaton jumps to state B,
>> - if event 0 happens, it stays in state A.
>>
>> Then he writes some functions to update the automaton after each event
>> (in the post). Plus this function he omits (I guess):
>> (define fsm-update-state old-fsm new-state)
>>   (struct-copy automaton old-fsm [current-state new-state]))
>>
>> HERE IS THE QUESTION:
>>
>> Using this way, after each event, there'd be a NEW automaton created. So
>> I'm worried about scaling. I'd like to generate 100 automata. In each
>> cycle, I'd pair the automata to interact for 50 times. Which means that
>> there'd be 100 new automata created for every single cycle. And I'd like to
>> run at least 1000 cycles.
>>
>> Would there be any problem with scaling? If yes, is there a way around
>> this?
>>
>> Any kind of comments and suggestions are welcomed and appreciated,
>> Thank you really much,
>> Chi
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> --
> Jens Axel Søgaard
>
>


-- 
*Nguyen Linh Chi*

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2015-09-03 Thread Nguyen Linh Chi
Wow as much as i appreciate and try to see through all the answers, i have to 
confess that i'm a first year Phd student in economics. So writing macro is too 
far for me now.

I'd just process with struct.. And see how expensive it is for my agent based 
model. Hopefully i can show you the code some day, regarding all these 
suggestions, if still relevant.

Thank you,
Chi

On 04/set/2015, at 03:25, mrmyers.random.suf...@gmail.com wrote:

> On Thursday, September 3, 2015 at 10:29:33 AM UTC-4, 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:
>> http://timthornton.net/blog/id/538fa6f2f09a16ba0674813d
>> 
>> I'd summarise it as following:
>> A finite state automaton has a number of states and each state has a name 
>> plus many transition rules. He structures it in racket as following:
>> 
>> (struct automaton (current-state states))
>> (struct state (name actions))
>> (struct action (event result))
>> 
>> A simple automaton can be like this:
>> (define simple-fsm (fsm 'A 
>>(list (fstate 'A (list (action 0 'A)
>>   (action 1 'B)))
>>  (fstate 'B (list (action 0 'B)
>>   (action 1 'A))
>> 
>> The automaton is in state A which has 2 transition rules: 
>> - if event 1 happens, the automaton jumps to state B, 
>> - if event 0 happens, it stays in state A.
>> 
>> Then he writes some functions to update the automaton after each event (in 
>> the post). Plus this function he omits (I guess):
>> (define fsm-update-state old-fsm new-state)
>>  (struct-copy automaton old-fsm [current-state new-state]))
>> 
>> HERE IS THE QUESTION:
>> 
>> Using this way, after each event, there'd be a NEW automaton created. So I'm 
>> worried about scaling. I'd like to generate 100 automata. In each cycle, I'd 
>> pair the automata to interact for 50 times. Which means that there'd be 100 
>> new automata created for every single cycle. And I'd like to run at least 
>> 1000 cycles.
>> 
>> Would there be any problem with scaling? If yes, is there a way around this?
>> 
>> Any kind of comments and suggestions are welcomed and appreciated,
>> Thank you really much,
>> Chi
> 
> You might want to take a look at https://github.com/mromyers/automata 
> specifically, https://github.com/mromyers/automata/blob/master/examples.rkt
> and https://github.com/mromyers/automata/blob/master/machines.rkt
> I more or less just use the definition that was in my textbook: you provide a 
> transition function, and the DFA or NFA just uses stream-fold to get the 
> extended transition. I used a bunch of generics stuff to try to generalize 
> everything past the point of practicality, but it's still reasonably fast. 
> It's not documented, but use (in-machine? M seq) to check for acceptance, 
> (extended-transition M start seq) for final state(s).
> 
> There's also a minimization function and nfa->dfa conversion in there, but 
> they might have some bugs.
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "Racket Users" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/racket-users/4o1goSwrLHA/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.