Forums > MaxMSP

Weighted Average of n Floats

April 14, 2008 | 3:03 pm

I’d like to compute a weighted average of an arbitrary number of
floats. "lave" from L Objects and the other averaging objects to be
found on MaxObjects will only compute an unweighted 1:1:… average as
far as I can tell.


Morgan Sutherland


April 14, 2008 | 3:07 pm

Where are the floats coming from? Could you send a bang each time you get a float, then use counter to count each time you get a float, and continually add the floats, then when you need to find the average, just divide the sum by counter?


April 14, 2008 | 3:22 pm

Do you meen a histogram? Counting how many times a particular number
occurs?

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

> From: Myrddin_Wyllt
> Organization: Cycling ’74
> Reply-To:
> Date: Mon, 14 Apr 2008 09:07:21 -0600
> To:

> Subject: [maxmsp] Re: Weighted Average of n Floats
>
>
> Where are the floats coming from? Could you send a bang each time you get a
> float, then use counter to count each time you get a float, and continually
> add the floats, then when you need to find the average, just divide the sum by
> counter?


April 14, 2008 | 3:25 pm

Could you describe this approach in a little more detail? I think I
see what you’re getting at…

On Mon, Apr 14, 2008 at 11:07 AM, Myrddin_Wyllt
wrote:
>
> Where are the floats coming from? Could you send a bang each time you get a float, then use counter to count each time you get a float, and continually add the floats, then when you need to find the average, just divide the sum by counter?
>


Morgan Sutherland


April 14, 2008 | 3:28 pm

Could you describe this approach in a little more detail? I think I
see what you’re getting at…

On Mon, Apr 14, 2008 at 11:07 AM, Myrddin_Wyllt
wrote:
>
> Where are the floats coming from? Could you send a bang each time you get a float, then use counter to count each time you get a float, and continually add the floats, then when you need to find the average, just divide the sum by counter?
>


Morgan Sutherland


April 14, 2008 | 3:32 pm

jb.histo located with maxobjects.com in

http://www.greyfade.com/joe/max_msp.html

Total time search to download < 2:00

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

> From: Myrddin_Wyllt
> Organization: Cycling ’74
> Reply-To:
> Date: Mon, 14 Apr 2008 09:07:21 -0600
> To:

> Subject: [maxmsp] Re: Weighted Average of n Floats
>
>
> Where are the floats coming from? Could you send a bang each time you get a
> float, then use counter to count each time you get a float, and continually
> add the floats, then when you need to find the average, just divide the sum by
> counter?


April 14, 2008 | 3:32 pm

No, I need the mean/average of a number of floats (over any time
interval), but I want to weight certain floats that are averaged (like
how grades are computing…you know, 50% final exam, 25% problem sets
etc.)

On Mon, Apr 14, 2008 at 11:22 AM, Gary Lee Nelson
wrote:
> Do you meen a histogram? Counting how many times a particular number
> occurs?
>
> Cheers
> Gary Lee Nelson
> Oberlin College
> http://www.timara.oberlin.edu/GaryLeeNelson
>
>
> > From: Myrddin_Wyllt
> > Organization: Cycling ’74
> > Reply-To:
> > Date: Mon, 14 Apr 2008 09:07:21 -0600
> > To:

> > Subject: [maxmsp] Re: Weighted Average of n Floats
>
>
> >
> >
> > Where are the floats coming from? Could you send a bang each time you get a
> > float, then use counter to count each time you get a float, and continually
> > add the floats, then when you need to find the average, just divide the sum by
> > counter?
>
>
>


Morgan Sutherland


April 14, 2008 | 3:52 pm

Sorry, I don’t understand how a histogram can achieve what I’m looking
for. I need to be able to set the weights myself and I need one float
value at the end, the average. Is the idea that I can use the
histogram to set the weights? If so, I’m not quite sure how I’d do
this…

