Aleš Erjavec avatar Aleš Erjavec committed 4f4446f

Moved _modelmaps package into orangecontrib namespace.

Comments (0)

Files changed (56)

-recursive-include _modelmaps *.png
+recursive-include orangecontrib/modelmaps *.png
 recursive-include tests *
 recursive-include docs/rst *
 include docs/Makefile

_modelmaps/__init__.py

-"""
-Examples
-========
-
-No examples are implemented yet. Write to the author for more information.
-
-"""
-
-import math
-import os.path
-import pickle
-import random
-import time
-
-import numpy as np
-
-#from orngScaleData import getVariableValuesSorted
-#from OWDistanceFile import readMatrix
-
-from Orange import data, feature
-
-from model import *
-from modelmap import *
-
-#ROOT = "/home/miha/work/res/metamining/"
-#OUT_FILE = ROOT + "dst/zoo"
-#OUT_FILE = ROOT + "dst/zoo"
-#OUT_FILE = ROOT + "_astra_/fprdk"
-#
-#def saveSymMatrix(matrix, file, items=None, saveItems=False):
-#    fn = open(file + ".dst", 'w')
-#    fn.write("%d labeled\n" % matrix.dim)
-#    items = items if items else matrix.items
-#    for i in range(matrix.dim):
-#        fn.write("%s" % items[i]['attributes'])
-#        for j in range(i + 1):
-#            fn.write("\t%.6f" % matrix[i, j])
-#        fn.write("\n")
-#
-#    fn.close()
-#    if saveItems:
-#        items.save(file + ".tab")
-#
-#
-#
-#def loadModel(fn):
-#    if os.path.exists('%s.npy' % fn):
-#        matrix, _labels, data = readMatrix('%s.npy' % fn)
-#    elif os.path.exists("%s-prob.dst" % fn):
-#        matrix, _labels, data = readMatrix("%s-prob.dst" % fn)
-#    elif os.path.exists("%s.dst" % fn):
-#        matrix, _labels, data = readMatrix("%s.dst" % fn)
-#    else:
-#        return None
-#
-#    if os.path.exists("%s.tab" % fn):
-#        data = data.Table("%s.tab" % fn)
-#        matrix.items = data
-#    else:
-#        print "ExampleTable %s not found!\n" % ("%s.tab" % fn)
-#    if os.path.exists("%s.res" % fn):
-#        matrix.results = pickle.load(open("%s.res" % fn, 'rb'))
-#    else:
-#        print "Results pickle %s not found!\n" % ("%s.res" % fn)
-#
-#    return matrix
-#
-#def saveModel(smx, fn):
-#    saveSymMatrix(smx, "%s" % fn, smx.items)
-#    smx.items.save('%s.tab' % fn)
-#    pickle.dump(smx.results, open('%s.res' % fn, "wb"))
-#
-#
-#def evaluateProjections(vizr, attributeList):
-#    vizr.evaluatedProjectionsCount = 0
-#    vizr.optimizedProjectionsCount = 0
-#    vizr.evaluationData = {}            # clear all previous data about tested permutations and stuff
-#    vizr.evaluationData["triedCombinations"] = {}
-#    vizr.clearResults()
-#
-#    vizr.clearArguments()
-#
-#    if vizr.projOptimizationMethod != 0:
-#        vizr.freeviz.useGeneralizedEigenvectors = 1
-#        vizr.graph.normalizeExamples = 0
-#
-#    domain = data.Domain([feature.Continuous("xVar"), feature.Continuous("yVar"), feature.Discrete(vizr.graph.dataDomain.classVar.name, values=getVariableValuesSorted(vizr.graph.dataDomain.classVar))])
-#    classListFull = vizr.graph.originalData[vizr.graph.dataClassIndex]
-#
-#    for attributes in attributeList:
-#        attrIndices = [vizr.graph.attributeNameIndex[attr] for attr in attributes]
-#        #print attrIndices
-#        if vizr.projOptimizationMethod != 0:
-#            projections = vizr.freeviz.findProjection(vizr.projOptimizationMethod, attrIndices, setAnchors=0, percentDataUsed=vizr.percentDataUsed)
-#            if projections != None:
-#                xanchors, yanchors, (attrNames, newIndices) = projections
-#                table = vizr.graph.createProjectionAsExampleTable(newIndices, domain=domain, XAnchors=xanchors, YAnchors=yanchors)
-#
-#            if table == None or len(table) < vizr.minNumOfExamples: continue
-#            accuracy, other_results = vizr.evaluateProjection(table)
-#            generalDict = {"XAnchors": list(xanchors), "YAnchors": list(yanchors), "Results": vizr.evaluationResults} if vizr.saveEvaluationResults else {"XAnchors": list(xanchors), "YAnchors": list(yanchors)}
-#            vizr.addResult(accuracy, other_results, len(table), attrNames, vizr.evaluatedProjectionsCount, generalDict=generalDict)
-#            vizr.evaluatedProjectionsCount += 1
-#        else:
-#            XAnchors = vizr.graph.createXAnchors(len(attrIndices))
-#            YAnchors = vizr.graph.createYAnchors(len(attrIndices))
-#            validData = vizr.graph.getValidList(attrIndices)
-#            if numpy.sum(validData) >= vizr.minNumOfExamples:
-#                classList = numpy.compress(validData, classListFull)
-#                selectedData = numpy.compress(validData, numpy.take(vizr.graph.noJitteringScaledData, attrIndices, axis=0), axis=1)
-#                sum_i = vizr.graph._getSum_i(selectedData)
-#
-#                table = vizr.graph.createProjectionAsExampleTable(attrIndices, validData=validData, classList=classList, sum_i=sum_i, XAnchors=XAnchors, YAnchors=YAnchors, domain=domain)
-#                accuracy, other_results = vizr.evaluateProjection(table)
-#                generalDict = {"Results": vizr.evaluationResults} if vizr.saveEvaluationResults else {}
-#                vizr.addResult(accuracy, other_results, len(table), [vizr.graph.attributeNames[i] for i in attrIndices], vizr.evaluatedProjectionsCount, generalDict)
-#                vizr.evaluatedProjectionsCount += 1
-#
-#    return vizr.evaluatedProjectionsCount

_modelmaps/model.py

-"""
-.. index:: model
-
-*****
-Model
-*****
-
-.. autoclass:: Orange.modelmaps.Model
-   :members:
-
-"""
-
-import uuid
-import numpy as np
-
-from itertools import groupby
-from operator import itemgetter
-
-from Orange import data
-
-class Model(object):
-
-    def __init__(self, type_, classifier, probabilities, \
-                 class_values, attributes, \
-                 instance_predictions=None, instance_classes=None, \
-                 name=None, XAnchors=None, YAnchors=None):
-        """Meta-model, a node in Model Map.
-        
-        :param type_: model type; must be in MODEL_LIST
-        :type type_: string
-        
-        :param classifier: classifier object of this model
-        :type classifier: :obj:`Orange.classification.Classifier`
-        
-        :param probabilities: list of predicted probabilities (for all classes) 
-        :type probabilities: list of :obj:`numpy.ndarray`
-        
-        :param attributes: list of attribute names
-        :type attributes: list
-        
-        :param instance_predictions: array of predicted classes for all instances
-        :type instance_predictions: :obj:`numpy.ndarray`
-        
-        :param instance_classes: array of true classes for all instances
-        :type instance_classes: :obj:`numpy.ndarray`
-        
-        :param name: model name
-        :type name: string
-        
-        :param XAnchors: 
-        :type XAnchors: list 
-        
-        :param YAnchors: 
-        :type YAnchors: list
-        
-        """
-
-        self.uuid = uuid.uuid4().hex
-        self.type = type_
-        self.classifier = classifier
-        self.probabilities = probabilities
-        self.class_values = class_values
-        self.attributes = attributes
-        self.instance_predictions = instance_predictions
-        self.instance_classes = instance_classes
-        self.name = name if name is not None else self.type
-        self.XAnchors = XAnchors
-        self.YAnchors = YAnchors
-
-    def get_instance(self, domain):
-        """Return an :obj:`Orange.data.Table` instance with model meta-data.
-        
-        :param domain: instance will match given domain 
-        :type domain: :obj:`Orange.data.Domain`
-        """
-
-        inst = data.Instance(domain)
-
-        inst['uuid'] = self.uuid
-        inst['number of attributes'] = len(set(self.attributes))
-        results = [p == c for p, c in zip(self.instance_predictions, self.instance_classes)]
-        inst['CA'] = sum(results) / float(len(results))
-        inst['P'] = np.mean([p[self.class_values[c]] for p, c in zip(self.probabilities, self.instance_classes)])
-
-        classes = zip(*sorted(self.class_values.items(), key=itemgetter(1)))[0]
-        outcomes = np.array([c == self.instance_classes for c in classes]).T
-
-        inst['Brier'] = np.sum(np.square(self.probabilities - outcomes)) / len(self.probabilities)
-        inst['Brier by class'] = ', '.join(map(str, zip(*sorted(zip(classes, np.sum(np.square(self.probabilities - outcomes), axis=0) / len(self.probabilities))))[1]))
-        inst['type'] = self.type
-        inst['model'] = self
-        inst['attributes'] = ', '.join(self.attributes)
-        #ex["AUC"] = nets[i].items[m]["AUC"].value
-        resultsByClass = sorted([(p == c, c) for p, c in zip(self.instance_predictions, self.instance_classes)], key=itemgetter(1))
-        groups = []
-        for _k, g in groupby(resultsByClass, lambda x: x[1]):
-            resultsByClass, _classes = zip(*g)
-            groups.append(resultsByClass)
-        inst["CA by class"] = ', '.join([str(sum(results) / float(len(results))) for results in groups])
-        #ex["cluster CA"] = best_indices[i][j]
-        #ex["cluster size"] = median_csizes[i][j]
-        inst["label"] = self.name
-
-        return inst

_modelmaps/modelmap.py

