def initialize(self, key): # Run through the standard initialization super().initialize(key) # for now, start with white noise self.data_mat = self.sigma_mat.copy() self.data_mat_last = self.data_mat.copy() #Set up p0 and the independent sampler fname = Starfish.specfmt.format(self.spectrum_id, self.order) + "phi.json" phi = PhiParam.load(fname) # print("Phi.regions", phi.regions) # import sys # sys.exit() # Get the regions matrix region_func = make_k_func_region(phi) max_r = 4.0 * np.max(phi.regions, axis=0)[2] self.region_mat = get_dense_C(self.wl, k_func=region_func, max_r=max_r) print(self.region_mat) # Then set phi to None phi.regions = None #Loading file that was previously output # Convert PhiParam object to an array self.p0 = phi.toarray() jump = Starfish.config["Phi_jump"] cheb_len = (self.npoly - 1) if self.chebyshevSpectrum.fix_c0 else self.npoly cov_arr = np.concatenate((Starfish.config["cheb_jump"]**2 * np.ones((cheb_len,)), np.array([jump["sigAmp"], jump["logAmp"], jump["l"]])**2 )) cov = np.diag(cov_arr) def lnfunc(p): # Convert p array into a PhiParam object ind = self.npoly if self.chebyshevSpectrum.fix_c0: ind -= 1 cheb = p[0:ind] sigAmp = p[ind] ind+=1 logAmp = p[ind] ind+=1 l = p[ind] phi = PhiParam(self.spectrum_id, self.order, self.chebyshevSpectrum.fix_c0, cheb, sigAmp, logAmp, l) self.update_Phi(phi) lnp = self.evaluate() self.logger.debug("Evaluated Phi parameters: {} {}".format(phi, lnp)) return lnp def rejectfn(): self.logger.debug("Calling Phi revertfn.") self.revert_Phi() self.sampler = StateSampler(lnfunc, self.p0, cov, query_lnprob=self.get_lnprob, rejectfn=rejectfn, debug=True)
fname = Starfish.specfmt.format(spectrum_id, order) + "regions.json" f = open(fname, "r") read = json.load(f) # read is a dictionary f.close() mus = np.array(read["mus"]) if args.noise: sigma_mat = sigma**2 * np.eye(len(sigma)) fname = Starfish.specfmt.format(spectrum_id, order) + "phi.json" phi = PhiParam.load(fname) if phi.regions is not None: region_func = make_k_func_region(phi) max_r = 4.0 * np.max(phi.regions, axis=0)[2] region_mat = get_dense_C(wl, k_func=region_func, max_r=max_r) else: region_mat = 0.0 max_r = 6.0 * phi.l # [km/s] # Create a partial function which returns the proper element. k_func = make_k_func(phi) data_mat = get_dense_C(wl, k_func=k_func, max_r=max_r) + phi.sigAmp * sigma_mat + region_mat # Get many random draws from data_mat draws = random_draws(data_mat, num=4) min_spec, max_spec = std_envelope(draws)
def initialize(self, key): # Run through the standard initialization super().initialize(key) # for now, start with white noise self.data_mat = self.sigma_mat.copy() self.data_mat_last = self.data_mat.copy() #Set up p0 and the independent sampler fname = Starfish.specfmt.format(self.spectrum_id, self.order) + "phi.json" phi = PhiParam.load(fname) # print("Phi.regions", phi.regions) # import sys # sys.exit() # Get the regions matrix region_func = make_k_func_region(phi) max_r = 4.0 * np.max(phi.regions, axis=0)[2] self.region_mat = get_dense_C(self.wl, k_func=region_func, max_r=max_r) print(self.region_mat) # Then set phi to None phi.regions = None #Loading file that was previously output # Convert PhiParam object to an array self.p0 = phi.toarray() jump = Starfish.config["Phi_jump"] cheb_len = (self.npoly - 1) if self.chebyshevSpectrum.fix_c0 else self.npoly cov_arr = np.concatenate( (Starfish.config["cheb_jump"]**2 * np.ones((cheb_len, )), np.array([jump["sigAmp"], jump["logAmp"], jump["l"]])**2)) cov = np.diag(cov_arr) def lnfunc(p): # Convert p array into a PhiParam object ind = self.npoly if self.chebyshevSpectrum.fix_c0: ind -= 1 cheb = p[0:ind] sigAmp = p[ind] ind += 1 logAmp = p[ind] ind += 1 l = p[ind] phi = PhiParam(self.spectrum_id, self.order, self.chebyshevSpectrum.fix_c0, cheb, sigAmp, logAmp, l) self.update_Phi(phi) lnp = self.evaluate() self.logger.debug("Evaluated Phi parameters: {} {}".format( phi, lnp)) return lnp def rejectfn(): self.logger.debug("Calling Phi revertfn.") self.revert_Phi() self.sampler = StateSampler(lnfunc, self.p0, cov, query_lnprob=self.get_lnprob, rejectfn=rejectfn, debug=True)
fname = Starfish.specfmt.format(spectrum_id, order) + "regions.json" f = open(fname, "r") read = json.load(f) # read is a dictionary f.close() mus = np.array(read["mus"]) if args.noise: sigma_mat = sigma**2 * np.eye(len(sigma)) fname = Starfish.specfmt.format(spectrum_id, order) + "phi.json" phi = PhiParam.load(fname) if phi.regions is not None: region_func = make_k_func_region(phi) max_r = 4.0 * np.max(phi.regions, axis=0)[2] region_mat = get_dense_C(wl, k_func=region_func, max_r=max_r) else: region_mat = 0.0 max_r = 6.0 * phi.l # [km/s] # Create a partial function which returns the proper element. k_func = make_k_func(phi) data_mat = get_dense_C(wl, k_func=k_func, max_r=max_r) + phi.sigAmp*sigma_mat + region_mat # Get many random draws from data_mat draws = random_draws(data_mat, num=4) min_spec, max_spec = std_envelope(draws)