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
>> <https://groups.google.com/d/msgid/racket-users/c4b31aac-8ad9-4a14-8d34-b46b71f4a5dfn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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.


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

2021-12-21 Thread Linh Chi Nguyen


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.


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&utm_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&utm_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&utm_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.


[racket-users] (seventh RacketCon) Call for Speakers

2017-06-07 Thread Linh Chi Nguyen
I endorse that Racket Con is super cool. I was in last year. Every one has a 
universe of beautiful things in their head.

If there is something i have learnt from game theory, it is this: if we have 
the same prior, then we cannot agree to disagree. However, since we have 
different genetic settings, different data history etc, we inevitably disagree. 
Maintaining a nurturing environment for conflicting interests is important. And 
racket has it.

You would find that the vibe of Racket is very relaxing, modern and tolerant. 
Everything is laid back, there is no entry barrier at all.

So if you worry that you do weird and insignificant stuff, i tell you that the 
world has taught you wrong and Racket is your refugee shelter.

Please do not hesitate 💚💛💜

-- 
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.


[racket-users] Re: generate sentences

2017-03-17 Thread Linh Chi Nguyen
i have some progress on the markov machine that generate random sentences. i 
update here just in case.

the program that consumes text and then calculate the probability of the next 
word, given the current word is a markov machine of memory 1. memory 1 means 
that we input it one word and it generates the next word.

i try the markov machine with memory 2, and it generates better sentences. 
memory 2 means that it guesses what is the next word after two current words. 
memory 3 (it guesses what is the next word after 3 current words) is too much. 
usually it just retrieves a whole sentence from sample text. or i need bigger 
sample with longer sentences.

then i scan the text but backward. in this way i can tell the program to 
say-something-in-reverse. it can generate sentence from the end back to the 
begining.

why? because when i tell the program to (say-something-about "flower"), it will 
generate the rest of the sentence, from the keyword "flower" to the ending 
signal which is a dot ".". then it will generate the first part of the 
sentence, from the keyword "flower" back to the begining signal which is a 
space " ".

now, though i dont have a chatbot yet, i can have fun asking the program to 
respond vaguely to my whimsical inquiries.

> (say-something-about "you")
"  \"Are you a noise ."
> (say-something-about "earth")
"  There was himself, he was there, a whole earth ."
> (say-something-about "life")
"  He did not bear to have to keep his consciousness, he could relapse into 
life ."
> (say-something-about "neutrality")
"  He felt was merely impersonal, though a hot flash passed through his 
neutrality as the little uneasiness took pleasure ."

have a good day ^^,

-- 
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
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"  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"  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"  wrote:

>
> On Feb 25, 2017, at 1:33 PM, Linh Chi Nguyen 
> 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"  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"  wrote:

>
> On Feb 25, 2017, at 1:33 PM, Linh Chi Nguyen 
> 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-26 Thread Nguyen Linh Chi
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"  wrote:

>
> On Feb 25, 2017, at 1:33 PM, Linh Chi Nguyen 
> 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-25 Thread Linh Chi Nguyen
after i did the exercise as guided, i think there is no need to use hash-table.

also, i don't use the provided text input, but i read-words from text files. so 
i have to add some trick to create the beginning " " and the end "." for the 
writing-style.

in the function (add-to-ws ws word1 word2), i put some extra conditions, to 
check if word1 (or word2) is ended with ".". if yes, i de-dot the word and 
update as usual. if no, i update the words as usual.

https://github.com/ayaderaghul/lab7-htdp

the lab 7 guide is surprisingly elegant (or maybe not surprisingly, because it 
comes from such and such :) however, i read that "students cant post solutions 
to exercises online", i dont know if this apply to my case.

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.

[0] the secret hope is based on this story about putting monkeys in a room full 
of typesetters. as time runs to infinity, the probability of these monkeys 
typing out a Shakepears-level novel increases.

good night,

-- 
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-25 Thread Linh Chi Nguyen
oh it's very kind of you.
thank you,
let's see

-- 
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"  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"  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 l

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))
>

