Changeset 5000:18108debf6a8 in orange


Ignore:
Timestamp:
07/22/08 22:02:10 (6 years ago)
Author:
janezd <janez.demsar@…>
Branch:
default
Convert:
9ae0ef0990653f66db2dbc4c4caf6f213c9c5078
Message:
  • added getitemsets to sparse inducer
Location:
source/orange
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • source/orange/assoc.hpp

    r4996 r5000  
    5151  float lift; //P rule's lift 
    5252  float leverage; //P rule's leverage 
    53   float nAppliesLeft; //P number of examples covered by the rule's left side  
    54   float nAppliesRight; //P number of examples covered by the rule's right side  
     53  float nAppliesLeft; //P number of examples covered by the rule's left side 
     54  float nAppliesRight; //P number of examples covered by the rule's right side 
    5555  float nAppliesBoth; //P number of examples covered by the rule 
    5656  float nExamples; //P number of learning examples 
    5757  int nLeft; //PR number of items on the rule's left side 
    5858  int nRight; //PR number of items on the rule's right side 
    59    
     59 
    6060  PExampleTable examples; //PR examples which the rule was built from 
    6161  PIntList matchLeft; //PR indices of examples that match the left side of the rule 
     
    129129  // This constructor is called when building the 1-tree 
    130130  TItemSetValue(int al); 
    131    
     131 
    132132  // This constructor is called when itemsets are intersected (makePairs ets) 
    133133  TItemSetValue(int al, const TExampleSet &ex, float asupp); 
     
    230230    TSparseISubNodes subNode;               //children items 
    231231    vector<int> exampleIds; 
    232      
     232 
    233233    TSparseItemsetNode(long avalue = -1);           //constructor 
    234234 
     
    254254  void delLeafSmall(float minSupport); 
    255255    PAssociationRules genRules(int maxDepth, float minConf, float nOfExamples, bool storeExamples); 
    256     long getItemsetRules(long itemset[], int iLength, float minConf,  
     256    long getItemsetRules(long itemset[], int iLength, float minConf, 
    257257                         float nAppliesBoth, float nOfExamples, PAssociationRules rules, bool storeExamples, TSparseItemsetNode *bothNode); 
    258258    PDomain domain; 
     
    271271  float confidence; //P required confidence 
    272272  float support; //P required support 
    273    
     273 
    274274  bool storeExamples; //P stores examples corresponding to rules 
    275275 
    276276  TAssociationRulesSparseInducer(float asupp=0.1, float aconf=0, int awei=0); 
     277  TSparseItemsetTree *TAssociationRulesSparseInducer::buildTree(PExampleGenerator examples, const int &weightID, long &i, float &fullWeight); 
    277278  PAssociationRules operator()(PExampleGenerator, const int &weightID); 
    278279 
     
    311312  int voteWeight; //P vote weight (s=support, c=confidence, p=product) 
    312313  int maxItemSets; //P maximal number of itemsets (increase if you want) 
    313   
     314 
    314315  TAssociationLearner(); 
    315316  virtual PClassifier operator()(PExampleGenerator gen, const int & = 0); 
     
    323324  PAssociationRules rules; //P association rules 
    324325  int voteWeight; //P vote weight (s=support, c=confidence, p=product) 
    325   
     326 
    326327  TAssociationClassifier(PDomain dom=PDomain(), PAssociationRules arules=PAssociationRules(), char avote='s'); 
    327328  virtual PDistribution classDistribution(const TExample &); 
  • source/orange/assoc_sparse.cpp

    r4996 r5000  
    3838      // walk through all attributes in example and adding to sparseExample only those having some value 
    3939      PITERATE(TVarList, vi, example->domain->variables) 
    40           if (!(*example)[(*vi)].isSpecial())  
     40          if (!(*example)[(*vi)].isSpecial()) 
    4141              length++; 
    42            
     42 
    4343      itemset = new long[length]; 
    4444      length = 0; 
    4545 
    46       PITERATE(TVarList, vi2, example->domain->variables)  
    47           if (!(*example)[(*vi2)].isSpecial())  
     46      PITERATE(TVarList, vi2, example->domain->variables) 
     47          if (!(*example)[(*vi2)].isSpecial()) 
    4848              itemset[length++] = example->domain->getVarNum(*vi2); 
    4949  } 
     
    6363 
    6464TSparseExamples::TSparseExamples(PExampleGenerator examples, int weightID){ 
    65     fullWeight = 0.0;                
     65    fullWeight = 0.0; 
    6666    TSparseExample *sparseExm; 
    6767    domain = examples->domain; 
     
    111111        subNode[avalue] = new TSparseItemsetNode(avalue); 
    112112        subNode[avalue]->parent = this; 
    113     }  
     113    } 
    114114    //returns new node 
    115115    return subNode[avalue]; 
     
    133133int TSparseItemsetTree::buildLevelOne(vector<long> intDomain) { 
    134134    int count = 0; 
    135      
     135 
    136136    ITERATE(vector<long>,idi,intDomain) { 
    137137        root->addNode(*idi); 
     
    148148    long count = 0; 
    149149    vector<NodeDepth> nodeQue; 
    150      
     150 
    151151    long *cItemset = new long[maxDepth +1]; 
    152152    int currDepth; 
    153     TSparseItemsetNode *currNode;  
     153    TSparseItemsetNode *currNode; 
    154154 
    155155    nodeQue.push_back(NodeDepth(root,0)); // put root in que 
     
    162162 
    163163        if (currDepth) cItemset[currDepth - 1] = currNode->value;       // generates candidate itemset 
    164          
     164 
    165165        if (currDepth == maxDepth)                                      // we found an instance that can be extended 
    166166            for(TSparseISubNodes::iterator iter(++(root->subNode.find(currNode->value))), \ 
     
    175175                        if (count>maxCount) return count; 
    176176                    } 
    177                      
    178                 }    
     177 
     178                } 
    179179        else RITERATE(TSparseISubNodes,sni,currNode->subNode)       //adds subnodes to list 
    180180            nodeQue.push_back(NodeDepth(sni->second, currDepth + 1)); 
     
    184184 
    185185 
    186 // tests if some candidate itemset can be extended to large itemset  
    187 bool TSparseItemsetTree::allowExtend(long itemset[], int iLength) {  
     186// tests if some candidate itemset can be extended to large itemset 
     187bool TSparseItemsetTree::allowExtend(long itemset[], int iLength) { 
    188188    typedef pair<int,int> IntPair; // <parent node index, depth> 
    189189    typedef pair<TSparseItemsetNode *,IntPair> NodeDepth; 
    190190 
    191191    vector<NodeDepth> nodeQue; 
    192      
     192 
    193193    int currDepth; 
    194194    int currPrIndex;                                //parent index 
    195     TSparseItemsetNode *currNode;  
     195    TSparseItemsetNode *currNode; 
    196196    int i; 
    197      
     197 
    198198    nodeQue.push_back(NodeDepth(root,IntPair(-1,1))); // put root in que 
    199199 
     
    202202        currPrIndex = nodeQue.back().second.first;  // parentIndex 
    203203        currDepth = nodeQue.back().second.second;   // depth 
    204          
     204 
    205205        nodeQue.pop_back(); 
    206206 
    207207        if (currDepth == iLength) continue;         // we found an instance 
    208          
     208 
    209209        for (i = currDepth; i!=currPrIndex; i--)        //go through all posible successors of this node 
    210210            if (currNode->hasNode(itemset[i])) 
     
    217217 
    218218// counts number of leaf nodes not using any recursion 
    219 long TSparseItemsetTree::countLeafNodes() {  
     219long TSparseItemsetTree::countLeafNodes() { 
    220220    long countLeaf = 0; 
    221221    vector<TSparseItemsetNode *> nodeQue; 
     
    229229 
    230230        if (!currNode->subNode.empty())         //if node is leaf count++ else count children 
    231             RITERATE(TSparseISubNodes,sni,currNode->subNode)  
     231            RITERATE(TSparseISubNodes,sni,currNode->subNode) 
    232232                nodeQue.push_back(sni->second); 
    233233        else countLeaf++;                       // node is leaf 
     
    239239 
    240240// counts supports of all aimLength long branches in tree using one example (itemset) data 
    241 void TSparseItemsetTree::considerItemset(long itemset[], int iLength, float weight, int aimLength) {     
     241void TSparseItemsetTree::considerItemset(long itemset[], int iLength, float weight, int aimLength) { 
    242242    typedef pair<int,int> IntPair; // <parent node index, depth> 
    243243    typedef pair<TSparseItemsetNode *,IntPair> NodeDepth; 
    244244 
    245245    vector<NodeDepth> nodeQue; 
    246      
     246 
    247247    int currDepth; 
    248248    int currPrIndex;                                //parent index 
    249     TSparseItemsetNode *currNode;  
     249    TSparseItemsetNode *currNode; 
    250250    int i, end = iLength - aimLength; 
    251251 
     
    256256        currPrIndex = nodeQue.back().second.first;  // parentIndex 
    257257        currDepth = nodeQue.back().second.second;   // depth 
    258          
     258 
    259259        nodeQue.pop_back(); 
    260260 
     
    269269 
    270270// counts supports of all aimLength long branches in tree using examples data 
    271 void TSparseItemsetTree::considerExamples(TSparseExamples *examples, int aimLength) {    
     271void TSparseItemsetTree::considerExamples(TSparseExamples *examples, int aimLength) { 
    272272        ITERATE(vector<TSparseExample*>,ei,examples->transaction) 
    273273            if (aimLength <= (*ei)->length) 
     
    283283        assignExamples((*node)[*itemset], itemset+1, itemsetend, exampleId); 
    284284} 
    285      
     285 
    286286void TSparseItemsetTree::assignExamples(TSparseExamples &examples) 
    287287{ 
     
    289289  ITERATE(vector<TSparseExample*>,ei,examples.transaction) 
    290290    assignExamples(root, (*ei)->itemset, (*ei)->itemset+(*ei)->length, exampleId++); 
    291 }   
     291} 
    292292 
    293293 
    294294 
    295295// deletes all leaves that have weiSupp smaler than given minSupp; 
    296 void TSparseItemsetTree::delLeafSmall(float minSupp) {   
     296void TSparseItemsetTree::delLeafSmall(float minSupp) { 
    297297    long countLeaf = 0; 
    298298    vector<TSparseItemsetNode *> nodeQue; 
     
    306306 
    307307        if (!currNode->subNode.empty())     //if node is not leaf add children else check support 
    308             RITERATE(TSparseISubNodes,sni,currNode->subNode)  
     308            RITERATE(TSparseISubNodes,sni,currNode->subNode) 
    309309                nodeQue.push_back(sni->second); 
    310         else  
     310        else 
    311311            if (currNode->weiSupp < minSupp) { 
    312312                currNode->parent->subNode.erase(currNode->value); 
     
    317317 
    318318 
    319 // generates all posible association rules from tree using given confidence 
     319// generates all possible association rules from tree using given confidence 
    320320PAssociationRules TSparseItemsetTree::genRules(int maxDepth, float minConf, float nOfExamples, bool storeExamples) { 
    321321    typedef pair<TSparseItemsetNode *,int> NodeDepth; //<node,depth> 
     
    323323    int count=0; 
    324324    vector<NodeDepth> nodeQue; 
    325      
     325 
    326326    PAssociationRules rules = mlnew TAssociationRules(); 
    327      
     327 
    328328    long *itemset = new long[maxDepth]; 
    329329    int currDepth; 
    330     TSparseItemsetNode *currNode;  
     330    TSparseItemsetNode *currNode; 
    331331 
    332332    nodeQue.push_back(NodeDepth(root,0)); // put root in que 
     
    339339 
    340340        if (currDepth) itemset[currDepth - 1] = currNode->value;  // create itemset to check for confidence 
    341      
     341 
    342342        if (currDepth > 1) 
    343343            count += getItemsetRules(itemset, currDepth, minConf, currNode->weiSupp, nOfExamples, rules, storeExamples, currNode);  //creates rules from itemsets and adds them to rules 
     
    346346            nodeQue.push_back(NodeDepth(sni->second, currDepth + 1)); 
    347347    } 
    348      
     348 
    349349    return rules; 
    350350}; 
    351351 
    352352// checks if itemset generates some rules with enough confidence and adds these rules to resultset 
    353 long TSparseItemsetTree::getItemsetRules(long itemset[], int iLength, float minConf,  
    354                                    float nAppliesBoth, float nOfExamples,  
     353long TSparseItemsetTree::getItemsetRules(long itemset[], int iLength, float minConf, 
     354                                   float nAppliesBoth, float nOfExamples, 
    355355                                   PAssociationRules rules, 
    356356                                   bool storeExamples, TSparseItemsetNode *bothNode) { 
    357      
     357 
    358358    float nAppliesLeft, nAppliesRight; 
    359359    long count = 0; 
     
    361361    TExample exLeft(domain), exRight(domain); 
    362362  const bool sparseRules = domain->variables->empty(); 
    363      
     363 
    364364    nAppliesLeft=nAppliesBoth; 
    365365    nAppliesRight=nAppliesBoth; 
    366      
     366 
    367367    typedef pair<int,int> IntPair; // <parent node index, depth> 
    368368    typedef pair<TSparseItemsetNode *,IntPair> NodeDepth; 
    369369 
    370370    vector<NodeDepth> nodeQue; 
    371      
     371 
    372372    int currDepth, i, j; 
    373373    int currPrIndex; //parent index 
    374374    TSparseItemsetNode *currNode, *tempNode; 
    375      
     375 
    376376    long *leftItemset = new long[iLength - 1]; 
    377377    float thisConf; 
    378      
     378 
    379379    nodeQue.push_back(NodeDepth(root,IntPair(-1,0))); // put root in que 
    380380 
     
    383383        currPrIndex = nodeQue.back().second.first;  // parentIndex 
    384384        currDepth = nodeQue.back().second.second;   // depth 
    385          
     385 
    386386        nodeQue.pop_back(); 
    387387 
     
    404404              j++; 
    405405            } 
    406             else {  
     406            else { 
    407407              _ASSERT(itemset[j] == leftItemset[i]); 
    408408              exLeftS->setMeta(leftItemset[i], TValue(1.0)); 
     
    423423 
    424424          tempNode = root; 
    425           for (i=0; i< iLength; i++)  
     425          for (i=0; i< iLength; i++) 
    426426            if (   ) { 
    427427              exRight[itemset[i]] = 1.0; 
     
    446446                      exLeft[leftItemset[i]].varType=0; 
    447447                    } 
    448          
    449                  
     448 
     449 
    450450                  tempNode = root; 
    451                   for (i=0; i<iLength;i++)  
     451                  for (i=0; i<iLength;i++) 
    452452                      if (exLeft[itemset[i]].isSpecial()) { 
    453453                          exRight[itemset[i]].setSpecial(false); 
     
    478478        } 
    479479    } 
    480          
     480 
    481481    return count; 
    482482}; 
     
    494494{} 
    495495 
    496 PAssociationRules TAssociationRulesSparseInducer::operator()(PExampleGenerator examples, const int &weightID) 
    497 {   float nMinSupp; 
    498     long currItemSets, i,newItemSets; 
     496 
     497TSparseItemsetTree *TAssociationRulesSparseInducer::buildTree(PExampleGenerator examples, const int &weightID, long &i, float &fullWeight) 
     498{ 
     499    float nMinSupp; 
     500    long currItemSets, newItemSets; 
    499501 
    500502    // reformat examples in sparseExm for better efficacy 
    501503    TSparseExamples sparseExm(examples, weightID); 
    502504 
     505    fullWeight = sparseExm.fullWeight; 
     506 
    503507    // build first level of tree 
    504508    TSparseItemsetTree *tree = new TSparseItemsetTree(sparseExm); 
    505     newItemSets = tree->buildLevelOne(sparseExm.intDomain);  
     509    newItemSets = tree->buildLevelOne(sparseExm.intDomain); 
    506510 
    507511    nMinSupp = support * sparseExm.fullWeight; 
    508      
    509     //while it is posible to extend tree repeat... 
     512 
     513    //while it is possible to extend tree repeat... 
    510514    for(i=1;newItemSets;i++) { 
    511515        tree->considerExamples(&sparseExm,i); 
    512516        tree->delLeafSmall(nMinSupp); 
    513          
     517 
    514518        currItemSets = tree->countLeafNodes(); 
    515519 
     
    522526        } 
    523527    } 
    524      
     528 
    525529    if (storeExamples) 
    526530      tree->assignExamples(sparseExm); 
    527        
    528     PAssociationRules rules = tree->genRules(i, confidence, sparseExm.fullWeight, storeExamples); 
    529      
     531 
     532    return tree; 
     533} 
     534 
     535 
     536PAssociationRules TAssociationRulesSparseInducer::operator()(PExampleGenerator examples, const int &weightID) 
     537{ 
     538  long i; 
     539  float fullWeight; 
     540  TSparseItemsetTree *tree = buildTree(examples, weightID, i, fullWeight); 
     541  PAssociationRules rules = tree->genRules(i, confidence, fullWeight, storeExamples); 
     542  delete tree; 
     543 
    530544  if (storeExamples) { 
    531545    PExampleTable xmpls = mlnew TExampleTable(examples); 
     
    538552 
    539553 
     554 
    540555/**************************************************************************************** 
    541556TItemsetsSparseInducer 
     
    558573    // build first level of tree 
    559574    TSparseItemsetTree *tree = new TSparseItemsetTree(sparseExm); 
    560     newItemSets = tree->buildLevelOne(sparseExm.intDomain);  
     575    newItemSets = tree->buildLevelOne(sparseExm.intDomain); 
    561576 
    562577    nMinSupp = support * sparseExm.fullWeight; 
    563      
     578 
    564579    //while it is posible to extend tree repeat... 
    565580    for(i=1;newItemSets;i++) { 
    566581        tree->considerExamples(&sparseExm,i); 
    567582        tree->delLeafSmall(nMinSupp); 
    568          
     583 
    569584        currItemSets = tree->countLeafNodes(); 
    570585 
     
    580595  if (storeExamples) 
    581596      tree->assignExamples(sparseExm); 
    582      
     597 
    583598    return tree; 
    584599} 
  • source/orange/lib_learner.cpp

    r4996 r5000  
    5353/* ************ MAJORITY AND COST ************ */ 
    5454 
    55 #include "majority.hpp"  
     55#include "majority.hpp" 
    5656C_CALL(MajorityLearner, Learner, "([examples] [, weight=, estimate=]) -/-> Classifier") 
    5757C_CALL(CostLearner, Learner, "([examples] [, weight=, estimate=, costs=]) -/-> Classifier") 
     
    111111        PyTuple_SET_ITEM(itemset, el, vp); 
    112112      } 
    113        
     113 
    114114      PyObject *examples; 
    115115      if (storeExamples) { 
     
    127127      PyTuple_SET_ITEM(rr, 0, itemset); 
    128128      PyTuple_SET_ITEM(rr, 1, examples); 
    129        
     129 
    130130      PyList_Append(listOfItems, rr); 
    131131      Py_DECREF(rr); 
    132        
     132 
    133133      gatherRules((*isi).branch, itemsSoFar, listOfItems, storeExamples); 
    134134    } 
     
    138138 
    139139PyObject *AssociationRulesInducer_getItemsets(PyObject *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS, "(examples[, weightID]) -> list-of-itemsets") 
    140 {  
     140{ 
    141141  PyTRY 
    142142    int weightID; 
     
    149149 
    150150    TItemSetNode *tree = NULL; 
    151     int depth, nOfExamples; 
    152     TDiscDistribution classDist; 
    153     CAST_TO(TAssociationRulesInducer, inducer); 
    154     inducer->buildTrees(egen, weightID, tree, depth, nOfExamples, classDist); 
    155      
    156     PyObject *listOfItemsets = PyList_New(0); 
    157     vector<pair<int, int> > itemsSoFar; 
    158     gatherRules(tree, itemsSoFar, listOfItemsets, inducer->storeExamples); 
     151    PyObject *listOfItemsets = NULL; 
     152    try { 
     153        int depth, nOfExamples; 
     154        TDiscDistribution classDist; 
     155        CAST_TO(TAssociationRulesInducer, inducer); 
     156        inducer->buildTrees(egen, weightID, tree, depth, nOfExamples, classDist); 
     157 
     158        listOfItemsets = PyList_New(0); 
     159        vector<pair<int, int> > itemsSoFar; 
     160        gatherRules(tree, itemsSoFar, listOfItemsets, inducer->storeExamples); 
     161    } 
     162    catch (...) { 
     163        if (tree) 
     164            delete tree; 
     165        throw; 
     166    } 
     167 
     168    delete tree; 
     169    return listOfItemsets; 
     170  PyCATCH 
     171} 
     172 
     173 
     174void gatherRules(TSparseItemsetNode *node, vector<int> &itemsSoFar, PyObject *listOfItems, bool storeExamples) 
     175{ 
     176    if (itemsSoFar.size()) { 
     177        PyObject *itemset = PyTuple_New(itemsSoFar.size()); 
     178        int el = 0; 
     179        vector<int>::const_iterator sfi(itemsSoFar.begin()), sfe(itemsSoFar.end()); 
     180        for(; sfi != sfe; sfi++, el++) 
     181            PyTuple_SET_ITEM(itemset, el, PyInt_FromLong(*sfi)); 
     182 
     183        PyObject *examples; 
     184        if (storeExamples) { 
     185          examples = PyList_New(node->exampleIds.size()); 
     186          int ele = 0; 
     187          ITERATE(vector<int>, ei, node->exampleIds) 
     188            PyList_SetItem(examples, ele++, PyInt_FromLong(*ei)); 
     189        } 
     190        else { 
     191          examples = Py_None; 
     192          Py_INCREF(Py_None); 
     193        } 
     194 
     195      PyObject *rr = PyTuple_New(2); 
     196      PyTuple_SET_ITEM(rr, 0, itemset); 
     197      PyTuple_SET_ITEM(rr, 1, examples); 
     198 
     199      PyList_Append(listOfItems, rr); 
     200      Py_DECREF(rr); 
     201    } 
     202 
     203    itemsSoFar.push_back(0); 
     204    ITERATE(TSparseISubNodes, isi, node->subNode) { 
     205        itemsSoFar.back() = (*isi).first; 
     206        gatherRules((*isi).second, itemsSoFar, listOfItems, storeExamples); 
     207    } 
     208    itemsSoFar.pop_back(); 
     209} 
     210 
     211 
     212PyObject *AssociationRulesSparseInducer_getItemsets(PyObject *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS, "(examples[, weightID]) -> list-of-itemsets") 
     213{ 
     214  PyTRY 
     215    int weightID; 
     216    PExampleGenerator egen = exampleGenFromArgs(args, weightID); 
     217    if (!egen) 
     218      return PYNULL; 
     219 
     220    if (egen->domain->hasContinuousAttributes(true)) 
     221      PYERROR(PyExc_TypeError, "cannot induce rules with non-discrete attributes", NULL); 
     222 
     223    CAST_TO(TAssociationRulesSparseInducer, inducer); 
     224    long i; 
     225    float fullWeight; 
     226    TSparseItemsetTree *tree = NULL; 
     227    PyObject *listOfItemsets = NULL; 
     228 
     229    try { 
     230        inducer->buildTree(egen, weightID, i, fullWeight); 
     231        listOfItemsets = PyList_New(0); 
     232        vector<int> itemsSoFar; 
     233        gatherRules(tree->root, itemsSoFar, listOfItemsets, inducer->storeExamples); 
     234    } 
     235    catch (...) { 
     236        if (tree) 
     237            delete tree; 
     238        throw; 
     239    } 
     240 
    159241    delete tree; 
    160242    return listOfItemsets; 
     
    180262    const TSparseItemsetNode *node; 
    181263    PSparseItemsetTree tree; 
    182      
     264 
    183265    TItemsetNodeProxy(const TSparseItemsetNode *n, PSparseItemsetTree t) 
    184266    : node(n), 
     
    207289 
    208290int ItemsetNodeProxy_traverse(PyObject *self, visitproc visit, void *arg) 
    209 {  
     291{ 
    210292    int err = Orange_traverse((TPyOrange *)self, visit, arg); 
    211293    if (err) 
     
    219301 
    220302int ItemsetNodeProxy_clear(PyObject *self) 
    221 {  
     303{ 
    222304  SELF_AS(TItemsetNodeProxy).tree = PSparseItemsetTree(); 
    223305    return Orange_clear((TPyOrange *)self); 
     
    281363                                   Example_FromWrappedExample(arule->right), 
    282364                                   packOrangeDictionary(self)); 
    283   PyCATCH                           
     365  PyCATCH 
    284366} 
    285367 
     
    289371    if (!PyOrExample_Check(arg)) 
    290372      PYERROR(PyExc_TypeError, "attribute error (example expected)", PYNULL); 
    291      
     373 
    292374    CAST_TO(TAssociationRule, rule) 
    293375    return PyInt_FromLong(rule->appliesLeft(PyExample_AS_ExampleReference(arg)) ? 1 : 0); 
     
    300382    if (!PyOrExample_Check(arg)) 
    301383      PYERROR(PyExc_TypeError, "attribute error (example expected)", PYNULL); 
    302      
     384 
    303385    CAST_TO(TAssociationRule, rule) 
    304386    return PyInt_FromLong(rule->appliesRight(PyExample_AS_ExampleReference(arg)) ? 1 : 0); 
     
    311393    if (!PyOrExample_Check(arg)) 
    312394      PYERROR(PyExc_TypeError, "attribute error (example expected)", PYNULL); 
    313      
     395 
    314396    CAST_TO(TAssociationRule, rule) 
    315397    return PyInt_FromLong(rule->appliesBoth(PyExample_AS_ExampleReference(arg)) ? 1 : 0); 
     
    366448    } 
    367449 
    368     case 1:  
     450    case 1: 
    369451      if (PyArg_ParseTuple(obj, "O&:convertFromPython(AssociationRule)", cc_AssociationRule, &rule)) 
    370452        return true; 
     
    372454        break; 
    373455  } 
    374      
     456 
    375457  PYERROR(PyExc_TypeError, "invalid arguments", false); 
    376458} 
     
    404486 
    405487PyObject *AssociationRule_str(TPyOrange *self) 
    406 {  
     488{ 
    407489  PyObject *result = callbackOutput((PyObject *)self, NULL, NULL, "str", "repr"); 
    408490  if (result) 
     
    415497 
    416498PyObject *AssociationRule_repr(TPyOrange *self) 
    417 {  
     499{ 
    418500  PyObject *result = callbackOutput((PyObject *)self, NULL, NULL, "repr", "str"); 
    419501  if (result) 
     
    553635 
    554636  /* This works for ordinary (not overloaded) TreeStopCriteria 
    555      and for Python classes derived from TreeStopCriteria.  
     637     and for Python classes derived from TreeStopCriteria. 
    556638     The latter have different self->ob_type, so TreeStopCriteria_new will construct 
    557639     an instance of TreeStopCriteria_Python */ 
     
    561643 
    562644PyObject *TreeStopCriteria_lowcall(PyObject *self, PyObject *args, PyObject *keywords, bool allowPython) 
    563 {  
     645{ 
    564646  static TTreeStopCriteria _cbdefaultStop; 
    565647  PyTRY 
     
    639721        Py_DECREF(item); 
    640722      } 
    641        
     723 
    642724      Py_DECREF(iterator); 
    643725      if (PyErr_Occurred()) 
    644726        return PYNULL; 
    645727    } 
    646      
     728 
    647729    PClassifier branchSelector; 
    648730    PStringList descriptions; 
     
    705787    } 
    706788 
    707   PyCATCH  
     789  PyCATCH 
    708790} 
    709791 
     
    746828 
    747829PyObject *TreePruner_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(tree) -> tree") 
    748 {  
     830{ 
    749831  PyTRY 
    750832    NO_KEYWORDS 
     
    815897PyObject *TreeNodeList__reduce__(TPyOrange *self, PyObject *) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_reduce(self); } 
    816898 
    817   
     899 
    818900/************* C45 ************/ 
    819901 
     
    898980      TFloatList *basesY = mlnew TFloatList(nAnchors); 
    899981      PFloatList wbasesX = basesX, wbasesY = basesY; 
    900     
     982 
    901983      TFloatList::iterator xi(basesX->begin()); 
    902984      TFloatList::iterator yi(basesY->begin()); 
     
    9271009        if (array->dimensions[1] != 3) 
    9281010          PYERROR(PyExc_AttributeError, "the matrix of projections must have three columns", PYNULL); 
    929            
     1011 
    9301012        const char arrayType = getArrayType(array); 
    9311013        if ((arrayType != 'f') && (arrayType != 'd')) 
     
    10411123    buf.writeDouble(p2nn->minClass); 
    10421124    buf.writeDouble(p2nn->maxClass); 
    1043     
     1125 
    10441126    return Py_BuildValue("O(Os#)N", getExportedFunction("__pickleLoaderP2NN"), 
    10451127                                    self->ob_type, 
     
    10561138    char *pbuf; 
    10571139    int bufSize; 
    1058     if (!PyArg_ParseTuple(args, "Os#:__pickleLoaderP2NN", &type, &pbuf, &bufSize))     
     1140    if (!PyArg_ParseTuple(args, "Os#:__pickleLoaderP2NN", &type, &pbuf, &bufSize)) 
    10591141      return NULL; 
    10601142 
     
    11401222      if (error <= TLogRegFitter::Divergence) 
    11411223          return Py_BuildValue("N", WrapOrange(classifier)); 
    1142       else  
     1224      else 
    11431225          return Py_BuildValue("N", WrapOrange(variable)); 
    11441226  PyCATCH 
     
    11641246    int error; 
    11651247    PVariable attribute; 
    1166      
     1248 
    11671249    beta = (*fitter)(egen, weight, beta_se, likelihood, error, attribute); 
    11681250 
     
    13681450  PyCATCH 
    13691451} 
    1370    
     1452 
    13711453 
    13721454PyObject *SVMClassifier_getDecisionValues(PyObject *self, PyObject* args, PyObject *keywords) PYARGS(METH_VARARGS, "(Example) -> list of floats") 
     
    13971479        || !convertFromPython(pyvalue, value, me->domain->classVar)) 
    13981480      return PYNULL; 
    1399        
     1481 
    14001482    return PyFloat_FromDouble((double)SELF_AS(TBayesClassifier).p(value, *ex)); 
    14011483 
     
    14851567    int weightID = 0; 
    14861568    int targetClass = -1; 
    1487      
     1569 
    14881570    if (!PyArg_ParseTuple(args, "O&O&i:RuleEvaluator.call",  pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID, &targetClass)) 
    14891571      return PYNULL; 
     
    15231605    CAST_TO(TRuleEvaluator, evaluator) 
    15241606    float quality; 
    1525       
     1607 
    15261608    quality = (*evaluator)(rule, gen, weightID, targetClass, apriori); 
    15271609    return PyFloat_FromDouble(quality); 
     
    16081690PyObject *RuleValidator_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(rule, table, weightID, targetClass, apriori) -/-> (quality)") 
    16091691{ 
    1610    
     1692 
    16111693  PyTRY 
    16121694    NO_KEYWORDS 
     
    17531835    PRule res = (*finder)(gen, weightID, targetClass, baseRules); 
    17541836    return WrapOrange(res); 
    1755   PyCATCH  
     1837  PyCATCH 
    17561838} 
    17571839 
     
    19021984 
    19031985PyObject *RuleClassifierConstructor_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(rules, examples[, weight]) -> (RuleClassifier)") 
    1904 {  
     1986{ 
    19051987  PyTRY 
    19061988    NO_KEYWORDS 
     
    19252007 
    19262008PyObject *RuleClassifier_logit_new(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(rules, min_beta, examples[, weight])") 
    1927 {  
     2009{ 
    19282010  PyTRY 
    19292011    NO_KEYWORDS 
Note: See TracChangeset for help on using the changeset viewer.