Forums > MaxMSP

weighted random a la SC "[1,2,4].wchoose([0.5,0.3,0.1]);" in Max



kjg
February 16, 2008 | 10:02 pm

Hello,

What would be the simplest way to implement a weighted random in Max, comparable to the following line of SuperCollider code?

[1,2,4].wchoose([0.5,0.3,0.1]);

The line results in a value of 1, 2 or 3, where the weighting is:
1 five times more often than 4, and 2 three times more often than 4.

In SC the values for the weighting don’t have to add up to one, they are automatically normalized. They just have to be smaller than 1.

I am aware of the possibilities of the [table] object, but am looking for something a bit cleaner, that can use floats et cetera. Ideally an object that would take two lists (values/weightings) and output a value when banged.

Any thoughts would be appreciated.

Regards,
Klaas-Jan


f
February 16, 2008 | 11:18 pm

good example of where syntax shines and patching gets ugly.
(although you’re wrong about the auto normalisation – that’d be
[1,2,4].wchoose([0.5,0.3,0.1].normalizeSum); to be really picky)
simplest i don’t know, but one way to do it would be with chained
[split] or [if] statements. of course this would mean to hardcode
the number of elements in the lists. arbitrary length is a bit more
complicated. perhaps there’s already a Lobject for it – or you could
code something fairly easily in javascript/java.

max v2;
#N vpatcher 10 59 396 417;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 20 257 38 196617 zl mth;
#P newex 244 56 40 196617 / 100.;
#P flonum 244 28 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 203 57 40 196617 / 100.;
#P flonum 203 29 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 257 189 100 196617 4 – 20%;
#P comment 257 174 100 196617 2 – 30%;
#P newex 105 234 21 196617 t 2;
#P newex 91 216 21 196617 t 1;
#P newex 121 133 60 196617 split 50 79;
#P newex 77 105 54 196617 split 0 49;
#P newex 77 81 64 196617 random 101;
#P newex 77 198 21 196617 t 0;
#P comment 257 159 100 196617 1 – 50%;
#P newex 162 58 40 196617 / 100.;
#P flonum 162 30 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 20 288 32 196617 print;
#P message 60 21 34 196617 1 2 4;
#P newex 60 38 27 196617 t l b;
#P connect 0 0 18 0;
#P connect 18 0 2 0;
#P connect 11 0 18 1;
#P connect 10 0 18 1;
#P connect 6 0 18 1;
#P connect 1 0 0 0;
#P connect 0 1 7 0;
#P connect 7 0 8 0;
#P connect 8 0 6 0;
#P connect 9 0 10 0;
#P connect 9 1 11 0;
#P connect 4 0 8 2;
#P connect 8 1 9 0;
#P connect 15 0 9 1;
#P connect 3 0 4 0;
#P connect 17 0 9 2;
#P connect 14 0 15 0;
#P connect 16 0 17 0;
#P pop;

_f

Am 16.02.2008 um 23:02 schrieb Klaas-Jan Govaart:

>
> Hello,
>
> What would be the simplest way to implement a weighted random in
> Max, comparable to the following line of SuperCollider code?
>
> [1,2,4].wchoose([0.5,0.3,0.1]);
>
> The line results in a value of 1, 2 or 3, where the weighting is:
> 1 five times more often than 4, and 2 three times more often than 4.
>
> In SC the values for the weighting don’t have to add up to one,
> they are automatically normalized. They just have to be smaller
> than 1.
>
> I am aware of the possibilities of the [table] object, but am
> looking for something a bit cleaner, that can use floats et cetera.
> Ideally an object that would take two lists (values/weightings) and
> output a value when banged.
>
> Any thoughts would be appreciated.
>
> Regards,
> Klaas-Jan

#|
fredrikolofsson.com klippav.org musicalfieldsforever.com
|#


kjg
February 16, 2008 | 11:58 pm

Quote: f wrote on Sun, 17 February 2008 00:18
—————————————————-
> good example of where syntax shines and patching gets ugly.

yes, isn’t it. Wouldn’t it be great to have an object like expr in which you could dump a line of SC code in cases like this?

SCexpr is on my wishlist for Max 5.1 ;)

> (although you’re wrong about the auto normalisation – that’d be
> [1,2,4].wchoose([0.5,0.3,0.1].normalizeSum); to be really picky)

Oops! Of course, you are right. I just remembered it was very easy, but of course not "autocomplete_my_thought mode = 1" easy.

> simplest i don’t know, but one way to do it would be with chained
> [split] or [if] statements. of course this would mean to hardcode
> the number of elements in the lists. arbitrary length is a bit more
> complicated. perhaps there’s already a Lobject for it – or you could
> code something fairly easily in javascript/java.

Thanks for the example, but this is already getting "uglier" than I was hoping for.
Especially the hardcoded length of the list I don’t like. Could be scripted I guess, but it would be hardly elegant.

Thanks again!
Klaas-Jan

February 17, 2008 | 1:05 am

Use quantile function with table object

#P button 278 92 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 278 118 40 196617 t clear;
#P button 35 53 15 0;
#P newex 35 146 44 196617 uzi 100;
#N vtable 128 983 297 1193 464 990001 128 histogram;
#P newobj 180 256 80 196617 table histogram;
#P newex 180 232 81 196617 histo;
#P newex 133 147 55 196617 zl group 2;
#P newex 133 119 99 196617 t l clear;
#P number 133 232 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 91 146 15 0;
#P message 133 94 61 196617 1 5 2 3 4 1;
#N vtable 128 20 74 230 241 1 128 weights;
#P newobj 133 192 70 196617 table weights;
#P comment 329 119 100 196617 clear histogram;
#P window linecount 3;
#P comment 270 257 100 196617 < - table shows a histogram of 100 choices;
#P window linecount 4;
#P comment 155 34 100 196617 value/weight pairs in a list. weights must be
integers for table;
#P window linecount 2;
#P comment 7 192 121 196617 weights store at location corresponding to
value;
#P window linecount 3;
#P comment 47 88 82 196617 100 bangs for table quantil function;
#P connect 14 0 13 0;
#P fasten 14 0 6 0 40 81 138 81;
#P fasten 15 0 11 0 283 221 185 221;
#P fasten 15 0 12 0 283 251 185 251;
#P connect 5 0 8 0;
#P fasten 5 0 11 0 138 220 185 220;
#P connect 16 0 15 0;
#P fasten 13 0 5 0 40 182 138 182;
#P connect 11 0 12 0;
#P connect 11 1 12 1;
#P fasten 7 0 5 0 96 178 138 178;
#P fasten 9 1 5 0 227 178 138 178;
#P connect 10 0 5 0;
#P connect 6 0 9 0;
#P connect 9 0 10 0;
#P window clipboard copycount 17;

On 2/16/08 5:02 PM, "Klaas-Jan Govaart" wrote:

