def __init__(self, tobjects, distance, find_closest_points, k, 
              get_labels_of_record):
     '''
     Constructor.
     
     @type tobjects: list of records
     @param tobjects: used to calculate parameters (probabilities)
         and nearest neighbours amongst the records it returns;
         NOTE: if a user wants to manipulate, which codes to consider(e.g. higher or lower level) 
         it is good to give a specific tobjects parameter
         
     @type distance: object that contains a method of signature: distance(rec1, rec2)
     @param distance: returns distance measure between rec1 and rec2
     
     @type find_closest_points: function of signature:
         find_closest_points(sample, records, excluding, how_many, distance)
     @param distance: finding closest points,
     
     @type k: integer
     @param k: no. of neighbours taken into consideration
     
     @type get_labels_of_record: function
     @param get_labels_of_record: returns list of labels assigned to a record
     
     '''
     self.tobjects = tobjects()
     self.distance = distance
     self.find_closest_points = find_closest_points
     self.k = k
     self.get_labels_of_record = get_labels_of_record
     self.list_of_all_labels = find_all_labels(self.tobjects, self.get_labels_of_record)
     
     #compute the counts:
     self.c, self.c_prim = self.__calculate_label_counts()
     self.fraction_knn_thresholds, self.fmeasure_per_class = self.__calculate_thresholds()
    def __init__(self, frecords, distance, find_closest_points, k_list,
                 get_labels_of_record):
        '''
        Constructor.
        
        @type frecords: list of records
        @param frecords: used to calculate parameters (probabilities)
            and nearest neighbours amongst the records it returns;
            NOTE: if a user wants to manipulate, which codes to consider(e.g. higher or lower level) 
            it is good to give a specific frecords parameter
            
        @type distance: object that contains a method of signature: distance(rec1, rec2)
        @param distance: returns distance measure between 2 records
        
        @type find_closest_points: function of signature:
            find_closest_points(sample, records, excluding, how_many, distance);
            It returns training objects which are closest to the sample, in a sorted form, increasing
            order in terms of their distance from sample.
        @param distance: finding closest points,
        
        @type k_list: list of integers
        @param k_list: list of no. of neighbours taken into consideration
        
        @type get_labels_of_record: function
        @param get_labels_of_record: returns list of labels assigned to a record
        
        '''
        self.frecords = list(frecords(
        ))  #TODO: zrobic podawanie listy skoro i tak robi sie liste z tego!
        self.distance = distance
        self.find_closest_points = find_closest_points
        self.k_list = k_list
        self.k_max = max(k_list)
        PRINTER('[MlKnnFractionalEnsembledStrongest: init] max k: ' +
                str(self.k_max))
        self.get_labels_of_record = get_labels_of_record

        self.list_of_all_labels = find_all_labels(self.frecords,
                                                  self.get_labels_of_record)
        PRINTER('[MlKnnFractionalEnsembledStrongest: init] labels: ' +
                str(self.list_of_all_labels))

        #compute the counts of the form c[k][label][i]
        #<- how many times for k, label i-neighbouring codes codes have the same label:
        self.c, self.c_prim = self.__calculate_label_counts()

        self.fraction_knn_thresholds = {}
        self.fraction_knn_fmeasures = {}
        for k in self.k_list:
            self.fraction_knn_thresholds[k], self.fraction_knn_fmeasures[
                k] = self.__calculate_thresholds(self.c[k], self.c_prim[k])
 def __init__(self, frecords, distance, find_closest_points, k_list, 
              get_labels_of_record):
     '''
     Constructor.
     
     @type frecords: list of records
     @param frecords: used to calculate parameters (probabilities)
         and nearest neighbours amongst the records it returns;
         NOTE: if a user wants to manipulate, which codes to consider(e.g. higher or lower level) 
         it is good to give a specific frecords parameter
         
     @type distance: object that contains a method of signature: distance(rec1, rec2)
     @param distance: returns distance measure between 2 records
     
     @type find_closest_points: function of signature:
         find_closest_points(sample, records, excluding, how_many, distance);
         It returns training objects which are closest to the sample, in a sorted form, increasing
         order in terms of their distance from sample.
     @param distance: finding closest points,
     
     @type k_list: list of integers
     @param k_list: list of no. of neighbours taken into consideration
     
     @type get_labels_of_record: function
     @param get_labels_of_record: returns list of labels assigned to a record
     
     '''
     self.frecords = list(frecords())#TODO: zrobic podawanie listy skoro i tak robi sie liste z tego!
     self.distance = distance
     self.find_closest_points = find_closest_points
     self.k_list = k_list
     self.k_max = max(k_list)
     PRINTER('[MlKnnFractionalEnsembledStrongest: init] max k: '+str(self.k_max))
     self.get_labels_of_record = get_labels_of_record
     
     self.list_of_all_labels = find_all_labels(self.frecords, self.get_labels_of_record)
     PRINTER('[MlKnnFractionalEnsembledStrongest: init] labels: '+str(self.list_of_all_labels))
     
     #compute the counts of the form c[k][label][i] 
     #<- how many times for k, label i-neighbouring codes codes have the same label:
     self.c, self.c_prim = self.__calculate_label_counts()
     
     self.fraction_knn_thresholds = {}
     self.fraction_knn_fmeasures = {}
     for k in self.k_list:
         self.fraction_knn_thresholds[k], self.fraction_knn_fmeasures[k] = self.__calculate_thresholds(self.c[k], self.c_prim[k])
