This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Computing projection of correlation matrix

+1 vote

How can I compute projection of the autocorelation function $C(x.x')$ on 1D Finite Element space?

asked Oct 6, 2016 by antonoguy FEniCS Novice (250 points)

1 Answer

+2 votes
 
Best answer

You can use the following with P1 elements. If your 1D space can be mapped from the unit interval, the analytical solutions $(\lambda, \xi)$ of $\int_D C(x, x^\prime) \xi(x) \; \mathrm{d}x = \lambda \xi(x^\prime)$ are known, I believe.

from dolfin import *
import numpy as np

mesh = IntervalMesh(64, -1., 1.)
V = FunctionSpace(mesh, 'CG', 1)
v = TestFunction(V)
u = TrialFunction(V)

# Covariance kernel function
k = Expression('exp(-std::abs(x_i - x[0])/lam)', x_i=0.0, lam=1)

# Covariance discrete matrix
C = np.zeros((mesh.num_vertices(), mesh.num_vertices()))

# Evaluate \int C(x, x') \xi(x') dx'
coords = mesh.coordinates()
dof2v = dof_to_vertex_map(V)
for j in range(len(coords)):
    k.x_i = Vertex(mesh, dof2v[j]).midpoint()[0]
    C[j, :] = assemble(k*v*dx)

You may want to use this to compute the Mercer basis functions. This can be done by doing a similar Galerkin projection of $\int_D C(x, x^\prime) \xi(x) \; \mathrm{d}x$ onto the 1D interval and solving the corresponding eigenvalue problem. Keep in mind that the system will be dense.

answered Oct 6, 2016 by nate FEniCS Expert (17,050 points)
selected Oct 7, 2016 by antonoguy

Thanks a lot, Nate!

...