>
> Hello,
>
> What would be the simplest way to implement a weighted random in Max,
> comparable to the following line of SuperCollider code?
>
> [1,2,4].wchoose([0.5,0.3,0.1]);
>
> The line results in a value of 1, 2 or 3, where the weighting is:
> 1 five times more often than 4, and 2 three times more often than 4.
>
> In SC the values for the weighting don’t have to add up to one, they are
> automatically normalized. They just have to be smaller than 1.
>
> I am aware of the possibilities of the [table] object, but am looking for
> something a bit cleaner, that can use floats et cetera. Ideally an object that
> would take two lists (values/weightings) and output a value when banged.
>
> Any thoughts would be appreciated.
>
> Regards,
> Klaas-Jan
>
>
>
>

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson

February 17, 2008 | 1:20 am

Weights smaller than 1. & two lists

#P button 133 35 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 212 69 43 196617 0.5 0.3 0.1;
#P message 133 69 34 196617 1 2 4;
#P newex 133 92 89 196617 mxj list.Multiplex;
#P newex 193 249 117 196617 expr .5+$f1*1000000.;
#P newex 133 206 70 196617 unpack 0 0.;
#P button 321 222 15 0;
#P newex 321 248 40 196617 t clear;
#P button 35 31 15 0;
#P newex 35 146 44 196617 uzi 100;
#N vtable 128 983 297 1230 721 990001 128 histogram;
#P newobj 180 339 80 196617 table histogram;
#P newex 180 315 81 196617 histo;
#P newex 133 147 55 196617 zl group 2;
#P newex 133 119 99 196617 t l clear;
#P number 133 315 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 91 146 15 0;
#N vtable 128 20 74 230 241 0 128 weights;
#P newobj 133 275 70 196617 table weights;
#P comment 366 250 100 196617 clear histogram;
#P window linecount 3;
#P comment 270 340 100 196617 < - table shows a histogram of 100 choices;
#P window linecount 2;
#P comment 7 275 121 196617 weights store at location corresponding to
value;
#P window linecount 3;
#P comment 47 88 82 196617 100 bangs for table quantil function;
#P connect 20 0 18 0;
#P connect 20 0 19 0;
#P connect 17 0 7 0;
#P connect 18 0 17 0;
#P connect 19 0 17 1;
#P connect 12 0 11 0;
#P connect 8 0 15 0;
#P connect 15 0 4 0;
#P connect 16 0 4 1;
#P connect 15 1 16 0;
#P fasten 13 0 9 0 326 301 185 301;
#P fasten 13 0 10 0 326 334 185 334;
#P connect 4 0 6 0;
#P fasten 4 0 9 0 138 303 185 303;
#P connect 14 0 13 0;
#P connect 9 1 10 1;
#P connect 9 0 10 0;
#P fasten 11 0 4 0 40 266 138 266;
#P fasten 5 0 4 0 96 260 138 260;
#P fasten 7 1 4 0 227 233 138 233;
#P connect 7 0 8 0;
#P window clipboard copycount 21;

On 2/16/08 5:02 PM, "Klaas-Jan Govaart" wrote:

>
> Hello,
>
> What would be the simplest way to implement a weighted random in Max,
> comparable to the following line of SuperCollider code?
>
> [1,2,4].wchoose([0.5,0.3,0.1]);
>
> The line results in a value of 1, 2 or 3, where the weighting is:
> 1 five times more often than 4, and 2 three times more often than 4.
>
> In SC the values for the weighting don’t have to add up to one, they are
> automatically normalized. They just have to be smaller than 1.
>
> I am aware of the possibilities of the [table] object, but am looking for
> something a bit cleaner, that can use floats et cetera. Ideally an object that
> would take two lists (values/weightings) and output a value when banged.
>
> Any thoughts would be appreciated.
>
> Regards,
> Klaas-Jan
>
>
>
>

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson


kjg
February 17, 2008 | 5:12 am

Thank you for your input Gary, but I’m still looking for something other than table though. It just can’t be use with floats, really.
In this patch I tried inputting some floats, trying to get them back out with only two decimal points of resolution. Quickly hitting the table limit of 16383 though, of course..

Any thoughts on what I could use besides table?

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 143 426 32 196617 print;
#P newex 143 403 41 196617 * 0.01;
#P button 143 52 15 0;
#P newex 143 137 101 196617 vexpr int($f1*100);
#P message 222 157 67 196617 0.5 0.3 0.1;
#P message 143 119 151 196617 21.234501 432.345612 7654.566895;
#P newex 143 180 89 196617 mxj list.Multiplex;
#P newex 203 337 117 196617 expr .5+$f1*1000000.;
#P newex 143 294 70 196617 unpack 0 0.;
#P button 45 119 15 0;
#P newex 45 234 44 196617 uzi 100;
#P newex 143 235 55 196617 zl group 2;
#P newex 143 207 99 196617 t l clear;
#P button 101 234 15 0;
#N vtable 16383 20 74 230 241 1 100000 weights;
#P newobj 143 363 70 196617 table weights;
#P window linecount 2;
#P comment 17 363 121 196617 weights store at location corresponding to value;
#P window linecount 3;
#P comment 57 176 82 196617 100 bangs for table quantil function;
#P connect 7 0 6 0;
#P connect 14 0 11 0;
#P connect 11 0 13 0;
#P fasten 13 0 10 0 148 156;
#P connect 10 0 4 0;
#P connect 4 0 5 0;
#P connect 5 0 8 0;
#P fasten 6 0 2 0 50 354 148 354;
#P fasten 3 0 2 0 106 348 148 348;
#P fasten 4 1 2 0 237 321 148 321;
#P connect 8 0 2 0;
#P connect 2 0 15 0;
#P connect 15 0 16 0;
#P connect 8 1 9 0;
#P connect 9 0 2 1;
#P connect 14 0 12 0;
#P connect 12 0 10 1;

February 17, 2008 | 5:46 am

here is one where you can change the weights automatically