Esempio n. 4
0
    def __init__(self, frecords, distance, find_closest_points, k_list,
                 get_labels_of_record):
        '''
        Constructor.
        
        @type frecords: list of records
        @param frecords: used to calculate parameters (probabilities)
            and nearest neighbours amongst the records it returns;
            NOTE: if a user wants to manipulate, which codes to consider(e.g. higher or lower level) 
            it is good to give a specific frecords parameter
            
        @type distance: object that contains a method of signature: distance(rec1, rec2)
        @param distance: returns distance measure between 2 records
        
        @type find_closest_points: function of signature:
            find_closest_points(sample, records, excluding, how_many, distance);
            It returns training objects which are closest to the sample, in a sorted form, increasing
            order in terms of their distance from sample.
        @param distance: finding closest points,
        
        @type k_list: list of integers
        @param k_list: list of no. of neighbours taken into consideration
        
        @type get_labels_of_record: function
        @param get_labels_of_record: returns list of labels assigned to a record
        
        '''
        self.list_of_all_labels = find_all_labels(list(frecords()),
                                                  get_labels_of_record)
        self.k_list = k_list
        PRINTER('[MlKnnFractionalEnsembledStrongest: init] labels: ' +
                str(self.list_of_all_labels))
        PRINTER(
            '[MlKnnFractionalEnsembledStrongest: init]: START OF TRAINING...')

        self.mlknn_fractionals = {}
        for k in self.k_list:
            self.mlknn_fractionals[k] = MlKnnFractional(
                frecords, distance, find_closest_points, k,
                get_labels_of_record)

        PRINTER(
            '[MlKnnFractionalEnsembledStrongest: init]: END OF TRAINING...')
Esempio n. 5
0
 def __init__(self, tobjects, distance, find_closest_points, k,
              smoothing_param, get_labels_of_record):
     '''
     Constructor.
     
     @type tobjects: list of training objects
     @param tobjects: used to calculate parameters (probabilities)
         and nearest neighbours amongst the training objects it returns;
         NOTE: if a user wants to manipulate, which codes to consider(e.g. higher or lower level) 
         it is good to give a specific tobjects parameter
         
     @type distance: object that contains a method of signature: distance(rec1, rec2)
     @param distance: returns distance measure between rec1 and rec2
     
     @type find_closest_points: function of signature:
         find_closest_points(sample, objects, excluding, how_many, distance)
     @param distance: finding closest points for sample amongst the objects,
     
     @type k: integer
     @param k: no. of neighbours taken into consideration
     
     @type k: smoothing_param
     @param smoothing_param - min number of occurences of each label = as in the algorithm
     
     @type get_labels_of_record: function
     @param get_labels_of_record: returns list of labels assigned to a record
     
     '''
     self.tobjects = tobjects  #list(tobjects())
     self.distance = distance
     self.find_closest_points = find_closest_points
     self.k = k
     self.smoothing_param = smoothing_param
     self.get_labels_of_record = get_labels_of_record
     self.labels = find_all_labels(self.tobjects, self.get_labels_of_record)
     PRINTER('[MlKnn: init] labels: ' + str(self.labels))
     self.threshold = self.init_zero_thresholds(self.labels)
     #compute the probabilities:
     self.labelprobabilities, self.labelcounterprobabilities = self.__get_label_probabilities(
     )
     self.posteriorprobabilities = self.__get_posterior_probabilities()