-"""
-.. index:: model map
-
-***************
-Build Model Map
-***************
-
-.. autoclass:: Orange.modelmaps.BuildModelMap
-   :members:
-   
-**************
-Help Functions
-**************
-
-.. autofunction:: load
-.. autofunction:: save
-.. autofunction:: get_models_table
-.. autofunction:: get_feature_subsets
-
-"""
-
-import bz2, itertools, math, random, os.path, time, uuid, re, sys
-import cPickle as pickle
-
-import scipy.stats
-import numpy as np
-
-import orngVizRank as vr
-import model
-
-from orngScaleData import getVariableValuesSorted
-
-from Orange import data, distance, ensemble, feature, misc, projection
-from Orange.classification.knn import kNNLearner
-from Orange.classification.tree import SimpleTreeLearner, TreeLearner
-
-MODEL_LIST = ["", "SCATTERPLOT", "RADVIZ", "SPCA", "POLYVIZ", "TREE", "NaiveLearner", "kNNLearner", "SVM", "RF"]
-
-def distance_mi(m1, m2):
-    """Return inverted normalized mutual information.
-
-    1 - NMI(m1.instance_predictions, m2.instance_predictions)
-    """
-
-    classes1 = np.unique(m1.instance_predictions)
-    classes2 = np.unique(m2.instance_predictions)
-    m1_classes = [m1.instance_predictions == c for c in classes1]
-    m2_classes = [m2.instance_predictions == c for c in classes2]
-    m1_p = [np.average(m1_c1) for m1_c1 in m1_classes]
-    m2_p = [np.average(m2_c2) for m2_c2 in m2_classes]
-
-    eps = np.finfo(float).eps
-    mi = sum(sum(np.average(m1_c1 & m2_c2) * np.log2(max(np.average(m1_c1 & m2_c2) / p1 / p2, eps)) for m2_c2, p2 in zip(m2_classes, m2_p)) for m1_c1, p1 in zip(m1_classes, m1_p))
-    h1 = -sum(p * np.log2(p) for p in m1_p)
-    h2 = -sum(p * np.log2(p) for p in m2_p)
-
-    return 0 if h1 == 0 and h2 == 0 else 1. - 2 * mi / (h1 + h2)
-
-def distance_class(m1, m2):
-    w = np.average(m1.instance_predictions != m2.instance_predictions)
-    return 1 if math.isnan(w) else w
-
-def distance_manhattan(m1, m2):
-    return np.sum(np.abs(m1.probabilities - m2.probabilities)) / 2. / len(m1.probabilities)
-
-def distance_euclidean(m1, m2):
-    return np.sum(np.sqrt(np.sum((m1.probabilities - m2.probabilities)**2, axis=1))) / math.sqrt(2.) / len(m1.probabilities)
-
-def distance_rank(m1, m2):
-    return 1 - abs(scipy.stats.spearmanr(m1.probabilities, m2.probabilities, axis=None)[0])
-
-def get_feature_subsets_scatterplot(domain, nsubsets):
-    """Return attribute subsets for Scatter Plot."""
-    attrs = []
-    for i in range(len(domain.features)):
-        for j in range(i):
-            attrs.append((domain.features[i].name, domain.features[j].name))
-    random.shuffle(attrs)
-
-    if nsubsets > len(attrs):
-        raise AttributeError("Attribute nsubsets higher than number of possible combinations: %d." % len(attrs))
-
-    return attrs[:nsubsets]
-
-def get_feature_subsets(domain, nsubsets=None, min_features=None, max_features=None):
-    """Return random attribute subsets.
-    
-    :param domain: data set domain to extract features
-    :type domain: :obj:`Orange.data.Domain`
-    
-    :param nsubsets:  number of attribute subsets
-    :type nsubsets: int
-    
-    """
-
-    def binomial(n, k):
-        if n > k:
-            return math.factorial(n) / (math.factorial(k) * math.factorial(n - k))
-        elif n == k:
-            return 1
-        else:
-            return 0
-
-    max_features = len(domain.features) if max_features is None else min(max_features, len(domain.features))
-    min_features = 2 if min_features is None else max(min(min_features, max_features), 2)
-
-    attrs = [var.name for var in domain.features]
-    nattrs = len(attrs)
-    total = sum(binomial(nattrs, i) for i in range(min_features, max_features + 1))
-
-    if nsubsets is not None and nsubsets > total:
-        raise AttributeError("Attribute nsubsets higher than number of possible combinations: %d." % total)
-
-    if min_features == max_features:
-        combinations = itertools.combinations(attrs, max_features)
-    else:
-        combinations = (itertools.chain(*(itertools.combinations(attrs, i) for i in range(min_features, max_features + 1))))
-
-    if nsubsets is None:
-        return list(combinations)
-    else:
-        selectors = [1] * nsubsets + [0] * (total - nsubsets)
-        random.shuffle(selectors)
-        return list(itertools.compress(combinations, selectors))
-    #return list(itertools.compress(combinations, xrange(10)))
-
-def get_models_table():
-    """Return an empty data table for model meta data."""
-
-    attrs = []
-    attrs.append(feature.String("uuid"))
-    varAttrs = feature.Continuous("number of attributes")
-    varAttrs.numberOfDecimals = 0
-    attrs.append(varAttrs)
-    attrs.append(feature.Continuous("CA"))
-    attrs.append(feature.String("CA by class"))
-    attrs.append(feature.Continuous("P"))
-    attrs.append(feature.Continuous("AUC"))
-    attrs.append(feature.Continuous("Brier"))
-    attrs.append(feature.Continuous("Brier by class"))
-    attrs.append(feature.Continuous("cluster CA"))
-    attrs.append(feature.String("label"))
-    attrs.append(feature.String("attributes"))
-    attrs.append(feature.Discrete("type", values=MODEL_LIST[1:]))
-    attrs.append(feature.Python("model"))
-    csizes = feature.Continuous("cluster size")
-    csizes.numberOfDecimals = 0
-    attrs.append(csizes)
-
-    return data.Table(data.Domain(attrs, 0))
-
-
-def load(file_name):
-    """Load a model map. Read compressed tuple containing model similarity
-    matrix and data table.
-
-    """
-
-    base, ext = os.path.splitext(file_name)
-    file_name = base if ext.lower() == ".bz2" else file_name
-
-    smx, table, data = pickle.load(bz2.BZ2File('%s.bz2' % file_name, "r"))
-    return smx, table, data
-
-def save(file_name, smx, model_data, original_data):
-    """Save model map to disk. Model similarity matrix and data table tuple
-    is pickled and compressed as a bz2 archive.
-
-    """
-
-    if original_data is None or smx is None or model_data is None:
-        raise AttributeError("Distance matrix, model meta-data table, and original data table must be given.")
-
-    base, ext = os.path.splitext(file_name)
-    file_name = base if ext.lower() == ".bz2" else file_name
-
-    pickle.dump((smx, model_data, original_data), bz2.BZ2File('%s.bz2' % file_name, "w"), -1)
-
-class BuildModelMap(object):
-
-    def __init__(self, fname, folds=10, model_limit=500):
-
-        self.model_limit = model_limit
-        self.data_d = self._get_data(fname)
-        #self.data_c = self._get_data(fname, continuize=True)
-        self.data_d = data.filter.IsDefined(domain=self.data_d.domain)(self.data_d)
-
-        self.folds = folds if len(self.data_d) < 2000 else 2
-
-        self.indices = data.sample.SubsetIndicesCV(self.data_d, self.folds, randseed=0)
-
-    def _get_data(self, fname, continuize=False):
-        """Return a data Table.
-           
-        :param fname: data set file name
-        :type fname: string
-        
-        :param continuize:  if true, it tries to load a name-c.tab data table as Orange DomainContinuizer changes attribute names.
-        :type continuize: bool
-        
-        """
-
-        if continuize:
-            base, ext = os.path.splitext(fname)
-            if base[-2:] == "-c":
-                fname = "%s%s" % (base, ext)
-            else:
-                fname = "%s-c%s" % (base, ext)
-
-            table = data.Table(fname)
-            return table
-            ##############################################################################
-            ## preprocess Data set
-#            transformer = data.continuization.DomainContinuizer()
-#            transformer.multinomialTreatment = data.continuization.DomainContinuizer.NValues
-#            transformer.continuousTreatment = data.continuization.DomainContinuizer.NormalizeBySpan
-#            transformer.classTreatment = data.continuization.DomainContinuizer.Ignore
-#            table = table.translate(transformer(table))
-#            return feature.imputation.AverageConstructor(table)(table)
-        else:
-            return data.Table(fname)
-
-    def data(self):
-        return self.data_d
-
-    def build_model(self, learner, data):
-        """Build a classification meta-model.
-        
-        :param learner: classification learner to wrap
-        :type learner: :obj:`Orange.classification.Learner`
-        
-        :param data: data set
-        :type data: :obj:`Orange.data.Table`
-        
-        """
-
-        probabilities = []
-        instance_predictions = []
-        instance_classes = []
-        res = []
-        # estimate class probabilities using CV
-        for fold in range(self.folds):
-            learnset = data.selectref(self.indices, fold, negate=1)
-            testset = data.selectref(self.indices, fold, negate=0)
-            classifier = learner(learnset)
-            tcn = 0
-            for i in range(len(data)):
-                if (self.indices[i] == fold):
-                    ex = data.Instance(testset[tcn])
-                    ex.setclass("?")
-
-                    cr = classifier(ex, classifier.GetBoth)
-                    if cr[0].isSpecial():
-                        raise "Classifier %s returned unknown value" % (classifier.name)
-
-                    probabilities.append(list(cr[1]))
-                    instance_predictions.append(cr[0])
-                    instance_classes.append(testset[tcn].get_class())
-                    tcn += 1
-
-        return model.Model(type(learner).__name__,
-                     learner(data),
-                     np.array(probabilities),
-                     {val: i for i, val in enumerate(self.data_d.domain.class_var.values)},
-                     [x.name for x in data.domain.attributes],
-                     instance_predictions,
-                     instance_classes)
-
-    def build_projection_model(self, attributes, visualizationMethod):
-        """Build a projection meta-model."""
-
-        method = "?"
-        if visualizationMethod == vr.SCATTERPLOT:
-            graph = data.preprocess.scaling.ScaleScatterPlotData()
-            method = "SCATTERPLOT"
-        elif visualizationMethod == vr.RADVIZ:
-            graph = data.preprocess.scaling.ScaleLinProjData()
-            graph.normalizeExamples = 1
-            method = "RADVIZ"
-        elif visualizationMethod in [vr.LINEAR_PROJECTION, vr.KNN_IN_ORIGINAL_SPACE]:
-            graph = data.preprocess.scaling.ScaleLinProjData()
-            graph.normalizeExamples = 0
-            method = "SPCA"
-        elif visualizationMethod == vr.POLYVIZ:
-            graph = data.preprocess.scaling.ScalePolyvizData()
-            graph.normalizeExamples = 1
-            method = "POLYVIZ"
-        else:
-            print "an invalid visualization method was specified. VizRank can not run."
-            return
-
-        graph.setData(self.data_d, graph.rawSubsetData)
-        attrIndices = [graph.attributeNameIndex[attr] for attr in attributes]
-        #domain = data.Domain([feature.Continuous("xVar"), feature.Continuous("yVar"), graph.dataDomain.class_var])
-        classListFull = graph.original_data[graph.dataClassIndex]
-        table = None
-
-        if visualizationMethod == vr.LINEAR_PROJECTION:
-            freeviz = projection.linear.FreeViz(graph)
-            projections = freeviz.find_projection(vr.PROJOPT_SPCA, attrIndices, set_anchors=0, percent_data_used=100)
-            if projections != None:
-                XAnchors, YAnchors, (attrNames, newIndices) = projections
-                table = graph.create_projection_as_example_table(newIndices, XAnchors=XAnchors, YAnchors=YAnchors)
-            else:
-                print 'a null projection found'
-        elif visualizationMethod == vr.SCATTERPLOT:
-            XAnchors = YAnchors = None
-            table = graph.create_projection_as_example_table(attrIndices)
-        else:
-            XAnchors = graph.create_xanchors(len(attrIndices))
-            YAnchors = graph.create_yanchors(len(attrIndices))
-            validData = graph.get_valid_list(attrIndices)
-            # more than min number of examples
-            if np.sum(validData) >= 10:
-                classList = np.compress(validData, classListFull)
-                selectedData = np.compress(validData, np.take(graph.no_jittering_scaled_data, attrIndices, axis=0), axis=1)
-                sum_i = graph._getSum_i(selectedData)
-                table = graph.create_projection_as_example_table(attrIndices, validData=validData, classList=classList, sum_i=sum_i, XAnchors=XAnchors, YAnchors=YAnchors)
-
-        if not table: return None
-
-        probabilities = []
-        instance_predictions = []
-        instance_classes = []
-        learner = kNNLearner(k=0, rankWeight=0, distanceConstructor=distance.Euclidean(normalize=0))
-
-        for fold in range(self.folds):
-            learnset = table.selectref(self.indices, fold, negate=1)
-            testset = table.select(self.indices, fold, negate=0)
-            classifier = learner(learnset)
-
-            for ex in testset:
-                instance_classes.append(ex.get_class().value)
-                ex.setclass("?")
-                cl, prob = classifier(ex, classifier.GetBoth)
-                probabilities.append(list(prob))
-                instance_predictions.append(cl.value)
-
-            if len(table) > 2000:
-                break
-
-        return model.Model(method,
-                     None, #learner(table),
-                     np.array(probabilities),
-                     {val: i for i, val in enumerate(self.data_d.domain.class_var.values)},
-                     attributes,
-                     np.array(instance_predictions),
-                     np.array(instance_classes),
-                     XAnchors=XAnchors,
-                     YAnchors=YAnchors)
-
-
-    def build_rf_models(self, trees=50, max_depth=2, three_folds=False):
-        if three_folds:
-            indices = data.sample.SubsetIndicesCV(folds=3, stratified=data.sample.SubsetIndices.Stratified, randseed=42)(self.data_d)
-        else:
-            indices = data.sample.SubsetIndices2(p0=0.5, stratified=data.sample.SubsetIndices.Stratified, randseed=42)(self.data_d)
-
-        rv = []
-
-        for i in range(3 if three_folds else 1):
-            train = self.data_d.select(indices, 0)
-
-            min_instances = 5
-            rf_learner = ensemble.forest.RandomForestLearner(trees=trees*2, base_learner=TreeLearner(), name="RF: %d trees; max depth: None; min instances: %d" % (trees, min_instances))
-            rf_classifier = rf_learner(train)
-
-            remaining_folds = range(3)
-            remaining_folds.remove(i)
-
-            for j in range(2 if three_folds else 1):
-
-                test = self.data_d.select(indices, remaining_folds[j])
-
-                def get_features(cls, domain):
-                    #features = re.findall('{ [01] \d+ (\d+)', pickle.dumps(cls))
-                    #return [domain[i].name for i in map(int, features)]
-                    def tree_attr(node):
-                        if not node or node.branch_selector is None:
-                            return []
-
-                        size = [node.branch_selector.class_var.name]
-                        if node.branch_selector:
-                            for branch in node.branches:
-                                    size += tree_attr(branch)
-                        return size
-
-                    return tree_attr(cls.tree)
-
-                models = []
-                for c in rf_classifier.classifiers:
-                    probabilities = []
-                    instance_predictions = []
-                    instance_classes = []
-                    for ex in test if three_folds else train:
-                        ex = data.Instance(ex)
-                        instance_classes.append(ex.get_class().value)
-                        ex.setclass("?")
-                        cl, prob = c(ex, c.GetBoth)
-                        if cl.isSpecial():
-                            raise "Classifier %s returned unknown value" % c.name
-                        probabilities.append(list(prob))
-                        instance_predictions.append(cl.value)
-
-                    models.append(model.Model("RF",
-                                        c,
-                                        np.array(probabilities),
-                                        {val: k for k, val in enumerate(test.domain.class_var.values)},
-                                        get_features(c, test.domain),
-                                        np.array(instance_predictions),
-                                        np.array(instance_classes),
-                                        XAnchors=None,
-                                        YAnchors=None))
-
-                rv.append((models, rf_classifier, self.data_d.select(indices, remaining_folds[(j + 1) % 2]) if three_folds else test))
-
-        return rv[0] if len(rv) == 1 else rv
-
-
-    def _print_time(self, time_start, iter, numiter):
-        time_elapsed = time.time() - time_start
-        time_total = time_elapsed / iter * (numiter * (numiter-1) / 2.)
-        time_remainng = int(time_total - time_elapsed)
-        print iter, '/', numiter * (numiter - 1) / 2, '| remaining:', time_remainng / 60 / 60, ':', time_remainng / 60 % 60, ':', time_remainng % 60
-
-    def build_model_matrix(self, models, dist=distance_manhattan):
-        """Build a distance matrix of models given the distance measure."""
-
-        dim = len(models)
-        print "%d models to matrix -- %s" % (dim, dist.__name__)
-        smx = misc.SymMatrix(dim)
-        counter = 0
-        time_start = time.time()
-        for i in range(dim):
-            for j in range(i):
-                smx[i, j] = dist(models[i], models[j])
-
-            counter += i
-            if (i+1) % 1000 == 0:
-                self._print_time(time_start, counter, dim)
-
-        return smx
-
-    def build_model_data(self, models):
-        """Return an :obj:`Orange.data.Table` of model meta-data."""
-
-        table = get_models_table()
-        table.extend([model.get_instance(table.domain) for model in models])
-        return table

