def __init__(self, *, uid=None, grid_context=None, K=1, block_type='msoa', hmc_all_iterations=100000, hmc_burn_in=25000, hmc_calibration=50000, hmc_info_interval=20000, hmc_thinning=5, verbose=False, lengthscale=1):
    self.uid = uid
    self.context = grid_context
    self.K = K
    self.NN = self.context.mask.shape[0]
    self.hmc_thinning = hmc_thinning
    self.hmc_info_interval = hmc_info_interval
    self.N = grid_context.counts.shape[0]
    self.J = self.context.J
    initial_Z = np.zeros((self.N, self.K), dtype=int)
    initial_Z[(np.arange(self.N), np.random.choice(self.K, self.N))] = 1
    self.Z_samples = []
    if (block_type == 'lad'):
        block_assignment = np.asarray(grid_context.lads)
    elif (block_type == 'msoa'):
        block_assignment = np.asarray(grid_context.msoas)
    elif (block_type == 'ward'):
        block_assignment = np.asarray(grid_context.wards)
    else:
        block_assignment = np.repeat(1, self.N)
    block_centroid_file_path = (((Path(os.getcwd()) / 'data') / 'processed') / f'{block_type}-centroids-map.csv')
    block_centroids = pd.read_csv(block_centroid_file_path)
    self.coord_x = block_centroids['x'].values
    self.coord_x = (self.coord_x - np.min(self.coord_x))
    self.coord_y = block_centroids['y'].values
    self.coord_y = (self.coord_y - np.min(self.coord_y))
    self.block_labels = block_centroids.iloc[:, 1].values
    unique_block_labels = np.unique(self.block_labels)
    self.block_assignment_numeric = np.zeros(block_assignment.shape[0], dtype=np.int)
    for (idx_cell, block_label) in enumerate(block_assignment):
        self.block_assignment_numeric[idx_cell] = np.where((unique_block_labels == block_label))[0]
    self.block_assignment = block_assignment
    B = (np.max(self.block_assignment_numeric) + 1)
    self.B = B
    self.lengthscale = lengthscale
    self.beta_prior = BetaPriorWithIntercept(a=1, b=0.01)
    self.f_prior = GPNonGridPriorSqExpFixed(coord_x=self.coord_x, coord_y=self.coord_y, variance=100, lengthscale=self.lengthscale)
    self.log_theta_prior = GaussianPrior(mean=np.asarray([0]), variance=np.asarray([100.0]))
    init_beta_estimand = np.random.normal(0, 1, (self.context.J * self.K))
    init_beta_mass_matrix = (1000.0 * np.ones((self.context.J * self.K)))
    self.beta_sampler = HMCSampler(func_lpdf=self.beta_loglik, func_nabla_lpdf=self.nabla_beta_loglik, func_plot=(self.plot_beta if verbose else None), init_estimand=init_beta_estimand, init_M_diag=init_beta_mass_matrix, init_L=20, init_epsilon=0.05, n_burnin=hmc_burn_in, n_calib=hmc_calibration, S=hmc_all_iterations, n_info_interval=hmc_info_interval, thinning=hmc_thinning, unique_estimation_id=uid, adaptive=True)
    init_f_estimand = np.random.normal(0, 1, (B * self.K))
    init_f_mass_matrix = (10000.0 * np.ones((B * self.K)))
    self.f_sampler = HMCSampler(func_lpdf=self.f_loglik, func_nabla_lpdf=self.nabla_f_loglik, func_plot=(self.plot_f if verbose else None), init_estimand=init_f_estimand, init_M_diag=init_f_mass_matrix, init_L=100, init_epsilon=0.05, n_burnin=hmc_burn_in, n_calib=hmc_calibration, S=hmc_all_iterations, n_info_interval=hmc_info_interval, thinning=hmc_thinning, unique_estimation_id=uid, adaptive=False)
    self.current_beta = self.beta_sampler.estimand
    self.current_f = self.f_sampler.estimand
    self.current_Z = initial_Z
    self.logger = logging.getLogger(__name__)
