source: orange/source/orange/lib_learner.cpp @ 11610:33695add91c0

Revision 11610:33695add91c0, 98.1 KB checked in by Ales Erjavec <ales.erjavec@…>, 10 months ago (diff)

Cleanup of TLinearLearner/Classifier.

The training examples are sorted before training so the labels in
LIBLINEAR model match the order of class_var.values.

TLinearClassifier no longer has the 'examples' member, has a changed
constructor and (un)pickle signature.

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