def adaptation(self, ti): kadp = np.ones(self.nadp) kadp[0] = STD_RATIO1 kadp[1:3] = STD_RATIO2 kadp[3:5] = STD_RATIO3 sumX = 0 sumX2 = 0 for iadp in range(self.nadp): nCompo = self.gmdistr.get_params()['n_components'] tmp_gmdistr = GMM(n_components=nCompo, covariance_type='full') tmp_gmdistr.weights_ = self.gmdistr.weights_ tmp_gmdistr.means_ = self.gmdistr.means_ tmp_gmdistr.covars_ = self.gmdistr.covars_ * kadp[iadp]**2 subSmp = MainSmp(self.nsmp, tmp_gmdistr, self.rv_array, self.r_array, self.sl_array, self.gd_array, self.gcov_array) i = 0 while i <= MAX_NUM_UPDATE: try: smps = subSmp.sample() f = subSmp.priorPDF(smps) g = 1 - subSmp.condAvailability(smps, ti) hv, responsibilities = subSmp.score_samples(smps) gf2hv = g * f / hv self.updateParameter(smps, responsibilities, gf2hv) i += 1 break except ValueError: i += 1 continue sumX += np.sum(gf2hv) sumX2 += np.sum(gf2hv**2) npre = self.nadp * self.nsmp pfpre = 1. / npre * sumX Spf2pre = 1. / (npre * (npre - 1)) * (sumX2 - 2 * sumX * pfpre + npre * pfpre**2) return pfpre, Spf2pre
def getKopt(self, k_array, ti): pf = np.zeros(k_array.shape) for k in k_array: nCompo = self.gmdistr.get_params()['n_components'] tmp_gmdistr = GMM(n_components=nCompo,covariance_type='full') tmp_gmdistr.weights_ = self.gmdistr.weights_ tmp_gmdistr.means_ = self.gmdistr.means_ tmp_gmdistr.covars_ = self.gmdistr.covars_ * k**2 subSmp = MainSmp(self.nsmp, tmp_gmdistr, self.rv_array, self.r_array, self.sl_array, self.gd_array, self.gcov_array) smps = subSmp.sample() indx = np.where(k_array==k)[0][0] pf[indx], dummy = subSmp.getPf(smps, ti) if indx>0 and pf[indx] < KRATIO_CRITERIA * np.mean(pf[:indx]): k_indx = indx-1 break else: k_indx = -1 return k_array[k_indx]
def getKopt(self, k_array, ti): pf = np.zeros(k_array.shape) for k in k_array: nCompo = self.gmdistr.get_params()['n_components'] tmp_gmdistr = GMM(n_components=nCompo, covariance_type='full') tmp_gmdistr.weights_ = self.gmdistr.weights_ tmp_gmdistr.means_ = self.gmdistr.means_ tmp_gmdistr.covars_ = self.gmdistr.covars_ * k**2 subSmp = MainSmp(self.nsmp, tmp_gmdistr, self.r_array, self.sl_array, self.gd_array) smps = subSmp.sample() indx = np.where(k_array == k)[0][0] pf[indx], dummy = subSmp.getPf(smps, ti) if indx > 0 and pf[indx] < KRATIO_CRITERIA * np.mean(pf[:indx]): k_indx = indx - 1 break else: k_indx = -1 return k_array[k_indx]
def adaptation(self, ti): kadp = np.ones(self.nadp) kadp[0] = STD_RATIO1 kadp[1:3] = STD_RATIO2 kadp[3:5] = STD_RATIO3 sumX = 0; sumX2 = 0; for iadp in range(self.nadp): nCompo = self.gmdistr.get_params()['n_components'] tmp_gmdistr = GMM(n_components=nCompo,covariance_type='full') tmp_gmdistr.weights_ = self.gmdistr.weights_ tmp_gmdistr.means_ = self.gmdistr.means_ tmp_gmdistr.covars_ = self.gmdistr.covars_ * kadp[iadp]**2 subSmp = MainSmp(self.nsmp, tmp_gmdistr, self.rv_array, self.r_array, self.sl_array, self.gd_array, self.gcov_array) i = 0 while i<=MAX_NUM_UPDATE: try: smps = subSmp.sample() f = subSmp.priorPDF(smps) g = 1 - subSmp.condAvailability(smps, ti) hv, responsibilities = subSmp.score_samples(smps) gf2hv = g*f/hv self.updateParameter(smps, responsibilities, gf2hv) i += 1 break except ValueError: i += 1 continue sumX += np.sum(gf2hv) sumX2 += np.sum(gf2hv**2) npre = self.nadp * self.nsmp pfpre = 1./npre * sumX Spf2pre = 1./(npre*(npre-1)) * (sumX2 - 2*sumX*pfpre + npre * pfpre**2) return pfpre, Spf2pre