Changeset 10968:4fc91cbe443f in orange


Ignore:
Timestamp:
08/21/12 14:22:12 (20 months ago)
Author:
mlevar
Branch:
default
Message:

Added Clustering Trees to Orange.core

Location:
source/orange
Files:
6 added
2 edited

Legend:

Unmodified
Added
Removed
  • source/orange/lib_kernel.cpp

    r10606 r10968  
    57145714} 
    57155715 
     5716/* ************ MULTI-TARGET LEARNER AND CLASSIFIER ************ */ 
     5717 
     5718#include "multi_classifier.hpp" 
     5719#include "multi_learner.hpp" 
     5720 
     5721ABSTRACT(MultiLearner - Orange.classification.MultiLearner, Orange) 
     5722 
     5723PyObject *MultiLearner_call(PyObject *self, PyObject *targs, PyObject *keywords) PYDOC("(examples) -> Classifier") 
     5724{ 
     5725  PyTRY 
     5726    NO_KEYWORDS 
     5727 
     5728    if (PyOrange_OrangeBaseClass(self->ob_type) == &PyOrLearner_Type) { 
     5729      PyErr_Format(PyExc_SystemError, "Learner.call called for '%s': this may lead to stack overflow", self->ob_type->tp_name); 
     5730      return PYNULL; 
     5731    } 
     5732 
     5733    PExampleGenerator egen; 
     5734    int weight = 0; 
     5735    if (!PyArg_ParseTuple(targs, "O&|O&", pt_ExampleGenerator, &egen, pt_weightByGen(egen), &weight)) 
     5736      PYERROR(PyExc_AttributeError, "Learner.__call__: examples and, optionally, weight attribute expected", PYNULL); 
     5737 
     5738    PMultiClassifier classfr = SELF_AS(TMultiLearner)(egen, weight); 
     5739 
     5740    if (!classfr) 
     5741      PYERROR(PyExc_SystemError, "learning failed", PYNULL); 
     5742     
     5743    return WrapOrange(classfr); 
     5744  PyCATCH 
     5745} 
     5746 
     5747/* ************ MULTI LEARNER and MULTI CLASSIFIER ************ */ 
     5748 
     5749ABSTRACT(MultiClassifier - Orange.classification.MultiClassifier, Orange) 
     5750 
     5751PyObject *MultiClassifier_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(example[, format]) -> Value | distribution | (Value, distribution)") 
     5752{ PyTRY 
     5753    NO_KEYWORDS 
     5754 
     5755    CAST_TO(TMultiClassifier, multi_classifier); 
     5756 
     5757    if ((PyOrange_OrangeBaseClass(self->ob_type) == &PyOrClassifier_Type) && !dynamic_cast<TClassifier_Python *>(multi_classifier)) {  
     5758      PyErr_Format(PyExc_SystemError, "Classifier.call called for '%s': this may lead to stack overflow", self->ob_type->tp_name); 
     5759      return PYNULL; 
     5760    } 
     5761 
     5762    if (!multi_classifier) 
     5763      PYERROR(PyExc_SystemError, "attribute error", PYNULL); 
     5764 
     5765    TExample *example; 
     5766    int dist=0; 
     5767    if (!PyArg_ParseTuple(args, "O&|i", ptr_Example, &example, &dist)) 
     5768      PYERROR(PyExc_TypeError, "attribute error; example (and, optionally, return type) expected", PYNULL); 
     5769    PyObject *returnValues; 
     5770    PValueList classValues; 
     5771    switch (dist) { 
     5772      case 0: 
     5773        classValues = (*multi_classifier)(*example); 
     5774        returnValues = PyList_New(multi_classifier->classVars->size()); 
     5775        for(int i = 0; i< multi_classifier->classVars->size(); i++) 
     5776            PyList_SET_ITEM(returnValues, i, Value_FromVariableValue(multi_classifier->classVars->at(i), classValues->at(i))); 
     5777        return returnValues; 
     5778      case 1: 
     5779        return WrapOrange(multi_classifier->classDistribution(*example)); 
     5780      case 2: 
     5781        PDistributionList classDists; 
     5782        multi_classifier->predictionAndDistribution(*example, classValues, classDists); 
     5783        returnValues = PyList_New(multi_classifier->classVars->size()); 
     5784        for(int i = 0; i< multi_classifier->classVars->size(); i++) 
     5785            PyList_SET_ITEM(returnValues, i, Value_FromVariableValue(multi_classifier->classVars->at(i), classValues->at(i))); 
     5786 
     5787        return Py_BuildValue("NN", returnValues, WrapOrange(classDists));  
     5788    } 
     5789 
     5790    PYERROR(PyExc_AttributeError, "invalid parameter for classifier call", PYNULL); 
     5791 
     5792  PyCATCH 
     5793} 
    57165794 
    57175795 
  • source/orange/lib_learner.cpp

    r10619 r10968  
    5252 
    5353#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 
    5489 
    5590/* ************ SIMPLE TREE LEARNER ************ */ 
Note: See TracChangeset for help on using the changeset viewer.