Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Energy distr #269

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
4 changes: 2 additions & 2 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ name: CI
on:
# Triggers the workflow on push or pull request events but only for the develop branch
push:
branches: [ develop ]
branches: [ develop, v1.0 ]
pull_request:
branches: [ develop ]
branches: [ develop, v1.0 ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
Binary file not shown.
263 changes: 263 additions & 0 deletions notebooks/notebook_shapiro.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "cfc7bba9",
"metadata": {},
"source": [
"# Shapiro-Wilk test for normal and lognormal distributions"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8e456eaf",
"metadata": {},
"outputs": [],
"source": [
"import sandy"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "35fae75e",
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"import pandas as pd\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8e08433c",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import seaborn as sns"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c57f6407",
"metadata": {},
"outputs": [],
"source": [
"logging.getLogger().setLevel(logging.WARN)"
]
},
{
"cell_type": "markdown",
"id": "8d1ddd57",
"metadata": {},
"source": [
"Generate 5000 xs samples normally and log-normally distributed"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fa73bbbc",
"metadata": {},
"outputs": [],
"source": [
"tape = sandy.get_endf6_file(\"jeff_33\", \"xs\", 10010)\n",
"njoy_kws = dict(err=1, errorr33_kws=dict(mt=102))\n",
"nsmp = 5000\n",
"seed = 5\n",
"\n",
"smp_norm = tape.get_perturbations(nsmp, njoy_kws=njoy_kws, smp_kws=dict(seed33=seed, pdf=\"normal\"))[33]\n",
"smp_lognorm = tape.get_perturbations(nsmp, njoy_kws=njoy_kws, smp_kws=dict(seed33=seed, pdf=\"lognormal\"))[33]\n",
"smp_uniform = tape.get_perturbations(nsmp, njoy_kws=njoy_kws, smp_kws=dict(seed33=seed, pdf=\"uniform\"))[33]"
]
},
{
"cell_type": "markdown",
"id": "08f12802",
"metadata": {},
"source": [
"## Shapiro-Wilk test normal samples and normal distribution"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4cf664f6",
"metadata": {},
"outputs": [],
"source": [
"stat_norm = []\n",
"stat_lognorm = []\n",
"for n in [10, 50, 100, 500, 1000, 5000]:\n",
" df = smp_norm.test_shapiro(pdf=\"normal\", size=n)\n",
" idx = df.statistic.idxmin()\n",
" stat_norm.append(df.loc[idx].rename(n))\n",
"\n",
" df = smp_norm.test_shapiro(pdf=\"lognormal\", size=n)\n",
" idx = df.statistic.idxmin()\n",
" stat_lognorm.append(df.loc[idx].rename(n))\n",
"\n",
"opts = dict(left_index=True, right_index=True, suffixes=(\"_norm\", \"_lognorm\"))\n",
"pd.DataFrame(stat_norm).merge(pd.DataFrame(stat_lognorm), **opts).rename_axis(\"# SMP\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "449bdf7d",
"metadata": {},
"outputs": [],
"source": [
"test = smp_norm.test_shapiro(pdf=\"normal\", size=5000)\n",
"\n",
"fig, ax = plt.subplots(figsize=(7, 4), dpi=100)\n",
"\n",
"idx = test.statistic.idxmin()\n",
"w = test.loc[idx]\n",
"sns.histplot(data=smp_norm.data.loc[idx], label=f\"W:stat={w.statistic:.2e}, p-value={w.pvalue:.2e}\", color=\"dodgerblue\")\n",
"\n",
"idx = test.statistic.idxmax()\n",
"w = test.loc[idx]\n",
"sns.histplot(data=smp_norm.data.loc[idx], label=f\"W:stat={w.statistic:.2e}, p-value={w.pvalue:.2e}\", color=\"tomato\")\n",
"\n",
"ax.set(xlabel=\"W\")\n",
"ax.legend()\n",
"fig.tight_layout()"
]
},
{
"cell_type": "markdown",
"id": "78c3e97d",
"metadata": {},
"source": [
"## Shapiro-Wilk test for lognormal samples and lognormal distribution"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "be16d4f1",
"metadata": {},
"outputs": [],
"source": [
"stat_norm = []\n",
"stat_lognorm = []\n",
"for n in [10, 50, 100, 500, 1000, 5000]:\n",
" df = smp_lognorm.test_shapiro(pdf=\"normal\", size=n)\n",
" idx = df.statistic.idxmin()\n",
" stat_norm.append(df.loc[idx].rename(n))\n",
"\n",
" df = smp_lognorm.test_shapiro(pdf=\"lognormal\", size=n)\n",
" idx = df.statistic.idxmin()\n",
" stat_lognorm.append(df.loc[idx].rename(n))\n",
"\n",
"opts = dict(left_index=True, right_index=True, suffixes=(\"_norm\", \"_lognorm\"))\n",
"pd.DataFrame(stat_norm).merge(pd.DataFrame(stat_lognorm), **opts).rename_axis(\"# SMP\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8fa36199",
"metadata": {},
"outputs": [],
"source": [
"test = smp_lognorm.test_shapiro(pdf=\"lognormal\", size=5000)\n",
"\n",
"fig, ax = plt.subplots(figsize=(7, 4), dpi=100)\n",
"\n",
"idx = test.statistic.idxmin()\n",
"w = test.loc[idx]\n",
"sns.histplot(data=smp_lognorm.data.loc[idx], label=f\"W:stat={w.statistic:.2e}, p-value={w.pvalue:.2e}\", color=\"dodgerblue\")\n",
"\n",
"idx = test.statistic.idxmax()\n",
"w = test.loc[idx]\n",
"sns.histplot(data=smp_lognorm.data.loc[idx], label=f\"W:stat={w.statistic:.2e}, p-value={w.pvalue:.2e}\", color=\"tomato\")\n",
"\n",
"ax.set(xlabel=\"W\")\n",
"ax.legend()\n",
"fig.tight_layout()"
]
},
{
"cell_type": "markdown",
"id": "975dbaa1",
"metadata": {},
"source": [
"## Shapiro-Wilk test for uniform samples and normal distribution"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bded2114",
"metadata": {},
"outputs": [],
"source": [
"stat_norm = []\n",
"stat_lognorm = []\n",
"for n in [10, 50, 100, 500, 1000, 5000]:\n",
" df = smp_uniform.test_shapiro(pdf=\"normal\", size=n)\n",
" idx = df.statistic.idxmin()\n",
" stat_norm.append(df.loc[idx].rename(n))\n",
"\n",
" df = smp_uniform.test_shapiro(pdf=\"lognormal\", size=n)\n",
" idx = df.statistic.idxmin()\n",
" stat_lognorm.append(df.loc[idx].rename(n))\n",
"\n",
"opts = dict(left_index=True, right_index=True, suffixes=(\"_norm\", \"_lognorm\"))\n",
"pd.DataFrame(stat_norm).merge(pd.DataFrame(stat_lognorm), **opts).rename_axis(\"# SMP\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b6e1d4ee",
"metadata": {},
"outputs": [],
"source": [
"test = smp_uniform.test_shapiro(pdf=\"uniform\", size=5000)\n",
"\n",
"fig, ax = plt.subplots(figsize=(7, 4), dpi=100)\n",
"\n",
"idx = test.statistic.idxmin()\n",
"w = test.loc[idx]\n",
"sns.histplot(data=smp_uniform.data.loc[idx], label=f\"W:stat={w.statistic:.2e}, p-value={w.pvalue:.2e}\", color=\"dodgerblue\")\n",
"\n",
"idx = test.statistic.idxmax()\n",
"w = test.loc[idx]\n",
"sns.histplot(data=smp_uniform.data.loc[idx], label=f\"W:stat={w.statistic:.2e}, p-value={w.pvalue:.2e}\", color=\"tomato\")\n",
"\n",
"ax.set(xlabel=\"W\")\n",
"ax.legend()\n",
"fig.tight_layout()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python3 (sandy-devel)",
"language": "python",
"name": "sandy-devel"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2 changes: 1 addition & 1 deletion requirements_conda.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ scipy
sphinx
seaborn >= 0.9
statsmodels
pytables
pytables
Binary file added rwf.cp310-win_amd64.pyd
Binary file not shown.
3 changes: 2 additions & 1 deletion sandy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .decay import *
from .energy_grids import *
from .errorr import *
from .groupr import *
from .gendf import *
from .fy import *
from .tsl import *
from .gls import *
Expand All @@ -23,6 +23,7 @@
from .utils import *
from .core import *
from .sampling import *
from .spectra import *
import sandy.mcnp
import sandy.aleph2
import sandy.tools
Expand Down
Loading