def __init__(self, *, uid=None, grid_context=None, K=1, block_type='msoa', hmc_all_iterations=100000, hmc_burn_in=25000, hmc_calibration=50000, hmc_info_interval=20000, hmc_thinning=5, verbose=False, lengthscale=1):
    self.uid = uid
    self.context = grid_context
    self.K = K
    self.NN = self.context.mask.shape[0]
    self.hmc_thinning = hmc_thinning
    self.hmc_info_interval = hmc_info_interval
    self.N = grid_context.counts.shape[0]
    self.J = self.context.J
    initial_Z = np.zeros((self.N, self.K), dtype=int)
    initial_Z[(np.arange(self.N), np.random.choice(self.K, self.N))] = 1
    self.Z_samples = []
    if (block_type == 'lad'):
        block_assignment = np.asarray(grid_context.lads)
    elif (block_type == 'msoa'):
        block_assignment = np.asarray(grid_context.msoas)
    elif (block_type == 'ward'):
        block_assignment = np.asarray(grid_context.wards)
    else:
        block_assignment = np.repeat(1, self.N)
    block_centroid_file_path = (((Path(os.getcwd()) / 'data') / 'processed') / f'{block_type}-centroids-map.csv')
    block_centroids = pd.read_csv(block_centroid_file_path)
    self.coord_x = block_centroids['x'].values
    self.coord_x = (self.coord_x - np.min(self.coord_x))
    self.coord_y = block_centroids['y'].values
    self.coord_y = (self.coord_y - np.min(self.coord_y))
    self.block_labels = block_centroids.iloc[:, 1].values
    unique_block_labels = np.unique(self.block_labels)
    self.block_assignment_numeric = np.zeros(block_assignment.shape[0], dtype=np.int)
    for (idx_cell, block_label) in enumerate(block_assignment):
        self.block_assignment_numeric[idx_cell] = np.where((unique_block_labels == block_label))[0]
    self.block_assignment = block_assignment
    B = (np.max(self.block_assignment_numeric) + 1)
    self.B = B
    self.lengthscale = lengthscale
    self.beta_prior = BetaPriorWithIntercept(a=1, b=0.01)
    self.f_prior = GPNonGridPriorSqExpFixed(coord_x=self.coord_x, coord_y=self.coord_y, variance=100, lengthscale=self.lengthscale)
    self.log_theta_prior = GaussianPrior(mean=np.asarray([0]), variance=np.asarray([100.0]))
    init_beta_estimand = np.random.normal(0, 1, (self.context.J * self.K))
    init_beta_mass_matrix = (1000.0 * np.ones((self.context.J * self.K)))
    self.beta_sampler = HMCSampler(func_lpdf=self.beta_loglik, func_nabla_lpdf=self.nabla_beta_loglik, func_plot=(self.plot_beta if verbose else None), init_estimand=init_beta_estimand, init_M_diag=init_beta_mass_matrix, init_L=20, init_epsilon=0.05, n_burnin=hmc_burn_in, n_calib=hmc_calibration, S=hmc_all_iterations, n_info_interval=hmc_info_interval, thinning=hmc_thinning, unique_estimation_id=uid, adaptive=True)
    init_f_estimand = np.random.normal(0, 1, (B * self.K))
    init_f_mass_matrix = (10000.0 * np.ones((B * self.K)))
    self.f_sampler = HMCSampler(func_lpdf=self.f_loglik, func_nabla_lpdf=self.nabla_f_loglik, func_plot=(self.plot_f if verbose else None), init_estimand=init_f_estimand, init_M_diag=init_f_mass_matrix, init_L=100, init_epsilon=0.05, n_burnin=hmc_burn_in, n_calib=hmc_calibration, S=hmc_all_iterations, n_info_interval=hmc_info_interval, thinning=hmc_thinning, unique_estimation_id=uid, adaptive=False)
    self.current_beta = self.beta_sampler.estimand
    self.current_f = self.f_sampler.estimand
    self.current_Z = initial_Z
    self.logger = logging.getLogger(__name__)