Skip to content
Snippets Groups Projects
Select Git revision
  • 137889ebb1c9384c99534cf98fc6a057acc95099
  • master default protected
  • exec_auto_adjust_trace
  • let_variables
  • v1.4.1
  • v1.4.0
  • v1.3.0
  • v1.2.0
  • v1.1.0
  • v1.0.0
10 results

HelpCommand.java

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    hoeffding_tree.cpp 4.38 KiB
    #include <sicstus/sicstus.h>
    /* ex_glue.h is generated by splfr from the foreign/[2,3] facts.
       Always include the glue header in your foreign resource code.
    */
    #include "hoeffding_tree_glue.h"
    #include <mlpack/methods/hoeffding_trees/hoeffding_tree_model.hpp>
    #include <mlpack/core.hpp>
    
    // including helper functions for converting between arma structures and arrays
    #include "../../helper_files/helper.hpp"
    
    // some of the most used namespaces
    using namespace arma;
    using namespace mlpack;
    using namespace std;
    using namespace mlpack::tree;
    
    // Global Variable of the HoeffdingTreeModel object so it can be accessed from all functions
    HoeffdingTreeModel hoeffdingTreeObj;
    
    // TODO: 
    // input:   const TreeType & 	            type = GINI_HOEFFDING,
    //          const arma::mat & 	            dataset,
    //          const data::DatasetInfo & 	    datasetInfo,
    //          const arma::Row< size_t > & 	labels,
    //          const size_t 	                numClasses,
    //          const bool 	                    batchTraining,
    //          const double 	                successProbability,
    //          const size_t 	                maxSamples,
    //          const size_t 	                checkInterval,
    //          const size_t 	                minSamples,
    //          const size_t 	                bins,
    //          const size_t 	                observationsBeforeBinning
    // output: 
    // description: 
    void initAndBuildModel(char const *treeType,
                            float *dataMatArr, SP_integer dataMatSize, SP_integer dataMatRowNum,
                            float *labelsArr, SP_integer labelsArrSize,
                            SP_integer numClasses, SP_integer batchTraining, double successProbability, SP_integer maxSamples, SP_integer checkInterval, SP_integer minSamples, SP_integer bins, SP_integer observationsBeforeBinning)
    {
        // convert the Prolog arrays to arma::mat
        mat data = convertArrayToMat(dataMatArr, dataMatSize, dataMatRowNum);
    
        // convert the Prolog arrays to arma::rowvec
        Row< size_t > labelsVector = convertArrayToVec(labelsArr, labelsArrSize);
    
        if (strcmp(treeType, "gini-hoeffding") == 0)
            hoeffdingTreeObj = HoeffdingTreeModel(HoeffdingTreeModel::GINI_HOEFFDING);
        else if (strcmp(treeType, "gini-binary") == 0)
            hoeffdingTreeObj = HoeffdingTreeModel(HoeffdingTreeModel::GINI_BINARY);
        else if (strcmp(treeType, "info-hoeffding") == 0)
            hoeffdingTreeObj = HoeffdingTreeModel(HoeffdingTreeModel::INFO_HOEFFDING);
        else if (strcmp(treeType, "info-binary") == 0)
            hoeffdingTreeObj = HoeffdingTreeModel(HoeffdingTreeModel::INFO_BINARY);
        else
            cout << "wrong treeType input" << endl;
        
        hoeffdingTreeObj.BuildModel(data, data::DatasetInfo(data.n_rows), labelsVector, numClasses, (batchTraining == 1), successProbability, maxSamples, checkInterval, minSamples, bins, observationsBeforeBinning);
    }
    
    // TODO: 
    // input:   const arma::mat & 	dataset,
    //          arma::Row< size_t > & 	predictions <-,
    //          arma::rowvec & 	probabilities <-
    // output: 
    // description: 
    void classify(float *dataMatArr, SP_integer dataMatSize, SP_integer dataMatRowNum,
                    float **predictArr, SP_integer *predictArrSize,
                    float **probsArr, SP_integer *probsArrSize)
    {
        // convert the Prolog arrays to arma::mat
        mat data = convertArrayToMat(dataMatArr, dataMatSize, dataMatRowNum);
    
        // create the ReturnVector
        Row< size_t > predictReturnVector;
        
        // create the ReturnVector
        rowvec probsReturnVector;
    
    
        hoeffdingTreeObj.Classify(data, predictReturnVector, probsReturnVector);
    
        
        // return the Vector
        returnVectorInformation(predictReturnVector, predictArr, predictArrSize);
    
        // return the Vector
        returnVectorInformation(probsReturnVector, probsArr, probsArrSize);
    }
    
    // TODO: 
    // input:   const arma::mat & 	dataset,
    //          const arma::Row< size_t > & 	labels,
    //          const bool 	batchTraining
    // output: 
    // description: 
    void train(float *dataMatArr, SP_integer dataMatSize, SP_integer dataMatRowNum,
                float *labelsArr, SP_integer labelsArrSize,
                SP_integer batchTraining)
    {
        // convert the Prolog arrays to arma::mat
        mat data = convertArrayToMat(dataMatArr, dataMatSize, dataMatRowNum);
        
        // convert the Prolog arrays to arma::rowvec
        Row< size_t > labelsVector = convertArrayToVec(labelsArr, labelsArrSize);
    
        hoeffdingTreeObj.Train(data, labelsVector, (batchTraining == 1));
    }