def plotPDS(self): pds = PDS(self.Rm, self.Rs) # 窗口大小选择 pds.model(self.win, self.k) # pds 建模 得到pds.F Rsun = self.Rss[:self.n, :] # 选取子机上同样n 组未知样本进行PDS 预测 Rsunp = pds.predict(Rsun) # Rsunp 为预测结果 win = self.win # 舍弃窗口两端 Rmswin = self.Rms[:, win:Rsun.shape[1] - win] #Rmswin 源机上去掉两端的光谱 x = np.arange(1100, 2500, 2) xwin = x[win:Rsun.shape[1] - win] p = PlotCanvas() # 差值 for i in range(Rsunp.shape[0]): y1 = p.averSpec(Rmswin) # 源机均值光谱 p.axes.plot(xwin, y1, 'r-', label='源机均值光谱') y2 = Rsunp[i, :] # 从子机预测的光谱 p.axes.plot(xwin, y2, label='样本' + str(i + 1) + '预测值') # 差值 y = y2 - y1 # 目标机光谱 p.axes.plot(xwin, y, label='样本' + str(i + 1) + '预测偏差') p.axes.legend() p.axes.set_title("PDS算法预测结果") self.hlayout4.replaceWidget(self.wg, p) self.wg = p Rmun = Rmswin[:self.n, :] sep = p.computeSEP(Rmun, Rsunp) self.lb5.setVisible(True) self.lb5.setText('%.5f' % sep) pass
def plot(self): p = PlotCanvas(dpi=75) data = self.data matdata = data[self.cbx.currentText()] arrdata = np.array(matdata.__getitem__("data")[0][0]) x = np.arange(1100, 2500, 2) for i in range(arrdata.shape[0]): y = arrdata[i] p.axes.plot(x, y, 'r-') p.axes.set_title(self.cbx.currentText()+ "80组玉米样本光谱") self.hlayout3.replaceWidget(self.wg1, p) self.wg1 = p # 绘制均值光谱 p2 = PlotCanvas(dpi=75) y = p2.averSpec(arrdata) p2.axes.plot(x, y, 'r-') p2.axes.set_title(self.cbx.currentText()) self.hlayout3.replaceWidget(self.wg2, p2) self.wg2 = p2
def plotShenks(self): win = self.win sks = Shenks(self.Rm, self.Rs) # 窗口大小选择 sks.model(win) # sks 建模 xnew = sks.xnew # 由一元二次模型校正后的波长 ynew = sks.ynew # 由校正后波长插值后的吸光度 Rsun = self.Rss[:self.n, :] # 选取子机上同样n 组未知样本进行Sks预测 Rsunp = sks.predict(Rsun) x = np.arange(1100, 2500, 2) # 舍弃窗口两端 xnew = sks.xnew # 由校正模型 校正后的 波长 Rmswin = self.Rms[:, win:Rsun.shape[1] - win] p = PlotCanvas() y1 = p.averSpec(Rmswin) # 源机均值光谱 y1 = y1[:xnew.shape[0]] # Rmswin 源机上去掉多余波长的光谱 # 差值 for i in range(Rsunp.shape[0]): p.axes.plot(xnew, y1, 'r-', label='源机均值光谱') y2 = Rsunp[i] # 从子机预测的光谱 p.axes.plot(xnew, y2, label='样本' + str(i + 1) + '预测值') # 差值 y = y2 - y1 # 目标机光谱 p.axes.plot(xnew, y, label='样本' + str(i + 1) + '预测偏差') p.axes.legend() p.axes.set_title("Shenk's算法预测结果") self.hlayout4.replaceWidget(self.wg, p) self.wg = p Rmswin = Rmswin[:, :xnew.shape[0]] Rmun = Rmswin[:self.n, :] sep = p.computeSEP(Rmun, Rsunp) self.lb5.setVisible(True) self.lb5.setText('%.5f' % sep) pass
def plotDS(self): p = PlotCanvas() mlr = MLR(self.Rs, self.Rm) # 由选取的n 组样本进行DS 建模 mlr.modelling() Rsun = self.Rss[:self.n, :] # 选取子机上同样n 组未知样本进行DS 预测 Rsunp = np.dot(Rsun, mlr.A) # A 为得到的转换矩阵,Rsunp 为预测结果 x = np.arange(1100, 2500, 2) for i in range(Rsunp.shape[0]): y1 = p.averSpec(self.Rms) # 源机均值光谱 p.axes.plot(x, y1, 'r-', label='源机均值光谱') y2 = Rsunp[i, :] # 从子机预测的光谱 p.axes.plot(x, y2, label='样本' + str(i + 1) + '预测值') # 差值 y = y2 - y1 # 目标机光谱 p.axes.plot(x, y, label='样本' + str(i + 1) + '预测偏差') p.axes.legend() p.axes.set_title("DS算法预测结果") self.hlayout4.replaceWidget(self.wg, p) self.wg = p Rmun = self.Rms[:self.n, :] sep = p.computeSEP(Rmun, Rsunp) self.lb5.setVisible(True) self.lb5.setText('%.5f' % sep) pass