def _iter_scorer(train_inds, test_inds, flux_arr, model__and__model_flux_mean, method, score_methods, include_mle): model = model__and__model_flux_mean[0] model_flux_mean = model__and__model_flux_mean[1] flux_test = flux_arr[test_inds] flux_conv_test = None if score_methods != ['LL']: for pca_model in model: if flux_conv_test is None: flux_conv_test = iz.transform_inverse_transform(flux_test, pca_model, model_flux_mean, method) flux_test -= flux_conv_test else: residual = iz.transform_inverse_transform(flux_test, pca_model, model_flux_mean, method) flux_conv_test += residual flux_test -= residual scores = {} for score_method in score_methods: #print("Calculating score:" + score_method) score_func = iz.get_score_func(score_method) if score_func is not None: if score_method != 'MAE': scores[score_method] = score_func(flux_test, flux_conv_test, multioutput='uniform_average') else: scores[score_method] = np.mean(np.median(np.abs(flux_test - flux_conv_test), axis=1)) if (include_mle or score_method == 'LL') and method in ['FA', 'PCA']: try: scores['mle'] = model.score(flux_test) except np.linalg.linalg.LinAlgError: scores['mle'] = 0 #-2**10 #float("-inf") except ValueError: scores['mle'] = 0 #-2**10 #float("-inf") #print("Scores: " + str(scores)) return scores
def _iter_modeler(train_inds, test_inds, flux_arr, model, method): model_list = [] flux_train = flux_arr[train_inds] flux_avg = np.mean(flux_train, axis=0) for i in range(2): new_model = est_clone(model) new_model.fit(flux_train) back_train = iz.transform_inverse_transform(flux_train, new_model, flux_avg, method) flux_train -= back_train model_list.append(new_model) return model_list, flux_avg