save this one as flux in patches
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 316 84 14 196617 2;
#P newex 254 57 105 196617 sel 1 2 3;
#P newex 285 84 30 196617 t 1 0;
#P newex 254 84 30 196617 t 1 1;
#P newex 125 320 58 196617 split 0 126;
#P newex 62 239 22 196617 b 1;
#P newex 102 60 55 196617 clip 3 128;
#P newex 182 58 55 196617 clip 3 128;
#P newex 58 89 22 196617 b 1;
#N vtable 1 381 64 591 231 979704 128;
#P newobj 102 115 30 196617 table;
#P message 102 92 41 196617 size $1;
#P newex 0 56 27 196617 i $1;
#N comlet Do it;
#P inlet 58 35 15 0;
#P newex 0 35 45 196617 loadbang;
#P newex 30 56 27 196617 i $2;
#P comment 52 21 25 196617 do it;
#P newex 117 426 29 196617 pack;
#P message 117 451 63 196617 select $1 $2;
#N comlet update;
#P outlet 117 475 15 0;
#N comlet table;
#P outlet 77 475 15 0;
#P newex 133 181 27 196617 i;
#N comlet size 3-127;
#P inlet 102 35 15 0;
#P comment 97 21 25 196617 size;
#N comlet 0-off 1-fall 2-rebound 3-grow;
#P inlet 254 35 15 0;
#P comment 254 21 33 196617 mode;
#P comment 182 21 33 196617 range;
#P comment 150 21 25 196617 data;
#P newex 182 78 27 196617 – 1;
#N comlet range 3-127;
#P inlet 182 35 15 0;
#N comlet data;
#P inlet 154 35 15 0;
#P newex 144 390 27 196617 + 1;
#P newex 144 297 38 196617 % 127;
#P message 530 321 14 196617 2;
#P message 359 321 14 196617 3;
#P newex 385 296 155 196617 if $i1 < 2 then out2 bang else $i1;
#P newex 385 321 27 196617 – 1;
#P newex 184 321 27 196617 + 1;
#P newex 184 296 165 196617 if $i1 > $i2 then out2 bang else $i1;
#P newex 144 266 105 196617 gate 3;
#N funbuff 0;
#P newobj 239 241 50 196617 funbuff;
#P newex 62 264 27 196617 i;
#P newex 292 261 21 196617 + 1;
#P connect 7 1 21 0;
#P connect 7 1 9 0;
#P connect 7 0 6 0;
#P connect 3 2 7 0;
#P connect 4 1 21 0;
#P connect 4 1 8 0;
#P connect 14 0 4 1;
#P connect 40 2 41 0;
#P connect 21 0 2 0;
#P connect 21 0 0 0;
#P connect 40 1 39 0;
#P connect 40 0 38 0;
#P connect 18 0 40 0;
#P connect 2 0 3 1;
#P connect 12 0 32 0;
#P connect 12 0 2 0;
#P connect 4 0 5 0;
#P connect 3 1 4 0;
#P connect 34 0 10 1;
#P connect 34 0 14 0;
#P connect 13 0 34 0;
#P connect 27 0 34 0;
#P connect 38 1 37 1;
#P connect 39 1 37 1;
#P connect 37 0 11 0;
#P connect 3 0 10 0;
#P connect 38 0 3 0;
#P connect 39 0 3 0;
#P connect 8 0 3 0;
#P connect 9 0 3 0;
#P connect 40 3 3 0;
#P connect 41 0 3 0;
#P connect 11 0 36 0;
#P connect 11 0 25 1;
#P connect 6 0 25 1;
#P connect 5 0 36 0;
#P connect 5 0 25 1;
#P connect 32 0 22 0;
#P connect 32 0 21 0;
#P connect 10 0 37 0;
#P connect 24 0 23 0;
#P connect 25 0 24 0;
#P connect 1 0 25 0;
#P connect 33 0 32 0;
#P connect 31 0 32 0;
#P connect 30 0 31 0;
#P connect 35 0 31 0;
#P connect 20 0 35 0;
#P connect 0 0 1 1;
#P connect 36 0 1 0;
#P connect 6 0 36 0;
#P connect 29 0 33 0;
#P connect 28 0 27 0;
#P connect 28 0 30 0;
#P window clipboard copycount 42;

