static void check_consistent (GtkTreeModel *model, GtkTreeIter *child) { GtkTreeIter parent; if (gtk_tree_model_iter_parent (model, &parent, child)) { gtk_tree_store_set (GTK_TREE_STORE (model), &parent, CASE_INCONSISTENT, ! children_consistent (model, &parent), -1); check_consistent (model, &parent); } }
int PocketPLA::run_pla(){ size_t dimension = train->data_x[0].size(); // init w double * const w = new double[dimension]; for(int i=0; i<dimension; ++i) w[i] = 0; double * const w_optimal = new double[dimension]; for(int i=0; i<dimension; ++i) w_optimal[i] = 0; int min_error; // iteration size_t N = train->data_y.size(); for(int iter=0; iter<50; ++iter){ int start = rand() % N; int error_index = check_consistent(w, start); if(error_index >= N) break; for(int i=0; i<dimension; ++i){ w[i] = w[i] + (double)(train->data_y[error_index]) * train->data_x[error_index][i]; } //testing int error = testing(w); if(iter==0) min_error = error; if(error < min_error) { min_error = error; for(int i=0; i<dimension; ++i) w_optimal[i] = w[i]; } } // for q19 //min_error = testing(w); delete [] w_optimal; delete [] w; return min_error; }
static void show_case_toggled (GtkCellRendererToggle *cell, gchar *str, struct _app_data *app) { GtkTreeModel *model; GtkTreePath *path; GtkTreeIter iter; test_case_t *c; gboolean active; active = ! gtk_cell_renderer_toggle_get_active (cell); model = GTK_TREE_MODEL (app->case_store); path = gtk_tree_path_new_from_string (str); gtk_tree_model_get_iter (model, &iter, path); gtk_tree_path_free (path); gtk_tree_store_set (app->case_store, &iter, CASE_SHOWN, active, CASE_INCONSISTENT, FALSE, -1); gtk_tree_model_get (model, &iter, CASE_DATA, &c, -1); if (c != NULL) { if (active == c->shown) return; c->shown = active; } else { recurse_set_shown (model, &iter, active); } check_consistent (model, &iter); graph_view_update_visible ((GraphView *) app->gv); }