The problem below fails to converge to default accuracy using default method.
With[{a = 1 - 1/100000},
NExpectation[Log[1 - 2 a x^2 + a^2 x^4]^2,
x \[Distributed] NormalDistribution[], WorkingPrecision -> 100]]
The warning I get is that
following: singularity, value of the integration is 0, highly \
oscillatory integrand, or WorkingPrecision too small
I think I can rule out "working precision" and value of integrand is 0....what should I do if it's highly oscillatory?
More generally I'm trying to plot this expectation as a function of $a$ and end up with fractal-like structure in the plot. Trying to figure out if it's really there, or whether it's artifact of default numerical integration method.
obj[a_] := NExpectation[Log[1 - 2 a x^2 + a^2 x^4]^2,
x \[Distributed] NormalDistribution[]];
Plot[obj[a], {a, 0.75, 1.2}]
Edit after letting it run overnight, original plot seems to be due to numerical issues
Clear[x];
term[a_] :=
TransformedDistribution[Log[1 - 2 a x^2 + a^2 x^4],
x \[Distributed] NormalDistribution[]];
mean[a_] :=
NExpectation[q, q \[Distributed] term[a],
Method -> {"NIntegrate", {MinRecursion -> 9,
MaxRecursion -> 30}}];
mean2[a_] :=
NExpectation[q^2, q \[Distributed] term[a],
Method -> {"NIntegrate", {MinRecursion -> 9, MaxRecursion -> 30}}];
NExpectation
it should compute a smoother graph and need to evaluateobj
at fewer points $\endgroup$