flux help window:
#P user hint 58 183 87 195 "maximum value for fluctuation" 1000 100 0 65535 65535 52428 9 3 0 1 0 0 0;
#P user hint 43 163 79 177 "update probabilities" 1000 100 0 65535 65535 52428 9 3 0 1 0 0 0;
#P user hint 31 144 60 158 "size – elements in the table" 1000 100 0 65535 65535 52428 9 3 0 1 0 0 0;
#P user hint 36 125 69 140 "metronome period" 1000 100 0 65535 65535 52428 9 3 0 1 0 0 0;
#P user hint 21 125 36 140 "toggle metronome on/off" 1000 100 0 65535 65535 52428 9 3 0 1 0 0 0;
#P user hint 14 105 29 121 "do it once" 1000 100 0 65535 65535 52428 9 3 0 1 0 0 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P hidden message 57 48 26 196617 100;
#P number 36 124 34 9 10 0 8293 3 132 0 123 221 221 221 222 222 222 0 0 0;
#P hidden newex -75 282 75 196617 expr 127 – $i1;
#P hidden newex -75 315 53 196617 send pitch;
#P comment 124 209 203 196617 grow – increment probility when picked.;
#P comment 136 253 233 196617 Toggle on minimum/maximum.;
#P comment 124 242 253 196617 rebound – increment/decrement probility when picked.;
#P comment 135 230 245 196617 Value jumps to minimum when it hits maximum.;
#P comment 124 220 233 196617 fall – increment probility when picked.;
#P comment 124 198 233 196617 noflux – off;
#P hidden message 30 48 26 196617 127;
#P hidden message 3 48 26 196617 128;
#P hidden newex 3 21 45 196617 loadbang;
#P button 15 106 15 0;
#P comment 78 286 176 196617 update chosen element;
#N vpatcher 40 55 440 355;
#N comlet data out;
#P outlet 13 138 15 0;
#N comlet data in;
#P inlet 13 53 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 13 79 1665 196617 unpack 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
#P newex 13 109 1665 196617 funnel 128;
#P comment 48 51 179 196617 translate multislider to table;
#P connect 3 0 2 0;
#P connect 2 0 1 0;
#P connect 1 0 4 0;
#P connect 2 1 1 1;
#P connect 2 2 1 2;
#P connect 2 3 1 3;
#P connect 2 4 1 4;
#P connect 2 5 1 5;
#P connect 2 6 1 6;
#P connect 2 7 1 7;
#P connect 2 8 1 8;
#P connect 2 9 1 9;
#P connect 2 10 1 10;
#P connect 2 11 1 11;
#P connect 2 12 1 12;
#P connect 2 13 1 13;
#P connect 2 14 1 14;
#P connect 2 15 1 15;
#P connect 2 16 1 16;
#P connect 2 17 1 17;
#P connect 2 18 1 18;
#P connect 2 19 1 19;
#P connect 2 20 1 20;
#P connect 2 21 1 21;
#P connect 2 22 1 22;
#P connect 2 23 1 23;
#P connect 2 24 1 24;
#P connect 2 25 1 25;
#P connect 2 26 1 26;
#P connect 2 27 1 27;
#P connect 2 28 1 28;
#P connect 2 29 1 29;
#P connect 2 30 1 30;
#P connect 2 31 1 31;
#P connect 2 32 1 32;
#P connect 2 33 1 33;
#P connect 2 34 1 34;
#P connect 2 35 1 35;
#P connect 2 36 1 36;
#P connect 2 37 1 37;
#P connect 2 38 1 38;
#P connect 2 39 1 39;
#P connect 2 40 1 40;
#P connect 2 41 1 41;
#P connect 2 42 1 42;
#P connect 2 43 1 43;
#P connect 2 44 1 44;
#P connect 2 45 1 45;
#P connect 2 46 1 46;
#P connect 2 47 1 47;
#P connect 2 48 1 48;
#P connect 2 49 1 49;
#P connect 2 50 1 50;
#P connect 2 51 1 51;
#P connect 2 52 1 52;
#P connect 2 53 1 53;
#P connect 2 54 1 54;
#P connect 2 55 1 55;
#P connect 2 56 1 56;
#P connect 2 57 1 57;
#P connect 2 58 1 58;
#P connect 2 59 1 59;
#P connect 2 60 1 60;
#P connect 2 61 1 61;
#P connect 2 62 1 62;
#P connect 2 63 1 63;
#P connect 2 64 1 64;
#P connect 2 65 1 65;
#P connect 2 66 1 66;
#P connect 2 67 1 67;
#P connect 2 68 1 68;
#P connect 2 69 1 69;
#P connect 2 70 1 70;
#P connect 2 71 1 71;
#P connect 2 72 1 72;
#P connect 2 73 1 73;
#P connect 2 74 1 74;
#P connect 2 75 1 75;
#P connect 2 76 1 76;
#P connect 2 77 1 77;
#P connect 2 78 1 78;
#P connect 2 79 1 79;
#P connect 2 80 1 80;
#P connect 2 81 1 81;
#P connect 2 82 1 82;
#P connect 2 83 1 83;
#P connect 2 84 1 84;
#P connect 2 85 1 85;
#P connect 2 86 1 86;
#P connect 2 87 1 87;
#P connect 2 88 1 88;
#P connect 2 89 1 89;
#P connect 2 90 1 90;
#P connect 2 91 1 91;
#P connect 2 92 1 92;
#P connect 2 93 1 93;
#P connect 2 94 1 94;
#P connect 2 95 1 95;
#P connect 2 96 1 96;
#P connect 2 97 1 97;
#P connect 2 98 1 98;
#P connect 2 99 1 99;
#P connect 2 100 1 100;
#P connect 2 101 1 101;
#P connect 2 102 1 102;
#P connect 2 103 1 103;
#P connect 2 104 1 104;
#P connect 2 105 1 105;
#P connect 2 106 1 106;
#P connect 2 107 1 107;
#P connect 2 108 1 108;
#P connect 2 109 1 109;
#P connect 2 110 1 110;
#P connect 2 111 1 111;
#P connect 2 112 1 112;
#P connect 2 113 1 113;
#P connect 2 114 1 114;
#P connect 2 115 1 115;
#P connect 2 116 1 116;
#P connect 2 117 1 117;
#P connect 2 118 1 118;
#P connect 2 119 1 119;
#P connect 2 120 1 120;
#P connect 2 121 1 121;
#P connect 2 122 1 122;
#P connect 2 123 1 123;
#P connect 2 124 1 124;
#P connect 2 125 1 125;
#P connect 2 126 1 126;
#P connect 2 127 1 127;
#P pop;
#P newobj 43 162 35 196617 p data;
#B color 5;
#P hidden newex -70 164 55 196617 metro 100;
#P toggle 22 124 15 0;
#P number 57 181 29 9 0 127 8295 3 132 0 123 221 221 221 222 222 222 0 0 0;
#P newex 15 265 68 196617 flux 128 127;
#B color 5;
#P number 15 297 34 9 0 127 12391 3 132 0 123 221 221 221 222 222 222 0 0 0;
#P number 29 144 34 9 0 0 8293 3 132 0 123 221 221 221 222 222 222 0 0 0;
#P comment 82 267 180 196617 arguments: size , range;
#P comment 49 299 284 196617 current pick (quantile);
#P comment 12 91 291 196617 probability fluctuation for quantile (see MAX Reference Guide);
#P window linecount 2;
#P comment 14 325 246 196617 LoneMonad http://faculty.roosevelt.edu/malone/default.htm;
#P user hint 388 94 536 231 "click in this area to set some probabilites" 1000 100 0 65535 65535 52428 9 3 0 1 0 0 0;
#P user multiSlider 391 97 140 128 0. 127. 128 2920 0 0 0 2 0 0 1;
#M frgb 132 0 123;
#M brgb 239 125 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user hint 72 199 123 215 "flux mode" 1000 100 0 65535 65535 52428 9 3 0 1 0 0 0;
#P user umenu 71 198 52 151191595 1 96 215 0;
#X setrgb 239 125 255 164 2 146 239 125 255 239 125 255 255 0 255 239 125 255 255 90 203;
#X add no flux;
#X add grow;
#X add fall;
#X add rebound;
#P user hint 165 298 337 313 "click here to load fm3synth1~.help" 1000 100 0 65535 65535 52428 9 3 0 1 0 0 0;
#P user panel 384 91 155 144;
#X brgb 239 125 255;
#X frgb 15 0 18;
#X border 0;
#X rounded 20;
#X shadow 4;
#X done;
#P background;
#P user panel 9 86 373 236;
#X brgb 239 125 255;
#X frgb 15 0 18;
#X border 0;
#X rounded 20;
#X shadow 4;
#X done;
#P background;
#P user panel 1 77 545 280;
#X brgb 132 0 123;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 4;
#X done;
#P noclick;
#P background;
#P fasten 14 1 6 0 78 295 378 295 378 90 396 90;
#P lcolor 6;
#P connect 4 0 14 4;
#P lcolor 6;
#P connect 15 0 14 3;
#P lcolor 6;
#P hidden connect 23 0 15 0;
#P hidden connect 21 0 22 0;
#P hidden connect 21 0 23 0;
#P hidden connect 21 0 33 0;
#P connect 18 0 14 2;
#P lcolor 6;
#P fasten 6 0 18 0 396 287 381 287 381 159 48 159;
#P lcolor 6;
#P hidden connect 33 0 32 0;
#P connect 12 0 14 1;
#P lcolor 6;
#P hidden connect 22 0 12 0;
#P hidden connect 31 0 30 0;
#P hidden connect 31 0 13 0;
#P connect 20 0 14 0;
#P lcolor 6;
#P hidden connect 17 0 14 0;
#P hidden connect 32 0 17 1;
#P hidden connect 16 0 17 0;
#P hidden connect 14 0 31 0;
#P window clipboard copycount 40;

February 17, 2008 | 3:13 pm

Sorry for the misunderstanding. Your original message seemed to indicate
that you were selecting only from ints.

Try this urn-like algorithm.

Build a list that has n copies of each value where n represents the weight.
1 5 2 3 4 1 would become 1 1 1 1 1 2 2 2 4
Scramble that list to something like 1 2 1 2 2 1 1 4
Cycle through the scrambled list taking and removing each item in turn.
When the list is empty, refill it and scramble again.

On 2/17/08 12:12 AM, "Klaas-Jan Govaart" wrote:

