Generating all possible pairs of polynomial interaction combinations?
Show older comments
I have a matrix X where column one represents a time series, lets call it “ a ”, and column two represents another time series, that we can call “ b ”.
What I want to produce is all possible combinations of each time series multiplied with polynomial versions of the other series (“the other series” will be several other series in the future), after specifying a maximum polynomial order. I would also like to receive the polynomial versions of each variable separately (multiplied with nothing) if possible.
So say I want the polynomial order to be no higher than 3 and I only have the two variables a and b, what I would like to produce is the following (provided I didn’t miss any combination when doing this series manually):
a^1
a^2
a^3
b^1
b^2
b^3
a^1*b^1
a^2*b^1
a^3*b^1
a^1*b^2
a^1*b^3
Preferably I would like to be able to do this even when the polynomial orders aren’t integers, and when I have several more variables than a and b. So if I were to add a variable c I would also like all possible combinations of that with a and b, but I would still like the combinations expressed as pairs, or rather combinations of max length 2, so a^1*b^1*c^1 for example is too long and therefore not a valid combination.
Most combination generating approaches I can think of will probably also generate combinations such as: a^1*a^2, but since that’s the same as just a^3 I don’t want it, I could of course generate it and then remove it by a function like “unique” etc. but if possible I would prefer to not generate those combinations to begin with in the interest of saving memory.
Does anyone have any ideas for solving this?
Thanks in advance!
Accepted Answer
More Answers (0)
Categories
Find more on Polynomials in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!