Changeset 9724:318e91106d47 in orange


Ignore:
Timestamp:
02/06/12 13:52:55 (2 years ago)
Author:
markotoplak
Branch:
default
Children:
9725:6c16952df555, 9752:cbd6f6f10f06
rebase_source:
be8730bf9f2e7e771332dfc8b3876c8a62826bd1
Message:

Renames in Orange.distance.

Files:
19 edited

Legend:

Unmodified
Added
Removed
  • Orange/classification/knn.py

    r9671 r9724  
    3030 
    3131        component that constructs the object for measuring distances between 
    32         instances. Defaults to :class:`~Orange.distance.instances.EuclideanConstructor`. 
     32        instances. Defaults to :class:`~Orange.distance.Euclidean`. 
    3333 
    3434    .. attribute:: weight_id 
  • Orange/clustering/hierarchical.py

    r9723 r9724  
    310310The most common things to cluster are certainly examples. To show how to 
    311311this is done, we shall now load the Iris data set, initialize a distance 
    312 matrix with the distances measure by :class:`ExamplesDistance_Euclidean` 
     312matrix with the distances measure by :class:`Euclidean` 
    313313and cluster it with average linkage. Since we don't need the matrix, 
    314314we shall let the clustering overwrite it (not that it's needed for 
     
    321321    matrix = Orange.core.SymMatrix(len(data)) 
    322322    matrix.setattr("objects", data) 
    323     distance = Orange.distance.EuclideanConstructor(data) 
     323    distance = Orange.distance.Euclidean(data) 
    324324    for i1, instance1 in enumerate(data): 
    325325        for i2 in range(i1+1, len(data)): 
     
    475475 
    476476def clustering(data, 
    477                distance_constructor=orange.ExamplesDistanceConstructor_Euclidean, 
     477               distance_constructor=Orange.distance.Euclidean, 
    478478               linkage=AVERAGE, 
    479479               order=False, 
     
    484484    :type data: :class:`Orange.data.Table` 
    485485    :param distance_constructor: Instance distance constructor 
    486     :type distance_constructor: :class:`Orange.distance.ExamplesDistanceConstructor` 
     486    :type distance_constructor: :class:`Orange.distance.DistanceConstructor` 
    487487    :param linkage: Linkage flag. Must be one of global module level flags: 
    488488     
     
    15111511 
    15121512def instance_distance_matrix(data, 
    1513             distance_constructor=orange.ExamplesDistanceConstructor_Euclidean, 
     1513            distance_constructor=Orange.distance.Euclidean, 
    15141514            progress_callback=None): 
    15151515    """ A helper function that computes an :class:`Orange.core.SymMatrix` of all 
     
    15191519    :type data: :class:`Orange.data.Table` 
    15201520     
    1521     :param distance_constructor: An ExamplesDistance_Constructor instance. 
     1521    :param distance_constructor: An DistanceConstructor instance. 
    15221522    :type distance_constructor: :class:`Orange.distance.DistanceConstructor` 
    15231523     
  • Orange/clustering/kmeans.py

    r9671 r9724  
    294294    :param k: the number of clusters. 
    295295    :type k: integer 
    296     :param distfun: a distance function. 
    297     :type distfun: :class:`orange.ExamplesDistance` 
    298      """ 
     296    """ 
    299297    return data.getitems(random.sample(range(len(data)), k)) 
    300298 
     
    307305    :type k: integer 
    308306    :param distfun: a distance function. 
    309     :type distfun: :class:`orange.ExamplesDistance` 
     307    :type distfun: :class:`Orange.distance.Distance` 
    310308    """ 
    311309    center = data_center(data) 
     
    338336        :type k: integer 
    339337        :param distfun: a distance function. 
    340         :type distfun: :class:`orange.ExamplesDistance` 
     338        :type distfun: :class:`Orange.distance.Distance` 
    341339        """ 
    342340        sample = orange.ExampleTable(random.sample(data, min(self.n, len(data)))) 
     
    393391    def __init__(self, data=None, centroids=3, maxiters=None, minscorechange=None, 
    394392                 stopchanges=0, nstart=1, initialization=init_random, 
    395                  distance=orange.ExamplesDistanceConstructor_Euclidean, 
     393                 distance=Orange.distance.Euclidean, 
    396394                 scoring=score_distance_to_centroids, inner_callback = None, 
    397395                 outer_callback = None): 
     
    404402        :type nstart: integer 
    405403        :param distance: an example distance constructor, which measures the distance between two instances. 
    406         :type distance: :class:`orange.ExamplesDistanceConstructor` 
     404        :type distance: :class:`Orange.distance.DistanceConstructor` 
    407405        :param initialization: a function to select centroids given data instances, k and a example distance function. This module implements different approaches (:func:`init_random`, :func:`init_diversity`, :class:`init_hclustering`).  
    408406        :param scoring: a function that takes clustering object and returns the clustering score. It could be used, for instance, in procedure that repeats the clustering nstart times, returning the clustering with the lowest score. 
  • Orange/evaluation/reliability.py

    r9697 r9724  
    400400    def __call__(self, instances, learner): 
    401401        nearest_neighbours_constructor = Orange.classification.knn.FindNearestConstructor() 
    402         nearest_neighbours_constructor.distanceConstructor = Orange.distance.EuclideanConstructor() 
     402        nearest_neighbours_constructor.distanceConstructor = Orange.distance.Euclidean() 
    403403         
    404404        distance_id = Orange.data.new_meta_id() 
     
    467467    def __call__(self, instances, learner): 
    468468        nearest_neighbours_constructor = Orange.classification.knn.FindNearestConstructor() 
    469         nearest_neighbours_constructor.distanceConstructor = Orange.distance.EuclideanConstructor() 
     469        nearest_neighbours_constructor.distanceConstructor = Orange.distance.Euclidean() 
    470470         
    471471        distance_id = Orange.data.new_meta_id() 
     
    514514    def __call__(self, instances, *args): 
    515515        nnm = Orange.classification.knn.FindNearestConstructor() 
    516         nnm.distanceConstructor = Orange.distance.MahalanobisConstructor() 
     516        nnm.distanceConstructor = Orange.distance.Mahalanobis() 
    517517         
    518518        mid = Orange.data.new_meta_id() 
     
    558558        instance_avg = numpy.average(X, 0) 
    559559         
    560         distance_constructor = Orange.distance.MahalanobisConstructor() 
     560        distance_constructor = Orange.distance.Mahalanobis() 
    561561        distance = distance_constructor(new_instances) 
    562562         
  • Orange/multilabel/multiknn.py

    r9671 r9724  
    6868    def _build_knn(self, instances): 
    6969        nnc = Orange.classification.knn.FindNearestConstructor() 
    70         nnc.distanceConstructor = Orange.core.ExamplesDistanceConstructor_Euclidean() 
     70        nnc.distanceConstructor = Orange.distance.Euclidean() 
    7171         
    7272        weight_id = Orange.data.new_meta_id() 
  • Orange/testing/unit/tests/test_distance.py

    r9679 r9724  
    33from Orange.misc.testing import datasets_driven, test_on_data 
    44 
    5 from Orange.distance import instances 
     5from Orange.distance import * 
    66 
    77@datasets_driven 
    88class TestEuclideanDistance(testing.DistanceTestCase): 
    9     DISTANCE_CONSTRUCTOR = instances.EuclideanConstructor() 
     9    DISTANCE_CONSTRUCTOR = Euclidean() 
    1010 
    1111@datasets_driven     
    1212class TestMannhatanDistance(testing.DistanceTestCase): 
    13     DISTANCE_CONSTRUCTOR = instances.ManhattanConstructor() 
     13    DISTANCE_CONSTRUCTOR = Manhattan() 
    1414     
    1515@datasets_driven 
    1616class TestHammingDistance(testing.DistanceTestCase): 
    17     DISTANCE_CONSTRUCTOR = instances.HammingConstructor() 
     17    DISTANCE_CONSTRUCTOR = Hamming() 
    1818     
    1919@datasets_driven 
    2020class TestReliefDistance(testing.DistanceTestCase): 
    21     DISTANCE_CONSTRUCTOR = instances.ReliefConstructor() 
     21    DISTANCE_CONSTRUCTOR = Relief() 
    2222 
    2323@datasets_driven 
    2424class TestPearsonRDistance(testing.DistanceTestCase): 
    25     DISTANCE_CONSTRUCTOR = instances.PearsonRConstructor() 
     25    DISTANCE_CONSTRUCTOR = PearsonR() 
    2626 
    2727@datasets_driven 
    2828class TestSpearmanRDistance(testing.DistanceTestCase): 
    29     DISTANCE_CONSTRUCTOR = instances.SpearmanRConstructor() 
     29    DISTANCE_CONSTRUCTOR = SpearmanR() 
    3030     
    3131@datasets_driven 
    3232class TestPearsonRAbsoluteDistance(testing.DistanceTestCase): 
    33     DISTANCE_CONSTRUCTOR = instances.PearsonRAbsoluteConstructor() 
     33    DISTANCE_CONSTRUCTOR = PearsonRAbsolute() 
    3434     
    3535@datasets_driven 
    3636class TestSpearmanRAbsoluteDistance(testing.DistanceTestCase): 
    37     DISTANCE_CONSTRUCTOR = instances.SpearmanRAbsoluteConstructor() 
     37    DISTANCE_CONSTRUCTOR = SpearmanRAbsolute() 
    3838     
    3939@datasets_driven 
    4040class TestMahalanobisDistance(testing.DistanceTestCase): 
    41     DISTANCE_CONSTRUCTOR = instances.MahalanobisConstructor() 
     41    DISTANCE_CONSTRUCTOR = Mahalanobis() 
    4242     
    4343if __name__ == "__main__": 
  • Orange/testing/unit/tests/test_hclustering.py

    r9679 r9724  
    55                       
    66from Orange.clustering import hierarchical as hier      
    7 from Orange.distance.instances import * 
     7from Orange.distance import * 
    88                            
    99import Orange.misc.testing as testing 
     
    1717    @testing.test_on_data 
    1818    def test_example_clustering_on(self, data): 
    19         constructors = [EuclideanConstructor, ManhattanConstructor] 
     19        constructors = [Euclidean, Manhattan] 
    2020        for distance_constructor in constructors: 
    2121            clust = clustering(data, distance_constructor, HierarchicalClustering.Single) 
     
    3333    @testing.test_on_datasets(datasets=["iris"]) 
    3434    def test_pickling_on(self, data): 
    35         cluster = clustering(data, EuclideanConstructor, HierarchicalClustering.Single) 
     35        cluster = clustering(data, Euclidean, HierarchicalClustering.Single) 
    3636        s = pickle.dumps(cluster) 
    3737        cluster_clone = pickle.loads(s) 
     
    4444            self.assert_(val >= 0 and val <=100) 
    4545            self.assertIsInstance(val, float) 
    46         matrix = instance_distance_matrix(data, EuclideanConstructor(), progress_callback=p) 
     46        matrix = instance_distance_matrix(data, Euclidean(), progress_callback=p) 
    4747        root1 = HierarchicalClustering(matrix, progress_callback=p) 
    4848        root2 = hier.clone(root1) 
  • Orange/testing/unit/tests/test_kmeans.py

    r9679 r9724  
    33from Orange.clustering import kmeans 
    44from Orange.clustering.kmeans import Clustering 
    5 from Orange.distance.instances import * 
     5from Orange.distance import * 
    66 
    77@testing.datasets_driven 
     
    2323    @testing.test_on_data 
    2424    def test_init_functs(self, table): 
    25         distfunc = EuclideanConstructor(table) 
     25        distfunc = Euclidean(table) 
    2626        for k in [1, 5, 10]: 
    2727            self._test_init_func(table, k, distfunc) 
  • Orange/testing/unit/tests/test_knn.py

    r9679 r9724  
    44from Orange.misc.testing import datasets_driven, test_on_data 
    55from Orange.classification import knn 
    6 from Orange.distance.instances import EuclideanConstructor 
     6from Orange.distance import Euclidean 
    77 
    88 
     
    1111class TestKNNLearner(testing.LearnerTestCase): 
    1212    def setUp(self): 
    13         self.learner = knn.kNNLearner(distance_constructor=EuclideanConstructor()) 
     13        self.learner = knn.kNNLearner(distance_constructor=Euclidean()) 
    1414     
    1515    @testing.test_on_data 
    1616    def test_learner_on(self, dataset): 
    1717        testing.LearnerTestCase.test_learner_on(self, dataset) 
    18         instance = dataset.randomexample() 
     18        instance = dataset.random_instance() 
    1919        self.assertEqual(len(self.classifier.find_nearest(3, instance)), 3) 
    2020         
  • Orange/testing/unit/tests/test_mds.py

    r9679 r9724  
    44import unittest 
    55from Orange.projection import mds 
    6 from Orange.distance.instances import distance_matrix, EuclideanConstructor 
     6from Orange.distance import distance_matrix, Euclidean 
    77     
    88@datasets_driven 
  • docs/reference/rst/code/distances-test.py

    r9663 r9724  
    55 
    66# Euclidean distance constructor 
    7 d2Constr = Orange.distance.EuclideanConstructor() 
     7d2Constr = Orange.distance.Euclidean() 
    88d2 = d2Constr(iris) 
    99 
    1010# Constructs  
    11 dPears = Orange.distance.PearsonRConstructor(iris) 
     11dPears = Orange.distance.PearsonR(iris) 
    1212 
    1313#reference instance 
  • docs/reference/rst/code/knnExample2.py

    r9638 r9724  
    44knn = Orange.classification.knn.kNNLearner() 
    55knn.k = 10 
    6 knn.distance_constructor = Orange.core.ExamplesDistanceConstructor_Hamming() 
     6knn.distance_constructor = Orange.distance.Hamming() 
    77knn = knn(iris) 
    88for i in range(5): 
  • docs/reference/rst/code/knnInstanceDistance.py

    r9638 r9724  
    44 
    55nnc = Orange.classification.knn.FindNearestConstructor() 
    6 nnc.distanceConstructor = Orange.core.ExamplesDistanceConstructor_Euclidean() 
     6nnc.distanceConstructor = Orange.distance.Euclidean() 
    77 
    88did = Orange.data.new_meta_id() 
  • docs/reference/rst/code/knnlearner.py

    r9638 r9724  
    1515knn = Orange.classification.knn.kNNLearner(train, k=10) 
    1616for i in range(5): 
    17     instance = test.randomexample() 
     17    instance = test.random_instance() 
    1818    print instance.getclass(), knn(instance) 
    1919 
     
    2323knn = Orange.classification.knn.kNNLearner() 
    2424knn.k = 10 
    25 knn.distanceConstructor = Orange.core.ExamplesDistanceConstructor_Hamming() 
     25knn.distance_constructor = Orange.distance.Hamming() 
    2626knn = knn(train) 
    2727for i in range(5): 
    28     instance = test.randomexample() 
     28    instance = test.random_instance() 
    2929    print instance.getclass(), knn(instance) 
  • docs/reference/rst/code/mds-advanced.py

    r9372 r9724  
    1212 
    1313# Construct a distance matrix using Euclidean distance 
    14 dist = Orange.core.ExamplesDistanceConstructor_Euclidean(table) 
     14dist = Orange.distance.Euclidean(table) 
    1515matrix = Orange.core.SymMatrix(len(table)) 
    1616for i in range(len(table)): 
  • docs/reference/rst/code/mds-euclid-torgerson-3d.py

    r9663 r9724  
    1111 
    1212# Construct a distance matrix using Euclidean distance 
    13 dist = Orange.distance.EuclideanConstructor(table) 
     13dist = Orange.distance.Euclidean(table) 
    1414matrix = Orange.core.SymMatrix(len(table)) 
    1515matrix.setattr('items', table) 
  • docs/reference/rst/code/outlier2.py

    r9663 r9724  
    33data = Orange.data.Table("bridges") 
    44outlier_det = Orange.preprocess.outliers.OutlierDetection() 
    5 outlier_det.set_examples(data, Orange.distance.EuclideanConstructor(data)) 
     5outlier_det.set_examples(data, Orange.distance.Euclidean(data)) 
    66outlier_det.set_knn(3) 
    77z_values = outlier_det.z_values() 
  • docs/reference/rst/code/svm-custom-kernel.py

    r9663 r9724  
    33 
    44from Orange.classification.svm import SVMLearner, kernels 
    5 from Orange.distance import EuclideanConstructor 
    6 from Orange.distance import HammingConstructor 
     5from Orange.distance import Euclidean 
     6from Orange.distance import Hamming 
    77 
    88table = data.Table("iris.tab") 
    99l1 = SVMLearner() 
    10 l1.kernel_func = kernels.RBFKernelWrapper(EuclideanConstructor(table), gamma=0.5) 
     10l1.kernel_func = kernels.RBFKernelWrapper(Euclidean(table), gamma=0.5) 
    1111l1.kernel_type = SVMLearner.Custom 
    1212l1.probability = True 
     
    1515 
    1616l2 = SVMLearner() 
    17 l2.kernel_func = kernels.RBFKernelWrapper(HammingConstructor(table), gamma=0.5) 
     17l2.kernel_func = kernels.RBFKernelWrapper(Hamming(table), gamma=0.5) 
    1818l2.kernel_type = SVMLearner.Custom 
    1919l2.probability = True 
     
    2323l3 = SVMLearner() 
    2424l3.kernel_func = kernels.CompositeKernelWrapper( 
    25     kernels.RBFKernelWrapper(EuclideanConstructor(table), gamma=0.5), 
    26     kernels.RBFKernelWrapper(HammingConstructor(table), gamma=0.5), l=0.5) 
     25    kernels.RBFKernelWrapper(Euclidean(table), gamma=0.5), 
     26    kernels.RBFKernelWrapper(Hamming(table), gamma=0.5), l=0.5) 
    2727l3.kernel_type = SVMLearner.Custom 
    2828l3.probability = True 
Note: See TracChangeset for help on using the changeset viewer.