Last active
November 5, 2021 21:20
-
-
Save Kensuke-Mitsuzawa/ad0e1432592f78e81076b06be135b8f6 to your computer and use it in GitHub Desktop.
generate_dirac_delta_distribution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typing | |
from pathlib import Path | |
import pandas | |
from tqdm import tqdm | |
import os | |
import numpy as np | |
def ddf(x: np.ndarray, sig: float): | |
val = [] | |
for i in x: | |
if -(1/(2*sig))<=i and i<=(1/(2*sig)): | |
val.append(sig) | |
else: | |
val.append(0) | |
return val | |
def dirac_delta_emp(y_var: float, seq_y_i: np.ndarray, sigma_dirac=0.5): | |
return sum(ddf([y_var - value_i for value_i in seq_y_i], sigma_dirac)) / len(seq_y_i) | |
def p_kpi(kpi_from: float, kpi_to: float, seq_y_i: np.ndarray, step=0.01) -> float: | |
x_and_y = [] | |
for k_i in np.arange(kpi_from, kpi_to, step): | |
__y = dirac_delta_emp(k_i, seq_y_i) | |
x_and_y.append((k_i, __y)) | |
return x_and_y | |
def generate_dirac_distribuion(n_sampling: int = 100): | |
empirical_distribution = [] | |
for df_i in range(0, n_sampling): | |
# sampling from normal distribution | |
empirical_var = np.random.normal(loc=5.0, scale=3.0) | |
empirical_distribution.append(empirical_var) | |
uncertainty_kpi = p_kpi(0, 50, empirical_distribution, step=0.01) | |
import pandas | |
df = pandas.DataFrame(uncertainty_kpi, columns=['x', 'y']) | |
ax = df.plot(x='x', y='y') | |
return df, ax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment