def convert_model(self, drone_model, base_model, datapoints, scaler=None, cache_data=True, epoch_reset=False):
    (datapoints_for_drone, refs) = self.get_refs(base_model, datapoints, scaler, cache_data)
    inflate = 0
    if epoch_reset:
        self._epoch = 0
    avloss = 0
    while ((self._epoch < self._num_epochs) or (self._updatedLoss < avloss)):
        epochloss = []
        for (batchX, batchY) in next_batch(datapoints_for_drone, refs, self._batchSize):
            batchY = np.array(batchY)
            if (batchX.shape[0] != self._batchSize):
                print('Batch size insufficient ({}), continuing...'.format(batchY.shape[0]))
                continue
            preds = drone_model.evaluate_total(batchX, debug=False)
            (loss, error) = dot_loss(preds, batchY)
            epochloss.append(loss)
            drone_model.update(batchX, batchY, self._learning_rate)
        avloss = np.average(epochloss)
        diff = 0.0
        if (self._epoch > 0):
            diff = (math.fabs((avloss - self._losses[(- 1)])) / avloss)
            self._diffs.append(diff)
            self._losses.append(avloss)
            update = 0
            modify = (True if (diff < self._threshold) else False)
            if modify:
                inflate += 1
                modify = (True if (self._updatedLoss == 1000.0) else ((avloss < (self._updatedLoss - (((50.0 * (1.0 - np.exp(((- 0.04) * inflate)))) * diff) * avloss))) and (inflate > 5)))
            if modify:
                update = 1
                inflate = 0
                print('Model conversion not sufficient, updating...')
                print(('Last updated loss: %s' % self._updatedLoss))
                self._updatedLoss = avloss
                if self._add_layer_dynamic:
                    drone_model.add_layer_dynamic()
                elif (self._layer_to_expand is not None):
                    drone_model.expand_layer_dynamic(self._layer_to_expand)
                else:
                    drone_model.expand_layer_dynamic(self.round_robin(drone_model.num_layers()))
                print('Model structure is now:')
                drone_model.print_layers()
            self._updates.append(update)
        print(('Epoch: %s, loss %s, diff %.5f, last updated loss %.5f' % (self._epoch, avloss, diff, self._updatedLoss)))
        if (self._epoch == 0):
            self._losses.append(avloss)
            self._diffs.append((math.fabs((avloss - self._updatedLoss)) / avloss))
            self._updates.append(0)
        self._epoch += 1
    return drone_model
def convert_model(self, drone_model, base_model, datapoints, scaler=None, cache_data=True, epoch_reset=False):
    (datapoints_for_drone, refs) = self.get_refs(base_model, datapoints, scaler, cache_data)
    inflate = 0
    if epoch_reset:
        self._epoch = 0
    avloss = 0
    while ((self._epoch < self._num_epochs) or (self._updatedLoss < avloss)):
        epochloss = []
        for (batchX, batchY) in next_batch(datapoints_for_drone, refs, self._batchSize):
            batchY = np.array(batchY)
            if (batchX.shape[0] != self._batchSize):
                print('Batch size insufficient ({}), continuing...'.format(batchY.shape[0]))
                continue
            preds = drone_model.evaluate_total(batchX, debug=False)
            (loss, error) = dot_loss(preds, batchY)
            epochloss.append(loss)
            drone_model.update(batchX, batchY, self._learning_rate)
        avloss = np.average(epochloss)
        diff = 0.0
        if (self._epoch > 0):
            diff = (math.fabs((avloss - self._losses[(- 1)])) / avloss)
            self._diffs.append(diff)
            self._losses.append(avloss)
            update = 0
            modify = (True if (diff < self._threshold) else False)
            if modify:
                inflate += 1
                modify = (True if (self._updatedLoss == 1000.0) else ((avloss < (self._updatedLoss - (((50.0 * (1.0 - np.exp(((- 0.04) * inflate)))) * diff) * avloss))) and (inflate > 5)))
            if modify:
                update = 1
                inflate = 0
                print('Model conversion not sufficient, updating...')
                print(('Last updated loss: %s' % self._updatedLoss))
                self._updatedLoss = avloss
                if self._add_layer_dynamic:
                    drone_model.add_layer_dynamic()
                elif (self._layer_to_expand is not None):
                    drone_model.expand_layer_dynamic(self._layer_to_expand)
                else:
                    drone_model.expand_layer_dynamic(self.round_robin(drone_model.num_layers()))
                print('Model structure is now:')
                drone_model.print_layers()
            self._updates.append(update)
        print(('Epoch: %s, loss %s, diff %.5f, last updated loss %.5f' % (self._epoch, avloss, diff, self._updatedLoss)))
        if (self._epoch == 0):
            self._losses.append(avloss)
            self._diffs.append((math.fabs((avloss - self._updatedLoss)) / avloss))
            self._updates.append(0)
        self._epoch += 1
    return drone_model