#!/usr/bin/python3
"""
Feedforward neural network with hardcoded weights and bias for 2d input
    - input: input two numerical values separated by ","
    - usage: python feedforward_nn.py --input 1,0
"""
import argparse
import numpy as np


def sigmoid(x):
    """Sigmoid activation function: f(x) = 1 / (1 + e^(-x))
    """
    return 1 / (1 + np.exp(-x))


class Neuron:
    def __init__(self, weights, bias):
        self.weights = weights
        self.bias = bias

    def feedforward(self, inputs):
        """ Weight inputs, add bias, then use the activation function
        """
        total = np.dot(self.weights, inputs) + self.bias
        return sigmoid(total)


class NeuralNetwork:
    """
    A neural network with:
    - 2 inputs
    - a hidden layer with 2 neurons (h1, h2)
    - an output layer with 1 neuron (o1)
    Each neuron has the same weights and bias:
    - w = [0, 1]
    - b = 0
    """
    def __init__(self):
        weights = np.array([0, 1])
        bias = 0

        # The Neuron class here is from the previous section
        self.h1 = Neuron(weights, bias)
        self.h2 = Neuron(weights, bias)
        self.o1 = Neuron(weights, bias)

    def feedforward(self, x):
        out_h1 = self.h1.feedforward(x)
        out_h2 = self.h2.feedforward(x)

        # The inputs for o1 are the outputs from h1 and h2
        out_o1 = self.o1.feedforward(np.array([out_h1, out_h2]))

        return out_o1


def main():
    ap = argparse.ArgumentParser(description="[Info] feedforwad neural network with two inputs and fixed weights and bias")
    ap.add_argument("-i", "--input", required=True, type=str, help="2d input array to neural network")
    args = vars(ap.parse_args())
    # parameters
    x = np.array([float(i) for i in args["input"].split(",")])
    # instance
    nn = NeuralNetwork()
    # inference
    y_hat = nn.feedforward(x)
    # decision
    print("Output is {}".format(round(y_hat, 3)))
    if y_hat > .5:
        print("[INFO] it is a dog")
    else:
        print("[INFO] it is a cat")


if __name__ == '__main__':
    main()

#!/usr/bin/python3
"""
Feedforward neural network with hardcoded weights and bias for 2d input
    - input: input two numerical values separated by ","
    - usage: python feedforward_nn.py --input 1,0
"""
import argparse
import numpy as np


def sigmoid(x):
    """Sigmoid activation function: f(x) = 1 / (1 + e^(-x))
    """
    return 1 / (1 + np.exp(-x))


class Neuron:
    def __init__(self, weights, bias):
        self.weights = weights
        self.bias = bias

    def feedforward(self, inputs):
        """ Weight inputs, add bias, then use the activation function
        """
        total = np.dot(self.weights, inputs) + self.bias
        return sigmoid(total)


class NeuralNetwork:
    """
    A neural network with:
    - 2 inputs
    - a hidden layer with 2 neurons (h1, h2)
    - an output layer with 1 neuron (o1)
    Each neuron has the same weights and bias:
    - w = [0, 1]
    - b = 0
    """
    def __init__(self):
        weights = np.array([0, 1])
        bias = 0

        # The Neuron class here is from the previous section
        self.h1 = Neuron(weights, bias)
        self.h2 = Neuron(weights, bias)
        self.o1 = Neuron(weights, bias)

    def feedforward(self, x):
        out_h1 = self.h1.feedforward(x)
        out_h2 = self.h2.feedforward(x)

        # The inputs for o1 are the outputs from h1 and h2
        out_o1 = self.o1.feedforward(np.array([out_h1, out_h2]))

        return out_o1


def main():
    ap = argparse.ArgumentParser(description="[Info] feedforwad neural network with two inputs and fixed weights and bias")
    ap.add_argument("-i", "--input", required=True, type=str, help="2d input array to neural network")
    args = vars(ap.parse_args())
    # parameters
    x = np.array([float(i) for i in args["input"].split(",")])
    # instance
    nn = NeuralNetwork()
    # inference
    y_hat = nn.feedforward(x)
    # decision
    print("Output is {}".format(round(y_hat, 3)))
    if y_hat > .5:
        print("[INFO] it is a dog")
    else:
        print("[INFO] it is a cat")


if __name__ == '__main__':
    main()

#!/usr/bin/python3 Feedforward neural network with hardcoded weights and bias for 2d input     - input: input two numerical values separated by ","     - usage: python feedforward_nn.py --input 1,0 Sigmoid activation function: f(x) = 1 / (1 + e^(-x)) Weight inputs, add bias, then use the activation function A neural network with:     - 2 inputs     - a hidden layer with 2 neurons (h1, h2)     - an output layer with 1 neuron (o1)     Each neuron has the same weights and bias:     - w = [0, 1]     - b = 0 # The Neuron class here is from the previous section # The inputs for o1 are the outputs from h1 and h2 # parameters # instance # inference # decision