[racket-users] generate sentences

2017-02-21 Thread Linh Chi Nguyen
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) next-dispatch))]

this exercise is at the beginer level, so i guess, someone must have done it 
before. anyone has experience in doing this? like, is it a good way to 
represent the data in a hash table? how to handle when the sample text (so the 
hash table) becomes very large?

here is the sample text:

They had marched more than thirty kilometres since dawn, along the white, hot 
road where occasional thickets of trees threw a moment of shade, then out into 
the glare again. On either hand, the valley, wide and shallow, glittered with 
heat; dark green patches of rye, pale young corn, fallow and meadow and black 
pine woods spread in a dull, hot diagram under a glistening sky. But right in 
front the mountains ranged across, pale blue and very still, snow gleaming 
gently out of the deep atmosphere. And towards the mountains, on and on, the 
regiment marched between the rye fields and the meadows, between the scraggy 
fruit trees set regularly on either side the high road. The burnished, dark 
green rye threw off a suffocating heat, the mountains drew gradually nearer and 
more distinct. While the feet of the soldiers grew hotter, sweat ran through 
their hair under their helmets, and their knapsacks could burn no more in 
contact with their shoulders, but seemed instead to give off a cold, prickly 
sensation.

thank you,
and have a good day,
(if you read until this point)

 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop re

[racket-users] mass production of definitions

2016-10-27 Thread Linh Chi Nguyen
in case someone finds this useful :)




hi vincent,

how are you?

i would like to ask you this , i'm trying to mass produce definitions, however 
`eval is tricky:

(define l1 (list 'a 'b))
(define l2 (list (list 1 2) (list 3 4)))
(for ([i (in-list l1)] [j (in-list l2)]) (eval `(define i j)))

