I try to implement weighted sums in the Patterns system and thought this should work (ignore the boringness of the code, it is simplified) but it apparently throws an error for me, anyone knows why?
Hey till
I’ve got an improved Pw that can take patterns for weights, and doesn’t require normalized weight values, I’ll post when I’m at my computer.
(To answer your q: I recall this being a limitation of Pwrand, which lead me to make the newer version)
I’ve found I use this class VERY heavily - composing by using Pwnrands containing Pseg's for each weight has become a pretty core compositional pattern for me.
Pwrand([1, 2, 3], Ptuple([10, 1, 1]).collect(_.normalizeSum), 100).asStream.all.histo.plot; // weights are normalized for each .next()
Pwrand([1, 2, 3], Ptuple([2, 1, 1]).collect(_.normalizeSum), 100).asStream.all.histo.plot;
Pwrand([1, 2], Ptuple([1, Pseq([0.0, 1]).stutter(50)]).collect(_.normalizeSum), 100).asStream.all.histo.plot; // Weights can be streams
Which allows the same behaviour (regarding normalisation and integration of patterns into the weights). So, there we have two solutions… but I am required by the mechanism of this forum to pick one and James’ works without extensions…