_modelmaps/widgets/OWModelEmbedder.py

-"""
-<name>Model Embedder</name>
-<description>Embeds a model widget</description>
-<contact>Miha Stajdohar (miha.stajdohar(@at@)gmail.com)</contact>
-<icon>icons/DistanceFile.png</icon>
-<priority>6530</priority>
-"""
-
-import sip
-
-import OWGUI
-import orngMisc
-
-from OWWidget import *
-from Orange import data, misc, distance, modelmaps
-
-import OWScatterPlot
-import OWRadviz
-import OWLinProj
-import OWPolyviz
-import OWClassificationTreeGraph
-import OWNomogram
-import OWMDS
-
-class OWModelEmbedder(OWWidget):
-    settingsList = []
-
-    def __init__(self, parent=None, signalManager=None, name='Model Embedder'):
-
-        OWWidget.__init__(self, parent, signalManager, name, noReport=True)
-
-        self.inputs = [("Data", data.Table, self.setData),
-                       ("Model", modelmaps.Model, self.setModel, Default)]
-
-        self.outputs = [("Selected Data", data.Table), ("Other Data", data.Table)]
-
-        self.ow = None
-        self.data = None
-        self.model = None
-
-        self.loadSettings()
-
-        self.widgets = {}
-
-    def setData(self, data):
-        self.data = data
-        self.showWidget()
-
-    def setModel(self, model):
-        self.model = model
-        self.showWidget()
-
-    def setWidget(self, widgetType):
-        if str(widgetType) in self.widgets:
-            self.ow = self.widgets[str(widgetType)]
-        else:
-            self.ow = widgetType(self)
-            self.widgets[str(widgetType)] = self.ow
-        return self.ow
-
-    def showWidget(self):
-        self.information()
-
-        if self.ow is not None:
-            self.ow.topWidgetPart.hide()
-            self.ow.setLayout(self.layout())
-        elif self.layout() is not None:
-            sip.delete(self.layout())
-
-        self.ow = None
-        if self.data is None:
-            self.information("No learning data given.")
-            return
-        if self.model is None: return
-
-        modelType = self.model.type.upper()
-        attr = self.model.attributes
-
-        projWidget = None
-        if modelType == "SCATTERPLOT" or modelType == "SCATTTERPLOT":
-            projWidget = self.setWidget(OWScatterPlot.OWScatterPlot)
-
-        if modelType == "RADVIZ":
-            projWidget = self.setWidget(OWRadviz.OWRadviz)
-
-        if modelType == "POLYVIZ":
-            projWidget = self.setWidget(OWPolyviz.OWPolyviz)
-
-        if projWidget is not None:
-            self.ow.setData(self.data)
-            self.ow.setShownAttributes(attr)
-            self.ow.handleNewSignals()
-
-        ################################
-        ### add new model types here ###
-        ################################
-
-        if modelType == "SPCA" or modelType == "LINPROJ":
-            self.setWidget(OWLinProj.OWLinProj)
-            self.ow.setData(self.data)
-            self.ow.setShownAttributes(attr)
-            self.ow.handleNewSignals()
-            xAnchors, yAnchors = self.model.XAnchors, self.model.YAnchors
-            self.ow.updateGraph(None, setAnchors=1, XAnchors=xAnchors, YAnchors=yAnchors)
-
-        if modelType == "TREE":
-            self.setWidget(OWClassificationTreeGraph.OWClassificationTreeGraph)
-            classifier = self.model.classifier
-            self.ow.ctree(classifier)
-
-        if modelType == "BAYES":
-            self.setWidget(OWNomogram.OWNomogram)
-            classifier = self.model.classifier
-            self.ow.classifier(classifier)
-
-        if modelType == "KNN":
-            #exclude = [att for att in self.data.domain if att.name not in attr + [self.data.domain.classVar.name]]
-            #data2 = orange.Preprocessor_ignore(self.data, attributes=exclude)
-            domain = data.Domain(attr + [self.data.domain.classVar.name], self.data.domain)
-            data2 = data.Table(domain, data)
-            dist = distance.Euclidean(data2)
-            smx = misc.SymMatrix(len(data2))
-            smx.setattr('items', data2)
-            pb = OWGUI.ProgressBar(self, 100)
-            milestones = orngMisc.progressBarMilestones(len(data2) * (len(data2) - 1) / 2, 100)
-            count = 0
-            for i in range(len(data2)):
-                for j in range(i + 1):
-                    smx[i, j] = dist(data2[i], data2[j])
-                    if count in milestones:
-                        pb.advance()
-                    count += 1
-            pb.finish()
-            self.setWidget(OWMDS.OWMDS)
-            self.ow.cmatrix(smx)
-
-        if self.ow is not None:
-            self.ow.send = self.send
-            if self.layout() is not None: sip.delete(self.layout())
-            self.setLayout(self.ow.layout())
-            self.ow.topWidgetPart.show()
-
-        self.update()
-
-
-if __name__ == "__main__":
-    appl = QApplication(sys.argv)
-    view = OWModelEmbedder()
-    view.show()
-    view.setWindowTitle("Model Embedder")
-    appl.exec_()

