Example #1
0
/* Given one set of values from one margin, do the actual scaling.
 On the first pass, this function takes notes on each margin's element list and total 
 in the original data. Later passes just read the notes and call the scaling() function above.
*/
static void one_set_of_values(mnode_t *const * const icon, const int ctr, void *in){
    rake_t *r = in;
    int size = r->indata->matrix->size1;
    static bool *t = NULL;
    if (!t) t = malloc(size * sizeof(bool));
	int first_pass = 0;
    double in_sum;
	if (ctr < r->ct)
		in_sum = gsl_vector_get(r->indata_values, ctr);
    else {
        r->ct++;
        if (ctr >= r->al) rakeinfo_grow(r);
   		index_get_element_list(icon, t);
        in_sum = 0;
        int n=0, al=0;
        r->elmtlist[ctr] = NULL;
        for(int m=0; m < size; m++)
            if (t[m]){
                in_sum += r->indata->weights->data[m];
                if (n >= al) {
                    al = (al+1)*2;
                    r->elmtlist[ctr] = realloc(r->elmtlist[ctr], al*sizeof(size_t));
                }
                r->elmtlist[ctr][n++] = m;
            }
        r->elmtlist_sizes[ctr] = n;
        r->indata_values->data[ctr] = in_sum;
		first_pass++;
	}
    if (!r->elmtlist_sizes[ctr]) return;
    if (!first_pass && !in_sum)  return;
    scaling(r->elmtlist[ctr], r->elmtlist_sizes[ctr], r->fit->weights, in_sum);
}
Example #2
0
/* Given one set of values from one margin, do the actual scaling.
 On the first pass, this function takes notes on each margin's element list and total 
 in the original data. Later passes just read the notes and call the scaling() function above.
*/
static void one_set_of_values(mnode_t *const * const margincons, int ctr, void *in){
    rake_t *r = in;
    size_t marginsize = r->indata->matrix->size1;
    size_t fitsize = r->fit->matrix->size1;
    bool melmts[marginsize];
    bool fitelmts[fitsize];
	bool first_pass = false;
    double in_sum;
	if (ctr < r->ct)
		in_sum = gsl_vector_get(r->indata_values, ctr);
    else {
        r->ct++;
        if (ctr >= r->al || r->al==0) rakeinfo_grow(r);
   		index_get_element_list(margincons, melmts, marginsize, true);
   		index_get_element_list(margincons, fitelmts, fitsize, false);
        in_sum = 0;
        int n=0, al=0;
        r->elmtlist[ctr] = NULL;
        //use margin index to get total for this margin.
        for(int m=0; m < marginsize; m++)
            if (melmts[m]) in_sum += r->indata->weights->data[m];
        //use fit index to get elements involved in this margin
        for(int m=0; m < fitsize; m++)
            if (fitelmts[m]){
                if (n >= al) {
                    al = (al+1)*2;
                    r->elmtlist[ctr] = realloc(r->elmtlist[ctr], al*sizeof(size_t));
                }
                r->elmtlist[ctr][n++] = m;
            }
        r->elmtlist_sizes[ctr] = n;
        r->indata_values->data[ctr] = in_sum;
		first_pass = true;
	}
    if (!r->elmtlist_sizes[ctr]) return;
    if (!first_pass && !in_sum)  return;
    scaling(r->elmtlist[ctr], r->elmtlist_sizes[ctr], r->fit->weights, in_sum, r->maxdev);
}