-- A script which demonstrates how the binomial and poisson distributions -- approximate each other. --- Imports --- -- Goal -- import Goal.Core import Goal.Geometry import Goal.Probability --- Script --- main = renderableToAspectWindow False 800 600 . toRenderable $ poissonLayout 5 poissonLayout :: Double -> Layout Int Double poissonLayout lmda = execEC $ do layout_title .= "Binomial Convergence to Poisson" layout_y_axis . laxis_title .= "Probability Mass" layout_x_axis . laxis_title .= "Count" let rng = [0..20] plot . liftEC $ do let pd = chart Standard $ fromList Poisson [lmda] ppnts = zip rng $ density pd <$> rng plot_points_style .= filledCircles 8 (opaque red) plot_points_title .= ("λ = " ++ show lmda) plot_points_values .= ppnts let bplt n = liftEC $ do let p = lmda / fromIntegral n alph = 2 * fromIntegral n / 100 bd = chart Standard $ fromList (Binomial n) [p] bpnts = zip rng $ density bd <$> take (n+1) rng plot_points_style .= filledCircles 5 (withOpacity black alph) plot_points_title .= ("n = " ++ show n ++ ", p = " ++ show p) plot_points_values .= bpnts plot $ bplt 10 plot $ bplt 25 plot $ bplt 100