[scripts] interpolation of bad results :D

:Release Notes:
shit results - shit interpolation :D

:Detailed Notes:
-

:Testing Performed:
Mostly similar to the visible results

:QA Notes:
-

:Issues Addressed:
-
This commit is contained in:
Artur Mukhamadiev 2025-10-25 13:58:49 +03:00
parent 31d550bc89
commit f56935c748
3 changed files with 124 additions and 0 deletions

View File

@ -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']))

74
shit.py Normal file
View File

@ -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()

9
shit.yml Normal file
View File

@ -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'