_modelmaps/widgets/OWModelFile.py

-"""
-<name>Model File</name>
-<description>Load a Model Map</description>
-<contact>Miha Stajdohar (miha.stajdohar(@at@)gmail.com)</contact>
-<icon>icons/DistanceFile.png</icon>
-<priority>6510</priority>
-"""
-import os.path
-import cPickle as pickle
-import bz2
-
-import OWGUI
-import orngMisc
-
-from OWWidget import *
-from Orange import data, misc
-
-class OWModelFile(OWWidget):
-    settingsList = ["files", "file_index"]
-
-    def __init__(self, parent=None, signalManager=None):
-        OWWidget.__init__(self, parent, signalManager, name='Model File', wantMainArea=0, resizingEnabled=1)
-
-        self.outputs = [("Distances", misc.SymMatrix),
-                        ("Model Meta-data", data.Table),
-                        ("Original Data", data.Table)]
-
-        #self.dataFileBox.setTitle("Model File")
-        self.files = []
-        self.file_index = 0
-
-        self.matrix = None
-        self.matrices = None
-        self.model_data = None
-        self.original_data = None
-        self.selected_matrix = None
-
-        self.loadSettings()
-
-        self.fileBox = OWGUI.widgetBox(self.controlArea, "Model File", addSpace=True)
-        hbox = OWGUI.widgetBox(self.fileBox, orientation=0)
-        self.filecombo = OWGUI.comboBox(hbox, self, "file_index", callback=self.loadFile)
-        self.filecombo.setMinimumWidth(250)
-        button = OWGUI.button(hbox, self, '...', callback=self.browseFile)
-        button.setIcon(self.style().standardIcon(QStyle.SP_DirOpenIcon))
-        button.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
-
-        self.propertiesBox = OWGUI.widgetBox(self.controlArea, "Properties", addSpace=True)
-        self.select_matrix_combo = OWGUI.comboBox(self.propertiesBox, self, "selected_matrix", label='Select matrix:', orientation='horizontal', callback=self.select_matrix)
-        self.select_matrix_combo.setEnabled(False)
-
-#        Moved to SymMatrixTransform widget
-#
-#        ribg = OWGUI.radioButtonsInBox(self.controlArea, self, "normalizeMethod", [], "Normalize method", callback = self.setNormalizeMode)
-#        OWGUI.appendRadioButton(ribg, self, "normalizeMethod", "None", callback = self.setNormalizeMode)
-#        OWGUI.appendRadioButton(ribg, self, "normalizeMethod", "To interval [0,1]", callback = self.setNormalizeMode)
-#        OWGUI.appendRadioButton(ribg, self, "normalizeMethod", "Sigmoid function: 1 / (1 + e^x)", callback = self.setNormalizeMode)
-#        
-#        ribg = OWGUI.radioButtonsInBox(self.controlArea, self, "invertMethod", [], "Invert method", callback = self.setInvertMode)
-#        OWGUI.appendRadioButton(ribg, self, "invertMethod", "None", callback = self.setInvertMode)
-#        OWGUI.appendRadioButton(ribg, self, "invertMethod", "-X", callback = self.setInvertMode)
-#        OWGUI.appendRadioButton(ribg, self, "invertMethod", "1 - X", callback = self.setInvertMode)
-#        OWGUI.appendRadioButton(ribg, self, "invertMethod", "Max - X", callback = self.setInvertMode)
-#        OWGUI.appendRadioButton(ribg, self, "invertMethod", "1 / X", callback = self.setInvertMode)
-
-        OWGUI.rubber(self.controlArea)
-
-        self.adjustSize()
-
-        for i in range(len(self.files) - 1, -1, -1):
-            if not (os.path.exists(self.files[i]) and os.path.isfile(self.files[i])):
-                del self.files[i]
-
-        if self.files:
-            self.loadFile()
-
-    def select_matrix(self):
-        self.matrix = self.matrices[str(self.select_matrix_combo.currentText())]
-        self.relabel()
-
-    def browseFile(self):
-        if self.files:
-            lastPath = os.path.split(self.files[0])[0]
-        else:
-            lastPath = "."
-        fn = unicode(QFileDialog.getOpenFileName(self, "Open Model Map File",
-                                             lastPath, "Model Map (*.bz2)"))
-        fn = os.path.abspath(fn)
-        if fn in self.files: # if already in list, remove it
-            self.files.remove(fn)
-        self.files.insert(0, fn)
-        self.file_index = 0
-        self.loadFile()
-
-    def loadFile(self):
-        if self.file_index:
-            fn = self.files[self.file_index]
-            self.files.remove(fn)
-            self.files.insert(0, fn)
-            self.file_index = 0
-        else:
-            fn = self.files[0]
-
-        self.filecombo.clear()
-        self.select_matrix_combo.clear()
-        self.select_matrix_combo.setEnabled(False)
-
-        for file in self.files:
-            self.filecombo.addItem(os.path.split(file)[1])
-        #self.filecombo.updateGeometry()
-
-        self.matrix = None
-        self.matrices = None
-        self.model_data = None
-        self.original_data = None
-        pb = OWGUI.ProgressBar(self, 100)
-        pb.advance()
-        self.error()
-        try:
-            matrix, self.model_data, self.original_data = pickle.load(bz2.BZ2File('%s' % fn, "r"))
-            if type(matrix) == type({}):
-                for name in matrix.iterkeys():
-                    self.select_matrix_combo.addItem(name)
-
-                self.matrices = matrix
-                self.matrix = matrix[str(self.select_matrix_combo.currentText())]
-                self.select_matrix_combo.setEnabled(True)
-
-            elif type(matrix) == type(misc.SymMatrix(1)):
-                self.matrix = matrix
-                self.select_matrix_combo.addItem("Single matrix found")
-            else:
-                try:
-                    self.matrix = misc.SymMatrix(matrix)
-                    self.select_matrix_combo.addItem("Single matrix found")
-                except TypeError:
-                    self.matrix = misc.SymMatrix(matrix + matrix.T)
-                    self.select_matrix_combo.addItem("Single matrix found")
-
-        except Exception, ex:
-            self.error("Error while reading the file: '%s'" % str(ex))
-            return
-
-        pb.finish()
-        self.relabel()
-
-    def relabel(self):
-        self.error()
-        if self.matrix is not None:
-            if self.model_data is not None and self.matrix.dim == len(self.model_data):
-                self.matrix.setattr("items", self.model_data)
-            else:
-                self.error("The number of model doesn't match the matrix dimension. Invalid Model Map file.")
-
-            if self.original_data is not None:
-                self.matrix.setattr("original_data", self.original_data)
-
-            self.send("Distances", self.matrix)
-
-        if self.model_data is not None:
-            self.send("Model Meta-data", self.model_data)
-
-        if self.original_data is not None:
-            self.send("Original Data", self.original_data)
-
-if __name__ == "__main__":
-    a = QApplication(sys.argv)
-    ow = OWModelFile()
-    ow.show()
-    a.exec_()
-    ow.saveSettings()

_modelmaps/widgets/OWModelMap.py