i have tried (eval (list 'define i j)) and other variants but nothing works.
=.=
can you explain to me a bit about this?

(i have 2 exams this week in order to be accepted into the second year, that's 
why i have gone into hibernation since september y.y)

thank you,

+


Hi Chi,

On Wed, 26 Oct 2016 04:41:16 -0500,
Nguyen Linh Chi wrote:
>
> hi vincent,
>
> how are you?

I'm doing great! Now that I'm done with releasing Racket 6.7, I'm a
little bit less busy. :)


> i would like to ask you this , i'm trying to mass produce definitions,
> however `eval is tricky:
>
> (define l1 (list 'a 'b))
> (define l2 (list (list 1 2) (list 3 4)))
> (for ([i (in-list l1)] [j (in-list l2)]) (eval `(define i j)))
>
> i have tried (eval (list 'define i j)) and other variants but nothing
> works.
> =.=
> can you explain to me a bit about this?

As you say, `eval` is tricky. It's almost never the right tool to use in
Racket. Matthew wrote a great blog post about this:


http://blog.racket-lang.org/2011/10/on-eval-in-dynamic-languages-generally.html

What you're trying to do, really, is to write a program (the loop) that
generates a program (a bunch of definitions). That's exactly what
Racket's macros are for.

As a general intro to macros, and Racket's syntax system in general, I
highly recommend Greg Hendershott's Fear of Macros:

http://www.greghendershott.com/fear-of-macros/

Now, as for the specific example you're interested in, here's how you
would do it with a macro:

(define-syntax-rule (multi-define (var ...) (val ...))
  (begin (define var val) ...))

(multi-define (a b) ((list 1 2) (list 3 4)))

and then you use `a` and `b` as if they were any variables.

What this code does is define a new form, `multi-define`. This new form
expects, first, a sequence of variable names (identifiers) inside
parentheses, then second, a sequence of values to use for their bindings.
Then, this new form *expands* into (that is, creates new code) a series
of definitions (that's what the `...` do. that's actual syntax).

Then, the code uses that new form to define `a` and `b`. Note that the
subforms (like arguments, but for syntactic forms) are just sequences
within parentheses. I.e., they are not list *values*. They exist purely
as syntactic constructs.

Now, what this means is that if you want to *compute* the lists of
variables and values, things get a bit more complicated. You'd need to
do that computation at expansion time. That's absolutely doable, and I'm
happy to discuss it further if that's indeed what you want to do. If so,
I'd recommend you read Greg's guide first, just to get the general idea.


With that said, that was the answer to the question you actually asked.
Now, I'll give you the answer to a slightly different question, whose
answer is simpler, but that may still solve the more general problem
you're having.

Variables are useful because they allow you to use the *name* of
something (e.g., `x`) and get access to its *value* (e.g., `2`, assuming
you had `(define x 2)` somewhere). Now, variables are not the only way
of mapping names (or *keys*) to values. A hash table (i.e., `make-hash`)
gives you that too. You put key-value pairs in the hash table, then
later you can ask for the value that is associated with a certain key.

Of course, they're pros and cons to using variables vs hash tables. So
each of them is appropriate in different contexts. In this case, the
advantage of hash tables that interest you is that they're regular
values, like numbers, or lists. Which means you can create them easily
at runtime, from lists of keys and lists of values (e.g., using
`for/hash`). One disadvantage is that hash tables are just "global"
mappings (i.e., a key will map to one value, no matter what), whereas
variables can have scope, shadowing, etc. This may or may not matter in
your case. Finally, more of a surface difference, you can get the value
of a variable just by writing its name down (e.g., `x`). With a hash
table, you need to get the value explicitly (e.g., `(hash-ref my-table x))`.

In any case, I'd recommend you look into whether hash tables may be able
to solve your problem before diving too deep into macros. Both are
useful, of course, but I'd recommend using the simplest tool that will
do the job, and hash tables are simpler than macros.


> (i have 2 exams this week in order to be accepted into the second year,
> that's why i have gone 

[racket-users] Re: [ANN] New package: live-free-or-die

2016-09-25 Thread Linh Chi Nguyen
let its spirit live on,
for jay's big heart ^^

On Thursday, 22 September 2016 04:33:32 UTC+2, Jay McCarthy  wrote:
> I've just put a new package on the server: live-free-or-die
> 
> This package lets you escape from Typed Racket's contracts.
> 
> --
> 
> Here's a little example:
> 
> Suppose that "server.rkt" is:
> 
> ```
> #lang typed/racket
> 
> (: f ((Listof Float) -> Float))
> (define (f l)
>   (cond
> [(empty? l)
>  0.0]
> [else
>  (+ (first l)
> (f (rest l)))]))
> 
> (provide f)
> ```
> 
> And that "client.rkt" is:
> 
> ```
> #lang racket/base
> (require live-free-or-die)
> (live-free-or-die!)
> 
> (require "server.rkt")
> (f (vector 1 2 3))
> ```
> 
> Then this is what you get when you run the program:
> 
> $ racket "client.rkt"
> zsh: segmentation fault  racket "client.rkt"
> 
> For your convenience, `live-free-or-die!` is also aliased to
> `Doctor-Tobin-Hochstadt:Tear-down-this-wall!`
> 
> --
> 
> Enjoy!
> 
> -- 
> Jay McCarthy
> Associate Professor
> PLT @ CS @ UMass Lowell
> http://jeapostrophe.github.io
> 
>"Wherefore, be not weary in well-doing,
>   for ye are laying the foundation of a great work.
> And out of small things proceedeth that which is great."
>   - D&C 64:33

-- 
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.


[racket-users] post racketcon '16: simulation of population playing PD game in Racket

2016-09-25 Thread Linh Chi Nguyen
Hello everyone,
So I thank again Matthias for the opportunity and everyone for the incredible 
hospitality.

I write down the script of my presentation, add notes, add the extra parts 
(that i said i didnt have time to show), link to code parts on github, and 
append a final part to answer Ben's question: why it drops? (turns out he is 
asking a bigger question he didnt know)

https://drive.google.com/file/d/0B-ReBF4UIaa9NlU4aUhjd3FISkU/view?usp=sharing

for other concerns, as i said, this project continues and is a very long way to 
go. so for now, with the help of Vincent and Jay :) i would continue to work 
and update github repo:

https://github.com/ayaderaghul/fsm-pd2

i dont know any way better to do this, so i write notes in slides and export 
them to pdf. if you know a better way so that the content can be read easier, 
please do tell me.

cheers,
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] lazy vs strict, raco vs racket

2016-01-27 Thread chi

Oh thank you so much for your answer.
It helps a lot,
good day,
chi

On 27/01/2016 13:29, Jay McCarthy wrote:

On Wed, Jan 27, 2016 at 3:26 AM, Linh Chi Nguyen
 wrote:

Hello, so i have this racket code to run simulation, and I can run it on sorta 
a cluster (the lab utilises the computer classroom at night and turns it into a 
cluster - as they call it).

The thing is when i run on the cluster, it doesn't accept any kind of GUI, so i have to switch from 
(require plot) into (require plot/no-gui), even if i don't use any "plot" in the process. 
I mean i just print out some data and the "plot" function (though appear in the code 
script) isn't used at all. This error doesn't happen when i run on my laptop.

Does that mean that when i run the code on laptop, it's a lazy evaluation, and 
on the cluster, it's a strict evaluation?

No, lazy vs strict is not what is going on.

When you `(require X)` then the code at the top-level of X is run. So
if the module were something like

```
(module X racket/base (printf "Hi!\n"))
```

then just doing the `require` will cause `printf` to run and display something.

When you run `(require plot)` it eventually does a `(require
racket/gui)` which has a line that is something like
`(initialize-the-GUI-system!)` at the top-level. You can't run that
line without, for instance X11, so it would fail. But `(require
plot/no-gui)` makes sure to never require something with that at the
top-level.


Second point, what is raco vs racket? For example, when this line "racket -t file.rkt" is 
used, it runs the main module inside the file. And when this line "raco test -s test-name 
file.rkt" it runs a test module inside the file.

However, the former line will print out data in the current directory, the 
latter print out data in the code script directory (if these two directories 
are different). So why is that?

`racket` is the binary for the virtual machine that can load Racket
programs and run them.

`raco` is a particular Racket program that has a bunch of sub-commands
implementing tools inside for Racket. If you run `raco --help` it will
give a list of all the sub-commands. On my machine, I get this list:

```
Usage: raco   ...  ...

Frequently used commands:
   docs search and view documentation
   make compile source to bytecode
   setupinstall and build libraries and documentation
   pkg  manage packages
   planet   manage Planet package installations
   covera code coverage tool
   exe  create executable
   test run tests associated with files/directories

All available commands:
   check-requires   check for useless requires
   contract-profile profile overhead from contracts
   covera code coverage tool
   ctoolcompile and link C-based extensions
   decompiledecompile bytecode
   demodularize produce a whole program from a single module
   dependencies-graph   opens a GUI window showing transitive module
dependencies (aka `Module Browser')
   distribute   prepare executable(s) in a directory for distribution
   docs search and view documentation
   exe  create executable
   expand   macro-expand source
   fc   change directory to given collection's location
   link manage library-collection directories
   make compile source to bytecode
   pack pack files/collections into a .plt archive
   pkg  manage packages
   planet   manage Planet package installations
   profile  profile execution time
   puresuri run a puresuri slideshow
   read read and pretty-print source
   scribble render a Scribble document
   setupinstall and build libraries and documentation
   show-dependenciesshow module dependencies
   test run tests associated with files/directories
   unpack   unpack files/collections from a .plt archive

A command can be specified by an unambiguous prefix.
See `raco help ' for help on a command.
```

You can think of `raco` as a Racket-specific set of executables
similar to /bin, /usr/bin, /usr/local/bin, etc but where all the
commands are implemented in Racket and are managed by the Racket
environment.

The particular command that you mention, `raco test`, is a program for
running Racket programs and seeing if they have tests and if those
tests are successful.

Jay


 From a non-programmer perspective,
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 o

[racket-users] lazy vs strict, raco vs racket

2016-01-27 Thread Linh Chi Nguyen
Hello, so i have this racket code to run simulation, and I can run it on sorta 
a cluster (the lab utilises the computer classroom at night and turns it into a 
cluster - as they call it).

The thing is when i run on the cluster, it doesn't accept any kind of GUI, so i 
have to switch from (require plot) into (require plot/no-gui), even if i don't 
use any "plot" in the process. I mean i just print out some data and the "plot" 
function (though appear in the code script) isn't used at all. This error 
doesn't happen when i run on my laptop.

Does that mean that when i run the code on laptop, it's a lazy evaluation, and 
on the cluster, it's a strict evaluation?

Second point, what is raco vs racket? For example, when this line "racket -t 
file.rkt" is used, it runs the main module inside the file. And when this line 
"raco test -s test-name file.rkt" it runs a test module inside the file.

However, the former line will print out data in the current directory, the 
latter print out data in the code script directory (if these two directories 
are different). So why is that? 

>From a non-programmer perspective,
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] 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 process is a lottery that gives automaton a 5/16 
probability to be chosen, 0 for automaton b, 1/2 for automaton c, 3/16 
for automaton d.