>
> Thank you for your input Gary, but I’m still looking for something other than
> table though. It just can’t be use with floats, really.
> In this patch I tried inputting some floats, trying to get them back out with
> only two decimal points of resolution. Quickly hitting the table limit of
> 16383 though, of course..
>
> Any thoughts on what I could use besides table?
>
> #P window setfont "Sans Serif" 9.;
> #P window linecount 1;
> #P newex 143 426 32 196617 print;
> #P newex 143 403 41 196617 * 0.01;
> #P button 143 52 15 0;
> #P newex 143 137 101 196617 vexpr int($f1*100);
> #P message 222 157 67 196617 0.5 0.3 0.1;
> #P message 143 119 151 196617 21.234501 432.345612 7654.566895;
> #P newex 143 180 89 196617 mxj list.Multiplex;
> #P newex 203 337 117 196617 expr .5+$f1*1000000.;
> #P newex 143 294 70 196617 unpack 0 0.;
> #P button 45 119 15 0;
> #P newex 45 234 44 196617 uzi 100;
> #P newex 143 235 55 196617 zl group 2;
> #P newex 143 207 99 196617 t l clear;
> #P button 101 234 15 0;
> #N vtable 16383 20 74 230 241 1 100000 weights;
> #P newobj 143 363 70 196617 table weights;
> #P window linecount 2;
> #P comment 17 363 121 196617 weights store at location corresponding to value;
> #P window linecount 3;
> #P comment 57 176 82 196617 100 bangs for table quantil function;
> #P connect 7 0 6 0;
> #P connect 14 0 11 0;
> #P connect 11 0 13 0;
> #P fasten 13 0 10 0 148 156;
> #P connect 10 0 4 0;
> #P connect 4 0 5 0;
> #P connect 5 0 8 0;
> #P fasten 6 0 2 0 50 354 148 354;
> #P fasten 3 0 2 0 106 348 148 348;
> #P fasten 4 1 2 0 237 321 148 321;
> #P connect 8 0 2 0;
> #P connect 2 0 15 0;
> #P connect 15 0 16 0;
> #P connect 8 1 9 0;
> #P connect 9 0 2 1;
> #P connect 14 0 12 0;
> #P connect 12 0 10 1;

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson


f
February 17, 2008 | 4:38 pm

basic javascript solution…

///////save as wchoose.js

// /f0 080217

//weights should add up to one for it to function properly
//both lists (weights and values) should be equal in length

inlets= 2;
setinletassist(0, "bang, list");
setinletassist(1, "weights");
setoutletassist(0, "the chosen one");
var wlist= new Array(); //weights
var vlist= new Array(); //values

function list() {
if(inlet==0) {
vlist= arguments;
} else {
wlist= arguments;
}
}
function bang() {
var i, sum= 0;
var r= Math.random();
for(i= 0; i
sum= sum+wlist[i];
if(r
outlet(0, vlist[i]);
i= vlist.length;
}
}
}

///////test patch

max v2;
#N vpatcher 389 169 783 540;
#P window setfont "Sans Serif" 9.;
#P message 234 138 37 196617 10 20;
#P message 272 138 43 196617 0.1 0.9;
#P button 275 114 15 0;
#P message 142 95 67 196617 10 20 30 40;
#P message 210 95 91 196617 0.6 0.3 0.05 0.05;
#P button 183 71 15 0;
#P message 50 52 52 196617 10 20 30;
#P newex 119 270 72 196617 js wchoose.js;
#P message 139 231 44 196617 compile;
#P newex 119 299 32 196617 print;
#P message 103 52 61 196617 0.6 0.3 0.1;
#P button 82 254 15 0;
#P button 91 28 15 0;
#P comment 169 35 95 196617 values and weights;
#P comment 98 252 152 196617 pick random value with weights;
#P connect 2 0 8 0;
#P connect 2 0 4 0;
#P connect 14 0 7 0;
#P connect 11 0 7 0;
#P connect 3 0 7 0;
#P connect 8 0 7 0;
#P fasten 6 0 7 0 130 269;
#P connect 7 0 5 0;
#P connect 9 0 11 0;
#P connect 13 0 7 1;
#P connect 10 0 7 1;
#P connect 4 0 7 1;
#P connect 9 0 10 0;
#P connect 12 0 14 0;
#P connect 12 0 13 0;
#P pop;

Am 17.02.2008 um 16:13 schrieb Gary Lee Nelson:

> Sorry for the misunderstanding. Your original message seemed to
> indicate
> that you were selecting only from ints.
>
> Try this urn-like algorithm.
>
> Build a list that has n copies of each value where n represents the
> weight.
> 1 5 2 3 4 1 would become 1 1 1 1 1 2 2 2 4
> Scramble that list to something like 1 2 1 2 2 1 1 4
> Cycle through the scrambled list taking and removing each item in
> turn.
> When the list is empty, refill it and scramble again.
>
>
> On 2/17/08 12:12 AM, "Klaas-Jan Govaart" wrote:
>
>>
>> Thank you for your input Gary, but I’m still looking for something
>> other than
>> table though. It just can’t be use with floats, really.
>> In this patch I tried inputting some floats, trying to get them
>> back out with
>> only two decimal points of resolution. Quickly hitting the table
>> limit of
>> 16383 though, of course..
>>
>> Any thoughts on what I could use besides table?
>>
>> #P window setfont "Sans Serif" 9.;
>> #P window linecount 1;
>> #P newex 143 426 32 196617 print;
>> #P newex 143 403 41 196617 * 0.01;
>> #P button 143 52 15 0;
>> #P newex 143 137 101 196617 vexpr int($f1*100);
>> #P message 222 157 67 196617 0.5 0.3 0.1;
>> #P message 143 119 151 196617 21.234501 432.345612 7654.566895;
>> #P newex 143 180 89 196617 mxj list.Multiplex;
>> #P newex 203 337 117 196617 expr .5+$f1*1000000.;
>> #P newex 143 294 70 196617 unpack 0 0.;
>> #P button 45 119 15 0;
>> #P newex 45 234 44 196617 uzi 100;
>> #P newex 143 235 55 196617 zl group 2;
>> #P newex 143 207 99 196617 t l clear;
>> #P button 101 234 15 0;
>> #N vtable 16383 20 74 230 241 1 100000 weights;
>> #P newobj 143 363 70 196617 table weights;
>> #P window linecount 2;
>> #P comment 17 363 121 196617 weights store at location
>> corresponding to value;
>> #P window linecount 3;
>> #P comment 57 176 82 196617 100 bangs for table quantil function;
>> #P connect 7 0 6 0;
>> #P connect 14 0 11 0;
>> #P connect 11 0 13 0;
>> #P fasten 13 0 10 0 148 156;
>> #P connect 10 0 4 0;
>> #P connect 4 0 5 0;
>> #P connect 5 0 8 0;
>> #P fasten 6 0 2 0 50 354 148 354;
>> #P fasten 3 0 2 0 106 348 148 348;
>> #P fasten 4 1 2 0 237 321 148 321;
>> #P connect 8 0 2 0;
>> #P connect 2 0 15 0;
>> #P connect 15 0 16 0;
>> #P connect 8 1 9 0;
>> #P connect 9 0 2 1;
>> #P connect 14 0 12 0;
>> #P connect 12 0 10 1;
>
>
> Cheers
> Gary Lee Nelson
> Oberlin College
> http://www.timara.oberlin.edu/GaryLeeNelson
>
>
>