-"""
-<name>Model Map</name>
-<description>Visualization and analysis of prediction models</description>
-<icon>icons/Network.png</icon>
-<contact>Miha Stajdohar (miha.stajdohar(@at@)gmail.com)</contact> 
-<priority>6520</priority>
-"""
-
-import os.path
-
-from Orange import classification, misc, modelmaps, network, utils
-from Orange.network.community import CommunityDetection
-from OWNxCanvasQt import OWNxCanvas
-
-from orngScaleLinProjData import *
-from OWNxExplorer import *
-from OWkNNOptimization import OWVizRank
-from OWNxHist import *
-from OWDistributions import OWDistributionGraph
-
-from PyQt4 import QtCore
-
-dir = utils.environ.widget_install_dir
-
-ICON_PATHS = [("TREE", "Classify/icons/ClassificationTree"),
-              ("SCATTERPLOT", "Visualize/icons/ScatterPlot"),
-              ("SCATTTERPLOT", "Visualize/icons/ScatterPlot"),
-              ("LINEAR_PROJECTION", "Visualize/icons/LinearProjection"),
-              ("SPCA", "Visualize/icons/LinearProjection"),
-              ("RADVIZ", "Visualize/icons/Radviz"),
-              ("POLYVIZ", "Visualize/icons/Polyviz"),
-              ("NaiveLearner", "Classify/icons/NaiveBayes"),
-              ("BAYES", "Classify/icons/NaiveBayes"),
-              ("kNNLearner", "Classify/icons/kNearestNeighbours"),
-              ("KNN", "Classify/icons/kNearestNeighbours"),
-              ("SVM", "Classify/icons/BasicSVM"),
-              ("RF", "Classify/icons/RandomForest")]
-
-ICON_SIZES = ["16", "32", "40", "48", "60"]
-
-MODEL_IMAGES = {"MISSING": os.path.join(dir, "icons/Unknown.png")}
-
-PIXMAP_CACHE = {}
-
-for size in ICON_SIZES:
-    for model, path in ICON_PATHS:
-        MODEL_IMAGES[model + size] = os.path.join(dir, "%s_%s.png" % (path, size))
-
-class ModelItem(orangeqt.ModelItem):
-    def __init__(self, index, x=None, y=None, parent=None):
-        orangeqt.ModelItem.__init__(self, index, OWPoint.Ellipse, Qt.blue, 5, parent)
-        if x is not None:
-            self.set_x(x)
-        if y is not None:
-            self.set_y(y)
-
-    def paint(self, painter, option, widget):
-        orangeqt.ModelItem.paint(self, painter, option, widget)
-
-#        lbl = self.text()
-#
-#        if lbl == "":
-#            return
-#
-#        metrics = painter.fontMetrics()
-#        th = metrics.height()
-#
-#        pen = painter.pen()
-#        pen.setColor(QtCore.Qt.black)
-#        painter.setPen(pen)
-#
-#        for i, l in enumerate(lbl.split(", ")):
-#            tw = metrics.width(l)
-#            r = QtCore.QRectF(-tw / 2., self.size() / 2. + 5 + i * th, tw, th);
-#            painter.drawText(r, QtCore.Qt.AlignCenter, l);
-
-class ModelCurve(NetworkCurve):
-    def __init__(self, parent=None, pen=QPen(Qt.black), xData=None, yData=None):
-        NetworkCurve.__init__(self, parent, pen=QPen(Qt.black), xData=None, yData=None)
-
-class OWModelMapCanvas(OWNxCanvas):
-
-    def __init__(self, master, parent=None, name="None"):
-        OWNxCanvas.__init__(self, master, parent, name)
-        self.networkCurve = ModelCurve()
-        self.NodeItem = ModelItem
-
-        self.selectionNeighbours = 1
-        self.tooltipNeighbours = 1
-        self.plotAccuracy = None
-        self.vizAttributes = None
-        self.radius = 100
-
-    def mouseMoveEvent(self, event):
-        OWNxCanvas.mouseMoveEvent(self, event)
-
-        if self.graph is None or self.layout is None:
-            return
-
-        if self.plotAccuracy or self.vizAttributes:
-            cursor = self.mapToScene(event.pos())
-            nearest = self.nearest_point(cursor)
-
-            if nearest is not None:
-                toMark = set(self.get_neighbors_upto(nearest.index(), self.tooltipNeighbours))
-                toMark = list(toMark)
-                self.networkCurve.clear_node_marks()
-                self.networkCurve.set_node_marks(dict((i, True) for i in toMark))
-                if self.plotAccuracy:
-                    self.plotAccuracy(toMark)
-                if self.vizAttributes:
-                    self.vizAttributes(toMark)
-            else:
-                nodes = self.networkCurve.nodes().items()
-                nodes = [i for i, n in nodes if (n.pos() - cursor).manhattanLength() < self.radius]
-
-                self.networkCurve.clear_node_marks()
-                self.networkCurve.set_node_marks(dict((i, True) for i in nodes))
-
-                if self.plotAccuracy:
-                    self.plotAccuracy(nodes)
-                if self.vizAttributes:
-                    self.vizAttributes(nodes)
-
-    def set_tooltip_attributes(self, attributes):
-        if self.graph is None or self.items is None or \
-           not isinstance(self.items, data.Table):
-            return
-
-        attributes = ["Cluster CA", "label", "P", "attributes"]
-
-#        lbl  = "%s\n" % self.graph.items()[vertex.index]["label"].value
-#        lbl += "CA: %.4g\n" % self.graph.items()[vertex.index]["CA"].value
-#        #lbl += "AUC: %.4g\n" % self.graph.items()[vertex.index]["AUC"].value
-#        #lbl += "CA best: %s\n" % clusterCA 
-#        lbl += "Attributes: %d\n" % len(self.graph.items()[vertex.index]["attributes"].value.split(", "))
-#        lbl += ", ".join(sorted(self.graph.items()[vertex.index]["attributes"].value.split(", ")))
-
-        tooltip_attributes = [self.items.domain[att] for att in \
-                                 attributes if att in self.items.domain]
-        self.networkCurve.set_node_tooltips(dict((node, ', '.join(str( \
-                   self.items[node][att]) for att in tooltip_attributes)) \
-                                                        for node in self.graph))
-
-    def loadIcons(self):
-        items = self.items
-        maxsize = str(max(map(int, ICON_SIZES)))
-        minsize = min(map(int, ICON_SIZES))
-        for v in self.networkCurve.nodes().itervalues():
-            size = str(minsize) if v.size() <= minsize else maxsize
-
-            for i in range(len(ICON_SIZES) - 1):
-                if int(ICON_SIZES[i]) < v.size() <= int(ICON_SIZES[i + 1]):
-                    size = ICON_SIZES[i]
-            imageKey = items[v.index()]['type'].value + size
-            if imageKey not in MODEL_IMAGES:
-                imageKey = "MISSING"
-
-            fn = MODEL_IMAGES[imageKey]
-            if not fn in PIXMAP_CACHE:
-                PIXMAP_CACHE[fn] = QPixmap(fn)
-            v.set_image(PIXMAP_CACHE[fn])
-
-    def set_representatives(self, node_keys):
-        nodes = self.networkCurve.nodes()
-        map(ModelItem.set_representative, [nodes[i] for i in node_keys])
-
-
-class ModelClusterView(network.NxView):
-    """A network view expanding and contracting nodes that represent model 
-    communities. 
-    
-    """
-
-    def __init__(self, community_detection):
-        network.NxView.__init__(self)
-
-        self._community_detection = community_detection
-        self._representatives = None
-        self._expanded_nodes = set()
-        self._representatives_graph = None
-
-    def __del__(self):
-        if self._nx_explorer is not None:
-            QObject.disconnect(self._nx_explorer.networkCanvas, SIGNAL('point_rightclicked(Point*)'), self.hierarchical_expand)
-
-    def set_nx_explorer(self, _nx_explorer):
-        network.NxView.set_nx_explorer(self, _nx_explorer)
-
-        if self._nx_explorer is not None:
-            QObject.connect(self._nx_explorer.networkCanvas, SIGNAL('point_rightclicked(Point*)'), self.hierarchical_expand)
-
-    def update_network(self):
-        if self._nx_explorer is not None and self._network is not None:
-            subnet = self._network
-            self._nx_explorer.change_graph(subnet)
-
-    def init_network(self, graph):
-        self._network = graph
-
-        if graph is None or self._community_detection is None:
-            return None
-
-        return self.hierarchical_subgraph()
-
-    def set_representatives(self):
-        if self._nx_explorer is None or self._representatives is None:
-            return
-
-        self._nx_explorer.networkCanvas.set_representatives(key for key, val in self._representatives.iteritems() if len(val) > 1)
-
-    def hierarchical_subgraph(self):
-        if self._network is None:
-            return
-
-        labels = self._community_detection(self._network)
-        clusters = {}
-        for key, val in labels.iteritems():
-            clusters[val] = clusters.get(val, []) + [key]
-
-        items = self._network.items()
-        self._representatives = {max(val, key=lambda x, items=items: items[x]["P"].value): val for val in clusters.itervalues()}
-        #for key, val in clusters.items():
-        #    representatives.append(max(val, key=lambda x, items=items: items[x]["CA"].value))
-        # find neighbors for all representatives
-        subgraph = network.nx.Graph.subgraph(self._network, self._representatives.iterkeys())
-
-        # add meta-edges between representatives        
-        #repr_neighbors = {key: set(itertools.chain.from_iterable(self._network.adj[n].keys() for n in cluster)) for key, cluster in self._representatives.iteritems()}
-        #repr_keys = repr_neighbors.keys()
-        #edges = list(itertools.chain.from_iterable([(repr_keys[i], repr_keys[j]) for j in range(i) if repr_keys[i] in repr_neighbors[repr_keys[j]]] for i in range(len(repr_keys))))
-        #subgraph.add_edges_from(edges)
-        #self._representatives_graph = subgraph
-
-        return subgraph
-
-    def hierarchical_expand(self, node):
-
-        if not node.is_representative():
-            return
-
-        nodes = set(self._representatives[node.index()])
-        nodes.remove(node.index())
-        graph_nodes = set(self._nx_explorer.graph.nodes_iter())
-        if len(nodes & graph_nodes) > 0: # contract nodes
-            nodes = graph_nodes - nodes
-            self._expanded_nodes.remove(node)
-        else: # expand nodes
-            nodes = graph_nodes | nodes
-            self._expanded_nodes.add(node)
-
-        self.select_expanded()
-        qApp.processEvents()
-
-        subgraph = network.nx.Graph.subgraph(self._network, nodes)
-        self._nx_explorer.change_graph(subgraph)
-        self.set_representatives()
-
-    def select_expanded(self):
-        self._nx_explorer.networkCanvas.unmark_all_points()
-        map(lambda n: ModelItem.set_marked(n, True), self._expanded_nodes)
-
-class OWModelMap(OWNxExplorer, OWNxHist):
-
-    settingsList = ["autoSendSelection", "spinExplicit", "spinPercentage",
-        "maxLinkSize", "minVertexSize", "maxVertexSize", "networkCanvas.animate_plot",
-        "networkCanvas.animate_points", "networkCanvas.antialias_plot",
-        "networkCanvas.antialias_points", "networkCanvas.antialias_lines",
-        "networkCanvas.auto_adjust_performance", "invertSize", "optMethod",
-        "lastVertexSizeColumn", "lastColorColumn", "networkCanvas.show_indices", "networkCanvas.show_weights",
-        "lastNameComponentAttribute", "lastLabelColumns", "lastTooltipColumns",
-        "showWeights", "showEdgeLabels", "colorSettings",
-        "selectedSchemaIndex", "edgeColorSettings", "selectedEdgeSchemaIndex",
-        "showMissingValues", "fontSize", "mdsTorgerson", "mdsAvgLinkage",
-        "mdsSteps", "mdsRefresh", "mdsStressDelta", "organism", "showTextMiningInfo",
-        "toolbarSelection", "minComponentEdgeWidth", "maxComponentEdgeWidth",
-        "mdsFromCurrentPos", "labelsOnMarkedOnly", "tabIndex",
-        "networkCanvas.trim_label_words", "opt_from_curr", "networkCanvas.explore_distances",
-        "networkCanvas.show_component_distances", "fontWeight", "networkCanvas.state",
-        "networkCanvas.selection_behavior", "kNN", "spinLowerThreshold",
-        "spinUpperThreshold"]
-
-    def __init__(self, parent=None, signalManager=None, name="Model Map"):
-        OWNxExplorer.__init__(self, parent, signalManager, name,
-                               NetworkCanvas=OWModelMapCanvas)
-
-        OWNxHist.__init__(self, parent)
-
-        self.inputs = [("Community Detection", CommunityDetection, self.set_community),
-                       ("Distances", misc.SymMatrix, self.set_matrix, Default),
-                       ("Model Subset", data.Table, self.set_models_subset)]
-
-        self.outputs = [("Model", modelmaps.Model),
-                        ("Classifier", classification.Classifier),
-                        ("Selected Models", data.Table)]
-
-        self.vertexSize = 32
-        self.autoSendSelection = False
-        self.minVertexSize = 16
-        self.maxVertexSize = 16
-        self.vizAccurancy = False
-        self.vizAttributes = False
-        self.radius = 100
-        self.attrIntersection = []
-        self.attrIntersectionList = []
-        self.attrDifference = []
-        self.attrDifferenceList = []
-        self.kNN = 1
-
-        self.colorSettings = self.edgeColorSettings
-
-        self.loadSettings()
-
-        self.matrixTab = OWGUI.widgetBox(self.tabs, addToLayout=0, margin=4)
-        self.modelTab = OWGUI.widgetBox(self.tabs, addToLayout=0, margin=4)
-        self.tabs.insertTab(0, self.matrixTab, "Matrix")
-        self.tabs.insertTab(1, self.modelTab, "Model Info")
-        self.tabs.setCurrentIndex(self.tabIndex)
-
-        self.networkCanvas.appendToSelection = 0
-        self.networkCanvas.minVertexSize = self.minVertexSize
-        self.networkCanvas.maxVertexSize = self.maxVertexSize
-        self.networkCanvas.invertEdgeSize = 1
-
-        # MARTIX CONTROLS
-        self.addHistogramControls(self.matrixTab)
-        boxHistogram = OWGUI.widgetBox(self.matrixTab, box="Distance histogram")
-        self.histogram = OWHist(self, boxHistogram)
-        boxHistogram.layout().addWidget(self.histogram)
-
-        # VISUALIZATION CONTROLS
-        vizPredAcc = OWGUI.widgetBox(self.modelTab, "Prediction Accuracy", orientation="vertical")
-        OWGUI.checkBox(vizPredAcc, self, "vizAccurancy", "Visualize prediction accurancy", callback=self.visualize_info)
-        OWGUI.spin(vizPredAcc, self, "radius", 10, 1000, 1, label="Radius: ", callback=self.visualize_info)
-        self.predGraph = OWDistributionGraph(self, vizPredAcc)
-        self.predGraph.setMaximumSize(QSize(300, 300))
-        self.predGraph.setYRlabels(None)
-        self.predGraph.setAxisScale(QwtPlot.xBottom, 0.0, 1.0, 0.1)
-        self.predGraph.numberOfBars = 2
-        self.predGraph.barSize = 200 / (self.predGraph.numberOfBars + 1)
-        vizPredAcc.layout().addWidget(self.predGraph)
-
-        vizPredAcc = OWGUI.widgetBox(self.modelTab, "Attribute lists", orientation="vertical")
-        OWGUI.checkBox(vizPredAcc, self, "vizAttributes", "Display attribute lists", callback=self.visualize_info)
-
-        self.attrGraph = OWDistributionGraph(self, vizPredAcc)
-        self.attrGraph.setMaximumSize(QSize(300, 300))
-        self.attrGraph.setYRlabels(None)
-        self.attrGraph.setAxisScale(QwtPlot.xBottom, 0.0, 1.0, 0.1)
-        self.attrGraph.numberOfBars = 2
-        self.attrGraph.barSize = 200 / (self.attrGraph.numberOfBars + 1)
-        vizPredAcc.layout().addWidget(self.attrGraph)
-
-
-        #self.attrIntersectionBox = OWGUI.listBox(vizPredAcc, self, "attrIntersection", "attrIntersectionList", "Attribute intersection", selectionMode=QListWidget.NoSelection)
-        #self.attrDifferenceBox = OWGUI.listBox(vizPredAcc, self, "attrDifference", "attrDifferenceList", "Attribute difference", selectionMode=QListWidget.NoSelection)
-
-        self.attBox.hide()
-        self.visualize_info()
-
-        QObject.connect(self.networkCanvas, SIGNAL('selection_changed()'), self.node_selection_changed)
-
-        self.matrixTab.layout().addStretch(1)
-        self.modelTab.layout().addStretch(1)
-
-    def set_community(self, community_detection):
-        if community_detection is None:
-            self.set_network_view(None)
-        else:
-            mc_view = ModelClusterView(community_detection)
-            self.set_network_view(mc_view)
-            mc_view.set_representatives()
-
-    def plotAccuracy(self, vertices=None):
-        self.predGraph.tips.removeAll()
-        self.predGraph.clear()
-        #self.predGraph.setAxisScale(QwtPlot.yRight, 0.0, 1.0, 0.2)
-        self.predGraph.setAxisScale(QwtPlot.xBottom, 0.0, 1.0, 0.2)
-
-        if not vertices:
-            self.predGraph.replot()
-            return
-
-        self.predGraph.setAxisScale(QwtPlot.yLeft, -0.5, len(self.matrix.originalData.domain.classVar.values) - 0.5, 1)
-
-        scores = [[float(ca) for ca in ex["CA by class"].value.split(", ")] for ex in self.graph.items().getitems(vertices)]
-        scores = [sum(score) / len(score) for score in zip(*scores)]
-
-        currentBarsHeight = [0] * len(scores)
-        for cn, score in enumerate(scores):
-            subBarHeight = score
-            ckey = PolygonCurve(pen=QPen(self.predGraph.discPalette[cn]), brush=QBrush(self.predGraph.discPalette[cn]))
-            ckey.attach(self.predGraph)
-            ckey.setRenderHint(QwtPlotItem.RenderAntialiased, self.predGraph.useAntialiasing)
-
-            tmpx = cn - (self.predGraph.barSize / 2.0) / 100.0
-            tmpx2 = cn + (self.predGraph.barSize / 2.0) / 100.0
-            ckey.setData([currentBarsHeight[cn], currentBarsHeight[cn] + subBarHeight, currentBarsHeight[cn] + subBarHeight, currentBarsHeight[cn]], [tmpx, tmpx, tmpx2, tmpx2])
-            currentBarsHeight[cn] += subBarHeight
-
-            self.predGraph.addMarker("%.4f" % score, 0, cn, Qt.AlignRight | Qt.AlignBottom)
-
-
-        self.predGraph.replot()
-
-    def display_attribute_info(self, vertices=None):
-        self.attrIntersectionList = []
-        self.attrDifferenceList = []
-
-        if vertices is None or len(vertices) == 0:
-            return
-
-        attrList = [self.graph.items()[v]["attributes"].value.split(", ") for v in vertices]
-
-        #attrIntersection = set(attrList[0])
-        #attrUnion = set()
-        #for attrs in attrList:
-        #    attrIntersection = attrIntersection.intersection(attrs)
-        #    attrUnion = attrUnion.union(attrs)
-
-        #self.attrIntersectionList = attrIntersection
-        #self.attrDifferenceList = attrUnion.difference(attrIntersection)
-
-
-
-        self.attrGraph.tips.removeAll()
-        self.attrGraph.clear()
-        #self.predGraph.setAxisScale(QwtPlot.yRight, 0.0, 1.0, 0.2)
-        self.attrGraph.setAxisScale(QwtPlot.xBottom, 0.0, 1.0, 0.2)
-
-        if not vertices:
-            self.attrGraph.replot()
-            return
-
-        labels = [attr.name for attr in self.matrix.originalData.domain.attributes]
-        attrList = [{label:len([a for a in attrs if a == label]) for label in labels} for attrs in attrList]
-
-
-        self.attrGraph.setAxisScale(QwtPlot.yLeft, -0.5, len(labels) - 0.5, 1)
-
-        scores = [sum([attributes[label] for attributes in attrList]) for label in labels]
-        #scores = [sum(score) / len(score) for score in zip(*scores)]
-
-        self.attrGraph.setAxisScale(QwtPlot.xBottom, 0.0, max(scores), 1)
-
-        currentBarsHeight = [0] * len(scores)
-        for cn, score in enumerate(scores):
-            subBarHeight = score
-            ckey = PolygonCurve(pen=QPen(self.attrGraph.discPalette[cn]), brush=QBrush(self.attrGraph.discPalette[cn]))
-            ckey.attach(self.attrGraph)
-            ckey.setRenderHint(QwtPlotItem.RenderAntialiased, self.attrGraph.useAntialiasing)
-
-            tmpx = cn - (self.attrGraph.barSize / 2.0) / 100.0
-            tmpx2 = cn + (self.attrGraph.barSize / 2.0) / 100.0
-            ckey.setData([currentBarsHeight[cn], currentBarsHeight[cn] + subBarHeight, currentBarsHeight[cn] + subBarHeight, currentBarsHeight[cn]], [tmpx, tmpx, tmpx2, tmpx2])
-            currentBarsHeight[cn] += subBarHeight
-
-            self.attrGraph.addMarker("%d" % score, 0, cn, Qt.AlignRight | Qt.AlignBottom)
-
-
-        self.attrGraph.replot()
-
-    def visualize_info(self):
-        self.networkCanvas.radius = self.radius
-
-        if self.vizAccurancy:
-            self.networkCanvas.plotAccuracy = self.plotAccuracy
-        else:
-            self.networkCanvas.plotAccuracy = None
-            self.plotAccuracy(None)
-
-        if self.vizAttributes:
-            self.networkCanvas.vizAttributes = self.display_attribute_info
-        else:
-            self.networkCanvas.vizAttributes = None
-            self.display_attribute_info(None)
-
-    def set_models_subset(self, subsetData):
-        self.info()
-
-        if "uuid" not in subsetData.domain:
-            self.info("Invalid subset data. Data domain must contain 'uuid' attribute.")
-            return
-
-        uuids = set([ex["uuid"].value for ex in subsetData])
-        for v in self.vertices:
-            v.highlight = 1 if v.uuid in uuids else 0
-
-    def set_matrix(self, matrix):
-        self.warning()
-
-        if matrix is None:
-            OWNxHist.setMatrix(self, None)
-            return
-
-        if not hasattr(matrix, "items") or not hasattr(matrix, "original_data"):
-            self.warning("Data matrix does not have required data for items and original_data.")
-            return
-
-        requiredAttrs = set(["CA", "AUC", "attributes", "uuid"])
-        attrs = [attr.name for attr in matrix.items.domain]
-        if len(requiredAttrs.intersection(attrs)) != len(requiredAttrs):
-            self.warning("Items Orange.data.Table does not contain required attributes: %s." % ", ".join(requiredAttrs))
-            return
-
-        for ex in matrix.items:
-            ex["attributes"] = ", ".join(sorted(ex["attributes"].value.split(", ")))
-
-        OWNxHist.setMatrix(self, matrix)
-
-    def set_node_sizes(self):
-        OWNxExplorer.set_node_sizes(self)
-        self.networkCanvas.loadIcons()
-        self.networkCanvas.replot()
-
-    def set_node_styles(self):
-        #for v in self.networkCanvas.networkCurve.nodes().itervalues():
-        #    #auc = self.graph.items()[v.index()]
-        #    v.style = 1 #auc
-        pass
-
-    def node_selection_changed(self):
-        self.warning()
-
-        graph = self.graph_base
-
-        if graph is None or graph.items() is None or self.graph_matrix is None:
-            self.send("Model", None)
-            self.send("Selected Models", None)
-            return
-
-        if graph.number_of_nodes() != self.graph_matrix.dim:
-            self.warning('Network items and matrix results not of equal length.')
-            self.send("Model", None)
-            self.send("Selected Models", None)
-            return
-
-        selection = self.networkCanvas.selected_nodes()
-
-        if len(selection) == 1:
-            model = graph.items()[selection[0]]['model'].value
-            self.send('Model', model)
-            self.send('Selected Models', graph.items().getitems(selection))
-        elif len(selection) > 1:
-            self.send('Model', None)
-            self.send('Selected Models', graph.items().getitems(selection))
-        else:
-            self.send('Model', None)
-            self.send('Selected Models', None)
-
-        if self._network_view:
-            self._network_view.select_expanded()
-
-    def sendSignals(self):
-        if self.graph is None or self.graph_matrix is None:
-            self.set_graph_none()
-            return
-
-        self.set_graph(self.graph, ModelCurve)
-
-        if self._network_view:
-            self._network_view.set_representatives()
-
-        self.set_items_distance_matrix(self.graph_matrix)
-        #self.hierarchical_view()
-        # TODO clickedAttLstBox -> setLabelText(["attributes"]
-
-        for node in self.networkCanvas.networkCurve.nodes().itervalues():
-            node.uuid = self.graph_base.items()[node.index()]["uuid"].value
-
-        self.set_node_sizes()
-        self.set_node_styles()
-        self.set_node_colors()
-
-        #self.networkCanvas.set_node_labels(["attributes"])
-
-        labels = self.matrix.originalData.domain.classVar.values.native()
-        self.predGraph.numberOfBars = len(labels)
-        self.predGraph.barSize = 200 / (self.predGraph.numberOfBars + 1)
-        self.predGraph.setYLlabels(labels)
-        self.predGraph.setAxisScale(QwtPlot.xBottom, 0.0, 1.0, 0.2)
-        self.predGraph.setAxisScale(QwtPlot.yLeft, -0.5, len(labels) - 0.5, 1)
-
-        self.predGraph.enableYRaxis(0)
-        self.predGraph.setYRaxisTitle("")
-        self.predGraph.setXaxisTitle("CA")
-        self.predGraph.setShowXaxisTitle(True)
-        self.predGraph.replot()
-
-        labels = [attr.name for attr in self.matrix.originalData.domain.attributes]
-        self.attrGraph.numberOfBars = len(labels)
-        self.attrGraph.barSize = 200 / (self.attrGraph.numberOfBars + 1)
-        self.attrGraph.setYLlabels(labels)
-        self.attrGraph.setAxisScale(QwtPlot.xBottom, 0.0, 1.0, 0.2)
-        self.attrGraph.setAxisScale(QwtPlot.yLeft, -0.5, len(labels) - 0.5, 1)
-
-        self.attrGraph.enableYRaxis(0)
-        self.attrGraph.setYRaxisTitle("")
-        self.attrGraph.setXaxisTitle("models")
-        self.attrGraph.setShowXaxisTitle(True)
-        self.attrGraph.replot()
-
-        self.visualize_info()
-
-if __name__ == "__main__":
-    import OWModelFile
-    import pickle
-    modelName = 'zoo-168'
-    root = 'c:\\Users\\miha\\Projects\\res\\metamining\\'
-
-    appl = QApplication(sys.argv)
-    ow = OWModelMap()
-    ow.show()
-    mroot = '%snew\\' % root
-    matrix, labels, data = OWModelFile.readMatrix('%s%s.npy' % (mroot, modelName))
-    if os.path.exists('%s%s.tab' % (mroot, modelName)):
-        matrix.items = data.Table('%s%s.tab' % (mroot, modelName))
-    else:
-        print 'ExampleTable %s not found!\n' % ('%s%s.tab' % (mroot, modelName))
-    if os.path.exists('%s%s.res' % (mroot, modelName)):
-        matrix.results = pickle.load(open('%s%s.res' % \
-                                               (mroot, modelName), 'rb'))
-    else:
-        print 'Results pickle %s not found!\n' % \
-              ('%s%s.res' % (mroot, modelName))
-
-    matrix.originalData = data.Table('%stab\\zoo.tab' % root)
-    ow.set_matrix(matrix)
-    appl.exec_()
-
Add a comment to this file

