def _modeler(train_inds, test_inds, flux_arr, model, method): new_model = est_clone(model) flux_train = flux_arr[train_inds] #print("Training new model: " + str(new_model)) if method == 'KPCA': new_model.fit_inverse_transform = False new_model.fit(flux_train) sqrt_lambdas = np.diag(np.sqrt(model.lambdas_)) X_transformed = np.dot(model.alphas_, sqrt_lambdas) n_samples = X_transformed.shape[0] K = new_model._get_kernel(X_transformed) K.flat[::n_samples + 1] += model.alpha new_model.dual_coef_ = linalg.solve(K, flux_train) new_model.X_transformed_fit_ = X_transformed new_model.fit_inverse_transform = True else: if np.any(np.isinf(flux_train)): print("The given flux_train array contains inf's!") if np.any(np.isnan(flux_train)): print("The given flux_train array contains nan's!") new_model.fit(flux_train) #print("Returning new model: " + str(new_model)) return new_model
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