def __init__(self, alpha, threshold, sample, **kwargs): r"""See ``SVMClassifier`` for full documentation. """ Classifier.__init__(self) num_patterns = len(sample) check_svm_classification_sample(sample) self.dim = len(sample[0].pattern) if len(alpha) != num_patterns: raise ValueError('The supplied sample and multipliers vector do \ not have the same size') self.sv_indices = [i for i in range(len(alpha)) if alpha[i] != 0] self.support_vectors = [sample[i].pattern for i in self.sv_indices] self.signed_alphas = [alpha[i] * sample[i].label for i in self.sv_indices] self.threshold = threshold try: self.kernel = kwargs['kernel'] except KeyError: self.kernel = Kernel.get_default()
def __init__(self, dimensions, connections, **kwargs): r""" See ``MultilayerPerceptron`` for full documentation. """ Classifier.__init__(self) self.dimensions = dimensions self.connections = list(connections) try: self.thresholds = kwargs['thresholds'] self.has_thresholds = True except KeyError: self.thresholds = None self.has_thresholds = False try: self.activations = kwargs['activations'] except KeyError: self.activations = HeavisideActivationFunction() MultilayerPerceptron.check_size(self.dimensions, self.connections, self.thresholds, self.activations) self.notify_observers()
def __init__(self, weights, **kwargs): r""" See :class:`Perceptron` for full documentation. """ Classifier.__init__(self) self.__weights = self.__activation = None try: threshold = kwargs['threshold'] self.has_threshold = True except KeyError: self.has_threshold = False threshold = (0,) * len(weights) Perceptron.check_weights_and_threshold(weights, threshold) self.set_weights_and_threshold(weights, threshold) try: self.activation = kwargs['activation'] #activation function except KeyError: self.activation = HeavisideActivationFunction()