Changeset 3585:044eaebb0df5 in orange


Ignore:
Timestamp:
04/24/07 23:20:32 (7 years ago)
Author:
janezd <janez.demsar@…>
Branch:
default
Convert:
7d8b93acd4b7d275e37a48578d32c3365162f27a
Message:
  • added Preprocessor_shuffle
Location:
source/orange
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • source/orange/lib_preprocess.cpp

    r3284 r3585  
    275275C_CALL(Preprocessor_takeMissingClasses, Preprocessor, "([examples[, weightID]]) -/-> ExampleTable") 
    276276C_CALL(Preprocessor_dropMissingClasses, Preprocessor, "([examples[, weightID]]) -/-> ExampleTable") 
     277 
     278C_CALL(Preprocessor_shuffle, Preprocessor, "([examples[, weightID]] [attributes=<list-of-strings>]) -/-> ExampleTable") 
    277279 
    278280C_CALL(Preprocessor_addMissing, Preprocessor, "([examples[, weightID]] [<see the manual>]) -/-> ExampleTable") 
  • source/orange/preprocessors.cpp

    r3081 r3585  
    267267{  
    268268  return filterSelectionVector(mlnew TFilter_hasClassValue(true), gen); 
     269} 
     270 
     271 
     272TPreprocessor_shuffle::TPreprocessor_shuffle() 
     273: attributes(mlnew TVarList()) 
     274{} 
     275 
     276 
     277TPreprocessor_shuffle::TPreprocessor_shuffle(PVarList attrs) 
     278: attributes(attrs) 
     279{} 
     280 
     281 
     282PExampleGenerator TPreprocessor_shuffle::operator()(PExampleGenerator gen, const int &weightID, int &newWeight) 
     283{ 
     284  vector<int> indices; 
     285  PITERATE(TVarList, vi, attributes) { 
     286    const int idx = gen->domain->getVarNum(*vi, false); 
     287    if (idx == ILLEGAL_INT) 
     288      raiseError("attribute '%s' not found", (*vi)->name.c_str()); 
     289    indices.push_back(idx); 
     290  } 
     291     
     292  newWeight = weightID; 
     293 
     294  TExampleTable *newData = mlnew TExampleTable(gen); 
     295  PExampleGenerator wdata = newData; 
     296  const int tlen = newData->size(); 
     297  if (!tlen || !indices.size()) 
     298    return wdata; 
     299     
     300  PRandomGenerator rg = randomGenerator ? randomGenerator : mlnew TRandomGenerator; 
     301 
     302  const_ITERATE(vector<int>, ii, indices) { 
     303    for(int i = tlen; --i; ) 
     304      swap((*newData)[i][*ii], (*newData)[rg->randint(i)][*ii]); 
     305  } 
     306       
     307  return wdata; 
    269308} 
    270309 
  • source/orange/preprocessors.hpp

    r3081 r3585  
    145145  virtual PExampleGenerator operator()(PExampleGenerator, const int &weightID, int &newWeight); 
    146146  virtual PBoolList selectionVector(PExampleGenerator, const int &weightID); 
     147}; 
     148 
     149 
     150class ORANGE_API TPreprocessor_shuffle : public TPreprocessor { 
     151public: 
     152  __REGISTER_CLASS 
     153 
     154  PVarList attributes; //P tells which attributes to shuffle 
     155  PRandomGenerator randomGenerator; //P random number generator 
     156 
     157  TPreprocessor_shuffle(); 
     158  TPreprocessor_shuffle(PVarList); 
     159  virtual PExampleGenerator operator()(PExampleGenerator, const int &weightID, int &newWeight); 
    147160}; 
    148161 
Note: See TracChangeset for help on using the changeset viewer.