neural_network.perceptron ========================= .. py:module:: neural_network.perceptron .. autoapi-nested-parse:: Perceptron w = w + N * (d(k) - y) * x(k) Using perceptron network for oil analysis, with Measuring of 3 parameters that represent chemical characteristics we can classify the oil, in p1 or p2 p1 = -1 p2 = 1 Reference: https://en.wikipedia.org/wiki/Perceptron Attributes ---------- .. autoapisummary:: neural_network.perceptron.network neural_network.perceptron.samples neural_network.perceptron.target Classes ------- .. autoapisummary:: neural_network.perceptron.Perceptron Module Contents --------------- .. py:class:: Perceptron(sample: list[list[float]], target: list[int], learning_rate: float = 0.01, epoch_number: int = 1000, bias: float = -1, seed: int | None = 0) .. py:method:: sign(u: float) -> int threshold function for classification :param u: input number :return: 1 if the input is greater than or equal to 0, otherwise -1 >>> data = [[0], [-0.5], [0.5]] >>> targets = [1, -1, 1] >>> perceptron = Perceptron(data, targets) >>> perceptron.sign(0) 1 >>> perceptron.sign(-0.5) -1 >>> perceptron.sign(0.5) 1 .. py:method:: sort(sample: list[float]) -> int Classifies a single observation as P1 (-1) or P2 (1). The network must be trained first. :param sample: example row to classify as P1 or P2 :return: -1 if the sample is classified as P1, otherwise 1 >>> data = [[2.0149, 0.6192, 10.9263]] >>> targets = [-1] >>> perceptron = Perceptron(data, targets) >>> perceptron.training() 5 >>> perceptron.sort([2.0149, 0.6192, 10.9263]) -1 .. py:method:: training() -> int Trains the perceptron until it stops misclassifying the training data or the maximum number of epochs (``epoch_number``) is reached, whichever comes first. The epoch cap guarantees termination even if the data is not linearly separable. :return: the number of epochs the network was trained for. >>> data = [[2.0149, 0.6192, 10.9263]] >>> targets = [-1] >>> perceptron = Perceptron(data, targets) >>> perceptron.training() 5 .. py:attribute:: _rng .. py:attribute:: bias :value: -1 .. py:attribute:: col_sample .. py:attribute:: epoch_number :value: 1000 .. py:attribute:: learning_rate :value: 0.01 .. py:attribute:: number_sample .. py:attribute:: sample .. py:attribute:: target .. py:attribute:: weight :type: list :value: [] .. py:data:: network .. py:data:: samples .. py:data:: target