예제 #1
0
파일: MILFM.py 프로젝트: InkiInki/MILFM
    def __full_mapping(self):
        """
        Mapping bags by using all instances.
        @Note:
            The size of data set instance space will greatly affect the running time.
        """

        self.full_mapping = np.zeros((self.num_bags, self.num_ins))
        if not os.path.exists(self.mapping_path) or os.path.getsize(
                self.mapping_path) == 0:
            print("Full mapping starting...")
            open(self.mapping_path, 'a').close()

            for i in range(self.num_bags):
                print_progress_bar(i, self.num_bags)
                # print("%d-th bag mapping..." % i)
                for j in range(self.num_ins):
                    self.full_mapping[i, j] = max_similarity(
                        self.bags[i, 0][:, :self.dimensions], self.ins[j],
                        'rbf2', self.gamma)
            pd.DataFrame.to_csv(pd.DataFrame(self.full_mapping),
                                self.mapping_path,
                                index=False,
                                header=False,
                                float_format='%.6f')
            print("Full mapping end...")
        else:
            temp_data = load_file(self.mapping_path)
            for i in range(self.num_bags):
                self.full_mapping[i] = [
                    float(value) for value in temp_data[i].strip().split(',')
                ]
예제 #2
0
파일: MILDM.py 프로젝트: InkiInki/MILDM
    def __full_mapping(self):
        """
        Mapping bags by using all instances.
        @Note:
            The size of data set instance space will greatly affect the running time.
        """

        self.full_mapping = np.zeros((self.num_bags, self.num_ins))
        if not os.path.exists(self.save_mapping) or os.path.getsize(
                self.save_mapping) == 0:
            print("Full mapping starting...")
            open(self.save_mapping, 'a').close()

            for i in range(self.num_bags):
                print_progress_bar(i, self.num_bags)
                for j in range(self.num_ins):
                    self.full_mapping[i, j] = self.get_bag_ins_sim(i, j)
            pd.DataFrame.to_csv(pd.DataFrame(self.full_mapping),
                                self.save_mapping,
                                index=False,
                                header=False,
                                float_format='%.6f')
            print("Full mapping end...")
        else:
            temp_data = load_file(self.save_mapping)
            for i in range(self.num_bags):
                self.full_mapping[i] = [
                    float(value) for value in temp_data[i].strip().split(',')
                ]
예제 #3
0
 def __generate_ot_bag(self, bag_num):
     print("Generate other class bag...")
     for i in range(bag_num):
         print_progress_bar(i, bag_num)
         bag = []
         bag_size = np.random.randint(self.bag_size[0],
                                      self.bag_size[1] + 1)
         for j in range(bag_size):
             ins = self.data_space[np.random.choice(
                 self.ot_idx)].tolist() + [0]
             bag.append(ins)
         bag = np.array(bag)
         bag = np.array([bag, np.array([[0]])])
         self.bag_space.append(bag)
     print()
예제 #4
0
    def __load_data(self, train):
        flag = "train" if train else "test"
        print("Loading MNIST %s data..." % flag)

        data_loader = mnist_bag_loader(train, self.mnist_path)
        num_data = len(data_loader)

        ret_data, ret_label = [], []
        for i, (data, label) in enumerate(data_loader):
            print_progress_bar(i, num_data)
            data, label = data.reshape(-1).numpy().tolist(), int(
                label.numpy()[0])
            ret_data.append(data)
            ret_label.append(label)
        print()
        return ret_data, ret_label