コード例 #1
0
ファイル: cluster.py プロジェクト: dybisz/pattern_recognition
class Cluster:
    """
    This class holds data about single cluster,
    its center and points around it
    """
    def __init__(self, centroid, points, name, number, give_info = True, do_ellipsoid = True, do_cuboid = True):
        self.center = centroid
        self.points = points
        if do_cuboid:
            self.cuboid = Cuboid(self.points)
        if do_ellipsoid:
            self.ellipsoid = Ellipsoid(self.points, global_v.SEMI_AXIS_SCALE)
            if(global_v.CHAR_NUM == 3):    
                self.rejected_x, self.rejected_y, self.rejected_z = self.ellipsoid.is_point_in_ellipsoid(self.points[:])
            else:
                self.rejected_x, self.rejected_y = self.ellipsoid.is_point_in_ellipsoid(self.points[:])
            if give_info:
                self.__info(name, number)
                print('        >> points in ellipsoid:',(1- len(self.rejected_x)/len(self.points)) * 100,'%','\n')

    '''
        Prints out info about created cluster.
    '''
    def __info(self, name, number):
        print('    SYMBOL:',[name],'CLUSTER #',number,'\n'
              '        >> ellipsoid radius reduced to:', global_v.SEMI_AXIS_SCALE * 100,'%\n',
              '       >> minimum volume enclosing ellipsoid error:',global_v.MVEE_ERR)
コード例 #2
0
class Cluster:
    """
    This class holds data about single cluster,
    its center and points around it
    """
    def __init__(self,
                 centroid,
                 points,
                 name,
                 number,
                 give_info=True,
                 do_ellipsoid=True,
                 do_cuboid=True):
        if give_info:
            logger.log_header("Created Cluster: " + str([name]) +
                              " Number: #" + str(number),
                              styles=[logger.LogHeaderStyle.SUB_HEADER])

        self.center = centroid
        self.points = points
        if do_cuboid:
            logger.log("Creating Cuboid in Cluster")
            self.cuboid = Cuboid(self.points)
        if do_ellipsoid:
            logger.log("Creating Ellipsoid in Cluster")
            self.ellipsoid = Ellipsoid(self.points, global_v.SEMI_AXIS_SCALE)
            if (global_v.CHAR_NUM == 3):
                self.rejected_x, self.rejected_y, self.rejected_z = self.ellipsoid.is_point_in_ellipsoid(
                    self.points[:])
            else:
                self.rejected_x, self.rejected_y = self.ellipsoid.is_point_in_ellipsoid(
                    self.points[:])
            if give_info:
                self.__info(name, number)
                logger.log('Points in ellipsoid: ' +
                           str((1 - len(self.rejected_x) / len(self.points)) *
                               100) + '%')

    '''
        Prints out info about created cluster.
    '''

    def __info(self, name, number):
        logger.log("Name: " + str([name]) + " Number #" + str(number) + "\n" +
                   'ellipsoid radius reduced to:' +
                   str(global_v.SEMI_AXIS_SCALE * 100) + '%\n' +
                   'minimum volume enclosing ellipsoid error:' +
                   str(global_v.MVEE_ERR))