_modelmaps/widgets/__init__.py

Empty file removed.

Add a comment to this file

_modelmaps/widgets/icons/DistanceFile_16.png

Removed
Old image
Add a comment to this file

_modelmaps/widgets/icons/DistanceFile_32.png

Removed
Old image
Add a comment to this file

_modelmaps/widgets/icons/DistanceFile_40.png

Removed
Old image
Add a comment to this file

_modelmaps/widgets/icons/DistanceFile_48.png

Removed
Old image
Add a comment to this file

_modelmaps/widgets/icons/DistanceFile_60.png

Removed
Old image
Add a comment to this file

_modelmaps/widgets/icons/Network_16.png

Removed
Old image
Add a comment to this file

_modelmaps/widgets/icons/Network_32.png

Removed
Old image
Add a comment to this file

_modelmaps/widgets/icons/Network_40.png

Removed
Old image
Add a comment to this file

_modelmaps/widgets/icons/Network_48.png

Removed
Old image
Add a comment to this file

_modelmaps/widgets/icons/Network_60.png

Removed
Old image
Add a comment to this file

_modelmaps/widgets/icons/background_16.png

Removed
Old image
Add a comment to this file

_modelmaps/widgets/icons/background_32.png

Removed
Old image
Add a comment to this file

_modelmaps/widgets/icons/background_40.png