On Mon, Apr 14, 2008 at 11:32 AM, Gary Lee Nelson
wrote:
> jb.histo located with maxobjects.com in
> http://www.greyfade.com/joe/max_msp.html
>
> Total time search to download < 2:00
>
>
> Cheers
> Gary Lee Nelson
> Oberlin College
> http://www.timara.oberlin.edu/GaryLeeNelson
>
>
> > From: Myrddin_Wyllt
> > Organization: Cycling ’74
> > Reply-To:
> > Date: Mon, 14 Apr 2008 09:07:21 -0600
> > To:

> > Subject: [maxmsp] Re: Weighted Average of n Floats
> >
> >
>
>
> > Where are the floats coming from? Could you send a bang each time you get a
> > float, then use counter to count each time you get a float, and continually
> > add the floats, then when you need to find the average, just divide the sum by
> > counter?
>
>
>


Morgan Sutherland


April 14, 2008 | 4:04 pm

Quote: Morgan Sutherland wrote on Mon, 14 April 2008 09:03
—————————————————-
> I’d like to compute a weighted average of an arbitrary number of
> floats.

??

#P window setfont "Sans Serif" 12.;
#P window linecount 1;
#P comment 217 67 79 196620 weighting;
#P flonum 203 42 60 12 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 119 42 60 12 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 119 343 60 12 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 203 184 42 196620 !- 1.;
#P newex 203 118 36 196620 t f f;
#P newex 119 120 37 196620 t b f;
#P newex 174 237 39 196620 * 0.9;
#P newex 119 268 65 196620 + 0.;
#P newex 119 238 48 196620 * 0.1;
#P newex 119 208 37 196620 f;
#P comment 131 68 50 196620 data;
#P connect 9 0 5 0;
#P connect 10 0 6 0;
#P connect 3 0 8 0;
#P fasten 3 0 4 0 124 298 222 298 222 225 179 225;
#P connect 7 0 4 1;
#P fasten 6 1 2 1 234 171 162 171;
#P connect 6 0 7 0;
#P connect 5 0 1 0;
#P connect 5 1 1 1;
#P connect 1 0 2 0;
#P connect 2 0 3 0;
#P connect 4 0 3 1;
#P window clipboard copycount 12;


April 14, 2008 | 4:45 pm

Gregory,

Your patch computes an average for sure, but I’m not entirely sure how
the weighting works. If I change it to anything but zero, the output
quickly approaches infinity. I also don’t know how I’d scale it to
handle multiple inputs and multiple weights.

On Mon, Apr 14, 2008 at 12:04 PM, Gregory Taylor wrote:
>
> Quote: Morgan Sutherland wrote on Mon, 14 April 2008 09:03
> —————————————————-
>
> > I’d like to compute a weighted average of an arbitrary number of
> > floats.
>
> ??
>
> #P window setfont "Sans Serif" 12.;
> #P window linecount 1;
> #P comment 217 67 79 196620 weighting;
> #P flonum 203 42 60 12 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 119 42 60 12 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 119 343 60 12 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 203 184 42 196620 !- 1.;
> #P newex 203 118 36 196620 t f f;
> #P newex 119 120 37 196620 t b f;
> #P newex 174 237 39 196620 * 0.9;
> #P newex 119 268 65 196620 + 0.;
> #P newex 119 238 48 196620 * 0.1;
> #P newex 119 208 37 196620 f;
> #P comment 131 68 50 196620 data;
> #P connect 9 0 5 0;
> #P connect 10 0 6 0;
> #P connect 3 0 8 0;
> #P fasten 3 0 4 0 124 298 222 298 222 225 179 225;
> #P connect 7 0 4 1;
> #P fasten 6 1 2 1 234 171 162 171;
> #P connect 6 0 7 0;
> #P connect 5 0 1 0;
> #P connect 5 1 1 1;
> #P connect 1 0 2 0;
> #P connect 2 0 3 0;
> #P connect 4 0 3 1;
> #P window clipboard copycount 12;
>
> –
> knowledge is not enough/science is not enough/Love is dreaming this equation
>
>
>


Morgan Sutherland


April 14, 2008 | 7:47 pm

