Say you've $N$ functions $f_N(x)$ defined on a regular grid $x$. You don't know the form of $f(x)$, you've only got several realizations of it. The different functions are related to each other somehow, but you don't know exactly how. You want to pick $n$ representative ones, or equivalently, group them into $n$ clusters.
Here is an example:
N = 1000
library(MASS)
B = mvrnorm(N,mu=c(0,0,.0001),Sigma = matrix(c(1,.5,-.3,.5,.5,-.2,-.3,-.2,1),3))
X = cbind(1,x)
dim(B)
dim(X)
f = B[,1:2]%*%t(X)+as.matrix(rexp(N,rate = (abs(B[,3]))^.1))%*%t(as.matrix(sin(x)))
plot(1:10,cex=0,xlim=c(0,10),ylim=c(-10,10))
for (i in 1:nrow(f)){
lines(x,f[i,],col=rgb(1,0,0,.2))
}
(A plot will pop up)
I want to group them somehow. I'm not sure how. Intuitively, I want them organized by where they start, whether they go up or down, and how wiggly they are. But we're supposing that I didn't know the data generating process, I've only got that matrix f
.
I was thinking I could do a taylor expansion on each row of f
, out to some arbitrary order $t$. This would give me an approximation $f(x) = X'\beta$, where $X$ is $1,x,x^2,...,x^t$ and $\beta$ is the transformed Taylor approximation coefficients. I was thinking of then k-means clustering by those $\beta$'s.
My question: does that approach make sense? I just came up with it, but I don't know if any better methods have already been figured out.
And if it does make sense, how do you do a Taylor series in R, getting what I'm conceptualizing as $\beta$?