[PD] weighted average (or ?)

Mathieu Bouchard matju at artengine.ca
Wed Jun 16 19:47:48 CEST 2010

On Wed, 16 Jun 2010, João Pais wrote:

> I was going to program something, but wanted to see if someone hasn't 
> done it before. I needed a "weighted average" (probably the name is 
> incorrect, I just made it up), that is: considering an x number of 
> sliders going from 0 to 1, the sum of all sliders would be always 1.

The standard definition of the thing called "weighted average" is quite 
related to that. you compute the average of four numbers x1,x2,x3,x4 using 
four numbers a1,a2,a3,a4 by doing a1*x1 + a2*x2 + a3*x3 + a4*x4. All the a 
variables are nonnegative and they add up to one. In another variation, 
there's no requirement that they add up to one, but they have to add up to 
something else than zero and you divide by a1+a2+a3+a4 at the end to 
normalise the result (as if they added up to one).

Weighted average is also called "convex sum", because you can make all 
possible convex filled polygons with it (and nothing else) if you do it in 
two dimensions.

> In case I drag one slider up or down, the difference in value to the 
> total (1) would be distributed through the other sliders that aren't 
> active.

That requires quite a lot of objects if you don't use any externals.

I'd suggest instead to just have four normal sliders ranging from 0 to 1 
and normalise them by dividing by a1+a2+a3+a4. The only time it won't work 
is when all sliders are at zero. (this is what Tim Vets made for you).

> That itself isn't that hard to do, but then harder would be to consider 
> the previous state when the next change happens. So that a slider that 
> is already higher than the others by the next change would "retain" the 
> average countour.

I don't understand this or perhaps it's not an extra feature and just 
implied by equally distributing the excess and the lack.

> Is there any external/patch for this, or any statistic formula / website 
> I should look at for this?

I think that the difficulty is more in plugging the objects together.

If I had to do it myself, I'd do it using the [#many] abstraction, and I'd 
expect to use [#outer != (0 1 2 3)], [#fold +], [# *], [# -], [# /], 
[norecurse], and some more. With that, it'd take a lot fewer objects, and 
would then be easy to adapt to five, six, eight, any number of sliders, 
whereas an ordinary solution would take obscene numbers of modifications 
and of total objects. But even with GridFlow, it's not such an easy 
problem (to make it exactly like you want it).

  _ _ __ ___ _____ ________ _____________ _____________________ ...
| Mathieu Bouchard, Montréal, Québec. téléphone: +1.514.383.3801

More information about the Pd-list mailing list