Пример #1
0
void Block::outArg(
    Session &session,
    Instance &caller, Instance &instance,
    size_t position, size_t index, Node &arg
) {
    if (
        index >= params.size()
        || params[index].second == ParamMode::special
    ) {
        outSpecialArg(
            session, caller, instance,
            position, index, arg
        );
    } else if (
        params[index].second == ParamMode::out
        || params[index].second == ParamMode::var
    ) {
        arg.buildIn(
            session, caller,
            instance.at(params[index].first),
            [&, position, index](Type &) {
                return caller.strCallee(position)
                    + "->data." + params[index].first;
            }
        );
    }
}
Пример #2
0
/* ************************************************************************
 * Function that evaluates the quality of the current split
 * param :
 * 		node : the current node to be split
 * 		attInd : the index of the current feature to be evaluated as a splitting criterion
 * 		sortedInd : the 1D sorted instance index array of the corresponding attribute
 * 		splitPoint : a double pointer to receive the splitting point
 * 		eval0 : the evaluation measure of the current node's subset
 * 		w_size : the weighted size of the current node's subset
 *
 * return the value of the best split point evaluation, i.e. the best measure for the current criterion
 */
long double 	Cart::evalAttribute(Node * node, u_int attInd, u_int * sortedInd, double * splitPoint, double eval0, double w_size)
{
    DataHandler * data = node->getDataSet();
    u_int nbClass = data->getNbClass();
    bool ok = false;

    if(data->getAttribute(attInd)->is_nominal())
    {
        /*********** Nominal Attribute **************/
        return 0.0;
    }
    else
    {
        /*********** Numeric Attribute **************/
        double * totEff = new double[2];
        totEff[0] = 0.0;
        totEff[1] = 0.0;
        double ** classEff = new double*[2];
        classEff[0] = new double[nbClass];
        classEff[1] = new double[nbClass];

        for(u_int i=0; i<nbClass; i++)
        {
            classEff[0][i] = 0.0;
            classEff[1][i] = data->getDistrib(i);
            totEff[1] += classEff[1][i];
        }

        double currSplit = trainSet->getInstance(sortedInd[0])->at(attInd);
        long double bestEval = -(numeric_limits<long double>::max());

        for(u_int i=0; i<data->size(); i++)
        {
            Instance * inst = trainSet->getInstance(sortedInd[i]);
            double currVal = inst->at(attInd);
            u_int currClass = data->getClass(inst);
            double currWeight = data->getWeight(inst);

            if(currVal > currSplit)
            {
                long double currEval = eval0 - eval(w_size,nbClass,classEff,totEff,(u_int)2);
                if((currEval > 0) && (currEval > bestEval))
                {
                    ok = true;
                    bestEval = currEval;
                    (*splitPoint) = (currVal + currSplit) / 2.0;
                }
            }

            currSplit = currVal;
            classEff[0][currClass] += currWeight;
            classEff[1][currClass] -= currWeight;
            totEff[0] += currWeight;
            totEff[1] -= currWeight;
        }

        delete[] totEff;
        delete[] classEff[0];
        delete[] classEff[1];
        delete[] classEff;

        if(ok) return bestEval;
        else return -1.0;
    }
}