def _run(args): data = args[0] checkpoint = args[1] t_id = args[2] verbose = args[3] init_kwargs = args[4] trans_kwargs = args[5] # create copy of trans_kwargs so we don't mutate trans_kwargs = dict(trans_kwargs) n_iter = trans_kwargs['N'] if checkpoint is None: checkpoint = n_iter n_sweeps = 1 else: trans_kwargs['N'] = checkpoint n_sweeps = int(n_iter / checkpoint) diagnostics = [] state = BCState(data.T, **init_kwargs) # transpose dat to col-major for i in range(n_sweeps): t_start = time.time() state.transition(**trans_kwargs) t_iter = time.time() - t_start n_views = state.n_views log_score = state.log_score() diagnostic = { 'log_score': log_score, 'n_views': n_views, 'iters': checkpoint, 'time': t_iter } diagnostics.append(diagnostic) if verbose: msg = "Model {}:\n\t+ sweep {} of {} in {} sec." msg += "\n\t+ log score: {}" msg += "\n\t+ n_views: {}\n" print(msg.format(t_id, i, n_sweeps, t_iter, log_score, n_views)) metadata = state.get_metadata() return metadata, diagnostics
def _run(args): data = args[0] checkpoint = args[1] t_id = args[2] verbose = args[3] init_kwargs = args[4] trans_kwargs = args[5] # create copy of trans_kwargs so we don't mutate trans_kwargs = dict(trans_kwargs) n_iter = trans_kwargs['N'] if checkpoint is None: checkpoint = n_iter n_sweeps = 1 else: trans_kwargs['N'] = checkpoint n_sweeps = int(n_iter/checkpoint) diagnostics = [] state = BCState(data.T, **init_kwargs) # transpose dat to col-major for i in range(n_sweeps): t_start = time.time() state.transition(**trans_kwargs) t_iter = time.time() - t_start n_views = state.n_views log_score = state.log_score() diagnostic = { 'log_score': log_score, 'n_views': n_views, 'iters': checkpoint, 'time': t_iter} diagnostics.append(diagnostic) if verbose: msg = "Model {}:\n\t+ sweep {} of {} in {} sec." msg += "\n\t+ log score: {}" msg += "\n\t+ n_views: {}\n" print(msg.format(t_id, i, n_sweeps, t_iter, log_score, n_views)) metadata = state.get_metadata() return metadata, diagnostics
def test_transition(gdat): X, _, _ = gdat bcstate = BCState(X) bcstate.transition()