def unwrap_self_peek_model_queue(PGE): MAXFEV = 100 if PGE.remote_eval == True: MAXFEV = 2 pos, modl = -1, None while True: try: val = PGE.peek_in_queue.get() if val is None: print("Val None Breaking Peek Processor") break; pos = val[0] modl = val[1] # print("GOT HERE 1:", pos) passed = False passed = evaluate.eval_model(modl, PGE.vars, PGE.X_peek, PGE.Y_peek, PGE.err_method, MAXFEV=MAXFEV) if not passed: # print("Failed!!", pos, modl.error) PGE.peek_out_queue.put( (pos, modl.error, modl.exception) ) else: # print("Passed!!", pos, modl.id) vals = [ (k,v) for (k,v) in modl.params.valuesdict().items() ] # print("GOT HERE 2:", pos) ret_data = { 'score': modl.score, 'r2': modl.r2, 'evar': modl.evar, 'aic': modl.aic, 'bic': modl.bic, 'chisqr': modl.chisqr, 'redchi': modl.redchi, 'params': vals, 'nfev': modl.fit_result.nfev } # print("GOT HERE A:", pos) PGE.peek_out_queue.put( (pos, None, ret_data) ) # print("GOT HERE B:", pos) except Exception as e: print("peek breaking!", e, "\n ", pos, modl.id, modl.expr, val) break
def unwrap_self_eval_model_queue(PGE): MAXFEV = 100 if PGE.remote_eval == True: MAXFEV = 2 while True: try: val = PGE.eval_in_queue.get() if val is None: print("Val None Breaking Eval Processor") break; pos = val[0] modl = val[1] passed = False passed = evaluate.eval_model(modl, PGE.vars, PGE.X_train, PGE.Y_train, PGE.err_method, MAXFEV=MAXFEV) if not passed: PGE.eval_out_queue.put( (pos, modl.error, modl.exception) ) else: vals = [ (k,v) for (k,v) in modl.params.valuesdict().items() ] # vals = modl.params.valuesdict() ret_data = { 'score': modl.score, 'r2': modl.r2, 'evar': modl.evar, 'aic': modl.aic, 'bic': modl.bic, 'chisqr': modl.chisqr, 'redchi': modl.redchi, 'params': vals, 'nfev': modl.fit_result.nfev } PGE.eval_out_queue.put( (pos, None, ret_data) ) except Exception as e: print("eval breaking!", e, "\n ", pos, modl.expr, passed, modl.params.valuesdict()) break
def eval_models_local(self, models, peek=False, progress=False): if self.workers > 0: self.eval_models_multiprocess(models, peek, progress) else: L = len(models) ppp = L / 10 PPP = ppp if progress: which = "peek'n" if peek else "eval'n" print(" ", which, L, ppp, " ", end="", flush=True) for i,modl in enumerate(models): if progress and i >= PPP: print('.',end="",flush=True) PPP += ppp passed = evaluate.eval_model(modl, self.vars, self.X_train, self.Y_train, self.err_method) if not passed or modl.error is not None: info = "{:5d} ERROR ".format(modl.id) print(info, modl.expr, modl.jac, file=self.logs["evals"]) else: if peek: modl.peek_score = modl.score modl.peek_r2 = modl.r2 modl.peek_evar = modl.evar modl.peek_aic = modl.aic modl.peek_bic = modl.bic modl.peek_chisqr = modl.chisqr modl.peek_redchi = modl.redchi modl.peek_nfev = dat['nfev'] self.peek_nfev += modl.peek_nfev self.peekd_models += 1 modl.peeked = True else: modl.eval_nfev += dat['nfev'] self.eval_nfev += modl.eval_nfev self.evald_models += 1 modl.evaluated = True # info = "{:5d} {:5d} ".format(modl.id, modl.eval_nfev) # print(info, modl.expr, modl.jac, file=self.logs["evals"]) if modl.parent_id >= 0: parent = self.models[modl.parent_id] modl.improve_score = parent.score - modl.score modl.improve_r2 = modl.r2 - parent.r2 modl.improve_evar = modl.evar - parent.evar modl.improve_aic = parent.aic - modl.aic modl.improve_bic = parent.bic - modl.bic modl.improve_redchi = parent.redchi - modl.redchi else: # should probaly normalized this across the initial population and permenately set modl.improve_score = -0.000001 * modl.score modl.improve_r2 = -0.000001 * modl.r2 modl.improve_evar = -0.000001 * modl.evar modl.improve_aic = -0.000001 * modl.aic modl.improve_bic = -0.000001 * modl.bic modl.improve_redchi = -0.000001 * modl.redchi if progress: print("")