dev:questions_ulam
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
dev:questions_ulam [2015/05/30 05:48] – [Q: How to access slot number when using ''WindowServices scan()''?] ackley | dev:questions_ulam [2015/06/01 18:11] (current) – [Q: Do smaller grid geometries make the simulator run faster?] xychen | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Week One ===== | ===== Week One ===== | ||
- | To be copied here | + | ==== Q: The range of Unary ==== |
+ | What is the range for an '' | ||
+ | **A:** To understand the range of an Unary number, we first have to know how it is represented. An Unary(n) number takes n bits. It represents an integer of the number of 1's in it. For example | ||
+ | '' | ||
+ | |||
+ | That explains why the following code will output 1,3 and 7 when the value I expected is only 0,1,2,3. | ||
+ | < | ||
+ | DebugUtils du; | ||
+ | Unary(4) ns; | ||
+ | if(ns==0){ | ||
+ | ns=1; | ||
+ | } | ||
+ | else if(ns==1){ | ||
+ | ns=2; | ||
+ | } | ||
+ | else if(ns==2){ | ||
+ | ns=3; | ||
+ | } | ||
+ | else if(ns==3){ | ||
+ | ns=0; | ||
+ | } | ||
+ | du.printContext(); | ||
+ | </ | ||
+ | |||
+ | ==== Q: More about the bits in Unary ==== | ||
+ | If the value of an myUnary5 is '' | ||
+ | |||
+ | **A: 30-May-2015 02: | ||
===== Week Two ===== | ===== Week Two ===== | ||
Line 19: | Line 46: | ||
**A: 29-May-2015 04: | **A: 29-May-2015 04: | ||
< | < | ||
- | Atom a = ew[slot]; | + | Atom a = ew[index]; |
if (a is Foo) { | if (a is Foo) { | ||
Foo f = (Foo) a; // Note that f is a copy of a! | Foo f = (Foo) a; // Note that f is a copy of a! | ||
Line 54: | Line 81: | ||
if(density> | if(density> | ||
du.print((Int) ws.next()); | du.print((Int) ws.next()); | ||
- | for (Int slot = ws.next(); | + | for (Int idx = ws.next(); |
- | Atom a = ew[slot]; | + | Atom a = ew[idx]; |
if (a is Signal) { | if (a is Signal) { | ||
//compare your density with mine | //compare your density with mine | ||
Line 63: | Line 90: | ||
</ | </ | ||
- | **A: 29-May-2015 06: | + | **A: 29-May-2015 06: |
- | ==== Q: How to access | + | ==== Q: How to access |
- | //Thank you!// I fixed the code. This time I use the for loop on ws.next(). I wanted to use '' | + | //Thank you!// I fixed the code. This time I use the for loop on ws.next(). I wanted to use '' |
< | < | ||
WindowServices ws; | WindowServices ws; | ||
Line 73: | Line 100: | ||
Request r; | Request r; | ||
Int rt=au.getType((Atom) r); | Int rt=au.getType((Atom) r); | ||
- | for(Int | + | for(Int |
- | Atom a= ew[slot]; | + | Atom a= ew[idx]; |
if(a is Request){ | if(a is Request){ | ||
Request you=(Request) a; | Request you=(Request) a; | ||
if(density> | if(density> | ||
if(rdm.oneIn(2)){ | if(rdm.oneIn(2)){ | ||
- | ew.swap(0,slot); | + | ew.swap(0,idx); |
} | } | ||
} | } | ||
Line 86: | Line 113: | ||
</ | </ | ||
- | **A: 29-May-2015 11: | + | **A: 29-May-2015 11: |
< | < | ||
Line 95: | Line 122: | ||
if (ws.scan(rt)) { // Any matches for rt? | if (ws.scan(rt)) { // Any matches for rt? | ||
Atom a = ew[ws.getPick(0)]; | Atom a = ew[ws.getPick(0)]; | ||
- | if(a is Request){ | + | if(a is Request){ |
- | | + | r = (Request) a; |
.. use r.density etc .. | .. use r.density etc .. | ||
} | } | ||
Line 109: | Line 136: | ||
Int rt=au.getType((Atom) r); // Get type of element Request | Int rt=au.getType((Atom) r); // Get type of element Request | ||
if (ws.scan(rt)) { // Any matches for that? | if (ws.scan(rt)) { // Any matches for that? | ||
- | | + | r = (Request) ew[ws.getPick(0)]; |
.. use r.density etc .. | .. use r.density etc .. | ||
} | } | ||
</ | </ | ||
- | because that '' | + | because that particular |
+ | |||
+ | ==== Q: Does ws.getPick(typeIndex) only return one site? How to access each site within an event window? ==== | ||
+ | **Thank you**! Now I understand that '' | ||
+ | |||
+ | **A: 31-May-2015 12: | ||
+ | |||
+ | But even when you do need to loop, we have '' | ||
+ | |||
+ | <code - SSDemo1.ulam> | ||
+ | |||
+ | /** | ||
+ | | ||
+ | */ | ||
+ | |||
+ | element SSDemo1 { | ||
+ | // Typedefs | ||
+ | typedef Unsigned(8) Score; | ||
+ | |||
+ | // Utilities | ||
+ | EventWindow ew; | ||
+ | Random random; | ||
+ | DebugUtils du; | ||
+ | |||
+ | // Data members | ||
+ | Score val; | ||
+ | |||
+ | Void behave() { | ||
+ | if (val == 0) // randomize initial vals | ||
+ | val = random.bits(val.sizeof); | ||
+ | |||
+ | WindowServices ws; // Scanning support | ||
+ | SelectorServices ss; // Selection support | ||
+ | |||
+ | ws.reset(1, | ||
+ | ss.reset(); | ||
+ | |||
+ | for (Int idx = ws.next(); idx >= 0; idx = ws.next()) { | ||
+ | Atom a = ew[idx]; | ||
+ | if (a as SSDemo1) | ||
+ | ss.maximize(idx, | ||
+ | } | ||
+ | // This code is fairly general, but cumbersome. | ||
+ | if (ss.selectionMade()) { | ||
+ | Int sidx = ss.getSelectedKey(); | ||
+ | SSDemo1 f = (SSDemo1) ew[sidx]; // which we know is a SSDemo1 | ||
+ | if (f.val > 0) // ..if they' | ||
+ | val = f.val; | ||
+ | du.printContext(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | <code - SSDemo2.ulam> | ||
+ | |||
+ | /** | ||
+ | | ||
+ | */ | ||
+ | |||
+ | element SSDemo2 { | ||
+ | // Typedefs | ||
+ | typedef Unsigned(8) Score; | ||
+ | |||
+ | // Utilities | ||
+ | EventWindow ew; | ||
+ | Random random; | ||
+ | DebugUtils du; | ||
+ | |||
+ | // Data members | ||
+ | Score val; | ||
+ | |||
+ | Void behave() { | ||
+ | if (val == 0) // randomize initial vals | ||
+ | val = random.bits(val.sizeof); | ||
+ | |||
+ | WindowServices ws; // Scanning support | ||
+ | SelectorServices ss; // Selection support | ||
+ | |||
+ | ws.reset(0, | ||
+ | ss.reset(); | ||
+ | |||
+ | for (Int idx = ws.next(); idx >= 0; idx = ws.next()) { | ||
+ | Atom a = ew[idx]; | ||
+ | if (a as SSDemo2) | ||
+ | ss.maximize((Int) a.val); | ||
+ | } | ||
+ | // We scanned ourselves, so we know ss.selectionMade() will be | ||
+ | // true. So we just take the chosen value (even if it was ours). | ||
+ | val = (Score) ss.getSelectedValue(); | ||
+ | du.printContext(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Q: How to change the size of the MFM simulator? ==== | ||
+ | Sometimes the canvas is too big for my experiment. If I don't want those atoms diffuse too far away, I will draw a box of '' | ||
+ | |||
+ | A: In version 3, the '' | ||
+ | (and even the tile size!) on the command line. | ||
+ | |||
+ | Read the very beginning of the output from 'mfms -h' about geometry. | ||
+ | is specified is has to be the first argument on the command line. | ||
+ | |||
+ | Try something like: | ||
+ | |||
+ | you@linux$ ..path../ | ||
+ | |||
+ | or even | ||
+ | |||
+ | you@linux$ ..path../ | ||
+ | |||
+ | ==== Q: Do smaller grid geometries make the simulator run faster? ==== | ||
+ | |||
+ | **Thank you!** That's better than drawing '' | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | **A: 31-May-2015 01: | ||
+ | |||
+ | On a separate point, note that the "edge of the grid" is somewhat different that a ring of '' | ||
+ | |||
+ | {{: |
dev/questions_ulam.1432964901.txt.gz · Last modified: 2015/05/30 05:48 by ackley