Esempio n. 6
0
 def __init__(self, tobjects, distance, find_closest_points, k, smoothing_param, get_labels_of_record):
     '''
     Constructor.
     
     @type tobjects: list of training objects
     @param tobjects: used to calculate parameters (probabilities)
         and nearest neighbours amongst the training objects it returns;
         NOTE: if a user wants to manipulate, which codes to consider(e.g. higher or lower level) 
         it is good to give a specific tobjects parameter
         
     @type distance: object that contains a method of signature: distance(rec1, rec2)
     @param distance: returns distance measure between rec1 and rec2
     
     @type find_closest_points: function of signature:
         find_closest_points(sample, objects, excluding, how_many, distance)
     @param distance: finding closest points for sample amongst the objects,
     
     @type k: integer
     @param k: no. of neighbours taken into consideration
     
     @type k: smoothing_param
     @param smoothing_param - min number of occurences of each label = as in the algorithm
     
     @type get_labels_of_record: function
     @param get_labels_of_record: returns list of labels assigned to a record
     
     '''
     self.tobjects = tobjects#list(tobjects())
     self.distance = distance
     self.find_closest_points = find_closest_points
     self.k = k
     self.smoothing_param = smoothing_param
     self.get_labels_of_record = get_labels_of_record
     self.labels = find_all_labels(self.tobjects, self.get_labels_of_record)
     PRINTER('[MlKnn: init] labels: '+str(self.labels))
     self.threshold = self.init_zero_thresholds(self.labels)
     #compute the probabilities:
     self.labelprobabilities, self.labelcounterprobabilities = self.__get_label_probabilities()
     self.posteriorprobabilities = self.__get_posterior_probabilities()
    def __init__(self, frecords, distance, find_closest_points, k_list, get_labels_of_record):
        '''
        Constructor.
        
        @type frecords: list of records
        @param frecords: used to calculate parameters (probabilities)
            and nearest neighbours amongst the records it returns;
            NOTE: if a user wants to manipulate, which codes to consider(e.g. higher or lower level) 
            it is good to give a specific frecords parameter
            
        @type distance: object that contains a method of signature: distance(rec1, rec2)
        @param distance: returns distance measure between 2 records
        
        @type find_closest_points: function of signature:
            find_closest_points(sample, records, excluding, how_many, distance);
            It returns training objects which are closest to the sample, in a sorted form, increasing
            order in terms of their distance from sample.
        @param distance: finding closest points,
        
        @type k_list: list of integers
        @param k_list: list of no. of neighbours taken into consideration
        
        @type get_labels_of_record: function
        @param get_labels_of_record: returns list of labels assigned to a record
        
        '''
        self.list_of_all_labels = find_all_labels(list(frecords()), get_labels_of_record)
        self.k_list = k_list
        PRINTER('[MlKnnFractionalEnsembledStrongest: init] labels: '+str(self.list_of_all_labels))
        PRINTER('[MlKnnFractionalEnsembledStrongest: init]: START OF TRAINING...')
        
        self.mlknn_fractionals = {}
        for k in self.k_list:
            self.mlknn_fractionals[k] = MlKnnFractional(frecords, distance, find_closest_points, k, 
                 get_labels_of_record)

        PRINTER('[MlKnnFractionalEnsembledStrongest: init]: END OF TRAINING...')
    def __init__(self, tobjects, distance, find_closest_points, k,
                 get_labels_of_record):
        '''
        Constructor.
        
        @type tobjects: list of records
        @param tobjects: used to calculate parameters (probabilities)
            and nearest neighbours amongst the records it returns;
            NOTE: if a user wants to manipulate, which codes to consider(e.g. higher or lower level) 
            it is good to give a specific tobjects parameter
            
        @type distance: object that contains a method of signature: distance(rec1, rec2)
        @param distance: returns distance measure between rec1 and rec2
        
        @type find_closest_points: function of signature:
            find_closest_points(sample, records, excluding, how_many, distance)
        @param distance: finding closest points,
        
        @type k: integer
        @param k: no. of neighbours taken into consideration
        
        @type get_labels_of_record: function
        @param get_labels_of_record: returns list of labels assigned to a record
        
        '''
        self.tobjects = tobjects()
        self.distance = distance
        self.find_closest_points = find_closest_points
        self.k = k
        self.get_labels_of_record = get_labels_of_record
        self.list_of_all_labels = find_all_labels(self.tobjects,
                                                  self.get_labels_of_record)

        #compute the counts:
        self.c, self.c_prim = self.__calculate_label_counts()
        self.fraction_knn_thresholds, self.fmeasure_per_class = self.__calculate_thresholds(
        )
 def find_all_labels(self, tobjects, get_labels):
     return find_all_labels.find_all_labels(tobjects, get_labels)
 def find_all_labels(self, tobjects, get_labels):
     return find_all_labels.find_all_labels(tobjects, get_labels)