CODE CLASSIFIER

To buid rough sets and rules
 
#include "R.h"
#include "Rmath.h"

#include

extern "C" {
void  chooseBestCutC(int *k, double *cutCandidates, int *N, double *vec, int *objectsIdx, int *objectsIdxLengths,
                     int *numOfInt, int *decVec, int *nOfDec, int *attrType, int *minIntervalSize,
                     int *rmVec, int *idxVec, double *maxTPtoFP)    {

  int maxScore = 0;
  int maxIndIdx = 0;
  int curScore = 0;
  int flag = false;
  int sFlag = false;


  if(k[0] >= 1)  {
  int posAttr = 0;
  int negAttr = 0;

  std::vector posAttrDecisionCounts(nOfDec[0], 0);
  std::vector negAttrDecisionCounts(nOfDec[0], 0);

  int tmpObjIdx = 0;
  double tmpIntLength = 0.0;
  for(int j = 0; j <= k[0] - 1;  ++j) {
    if(attrType[0] > 0) {
      tmpObjIdx = 0;
      flag = false;
      curScore = 0;
      for(int m = 0; m <= numOfInt[0] - 1; ++m)  {
        posAttr = 0;
        negAttr = 0;
        for(int i = 0; i <= nOfDec[0] - 1; ++i) {
          posAttrDecisionCounts[i] = 0;
          negAttrDecisionCounts[i] = 0;
        }
        for(int i = tmpObjIdx; i <= tmpObjIdx + objectsIdxLengths[m] - 1; ++i) {
          if(vec[objectsIdx[i] - 1] >= cutCandidates[j]) {
            posAttr++;
            posAttrDecisionCounts[decVec[i] - 1]++;
          }
          else {
            negAttr++;
            negAttrDecisionCounts[decVec[i] - 1]++;
          }
        }
        if( posAttr >= 0.5*objectsIdxLengths[m] ) tmpIntLength = posAttr - 0.5*objectsIdxLengths[m];
        else tmpIntLength = 0.5*objectsIdxLengths[m] - posAttr;
        if( 0.5*objectsIdxLengths[m] - tmpIntLength >= minIntervalSize[0])  {
          if(flag == false) {
            curScore = 0;
            flag = true;
            sFlag = true;
          }
          for(int i = 0; i <= nOfDec[0] - 1; ++i) {
             curScore = curScore + (negAttr - negAttrDecisionCounts[i])*posAttrDecisionCounts[i] + (posAttr - posAttrDecisionCounts[i])*negAttrDecisionCounts[i];
          }
        }
        tmpObjIdx = tmpObjIdx + objectsIdxLengths[m];
      }
      if(curScore > maxScore) {
        maxScore = curScore;
        maxIndIdx = j + 1;
      }
    }
    if(flag == false) {
      rmVec[j] = 1;
    }
  }
  }

  if(sFlag == false) {
    idxVec[0] = 0;
    maxTPtoFP[0] = 0;
  }
  else  {
    idxVec[0] = maxIndIdx;
    maxTPtoFP[0] = maxScore;
  }

  return;
}
}

extern "C" {
void  chooseCutCandidatesC(double *vec, int *decVec, int *N, int *candidatesIdx, double *candidates) {

  for(int i = 0; i < N[0] - 1; ++i)    {
    if(decVec[i] != decVec[i+1])    {
      candidates[i] = (vec[i] + vec[i+1])*0.5;
      candidatesIdx[i] = true;
    }
  }
  return;
}
}

extern "C" {

void  computeIndiscernibilityAndChaos(int *INDclasses, int *INDsizes, int *NOfINDClasses,
                                      int *attrValues, int *NOfAttrValues,
                                      int *decValues, int *NOfDecs,
                                      int *output)  {

  int objectIterator = 0;
  for (int i=0; i     for (int j=0; j       ++output[i*NOfAttrValues[0]*NOfDecs[0] +
               (attrValues[INDclasses[objectIterator] - 1] - 1)*NOfDecs[0] +
               decValues[INDclasses[objectIterator] - 1] - 1];
      ++objectIterator;
    }
  }

  return;
}
}


 
 
 
 
#include
using namespace Rcpp;

template
inline bool filter(T const & x){
  return x.size() <= 1;
}

// [[Rcpp::export]]
List compute_indiscernibility(List input, CharacterVector attr_val, CharacterVector unique_attr_val) {
  std::map numbers;
  for (int i=0; i     numbers[unique_attr_val[i]] = i;
  }
  int numbers_size = numbers.size();
  int input_size = input.size();
  std::vector > result(input_size*numbers_size);
  for (int i=0; i     IntegerVector ind_class = input[i];
    int ind_class_size = ind_class.size();
    for (int j=0; j       result[i*numbers_size+numbers[attr_val[ind_class[j]-1]]].push_back(ind_class[j]);
    }
  }
  result.erase(std::remove_if(result.begin(), result.end(), filter >), result.end());
  return wrap(result);
}

