def __init__( self, position, k, x, y, x_indices, s_space, h_space, p_space, grid, sigma_f=1, noise_variance=0.01, Lambda_modes_list=None, term_factors=[1] * 11, ): super().__init__(position=position) self.domain = position.domain self.k, self.x, self.y = k, x, y self.x_indices = x_indices self.N = len(self.x) self.sigma_f = sigma_f self.noise_variance = noise_variance self.tau_f = position self.s_space = s_space self.h_space = h_space self.p_space = p_space self.len_p_space = self.p_space.shape[0] self.grid = grid self.fft = nifty5.FFTOperator(domain=self.s_space, target=self.h_space) self.F_h = nifty5.create_power_operator(domain=self.h_space, power_spectrum=nifty5.exp( self.tau_f)) self.F = nifty5.SandwichOperator.make(self.fft, self.F_h) self.F_matrix = probe_operator(self.F) self.F_tilde = np.zeros((self.N, self.N)) for i in range(self.N): for j in range(i + 1): self.F_tilde[i, j] = self.F_matrix[x_indices[i], x_indices[j]] if i != j: self.F_tilde[j, i] = self.F_matrix[x_indices[i], x_indices[j]] self.noise_covariance = np.diag( [self.noise_variance for i in range(self.N)]) self.G = np.linalg.inv(self.F_tilde + self.noise_covariance) self.smoothness_operator_f = nifty5.SmoothnessOperator( domain=self.p_space, logarithmic=True, strength=1 / self.sigma_f) if Lambda_modes_list is None: self.get_Lambda_modes(speedup=True) else: self.Lambda_modes_list = Lambda_modes_list self.term_factors = term_factors self.get_Lambdas()
def __init__( self, position, k, grid, sigma_beta=1, rho=1, mode='multifield', single_fields=None, term_factors=[1]*5, ): super().__init__(position=position) self.domain = position.domain self.k = k self.sigma_beta = sigma_beta self.rho = rho self.mode = mode self.fields = single_fields self.term_factors = term_factors if mode == 'multifield': self.beta = position.val['beta'] self.tau_beta = position.val['tau_beta'] else: self.fields[mode] = position self.beta = self.fields['beta'] self.tau_beta = self.fields['tau_beta'] self.s_space = self.beta.domain[0] self.h_space = self.s_space.get_default_codomain() self.p_space = self.tau_beta.domain self.len_p_space = self.p_space.shape[0] self.len_s_space = self.s_space.shape[0] self.grid = grid self.grid_coordinates = [i*self.s_space.distances[0] for i in range( self.s_space.shape[0])] # beta_vector is the R^N_bins vector with beta field values at the grid # positions self.beta_vector = np.array([self.beta.val[i] for i in self.grid]) self.fft = nifty5.FFTOperator(domain=self.s_space, target=self.h_space) self.B_inv_h = nifty5.create_power_operator( domain=self.h_space, power_spectrum=nifty5.exp(-self.tau_beta)) self.B_inv = nifty5.SandwichOperator.make(self.fft, self.B_inv_h) self.smoothness_operator_beta = nifty5.SmoothnessOperator( domain=self.p_space, strength=1/self.sigma_beta) self.get_del_B()
def test_func(): f1 = ift.from_random("normal", domain=dom, dtype=np.complex128) assert_allclose( ift.log(ift.exp((f1)))["d1"].local_data, f1["d1"].local_data)
def __init__( self, position, k, x, y, grid, sigma_f=1, sigma_beta=1, sigma_eta=1, rho=1, mode='multifield', single_fields=None, Lambda_modes_list=None, term_factors=[1]*11, ): super().__init__(position=position) self.domain = position.domain self.k, self.x, self.y = k, x, y self.N = len(self.x) self.sigma_beta = sigma_beta self.sigma_f = sigma_f self.sigma_eta = sigma_eta self.rho = rho self.mode = mode self.fields = single_fields if mode == 'multifield': self.beta = position.val['beta'] self.tau_beta = position.val['tau_beta'] self.tau_f = position.val['tau_f'] self.eta = position.val['eta'] else: self.fields[mode] = position self.beta = self.fields['beta'] self.tau_beta = self.fields['tau_beta'] self.tau_f = self.fields['tau_f'] self.eta = self.fields['eta'] self.s_space = self.beta.domain[0] self.h_space = self.s_space.get_default_codomain() self.p_space = self.tau_f.domain self.len_p_space = self.p_space.shape[0] self.len_s_space = self.s_space.shape[0] self.grid = grid self.grid_coordinates = [i*self.s_space.distances[0] for i in range( self.s_space.shape[0])] # beta_vector is the R^N_bins vector with beta field values at the grid # positions self.beta_vector = np.array([self.beta.val[i] for i in self.grid]) self.fft = nifty5.FFTOperator(domain=self.s_space, target=self.h_space) self.F_h = nifty5.create_power_operator( domain=self.h_space, power_spectrum=nifty5.exp(self.tau_f)) self.B_inv_h = nifty5.create_power_operator( domain=self.h_space, power_spectrum=nifty5.exp(-self.tau_beta)) self.B_inv = nifty5.SandwichOperator.make(self.fft, self.B_inv_h) self.F = nifty5.SandwichOperator.make(self.fft, self.F_h) self.F_matrix = probe_operator(self.F) self.F_tilde = np.zeros((self.N, self.N)) for i in range(self.N): for j in range(i+1): self.F_tilde[i, j] = self.F_matrix[ self.x_indices[i], self.x_indices[j]] if i != j: self.F_tilde[j, i] = self.F_matrix[ self.x_indices[i], self.x_indices[j]] self.exp_hat_eta_x = np.diag([np.exp( self.eta.val[self.x_indices[i]]) for i in range(self.N)]) self.G = np.linalg.inv(self.F_tilde + self.exp_hat_eta_x) self.smoothness_operator_f = nifty5.SmoothnessOperator( domain=self.p_space, strength=1/self.sigma_f) self.smoothness_operator_beta = nifty5.SmoothnessOperator( domain=self.p_space, strength=1/self.sigma_beta) # second derivative of eta nabla_nabla_eta = np.zeros(self.eta.val.shape) scipy.ndimage.laplace( input=self.eta.val, output=nabla_nabla_eta) self.nabla_nabla_eta_field = nifty5.Field( domain=self.s_space, val=nabla_nabla_eta) if Lambda_modes_list is None: self.get_Lambda_modes(speedup=True) else: self.Lambda_modes_list = Lambda_modes_list self.term_factors = term_factors self.get_Lambdas() self.get_del_B() self.get_del_exp_eta_x()
HT = ift.HarmonicTransformOperator(harmonic_space, position_space) # Domain on which the field's degrees of freedom are defined domain = ift.DomainTuple.make(harmonic_space) # Define amplitude (square root of power spectrum) def sqrtpspec(k): return 1. / (20. + k**2) p_space = ift.PowerSpace(harmonic_space) pd = ift.PowerDistributor(harmonic_space, p_space) a = ift.PS_field(p_space, sqrtpspec) A = pd(a) # Define sky operator sky = ift.exp(HT(ift.makeOp(A))) M = ift.DiagonalOperator(exposure) GR = ift.GeometryRemover(position_space) # Define instrumental response R = GR(M) # Generate mock data and define likelihood operator d_space = R.target[0] lamb = R(sky) mock_position = ift.from_random('normal', domain) data = lamb(mock_position) data = np.random.poisson(data.to_global_data().astype(np.float64)) data = ift.Field.from_global_data(d_space, data) likelihood = ift.PoissonianEnergy(data)(lamb)