def get_clustering(data_to_cluster, cluster_model_type, cluster_model_params):
    sw = Stopwatch()
    sw.start()

    if cluster_model_type == 'KMEANS':
        cluster_model = MiniBatchKMeans(**cluster_model_params)
    elif cluster_model_type == 'DBSCAN':
        cluster_model = DBSCAN_w_prediction(**cluster_model_params)

    cluster_model.fit(data_to_cluster)
    cluster_model.X = data_to_cluster

    sw.stop()
    logging.debug('Descriptors clustered into %d clusters.' %
                  cluster_model.n_clusters)
    return cluster_model
示例#2
0
文件: ga.py 项目: lirfu/evopy
    def run(self):
        self.iteration = 0
        self.best_unit = None
        self.evaluations = 0
        self.elapsed_time = 0
        stopwatch = Stopwatch()

        stop_cond = self.params['stop_condition']

        print('===> Initializing population!')
        stopwatch.start()
        self._initialize()
        best_unit = __get_best().copy()
        print('===> Done! ({})'.format(format_stopwatch(stopwatch)))

        print('===> Starting algorithm with population of {} units!'.format(
            len(self.population)))
        while not stop_cond.is_satisfied(self):
            self.iteration += 1
            self._run_step()
        print('===> Done! ({})'.format(format_stopwatch(stopwatch)))
        print(stop_cond.report(self))
示例#3
0
    def run(self):
        iteration = 0
        best_unit = None
        evaluations = 0
        elapsed_time = 0
        stopwatch = Stopwatch()
        stopwatch.start()

        print("===> Initializing population!")
        __initialize_population()
        best_unit = __get_best().clone()
        print_done_with_stopwatch(stopwatch)

        print("===> Starting algorithm with population of {} units!".format(len(self.population)))
        while not self.stop_condition.is_satisfied(iteration, best_unit, evaluations, elapsed_time):
            iteration += 1

            if self.params['elitism']:  # Save the queen.
                new_pop.append(__get_best().clone())

            for i in range(self.params['elitism'] - (self.params['elitism'] ? 1 : 0)):
                parents = __select_parents(self.population)
示例#4
0
# Optimizer
optimizer = optim.SGD(net.parameters(), lr=LEARNING_RATE, momentum=MOMENTUM)
scheduler = optim.lr_scheduler.StepLR(optimizer,
                                      step_size=LR_DECAY_EPOCHS,
                                      gamma=GAMMA)

# Loss function
criterion = Customized_Loss(beta=LOSS_BETA)

# Time measuring
stopwatch_train = Stopwatch()
stopwatch_epoch = Stopwatch()

# Training phase
total_epoch_time = 0
stopwatch_train.start()
for epoch in range(EPOCHS):
    net.log("[Epoch {}]".format(epoch + 1))

    net.train()
    scheduler.step()
    training_losses = []
    num_iters = 0
    stopwatch_epoch.start()
    import itertools
    #for images, ps in itertools.islice(train_loader, 10):
    for images, ps in train_loader:
        ps = ps.to(device=device)
        images = images.to(device=device)

        # Predict the pose