def analyze(self, M_c, T, X_L, X_D, kernel_list=(), n_steps=1, c=(), r=(), max_iterations=-1, max_time=-1): """Evolve the latent state by running MCMC transition kernels :param M_c: The column metadata :type M_c: dict :param T: The data table in mapped representation (all floats, generated by data_utils.read_data_objects) :param X_L: the latent variables associated with the latent state :type X_L: dict :param X_D: the particular cluster assignments of each row in each view :type X_D: list of lists :param kernel_list: names of the MCMC transition kernels to run :type kernel_list: list of strings :param n_steps: the number of times to run each MCMC transition kernel :type n_steps: int :param c: the (global) column indices to run MCMC transition kernels on :type c: list of ints :param r: the (global) row indices to run MCMC transition kernels on :type r: list of ints :param max_iterations: the maximum number of times ot run each MCMC transition kernel. Applicable only if max_time != -1. :type max_iterations: int :param max_time: the maximum amount of time (seconds) to run MCMC transition kernels for before stopping to return progress :type max_time: float :returns: X_L, X_D -- the evolved latent state """ if not xu.get_is_multistate(X_L, X_D): SEED = self.get_next_seed() X_L_prime, X_D_prime = _do_analyze(M_c, T, X_L, X_D, kernel_list, n_steps, c, r, max_iterations, max_time, SEED) return X_L_prime, X_D_prime else: X_L_prime_list = [] X_D_prime_list = [] for X_L_i, X_D_i in zip(X_L, X_D): SEED = self.get_next_seed() X_L_i_prime, X_D_i_prime = _do_analyze(M_c, T, X_L_i, X_D_i, kernel_list, n_steps, c, r, max_iterations, max_time, SEED) X_L_prime_list.append(X_L_i_prime) X_D_prime_list.append(X_D_i_prime) return X_L_prime_list, X_D_prime_list
def analyze(self, M_c, T, X_L, X_D, kernel_list=(), n_steps=1, c=(), r=(), max_iterations=-1, max_time=-1): """Evolve the latent state by running MCMC transition kernels :param M_c: The column metadata :type M_c: dict :param T: The data table in mapped representation (all floats, generated by data_utils.read_data_objects) :param X_L: the latent variables associated with the latent state :type X_L: dict :param X_D: the particular cluster assignments of each row in each view :type X_D: list of lists :param kernel_list: names of the MCMC transition kernels to run :type kernel_list: list of strings :param n_steps: the number of times to run each MCMC transition kernel :type n_steps: int :param c: the (global) column indices to run MCMC transition kernels on :type c: list of ints :param r: the (global) row indices to run MCMC transition kernels on :type r: list of ints :param max_iterations: the maximum number of times ot run each MCMC transition kernel. Applicable only if max_time != -1. :type max_iterations: int :param max_time: the maximum amount of time (seconds) to run MCMC transition kernels for before stopping to return progress :type max_time: float :returns: X_L, X_D -- the evolved latent state """ if not xu.get_is_multistate(X_L, X_D): SEED = self.get_next_seed() X_L_prime, X_D_prime = _do_analyze(M_c, T, X_L, X_D, kernel_list, n_steps, c, r, max_iterations, max_time, SEED) return X_L_prime, X_D_prime else: seeds = [self.get_next_seed() for seed_idx in range(len(X_L))] args = itertools.izip( itertools.cycle([M_c]), itertools.cycle([T]), X_L, X_D, itertools.cycle([kernel_list]), itertools.cycle([n_steps]), itertools.cycle([c]), itertools.cycle([r]), itertools.cycle([max_iterations]), itertools.cycle([max_time]), seeds, ) result = self.pool.map_async(_do_analyze2, args) X_L_prime_list, X_D_prime_list = zip(*result.get()) return X_L_prime_list, X_D_prime_list
def analyze(self, M_c, T, X_L, X_D, kernel_list=(), n_steps=1, c=(), r=(), max_iterations=-1, max_time=-1, **kwargs): """Evolve the latent state by running MCMC transition kernels :param M_c: The column metadata :type M_c: dict :param T: The data table in mapped representation (all floats, generated by data_utils.read_data_objects) :type T: list of lists :param X_L: the latent variables associated with the latent state :type X_L: dict :param X_D: the particular cluster assignments of each row in each view :type X_D: list of lists :param kernel_list: names of the MCMC transition kernels to run :type kernel_list: list of strings :param n_steps: the number of times to run each MCMC transition kernel :type n_steps: int :param c: the (global) column indices to run MCMC transition kernels on :type c: list of ints :param r: the (global) row indices to run MCMC transition kernels on :type r: list of ints :param max_iterations: the maximum number of times ot run each MCMC transition kernel. Applicable only if max_time != -1. :type max_iterations: int :param max_time: the maximum amount of time (seconds) to run MCMC transition kernels for before stopping to return progress :type max_time: float :param kwargs: optional arguments to pass to hadoop_line_processor.jar. Currently, presence of a 'chunk_size' kwarg causes different behavior. :returns: X_L, X_D -- the evolved latent state """ output_path = self.output_path input_filename = self.input_filename table_data_filename = self.table_data_filename analyze_args_dict_filename = self.command_dict_filename xu.assert_vpn_is_connected() # table_data = dict(M_c=M_c, T=T) analyze_args_dict = dict(command='analyze', kernel_list=kernel_list, n_steps=n_steps, c=c, r=r, max_time=max_time) # chunk_analyze is a special case of analyze if 'chunk_size' in kwargs: chunk_size = kwargs['chunk_size'] chunk_filename_prefix = kwargs['chunk_filename_prefix'] chunk_dest_dir = kwargs['chunk_dest_dir'] analyze_args_dict['command'] = 'chunk_analyze' analyze_args_dict['chunk_size'] = chunk_size analyze_args_dict['chunk_filename_prefix'] = chunk_filename_prefix # WARNING: chunk_dest_dir MUST be writeable by hadoop user mapred analyze_args_dict['chunk_dest_dir'] = chunk_dest_dir if not xu.get_is_multistate(X_L, X_D): X_L = [X_L] X_D = [X_D] # SEEDS = kwargs.get('SEEDS', None) xu.write_analyze_files(input_filename, X_L, X_D, table_data, table_data_filename, analyze_args_dict, analyze_args_dict_filename, SEEDS) os.system('cp %s analyze_input' % input_filename) n_tasks = len(X_L) self.send_hadoop_command(n_tasks) was_successful = self.get_hadoop_results() hadoop_output = None if was_successful: hu.copy_hadoop_output(output_path, 'analyze_output') X_L_list, X_D_list = hu.read_hadoop_output(output_path) hadoop_output = X_L_list, X_D_list return hadoop_output