Context
As a mean to understand the growth of structure in the universe, I am interested in characterising the curvature of random fields such as this one:
For this purpose I start with a PDF of the eigenvalues of the second derivative of the field (a measure of the local curvature). For a Gaussian Random Field this PDF reads
Pdf1= 2 Sqrt[2/π] (x1-x2) Exp[1/2 (-x1 (3 x1-x2)-x2 (3 x2-x1))]
and looks like this:
rg = {{x1, -Infinity, Infinity}, {x2, -Infinity, x1}};
rgn = {{x1, -2, 2}, {x2, -2, x1}};
ContourPlot[Pdf1, Sequence @@ rgn // Evaluate, ImageSize -> Small]
while when the field becomes non Gaussian (like the above), the PDF can be quite different:
My purpose is to use orthogonal polynomials to represent this Non Gaussian PDF.
Attempt
I have defined a scalar product
Clear[int]; int[a_, b_] :=
Integrate[ a b Pdf1, Sequence @@ rg // Evaluate]
and a numerical integration version of it
Clear[nint]; nint[a_, b_] :=
NIntegrate[ a b Pdf1, Sequence @@ rg // Evaluate]
I define my 2D polynomial
p = 2; pol0 =
Table[Table[x1^i x2^(p1 - i), {i, 0, p1}] // Flatten // Union,
{p1, 0, p}] // Flatten // Join
{1, x1, x2, x1^2, x1 x2, x2}
pol = Orthogonalize[pol0, int[#1, #2] &]
They look like this:
Map[ContourPlot[# Pdf1 , Sequence @@ rgn // Evaluate,
PlotPoints -> 15, PlotRange -> All] &, pol]
If I do the same thing numerically
pol = Orthogonalize[pol0, intn[#1, #2] &, Method -> "Reorthogonalization"];
I get the same answer.
But
If I try and find higher order polynomials numerically
p = 6; pol0 =
Table[Table[x1^i x2^(p1 - i), {i, 0, p1}] // Flatten // Union,
{p1, 0, p}] // Flatten // Join;
pol = Orthogonalize[pol0, intn[#1, #2] &, Method -> "Reorthogonalization"];
I get this
(* {1.,1.81473 x1-0.804133,-1.53835 x1+2.37903 x2+1.73585,2.33148 x1^2-2.23663 x1+0.170409 x2-0.0991482,-2.84065 x1^2+4.36636 x1 x2+4.97902 x1-2.46156 x2-1.87669,1.84722 x1^2-5.47403 x1 x2-4.89841 x1+4.11307 x2^2+6.90647 x2+2.25076,0,3.15107 x1^2 x2+1.83935 x1^2-3.44839 x1 x2-3.23326 x1+0.212753 x2^2+0.21619 x2+0.676981,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} *)
In other words the loss of accuracy in the orthogonalisation leads to zero higher order polynomials.
I have also tried Gramm Schmitt by hand (from somewhere on SE)
gs[vecs_, ip___] := Module[{ovecs = vecs},
Do[ovecs[[i]] -= Projection[ovecs[[i]], ovecs[[j]], ip], {i, 2,
Length[vecs]}, {j, 1, i - 1}]; ovecs];
pol1 = gs[pol0, Function[
NIntegrate[ ## Pdf1, Sequence @@ rg // Evaluate]]];
but it yields the same loss of accuracy.
I have also tried Eigenvectors of the matrix of scalar products
mat = ParallelTable[int[i, j], {i, pol0}, {j, pol0}];
eigs = Eigensystem[mat // N];
But the orthogonal polynomials are not of increasing order:
Map[ContourPlot[# Pdf1, Sequence @@ rgn // Evaluate,
PlotPoints -> 15, PlotRange -> All] &,
pol = eigs[[2]].pol0/Sqrt[eigs[[1]]] // Chop]
Note that while orthogonal they are not orthogonal 'in the same direction'.
Question
How can I compute the higher order orthogonal polynomials accurately?
Side Question
One option would be to stick to symbolic evaluation of the scalar product, but it seems to take forever for higher order polynomials.
Is it possible to tell
Orthogonalize
to not Normalise the polynomials which symbolically seems to take longest?
x1>x2
constraint but then my integrant would have|x1-x2|
instead of(x1-x2)
$\endgroup$Pdf1
in the integrand. Sorry. Towards the eigenvalues: Yes, you can order them, but I tried to say that computations might be easier without doing so. Of course, you would have to replacePdf1
by the correct distribution on the whole $mathbb{R}^2$ (by multiplying by1/2
and throwing in someAbs
). This would allow you to use Hermite polynomials. $\endgroup$PrecisionGoal
andAccuracyGoal
are a bit different: If set to a low value they giveNIntegrate
a bail out option to stop early, but they don't change the number precisionNIntegrate
uses for intermediate values in the internal calculations. By defaultNIntegrate
will use fast$MachinePrecision
numbers to perform those calculations but this (double) precision might not be enough to prevent catastrophic cancellation for high order oscillating polynomials.WorkingPrecision
tells Mma to use arbitrary precision numbers internally, which should solve the cancellation issue. $\endgroup$