layer* layer_raster::fit(provider_ptr pvd) { auto raster(pvd->fit_to_reg(m_raster)); std::vector<brig::table_def> tbls; for (size_t lvl(0); lvl < get_levels(); ++lvl) { auto tbl(get_table_def(lvl)); tbl.id.name = raster.levels[lvl].geometry.name; tbls.push_back(pvd->fit_to_create(tbl)); } return new layer_raster(pvd, raster, tbls); }
gint level_meters_expose_event(GtkWidget *widget, GdkEventExpose *event) { int idx = get_index(gtk_widget_get_name(widget)); int l1, l2; GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); get_levels(idx, &l1, &l2); redraw_meters(idx, allocation.width, allocation.height, l1, l2); gdk_draw_pixmap(gtk_widget_get_window(widget), gtk_widget_get_style(widget)->black_gc, pixmap[idx], event->area.x, event->area.y, event->area.x, event->area.y, event->area.width, event->area.height); return FALSE; }
CharacterVector reencode_factor(IntegerVector x) { CharacterVector levels(reencode_char(get_levels(x))); CharacterVector ret(x.length()); R_xlen_t nlevels = levels.length(); R_xlen_t len = x.length(); for (R_xlen_t i = 0; i < len; ++i) { int xi = x[i]; if (xi <= 0 || xi > nlevels) ret[i] = NA_STRING; else ret[i] = levels[xi - 1]; } return ret; }
gint level_meters_timeout_callback(gpointer data) { GtkWidget *widget; int idx, l1, l2; GtkAllocation allocation; update_peak_switch(); for (idx = 0; idx <= pcm_output_channels; idx++) { get_levels(idx, &l1, &l2); widget = idx == 0 ? mixer_mix_drawing : mixer_drawing[idx-1]; if (gtk_widget_get_visible(widget) && (pixmap[idx] != NULL)) { gtk_widget_get_allocation(widget, &allocation); redraw_meters(idx, allocation.width, allocation.height, l1, l2); gdk_draw_pixmap(gtk_widget_get_window(widget), gtk_widget_get_style(widget)->black_gc, pixmap[idx], 0, 0, 0, 0, allocation.width, allocation.height); } /* NPM: both cases below are special-case hack to get "Analog Volume" PCM peak levels updating correctly, should "Analog Volume" panel be selected before "Monitor PCM outs" panel. In that situation, "(gtk_widget_get_visible(widget) && (pixmap[idx] != NULL))" fails as level_meters_configure_event() hasn't been called yet (it gets called when user selects "Monitor PCM outs" panel). */ else if ((idx != 0) && ((idx-1) < envy_dac_volumes()) && (peak_changed[idx-1] == TRUE)) { draw_peak_labels(idx-1, FALSE, l1, l2); peak_changed[idx-1] = FALSE; // g_print("NPM PCM outputs hack calling draw_peak_labels(%i): %i\n", idx-1, l1); } /* NPM: make it work, even after user does a RESET, while in "Analog Volume" panel, before "Monitor PCM outs" created/configured */ else if ((idx != 0) && ((idx-1) < envy_dac_volumes()) && (peak_changed[idx-1] == RESET)) { /* note that get_levels() never retrieved l1, l2 due to unfulfilled RESET */ GtkWidget* lbl; /* NPM: Reset colors of peak labels for DACs in "Analog Volume" panel */ if ((idx-1) < envy_dac_volumes() /* index 0-8 corresponds to one of the eight DAC's */ && ((idx-1) < MAX_OUTPUT_CHANNELS) /* make sure within bounds of dac_peak_label[] */ && (lbl = dac_peak_label[idx-1]) != NULL) gtk_widget_modify_fg(lbl, GTK_STATE_NORMAL, NULL); /* reset color */ /* NPM: Reset colors of peak labels for ADCs in "Analog Volume" panel */ else if (((idx-1) >= (MAX_PCM_OUTPUT_CHANNELS+MAX_SPDIF_CHANNELS)) /* ADC channels begin at 11 = MAX_PCM_OUTPUT_CHANNELS+MAX_SPDIF_CHANNELS */ && ((idx-1) < (MAX_PCM_OUTPUT_CHANNELS+MAX_SPDIF_CHANNELS + envy_adc_volumes())) /* ADC channels end at 19 */ && (((idx-1) - (MAX_PCM_OUTPUT_CHANNELS+MAX_SPDIF_CHANNELS)) < MAX_INPUT_CHANNELS) /* make sure within bounds of adc_peak_label[] */ && (lbl = adc_peak_label[(idx-1) - (MAX_PCM_OUTPUT_CHANNELS+MAX_SPDIF_CHANNELS)]) != NULL) gtk_widget_modify_fg(lbl, GTK_STATE_NORMAL, NULL); /* reset color */ peak_changed[idx-1] = FALSE; /* hack -- force get_levels() to retrieve levels despite RESET */ get_levels(idx, &l1, &l2); draw_peak_labels(idx-1, FALSE, l1, l2); // g_print("NPM PCM outputs RESET hack calling draw_peak_labels(%i): %i\n", idx-1, l1); } } if (view_spdif_playback) { for (idx = MAX_PCM_OUTPUT_CHANNELS + 1; idx <= MAX_OUTPUT_CHANNELS + spdif_channels; idx++) { get_levels(idx, &l1, &l2); widget = idx == 0 ? mixer_mix_drawing : mixer_drawing[idx-1]; if (gtk_widget_get_visible(widget) && (pixmap[idx] != NULL)) { gtk_widget_get_allocation(widget, &allocation); redraw_meters(idx, allocation.width, allocation.height, l1, l2); gdk_draw_pixmap(gtk_widget_get_window(widget), gtk_widget_get_style(widget)->black_gc, pixmap[idx], 0, 0, 0, 0, allocation.width, allocation.height); } } } for (idx = MAX_PCM_OUTPUT_CHANNELS + MAX_SPDIF_CHANNELS + 1; idx <= input_channels + MAX_PCM_OUTPUT_CHANNELS + MAX_SPDIF_CHANNELS; idx++) { get_levels(idx, &l1, &l2); widget = idx == 0 ? mixer_mix_drawing : mixer_drawing[idx-1]; if (gtk_widget_get_visible(widget) && (pixmap[idx] != NULL)) { gtk_widget_get_allocation(widget, &allocation); redraw_meters(idx, allocation.width, allocation.height, l1, l2); gdk_draw_pixmap(gtk_widget_get_window(widget), gtk_widget_get_style(widget)->black_gc, pixmap[idx], 0, 0, 0, 0, allocation.width, allocation.height); } } for (idx = MAX_PCM_OUTPUT_CHANNELS + MAX_SPDIF_CHANNELS + MAX_INPUT_CHANNELS + 1; \ idx <= spdif_channels + MAX_PCM_OUTPUT_CHANNELS + MAX_SPDIF_CHANNELS + MAX_INPUT_CHANNELS; idx++) { get_levels(idx, &l1, &l2); widget = idx == 0 ? mixer_mix_drawing : mixer_drawing[idx-1]; if (gtk_widget_get_visible(widget) && (pixmap[idx] != NULL)) { gtk_widget_get_allocation(widget, &allocation); redraw_meters(idx, allocation.width, allocation.height, l1, l2); gdk_draw_pixmap(gtk_widget_get_window(widget), gtk_widget_get_style(widget)->black_gc, pixmap[idx], 0, 0, 0, 0, allocation.width, allocation.height); } } return TRUE; }
bool same_levels(SEXP left, SEXP right) { return character_vector_equal(get_levels(left), get_levels(right)); }
void C_Node(SEXP node, SEXP learnsample, SEXP weights, SEXP fitmem, SEXP controls, int TERMINAL, int depth) { int nobs, ninputs, jselect, q, j, k, i; double mincriterion, sweights, *dprediction; double *teststat, *pvalue, smax, cutpoint = 0.0, maxstat = 0.0; double *standstat, *splitstat; SEXP responses, inputs, x, expcovinf, linexpcov; SEXP varctrl, splitctrl, gtctrl, tgctrl, split, testy, predy; double *dxtransf, *thisweights; int *itable; nobs = get_nobs(learnsample); ninputs = get_ninputs(learnsample); varctrl = get_varctrl(controls); splitctrl = get_splitctrl(controls); gtctrl = get_gtctrl(controls); tgctrl = get_tgctrl(controls); mincriterion = get_mincriterion(gtctrl); responses = GET_SLOT(learnsample, PL2_responsesSym); inputs = GET_SLOT(learnsample, PL2_inputsSym); testy = get_test_trafo(responses); predy = get_predict_trafo(responses); q = ncol(testy); /* <FIXME> we compute C_GlobalTest even for TERMINAL nodes! </FIXME> */ /* compute the test statistics and the node criteria for each input */ C_GlobalTest(learnsample, weights, fitmem, varctrl, gtctrl, get_minsplit(splitctrl), REAL(S3get_teststat(node)), REAL(S3get_criterion(node)), depth); /* sum of weights: C_GlobalTest did nothing if sweights < mincriterion */ sweights = REAL(GET_SLOT(GET_SLOT(fitmem, PL2_expcovinfSym), PL2_sumweightsSym))[0]; REAL(VECTOR_ELT(node, S3_SUMWEIGHTS))[0] = sweights; /* compute the prediction of this node */ dprediction = REAL(S3get_prediction(node)); /* <FIXME> feed raw numeric values OR dummy encoded factors as y Problem: what happens for survival times ? */ C_prediction(REAL(predy), nobs, ncol(predy), REAL(weights), sweights, dprediction); /* </FIXME> */ teststat = REAL(S3get_teststat(node)); pvalue = REAL(S3get_criterion(node)); /* try the two out of ninputs best inputs variables */ /* <FIXME> be more flexible and add a parameter controlling the number of inputs tried </FIXME> */ for (j = 0; j < 2; j++) { smax = C_max(pvalue, ninputs); REAL(S3get_maxcriterion(node))[0] = smax; /* if the global null hypothesis was rejected */ if (smax > mincriterion && !TERMINAL) { /* the input variable with largest association to the response */ jselect = C_whichmax(pvalue, teststat, ninputs) + 1; /* get the raw numeric values or the codings of a factor */ x = get_variable(inputs, jselect); if (has_missings(inputs, jselect)) { expcovinf = GET_SLOT(get_varmemory(fitmem, jselect), PL2_expcovinfSym); thisweights = C_tempweights(jselect, weights, fitmem, inputs); } else { expcovinf = GET_SLOT(fitmem, PL2_expcovinfSym); thisweights = REAL(weights); } /* <FIXME> handle ordered factors separatly??? </FIXME> */ if (!is_nominal(inputs, jselect)) { /* search for a split in a ordered variable x */ split = S3get_primarysplit(node); /* check if the n-vector of splitstatistics should be returned for each primary split */ if (get_savesplitstats(tgctrl)) { C_init_orderedsplit(split, nobs); splitstat = REAL(S3get_splitstatistics(split)); } else { C_init_orderedsplit(split, 0); splitstat = REAL(get_splitstatistics(fitmem)); } C_split(REAL(x), 1, REAL(testy), q, thisweights, nobs, INTEGER(get_ordering(inputs, jselect)), splitctrl, GET_SLOT(fitmem, PL2_linexpcov2sampleSym), expcovinf, REAL(S3get_splitpoint(split)), &maxstat, splitstat); S3set_variableID(split, jselect); } else { /* search of a set of levels (split) in a numeric variable x */ split = S3get_primarysplit(node); /* check if the n-vector of splitstatistics should be returned for each primary split */ if (get_savesplitstats(tgctrl)) { C_init_nominalsplit(split, LENGTH(get_levels(inputs, jselect)), nobs); splitstat = REAL(S3get_splitstatistics(split)); } else { C_init_nominalsplit(split, LENGTH(get_levels(inputs, jselect)), 0); splitstat = REAL(get_splitstatistics(fitmem)); } linexpcov = get_varmemory(fitmem, jselect); standstat = Calloc(get_dimension(linexpcov), double); C_standardize(REAL(GET_SLOT(linexpcov, PL2_linearstatisticSym)), REAL(GET_SLOT(linexpcov, PL2_expectationSym)), REAL(GET_SLOT(linexpcov, PL2_covarianceSym)), get_dimension(linexpcov), get_tol(splitctrl), standstat); C_splitcategorical(INTEGER(x), LENGTH(get_levels(inputs, jselect)), REAL(testy), q, thisweights, nobs, standstat, splitctrl, GET_SLOT(fitmem, PL2_linexpcov2sampleSym), expcovinf, &cutpoint, INTEGER(S3get_splitpoint(split)), &maxstat, splitstat); /* compute which levels of a factor are available in this node (for printing) later on. A real `table' for this node would induce too much overhead here. Maybe later. */ itable = INTEGER(S3get_table(split)); dxtransf = REAL(get_transformation(inputs, jselect)); for (k = 0; k < LENGTH(get_levels(inputs, jselect)); k++) { itable[k] = 0; for (i = 0; i < nobs; i++) { if (dxtransf[k * nobs + i] * thisweights[i] > 0) { itable[k] = 1; continue; } } } Free(standstat); } if (maxstat == 0) { if (j == 1) { S3set_nodeterminal(node); } else { /* do not look at jselect in next iteration */ pvalue[jselect - 1] = R_NegInf; } } else { S3set_variableID(split, jselect); break; } } else {