3 Star 0 Fork 1

chenghui03/Calib_RT

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.py 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
import statsmodels.api as sm
import numpy as np
def generate_noise(path, noise_prop, seed):
data = np.load(path)
x, y = data["x"], data["y"]
datamatrix = np.concatenate((x[:, np.newaxis], y[:, np.newaxis]), axis=1)
datasize = len(x)
datasize_noise = datasize * noise_prop
noise_xrange_left, noise_xrange_right = np.min(x), np.max(x)
noise_yrange_low, noise_yrange_up = np.min(y), np.max(y)
np.random.seed(seed)
noisematrix = np.concatenate(( \
np.random.uniform(noise_xrange_left, noise_xrange_right,
(datasize_noise, 1), ),
np.random.uniform(noise_yrange_low, noise_yrange_up,
(datasize_noise, 1), ),), axis=1)
datamatrix = np.concatenate((datamatrix, noisematrix), axis=0)
return datamatrix[:, 0], datamatrix[:, 1]
def fit_by_raw_lowess(x, y,frac=0.1):
lowess = sm.nonparametric.lowess
y_lowess = lowess(y, x, frac)
x_fit, y_fit = zip(*y_lowess)
x_fit, y_fit = np.array(x_fit), np.array(y_fit)
return x_fit, y_fit
class Normalization(object):
def __init__(self,x,y) -> None:
self.x_bt = (np.min(x),np.max(x))
self.y_bt = (np.min(y),np.max(y))
self.x_normal = (x-self.x_bt[0])/(self.x_bt[1] - self.x_bt[0])
self.y_normal = (y-self.y_bt[0])/(self.y_bt[1] - self.y_bt[0])
def get_normalized_data(self):
return self.x_normal,self.y_normal
def denormalize_data(self,x_normal,y_normal):
x = (self.x_bt[1]-self.x_bt[0])*x_normal+self.x_bt[0]
y = (self.y_bt[1]-self.y_bt[0])*y_normal+self.y_bt[0]
return x,y
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/chenghui03/calib_-rt.git
git@gitee.com:chenghui03/calib_-rt.git
chenghui03
calib_-rt
Calib_RT
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385