Removed
Old image
Add a comment to this file

_modelmaps/widgets/icons/background_48.png

Removed
Old image
Add a comment to this file

_modelmaps/widgets/icons/background_60.png

Removed
Old image
 # add these directories to sys.path here. If the directory is relative to the
 # documentation root, use os.path.abspath to make it absolute, like shown here.
 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
-import _modelmaps
-sys.modules["Orange.modelmaps"] = _modelmaps
+import orangecontrib.modelmaps
+sys.modules["Orange.modelmaps"] = orangecontrib.modelmaps
 
 # -- General configuration -----------------------------------------------------
 

examples/ensemble/build_rf.py

 
 import os.path, sys
 import numpy as np
-import _modelmaps as mm
+import orangecontrib.modelmaps as mm
 #import cPickle as pickle
 
 from Orange import data, utils

examples/ensemble/mm_forest.py

 
 from Orange import clustering, distance, evaluation, utils
 
-import _modelmaps as mm
+import orangecontrib.modelmaps as mm
 
 ROOT = "/home/miha/work/res/modelmaps"
 ROOT = "C:\\Users\\Miha\\work\\res\\modelmaps"

examples/ensemble/play_with_rf.py

 from Orange import clustering, data, distance, ensemble, evaluation, network, utils
 from Orange.classification.tree import SimpleTreeLearner
 
-import _modelmaps as mm
+import orangecontrib.modelmaps as mm
 
 ROOT = "/home/miha/work/res/modelmaps"
 #ROOT = "C:\\Users\\Miha\\work\\res\\modelmaps"

examples/projections/distance_metric_comparisson.py

 import os, os.path, sys
 import scipy
 import numpy as np
-import _modelmaps as mm
+import orangecontrib.modelmaps as mm
 
 from time import time
 from Orange.orng import orngVizRank as vr

examples/projections/entropy_vr_mm.py

 
 import os.path, sys, time, itertools
 import numpy as np
-import _modelmaps as mm
+import orangecontrib.modelmaps as mm
 import cPickle as pickle
 
 import scatterplot

examples/projections/projections.py

 import os.path
-import _modelmaps as mm
+import orangecontrib.modelmaps as mm
 from time import time
 from Orange.orng import orngVizRank as vr
 

examples/projections/radviz.py

 
 import matplotlib.pyplot as plt
 
-import _modelmaps as mm
+import orangecontrib.modelmaps as mm
 
 from itertools import groupby
 from operator import itemgetter

examples/projections/scatterplot.py

 
 import matplotlib.pyplot as plt
 
-import _modelmaps as mm
+import orangecontrib.modelmaps as mm
 
 from itertools import groupby
 from operator import itemgetter

orangecontrib/__init__.py

+# namespace declaration.
+__import__("pkg_resources").declare_namespace(__name__)