In practice, option 1: this process is usually been done by drawing a 
unit line, marking intervals with different lengths:


+-++---+---+

then you throw a ball randomly in this line, if we see it landing in the 
interval with length 3/16, automaton a is chosen. Bigger interval means 
better chance of being chosen and it can proliferate over time (counted 
by cycles).


Or option 2: we can mark each point on the line associating with an 
automaton (however the line is continuous, hence it has infinite points) 
at random order. In this marking process, we just need to be sure about 
one thing: the number of points for automaton a has to sum up to 5/16 ~ 
25% length of the whole line, the number of points for automaton c has 
to sum up to 50% the length of the line


-> it's better to put all the points for the same automaton next to each 
other so they form a continuous interval (like in option1).


In coding, it's similar. The (random) function throws a ball, and gives 
a point but the computer doesnt simply see which automaton the point 
belongs to.


So we accumulate the payoff according to the order of the automata in 
the population. It's called a cumulative function.

F(a) = p(a) = 5/16
F(b) = p(a) + p(b) = 5/16
...
F(d) = p(a) + p(b) + p(c) + p(d) = 1

so the actual payoff of b will be F(b) - F(a) and so on..
(We can accumulate from the left or from the right).

And now the computer can compare r = (random) with the end point of each 
interval, then it knows what automaton interval the point belongs to.


