Example #1
0
/**
  * Main function
  */
int main(int argc, char *argv[])
{
    string xtr_file, xte_file, ytr_file, yte_file;

    // check that all inputs are given
    if(argc<4)
    {
        std::cout << "========================================================================================"<< std::endl
                  << " Wrong parameters number ("<<argc <<")." << std::endl
                  << " Provide a valid path for training, test and output files using the following syntax:" << std::endl
                  << " \n\n\t " << argv[0] << " xtr xte ytr yte" << std::endl
                  << "========================================================================================" << std::endl << std::endl;
        return 0;
    }

    // get file names from input
    xtr_file = argv[1];
    xte_file = argv[2];
    ytr_file = argv[3];
    yte_file = argv[4];

    try
    {
        gMat2D<T> Xtr, Xte, ytr, yte;

        // load data from file
        Xtr.readCSV(xtr_file);
        Xte.readCSV(xte_file);
        ytr.readCSV(ytr_file);
        yte.readCSV(yte_file);

        // specify the task sequence
        OptTaskSequence *seq = new OptTaskSequence();
        *seq << "paramsel:loocvprimal" << "optimizer:rlsprimal" << "pred:primal" << "perf:macroavg";
        // *seq << "kernel:linear" << "paramsel:loocvdual" << "optimizer:rlsdual" << "pred:dual" << "perf:macroavg";
        // *seq << "paramsel:siglam"
        //      << "kernel:rbf"
        //      << "optimizer:rlsdual"
        //      << "predkernel:traintest"
        //      << "pred:dual"
        //      << "perf:macroavg";

        GurlsOptionsList * process = new GurlsOptionsList("processes", false);

        // defines instructions for training process
        OptProcess* process1 = new OptProcess();
        *process1 << GURLS::computeNsave << GURLS::computeNsave << GURLS::ignore << GURLS::ignore;
        // *process1 << GURLS::computeNsave << GURLS::computeNsave << GURLS::computeNsave << GURLS::ignore << GURLS::ignore;
        // *process1 << GURLS::computeNsave
        //           << GURLS::computeNsave
        //           << GURLS::computeNsave
        //           << GURLS::ignore
        //           << GURLS::ignore
        //           << GURLS::ignore;
        process->addOpt("one", process1);

        // defines instructions for testing process
        OptProcess* process2 = new OptProcess();
        *process2 << GURLS::load << GURLS::load<< GURLS::computeNsave << GURLS::computeNsave;
        // *process2 << GURLS::load << GURLS::load << GURLS::load<< GURLS::compute << GURLS::compute;
        // *process2 << GURLS::load
        //           << GURLS::load
        //           << GURLS::ignore
        //           << GURLS::compute
        //           << GURLS::compute
        //           << GURLS::compute;
        process->addOpt("two", process2);

        // build an options' structure
        GurlsOptionsList* opt = new GurlsOptionsList("GURLSlooprimal", true);
        opt->addOpt("seq", seq);
        opt->addOpt("processes", process);

        GURLS G;

        string jobId0("one");
        string jobId1("two");

        clock_t    start = std::clock();

        // run gurls for training
        G.run(Xtr, ytr, *opt, jobId0);

        // run gurls for testing
        G.run(Xte, yte, *opt, jobId1);

        cout << "Elased time is " << (clock() - start) / (double)(CLOCKS_PER_SEC) << endl;

        cout << "Accuracy: ";
        cout << OptMatrix<gMat2D<T> >::dynacast(GurlsOptionsList::dynacast(opt->getOpt("perf"))->getOpt("acc"))->getValue()[0][0] << endl;


    }
    catch (gException& e)
    {
        cout << e.getMessage() << endl;
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;

}
Example #2
0
void GurlsOptionsList::copyOpt(string key, const GurlsOptionsList &from)
{

    const GurlsOption* toCopy = from.getOpt(key);

    GurlsOption* newOpt = NULL;

    switch(toCopy->getType())
    {
    case StringOption:
        newOpt = new OptString(OptString::dynacast(toCopy)->getValue());
        break;
    case NumberOption:
        newOpt = new OptNumber(OptNumber::dynacast(toCopy)->getValue());
        break;
    case StringListOption:
        newOpt = new OptStringList(OptStringList::dynacast(toCopy)->getValue());
        break;
    case NumberListOption:
        newOpt = new OptNumberList(OptNumberList::dynacast(toCopy)->getValue());
        break;
    case FunctionOption:
        newOpt = new OptFunction(OptFunction::dynacast(toCopy)->getName());
        break;
    case ProcessOption:
        newOpt = new OptProcess(*OptProcess::dynacast(toCopy));
        break;
    case MatrixOption:
    case VectorOption:
    {
       const OptMatrixBase* base = dynamic_cast<const OptMatrixBase*>(toCopy);

        if(base == NULL)
            throw gException(Exception_Illegal_Dynamic_Cast);

#ifdef _BGURLS
        if(base->hasBigArray())
        {
            switch(base->getMatrixType())
            {
                case OptMatrixBase::ULONG:
                    newOpt = copyOptMatrix<BigArray<unsigned long> >(toCopy);
                    break;
                case OptMatrixBase::FLOAT:
                    newOpt = copyOptMatrix<BigArray<float> >(toCopy);
                    break;
                case OptMatrixBase::DOUBLE:
                    newOpt = copyOptMatrix<BigArray<double> >(toCopy);
                    break;
            }
        }
        else
#endif
        {
            switch(base->getMatrixType())
            {
                case OptMatrixBase::ULONG:
                    newOpt = copyOptMatrix<gMat2D<unsigned long> >(toCopy);
                    break;
                case OptMatrixBase::FLOAT:
                    newOpt = copyOptMatrix<gMat2D<float> >(toCopy);
                    break;
                case OptMatrixBase::DOUBLE:
                    newOpt = copyOptMatrix<gMat2D<double> >(toCopy);
                    break;
            }
        }

    }
        break;
    case OptListOption:
    {
        const GurlsOptionsList* toCopy_list = GurlsOptionsList::dynacast(toCopy);

        newOpt = new GurlsOptionsList(*toCopy_list);
    }
        break;
    case OptArrayOption:
        newOpt = new OptArray(*OptArray::dynacast(toCopy));
        break;
    case TaskSequenceOption:
        newOpt = new OptTaskSequence(*OptTaskSequence::dynacast(toCopy));
        break;
    case TaskOption:
        newOpt = new OptTask(*OptTask::dynacast(toCopy));
        break;
    case TaskIDOption:
    case GenericOption:
        break;
    }

    if(newOpt != NULL)
        addOpt(key, newOpt);
}