orangecontrib/modelmaps/__init__.py

+"""
+Examples
+========
+
+No examples are implemented yet. Write to the author for more information.
+
+"""
+
+import math
+import os.path
+import pickle
+import random
+import time
+
+import numpy as np
+
+#from orngScaleData import getVariableValuesSorted
+#from OWDistanceFile import readMatrix
+
+from Orange import data, feature
+
+from model import *
+from modelmap import *
+
+#ROOT = "/home/miha/work/res/metamining/"
+#OUT_FILE = ROOT + "dst/zoo"
+#OUT_FILE = ROOT + "dst/zoo"
+#OUT_FILE = ROOT + "_astra_/fprdk"
+#
+#def saveSymMatrix(matrix, file, items=None, saveItems=False):
+#    fn = open(file + ".dst", 'w')
+#    fn.write("%d labeled\n" % matrix.dim)
+#    items = items if items else matrix.items
+#    for i in range(matrix.dim):
+#        fn.write("%s" % items[i]['attributes'])
+#        for j in range(i + 1):
+#            fn.write("\t%.6f" % matrix[i, j])
+#        fn.write("\n")
+#
+#    fn.close()
+#    if saveItems:
+#        items.save(file + ".tab")
+#
+#
+#
+#def loadModel(fn):
+#    if os.path.exists('%s.npy' % fn):
+#        matrix, _labels, data = readMatrix('%s.npy' % fn)
+#    elif os.path.exists("%s-prob.dst" % fn):
+#        matrix, _labels, data = readMatrix("%s-prob.dst" % fn)
+#    elif os.path.exists("%s.dst" % fn):
+#        matrix, _labels, data = readMatrix("%s.dst" % fn)
+#    else:
+#        return None
+#
+#    if os.path.exists("%s.tab" % fn):
+#        data = data.Table("%s.tab" % fn)
+#        matrix.items = data
+#    else:
+#        print "ExampleTable %s not found!\n" % ("%s.tab" % fn)
+#    if os.path.exists("%s.res" % fn):
+#        matrix.results = pickle.load(open("%s.res" % fn, 'rb'))
+#    else:
+#        print "Results pickle %s not found!\n" % ("%s.res" % fn)
+#
+#    return matrix
+#
+#def saveModel(smx, fn):
+#    saveSymMatrix(smx, "%s" % fn, smx.items)
+#    smx.items.save('%s.tab' % fn)
+#    pickle.dump(smx.results, open('%s.res' % fn, "wb"))
+#
+#
+#def evaluateProjections(vizr, attributeList):
+#    vizr.evaluatedProjectionsCount = 0
+#    vizr.optimizedProjectionsCount = 0
+#    vizr.evaluationData = {}            # clear all previous data about tested permutations and stuff
+#    vizr.evaluationData["triedCombinations"] = {}
+#    vizr.clearResults()
+#
+#    vizr.clearArguments()
+#
+#    if vizr.projOptimizationMethod != 0:
+#        vizr.freeviz.useGeneralizedEigenvectors = 1
+#        vizr.graph.normalizeExamples = 0
+#
+#    domain = data.Domain([feature.Continuous("xVar"), feature.Continuous("yVar"), feature.Discrete(vizr.graph.dataDomain.classVar.name, values=getVariableValuesSorted(vizr.graph.dataDomain.classVar))])
+#    classListFull = vizr.graph.originalData[vizr.graph.dataClassIndex]
+#
+#    for attributes in attributeList:
+#        attrIndices = [vizr.graph.attributeNameIndex[attr] for attr in attributes]
+#        #print attrIndices
+#        if vizr.projOptimizationMethod != 0:
+#            projections = vizr.freeviz.findProjection(vizr.projOptimizationMethod, attrIndices, setAnchors=0, percentDataUsed=vizr.percentDataUsed)
+#            if projections != None:
+#                xanchors, yanchors, (attrNames, newIndices) = projections
+#                table = vizr.graph.createProjectionAsExampleTable(newIndices, domain=domain, XAnchors=xanchors, YAnchors=yanchors)
+#
+#            if table == None or len(table) < vizr.minNumOfExamples: continue
+#            accuracy, other_results = vizr.evaluateProjection(table)
+#            generalDict = {"XAnchors": list(xanchors), "YAnchors": list(yanchors), "Results": vizr.evaluationResults} if vizr.saveEvaluationResults else {"XAnchors": list(xanchors), "YAnchors": list(yanchors)}
+#            vizr.addResult(accuracy, other_results, len(table), attrNames, vizr.evaluatedProjectionsCount, generalDict=generalDict)
+#            vizr.evaluatedProjectionsCount += 1
+#        else:
+#            XAnchors = vizr.graph.createXAnchors(len(attrIndices))
+#            YAnchors = vizr.graph.createYAnchors(len(attrIndices))
+#            validData = vizr.graph.getValidList(attrIndices)
+#            if numpy.sum(validData) >= vizr.minNumOfExamples:
+#                classList = numpy.compress(validData, classListFull)
+#                selectedData = numpy.compress(validData, numpy.take(vizr.graph.noJitteringScaledData, attrIndices, axis=0), axis=1)
+#                sum_i = vizr.graph._getSum_i(selectedData)
+#
+#                table = vizr.graph.createProjectionAsExampleTable(attrIndices, validData=validData, classList=classList, sum_i=sum_i, XAnchors=XAnchors, YAnchors=YAnchors, domain=domain)
+#                accuracy, other_results = vizr.evaluateProjection(table)
+#                generalDict = {"Results": vizr.evaluationResults} if vizr.saveEvaluationResults else {}
+#                vizr.addResult(accuracy, other_results, len(table), [vizr.graph.attributeNames[i] for i in attrIndices], vizr.evaluatedProjectionsCount, generalDict)
+#                vizr.evaluatedProjectionsCount += 1
+#
+#    return vizr.evaluatedProjectionsCount

orangecontrib/modelmaps/model.py

+"""
+.. index:: model
+
+*****
+Model
+*****
+
+.. autoclass:: Orange.modelmaps.Model
+   :members:
+
+"""
+
+import uuid
+import numpy as np
+
+from itertools import groupby
+from operator import itemgetter
+
+from Orange import data
+
+class Model(object):
+
+    def __init__(self, type_, classifier, probabilities, \
+                 class_values, attributes, \
+                 instance_predictions=None, instance_classes=None, \
+                 name=None, XAnchors=None, YAnchors=None):
+        """Meta-model, a node in Model Map.
+        
+        :param type_: model type; must be in MODEL_LIST
+        :type type_: string
+        
+        :param classifier: classifier object of this model
+        :type classifier: :obj:`Orange.classification.Classifier`
+        
+        :param probabilities: list of predicted probabilities (for all classes) 
+        :type probabilities: list of :obj:`numpy.ndarray`
+        
+        :param attributes: list of attribute names
+        :type attributes: list
+        
+        :param instance_predictions: array of predicted classes for all instances
+        :type instance_predictions: :obj:`numpy.ndarray`
+        
+        :param instance_classes: array of true classes for all instances
+        :type instance_classes: :obj:`numpy.ndarray`
+        
+        :param name: model name
+        :type name: string
+        
+        :param XAnchors: 
+        :type XAnchors: list 
+        
+        :param YAnchors: 
+        :type YAnchors: list
+        
+        """
+
+        self.uuid = uuid.uuid4().hex
+        self.type = type_
+        self.classifier = classifier
+        self.probabilities = probabilities
+        self.class_values = class_values
+        self.attributes = attributes
+        self.instance_predictions = instance_predictions
+        self.instance_classes = instance_classes
+        self.name = name if name is not None else self.type
+        self.XAnchors = XAnchors
+        self.YAnchors = YAnchors
+
+    def get_instance(self, domain):
+        """Return an :obj:`Orange.data.Table` instance with model meta-data.
+        
+        :param domain: instance will match given domain 
+        :type domain: :obj:`Orange.data.Domain`
+        """
+
+        inst = data.Instance(domain)
+
+        inst['uuid'] = self.uuid
+        inst['number of attributes'] = len(set(self.attributes))
+        results = [p == c for p, c in zip(self.instance_predictions, self.instance_classes)]
+        inst['CA'] = sum(results) / float(len(results))
+        inst['P'] = np.mean([p[self.class_values[c]] for p, c in zip(self.probabilities, self.instance_classes)])
+
+        classes = zip(*sorted(self.class_values.items(), key=itemgetter(1)))[0]
+        outcomes = np.array([c == self.instance_classes for c in classes]).T
+
+        inst['Brier'] = np.sum(np.square(self.probabilities - outcomes)) / len(self.probabilities)
+        inst['Brier by class'] = ', '.join(map(str, zip(*sorted(zip(classes, np.sum(np.square(self.probabilities - outcomes), axis=0) / len(self.probabilities))))[1]))
+        inst['type'] = self.type
+        inst['model'] = self
+        inst['attributes'] = ', '.join(self.attributes)
+        #ex["AUC"] = nets[i].items[m]["AUC"].value
+        resultsByClass = sorted([(p == c, c) for p, c in zip(self.instance_predictions, self.instance_classes)], key=itemgetter(1))
+        groups = []
+        for _k, g in groupby(resultsByClass, lambda x: x[1]):
+            resultsByClass, _classes = zip(*g)
+            groups.append(resultsByClass)
+        inst["CA by class"] = ', '.join([str(sum(results) / float(len(results))) for results in groups])
+        #ex["cluster CA"] = best_indices[i][j]
+        #ex["cluster size"] = median_csizes[i][j]
+        inst["label"] = self.name
+
+        return inst

orangecontrib/modelmaps/modelmap.py

+"""
+.. index:: model map
+
+***************
+Build Model Map
+***************
+
+.. autoclass:: Orange.modelmaps.BuildModelMap
+   :members:
+   
+**************
+Help Functions
+**************
+
+.. autofunction:: load
+.. autofunction:: save
+.. autofunction:: get_models_table
+.. autofunction:: get_feature_subsets
+
+"""
+
+import bz2, itertools, math, random, os.path, time, uuid, re, sys
+import cPickle as pickle
+
+import scipy.stats
+import numpy as np
+
+import orngVizRank as vr
+import model
+
+from orngScaleData import getVariableValuesSorted
+
+from Orange import data, distance, ensemble, feature, misc, projection