#|
fredrikolofsson.com klippav.org musicalfieldsforever.com
|#

February 17, 2008 | 5:35 pm

February 18, 2008 | 9:22 pm

Does wchoose.js do the job for you?

On 2/17/08 12:12 AM, "Klaas-Jan Govaart" wrote:

> Thank you for your input Gary, but I’m still looking for something other than
> table though. It just can’t be use with floats, really.
> In this patch I tried inputting some floats, trying to get them back out with
> only two decimal points of resolution. Quickly hitting the table limit of
> 16383 though, of course..

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson


kjg
February 19, 2008 | 2:29 am

Quote: Gary Lee Nelson wrote on Mon, 18 February 2008 22:22
—————————————————-
> Does wchoose.js do the job for you?
>

Thank you for your help Gary, and you too, Fredrik.

The scripts are looking good – definitely seems like the way to go in this case. Unfortunately, it’s not working yet. js spits out a few syntax error messages and I haven’t had any time really to go into it.
I should have some time later this week to find and eradicate these gremlins so I will report back then.

Regards,
Klaas-Jan

February 19, 2008 | 1:36 pm

Mine is working fine as is Frederik’s original java version. One problem I
have had occasionally is that my mailer breaks up long lines of text. This
can create errors when you paste the text into mxj.

On 2/18/08 9:29 PM, "Klaas-Jan Govaart" wrote:

>
> Quote: Gary Lee Nelson wrote on Mon, 18 February 2008 22:22
> —————————————————-
>> Does wchoose.js do the job for you?
>>
>
> Thank you for your help Gary, and you too, Fredrik.
>
> The scripts are looking good – definitely seems like the way to go in this
> case. Unfortunately, it’s not working yet. js spits out a few syntax error
> messages and I haven’t had any time really to go into it.
> I should have some time later this week to find and eradicate these gremlins
> so I will report back later.
>
> Regards,
> Klaas-Jan

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson


kjg
February 19, 2008 | 3:48 pm

Quote: Gary Lee Nelson wrote on Tue, 19 February 2008 14:36
—————————————————-
> Mine is working fine as is Frederik’s original java version. One problem I
> have had occasionally is that my mailer breaks up long lines of text. This
> can create errors when you paste the text into mxj.

in that case, it would be great if you could post the .js file as a zipped attachment, so the formatting stays intact.

and when you are referring to [mxj], you mean [js], right?

thank you,
kjg

February 19, 2008 | 4:16 pm

I am trying to test this js code as well. It looks like
some of the lines got truncated. Gary, can you re-paste the
source.

February 19, 2008 | 7:55 pm

Here is again. All the lines are very short. I broke the longer comment
into two lines.

///////save as wchoose.js

// /f0 080217

//both lists (weights and values)
//should be equal in length

inlets= 2;
setinletassist(0, "bang, list");
setinletassist(1, "weights");
setoutletassist(0, "the chosen one");
var wlist= new Array(); //weights
var vlist= new Array(); //values

function list() {
var i, sum= 0;
if(inlet==0) {
vlist= arguments;
} else {
wlist= arguments;
// get sum of all weights
for(i= 0; i
sum= sum+wlist[i];
}
// scale weights to total 1.0
sum= 1.0/sum;
for(i= 0; i
wlist[i]= sum*wlist[i];
}
}
}
function bang() {
var i, sum= 0;
var r= Math.random();
for(i= 0; i
sum= sum+wlist[i];
if(r
outlet(0, vlist[i]);
i= vlist.length;
}
}
}

On 2/19/08 11:16 AM, "Anthony Palomba" wrote:

>
> I am trying to test this js code as well. It looks like
> some of the lines got truncated. Gary, can you re-paste the
> source.

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson


kjg
February 19, 2008 | 8:16 pm

Same errors. Could you go check what’s the difference between what you are emailing and how it actually ends up on the forums?

or just post a zip of the js?

Quote: Gary Lee Nelson wrote on Tue, 19 February 2008 20:55
—————————————————-
> Here is again. All the lines are very short. I broke the longer comment
> into two lines.
>


kjg
February 19, 2008 | 8:20 pm

Quote: kjg wrote on Tue, 19 February 2008 21:16
—————————————————-
> Same errors. Could you go check what’s the difference between what you are emailing and how it actually ends up on the forums?
>
> or just post a zip of the js?
>

actually, you could probably see whats going wrong by looking at this – probably more convenient for you:

///////save as wchoose.js

// /f0 080217

//both lists (weights and values)
//should be equal in length

inlets= 2;
setinletassist(0, "bang, list");
setinletassist(1, "weights");
setoutletassist(0, "the chosen one");
var wlist= new Array(); //weights
var vlist= new Array(); //values

function list() {
var i, sum= 0;
if(inlet==0) {
vlist= arguments;
} else {
wlist= arguments;
// get sum of all weights
for(i= 0; i
sum= sum+wlist[i];
}
// scale weights to total 1.0
sum= 1.0/sum;
for(i= 0; i
wlist[i]= sum*wlist[i];
}
}
}
function bang() {
var i, sum= 0;
var r= Math.random();
for(i= 0; i
sum= sum+wlist[i];
if(r
outlet(0, vlist[i]);
i= vlist.length;
}
}
}

February 19, 2008 | 8:46 pm

That looks like a mailer error.

On 2/19/08 3:20 PM, "Klaas-Jan Govaart" wrote:

>
> Quote: kjg wrote on Tue, 19 February 2008 21:16
> —————————————————-
>> Same errors. Could you go check what’s the difference between what you are
>> emailing and how it actually ends up on the forums?
>>
>> or just post a zip of the js?
>>
>
> actually, you could probably see whats going wrong by looking at this -
> probably more convenient for you:
>
> ///////save as wchoose.js
>
> // /f0 080217
>
> //both lists (weights and values)
> //should be equal in length
>
> inlets= 2;
> setinletassist(0, "bang, list");
> setinletassist(1, "weights");
> setoutletassist(0, "the chosen one");
> var wlist= new Array(); //weights
> var vlist= new Array(); //values
>
> function list() {
> var i, sum= 0;
> if(inlet==0) {
> vlist= arguments;
> } else {
> wlist= arguments;
> // get sum of all weights
> for(i= 0; i
> sum= sum+wlist[i];
> }
> // scale weights to total 1.0
> sum= 1.0/sum;
> for(i= 0; i
> wlist[i]= sum*wlist[i];
> }
> }
> }
> function bang() {
> var i, sum= 0;
> var r= Math.random();
> for(i= 0; i
> sum= sum+wlist[i];
> if(r
> outlet(0, vlist[i]);
> i= vlist.length;
> }
> }
> }

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson


f
February 19, 2008 | 9:06 pm

