示例#1
0
 def templateCfEntryDistance(self, type_measurement):
     cluster1 = [[0.1, 0.1], [0.1, 0.2], [0.2, 0.1], [0.2, 0.2]];
     cluster2 = [[0.4, 0.4], [0.4, 0.5], [0.5, 0.4], [0.5, 0.5]];
     cluster3 = [[0.9, 0.9], [0.9, 1.0], [1.0, 0.9], [1.0, 1.0]];
        
     entry1 = cfentry(len(cluster1), linear_sum(cluster1), square_sum(cluster1));
     entry2 = cfentry(len(cluster2), linear_sum(cluster2), square_sum(cluster2));
     entry3 = cfentry(len(cluster3), linear_sum(cluster3), square_sum(cluster3));
        
     distance12 = entry1.get_distance(entry2, type_measurement);
     distance23 = entry2.get_distance(entry3, type_measurement);
     distance13 = entry1.get_distance(entry3, type_measurement);
        
     assert distance12 < distance23;
     assert distance23 < distance13;  
示例#2
0
 def testCfTreeInserionOneLeafThreeEntries(self):
     cluster1 = [[0.1, 0.1], [0.1, 0.2], [0.2, 0.1], [0.2, 0.2]];
     cluster2 = [[0.4, 0.4], [0.4, 0.5], [0.5, 0.4], [0.5, 0.5]];
     cluster3 = [[0.9, 0.9], [0.9, 1.0], [1.0, 0.9], [1.0, 1.0]];
         
     tree = cftree(3, 4, 0.0);
     tree.insert_cluster(cluster1);
     tree.insert_cluster(cluster2);
     tree.insert_cluster(cluster3);
         
     entry1 = cfentry(len(cluster1), linear_sum(cluster1), square_sum(cluster1));
     entry2 = cfentry(len(cluster2), linear_sum(cluster2), square_sum(cluster2));
     entry3 = cfentry(len(cluster3), linear_sum(cluster3), square_sum(cluster3));
         
     assert tree.find_nearest_leaf(entry1) == tree.find_nearest_leaf(entry2);
     assert tree.find_nearest_leaf(entry2) == tree.find_nearest_leaf(entry3);
示例#3
0
 def insert_cluster(self, cluster):
     """!
     @brief Insert cluster that is represented as list of points where each point is represented by list of coordinates.
     @details Clustering feature is created for that cluster and inserted to the tree.
     
     @param[in] cluster (list): Cluster that is represented by list of points that should be inserted to the tree.
     
     """
     
     entry = cfentry(len(cluster), linear_sum(cluster), square_sum(cluster));
     self.insert(entry);
示例#4
0
    def insert_cluster(self, cluster):
        """!
        @brief Insert cluster that is represented as list of points where each point is represented by list of coordinates.
        @details Clustering feature is created for that cluster and inserted to the tree.
        
        @param[in] cluster (list): Cluster that is represented by list of points that should be inserted to the tree.
        
        """

        entry = cfentry(len(cluster), linear_sum(cluster), square_sum(cluster))
        self.insert(entry)
示例#5
0
 def testCfEntryIncrease(self):
     tolerance = 0.00001;
     cluster = [ [0.1, 0.1], [0.2, 0.2], [0.5, 0.5], [0.4, 0.4], [0.6, 0.6] ];
        
     entry1 = cfentry(len(cluster), linear_sum(cluster), square_sum(cluster));
     entry2 = entry1 + entry1;
        
     assert cfentry(10, [3.6, 3.6], 3.28) == entry2;
        
     entry2 = entry2 + entry2;
     assert cfentry(20, [7.2, 7.2], 6.56) == entry2;
示例#6
0
 def templateCfClusterRepresentation(self, cluster, centroid, radius, diameter, tolerance):
     entry = cfentry(len(cluster), linear_sum(cluster), square_sum(cluster));
        
     assertion_centroid = centroid;
     if (type(centroid) != list):
         assertion_centroid = [ centroid ];
        
     if (type(centroid) == list):
         for dimension in range(0, len(assertion_centroid)):
             assert (assertion_centroid[dimension] - tolerance < ( entry.get_centroid() )[dimension]) and (( entry.get_centroid() )[dimension] < assertion_centroid[dimension] + tolerance);
        
     assert (radius - tolerance < entry.get_radius()) and (entry.get_radius() < radius + tolerance);
     assert (diameter - tolerance < entry.get_diameter()) and (entry.get_diameter() < diameter + tolerance);
示例#7
0
 def testCfTreeEntryAbsorbing(self):
     tree = cftree(2, 1, 10000.0);
     absorbing_entry = cfentry(0, [0.0, 0.0], 0.0);
       
     for offset in range(0, 10):
         cluster = [ [random() + offset, random() + offset] for i in range(10)];
         entry = cfentry(len(cluster), linear_sum(cluster), square_sum(cluster));
           
         absorbing_entry += entry;
           
         tree.insert(entry);
           
         assert 1 == tree.amount_entries;
         assert 1 == tree.amount_nodes;
         assert 1 == tree.height;
           
         assert None == tree.root.parent;
         assert absorbing_entry == tree.root.feature;
示例#8
0
 def __get_nearest_feature(self, point):
     """!
     @brief Find nearest entry for specified point.
     
     @param[in] point (list): Pointer to point from input dataset.
     
     @return (uint) Index of nearest entry to the specified point.
     
     """
     
     minimum_distance = float("Inf");
     index_nearest_feature = -1;
     
     for index_entry in range(0, len(self.__features)):
         point_entry = cfentry(1, linear_sum([ point ]), square_sum([ point ]));
         
         distance = self.__features[index_entry].get_distance(point_entry, self.__measurement_type);
         if (distance < minimum_distance):
             minimum_distance = distance;
             index_nearest_feature = index_entry;
             
     return index_nearest_feature;
             
     
示例#9
0
 def templateCfEntryValueDistance(self, cluster1, cluster2, value, tolerance, type_measurment):
     entry1 = cfentry(len(cluster1), linear_sum(cluster1), square_sum(cluster1));
     entry2 = cfentry(len(cluster2), linear_sum(cluster2), square_sum(cluster2));
        
     distance = entry1.get_distance(entry2, type_measurment);
     assert ( (value - tolerance < distance) and (value + tolerance > distance) );