source: orange/source/orange/lib_learner.cpp @ 11805:8c7bac69fbb4

Revision 11805:8c7bac69fbb4, 96.6 KB checked in by Ales Erjavec <ales.erjavec@…>, 4 months ago (diff)

Added a new constructor for CostWrapperClassifier.

It was not possible to construct an instance of CostWrapperClassifier through
the default constructor..

Line 
1#ifdef _MSC_VER
2  #pragma warning (disable : 4786 4114 4018 4267 4244)
3#endif
4
5#include <iostream>
6#include <sstream>
7
8#include "vars.hpp"
9#include "domain.hpp"
10#include "examples.hpp"
11#include "examplegen.hpp"
12#include "nearest.hpp"
13#include "estimateprob.hpp"
14#include "induce.hpp"
15#include "cost.hpp"
16#include "measures.hpp"
17#include "distance.hpp"
18#include "contingency.hpp"
19
20#include "callback.hpp"
21
22#include "cls_orange.hpp"
23#include "cls_value.hpp"
24#include "cls_example.hpp"
25#include "lib_kernel.hpp"
26
27#include "converts.hpp"
28
29#include "vectortemplates.hpp"
30#include "slist.hpp"
31
32#include "externs.px"
33
34/* ************ CLUSTERING TREE LEARNER ************ */
35
36#include "tdidt_clustering.hpp"
37C_CALL(ClusteringTreeLearner - Orange.multitarget.tree.ClusteringTreeLearner, MultiLearner, "([examples], [minMajority=, minMSE=, minExamples=, maxDepth=, method=])")
38C_NAMED(ClusteringTreeClassifier - Orange.multitarget.tree.ClusteringTreeClassifier, MultiClassifier, "()")
39
40PyObject *ClusteringTreeClassifier__reduce__(PyObject *self)
41{
42    PyTRY
43    ostringstream ss;
44
45    CAST_TO(TClusteringTreeClassifier, classifier);
46    classifier->save_model(ss);
47    return Py_BuildValue("O(s)N", getExportedFunction("__pickleLoaderClusteringTreeClassifier"), 
48        ss.str().c_str(), packOrangeDictionary(self));
49    PyCATCH
50}
51
52PyObject *__pickleLoaderClusteringTreeClassifier(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(buffer)")
53{
54    PyTRY
55    char *cbuf;
56    istringstream ss;
57
58    int buffer_size = 0;
59    if (!PyArg_ParseTuple(args, "s:__pickleLoaderClusteringTreeClassifier", &cbuf))
60        return NULL;
61    ss.str(string(cbuf));
62    PClusteringTreeClassifier classifier = mlnew TClusteringTreeClassifier();
63    classifier->load_model(ss);
64    return WrapOrange(classifier);
65    PyCATCH
66}
67
68
69/* ************ SIMPLE TREE LEARNER ************ */
70
71#include "tdidt_simple.hpp"
72C_CALL(SimpleTreeLearner - Orange.classification.tree.SimpleTreeLearner, Learner, "([examples], [maxMajority=, minExamples=, maxDepth=])")
73C_NAMED(SimpleTreeClassifier - Orange.classification.tree.SimpleTreeClassifier, Classifier, "()")
74
75PyObject *SimpleTreeClassifier__reduce__(PyObject *self)
76{
77    PyTRY
78    ostringstream ss;
79
80    CAST_TO(TSimpleTreeClassifier, classifier);
81    classifier->save_model(ss);
82    return Py_BuildValue("O(s)N", getExportedFunction("__pickleLoaderSimpleTreeClassifier"), 
83        ss.str().c_str(), packOrangeDictionary(self));
84    PyCATCH
85}
86
87PyObject *__pickleLoaderSimpleTreeClassifier(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(buffer)")
88{
89    PyTRY
90    char *cbuf;
91    istringstream ss;
92
93    int buffer_size = 0;
94    if (!PyArg_ParseTuple(args, "s:__pickleLoaderSimpleTreeClassifier", &cbuf))
95        return NULL;
96    ss.str(string(cbuf));
97    PSimpleTreeClassifier classifier = mlnew TSimpleTreeClassifier();
98    classifier->load_model(ss);
99    return WrapOrange(classifier);
100    PyCATCH
101}
102
103
104/* ************ MAJORITY AND COST ************ */
105
106#include "majority.hpp"
107C_CALL(MajorityLearner - Orange.classification.majority.MajorityLearner, Learner, "([examples] [, weight=, estimate=]) -/-> Classifier")
108C_CALL(CostLearner - Orange.wrappers.CostLearner, Learner, "([examples] [, weight=, estimate=, costs=]) -/-> Classifier")
109
110
111#include "costwrapper.hpp"
112C_CALL(CostWrapperLearner - Orange.wrappers.CostWrapperLearner, Learner, "([examples] [, weight=, cost_matrix=]) -/-> Classifier")
113C_NAMED(CostWrapperClassifier - Orange.wrappers.CostWrapperClassifier, Classifier, "(classifier, cost_matrix)")
114
115
116PyObject *CostWrapperClassifier_new(PyTypeObject *type, PyObject *args)
117{
118  PyTRY
119    PClassifier classifier;
120    PCostMatrix costMatrix;
121    if (!PyArg_ParseTuple(args, "O&O&:CostWrapperClassifier.__new__", cc_Classifier, &classifier, cc_CostMatrix, &costMatrix)) {
122        raiseError("A Classifier and CostMatrix expected.");
123    }
124    return WrapNewOrange(mlnew TCostWrapperClassifier(costMatrix, classifier), type);
125  PyCATCH
126}
127
128/************* ASSOCIATION RULES ************/
129
130#include "assoc.hpp"
131C_CALL(AssociationLearner, Learner, "([examples] [, weight=, conf=, supp=, voteWeight=]) -/-> Classifier")
132C_NAMED(AssociationClassifier, ClassifierFD, "([rules=, voteWeight=])")
133C_CALL3(AssociationRulesInducer - Orange.associate.AssociationRulesInducer, AssociationRulesInducer, Orange, "([examples[, weightID]], confidence=, support=]) -/-> AssociationRules")
134C_CALL3(AssociationRulesSparseInducer - Orange.associate.AssociationRulesSparseInducer, AssociationRulesSparseInducer, Orange, "([examples[, weightID]], confidence=, support=]) -/-> AssociationRules")
135C_CALL3(ItemsetsSparseInducer - Orange.associate.ItemsetsSparseInducer, ItemsetsSparseInducer, Orange, "([examples[, weightID]], support=]) -/-> AssociationRules")
136
137BASED_ON(ItemsetNodeProxy - Orange.associate.ItemsetNodeProxy, Orange)
138
139bool operator < (const TAssociationRule &, const TAssociationRule &) { return false; }
140bool operator > (const TAssociationRule &, const TAssociationRule &) { return false; }
141
142PyObject *AssociationRulesInducer_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(examples[, weightID]) -> AssociationRules")
143{
144  PyTRY
145    NO_KEYWORDS
146
147    int weightID;
148    PExampleGenerator egen = exampleGenFromArgs(args, weightID);
149    if (!egen)
150      return PYNULL;
151
152    return WrapOrange(SELF_AS(TAssociationRulesInducer)(egen, weightID));
153  PyCATCH
154}
155
156void gatherRules(TItemSetNode *node, vector<pair<int, int> > &itemsSoFar, PyObject *listOfItems, bool storeExamples)
157{
158  for(; node; node = node->nextAttribute) {
159    itemsSoFar.push_back(make_pair(node->attrIndex, (int)0));
160    ITERATE(vector<TItemSetValue>, isi, node->values) {
161      itemsSoFar.back().second = (*isi).value;
162
163      PyObject *itemset = PyTuple_New(itemsSoFar.size());
164      int el = 0;
165      vector<pair<int, int> >::const_iterator sfi(itemsSoFar.begin()), sfe(itemsSoFar.end());
166      for(; sfi != sfe; sfi++, el++) {
167        PyObject *vp = PyTuple_New(2);
168        PyTuple_SET_ITEM(vp, 0, PyInt_FromLong((*sfi).first));
169        PyTuple_SET_ITEM(vp, 1, PyInt_FromLong((*sfi).second));
170        PyTuple_SET_ITEM(itemset, el, vp);
171      }
172
173      PyObject *examples;
174      if (storeExamples) {
175        examples = PyList_New((*isi).examples.size());
176        Py_ssize_t ele = 0;
177        ITERATE(TExampleSet, ei, (*isi).examples)
178          PyList_SetItem(examples, ele++, PyInt_FromLong((*ei).example));
179      }
180      else {
181        examples = Py_None;
182        Py_INCREF(Py_None);
183      }
184
185      PyObject *rr = PyTuple_New(2);
186      PyTuple_SET_ITEM(rr, 0, itemset);
187      PyTuple_SET_ITEM(rr, 1, examples);
188
189      PyList_Append(listOfItems, rr);
190      Py_DECREF(rr);
191
192      gatherRules((*isi).branch, itemsSoFar, listOfItems, storeExamples);
193    }
194    itemsSoFar.pop_back();
195  }
196}
197
198PyObject *AssociationRulesInducer_getItemsets(PyObject *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS, "(examples[, weightID]) -> list-of-itemsets")
199{
200  PyTRY
201    int weightID;
202    PExampleGenerator egen = exampleGenFromArgs(args, weightID);
203    if (!egen)
204      return PYNULL;
205
206    if (egen->domain->hasContinuousAttributes(true))
207      PYERROR(PyExc_TypeError, "cannot induce rules with non-discrete attributes", NULL);
208
209    TItemSetNode *tree = NULL;
210    PyObject *listOfItemsets = NULL;
211    try {
212        int depth, nOfExamples;
213        TDiscDistribution classDist;
214        CAST_TO(TAssociationRulesInducer, inducer);
215        inducer->buildTrees(egen, weightID, tree, depth, nOfExamples, classDist);
216
217        listOfItemsets = PyList_New(0);
218        vector<pair<int, int> > itemsSoFar;
219        gatherRules(tree, itemsSoFar, listOfItemsets, inducer->storeExamples);
220    }
221    catch (...) {
222        if (tree)
223            delete tree;
224        throw;
225    }
226
227    delete tree;
228    return listOfItemsets;
229  PyCATCH
230}
231
232
233void gatherRules(TSparseItemsetNode *node, vector<int> &itemsSoFar, PyObject *listOfItems, bool storeExamples)
234{
235    if (itemsSoFar.size()) {
236        PyObject *itemset = PyTuple_New(itemsSoFar.size());
237        Py_ssize_t el = 0;
238        vector<int>::const_iterator sfi(itemsSoFar.begin()), sfe(itemsSoFar.end());
239        for(; sfi != sfe; sfi++, el++)
240            PyTuple_SET_ITEM(itemset, el, PyInt_FromLong(*sfi));
241
242        PyObject *examples;
243        if (storeExamples) {
244          examples = PyList_New(node->exampleIds.size());
245          Py_ssize_t ele = 0;
246          ITERATE(vector<int>, ei, node->exampleIds)
247            PyList_SetItem(examples, ele++, PyInt_FromLong(*ei));
248        }
249        else {
250          examples = Py_None;
251          Py_INCREF(Py_None);
252        }
253
254      PyObject *rr = PyTuple_New(2);
255      PyTuple_SET_ITEM(rr, 0, itemset);
256      PyTuple_SET_ITEM(rr, 1, examples);
257
258      PyList_Append(listOfItems, rr);
259      Py_DECREF(rr);
260    }
261
262    itemsSoFar.push_back(0);
263    ITERATE(TSparseISubNodes, isi, node->subNode) {
264        itemsSoFar.back() = (*isi).first;
265        gatherRules((*isi).second, itemsSoFar, listOfItems, storeExamples);
266    }
267    itemsSoFar.pop_back();
268}
269
270
271PyObject *AssociationRulesSparseInducer_getItemsets(PyObject *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS, "(examples[, weightID]) -> list-of-itemsets")
272{
273  PyTRY
274    int weightID;
275    PExampleGenerator egen = exampleGenFromArgs(args, weightID);
276    if (!egen)
277      return PYNULL;
278
279    CAST_TO(TAssociationRulesSparseInducer, inducer);
280    long i;
281    float fullWeight;
282    TSparseItemsetTree *tree = NULL;
283    PyObject *listOfItemsets = NULL;
284
285    try {
286          tree = inducer->buildTree(egen, weightID, i, fullWeight);
287        listOfItemsets = PyList_New(0);
288        vector<int> itemsSoFar;
289        gatherRules(tree->root, itemsSoFar, listOfItemsets, inducer->storeExamples);
290    }
291    catch (...) {
292        if (tree)
293            delete tree;
294        throw;
295    }
296
297    delete tree;
298    return listOfItemsets;
299  PyCATCH
300}
301
302PyObject *AssociationRulesSparseInducer_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(examples[, weightID]) -> AssociationRules")
303{
304  PyTRY
305    NO_KEYWORDS
306
307    int weightID = 0;
308    PExampleGenerator egen =  exampleGenFromArgs(args, weightID);
309    if (!egen)
310      return PYNULL;
311
312    return WrapOrange(SELF_AS(TAssociationRulesSparseInducer)(egen, weightID));
313  PyCATCH
314}
315
316class TItemsetNodeProxy : public TOrange {
317public:
318    const TSparseItemsetNode *node;
319    PSparseItemsetTree tree;
320
321    TItemsetNodeProxy(const TSparseItemsetNode *n, PSparseItemsetTree t)
322    : node(n),
323    tree(t)
324    {}
325};
326
327
328PyObject *ItemsetsSparseInducer_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(examples[, weightID]) -> AssociationRules")
329{
330  PyTRY
331    NO_KEYWORDS
332
333    int weightID = 0;
334    PExampleGenerator egen =  exampleGenFromArgs(args, weightID);
335    if (!egen)
336      return PYNULL;
337
338    PSparseItemsetTree tree = SELF_AS(TItemsetsSparseInducer)(egen, weightID);
339    return WrapOrange(POrange(new TItemsetNodeProxy(tree->root, tree)));
340  PyCATCH
341}
342
343PYXTRACT_IGNORE int Orange_traverse(TPyOrange *, visitproc, void *);
344PYXTRACT_IGNORE int Orange_clear(TPyOrange *);
345
346int ItemsetNodeProxy_traverse(PyObject *self, visitproc visit, void *arg)
347{
348    int err = Orange_traverse((TPyOrange *)self, visit, arg);
349    if (err)
350        return err;
351
352    CAST_TO_err(TItemsetNodeProxy, node, -1);
353    PVISIT(node->tree);
354  PVISIT(node->tree->domain);
355    return 0;
356}
357
358int ItemsetNodeProxy_clear(PyObject *self)
359{
360  SELF_AS(TItemsetNodeProxy).tree = PSparseItemsetTree();
361    return Orange_clear((TPyOrange *)self);
362}
363
364PyObject *ItemsetNodeProxy_get_children(PyObject *self)
365{
366  PyTRY
367    CAST_TO(TItemsetNodeProxy, nodeProxy);
368    const TSparseItemsetNode *me = nodeProxy->node;
369    PyObject *children = PyDict_New();
370    const_ITERATE(TSparseISubNodes, ci, me->subNode)
371      PyDict_SetItem(children, PyInt_FromLong(ci->first), WrapOrange(POrange(new TItemsetNodeProxy(ci->second, nodeProxy->tree))));
372    return children;
373  PyCATCH
374}
375
376PyObject *ItemsetNodeProxy_get_examples(PyObject *self)
377{
378  PyTRY
379    const TSparseItemsetNode *me = SELF_AS(TItemsetNodeProxy).node;
380    PyObject *examples = PyList_New(me->exampleIds.size());
381    Py_ssize_t i = 0;
382    const_ITERATE(vector<int>, ci, me->exampleIds)
383      PyList_SetItem(examples, i++, PyInt_FromLong(*ci));
384    return examples;
385  PyCATCH
386}
387
388PyObject *ItemsetNodeProxy_get_support(PyObject *self)
389{
390  PyTRY
391    return PyFloat_FromDouble(SELF_AS(TItemsetNodeProxy).node->weiSupp);
392  PyCATCH
393}
394
395PyObject *ItemsetNodeProxy_get_itemId(PyObject *self)
396{
397  PyTRY
398    return PyInt_FromLong(SELF_AS(TItemsetNodeProxy).node->value);
399  PyCATCH
400}
401
402
403
404bool convertFromPython(PyObject *, PAssociationRule &);
405
406PyObject *AssociationRule_new(PyTypeObject *type, PyObject *args, PyObject *) BASED_ON(Orange - Orange.associate.AssociationRule, "(left, right, support, confidence)")
407{ PyTRY
408    PAssociationRule rule;
409    return  convertFromPython(args, rule) ? WrapOrange(rule) : PYNULL;
410  PyCATCH
411}
412
413PyObject *AssociationRule__reduce__(PyObject *self)
414{
415  PyTRY
416    CAST_TO(TAssociationRule, arule);
417    return Py_BuildValue("O(NN)N", self->ob_type,
418                                   Example_FromWrappedExample(arule->left),
419                                   Example_FromWrappedExample(arule->right),
420                                   packOrangeDictionary(self));
421  PyCATCH
422}
423
424
425PyObject *AssociationRule_appliesLeft(PyObject *self, PyObject *arg, PyObject *) PYARGS(METH_O, "(example) -> bool")
426{ PyTRY
427    if (!PyOrExample_Check(arg))
428      PYERROR(PyExc_TypeError, "attribute error (example expected)", PYNULL);
429
430    CAST_TO(TAssociationRule, rule)
431    return PyInt_FromLong(rule->appliesLeft(PyExample_AS_ExampleReference(arg)) ? 1 : 0);
432  PyCATCH
433}
434
435
436PyObject *AssociationRule_appliesRight(PyObject *self, PyObject *arg, PyObject *) PYARGS(METH_O, "(example) -> bool")
437{ PyTRY
438    if (!PyOrExample_Check(arg))
439      PYERROR(PyExc_TypeError, "attribute error (example expected)", PYNULL);
440
441    CAST_TO(TAssociationRule, rule)
442    return PyInt_FromLong(rule->appliesRight(PyExample_AS_ExampleReference(arg)) ? 1 : 0);
443  PyCATCH
444}
445
446
447PyObject *AssociationRule_appliesBoth(PyObject *self, PyObject *arg, PyObject *) PYARGS(METH_O, "(example) -> bool")
448{ PyTRY
449    if (!PyOrExample_Check(arg))
450      PYERROR(PyExc_TypeError, "attribute error (example expected)", PYNULL);
451
452    CAST_TO(TAssociationRule, rule)
453    return PyInt_FromLong(rule->appliesBoth(PyExample_AS_ExampleReference(arg)) ? 1 : 0);
454  PyCATCH
455}
456
457
458PyObject *AssociationRule_native(PyObject *self)
459{ PyTRY
460    CAST_TO(TAssociationRule, rule)
461    return Py_BuildValue("NNff", Example_FromWrappedExample(rule->left), Example_FromWrappedExample(rule->right), rule->support, rule->confidence);
462  PyCATCH
463}
464
465bool convertFromPython(PyObject *obj, PAssociationRule &rule)
466{ if (PyOrOrange_Check(obj))
467    if (!PyOrange_AS_Orange(obj)) {
468      rule = PAssociationRule();
469      return true;
470    }
471    else if (PyOrAssociationRule_Check(obj)) {
472      rule = PyOrange_AsAssociationRule(obj);
473      return true;
474    }
475
476  TExample *le, *re;
477
478  switch (PyTuple_Size(obj)) {
479    case 6:
480      float nAppliesLeft, nAppliesRight, nAppliesBoth, nExamples;
481      if (PyArg_ParseTuple(obj, "O&O&ffff:convertFromPython(AssociationRule)", ptr_Example, &le, ptr_Example, &re, &nAppliesLeft, &nAppliesRight, &nAppliesBoth, &nExamples)) {
482        PExample nle = mlnew TExample(*le);
483        PExample nre = mlnew TExample(*re);
484        rule = mlnew TAssociationRule(nle, nre, nAppliesLeft, nAppliesRight, nAppliesBoth, nExamples);
485        return true;
486      }
487      else
488        break;
489
490    case 2:
491    case 3:
492    case 4: {
493      float support = -1, confidence = -1;
494      if (PyArg_ParseTuple(obj, "O&O&|ff:convertFromPython(AssociationRule)", ptr_Example, &le, ptr_Example, &re, &support, &confidence)) {
495        PExample nle = mlnew TExample(*le);
496        PExample nre = mlnew TExample(*re);
497        rule = mlnew TAssociationRule(nle, nre);
498        rule->support = support;
499        rule->confidence = confidence;
500        return true;
501      }
502      else
503        break;
504    }
505
506    case 1:
507      if (PyArg_ParseTuple(obj, "O&:convertFromPython(AssociationRule)", cc_AssociationRule, &rule))
508        return true;
509      else
510        break;
511  }
512
513  PYERROR(PyExc_TypeError, "invalid arguments", false);
514}
515
516
517string side2string(PExample ex)
518{ string res;
519
520  if (ex->domain->variables->empty())
521    ITERATE(TMetaValues, mi, ex->meta) {
522      if (res.length())
523        res += " ";
524      res += ex->domain->getMetaVar((*mi).first)->get_name();
525    }
526
527  else {
528    string val;
529
530    TVarList::const_iterator vi(ex->domain->variables->begin());
531    for(TExample::const_iterator ei(ex->begin()), ee(ex->end()); ei!=ee; ei++, vi++)
532      if (!(*ei).isSpecial()) {
533        if (res.length())
534          res += " ";
535        (*vi)->val2str(*ei, val);
536        res += (*vi)->get_name() + "=" + val;
537      }
538  }
539
540  return res;
541}
542
543PyObject *AssociationRule_str(TPyOrange *self)
544{
545  PyObject *result = callbackOutput((PyObject *)self, NULL, NULL, "str", "repr");
546  if (result)
547    return result;
548
549  CAST_TO(TAssociationRule, rule);
550  return PyString_FromFormat("%s -> %s", side2string(rule->left).c_str(), side2string(rule->right).c_str());
551}
552
553
554PyObject *AssociationRule_repr(TPyOrange *self)
555{
556  PyObject *result = callbackOutput((PyObject *)self, NULL, NULL, "repr", "str");
557  if (result)
558    return result;
559
560  CAST_TO(TAssociationRule, rule);
561  return PyString_FromFormat("%s -> %s", side2string(rule->left).c_str(), side2string(rule->right).c_str());
562}
563
564
565PAssociationRules PAssociationRules_FromArguments(PyObject *arg) { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::P_FromArguments(arg); }
566PyObject *AssociationRules_FromArguments(PyTypeObject *type, PyObject *arg) { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_FromArguments(type, arg); }
567PyObject *AssociationRules_new(PyTypeObject *type, PyObject *arg, PyObject *kwds) BASED_ON(Orange - Orange.associate.AssociationRules, "(<list of AssociationRule>)")  ALLOWS_EMPTY { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_new(type, arg, kwds); }
568PyObject *AssociationRules_getitem_sq(TPyOrange *self, Py_ssize_t index) { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_getitem(self, index); }
569int       AssociationRules_setitem_sq(TPyOrange *self, Py_ssize_t index, PyObject *item) { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_setitem(self, index, item); }
570PyObject *AssociationRules_getslice(TPyOrange *self, Py_ssize_t start, Py_ssize_t stop) { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_getslice(self, start, stop); }
571int       AssociationRules_setslice(TPyOrange *self, Py_ssize_t start, Py_ssize_t stop, PyObject *item) { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_setslice(self, start, stop, item); }
572Py_ssize_t       AssociationRules_len_sq(TPyOrange *self) { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_len(self); }
573PyObject *AssociationRules_richcmp(TPyOrange *self, PyObject *object, int op) { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_richcmp(self, object, op); }
574PyObject *AssociationRules_concat(TPyOrange *self, PyObject *obj) { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_concat(self, obj); }
575PyObject *AssociationRules_repeat(TPyOrange *self, Py_ssize_t times) { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_repeat(self, times); }
576PyObject *AssociationRules_str(TPyOrange *self) { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_str(self); }
577PyObject *AssociationRules_repr(TPyOrange *self) { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_str(self); }
578int       AssociationRules_contains(TPyOrange *self, PyObject *obj) { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_contains(self, obj); }
579PyObject *AssociationRules_append(TPyOrange *self, PyObject *item) PYARGS(METH_O, "(AssociationRule) -> None") { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_append(self, item); }
580PyObject *AssociationRules_extend(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(sequence) -> None") { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_extend(self, obj); }
581PyObject *AssociationRules_count(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(AssociationRule) -> int") { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_count(self, obj); }
582PyObject *AssociationRules_filter(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "([filter-function]) -> AssociationRules") { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_filter(self, args); }
583PyObject *AssociationRules_index(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(AssociationRule) -> int") { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_index(self, obj); }
584PyObject *AssociationRules_insert(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "(index, item) -> None") { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_insert(self, args); }
585PyObject *AssociationRules_native(TPyOrange *self) PYARGS(METH_NOARGS, "() -> list") { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_native(self); }
586PyObject *AssociationRules_pop(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "() -> AssociationRule") { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_pop(self, args); }
587PyObject *AssociationRules_remove(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(AssociationRule) -> None") { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_remove(self, obj); }
588PyObject *AssociationRules_reverse(TPyOrange *self) PYARGS(METH_NOARGS, "() -> None") { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_reverse(self); }
589PyObject *AssociationRules_sort(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "([cmp-func]) -> None") { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_sort(self, args); }
590PyObject *AssociationRules__reduce__(TPyOrange *self, PyObject *) { return ListOfWrappedMethods<PAssociationRules, TAssociationRules, PAssociationRule, &PyOrAssociationRule_Type>::_reduce(self); }
591
592/************* CLASSIFICATION TREES ************/
593
594#include "tdidt.hpp"
595#include "tdidt_split.hpp"
596#include "tdidt_stop.hpp"
597#include "callback.hpp"
598
599C_CALL(TreeLearner - Orange.classification.tree._TreeLearner, Learner, "([examples] [, weight=, split=, stop=, nodeLearner=, lookDownOnUnknown=]) -/-> Classifier")
600
601C_NAMED(TreeNode - Orange.classification.tree.Node, Orange, "([lookDownOnUnknown=, branchSelector=, nodeClassifier=, branches=, contingency=])")
602C_NAMED(TreeClassifier - Orange.classification.tree._TreeClassifier, ClassifierFD, "([domain=, tree=, descender=])")
603
604C_NAMED(TreeStopCriteria_common - Orange.classification.tree.StopCriteria_common, TreeStopCriteria, "([maxMajority=, minExamples=])")
605HIDDEN(TreeStopCriteria_Python - Orange.classification.tree.StopCriteria_Python, TreeStopCriteria)
606NO_PICKLE(TreeStopCriteria_Python)
607
608C_CALL(TreeSplitConstructor_Combined - Orange.classification.tree.SplitConstructor_Combined, TreeSplitConstructor, "([examples, [weight, domainContingency, apriorClass, candidates] [discreteTreeSplitConstructor=, continuousTreeSplitConstructor=]) -/-> (Classifier, descriptions, sizes, quality)")
609
610ABSTRACT(TreeSplitConstructor_Measure - Orange.classification.tree.SplitConstructor_Score, TreeSplitConstructor)
611C_CALL(TreeSplitConstructor_Attribute - Orange.classification.tree.SplitConstructor_Feature, TreeSplitConstructor_Measure, "([measure=, worstAcceptable=, minSubset=])")
612C_CALL(TreeSplitConstructor_ExhaustiveBinary - Orange.classification.tree.SplitConstructor_ExhaustiveBinary, TreeSplitConstructor_Measure, "([measure=, worstAcceptable=, minSubset=])")
613C_CALL(TreeSplitConstructor_OneAgainstOthers - Orange.classification.tree.SplitConstructor_OneAgainstOthers, TreeSplitConstructor_Measure, "([measure=, worstAcceptable=, minSubset=])")
614C_CALL(TreeSplitConstructor_Threshold - Orange.classification.tree.SplitConstructor_Threshold, TreeSplitConstructor_Measure, "([measure=, worstAcceptable=, minSubset=])")
615PYXTRACT_IGNORE C_CALL(TreeSplitConstructor_LR - Orange.classification.tree.SplitConstructor_LR, TreeSplitConstructor, "([minSubset=])")
616
617BASED_ON(TreeExampleSplitter - Orange.classification.tree.Splitter, Orange)
618
619C_CALL(TreeExampleSplitter_IgnoreUnknowns - Orange.classification.tree.Splitter_IgnoreUnknowns, TreeExampleSplitter, "([node, examples[, weight]]) -/-> (ExampleGeneratorList, [list of weight ID's])")
620C_CALL(TreeExampleSplitter_UnknownsToCommon - Orange.classification.tree.Splitter_UnknownsToCommon, TreeExampleSplitter, "([node, examples[, weight]]) -/-> (ExampleGeneratorList, [list of weight ID's])")
621C_CALL(TreeExampleSplitter_UnknownsToAll - Orange.classification.tree.Splitter_UnknownsToAll, TreeExampleSplitter, "([node, examples[, weight]]) -/-> (ExampleGeneratorList, [list of weight ID's])")
622C_CALL(TreeExampleSplitter_UnknownsToRandom - Orange.classification.tree.Splitter_UnknownsToRandom, TreeExampleSplitter, "([node, examples[, weight]]) -/-> (ExampleGeneratorList, [list of weight ID's])")
623C_CALL(TreeExampleSplitter_UnknownsToBranch - Orange.classification.tree.Splitter_UnknownsToBranch, TreeExampleSplitter, "([node, examples[, weight]]) -/-> (ExampleGeneratorList, [list of weight ID's])")
624
625C_CALL(TreeExampleSplitter_UnknownsAsBranchSizes - Orange.classification.tree.Splitter_UnknownsAsBranchSizes, TreeExampleSplitter, "([branchIndex, node, examples[, weight]]) -/-> (ExampleGenerator, [list of weight ID's])")
626C_CALL(TreeExampleSplitter_UnknownsAsSelector - Orange.classification.tree.Splitter_UnknownsAsSelector, TreeExampleSplitter, "([branchIndex, node, examples[, weight]]) -/-> (ExampleGenerator, [list of weight ID's])")
627
628C_CALL(TreeDescender_UnknownToBranch - Orange.classification.tree.Descender_UnknownToBranch, TreeDescender, "(node, example) -/-> (node, {distribution | None})")
629C_CALL(TreeDescender_UnknownToCommonBranch - Orange.classification.tree.Descender_UnknownToCommonBranch, TreeDescender, "(node, example) -/-> (node, {distribution | None})")
630C_CALL(TreeDescender_UnknownToCommonSelector - Orange.classification.tree.Descender_UnknownToCommonSelector, TreeDescender, "(node, example) -/-> (node, {distribution | None})")
631C_CALL(TreeDescender_UnknownMergeAsBranchSizes - Orange.classification.tree.Descender_UnknownMergeAsBranchSizes, TreeDescender, "(node, example) -/-> (node, {distribution | None})")
632C_CALL(TreeDescender_UnknownMergeAsSelector - Orange.classification.tree.Descender_UnknownMergeAsSelector, TreeDescender, "(node, example) -/-> (node, {distribution | None})")
633
634ABSTRACT(TreePruner - Orange.classification.tree.Pruner, Orange)
635C_CALL (TreePruner_SameMajority - Orange.classification.tree.Pruner_SameMajority, TreePruner, "([tree]) -/-> tree")
636C_CALL (TreePruner_m - Orange.classification.tree.Pruner_m, TreePruner, "([tree]) -/-> tree")
637
638
639PyObject *TreeNode_tree_size(PyObject *self, PyObject *, PyObject *) PYARGS(METH_NOARGS, "() -> int")
640{ PyTRY
641    return PyInt_FromLong(PyOrange_AsTreeNode(self)->treeSize());
642  PyCATCH
643}
644
645
646PyObject *TreeNode_remove_stored_info(PyObject *self, PyObject *, PyObject *) PYARGS(METH_NOARGS, "() -> None")
647{ PyTRY
648    PyOrange_AsTreeNode(self)->removeStoredInfo();
649    RETURN_NONE;
650  PyCATCH
651}
652
653
654PyObject *TreeStopCriteria_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.tree.StopCriteria, "()")
655{ if (type == (PyTypeObject *)&PyOrTreeStopCriteria_Type) {
656      PyObject *name=NULL;
657      if (args && !PyArg_ParseTuple(args, "|O", &name))
658        PYERROR(PyExc_TypeError, "TreeStopCriteria: invalid arguments - name or callback function expected", PYNULL);
659
660      if (!args || !name || name && PyString_Check(name)) {
661          PyObject *self = WrapNewOrange(mlnew TTreeStopCriteria(), type);
662          if (name)
663            PyObject_SetAttrString(self, "name", name);
664          return self;
665      }
666      // (args && name && !PyStringString_Check(name)
667
668      return setCallbackFunction(WrapNewOrange(mlnew TTreeStopCriteria_Python(), type), args);
669  }
670
671  return WrapNewOrange(mlnew TTreeStopCriteria_Python(), type);
672}
673
674
675/* This is all twisted: Python classes are derived from TreeStopCriteria;
676   although the underlying C++ structure is TreeStopCriteria_Python,
677   the Python base is always TreeStopCritera. We must therefore define
678   TreeStopCriteria__reduce__ to handle both C++ objects, and need not
679   define TreeStopCriteria_Python__reduce__
680*/
681
682PyObject *TreeStopCriteria__reduce__(PyObject *self)
683{
684  POrange orself = PyOrange_AS_Orange(self);
685
686  if (orself.is_derived_from(TTreeStopCriteria_Python) && PyObject_HasAttrString(self, "__callback")) {
687    PyObject *packed = packOrangeDictionary(self);
688    PyObject *callback = PyDict_GetItemString(packed, "__callback");
689    PyDict_DelItemString(packed, "__callback");
690    return Py_BuildValue("O(O)N", self->ob_type, callback, packed);
691  }
692
693  /* This works for ordinary (not overloaded) TreeStopCriteria
694     and for Python classes derived from TreeStopCriteria.
695     The latter have different self->ob_type, so TreeStopCriteria_new will construct
696     an instance of TreeStopCriteria_Python */
697  return Py_BuildValue("O()N", self->ob_type, packOrangeDictionary(self));
698}
699
700
701PyObject *TreeStopCriteria_lowcall(PyObject *self, PyObject *args, PyObject *keywords, bool allowPython)
702{
703  static TTreeStopCriteria _cbdefaultStop;
704  PyTRY
705    NO_KEYWORDS
706
707    CAST_TO(TTreeStopCriteria, stop);
708    if (!stop)
709      PYERROR(PyExc_SystemError, "attribute error", PYNULL);
710
711    PExampleGenerator egen;
712    PDomainContingency dcont;
713    int weight = 0;
714    if (!PyArg_ParseTuple(args, "O&|O&O&:TreeStopCriteria.__call__", pt_ExampleGenerator, &egen, pt_weightByGen(egen), &weight, ptn_DomainContingency, &dcont))
715      return PYNULL;
716
717    bool res;
718
719    if (allowPython || (stop->classDescription() != &TTreeStopCriteria_Python::st_classDescription))
720      res = (*stop)(egen, weight, dcont);
721    else
722      res = _cbdefaultStop(egen, weight, dcont);
723
724    return PyInt_FromLong(res ? 1 : 0);
725  PyCATCH
726}
727
728
729PyObject *TreeStopCriteria_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("([examples, [weight, domainContingency]) -> bool")
730{  return TreeStopCriteria_lowcall(self, args, keywords, false); }
731
732
733PyObject *TreeStopCriteria_Python_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("([examples, [weight, domainContingency, apriorClass, candidates]) -/-> (Classifier, descriptions, sizes, quality)")
734{ return TreeStopCriteria_lowcall(self, args, keywords, false); }
735
736
737
738PyObject *TreeSplitConstructor_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.tree.SplitConstructor, "<abstract>")
739{ if (type == (PyTypeObject *)&PyOrTreeSplitConstructor_Type)
740    return setCallbackFunction(WrapNewOrange(mlnew TTreeSplitConstructor_Python(), type), args);
741  else
742    return WrapNewOrange(mlnew TTreeSplitConstructor_Python(), type);
743}
744
745
746PyObject *TreeSplitConstructor__reduce__(PyObject *self)
747{
748  return callbackReduce(self, PyOrTreeSplitConstructor_Type);
749}
750
751
752PyObject *TreeSplitConstructor_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(examples[, weight, contingency, apriori class distribution, candidates, nodeClassifier]) -> (Classifier, descriptions, sizes, quality)")
753{ PyTRY
754    NO_KEYWORDS
755
756    if (PyOrange_OrangeBaseClass(self->ob_type) == &PyOrTreeSplitConstructor_Type) {
757      PyErr_Format(PyExc_SystemError, "TreeSplitConstructor.call called for '%s': this may lead to stack overflow", self->ob_type->tp_name);
758      return PYNULL;
759    }
760
761    PExampleGenerator gen;
762    int weightID = 0;
763    PDomainContingency dcont;
764    PDistribution apriori;
765    PyObject *pycandidates = PYNULL;
766    PClassifier nodeClassifier;
767
768    if (!PyArg_ParseTuple(args, "O&|O&O&O&OO&:TreeSplitConstructor.call", pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID, ccn_DomainContingency, &dcont, ccn_Distribution, &apriori, &pycandidates, ccn_Classifier, &nodeClassifier))
769      return PYNULL;
770
771    vector<bool> candidates;
772    if (pycandidates) {
773      PyObject *iterator = PyObject_GetIter(pycandidates);
774      if (!iterator)
775        PYERROR(PyExc_SystemError, "TreeSplitConstructor.call: cannot iterate through candidates; a list exected", PYNULL);
776      for(PyObject *item = PyIter_Next(iterator); item; item = PyIter_Next(iterator)) {
777        candidates.push_back(PyObject_IsTrue(item) != 0);
778        Py_DECREF(item);
779      }
780
781      Py_DECREF(iterator);
782      if (PyErr_Occurred())
783        return PYNULL;
784    }
785
786    PClassifier branchSelector;
787    PStringList descriptions;
788    PDiscDistribution subsetSizes;
789    float quality;
790    int spentAttribute;
791
792    branchSelector = SELF_AS(TTreeSplitConstructor)(descriptions, subsetSizes, quality, spentAttribute,
793                                                    gen, weightID, dcont, apriori, candidates, nodeClassifier);
794
795    return Py_BuildValue("NNNfi", WrapOrange(branchSelector), WrapOrange(descriptions), WrapOrange(subsetSizes), quality, spentAttribute);
796  PyCATCH
797}
798
799
800PyObject *TreeExampleSplitter_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.tree.Splitter, "<abstract>")
801{ if (type == (PyTypeObject *)&PyOrTreeExampleSplitter_Type)
802    return setCallbackFunction(WrapNewOrange(mlnew TTreeExampleSplitter_Python(), type), args);
803  else
804    return WrapNewOrange(mlnew TTreeExampleSplitter_Python(), type);
805}
806
807
808PyObject *TreeExampleSplitter__reduce__(PyObject *self)
809{
810  return callbackReduce(self, PyOrTreeExampleSplitter_Type);
811}
812
813
814PyObject *TreeExampleSplitter_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(node, examples[, weight]) -/-> (ExampleGeneratorList, list of weight ID's")
815{ PyTRY
816    NO_KEYWORDS
817
818    if (PyOrange_OrangeBaseClass(self->ob_type) == &PyOrTreeExampleSplitter_Type) {
819      PyErr_Format(PyExc_SystemError, "TreeExampleSplitter.call called for '%s': this may lead to stack overflow", self->ob_type->tp_name);
820      return PYNULL;
821    }
822
823    PTreeNode node;
824    PExampleGenerator gen;
825    int weightID = 0;
826
827    if (!PyArg_ParseTuple(args, "O&O&|O&:TreeExampleSplitter.call", cc_TreeNode, &node, pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID))
828      return PYNULL;
829
830    vector<int> newWeights;
831    PExampleGeneratorList egl = SELF_AS(TTreeExampleSplitter)(node, gen, weightID, newWeights);
832
833    if (newWeights.size()) {
834      PyObject *pyweights = PyList_New(newWeights.size());
835      Py_ssize_t i = 0;
836      ITERATE(vector<int>, li, newWeights)
837        PyList_SetItem(pyweights, i++, PyInt_FromLong(*li));
838
839      return Py_BuildValue("NN", WrapOrange(egl), pyweights);
840    }
841
842    else {
843      return Py_BuildValue("NO", WrapOrange(egl), Py_None);
844    }
845
846  PyCATCH
847}
848
849
850
851PyObject *TreeDescender_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.tree.Descender, "<abstract>")
852{ if (type == (PyTypeObject *)&PyOrTreeDescender_Type)
853    return setCallbackFunction(WrapNewOrange(mlnew TMeasureAttribute_Python(), type), args);
854  else
855    return WrapNewOrange(mlnew TTreeDescender_Python(), type);
856}
857
858
859PyObject *TreeDescender__reduce__(PyObject *self)
860{
861  return callbackReduce(self, PyOrTreeDescender_Type);
862}
863
864
865PyObject *TreeDescender_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(node, example) -/-> (node, {distribution | None})")
866{ PyTRY
867    NO_KEYWORDS
868
869    if (PyOrange_OrangeBaseClass(self->ob_type) == &PyOrTreeDescender_Type) {
870      PyErr_Format(PyExc_SystemError, "TreeDescender.call called for '%s': this may lead to stack overflow", self->ob_type->tp_name);
871      return PYNULL;
872    }
873
874    PTreeNode onode;
875    TExample *example;
876    if (!PyArg_ParseTuple(args, "O&O&", cc_TreeNode, &onode, ptr_Example, &example))
877      PYERROR(PyExc_TypeError, "invalid parameters", PYNULL);
878
879    PDiscDistribution distr;
880    PTreeNode node = SELF_AS(TTreeDescender)(onode, *example, distr);
881    return Py_BuildValue("NN", WrapOrange(node), WrapOrange(distr));
882  PyCATCH
883}
884
885
886PyObject *TreePruner_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(tree) -> tree")
887{
888  PyTRY
889    NO_KEYWORDS
890
891    PyObject *obj;
892    PTreeNode node;
893    PTreeClassifier classifier;
894    if (PyArg_ParseTuple(args, "O", &obj))
895      if (PyOrTreeClassifier_Check(obj)) {
896        classifier = PyOrange_AsClassifier(obj);
897        node = classifier->tree;
898      }
899      else if (PyOrTreeNode_Check(obj))
900        node = PyOrange_AsTreeNode(obj);
901
902    if (!node)
903      PYERROR(PyExc_TypeError, "invalid arguments (a classifier expected)", PYNULL);
904
905    PTreeNode newRoot = SELF_AS(TTreePruner)(node);
906
907    if (classifier) {
908      PTreeClassifier newClassifier = CLONE(TTreeClassifier, classifier);
909      newClassifier->tree = newRoot;
910      return WrapOrange(newClassifier);
911    }
912    else
913      return WrapOrange(newRoot);
914  PyCATCH
915}
916
917
918PyObject *TreeClassifier_treesize(PyObject *self, PyObject *, PyObject *) PYARGS(METH_NOARGS, "() -> size")
919{ PyTRY
920    CAST_TO(TTreeClassifier, me);
921    if (!me->tree)
922      PYERROR(PyExc_SystemError, "TreeClassifier: 'tree' not defined", PYNULL);
923
924    return PyInt_FromLong(long(me->tree->treeSize()));
925  PyCATCH
926}
927
928
929PTreeNodeList PTreeNodeList_FromArguments(PyObject *arg) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::P_FromArguments(arg); }
930PyObject *TreeNodeList_FromArguments(PyTypeObject *type, PyObject *arg) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_FromArguments(type, arg); }
931PyObject *TreeNodeList_new(PyTypeObject *type, PyObject *arg, PyObject *kwds) BASED_ON(Orange - Orange.classification.tree.NodeList, "(<list of TreeNode>)")  ALLOWS_EMPTY { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_new(type, arg, kwds); }
932PyObject *TreeNodeList_getitem_sq(TPyOrange *self, Py_ssize_t index) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_getitem(self, index); }
933int       TreeNodeList_setitem_sq(TPyOrange *self, Py_ssize_t index, PyObject *item) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_setitem(self, index, item); }
934PyObject *TreeNodeList_getslice(TPyOrange *self, Py_ssize_t start, Py_ssize_t stop) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_getslice(self, start, stop); }
935int       TreeNodeList_setslice(TPyOrange *self, Py_ssize_t start, Py_ssize_t stop, PyObject *item) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_setslice(self, start, stop, item); }
936Py_ssize_t       TreeNodeList_len_sq(TPyOrange *self) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_len(self); }
937PyObject *TreeNodeList_richcmp(TPyOrange *self, PyObject *object, int op) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_richcmp(self, object, op); }
938PyObject *TreeNodeList_concat(TPyOrange *self, PyObject *obj) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_concat(self, obj); }
939PyObject *TreeNodeList_repeat(TPyOrange *self, Py_ssize_t times) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_repeat(self, times); }
940PyObject *TreeNodeList_str(TPyOrange *self) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_str(self); }
941PyObject *TreeNodeList_repr(TPyOrange *self) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_str(self); }
942int       TreeNodeList_contains(TPyOrange *self, PyObject *obj) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_contains(self, obj); }
943PyObject *TreeNodeList_append(TPyOrange *self, PyObject *item) PYARGS(METH_O, "(TreeNode) -> None") { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_append(self, item); }
944PyObject *TreeNodeList_extend(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(sequence) -> None") { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_extend(self, obj); }
945PyObject *TreeNodeList_count(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(TreeNode) -> int") { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_count(self, obj); }
946PyObject *TreeNodeList_filter(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "([filter-function]) -> TreeNodeList") { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_filter(self, args); }
947PyObject *TreeNodeList_index(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(TreeNode) -> int") { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_index(self, obj); }
948PyObject *TreeNodeList_insert(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "(index, item) -> None") { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_insert(self, args); }
949PyObject *TreeNodeList_native(TPyOrange *self) PYARGS(METH_NOARGS, "() -> list") { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_native(self); }
950PyObject *TreeNodeList_pop(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "() -> TreeNode") { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_pop(self, args); }
951PyObject *TreeNodeList_remove(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(TreeNode) -> None") { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_remove(self, obj); }
952PyObject *TreeNodeList_reverse(TPyOrange *self) PYARGS(METH_NOARGS, "() -> None") { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_reverse(self); }
953PyObject *TreeNodeList_sort(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "([cmp-func]) -> None") { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_sort(self, args); }
954PyObject *TreeNodeList__reduce__(TPyOrange *self, PyObject *) { return ListOfWrappedMethods<PTreeNodeList, TTreeNodeList, PTreeNode, &PyOrTreeNode_Type>::_reduce(self); }
955
956
957/************* C45 ************/
958
959#include "c4.5.hpp"
960
961C_CALL(C45Learner - Orange.classification.tree._C45Learner, Learner, "([examples] [, weight=, gainRatio=, subset=, batch=, probThresh=, minObjs=, window=, increment=, cf=, trials=]) -/-> Classifier")
962C_NAMED(C45Classifier - Orange.classification.tree._C45Classifier, Classifier, "()")
963
964PyObject *C45Learner_command_line(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(line) -> None")
965{ PyTRY
966    char *line;
967    if (!PyArg_ParseTuple(args, "s", &line))
968      PYERROR(PyExc_TypeError, "C45Learner.commandline: string argument expected", NULL);
969
970    SELF_AS(TC45Learner).parseCommandLine(string(line));
971    RETURN_NONE;
972  PyCATCH
973}
974
975C_NAMED(C45TreeNode - Orange.classification.tree.C45Node, Orange, "")
976
977PC45TreeNodeList PC45TreeNodeList_FromArguments(PyObject *arg) { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::P_FromArguments(arg); }
978PyObject *C45TreeNodeList_FromArguments(PyTypeObject *type, PyObject *arg) { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_FromArguments(type, arg); }
979PyObject *C45TreeNodeList_new(PyTypeObject *type, PyObject *arg, PyObject *kwds) BASED_ON(Orange - Orange.classification.tree.C45NodeList, "(<list of C45TreeNode>)") ALLOWS_EMPTY { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_new(type, arg, kwds); }
980PyObject *C45TreeNodeList_getitem_sq(TPyOrange *self, Py_ssize_t index) { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_getitem(self, index); }
981int       C45TreeNodeList_setitem_sq(TPyOrange *self, Py_ssize_t index, PyObject *item) { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_setitem(self, index, item); }
982PyObject *C45TreeNodeList_getslice(TPyOrange *self, Py_ssize_t start, Py_ssize_t stop) { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_getslice(self, start, stop); }
983int       C45TreeNodeList_setslice(TPyOrange *self, Py_ssize_t start, Py_ssize_t stop, PyObject *item) { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_setslice(self, start, stop, item); }
984Py_ssize_t       C45TreeNodeList_len_sq(TPyOrange *self) { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_len(self); }
985PyObject *C45TreeNodeList_richcmp(TPyOrange *self, PyObject *object, int op) { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_richcmp(self, object, op); }
986PyObject *C45TreeNodeList_concat(TPyOrange *self, PyObject *obj) { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_concat(self, obj); }
987PyObject *C45TreeNodeList_repeat(TPyOrange *self, Py_ssize_t times) { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_repeat(self, times); }
988PyObject *C45TreeNodeList_str(TPyOrange *self) { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_str(self); }
989PyObject *C45TreeNodeList_repr(TPyOrange *self) { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_str(self); }
990int       C45TreeNodeList_contains(TPyOrange *self, PyObject *obj) { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_contains(self, obj); }
991PyObject *C45TreeNodeList_append(TPyOrange *self, PyObject *item) PYARGS(METH_O, "(C45TreeNode) -> None") { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_append(self, item); }
992PyObject *C45TreeNodeList_extend(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(sequence) -> None") { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_extend(self, obj); }
993PyObject *C45TreeNodeList_count(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(C45TreeNode) -> int") { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_count(self, obj); }
994PyObject *C45TreeNodeList_filter(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "([filter-function]) -> C45TreeNodeList") { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_filter(self, args); }
995PyObject *C45TreeNodeList_index(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(C45TreeNode) -> int") { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_index(self, obj); }
996PyObject *C45TreeNodeList_insert(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "(index, item) -> None") { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_insert(self, args); }
997PyObject *C45TreeNodeList_native(TPyOrange *self) PYARGS(METH_NOARGS, "() -> list") { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_native(self); }
998PyObject *C45TreeNodeList_pop(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "() -> C45TreeNode") { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_pop(self, args); }
999PyObject *C45TreeNodeList_remove(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(C45TreeNode) -> None") { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_remove(self, obj); }
1000PyObject *C45TreeNodeList_reverse(TPyOrange *self) PYARGS(METH_NOARGS, "() -> None") { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_reverse(self); }
1001PyObject *C45TreeNodeList_sort(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "([cmp-func]) -> None") { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_sort(self, args); }
1002PyObject *C45TreeNodeList__reduce__(TPyOrange *self, PyObject *) { return ListOfWrappedMethods<PC45TreeNodeList, TC45TreeNodeList, PC45TreeNode, &PyOrC45TreeNode_Type>::_reduce(self); }
1003
1004
1005/************* kNN ************/
1006
1007#include "knn.hpp"
1008C_CALL(kNNLearner - Orange.classification.knn.kNNLearner, Learner, "([examples] [k=, weightID=, findNearest=] -/-> Classifier")
1009C_NAMED(kNNClassifier - Orange.classification.knn.kNNClassifier, ClassifierFD, "(example[, returnWhat]) -> prediction")
1010
1011
1012/************* PNN ************/
1013
1014#include "numeric_interface.hpp"
1015
1016#include "pnn.hpp"
1017
1018PyObject *P2NN_new(PyTypeObject *type, PyObject *args, PyObject *keywords) BASED_ON(ClassifierFD - Orange.classification.knn.P2NN, "(examples, anchors[, domain]) -> PNN")
1019{
1020  PyTRY
1021    PDomain domain;
1022    PExampleGenerator examples;
1023    PyObject *pybases;
1024    int normalizeExamples = 1;
1025    if (PyArg_ParseTuple(args, "O&O|iO&:P2NN", pt_ExampleGenerator, &examples, &pybases, &normalizeExamples, cc_Domain, &domain)) {
1026      if (!domain)
1027        domain = examples->domain;
1028
1029      if (!PyList_Check(pybases))
1030        PYERROR(PyExc_AttributeError, "the anchors should be given as a list", PYNULL);
1031
1032      const Py_ssize_t nAnchors = PyList_Size(pybases);
1033      if (nAnchors != domain->attributes->size())
1034        PYERROR(PyExc_AttributeError, "the number of attributes does not match the number of anchors", PYNULL);
1035
1036      TFloatList *basesX = mlnew TFloatList(nAnchors);
1037      TFloatList *basesY = mlnew TFloatList(nAnchors);
1038      PFloatList wbasesX = basesX, wbasesY = basesY;
1039
1040      TFloatList::iterator xi(basesX->begin());
1041      TFloatList::iterator yi(basesY->begin());
1042      PyObject *foo;
1043
1044      for(Py_ssize_t i = 0; i < nAnchors; i++)
1045        if (!PyArg_ParseTuple(PyList_GetItem(pybases, i), "ff|O", &*xi++, &*yi++, &foo)) {
1046          PyErr_Format(PyExc_TypeError, "anchor #%i is not a tuple of (at least) two elements", i);
1047          return PYNULL;
1048        }
1049
1050      return WrapNewOrange(mlnew TP2NN(domain, examples, wbasesX, wbasesY, -1.0, normalizeExamples != 0), type);
1051    }
1052
1053      PyErr_Clear();
1054      PyObject *matrix;
1055      PyObject *pyoffsets, *pynormalizers, *pyaverages;
1056      if (PyArg_ParseTuple(args, "O&OOOOO|i", cc_Domain, &domain, &matrix, &pybases, &pyoffsets, &pynormalizers, &pyaverages, &normalizeExamples)) {
1057        prepareNumeric();
1058  //      if (!PyArray_Check(matrix))
1059  //        PYERROR(PyExc_AttributeError, "the second argument (projection matrix) must a Numeric.array", PYNULL);
1060
1061        const int nAttrs = domain->attributes->size();
1062
1063        PyArrayObject *array = (PyArrayObject *)(matrix);
1064        if (array->nd != 2)
1065          PYERROR(PyExc_AttributeError, "two-dimensional array expected for matrix of projections", PYNULL);
1066        if (array->dimensions[1] != 3)
1067          PYERROR(PyExc_AttributeError, "the matrix of projections must have three columns", PYNULL);
1068
1069        const char arrayType = getArrayType(array);
1070        if ((arrayType != 'f') && (arrayType != 'd'))
1071          PYERROR(PyExc_AttributeError, "elements of matrix of projections must be doubles or floats", PYNULL);
1072
1073        const int nExamples = array->dimensions[0];
1074
1075        double *projections = new double[3*nExamples];
1076
1077        char *rowPtr = array->data;
1078        double *pi = projections;
1079        const int &strideRow = array->strides[0];
1080        const int &strideCol = array->strides[1];
1081
1082        if (arrayType == 'f') {
1083          for(int row = 0, rowe = nExamples; row < rowe; row++, rowPtr += strideRow) {
1084            *pi++ = double(*(float *)(rowPtr));
1085            *pi++ = double(*(float *)(rowPtr+strideCol));
1086            *pi++ = double(*(float *)(rowPtr+2*strideCol));
1087          }
1088        }
1089        else {
1090          for(int row = 0, rowe = nExamples; row < rowe; row++, rowPtr += strideRow) {
1091            *pi++ = *(double *)(rowPtr);
1092            *pi++ = *(double *)(rowPtr+strideCol);
1093            *pi++ = *(double *)(rowPtr+2*strideCol);
1094          }
1095        }
1096
1097
1098        double *bases = NULL;
1099        PFloatList offsets, normalizers, averages;
1100
1101        if (pybases == Py_None) {
1102          if ((pyoffsets != Py_None) || (pynormalizers != Py_None) || (pyaverages != Py_None))
1103            PYERROR(PyExc_AttributeError, "anchors, offsets, normalizers and averages must be either all given or all None", PYNULL);
1104        }
1105
1106        else {
1107          if (!PyList_Check(pybases) || ((pybases != Py_None) && (PyList_Size(pybases) != nAttrs)))
1108            PYERROR(PyExc_AttributeError, "the third argument must be a list of anchors with length equal the number of attributes", PYNULL);
1109
1110
1111          #define LOADLIST(x) \
1112          x = ListOfUnwrappedMethods<PAttributedFloatList, TAttributedFloatList, float>::P_FromArguments(py##x); \
1113          if (!x) return PYNULL; \
1114          if (x->size() != nAttrs) PYERROR(PyExc_TypeError, "invalid size of "#x" list", PYNULL);
1115
1116          LOADLIST(offsets)
1117          LOADLIST(normalizers)
1118          LOADLIST(averages)
1119          #undef LOADLIST
1120
1121          bases = new double[2*nAttrs];
1122          double *bi = bases;
1123          PyObject *foo;
1124
1125          for(int i = 0; i < nAttrs; i++, bi+=2)
1126            if (!PyArg_ParseTuple(PyList_GetItem(pybases, i), "dd|O", bi, bi+1, &foo)) {
1127              PyErr_Format(PyExc_TypeError, "anchor #%i is not a tuple of (at least) two elements", i);
1128              delete bases;
1129              return PYNULL;
1130            }
1131        }
1132
1133        return WrapNewOrange(mlnew TP2NN(domain, projections, nExamples, bases, offsets, normalizers, averages, TP2NN::InverseSquare, normalizeExamples != 0), type);
1134      }
1135
1136    PyErr_Clear();
1137    PYERROR(PyExc_TypeError, "P2NN.invalid arguments", PYNULL);
1138
1139  PyCATCH;
1140}
1141
1142
1143PyObject *P2NN__reduce__(PyObject *self)
1144{
1145  PyTRY
1146    CAST_TO(TP2NN, p2nn);
1147
1148    if (!p2nn->offsets)
1149      PYERROR(PyExc_SystemError, "cannot pickle an invalid instance of P2NN (no offsets)", NULL);
1150
1151    const int nAttrs = p2nn->offsets->size();
1152    const int nExamples = p2nn->nExamples;
1153
1154    TCharBuffer buf(3 + 2 * sizeof(int) + (4 * nAttrs + 3 * nExamples + 2) * sizeof(double));
1155
1156    buf.writeInt(nAttrs);
1157    buf.writeInt(nExamples);
1158
1159    if (p2nn->bases) {
1160      buf.writeChar(1);
1161      buf.writeBuf(p2nn->bases, 2 * nAttrs * sizeof(double));
1162    }
1163    else
1164      buf.writeChar(0);
1165
1166    if (p2nn->radii) {
1167      buf.writeChar(1);
1168      buf.writeBuf(p2nn->radii, 2 * nAttrs * sizeof(double));
1169    }
1170    else
1171      buf.writeChar(0);
1172
1173    if (p2nn->projections) {
1174      buf.writeChar(1);
1175      buf.writeBuf(p2nn->projections, 3 * nExamples * sizeof(double));
1176    }
1177    else
1178      buf.writeChar(0);
1179
1180    buf.writeDouble(p2nn->minClass);
1181    buf.writeDouble(p2nn->maxClass);
1182
1183    return Py_BuildValue("O(Os#)N", getExportedFunction("__pickleLoaderP2NN"),
1184                                    self->ob_type,
1185                                    buf.buf, buf.length(),
1186                                    packOrangeDictionary(self));
1187  PyCATCH
1188}
1189
1190
1191PyObject *__pickleLoaderP2NN(PyObject *, PyObject *args) PYARGS(METH_VARARGS, "(type, packed_data)")
1192{
1193  PyTRY
1194    PyTypeObject *type;
1195    char *pbuf;
1196    int bufSize;
1197    if (!PyArg_ParseTuple(args, "Os#:__pickleLoaderP2NN", &type, &pbuf, &bufSize))
1198      return NULL;
1199
1200    TCharBuffer buf(pbuf);
1201
1202    const int nAttrs = buf.readInt();
1203    const int nExamples = buf.readInt();
1204
1205    TP2NN *p2nn = new TP2NN(nAttrs, nExamples);
1206    if (buf.readChar()) {
1207      buf.readBuf(p2nn->bases, 2 * nAttrs * sizeof(double));
1208    }
1209    else {
1210      delete p2nn->bases;
1211      p2nn->bases = NULL;
1212    }
1213
1214    if (buf.readChar()) {
1215      buf.readBuf(p2nn->radii, 2 * nAttrs * sizeof(double));
1216    }
1217    else {
1218      delete p2nn->radii;
1219      p2nn->radii = NULL;
1220    }
1221
1222    if (buf.readChar()) {
1223      buf.readBuf(p2nn->projections, 3 * nExamples * sizeof(double));
1224    }
1225    else {
1226      delete p2nn->projections;
1227      p2nn->projections = NULL;
1228    }
1229
1230    p2nn->minClass = buf.readDouble();
1231    p2nn->maxClass = buf.readDouble();
1232
1233    return WrapNewOrange(p2nn, type);
1234  PyCATCH
1235}
1236
1237
1238C_CALL(kNNLearner, Learner, "([examples] [, weight=, k=] -/-> Classifier")
1239C_NAMED(kNNClassifier, ClassifierFD, "([k=, weightID=, findNearest=])")
1240
1241
1242/************* Logistic Regression ************/
1243
1244#include "logistic.hpp"
1245C_CALL(LogRegLearner, Learner, "([examples[, weight=]]) -/-> Classifier")
1246C_NAMED(LogRegClassifier - Orange.classification.logreg.LogRegClassifier, ClassifierFD, "([probabilities=])")
1247
1248
1249PyObject *LogRegFitter_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.logreg.LogRegFitter, "<abstract>")
1250{ if (type == (PyTypeObject *)&PyOrLogRegFitter_Type)
1251    return setCallbackFunction(WrapNewOrange(mlnew TLogRegFitter_Python(), type), args);
1252  else
1253    return WrapNewOrange(mlnew TLogRegFitter_Python(), type);
1254}
1255
1256PyObject *LogRegFitter__reduce__(PyObject *self)
1257{
1258  return callbackReduce(self, PyOrLogRegFitter_Type);
1259}
1260
1261
1262C_CALL(LogRegFitter_Cholesky - Orange.classification.logreg.LogRegFitter_Cholesky, LogRegFitter, "([example[, weightID]]) -/-> (status, beta, beta_se, likelihood) | (status, attribute)")
1263
1264PyObject *LogRegLearner_fitModel(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(examples[, weight])")
1265{
1266  PyTRY
1267      PExampleGenerator egen;
1268      int weight = 0;
1269      if (!PyArg_ParseTuple(args, "O&|O&:LogRegLearner", pt_ExampleGenerator, &egen, pt_weightByGen(egen), &weight))
1270        return PYNULL;
1271
1272      CAST_TO(TLogRegLearner, loglearn)
1273
1274      int error;
1275      PVariable variable;
1276      PClassifier classifier;
1277
1278      classifier = loglearn->fitModel(egen, weight, error, variable);
1279      if (error <= TLogRegFitter::Divergence)
1280          return Py_BuildValue("N", WrapOrange(classifier));
1281      else
1282          return Py_BuildValue("N", WrapOrange(variable));
1283  PyCATCH
1284}
1285
1286
1287PyObject *PyLogRegFitter_ErrorCode_FromLong(long);
1288
1289PyObject *LogRegFitter_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(examples[, weightID]) -/-> (status, beta, beta_se, likelihood) | (status, attribute)")
1290{
1291  PyTRY
1292    NO_KEYWORDS
1293
1294    int weight;
1295    PExampleGenerator egen = exampleGenFromArgs(args, weight);
1296    if (!egen)
1297      return PYNULL;
1298
1299    CAST_TO(TLogRegFitter, fitter)
1300
1301    PAttributedFloatList beta, beta_se;
1302    float likelihood;
1303    int error;
1304    PVariable attribute;
1305
1306    beta = (*fitter)(egen, weight, beta_se, likelihood, error, attribute);
1307
1308    if (error <= TLogRegFitter::Divergence)
1309      return Py_BuildValue("NNNf", PyLogRegFitter_ErrorCode_FromLong(error), WrapOrange(beta), WrapOrange(beta_se), likelihood);
1310    else
1311      return Py_BuildValue("NN", PyLogRegFitter_ErrorCode_FromLong(error), WrapOrange(attribute));
1312
1313  PyCATCH
1314}
1315
1316/************ Linear **********/
1317#include "liblinear_interface.hpp"
1318C_CALL(LinearLearner, Learner, "([examples] -/-> Classifier)")
1319C_NAMED(LinearClassifier - Orange.classification.svm.LinearClassifier, ClassifierFD, " ")
1320
1321
1322PyObject * LinearClassifier_new(PyTypeObject* type, PyObject* args, PyObject* kwargs) BASED_ON(ClassifierFD, "(Domain, str) -> LinearClassifier")
1323{
1324    PyTRY
1325        PDomain domain;
1326        char * model_string;
1327
1328        if (!PyArg_ParseTuple(args, "O&s:__new__", cc_Domain, &domain, &model_string)) {
1329            return NULL;
1330        }
1331        string buf(model_string);
1332        struct model * model = linear_load_model_alt(buf);
1333
1334        PLinearClassifier classifier = mlnew TLinearClassifier(domain, model);
1335
1336        return WrapOrange(classifier);
1337    PyCATCH
1338}
1339
1340
1341PyObject *LinearClassifier__reduce__(PyObject *self)
1342{
1343  PyTRY
1344    CAST_TO(TLinearClassifier, classifier);
1345    string buff;
1346    if (linear_save_model_alt(buff, classifier->getModel()) != 0)
1347        raiseError("Could not save the model");
1348
1349    return Py_BuildValue(
1350            "O(Os)N",
1351            self->ob_type,
1352            WrapOrange(classifier->domain),
1353            buff.c_str(),
1354            packOrangeDictionary(self));
1355  PyCATCH
1356}
1357
1358/*
1359 * Deprecated. Left here so old pickled objects can be restored.
1360 * The old pickled arguments were:
1361 *
1362 *     (type(self), classVar, examples, model_string),
1363 */
1364
1365PyObject *__pickleLoaderLinearClassifier(PyObject *, PyObject *args) PYARGS(METH_VARARGS, "(type, packed_data) Deprecated!!")
1366{
1367  PyTRY
1368    //raiseWarning(PyExc_DeprecationWarning, "Deprecated pickle reconstructor")
1369    PyTypeObject* type;
1370    PVariable var;
1371    PExampleTable examples;
1372    char *pBuff;
1373    if (!PyArg_ParseTuple(args, "OO&O&s", &type, cc_Variable, &var, cc_ExampleTable, &examples, &pBuff))
1374        return NULL;
1375    string buff(pBuff);
1376    model *model = linear_load_model_alt(buff);
1377    if (!model)
1378        raiseError("Could not load the model");
1379    return WrapNewOrange(mlnew TLinearClassifier(examples->domain, model), (PyTypeObject*)&PyOrLinearClassifier_Type);
1380  PyCATCH
1381}
1382
1383
1384PyObject * LinearClassifer_get_model_str(PyObject * self, PyObject *) PYARGS(METH_NOARGS, "() -> str")
1385{
1386    PyTRY
1387        CAST_TO(TLinearClassifier, classifier);
1388        string buff;
1389        if (linear_save_model_alt(buff, classifier->getModel()) != 0) {
1390            raiseError("Could not convert the model to a string");
1391        }
1392        return PyString_FromString(buff.c_str());
1393    PyCATCH
1394}
1395
1396
1397/************* LIBSVM ************/
1398
1399#include "libsvm_interface.hpp"
1400C_CALL(SVMLearner - Orange.classification.svm._SVMLearner, Learner, "([examples] -/-> Classifier)")
1401C_CALL(SVMLearnerSparse - Orange.classification.svm._SVMLearnerSparse, SVMLearner, "([examples] -/-> Classifier)")
1402C_NAMED(SVMClassifier - Orange.classification.svm._SVMClassifier, ClassifierFD," ")
1403C_NAMED(SVMClassifierSparse - Orange.classification.svm._SVMClassifierSparse, SVMClassifier," ")
1404
1405PyObject *SVMLearner_setWeights(PyObject *self, PyObject* args, PyObject *keywords) PYARGS(METH_VARARGS, "['list of tuple pairs'] -> None")
1406{
1407    PyTRY
1408
1409    PyObject *pyWeights;
1410    if (!PyArg_ParseTuple(args, "O:SVMLearner.setWeights", &pyWeights)) {
1411        //PyErr_Format(PyExc_TypeError, "SVMLearner.setWeights: an instance of Python List expected got '%s'", pyWeights->ob_type->tp_name);
1412        PYERROR(PyExc_TypeError, "SVMLearner.setWeights: Python List of attribute weights expected", PYNULL);
1413        return PYNULL;
1414    }
1415
1416    CAST_TO(TSVMLearner, learner);
1417
1418    Py_ssize_t size = PyList_Size(pyWeights);
1419    //cout << "n weights: " << size << endl;
1420    Py_ssize_t i;
1421
1422    free(learner->weight_label);
1423    free(learner->weight);
1424
1425    learner->nr_weight = size;
1426    learner->weight_label = NULL;
1427    learner->weight = NULL;
1428
1429    if (size > 0) {
1430        learner->weight_label = (int *)malloc((size)*sizeof(int));
1431        learner->weight = (double *)malloc((size)*sizeof(double));
1432    }
1433
1434    for (i = 0; i < size; i++) {
1435        int l;
1436        double w;
1437        PyArg_ParseTuple(PyList_GetItem(pyWeights, i), "id:SVMLearner.setWeights", &l, &w);
1438        learner->weight[i] = w;
1439        learner->weight_label[i] = l;
1440        //cout << "class: " << l << ", w: " << w << endl;
1441    }
1442
1443    RETURN_NONE;
1444    PyCATCH
1445}
1446
1447PyObject *KernelFunc_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.svm.kernels.KernelFunc, "<abstract>")
1448{ if (type == (PyTypeObject *)&PyOrKernelFunc_Type)
1449    return setCallbackFunction(WrapNewOrange(mlnew TKernelFunc_Python(), type), args);
1450  else
1451    return WrapNewOrange(mlnew TKernelFunc_Python(), type);
1452}
1453
1454
1455PyObject *KernelFunc__reduce__(PyObject *self)
1456{
1457  return callbackReduce(self, PyOrKernelFunc_Type);
1458}
1459
1460
1461PyObject *KernelFunc_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(Example, Example) -> float")
1462{
1463  PyTRY
1464    NO_KEYWORDS
1465
1466    if (PyOrange_OrangeBaseClass(self->ob_type) == &PyOrKernelFunc_Type) {
1467      PyErr_Format(PyExc_SystemError, "KernelFunc.call called for '%s': this may lead to stack overflow", self->ob_type->tp_name);
1468      return PYNULL;
1469    }
1470
1471    float f;
1472    PExample e1,e2;
1473    if (!PyArg_ParseTuple(args, "O&O&", cc_Example, &e1, cc_Example, &e2))
1474        return NULL;
1475    f=SELF_AS(TKernelFunc)(e1.getReference(),e2.getReference());
1476    return Py_BuildValue("f", f);
1477  PyCATCH
1478}
1479
1480PyObject *SVMClassifier__reduce__(PyObject* self)
1481{
1482  PyTRY
1483    CAST_TO(TSVMClassifier, svm);
1484    string buf;
1485    if (svm_save_model_alt(buf, svm->getModel())){
1486        raiseError("Error saving SVM model");
1487    }
1488
1489    return Py_BuildValue("O(OsOOO)N", self->ob_type,
1490                                    WrapOrange(svm->domain),
1491                                    buf.c_str(),
1492                                    WrapOrange(svm->supportVectors),
1493                                    WrapOrange(svm->kernelFunc),
1494                                    WrapOrange(svm->examples),
1495                                    packOrangeDictionary(self));
1496  PyCATCH
1497}
1498
1499
1500PyObject *SVMClassifierSparse__reduce__(PyObject* self)
1501{
1502  PyTRY
1503    CAST_TO(TSVMClassifierSparse, svm);
1504    string buf;
1505    if (svm_save_model_alt(buf, svm->getModel())){
1506        raiseError("Error saving SVM model.");
1507    }
1508
1509    return Py_BuildValue("O(OsbOOO)N", self->ob_type,
1510                                    WrapOrange(svm->domain),
1511                                    buf.c_str(),
1512                                    (char)(svm->useNonMeta? 1: 0),
1513                                    WrapOrange(svm->supportVectors),
1514                                    WrapOrange(svm->kernelFunc),
1515                                    WrapOrange(svm->examples),
1516                                    packOrangeDictionary(self));
1517  PyCATCH
1518}
1519
1520
1521PyObject *SVMClassifier_getDecisionValues(PyObject *self, PyObject* args, PyObject *keywords) PYARGS(METH_VARARGS, "(Example) -> list of floats")
1522{PyTRY
1523    PExample example;
1524    if (!PyArg_ParseTuple(args, "O&", cc_Example, &example))
1525        return NULL;
1526    PFloatList f=SELF_AS(TSVMClassifier).getDecisionValues(example.getReference());
1527    return WrapOrange(f);
1528PyCATCH
1529}
1530
1531PyObject *SVMClassifier_getModel(PyObject *self, PyObject* args, PyObject *keywords) PYARGS(METH_VARARGS, "() -> string")
1532{PyTRY
1533    string buf;
1534    svm_model* model = SELF_AS(TSVMClassifier).getModel();
1535    if (!model)
1536        raiseError("No model.");
1537    svm_save_model_alt(buf, model);
1538    return Py_BuildValue("s", buf.c_str());
1539PyCATCH
1540}
1541
1542
1543PyObject * SVMClassifier_new(PyTypeObject* type, PyObject* args, PyObject* kwargs) BASED_ON(ClassifierFD, "(Domain, model_string, supportVectors, [kernelFunc, examples]) -> SVMClassifier")
1544{
1545PyTRY
1546    PDomain domain;
1547    char*  model_string = NULL;
1548    PExampleTable supportVectors;
1549    PKernelFunc kernel;
1550    PExampleTable examples;
1551
1552    if (PyArg_ParseTuple(args, ""))
1553        return WrapNewOrange(mlnew TSVMClassifier(), type);
1554
1555    PyErr_Clear();
1556
1557    if (!PyArg_ParseTuple(args, "O&sO&|O&O&",
1558            cc_Domain, &domain,
1559            &model_string,
1560            cc_ExampleTable, &supportVectors,
1561            ccn_KernelFunc, &kernel,
1562            ccn_ExampleTable, &examples)) {
1563         // Old pickle arguments format.
1564        PVariable classVar;
1565        if (!PyArg_ParseTuple(args, "O&O&O&s|O&:__new__",
1566                cc_Variable, &classVar,
1567                ccn_ExampleTable, &examples,
1568                cc_ExampleTable, &supportVectors,
1569                &model_string,
1570                cc_KernelFunc, &kernel)) {
1571            return NULL;
1572        }
1573        PyErr_Clear();
1574        domain = supportVectors->domain;
1575    }
1576
1577    string buffer(model_string);
1578    svm_model* model = svm_load_model_alt(buffer);
1579    if (!model)
1580        raiseError("Error building LibSVM Model");
1581
1582    PSVMClassifier svm = mlnew TSVMClassifier(domain, model, supportVectors, kernel, examples);
1583
1584    return WrapOrange(svm);
1585PyCATCH
1586}
1587
1588
1589
1590PyObject * SVMClassifierSparse_new(PyTypeObject* type, PyObject* args, PyObject* kwargs) BASED_ON(SVMClassifier, "(Domain, model_string, useNonMeta, supportVectors, [kernelFunc, examples]) -> SVMClassifierSparse")
1591{
1592PyTRY
1593    PDomain domain;
1594    char*  model_string = NULL;
1595    char useNonMeta = 0;
1596
1597    PExampleTable supportVectors;
1598    PKernelFunc kernel;
1599    PExampleTable examples;
1600
1601    if (PyArg_ParseTuple(args, ""))
1602        return WrapNewOrange(mlnew TSVMClassifierSparse(), type);
1603
1604    PyErr_Clear();
1605
1606    if (!PyArg_ParseTuple(args, "O&sbO&|O&O&:__new__",
1607            cc_Domain, &domain,
1608            &model_string,
1609            &useNonMeta,
1610            cc_ExampleTable, &supportVectors,
1611            ccn_KernelFunc, &kernel,
1612            ccn_ExampleTable, &examples)) {
1613
1614         // Old pickle arguments format.
1615        PVariable classVar;
1616        if (!PyArg_ParseTuple(args, "O&O&O&s|bO&:__new__",
1617                cc_Variable, &classVar,
1618                ccn_ExampleTable, &examples,
1619                cc_ExampleTable, &supportVectors,
1620                &model_string,
1621                &useNonMeta,
1622                cc_KernelFunc, &kernel)) {
1623            return NULL;
1624        }
1625
1626        PyErr_Clear();
1627        domain = supportVectors->domain;
1628    }
1629
1630    string buffer(model_string);
1631    svm_model* model = svm_load_model_alt(buffer);
1632    if (!model)
1633        raiseError("Error building LibSVM Model");
1634
1635    PSVMClassifier svm = mlnew TSVMClassifierSparse(domain, model, useNonMeta != 0, supportVectors, kernel, examples);
1636
1637    return WrapOrange(svm);
1638PyCATCH
1639}
1640
1641   
1642/************* BAYES ************/
1643
1644#include "bayes.hpp"
1645C_CALL(BayesLearner - Orange.classification.bayes._BayesLearner, Learner, "([examples], [weight=, estimate=] -/-> Classifier")
1646C_NAMED(BayesClassifier - Orange.classification.bayes._BayesClassifier, ClassifierFD, "([probabilities=])")
1647
1648PyObject *BayesClassifier_p(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(class, example) -> float")
1649{ PyTRY
1650    CAST_TO(TBayesClassifier, me);
1651
1652    PyObject *pyvalue;
1653    TValue value;
1654    TExample *ex;
1655    if (   !PyArg_ParseTuple(args, "OO&:BayesClassifier.p", &pyvalue, ptr_Example, &ex)
1656        || !convertFromPython(pyvalue, value, me->domain->classVar))
1657      return PYNULL;
1658
1659    return PyFloat_FromDouble((double)SELF_AS(TBayesClassifier).p(value, *ex));
1660
1661  PyCATCH
1662}
1663
1664
1665
1666/************* RULES ************/
1667
1668#include "rulelearner.hpp"
1669
1670C_NAMED(Rule - Orange.classification.rules.Rule, Orange, "()")
1671
1672C_NAMED(RuleValidator_LRS - Orange.classification.rules.Validator_LRS, RuleValidator, "([alpha=0.05,min_coverage=0,max_rule_complexity=0,min_quality=numeric_limits<float>::min()])")
1673
1674C_NAMED(RuleEvaluator_Entropy - Orange.classification.rules.Evaluator_Entropy, RuleEvaluator, "()")
1675C_NAMED(RuleEvaluator_Laplace - Orange.classification.rules.Evaluator_Laplace, RuleEvaluator, "()")
1676C_NAMED(RuleEvaluator_LRS - Orange.classification.rules.Evaluator_LRS, RuleEvaluator, "()")
1677C_NAMED(RuleEvaluator_mEVC - Orange.classification.rules.Evaluator_mEVC, RuleEvaluator, "(ruleAlpha=1.0,attributeAlpha=1.0)")
1678
1679C_NAMED(EVDist, Orange, "()")
1680C_NAMED(EVDistGetter_Standard, EVDistGetter, "()")
1681
1682C_NAMED(RuleBeamFinder - Orange.classification.rules.BeamFinder, RuleFinder, "([validator=, evaluator=, initializer=, refiner=, candidateSelector=, ruleFilter=])")
1683
1684C_NAMED(RuleBeamInitializer_Default - Orange.classification.rules.BeamInitializer_Default, RuleBeamInitializer, "()")
1685
1686C_NAMED(RuleBeamRefiner_Selector - Orange.classification.rules.BeamRefiner_Selector, RuleBeamRefiner, "([discretization=])")
1687
1688C_NAMED(RuleBeamCandidateSelector_TakeAll - Orange.classification.rules.BeamCandidateSelector_TakeAll, RuleBeamCandidateSelector, "()")
1689
1690C_NAMED(RuleBeamFilter_Width - Orange.classification.rules.BeamFilter_Width, RuleBeamFilter, "([width=5])")
1691
1692C_NAMED(RuleDataStoppingCriteria_NoPositives - Orange.classification.rules.DataStoppingCriteria_NoPositives, RuleDataStoppingCriteria, "()")
1693
1694C_NAMED(RuleCovererAndRemover_Default - Orange.classification.rules.CovererAndRemover_Default, RuleCovererAndRemover, "()")
1695
1696C_NAMED(RuleStoppingCriteria_NegativeDistribution - Orange.classification.rules.StoppingCriteria_NegativeDistribution, RuleStoppingCriteria, "()")
1697C_CALL(RuleLearner - Orange.classification.rules.RuleLearner, Learner, "([examples[, weightID]]) -/-> Classifier")
1698
1699ABSTRACT(RuleClassifier - Orange.classification.rules.RuleClassifier, Classifier)
1700C_NAMED(RuleClassifier_firstRule - Orange.classification.rules.RuleClassifier_firstRule, RuleClassifier, "([rules,examples[,weightID]])")
1701C_NAMED(RuleClassifier_logit - Orange.classification.rules.RuleClassifier_logit, RuleClassifier, "([rules,minSig,minBeta,examples[,weightID]])")
1702
1703PyObject *Rule_call(PyObject *self, PyObject *args, PyObject *keywords)
1704{
1705  PyTRY
1706    NO_KEYWORDS
1707
1708    if (PyTuple_Size(args)==1) {
1709      PyObject *pyex = PyTuple_GET_ITEM(args, 0);
1710      if (PyOrExample_Check(pyex))
1711        return PyInt_FromLong(PyOrange_AsRule(self)->call(PyExample_AS_ExampleReference(pyex)) ? 1 : 0);
1712    }
1713
1714    PExampleGenerator egen;
1715    int references = 1;
1716    int negate = 0;
1717    if (!PyArg_ParseTuple(args, "O&|ii:Rule.__call__", &pt_ExampleGenerator, &egen, &references, &negate))
1718      return PYNULL;
1719
1720    CAST_TO(TRule, rule)
1721    PExampleTable res = (*rule)(egen,(references?true:false),(negate?true:false));
1722    return WrapOrange(res);
1723  PyCATCH
1724}
1725
1726PyObject *Rule_filterAndStore(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(examples, weightID, targetClass)")
1727{
1728  PyTRY
1729    PExampleGenerator gen;
1730    int weightID = 0;
1731    int targetClass = -1;
1732
1733    if (!PyArg_ParseTuple(args, "O&O&i:RuleEvaluator.call",  pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID, &targetClass))
1734      return PYNULL;
1735
1736    CAST_TO(TRule, rule);
1737    rule->filterAndStore(gen,weightID,targetClass);
1738    RETURN_NONE;
1739 PyCATCH
1740}
1741
1742PyObject *RuleEvaluator_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.rules.Evaluator, "<abstract>")
1743{ if (type == (PyTypeObject *)&PyOrRuleEvaluator_Type)
1744    return setCallbackFunction(WrapNewOrange(mlnew TRuleEvaluator_Python(), type), args);
1745  else
1746    return WrapNewOrange(mlnew TRuleEvaluator_Python(), type);
1747}
1748
1749PyObject *RuleEvaluator__reduce__(PyObject *self)
1750{
1751  return callbackReduce(self, PyOrRuleEvaluator_Type);
1752}
1753
1754
1755PyObject *RuleEvaluator_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(rule, table, weightID, targetClass, apriori) -/-> (quality)")
1756{
1757  PyTRY
1758    NO_KEYWORDS
1759
1760    PRule rule;
1761    PExampleGenerator gen;
1762    int weightID = 0;
1763    int targetClass = -1;
1764    PDistribution apriori;
1765
1766    if (!PyArg_ParseTuple(args, "O&O&O&iO&:RuleEvaluator.call", cc_Rule, &rule, pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID, &targetClass, cc_Distribution, &apriori))
1767      return PYNULL;
1768    CAST_TO(TRuleEvaluator, evaluator)
1769    float quality;
1770
1771    quality = (*evaluator)(rule, gen, weightID, targetClass, apriori);
1772    return PyFloat_FromDouble(quality);
1773  PyCATCH
1774}
1775
1776PyObject *EVDistGetter_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange, "<abstract>")
1777{ if (type == (PyTypeObject *)&PyOrEVDistGetter_Type)
1778    return setCallbackFunction(WrapNewOrange(mlnew TEVDistGetter_Python(), type), args);
1779  else
1780    return WrapNewOrange(mlnew TEVDistGetter_Python(), type);
1781}
1782
1783PyObject *EVDistGetter__reduce__(PyObject *self)
1784{
1785  return callbackReduce(self, PyOrEVDistGetter_Type);
1786}
1787
1788
1789PyObject *EVDistGetter_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(rule, length) -/-> (EVdist)")
1790{
1791  PyTRY
1792    NO_KEYWORDS
1793
1794    PRule rule;
1795    int parentLength, rLength;
1796
1797    if (!PyArg_ParseTuple(args, "O&ii:EVDistGetter.call", cc_Rule, &rule, &parentLength, &rLength))
1798      return PYNULL;
1799    CAST_TO(TEVDistGetter, getter)
1800    PEVDist dist = (*getter)(rule, parentLength, rLength);
1801
1802    return WrapOrange(dist);
1803  PyCATCH
1804}
1805
1806PyObject *RuleValidator_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.rules.Validator, "<abstract>")
1807{ if (type == (PyTypeObject *)&PyOrRuleValidator_Type)
1808    return setCallbackFunction(WrapNewOrange(mlnew TRuleValidator_Python(), type), args);
1809  else
1810    return WrapNewOrange(mlnew TRuleValidator_Python(), type);
1811}
1812
1813PyObject *RuleValidator__reduce__(PyObject *self)
1814{
1815  return callbackReduce(self, PyOrRuleValidator_Type);
1816}
1817
1818
1819PyObject *RuleValidator_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(rule, table, weightID, targetClass, apriori) -/-> (quality)")
1820{
1821
1822  PyTRY
1823    NO_KEYWORDS
1824
1825    PRule rule;
1826    PExampleGenerator gen;
1827    int weightID = 0;
1828    int targetClass = -1;
1829    PDistribution apriori;
1830
1831    if (!PyArg_ParseTuple(args, "O&O&O&iO&:RuleValidator.call", cc_Rule, &rule, pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID, &targetClass, cc_Distribution, &apriori))
1832      return PYNULL;
1833    CAST_TO(TRuleValidator, validator)
1834
1835    bool valid;
1836    valid = (*validator)(rule, gen, weightID, targetClass, apriori);
1837    return PyInt_FromLong(valid?1:0);
1838  PyCATCH
1839}
1840
1841PyObject *RuleCovererAndRemover_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.rules.CovererAndRemover, "<abstract>")
1842{ if (type == (PyTypeObject *)&PyOrRuleCovererAndRemover_Type)
1843    return setCallbackFunction(WrapNewOrange(mlnew TRuleCovererAndRemover_Python(), type), args);
1844  else
1845    return WrapNewOrange(mlnew TRuleCovererAndRemover_Python(), type);
1846}
1847
1848PyObject *RuleCovererAndRemover__reduce__(PyObject *self)
1849{
1850  return callbackReduce(self, PyOrRuleCovererAndRemover_Type);
1851}
1852
1853
1854PyObject *RuleCovererAndRemover_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(rule, table, weightID, targetClass) -/-> (table,newWeight)")
1855{
1856  PyTRY
1857    NO_KEYWORDS
1858
1859    PRule rule;
1860    PExampleGenerator gen;
1861    int weightID = 0;
1862    int newWeightID = 0;
1863    int targetClass = -1;
1864
1865    if (!PyArg_ParseTuple(args, "O&O&O&i:RuleCovererAndRemover.call", cc_Rule, &rule, pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID,&targetClass))
1866      return PYNULL;
1867    CAST_TO(TRuleCovererAndRemover, covererAndRemover)
1868
1869    PExampleTable res = (*covererAndRemover)(rule, gen, weightID, newWeightID, targetClass);
1870    return Py_BuildValue("Ni", WrapOrange(res),newWeightID);
1871  PyCATCH
1872}
1873
1874PyObject *RuleStoppingCriteria_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.rules.StoppingCriteria, "<abstract>")
1875{ if (type == (PyTypeObject *)&PyOrRuleStoppingCriteria_Type)
1876    return setCallbackFunction(WrapNewOrange(mlnew TRuleStoppingCriteria_Python(), type), args);
1877  else
1878    return WrapNewOrange(mlnew TRuleStoppingCriteria_Python(), type);
1879}
1880
1881PyObject *RuleStoppingCriteria__reduce__(PyObject *self)
1882{
1883  return callbackReduce(self, PyOrRuleStoppingCriteria_Type);
1884}
1885
1886
1887PyObject *RuleStoppingCriteria_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(rulelist, rule, table, weightID) -/-> (table)")
1888{
1889  PyTRY
1890    NO_KEYWORDS
1891
1892    PRuleList ruleList;
1893    PRule rule;
1894    PExampleGenerator gen;
1895    int weightID = 0;
1896
1897    if (!PyArg_ParseTuple(args, "O&O&O&O&:RuleStoppingCriteria.call", cc_RuleList, &ruleList, cc_Rule, &rule, pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID))
1898      return PYNULL;
1899    CAST_TO(TRuleStoppingCriteria, ruleStopping)
1900
1901    bool stop = (*ruleStopping)(ruleList, rule, gen, weightID);
1902    return PyInt_FromLong(stop?1:0);
1903  PyCATCH
1904}
1905
1906PyObject *RuleDataStoppingCriteria_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.rules.DataStoppingCriteria, "<abstract>")
1907{ if (type == (PyTypeObject *)&PyOrRuleDataStoppingCriteria_Type)
1908    return setCallbackFunction(WrapNewOrange(mlnew TRuleDataStoppingCriteria_Python(), type), args);
1909  else
1910    return WrapNewOrange(mlnew TRuleDataStoppingCriteria_Python(), type);
1911}
1912
1913PyObject *RuleDataStoppingCriteria__reduce__(PyObject *self)
1914{
1915  return callbackReduce(self, PyOrRuleDataStoppingCriteria_Type);
1916}
1917
1918
1919PyObject *RuleDataStoppingCriteria_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(table, weightID, targetClass) -/-> (table)")
1920{
1921  PyTRY
1922    NO_KEYWORDS
1923
1924    PExampleGenerator gen;
1925    int weightID = 0;
1926    int targetClass = -1;
1927
1928    if (!PyArg_ParseTuple(args, "O&O&i:RuleDataStoppingCriteria.call", pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID, &targetClass))
1929      return PYNULL;
1930    CAST_TO(TRuleDataStoppingCriteria, dataStopping)
1931
1932    bool stop = (*dataStopping)(gen, weightID, targetClass);
1933    return PyInt_FromLong(stop?1:0);
1934  PyCATCH
1935}
1936
1937PyObject *RuleFinder_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.rules.Finder, "<abstract>")
1938{ if (type == (PyTypeObject *)&PyOrRuleFinder_Type)
1939    return setCallbackFunction(WrapNewOrange(mlnew TRuleFinder_Python(), type), args);
1940  else
1941    return WrapNewOrange(mlnew TRuleFinder_Python(), type);
1942}
1943
1944PyObject *RuleFinder__reduce__(PyObject *self)
1945{
1946  return callbackReduce(self, PyOrRuleFinder_Type);
1947}
1948
1949
1950PyObject *RuleFinder_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(table, weightID, targetClass, baseRules) -/-> (rule)")
1951{
1952  PyTRY
1953    NO_KEYWORDS
1954
1955    PExampleGenerator gen;
1956    int weightID = 0;
1957    int targetClass = -1;
1958    PRuleList baseRules;
1959
1960    if (!PyArg_ParseTuple(args, "O&O&iO&:RuleFinder.call", pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID, &targetClass, ccn_RuleList, &baseRules))
1961      return PYNULL;
1962    CAST_TO(TRuleFinder, finder)
1963
1964    PRule res = (*finder)(gen, weightID, targetClass, baseRules);
1965    return WrapOrange(res);
1966  PyCATCH
1967}
1968
1969PyObject *RuleBeamRefiner_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.rules.BeamRefiner, "<abstract>")
1970{ if (type == (PyTypeObject *)&PyOrRuleBeamRefiner_Type)
1971    return setCallbackFunction(WrapNewOrange(mlnew TRuleBeamRefiner_Python(), type), args);
1972  else
1973    return WrapNewOrange(mlnew TRuleBeamRefiner_Python(), type);
1974}
1975
1976PyObject *RuleBeamRefiner__reduce__(PyObject *self)
1977{
1978  return callbackReduce(self, PyOrRuleBeamRefiner_Type);
1979}
1980
1981
1982PyObject *RuleBeamRefiner_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(rule, table, weightID, targetClass) -/-> (rules)")
1983{
1984  PyTRY
1985    NO_KEYWORDS
1986
1987    PExampleGenerator gen;
1988    int weightID = 0;
1989    int targetClass = -1;
1990    PRule rule;
1991
1992    if (!PyArg_ParseTuple(args, "O&O&O&i:RuleBeamRefiner.call", cc_Rule, &rule, pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID, &targetClass))
1993      return PYNULL;
1994    CAST_TO(TRuleBeamRefiner, refiner)
1995
1996    PRuleList res = (*refiner)(rule, gen, weightID, targetClass);
1997    return WrapOrange(res);
1998  PyCATCH
1999}
2000
2001PyObject *RuleBeamInitializer_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.rules.BeamInitializer, "<abstract>")
2002{ if (type == (PyTypeObject *)&PyOrRuleBeamInitializer_Type)
2003    return setCallbackFunction(WrapNewOrange(mlnew TRuleBeamInitializer_Python(), type), args);
2004  else
2005    return WrapNewOrange(mlnew TRuleBeamInitializer_Python(), type);
2006}
2007
2008PyObject *RuleBeamInitializer__reduce__(PyObject *self)
2009{
2010  return callbackReduce(self, PyOrRuleBeamInitializer_Type);
2011}
2012
2013
2014PyObject *RuleBeamInitializer_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(table, weightID, targetClass, baseRules, evaluator, prior) -/-> (rules, bestRule)")
2015{
2016  PyTRY
2017     NO_KEYWORDS
2018
2019    PExampleGenerator gen;
2020    PRuleList baseRules;
2021    PRuleEvaluator evaluator;
2022    PDistribution prior;
2023    PRule bestRule;
2024    int weightID = 0;
2025    int targetClass = -1;
2026    PRule rule;
2027
2028    if (!PyArg_ParseTuple(args, "O&O&iO&O&O&:RuleBeamInitializer.call", pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID, &targetClass, ccn_RuleList, &baseRules, cc_RuleEvaluator, &evaluator, cc_Distribution, &prior))
2029      return PYNULL;
2030    CAST_TO(TRuleBeamInitializer, initializer)
2031
2032    PRuleList res = (*initializer)(gen, weightID, targetClass, baseRules, evaluator, prior, bestRule);
2033    return Py_BuildValue("NN", WrapOrange(res), WrapOrange(bestRule));
2034  PyCATCH
2035}
2036
2037PyObject *RuleBeamCandidateSelector_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.rules.BeamCandidateSelector, "<abstract>")
2038{ if (type == (PyTypeObject *)&PyOrRuleBeamCandidateSelector_Type)
2039    return setCallbackFunction(WrapNewOrange(mlnew TRuleBeamCandidateSelector_Python(), type), args);
2040  else
2041    return WrapNewOrange(mlnew TRuleBeamCandidateSelector_Python(), type);
2042}
2043
2044PyObject *RuleBeamCandidateSelector__reduce__(PyObject *self)
2045{
2046  return callbackReduce(self, PyOrRuleBeamCandidateSelector_Type);
2047}
2048
2049
2050PyObject *RuleBeamCandidateSelector_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(existingRules, table, weightID) -/-> (candidates, remainingRules)")
2051{
2052  PyTRY
2053    NO_KEYWORDS
2054
2055    PExampleGenerator gen;
2056    PRuleList existingRules;
2057    int weightID = 0;
2058    PRuleList candidates;
2059
2060    if (!PyArg_ParseTuple(args, "O&O&O&:RuleBeamCandidateSelector.call", cc_RuleList, &existingRules, pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID))
2061      return PYNULL;
2062    CAST_TO(TRuleBeamCandidateSelector, selector)
2063
2064    PRuleList res = (*selector)(existingRules, gen, weightID);
2065    return Py_BuildValue("NN", WrapOrange(res), WrapOrange(existingRules));
2066  PyCATCH
2067}
2068
2069PyObject *RuleBeamFilter_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.rules.BeamFilter, "<abstract>")
2070{ if (type == (PyTypeObject *)&PyOrRuleBeamFilter_Type)
2071    return setCallbackFunction(WrapNewOrange(mlnew TRuleBeamFilter_Python(), type), args);
2072  else
2073    return WrapNewOrange(mlnew TRuleBeamFilter_Python(), type);
2074}
2075
2076PyObject *RuleBeamFilter__reduce__(PyObject *self)
2077{
2078  return callbackReduce(self, PyOrRuleBeamFilter_Type);
2079}
2080
2081
2082PyObject *RuleBeamFilter_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(rules, table, weightID) -/-> (rules)")
2083{
2084  PyTRY
2085    NO_KEYWORDS
2086
2087    PExampleGenerator gen;
2088    PRuleList rules;
2089    int weightID = 0;
2090
2091    if (!PyArg_ParseTuple(args, "O&O&O&:RuleBeamFilter.call", cc_RuleList, &rules, pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID))
2092      return PYNULL;
2093    CAST_TO(TRuleBeamFilter, filter)
2094
2095    (*filter)(rules, gen, weightID);
2096    return WrapOrange(rules);
2097  PyCATCH
2098}
2099
2100PyObject *RuleClassifierConstructor_new(PyTypeObject *type, PyObject *args, PyObject *keywords)  BASED_ON(Orange - Orange.classification.rules.ClassifierConstructor, "<abstract>")
2101{ if (type == (PyTypeObject *)&PyOrRuleClassifierConstructor_Type)
2102    return setCallbackFunction(WrapNewOrange(mlnew TRuleClassifierConstructor_Python(), type), args);
2103  else
2104    return WrapNewOrange(mlnew TRuleClassifierConstructor_Python(), type);
2105}
2106
2107
2108PyObject *RuleClassifierConstructor__reduce__(PyObject *self)
2109{
2110  return callbackReduce(self, PyOrRuleClassifierConstructor_Type);
2111}
2112
2113
2114PyObject *RuleClassifierConstructor_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(rules, examples[, weight]) -> (RuleClassifier)")
2115{
2116  PyTRY
2117    NO_KEYWORDS
2118
2119    if (PyOrange_OrangeBaseClass(self->ob_type) == &PyOrRuleClassifierConstructor_Type) {
2120      PyErr_Format(PyExc_SystemError, "RuleClassifierConstructor.call called for '%s': this may lead to stack overflow", self->ob_type->tp_name);
2121      return PYNULL;
2122    }
2123
2124    PExampleGenerator gen;
2125    int weightID = 0;
2126    PRuleList rules;
2127
2128    if (!PyArg_ParseTuple(args, "O&O&|O&:RuleClassifierConstructor.call", cc_RuleList, &rules, pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID))
2129      return PYNULL;
2130
2131    PRuleClassifier ruleClassifier;
2132    ruleClassifier = SELF_AS(TRuleClassifierConstructor)(rules, gen, weightID);
2133    return WrapOrange(ruleClassifier);
2134  PyCATCH
2135}
2136
2137PyObject *RuleClassifier_logit_new(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(rules, min_beta, examples[, weight])")
2138{
2139  PyTRY
2140    NO_KEYWORDS
2141
2142    if (PyOrange_OrangeBaseClass(self->ob_type) == &PyOrRuleClassifier_Type) {
2143      PyErr_Format(PyExc_SystemError, "RuleClassifier.call called for '%s': this may lead to stack overflow", self->ob_type->tp_name);
2144      return PYNULL;
2145    }
2146
2147    PExampleGenerator gen;
2148    int weightID = 0;
2149    float minSignificance = 0.5;
2150    float minBeta = 0.0;
2151    PRuleList rules;
2152    PDistributionList probList;
2153    PClassifier classifier;
2154    bool setPrefixRules;
2155    bool optimizeBetasFlag;
2156    float penalty = 0.01f;
2157
2158    if (!PyArg_ParseTuple(args, "O&fffO&|O&iiO&O&:RuleClassifier.call", cc_RuleList, &rules, &minSignificance, &minBeta, &penalty, pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID, &setPrefixRules, &optimizeBetasFlag, cc_Classifier, &classifier, cc_DistributionList, &probList))
2159      return PYNULL;
2160
2161    TRuleClassifier *rc = new TRuleClassifier_logit(rules, minSignificance, minBeta, penalty, gen, weightID, classifier, probList, setPrefixRules, optimizeBetasFlag);
2162    PRuleClassifier ruleClassifier = rc;
2163//    ruleClassifier = new SELF_AS(TRuleClassifier)(rules, gen, weightID);
2164    return WrapOrange(ruleClassifier);
2165  PyCATCH
2166}
2167
2168PRuleList PRuleList_FromArguments(PyObject *arg) { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::P_FromArguments(arg); }
2169PyObject *RuleList_FromArguments(PyTypeObject *type, PyObject *arg) { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_FromArguments(type, arg); }
2170PyObject *RuleList_new(PyTypeObject *type, PyObject *arg, PyObject *kwds) BASED_ON(Orange, "(<list of Rule>)") ALLOWS_EMPTY { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_new(type, arg, kwds); }
2171PyObject *RuleList_getitem_sq(TPyOrange *self, Py_ssize_t index) { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_getitem(self, index); }
2172int       RuleList_setitem_sq(TPyOrange *self, Py_ssize_t index, PyObject *item) { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_setitem(self, index, item); }
2173PyObject *RuleList_getslice(TPyOrange *self, Py_ssize_t start, Py_ssize_t stop) { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_getslice(self, start, stop); }
2174int       RuleList_setslice(TPyOrange *self, Py_ssize_t start, Py_ssize_t stop, PyObject *item) { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_setslice(self, start, stop, item); }
2175Py_ssize_t       RuleList_len_sq(TPyOrange *self) { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_len(self); }
2176PyObject *RuleList_richcmp(TPyOrange *self, PyObject *object, int op) { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_richcmp(self, object, op); }
2177PyObject *RuleList_concat(TPyOrange *self, PyObject *obj) { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_concat(self, obj); }
2178PyObject *RuleList_repeat(TPyOrange *self, Py_ssize_t times) { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_repeat(self, times); }
2179PyObject *RuleList_str(TPyOrange *self) { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_str(self); }
2180PyObject *RuleList_repr(TPyOrange *self) { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_str(self); }
2181int       RuleList_contains(TPyOrange *self, PyObject *obj) { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_contains(self, obj); }
2182PyObject *RuleList_append(TPyOrange *self, PyObject *item) PYARGS(METH_O, "(Rule) -> None") { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_append(self, item); }
2183PyObject *RuleList_extend(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(sequence) -> None") { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_extend(self, obj); }
2184PyObject *RuleList_count(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(Rule) -> int") { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_count(self, obj); }
2185PyObject *RuleList_filter(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "([filter-function]) -> RuleList") { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_filter(self, args); }
2186PyObject *RuleList_index(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(Rule) -> int") { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_index(self, obj); }
2187PyObject *RuleList_insert(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "(index, item) -> None") { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_insert(self, args); }
2188PyObject *RuleList_native(TPyOrange *self) PYARGS(METH_NOARGS, "() -> list") { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_native(self); }
2189PyObject *RuleList_pop(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "() -> Rule") { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_pop(self, args); }
2190PyObject *RuleList_remove(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(Rule) -> None") { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_remove(self, obj); }
2191PyObject *RuleList_reverse(TPyOrange *self) PYARGS(METH_NOARGS, "() -> None") { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_reverse(self); }
2192PyObject *RuleList_sort(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "([cmp-func]) -> None") { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_sort(self, args); }
2193PyObject *RuleList__reduce__(TPyOrange *self, PyObject *) { return ListOfWrappedMethods<PRuleList, TRuleList, PRule, &PyOrRule_Type>::_reduce(self); }
2194
2195PEVDistList PEVDistList_FromArguments(PyObject *arg) { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::P_FromArguments(arg); }
2196PyObject *EVDistList_FromArguments(PyTypeObject *type, PyObject *arg) { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_FromArguments(type, arg); }
2197PyObject *EVDistList_new(PyTypeObject *type, PyObject *arg, PyObject *kwds) BASED_ON(Orange, "(<list of EVDist>)") ALLOWS_EMPTY { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_new(type, arg, kwds); }
2198PyObject *EVDistList_getitem_sq(TPyOrange *self, Py_ssize_t index) { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_getitem(self, index); }
2199int       EVDistList_setitem_sq(TPyOrange *self, Py_ssize_t index, PyObject *item) { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_setitem(self, index, item); }
2200PyObject *EVDistList_getslice(TPyOrange *self, Py_ssize_t start, Py_ssize_t stop) { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_getslice(self, start, stop); }
2201int       EVDistList_setslice(TPyOrange *self, Py_ssize_t start, Py_ssize_t stop, PyObject *item) { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_setslice(self, start, stop, item); }
2202Py_ssize_t       EVDistList_len_sq(TPyOrange *self) { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_len(self); }
2203PyObject *EVDistList_richcmp(TPyOrange *self, PyObject *object, int op) { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_richcmp(self, object, op); }
2204PyObject *EVDistList_concat(TPyOrange *self, PyObject *obj) { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_concat(self, obj); }
2205PyObject *EVDistList_repeat(TPyOrange *self, Py_ssize_t times) { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_repeat(self, times); }
2206PyObject *EVDistList_str(TPyOrange *self) { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_str(self); }
2207PyObject *EVDistList_repr(TPyOrange *self) { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_str(self); }
2208int       EVDistList_contains(TPyOrange *self, PyObject *obj) { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_contains(self, obj); }
2209PyObject *EVDistList_append(TPyOrange *self, PyObject *item) PYARGS(METH_O, "(EVDist) -> None") { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_append(self, item); }
2210PyObject *EVDistList_extend(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(sequence) -> None") { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_extend(self, obj); }
2211PyObject *EVDistList_count(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(EVDist) -> int") { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_count(self, obj); }
2212PyObject *EVDistList_filter(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "([filter-function]) -> EVDistList") { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_filter(self, args); }
2213PyObject *EVDistList_index(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(EVDist) -> int") { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_index(self, obj); }
2214PyObject *EVDistList_insert(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "(index, item) -> None") { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_insert(self, args); }
2215PyObject *EVDistList_native(TPyOrange *self) PYARGS(METH_NOARGS, "() -> list") { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_native(self); }
2216PyObject *EVDistList_pop(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "() -> EVDist") { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_pop(self, args); }
2217PyObject *EVDistList_remove(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(EVDist) -> None") { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_remove(self, obj); }
2218PyObject *EVDistList_reverse(TPyOrange *self) PYARGS(METH_NOARGS, "() -> None") { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_reverse(self); }
2219PyObject *EVDistList_sort(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "([cmp-func]) -> None") { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_sort(self, args); }
2220PyObject *EVDistList__reduce__(TPyOrange *self, PyObject *) { return ListOfWrappedMethods<PEVDistList, TEVDistList, PEVDist, &PyOrEVDist_Type>::_reduce(self); }
2221
2222#include "lib_learner.px"
2223
Note: See TracBrowser for help on using the repository browser.