it’s the forum that eats parts of the code. it thinks those greater/less-than are html tags or something. looks allright on the mailinglist. (another reason to use the list).

here’s gary’s version again but this time posted from the forum and with code tags added. looks ok in the preview at least. sorry for the mess.
_f

[code]

///////save as wchoose.js

// /f0 080217

//weights should add up to one for it to function properly
//both lists (weights and values) should be equal in length

inlets= 2;
setinletassist(0, "bang, list");
setinletassist(1, "weights");
setoutletassist(0, "the chosen one");
var wlist= new Array(); //weights
var vlist= new Array(); //values

function list() {
var i, sum= 0;
if(inlet==0) {
vlist= arguments;
} else {
wlist= arguments;
// get sum of all weights
for(i= 0; i
sum= sum+wlist[i];
}
// scale weights to total 1.0
sum= 1.0/sum;
for(i= 0; i
wlist[i]= sum*wlist[i];
}
}
}
function bang() {
var i, sum= 0;
var r= Math.random();
for(i= 0; i
sum= sum+wlist[i];
if(r
outlet(0, vlist[i]);
i= vlist.length;
}
}
}

[code]

February 19, 2008 | 9:19 pm

Just posted the .zip file for this in the Forum with this subject

weighted random a la SC "[1,2,4].wchoose([0.5,0.3,0.1]) [message #130123]

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson

February 19, 2008 | 9:23 pm

I put a .zip in the forum.

On 2/19/08 4:06 PM, "f" wrote:

>
> it’s the forum that eats parts of the code. it thinks those greater/less-than
> are html tags or something. looks allright on the mailinglist. (another
> reason to use the list).
>
> here’s gary’s version again but this time posted from the forum and with code
> tags added. looks ok in the preview at least. sorry for the mess.
> _f
>
>
> [code]
>
> ///////save as wchoose.js
>
> // /f0 080217
>
> //weights should add up to one for it to function properly
> //both lists (weights and values) should be equal in length
>
> inlets= 2;
> setinletassist(0, "bang, list");
> setinletassist(1, "weights");
> setoutletassist(0, "the chosen one");
> var wlist= new Array(); //weights
> var vlist= new Array(); //values
>
> function list() {
> var i, sum= 0;
> if(inlet==0) {
> vlist= arguments;
> } else {
> wlist= arguments;
> // get sum of all weights
> for(i= 0; i
> sum= sum+wlist[i];
> }
> // scale weights to total 1.0
> sum= 1.0/sum;
> for(i= 0; i
> wlist[i]= sum*wlist[i];
> }
> }
> }
> function bang() {
> var i, sum= 0;
> var r= Math.random();
> for(i= 0; i
> sum= sum+wlist[i];
> if(r
> outlet(0, vlist[i]);
> i= vlist.length;
> }
> }
> }
>
> [code]
>

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson

February 19, 2008 | 9:27 pm

Just posted the .zip file for this in the Forum with this subject

weighted random a la SC "[1,2,4].wchoose([0.5,0.3,0.1]) [message #130123]

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson

February 20, 2008 | 4:54 pm

Actually the simplest way would be with lp.ernie from Litter Power.

The patch below generates the output that follows.

Ernie is part of Litter Pro. I’ll attach a screen shot just so you can see how simple the patch is.

Best,
Peter

—-
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 156 160 33 196617 print;
#P number 156 136 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 156 76 15 0;
#P newex 187 77 118 196617 loadmess set 50 30 10;
#P newex 156 111 55 196617 lp.ernie 3;
#P connect 3 0 4 0;
#P connect 0 0 3 0;
#P fasten 1 0 0 0 192 101 161 101;
#P connect 2 0 0 0;
#P window clipboard copycount 5;

—-

print: 1
print: 0
print: 1
print: 0
print: 0
print: 0
print: 1
print: 1
print: 1
print: 0
print: 1
print: 1
print: 2
print: 0
print: 0
print: 0
print: 0
print: 0
print: 1
print: 0
print: 0
print: 0
print: 1
print: 1
print: 2
print: 2


kjg
February 21, 2008 | 12:55 am

Quote: Peter Castine wrote on Wed, 20 February 2008 17:54
—————————————————-
> Actually the simplest way would be with lp.ernie from Litter Power.

But that would be the same functionality as [table], right Peter?
What about floats?

I should have mentioned it in the subject line, I know. Not just in the message (quoting myself):

"I am aware of the possibilities of the [table] object, but am looking for something a bit cleaner, that can use floats et cetera. Ideally an object that would take two lists (values/weightings) and output a value when banged."

So how about:
[f0,f1 … f100].wchoose([0.5, 0.3 … 0.1].normalizeSum);

Is this possible with litter too? just asking this out of curiosity by the way – the wchoose.js javascript supplied by Fredrik and Gary is doing a great job.

As are the litter pro objects, by the way :)

Thanks in advance.

Regards,
Klaas-Jan

February 21, 2008 | 1:05 pm

This is exactly what wchoose.js does.

On 2/20/08 7:55 PM, "Klaas-Jan Govaart" wrote:

> So how about:
> [f0,f1 … f100].wchoose([0.5, 0.3 … 0.1].normalizeSum);

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson

February 21, 2008 | 1:08 pm

Yes but the interface is much simpler. I use lp.ernie to generate indices
to a list of values that can include floats. The output of lp.ernie goes to
zl mth to make selections from the list.

On 2/20/08 7:55 PM, "Klaas-Jan Govaart" wrote:

> But that would be the same functionality as [table], right Peter?
> What about floats?

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson


kjg
February 21, 2008 | 1:24 pm

Yes I know. But I was asking out of curiosity if weighted random with floats could be done with Litter objects.

regards,
kjg

Quote: Gary Lee Nelson wrote on Thu, 21 February 2008 14:05
—————————————————-
> This is exactly what wchoose.js does.
>
>
> On 2/20/08 7:55 PM, "Klaas-Jan Govaart" wrote:
>
> > So how about:
> > [f0,f1 … f100].wchoose([0.5, 0.3 … 0.1].normalizeSum);
>


kjg
February 21, 2008 | 1:43 pm

Ok, then that would be the way I guess. Send lp.ernie the list of int weights, and use its output to make a selection out of a list of float values.

Thank you!
Klaas-Jan

Quote: Gary Lee Nelson wrote on Thu, 21 February 2008 14:08
—————————————————-
> Yes but the interface is much simpler. I use lp.ernie to generate indices
> to a list of values that can include floats. The output of lp.ernie goes to
> zl mth to make selections from the list.
>
>
> On 2/20/08 7:55 PM, "Klaas-Jan Govaart" wrote:
>
> > But that would be the same functionality as [table], right Peter?
> > What about floats?
>

>
>
—————————————————-

February 21, 2008 | 1:49 pm

Lp.ernie is Litter Pro. Which, btw, means that it supports UB (see the announcement from a week or so ago).

Lp.ernie will support up to 4095 different values, each of which can have a different weight.

