from __future__ import division %matplotlib inline import pylab as pl import numpy as np xs = np.random.normal(size=1000000) sigmas = np.linspace(.01, 10) xs_sigs = xs * sigmas[:, np.newaxis] pl.figure(figsize=(8, 3)) pl.subplot(121) pl.plot(sigmas, np.cos(xs_sigs).mean(axis=1)) pl.plot(sigmas, np.exp(- sigmas**2 / 2), color='red', linestyle='--') pl.subplot(122) pl.plot(sigmas, np.sin(xs_sigs).mean(axis=1)) pl.tight_layout() pl.figure(figsize=(6, 2)) pl.subplot(121) pl.plot(sigmas, np.cos(xs_sigs).std(axis=1)) pl.plot(sigmas, (1 - np.exp(- sigmas**2)) / np.sqrt(2), color='red', linestyle='--') pl.subplot(122) pl.plot(sigmas, np.sin(xs_sigs).std(axis=1)) pl.plot(sigmas, np.sqrt((1 - np.exp(-2 * sigmas**2)) / 2), color='red', linestyle='--') pl.tight_layout() xs = np.random.normal(size=1000000) mus = np.linspace(-5, 5) sigmas = 1 xs_mus = xs + mus[:, np.newaxis] pl.figure(figsize=(8, 3)) pl.subplot(121) pl.plot(mus, np.cos(xs_mus).mean(axis=1)) pl.plot(mus, np.exp(- sigmas**2 / 2) * np.cos(mus), color='red', linestyle='--') pl.subplot(122) pl.plot(mus, np.sin(xs_mus).mean(axis=1)) pl.plot(mus, np.exp(- sigmas**2 / 2) * np.sin(mus), color='red', linestyle='--') pl.tight_layout() pl.figure(figsize=(8, 3)) pl.subplot(121) pl.plot(mus, np.cos(xs_mus).std(axis=1)) pl.plot(mus, np.sqrt(.5 + np.exp(-2*sigmas**2) / 2 * np.cos(2 * mus) - np.exp(-sigmas**2) * np.cos(mus)**2), color='red', linestyle='--') pl.subplot(122) pl.plot(mus, np.sin(xs_mus).std(axis=1)) pl.plot(mus, np.sqrt(.5 - np.exp(-2*sigmas**2) / 2 * np.cos(2 * mus) - np.exp(-sigmas**2) * np.sin(mus)**2), color='red', linestyle='--') pl.tight_layout()