// [[Rcpp::export]]
List compute_chaos(List input, CharacterVector dec_val, CharacterVector unique_dec_val) {

  std::map indexes;
  for (int i=0; i     indexes[unique_dec_val[i]] = i;
  }
  int input_size = input.size();
  std::vector > result(input_size);
  int unique_dec_val_size = unique_dec_val.size();
  std::vector classCounts(unique_dec_val_size);

  for (int i=0; i     for (int j=0; j       classCounts[j] = 0;
    }
    IntegerVector ind_class = input[i];
    int ind_class_size = ind_class.size();
    for (int j=0; j       ++classCounts[indexes[dec_val[ind_class[j]-1]]];
    }
    result[i] = classCounts;
  }
  return wrap(result);
}

// // [[Rcpp::export]]
// List compute_indiscernibility_and_chaos(List input, CharacterVector attr_val, CharacterVector unique_attr_val, CharacterVector dec_val, CharacterVector unique_dec_val) {
//
//   std::map numbers;
//   for (int i=0; i //     numbers[unique_attr_val[i]] = i;
//   }
//   int numbers_size = numbers.size();
//   int input_size = input.size();
//
//   std::vector > new_ind_rel(input_size*numbers_size);
//   for (int i=0; i //     IntegerVector ind_class = input[i];
//     int ind_class_size = ind_class.size();
//     for (int j=0; j //       new_ind_rel[i*numbers_size+numbers[attr_val[ind_class[j]-1]]].push_back(ind_class[j]);
//     }
//   }
//   new_ind_rel.erase(std::remove_if(new_ind_rel.begin(), new_ind_rel.end(), filter >), new_ind_rel.end());
//
//   std::map indexes;
//   for (int i=0; i //     indexes[unique_dec_val[i]] = i;
//   }
//   int new_ind_rel_size = new_ind_rel.size();
//
//   std::vector > myresult;
//   if (new_ind_rel_size > 0) {
//     myresult.resize(new_ind_rel_size + 1);
//     int unique_dec_val_size = unique_dec_val.size();
//     std::vector classCounts(unique_dec_val_size);
//     for (int i=0; i //       for (int j=0; j //         classCounts[j] = 0;
//       }
//       std::vector ind_class = new_ind_rel[i];
//       int ind_class_size = ind_class.size();
//       myresult[0].push_back(ind_class_size);
//       for (int j=0; j //         ++classCounts[indexes[dec_val[ind_class[j]-1]]];
//       }
//       myresult[i+1] = classCounts;
//     }
//   } else {
//     myresult.resize(2);
//     myresult[0].push_back(10);
//     myresult[1].push_back(10);
//     myresult[1].push_back(0);
//   }
//   return wrap(myresult);
// }

//// [[Rcpp::export]]
// List compute_indiscernibility_and_chaos2(List input, CharacterVector attr_val, CharacterVector unique_attr_val, CharacterVector dec_val, CharacterVector unique_dec_val) {
//
//   std::map numbers;
//   int unique_attr_val_size = unique_attr_val.size();
//   for (int i=0; i //     numbers[unique_attr_val[i]] = i;
//   }
//
//   std::map indexes;
//   int unique_dec_val_size = unique_dec_val.size();
//   for (int i=0; i //     indexes[unique_dec_val[i]] = i;
//   }
//
//   std::vector tmp_class_counts(unique_dec_val_size, 0);
//
//   int input_size = input.size();
//   std::vector > class_counts_list(input_size*unique_attr_val_size, tmp_class_counts);
//   std::vector final_ind_classes_size(input_size*unique_attr_val_size, 0);
//   int tmp_number = 0;
//   for (int i=0; i //     std::vector ind_class = input[i];
//     int ind_class_size = ind_class.size();
//
//     for (int j=0; j //       tmp_number = i*unique_attr_val_size + numbers[attr_val[ind_class[j]-1]];
//       ++final_ind_classes_size[tmp_number];
//       ++class_counts_list[tmp_number][indexes[dec_val[ind_class[j]-1]]];
//     }
//   }
//
//   class_counts_list.insert(class_counts_list.begin(), final_ind_classes_size);
//
//   return wrap(class_counts_list);
// }

 

Contact

© 2014 Tous droits réservés.

Créer un site internet gratuitWebnode