To that extent it’s like table. The difference is that it is implementing the urn-with-balls-of-different-colors model (more like urn). The difference to urn is that ernie can have arbitrary numbers of balls of each color. With urn you have exactly one ball of the color ‘zero’, one ball of the color ‘one’, etc.

This sort of thing (and the SC object you originally described, at least as I understood it) are inherently discrete models. Which means integers. If you want to scale integers to discrete float values, that’s up to you, and you’d use lp.scampf or similar for that purpose. But as a rule, for float output you want a continuous model.

It sounds like you’re possibly looking for a triangular distribution model. That would be lp.linnie. (Starter Pack). Check out Wikipedia for nice pictures < http://en.wikipedia.org/wiki/Triangular_distribution>. I really need to find a way to link my help files to Wikipedia, they describe so much of this distribution stuff very nicely.

– P.

February 21, 2008 | 2:53 pm

Thank you for the reply Peter.

I have Litter Pro, and I was curious if there was some functionality in there I didn’t know of yet, like an object that just takes two list, one of states (float or int) and one of weights (float or int), and outputs a weighted choice when banged. I didn’t realize before that it just a choice between discrete states and that you actually have to generate a weighted
index to have the solution, and then use the index to select from the list of ints, floats or symbols.

Thanks for providing me with this insight Peter and Gary.

The wchoose.js script and the lp.ernie + zl mth solution both provide a way to do what I wanted.

Like you said, a discrete model – a random choice out of a list of distinct states:
[1.52, 3.87, 5.26].choose;

This is like urn, except with float "colors" for each ball. The same things could be done with urn combined with zl mth.

Or a weighted random choice:
[1.52, 3.87, 5.26].wchoose([0.05, 0.8, 0.15]);

This could be done with table or with lp.ernie combined with zl mth, provided the weights are converted to ints[vexpr int($f1*100)]?

Or a weighted random choice where the weights don’t add up to one:
[1.52, 3.87, 5.26].wchoose([0.01, 0.5, 0.2].normalizeSum);

The urn like models (table/lp.ernie + zl mth) don’t need the weights to add up to one so again these could be used here too.

The wchoose.js script kindly provided by Fredrik Olofsson and Gary Lee Nelson, can deals with all situations.

February 21, 2008 | 5:32 pm

I think for your floats I would simply send ernie’s output (or table’s) through a coll that looked like

0, 1.52;
1, 3.87;
2, 5.26;

Sorry, of course you have Litter Pro, Klaas-Jan. I didn’t immediately recognize your name from your initials.

BTW, those reading this thread who don’t have Litter Pro may be interested in < http://www.cycling74.com/forums/index.php?t=msg&th=31272&start=0>

February 21, 2008 | 10:25 pm

Quote: Peter Castine wrote on Thu, 21 February 2008 18:32
—————————————————-
> I think for your floats I would simply send ernie’s output (or table’s) through a coll that looked like
>
> 0, 1.52;
> 1, 3.87;
> 2, 5.26;

It has dawned on me now that it is about generating indexes. From there, there’s quite a few ways I guess. Coll makes a lot of sense too, indeed.

Btw, I’m using lp.ppp~ at the moment and I was trying to temporarily stop it by sending it a 0. in its left input. After that, it doesn’t come back on anymore. I have to reinstantiate the object. Is this normal behavior?

It would be great to stop it in some way by sending it a message in its left input. Float zero was what I tried first (zero clicks per second), but a on/off switching behavior using ints 1/0 would be equally good.
For now I just did it with a gate of course.

Anyway, the dying after a float 0 – is that expected behavior?

Regards,
Klaas-Jan

February 22, 2008 | 11:21 am

Interesting quirk. But you don’t need to reinstantiate the object, you just need to wait a while.

You basically have the same effect as when you set metro to an incredibly high value (say 3600000): when you change it back to a quicker value, you still have to wait an hour for the next bang and then the new value takes effect. Lp.ppp~ is similar.

It’s not just zero, if you set density to, say, 0.01 pops/second and then change it to a higher density, the inter-pop time calculated while density was 0.01pps could be 100" (or longer, since the pops have a random distribution).

There are ways to implement a more immediate response when density changes from hyper-sparse to a more normal value, but I’m not sure which would be most appropriate for lp.ppp~. I’m also wary of changing behavior at this point in time.

What exactly were you hoping to achieve with a zero density?

February 22, 2008 | 1:05 pm

i have had this problem with lp.ppp~
does anyone have a workaround?


kjg
February 22, 2008 | 1:11 pm

Quote: Peter Castine wrote on Fri, 22 February 2008 12:21
—————————————————-
> Interesting quirk. But you don’t need to reinstantiate the object, you just need to wait a while.
>
> You basically have the same effect as when you set metro to an incredibly high value (say 3600000): when you change it back to a quicker value, you still have to wait an hour for the next bang and then the new value takes effect. Lp.ppp~ is similar.
>
> It’s not just zero, if you set density to, say, 0.01 pops/second and then change it to a higher density, the inter-pop time calculated while density was 0.01pps could be 100" (or longer, since the pops have a random distribution).

Ah ok, that makes sense. So it is expected behaviour. Thank oyu for explaining.

>
> There are ways to implement a more immediate response when density changes from hyper-sparse to a more normal value, but I’m not sure which would be most appropriate for lp.ppp~. I’m also wary of changing behavior at this point in time.

I’ll use a gate then

>
> What exactly were you hoping to achieve with a zero density?

Quoting myself:
" It would be great to stop it in some way by sending it a message in its left input. Float zero was what I tried first (zero clicks per second), but a on/off switching behavior using ints 1/0 would be equally good."

I was just trying to switch it off.. That sort of works, except that for reason you explained, it might take some time to come back later then.
I’ll just use a gate or multiply the output by zero.

Thank you,
Klaas-Jan

PS: Congratulations on the release of Litter Power UB!

February 22, 2008 | 5:57 pm

Quote: kjg wrote on Fri, 22 February 2008 14:11
—————————————————-
> Quoting myself:
> " It would be great to stop it in some way by sending it a message in its left input. Float zero was what I tried first (zero clicks per second), but a on/off switching behavior using ints 1/0 would be equally good."
—————————————————-

Sorry, I missed the text. It’s been a long thread.

I can understand wanting to use lp.ppp~ this way, although I didn’t originally conceive of the object with your semantics in mind.

I will look into making a change that would allow you to do what you want, and without breaking other uses. But in the meantime you’ll need to use a gate~ or similar approach.

—————————————————-
> PS: Congratulations on the release of Litter Power UB!
—————————————————-

Thank you!

February 24, 2008 | 5:15 pm

Peter Castine schrieb:
> I really need to find a way to link my help files to Wikipedia, they
> describe so much of this distribution stuff very nicely.

That would be great, a message box with ; max_lauchbrowser url should do
it…


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
— _|_)—-|—–()————–
———-()——–www.ccmix.com

Viewing 38 posts - 1 through 38 (of 38 total)

Forums > MaxMSP