perhaps have averaging subpatches, then in your main average patch, multiple the numbers according to hwo muc hthey need to be weighted (ie, if its 35% of the total, multiply the number by .35), then add all of the outputs together.

to get the individual averages of the different floats, take whatever object is outputting the floats, connect it to a patch that will output a bang everytime a float is received (I would post a patch like this, but im at a computer currently w/o Max), say a "sel > 0" object (tho im not sure if you can have > or < in sel, but you get the idea); connect the sel object to a counter to keep track of the number of floats received. Also connect the object outputting the floats to an object to continually add them together (a '+' object, w/ the float outputting object in the right inlet and the number box in the left). Then divide that total by the counter's number.

Don’t know if this is what you’re looking for. sorry i cant post a patch. Ill be home later today and if you haven’t found a solution by then, ill try to work it out.


April 14, 2008 | 8:49 pm

"perhaps have averaging subpatches, then in your main average patch,
multiple the numbers according to hwo muc hthey need to be weighted
(ie, if its 35% of the total, multiply the number by .35), then add
all of the outputs together."

Ah! So simple. No need for you to try it yourself unless you want to.
I’ll post an abstraction when I have time.

Thanks Myrddin and everybody else.

On Mon, Apr 14, 2008 at 3:47 PM, Myrddin_Wyllt
wrote:
>
> perhaps have averaging subpatches, then in your main average patch, multiple the numbers according to hwo muc hthey need to be weighted (ie, if its 35% of the total, multiply the number by .35), then add all of the outputs together.
>
> to get the individual averages of the different floats, take whatever object is outputting the floats, connect it to a patch that will output a bang everytime a float is received (I would post a patch like this, but im at a computer currently w/o Max), say a "sel > 0" object (tho im not sure if you can have > or < in sel, but you get the idea); connect the sel object to a counter to keep track of the number of floats received. Also connect the object outputting the floats to an object to continually add them together (a '+' object, w/ the float outputting object in the right inlet and the number box in the left). Then divide that total by the counter's number.
>
> Don’t know if this is what you’re looking for. sorry i cant post a patch. Ill be home later today and if you haven’t found a solution by then, ill try to work it out.
>
>
>


Morgan Sutherland


April 15, 2008 | 1:11 am

a setting in the right hand box of .5 does a straight
average. feed it a set of random numbers and tack a
multislider in scroll mode on the bottom and see if
it doesn’t make more sense.


April 15, 2008 | 8:37 am

I’d use something like this, no need to scale weights:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 146 100 29 196617 t f b;
#P newex 170 124 27 196617 f;
#P message 90 178 14 196617 0;
#P comment 69 208 74 196617 weighted total;
#P comment 187 40 53 196617 weighting;
#P newex 146 261 32 196617 print;
#P newex 146 208 27 196617 f;
#P newex 146 178 27 196617 + 0.;
#P newex 146 236 27 196617 / 0.;
#P newex 187 208 27 196617 f;
#P newex 187 178 27 196617 + 0.;
#P newex 146 151 29 196617 * 0.;
#P flonum 187 66 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 146 66 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 146 40 29 196617 data;
#P comment 219 208 64 196617 total weight;
#P comment 80 160 34 196617 reset;
#P connect 16 0 5 0;
#P connect 3 0 16 0;
#P connect 16 1 15 0;
#P connect 15 0 5 1;
#P connect 15 0 6 0;
#P connect 4 0 15 1;
#P connect 10 0 8 0;
#P connect 10 0 9 1;
#P connect 7 0 8 1;
#P connect 7 0 6 1;
#P fasten 14 0 10 0 95 200 151 200;
#P fasten 14 0 7 0 95 200 192 200;
#P connect 6 0 7 0;
#P connect 8 0 11 0;
#P connect 9 0 10 0;
#P connect 5 0 9 0;
#P window clipboard copycount 17;


December 3, 2009 | 2:58 am

I ended up using this finally (8 elements max):

– Pasted Max Patch, click to expand. –

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