コード例 #3
0
 def __generate_objects(self, symbolClasses, type, with_test):
     set_of_objects = []
     for cl in symbolClasses:
         # Gather up points from each distorted class
         temp_points = []
         test_tmp = []
         for el in cl.learning_set:
             temp_points.append(el.characteristicsValues[:])
         
         if with_test:
             for el in cl.test_set:
                 test_tmp.append(el.characteristicsValues[:])
             
         if(type == ObjectType.ELLIPSOID):
             ellipsoid = Ellipsoid(temp_points)
             # Check accuracy 
             pointsInEllipsoid = ellipsoid.is_point_in_ellipsoid(temp_points,False, True)
             print("           Points in Ellipsoid:                            ", 100 * len(pointsInEllipsoid)/len(temp_points),"%")
             # Test set
             if with_test:
                 testPoints = ellipsoid.is_point_in_ellipsoid(test_tmp,False, True)
                 f = open(os.path.join("..","log",global_v.DIR_NAME,"TEST_SET_ACCURACY.txt"), 'a')
                 f.write("class [" + str(cl.name)+ "] ")
                 f.write("ellipsoid " + str(100 * len(testPoints)/len(test_tmp))+"%\n")
                 f.close()
                 print("           Test set accuracy:                              ", 100 * len(testPoints)/len(test_tmp),"%")                
             # Save an ellipsoid
             set_of_objects.append(EllipsoidWrap(temp_points,ellipsoid,cl.name))
             
         if(type == ObjectType.CUBOID):
             cuboid = Cuboid(temp_points)
             # Check accuracy
             pointsInCuboid = cuboid.points_in_cuboid(temp_points)
             print("           Points in Cuboid:                               ", 100 * len(pointsInCuboid)/len(temp_points),"%")
             # Test set
             if with_test:
                 testPoints = cuboid.points_in_cuboid(test_tmp)
                 print("           Test set accuracy:                              ", 100 * len(testPoints)/len(test_tmp),"%")   
                 f = open(os.path.join("..","log",global_v.DIR_NAME,"TEST_SET_ACCURACY.txt"), 'a')
                 f.write("class [" + str(cl.name)+ "] ")
                 f.write("cuboid " + str(100 * len(testPoints)/len(test_tmp))+ "%\n")
                 f.close()
             # Save an ellipsoid
             set_of_objects.append(CuboidWrap(temp_points,cuboid, cl.name))
         
     return set_of_objects
コード例 #4
0
    def __generate_objects(self, symbolClasses, type, with_test):
        set_of_objects = []
        for cl in symbolClasses:
            # Gather up points from each distorted class
            temp_points = []
            test_tmp = []
            for el in cl.learning_set:
                temp_points.append(el.characteristicsValues[:])

            if with_test:
                for el in cl.test_set:
                    test_tmp.append(el.characteristicsValues[:])

            if (type == ObjectType.ELLIPSOID):
                ellipsoid = Ellipsoid(temp_points)
                # Check accuracy
                pointsInEllipsoid = ellipsoid.is_point_in_ellipsoid(
                    temp_points, False, True)
                print(
                    "           Points in Ellipsoid:                            ",
                    100 * len(pointsInEllipsoid) / len(temp_points), "%")
                # Test set
                if with_test:
                    testPoints = ellipsoid.is_point_in_ellipsoid(
                        test_tmp, False, True)
                    f = open(
                        os.path.join("..", "log", global_v.DIR_NAME,
                                     "TEST_SET_ACCURACY.txt"), 'a')
                    f.write("class [" + str(cl.name) + "] ")
                    f.write("ellipsoid " +
                            str(100 * len(testPoints) / len(test_tmp)) + "%\n")
                    f.close()
                    print(
                        "           Test set accuracy:                              ",
                        100 * len(testPoints) / len(test_tmp), "%")
                # Save an ellipsoid
                set_of_objects.append(
                    EllipsoidWrap(temp_points, ellipsoid, cl.name))

            if (type == ObjectType.CUBOID):
                cuboid = Cuboid(temp_points)
                # Check accuracy
                pointsInCuboid = cuboid.points_in_cuboid(temp_points)
                print(
                    "           Points in Cuboid:                               ",
                    100 * len(pointsInCuboid) / len(temp_points), "%")
                # Test set
                if with_test:
                    testPoints = cuboid.points_in_cuboid(test_tmp)
                    print(
                        "           Test set accuracy:                              ",
                        100 * len(testPoints) / len(test_tmp), "%")
                    f = open(
                        os.path.join("..", "log", global_v.DIR_NAME,
                                     "TEST_SET_ACCURACY.txt"), 'a')
                    f.write("class [" + str(cl.name) + "] ")
                    f.write("cuboid " +
                            str(100 * len(testPoints) / len(test_tmp)) + "%\n")
                    f.close()
                # Save an ellipsoid
                set_of_objects.append(CuboidWrap(temp_points, cuboid, cl.name))

        return set_of_objects