def plotSmpAndSep(self): self.lb5.setVisible(False) p = PlotCanvas() sep = [] QMessageBox.information(self, "tip", "开始绘制请稍后...") for i in range(3, 30, 3): Rm = self.Rms[:i, :] # 截取前i 个样本 Rs = self.Rss[:i, :] pds = PDS(Rm, Rs) # 由选取的i 组样本进行DS 建模 win = self.win pds.model(win, self.k) Rsun = self.Rss[i:i * 2, :] # 选取子机上同样n 组未知样本进行DS 预测 Rmun = self.Rms[i:i * 2, :] Rsunp = pds.predict(Rsun) sep.append(p.computeSEP(Rmun[:, win:Rsun.shape[1] - win], Rsunp)) x = range(3, 30, 3) p.axes.plot(x, np.array(sep), linewidth=3, color='b', marker='o', markerfacecolor='red', markersize=12) p.axes.set_xlabel("样本数目(:组)") p.axes.set_ylabel("平均预测标准误差(SEP)") p.axes.set_title("样本数量 与 SEP 关系图") self.hlayout4.replaceWidget(self.wg, p) self.wg = p self.lb4.setText("绘制完成") pass
def plotKAndSep(self): self.lb5.setVisible(False) p = PlotCanvas() sep = [] QMessageBox.information(self, "tip", "开始绘制请稍后...") # 样本数量定为当前样本数量 n = 10 Rm = self.Rms[:n, :] # 截取前n 个样本 Rs = self.Rss[:n, :] pds = PDS(Rm, Rs) # 由选取的i 组样本进行DS 建模 win = self.win Rsun = self.Rss[n:n * 2, :] # 选取子机上同样n 组未知样本进行PDS 预测 Rmswin = self.Rms[:, win:Rsun.shape[1] - win] Rmun = Rmswin[n:n * 2, :] for i in range(1, n + 1): pds.model(win, i) Rsunp = pds.predict(Rsun) sep.append(p.computeSEP(Rmun, Rsunp)) x = range(1, n + 1) p.axes.plot(x, np.array(sep), linewidth=3, color='b', marker='o', markerfacecolor='red', markersize=12) p.axes.set_xlabel("主成分个数") p.axes.set_ylabel("平均预测标准误差(SEP)") p.axes.set_title("主成分个数 与 SEP 关系图") self.hlayout4.replaceWidget(self.wg, p) self.wg = p self.lb4.setText("绘制完成") pass
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 plotWinAndSep(self): self.lb5.setVisible(False) p = PlotCanvas() sep = [] QMessageBox.information(self, "tip", "开始绘制请稍后...") # 样本数量定为当前样本数量 n = self.n Rm = self.Rms[:n, :] # 截取前n 个样本 Rs = self.Rss[:n, :] sks = Shenks(Rm, Rs) # 由选取的n 组样本进行sks 建模. Rsun = self.Rss[n:n * 2, :] # 选取子机上同样n 组未知样本进行sks 预测 for i in range(1, 21): win = i sks.model(win) Rsunp = sks.predict(Rsun) xnew = sks.xnew Rmswin = self.Rms[:, win:Rsun.shape[1] - win] Rmswin = Rmswin[:, :xnew.shape[0]] Rmun = Rmswin[n:n * 2, :] sep.append(p.computeSEP(Rmun, Rsunp)) x = range(1, 21) p.axes.plot(x, np.array(sep), linewidth=3, color='b', marker='o', markerfacecolor='red', markersize=12) p.axes.set_xlabel("窗口大小") p.axes.set_ylabel("平均预测标准误差(SEP)") p.axes.set_title("窗口大小 与 SEP 关系图") self.hlayout4.replaceWidget(self.wg, p) self.wg = p self.lb4.setText("绘制完成") pass
def plotSmpAndSep(self): self.lb5.setVisible(False) p = PlotCanvas() sep = [] self.lb4.setText("绘制中......") for i in range(3, 30, 3): Rm = self.Rms[:i, :] # 截取前i 个样本 Rs = self.Rss[:i, :] mlr = MLR(Rs, Rm) # 由选取的n 组样本进行DS 建模 mlr.modelling() Rsun = self.Rss[i:i * 2, :] # 选取子机上同样n 组未知样本进行DS 预测 Rmun = self.Rms[i:i * 2, :] Rsunp = np.dot(Rsun, mlr.A) # A 为得到的转换矩阵,Rsunp 为预测结果 sep.append(p.computeSEP(Rmun, Rsunp)) x = range(3, 30, 3) p.axes.plot(x, np.array(sep), linewidth=3, color='b', marker='o', markerfacecolor='red', markersize=12) p.axes.set_xlabel("样本数目(:组)") p.axes.set_ylabel("平均预测标准误差(SEP)") p.axes.set_title("样本数量 与 SEP 关系图") self.hlayout4.replaceWidget(self.wg, p) self.wg = p self.lb4.setText("绘制完成") pass
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