(I dont know who do this first, it's like every person who starts to do 
evolution simulation will ask this question, and a person who already 
did this practice will tell them, and so on...)




On 14/10/2015 16:42, Matthias Felleisen wrote:


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)
(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


No, it is bad programming practice to add a sentinel in one function
that is used by another function. The locations are too far apart,
because programmers reason about function-sized pieces when they
approach code. (I did, I refactored, and I got the failure).

When you code, keep in mind that you write this code for other
people (possibly your older self in six months from now when you
revise the program) and it accidentally runs on a computer.



Here is how I rewrote your function and added a test:

;; -
;; [Vectorof Automaton] N -> [Listof Automaton]
;; (randomise-over-fitness v n) spawn a list of n fittest automata

;; Nguyen Linh Chi says:
;; This procedure uses an independent Bernoulli draw. We independently
;; draw a random number (associated with an automaton) for 10 times. How
;; likely an automaton is chosen depends on its own fitness (its interval
;; in the unit scale of the accumulated percentages.)

(module+ test
   (define p0 (vector (automaton 0 1 't1)  (automaton 0 90 't1)))
   (define p1 (list (automaton 0 90 't1)))
   ;; this test case fails if (random) picks a number < .01
   (check-equal?
(randomise-over-fitness p0 1) (list (automaton 0 90 't1

(define (randomise-over-fitness population0 speed)
   (define fitness (payoff-percentages population0))
   ;; (= (length fitness) (length population))
   ;; fitness is sorted and the last number is ~1.0
   (define population (vector->list population0))
   (for/list ([n (in-range speed)])
 [define r (random)]
 (define last (for/last ([p population] [f fitness] #:final (< r f)) p))
 (or last (error 'randomise "the unlikely happened: r = ~e is too large" 
r

the for/last combined with #:final brings across this intention.

The way I have written it, the code also points out that,
at least in principle, the world of floating point numbers
allows for a failure to find a fit enough automaton in this
list. (Yes, it is a very small chance.)

***

QUESTION: why do you accumulate fitness across different automata?
That is, why does payoff-percentages add the payoff of automata_i
to automata_{i+1}? I understand that this means the last automata
will h

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

2015-10-13 Thread Linh Chi Nguyen
oh if you dont like adding 0.
maybe you can use the keyword #:final instead of #:break

(they say it does just one more iteration before breaking the loop)

On Wednesday, 14 October 2015  05:53:03 UTC+2, Linh Chi Nguyen  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)
> >> (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 wrote:
> > 
> >> 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?)
> >> 

-- 
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] help on coding finite state automata

2015-10-13 Thread Nguyen Linh Chi
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)
>> (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  
> wrote:
> 
>> 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  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  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)))
>>>>&

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  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  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

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).
>>> 
>

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 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 insert it in 
the (match-population ...). doesnt it deserve to be outside?

- why you use [i (in-range 10)] in all for loop? what's the difference with [i 
10]. they both produce stream, right?



On Tuesday, 13 October 2015 01:46:04 UTC+2, Matthias Felleisen  wrote:
> 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.) 
> 
>

-- 
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] 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 accumulated-payoff-percentage population speed)
  (for/list ([n (in-range speed)])
[define r (random)] ;; SHOULDN"T THIS LINE BE OUTSIDE OF THE for/list 
COMPREHENSION?
(for/and ([p (in-list population)][a (in-list 
accumulated-payoff-percentage)]
  #:break (< r a))
  p)))
```

The randomly generated r has to be inside the for/list loop. Because if it's 
outside, then there is only one random number generated at the beginning, and 
the newly spawn automata will keep being the same one repeatedly.

For example, when the learning speed is s = 10, it means that, 10 old automata 
should be replaced with 10 new ones. And the replacement should be done in 10 
different places in the population.

This procedure is called an independent bernoulli draw. We independently draw a 
random number (associated with an automaton) for 10 times. How likely an 
automaton is chosen depends on its own fitness (its interval in the unit scale 
of the accumulated percentages.)

On Monday, 12 October 2015 03:46:05 UTC+2, Matthias Felleisen  wrote:
> I have pushed some more cleanups, more speed. 
> I added another question to the “spawning” procedure. 
> 
> 
> 
>

-- 
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] 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 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] running racket command line, load mode works but module mode doesnt

2015-10-11 Thread Linh Chi Nguyen
Dear Daniel, 
I have blindly tried and so far these two things work for me:

1.
Add this to the end of the file (maybe module* main #f...)
```
(module+ main
   (hello)
   )
```
and then "racket -t foo.rkt" prints "Hello, world!".

2. 
If you want to use "-e" (e.g. for testing) you need more bindings from
racket. You could require "racket" with -l:

$ racket -t foo.rkt -l racket -e '(hello)'

Thank you so so much Daniel,
Best,
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] running racket command line, load mode works but module mode doesnt

2015-10-11 Thread Linh Chi Nguyen
Dear Daniel, 
thank you for your answer, I have a sample code that I describe the same 
problem here in this thread (the last post of mine, you dont need to read the 
whole thread) including what command in which nested module I want to call:

https://groups.google.com/forum/?hl=en-GB#!topic/racket-users/4o1goSwrLHA

About namespace and binding stuff, I'm completely lost (I'm an economics 
student).
=.=~


On Sunday, 11 October 2015 11:54:58 UTC+2, daniel  wrote:
> Hi,
> 
> I try to help and hope I do not mess things up. I found those start up 
> things a bit tricky as well.
> 
> The main question is: What is available when you want to eval with the 
> -e option? (more technically: what bindings does your current namespace 
> provide at that point?)
> 
> The concept of namespaces is explained here: 
> http://docs.racket-lang.org/guide/eval.html?q=namespace#%28tech._namespace%29
> 
> When you use the "-e" switch Racket requires racket/init. And 
> racket/init provides all bindings from racket (plus some more from 
> racket/enter and racket/help):
> 
> ```
> (provide (all-from-out racket
> racket/enter
> racket/help))
> ```
> 
> That's described at http://docs.racket-lang.org/guide/racket.html and in 
> more detail in the reference at 
> http://docs.racket-lang.org/reference/running-sa.html#%28part._init-actions%29
> 
> If you use the "-f" switch to "load" a file you get a top-level 
> environment like in interaction mode with all the bindings from "racket".
> 
> 
> But if you use module loading with -t (or other module loading switches) 
> that is simply not the case. Then the top-level environment contains no 
> bindings (not even the binding for function calls).
> 
> 
> Given a file foo.rkt
> 
> ```
> #lang racket
> 
> (provide hello)
> 
> (define (hello)
>(display "Hello, world!\n"))
> ```
> 
> even this call fails:
> 
> $ racket -t foo.rkt -e '(+ 1 2)'
> 
> (That's because not even the function calls are provided.)
> 
> There are several ways to get your module "running":
> 
> 
> You could provide a submodule `main` in your which is evaluated when 
> your module is required by the racket executable:
> 
> Add
> ```
> (module+ main
>(hello)
>)
> ```
> 
> and then "racket -t foo.rkt" prints "Hello, world!".
> 
> 
> If you want to use "-e" (e.g. for testing) you need more bindings from 
> racket. You could require "racket" with -l:
> 
> $ racket -t foo.rkt -l racket -e '(hello)'
> 
> 
> Or your module could provide the bindings from racket. Then you could 
> add something like
> 
> ```
> (provide (all-from-out racket)
> ```
> 
> in the foo.rkt module.
> 
> 
> To sum up: When using interactive or load mode you get the bindings from 
> racket, racket/init at the top-level environment. But if you use module 
> mode your top-level environment is empty in the beginning.
> 
> 
> Kind regards,
> Daniel
> 
> 
> Am 10.10.2015 um 20:29 schrieb Linh Chi Nguyen:
> > Hi everyone,
> > The situation is that I have a racket file with the same code but 2 
> > version, one in module and one in load mode.
> >
> > ```
> > hi.rkt is in load mode
> > ```
> >
> > ```
> > bye.rkt is the same code but in module mode
> >
> > #lang racket
> > (provide run-some-commands)
> >
> > ```
> >
> > Both work just fine if I use a REPL.
> >
> > The load mode:
> > ```
> > ~@laptop$ racket
> > Welcome to Racket v6
> >> (load "hi.rkt")
> >> (run-some-commands x y z)
> > ...
> > ```
> >
> > Or as a module
> > ```
> > ~@laptop$ racket
> > Welcome to Racket v6
> >> (require "bye.rkt")
> >> (run-some-commands x y z)
> > ...
> > ```
> >
> > Now the problem is when I want to run the command without loading a REPL. I 
> > follow this doc (http://docs.racket-lang.org/guide/racket.html), it works 
> > just fine if i use the load mode:
> >
> > ```
> > ~@laptop$ racket -f hi.rkt -e '(run-some-commands x y z)'
> > ```
> >
> > However, if i use the module mode, it says nothing, sometimes it says 
> > bye.rkt is undefined.
> >
> > ```
> > ~@laptop$ racket bye.rkt -e '(run-some-commands x y z)'
> > ```
> >
> > I'm very confused because Racket recommends to use module instead of load 
> > mode.
> >
> > Any help?
> >
> > Thank you,
> > 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] 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 between the number of the states and the number of actions for 
each state. Now the automaton is less readable but more simple.

I also add some test that can be run with 
```
~laptop$ raco test fsm0.rkt
```

However I dont know to run this code without a repl.
Because the whole file fsm0.rkt is a module and it has many nested modules 
inside, and the command i need is in the nested one. There is a special module 
that has this command:

```
(module* main #f
(run))
```

So if i want to run a trial of the file, i open a repl:

```
~laptop$ racket
> (require (submod "fsm0.rkt" tv))
> (run)
```
and it runs and plot the result.

I dont want to open a repl. How to run the command right in the terminal 
(Because later on i want to run the command with arguments in the terminal)? 
for example, I've tried this but it doesnt work:

```
~laptop$ racket fsm0.rkt '(require (submod "fsm0.rkt" tv))' '(run)'
```

Thank you,
Chi




On Sunday, 11 October 2015 09:24:07 UTC+2, Linh Chi Nguyen  wrote:
> 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 (randomise-over-fitness accum-fitness population speed)]
> 
> The point of the simulation is that it "ressurect" already available 
> automata, regarding their fitness. Hence who has higher fitness gets more 
> offspring and grows in size gradually (at the expense of the poor doers).
> 
> What is not right here is the word "ressurect" and it catches your intuition.
> 
> I'm not a native English speaker and they are complaining that I should get a 
> native English speaker to proofread my paper. Sorry for that :)
> 
> On Sunday, 11 October 2015 05:07:02 UTC+2, Matthias Felleisen  wrote:
> > I forked, Racket-ized, and gained some speed (~2x). 
> > 
> >

-- 
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] 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 (randomise-over-fitness accum-fitness population speed)]

The point of the simulation is that it "ressurect" already available automata, 
regarding their fitness. Hence who has higher fitness gets more offspring and 
grows in size gradually (at the expense of the poor doers).

What is not right here is the word "ressurect" and it catches your intuition.

I'm not a native English speaker and they are complaining that I should get a 
native English speaker to proofread my paper. Sorry for that :)

On Sunday, 11 October 2015 05:07:02 UTC+2, Matthias Felleisen  wrote:
> I forked, Racket-ized, and gained some speed (~2x). 
> 
> 

-- 
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.


[racket-users] running racket command line, load mode works but module mode doesnt

2015-10-10 Thread Linh Chi Nguyen
Hi everyone,
The situation is that I have a racket file with the same code but 2 version, 
one in module and one in load mode.

```
hi.rkt is in load mode
```

```
bye.rkt is the same code but in module mode

#lang racket
(provide run-some-commands)

```

Both work just fine if I use a REPL. 

The load mode:
```
~@laptop$ racket
Welcome to Racket v6
> (load "hi.rkt")
> (run-some-commands x y z)
...
```

Or as a module
```
~@laptop$ racket
Welcome to Racket v6
> (require "bye.rkt")
> (run-some-commands x y z)
...
```

Now the problem is when I want to run the command without loading a REPL. I 
follow this doc (http://docs.racket-lang.org/guide/racket.html), it works just 
fine if i use the load mode:

```
~@laptop$ racket -f hi.rkt -e '(run-some-commands x y z)'
```

However, if i use the module mode, it says nothing, sometimes it says bye.rkt 
is undefined.

```
~@laptop$ racket bye.rkt -e '(run-some-commands x y z)'
```

I'm very confused because Racket recommends to use module instead of load mode.

Any help?

Thank you,
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-06 Thread Nguyen Linh Chi
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. (no
mutation yet). here on my github just fyi:

https://github.com/ayaderaghul/sample-fsm

Btw, the blogger suggests that because the automaton only needs to know the
current-state, if the population scales big, we just need to separate the
current-state as a single atom outside the machine itself (for better
performance).

I hope this may helps make the thread more complete.


On 4 September 2015 at 20:50,  wrote:

> On Friday, September 4, 2015 at 9:31:36 AM UTC-4, Michael Myers wrote:
> > 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're a bit fragile, so use at your own risk.
>
> Sorry for the duplicate, this was sent yesterday, and only arived just now.
>
> --
> 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.
>



-- 
*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] 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 
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 :
>
>> 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.


[racket-users] help on coding finite state automata

2015-09-03 Thread Linh Chi Nguyen
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.