Skip to content

Instantly share code, notes, and snippets.

@physicshinzui
Last active October 31, 2023 02:14
Show Gist options
  • Save physicshinzui/21dc5d2364f6c96c73dfbfa62ae8163e to your computer and use it in GitHub Desktop.
Save physicshinzui/21dc5d2364f6c96c73dfbfa62ae8163e to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 17,
"id": "0db197c6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"/Users/siida/workplace/perturbed.pdf\""
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using Distributions\n",
"using Plots\n",
" \n",
"Np = 25 # the number of perturbation\n",
"n_samples = 5000\n",
"dist1 = Normal(-5, 1)\n",
"dist2 = Normal(5, 1)\n",
"mixture = MixtureModel(Normal[dist1, dist2], [0.5,0.5])\n",
"xs = rand(mixture, n_samples)\n",
"bins = -100:2.0:100\n",
"p = histogram(xs, title=\"Original\", bins=bins)\n",
"ps = [p]\n",
"for i in 1:Np\n",
" ϵ = rand(Normal(0,1), n_samples)\n",
" xs = xs + ϵ\n",
" if i % 5==0\n",
" push!(ps, histogram(xs, bins=bins, title=\"$(i)\"))\n",
" end\n",
"end\n",
"all = plot(ps..., legend=false, size=(800,600))\n",
"xlims!(-100,100)\n",
"ylims!(0, 1700)\n",
"#savefig(all, \"perturbed.pdf\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dde6cd75",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"gist": {
"data": {
"description": "",
"public": true
},
"id": ""
},
"kernelspec": {
"display_name": "Julia 1.9.2",
"language": "julia",
"name": "julia-1.9"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment