diff --git a/interpolationConfiguration.py b/interpolationConfiguration.py new file mode 100644 index 0000000..ea0685c --- /dev/null +++ b/interpolationConfiguration.py @@ -0,0 +1,41 @@ +import yaml + +class InterpolConfig: + def __init__(self,config='shit.yml'): + with open(config, 'r') as f: + self.data = yaml.safe_load(f)['interpolation_config'] + if self.data is None: + raise Exception("Shit interpolation with shit config; it is not working!!!!") + pass + + def __path(self, path): + return self.data['tables_dir'] + path + + @property + def available_data(self) -> str: + return self.__path(self.data['available_data']) + + @property + def out_file(self) -> str: + return self.__path(self.data['out_file']) + + @property + def available_limit(self) -> int: + return int(self.data['available_limit']) + + @property + def total_points(self) -> int: + return int(self.data['total_points']) + + @property + def image_data(self): + import numpy as np + return np.array(self.data['image_data']) + + @property + def std_source(self): + """ + returns: dataframe with standard deviation source information :) + """ + import pandas as pd + return pd.read_csv(self.__path(self.data['std_dev'])) \ No newline at end of file diff --git a/shit.py b/shit.py new file mode 100644 index 0000000..bc9a933 --- /dev/null +++ b/shit.py @@ -0,0 +1,74 @@ +import pandas as pd +import numpy as np +from interpolationConfiguration import InterpolConfig +from scipy.stats import norm +from scipy.optimize import fsolve +import numpy as np +import logging +import matplotlib.pyplot as plt + +logging.basicConfig(level=logging.INFO, + format='%(asctime)s - %(levelname)s - %(message)s') + +class Interpol: + """ + Huhu, interpol + Interpolation of the uncompleted distribution + """ + def __init__(self, config='shit.yml'): + self.config = InterpolConfig(config) + self.available_data = pd.read_csv(self.config.available_data).iloc[:,1] + pass + + + def save(self, res: np.array): + array = [[1] * len(res), + res] + df = pd.DataFrame(array).transpose() + df.to_csv(self.config.out_file, header=False, index=False) + + # to interpolate data we first must find "true mean" + # for this we would take min value from csv, max value from image + # and take as granted that we have len(data)/total_points already there + def interpolate_part_of_data(): + pass + + def normal_dist(self): + mu = self.maximum_likelihood() + res = np.random.normal(loc=mu, scale=8, size=150) + _ = plt.figure(figsize=(10, 6), dpi=300) + plt.hist(res) + plt.title('Interpolated results') + plt.show() + + res = res[res >= self.config.available_limit] + res = np.append(res, self.available_data, axis=0) + plt.hist(res) + plt.title('Combined results') + plt.show() + self.save(res) + + + + + def maximum_likelihood(self): + def equation(mu, A, B, dAC, n_known, total): + prob_AB = norm.cdf((B-mu)/dAC) - norm.cdf((A-mu)/dAC) + return prob_AB - n_known/total + + # Your values + A = self.available_data.min() # left boundary + B = float(self.config.available_limit) # right boundary of known data + C = np.max(self.config.image_data) # right boundary of distribution + dAC = self.config.std_source.iloc[:,1].std() # standard deviation + logging.info(f"dAC={dAC}") + n_known = len(self.available_data) + total = n_known * 3 + logging.info(f"A={A}; B={B}; C={C}") + # Solve for mu + mu_estimate = fsolve(equation, x0=B, args=(A, B, dAC, n_known, total))[0] + logging.info(f"Estimated mean: {mu_estimate:.3f}") + return mu_estimate + +a = Interpol() +a.normal_dist() \ No newline at end of file diff --git a/shit.yml b/shit.yml new file mode 100644 index 0000000..6982275 --- /dev/null +++ b/shit.yml @@ -0,0 +1,9 @@ +interpolation_config: + tables_dir: 'tables/' # prefix directory of the tables + total_points: 150 # total points to generate + out_file: 'interpolated_nvv4l2.csv' # out file base name + available_data: 'nvv4l2h264enc_preset0.csv' # file to be processed + available_limit: 200 # limit of values in available data + image_data: [195.7, 214.7, 212.1, 214.1, 182.7, 207.0, 209.9, 198.3, 216.3, 208.3, + 212.2, 207.8, 214.7, 202.1, 209.3, 217.3, 214.3, 207.6, 211.9, 203.9] + std_dev: 'x264_one.csv' \ No newline at end of file