Skip to content
Snippets Groups Projects
Commit 369a053a authored by Luc Giffon's avatar Luc Giffon
Browse files

solve bug solution too fast

parent dcbb16f2
No related branches found
No related tags found
1 merge request!24Resolve "non negative omp"
......@@ -72,6 +72,9 @@ class NonNegativeOrthogonalMatchingPursuit:
tmp_T = T[:, bool_arr_selected_indexes]
sol = nnls(tmp_T, y)[0] # non negative least square
residual = y - tmp_T @ sol
int_used_atoms = np.sum(sol.astype(bool))
if int_used_atoms != i+1:
self._logger.warning("Atom found but not used. {} < {}".format(int_used_atoms, i+1))
if i + 1 == next_solution:
final_vec = np.zeros(T.shape[1])
......@@ -81,6 +84,11 @@ class NonNegativeOrthogonalMatchingPursuit:
i += 1
if len(lst_intermediate_solutions) == 0 and np.isclose(np.linalg.norm(residual), 0):
final_vec = np.zeros(T.shape[1])
final_vec[bool_arr_selected_indexes] = sol # solution is full of zero but on selected indices
lst_intermediate_solutions.append(final_vec)
nb_missing_solutions = len(self.requested_intermediate_solutions_sizes) - len(lst_intermediate_solutions)
if nb_missing_solutions > 0:
......
......@@ -115,6 +115,7 @@ if __name__ == "__main__":
print("Score full forest on test", nn_ompforest.score_base_estimator(X_test, y_test))
print("Size full forest", nnmodel_params.hyperparameters["n_estimators"])
print("Size extracted forests", intermediate_solutions)
print("Actual size extracted forest", [np.sum(coef.astype(bool)) for coef in nn_ompforest._omp.get_coef()])
print("Score non negative omp on train", nn_ompforest.score(X_train, y_train))
print("Score non negative omp on test", nn_ompforest.score(X_test, y_test))
print("Score omp on train", omp_forest.score(X_train, y_train))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment