void rpcountup(pNode me, int *nnode, int *nsplit, int *ncat) { int node2, split2; int cat2; int i, j, k; pSplit ss; if (me->complexity <= rp.alpha || me->leftson == 0) { /* no kids */ *nnode = 1; *nsplit = 0; *ncat = 0; } else { i = 0; j = 0; k = 0; for (ss = me->primary; ss; ss = ss->nextsplit) { i++; if (rp.numcat[ss->var_num] > 0) k++; } for (ss = me->surrogate; ss; ss = ss->nextsplit) { j++; if (rp.numcat[ss->var_num] > 0) k++; } rpcountup(me->leftson, nnode, nsplit, ncat); rpcountup(me->rightson, &node2, &split2, &cat2); *nnode += 1 + node2; *nsplit += i + j + split2; *ncat += k + cat2; } }
/*We add an parameter myAlpha. --ZhangYet*/ void s_to_rp(Sint *n, Sint *nvarx, Sint *ncat, Sint *method, double *opt, double *parms, Sint *xvals, Sint *x_grp, double *y, FLOAT *xmat, Sint *dissim, Sint *missmat, char **error, double *wt, Sint *ny, double *cost, double *myAlpha) { int itemp; int maxpri; int rval; /* return value */ savewhich = (int *) CALLOC((int)*n, sizeof(int)); /* ** The opt string is in the order of control.rpart() ** minsplit, minbucket, cp, maxcomptete, maxsurrogate, usesurrogate, ** and xval */ maxpri = opt[3] +1; rval = rpart( (int)*n, (int)*nvarx, ncat, (int)*method, maxpri, parms, y, xmat, (int)*dissim, missmat, &cptab, &tree, &(error[0]), savewhich, (int)*xvals, x_grp, wt, opt, (int)ny[0], cost, myAlpha); /*We add a parameter myAlpha here. --ZhangYet*/ /* ** count up the number of nodes, splits, categorical splits, and cp's */ rpcountup(tree, n, nvarx, &itemp); ncat[0] = itemp; *method = rp.num_unique_cp; if (rval==1) *n= -1; /* signal an error */ }