Changeset 3625:14201d609bce in orange


Ignore:
Timestamp:
04/30/07 17:52:53 (7 years ago)
Author:
janezd <janez.demsar@…>
Branch:
default
Convert:
d6f8b130edfaad5bf00ddd59550ca58718b6b621
Message:
  • added RemoveRedundantOneValue_hasAtLeastTwoValues
Location:
source/orange
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • source/orange/lib_preprocess.cpp

    r3585 r3625  
    222222 
    223223 
     224PyObject *RemoveRedundantOneValue_hasAtLeastTwoValues(PyObject *, PyObject *args) PYARGS(METH_VARARGS | METH_STATIC, "(attribute, examples) -> bool") 
     225{ 
     226  PyTRY 
     227    PExampleGenerator gen; 
     228    PyObject *var; 
     229    if (!PyArg_ParseTuple(args, "O&O:RemoveRedundantOneValue.hasAtLeastTwoValues", pt_ExampleGenerator, &gen, &var)) 
     230      return NULL; 
     231    int varIdx; 
     232    if (!varNumFromVarDom(var, gen->domain, varIdx)) 
     233      PYERROR(PyExc_AttributeError, "RemoveRedundantOneValue.hasAtLeastTwoValues: invalid attribute", NULL); 
     234    return PyBool_FromLong(TRemoveRedundantOneValue::hasAtLeastTwo(gen, varIdx) ? 1 : 0); 
     235  PyCATCH 
     236} 
     237     
    224238PyObject *RemoveUnusedValues_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(attribute, examples[, weightId]) -> attribute") 
    225239{ 
  • source/orange/redundancy.cpp

    r3450 r3625  
    309309{} 
    310310 
     311bool TRemoveRedundantOneValue::hasAtLeastTwo(PExampleGenerator gen, const int &idx) 
     312{ 
     313  float ev = ILLEGAL_FLOAT; 
     314  PEITERATE(ei, gen) { 
     315    const TValue val = (*ei)[idx]; 
     316    if (!val.isSpecial()) 
     317      if (ev == ILLEGAL_FLOAT) 
     318        ev = val.floatV; 
     319      else 
     320        if (ev != val.floatV) 
     321          return true; 
     322  } 
     323   
     324  return false; 
     325} 
     326 
     327 
    311328PDomain TRemoveRedundantOneValue::operator() 
    312329  (PExampleGenerator gen, PVarList suspicious, PExampleGenerator *nonRedundantResult, int weightID) 
     
    315332 
    316333  if (onData) { 
    317     TDomainDistributions distr(gen, weightID); 
     334    TDomainDistributions distr(gen, weightID, false, true); 
    318335    TDomainDistributions::iterator di(distr.begin()); 
    319     PITERATE(TVarList, vi, gen->domain->attributes) { 
    320       if (   suspicious && suspicious->size() && !exists(suspicious.getReference(), *vi)) 
     336    TVarList::const_iterator vi(gen->domain->attributes->begin()), ve(gen->domain->attributes->end()); 
     337    int idx = 0; 
     338    for(; vi!= ve; vi++, di++, idx++) { 
     339      if (   suspicious && suspicious->size() && !exists(suspicious.getReference(), *vi) 
     340          || ((*vi)->varType == TValue::FLOATVAR) && hasAtLeastTwo(gen, idx)) 
    321341        newDomain->addVariable(*vi); 
     342       
    322343      else { 
    323         const TDiscDistribution *discdist = (*di).AS(TDiscDistribution); 
     344        const TDiscDistribution *discdist = *di ? (*di).AS(TDiscDistribution) : NULL; 
    324345        if (!discdist) 
    325346          newDomain->addVariable(*vi); 
     
    333354        } 
    334355      } 
    335       di++; 
    336356    } 
    337357  } 
     
    355375: removeOneValued(rov) 
    356376{} 
     377 
    357378 
    358379 
  • source/orange/redundancy.hpp

    r2843 r3625  
    7474  TRemoveRedundantOneValue(bool anOnData=true); 
    7575  virtual PDomain operator()(PExampleGenerator gen, PVarList suspicious=PVarList(), PExampleGenerator *nonRedundantResult=NULL, int aweightID=0); 
     76  static bool hasAtLeastTwo(PExampleGenerator gen, const int &idx); 
    7677}; 
    7778 
Note: See TracChangeset for help on using the changeset viewer.