<jupyter_start><jupyter_text>Implementation of a simple neuron<jupyter_code>import numpy as np

class Neuron(object):
    """ A simple neuron.
    Args:
        num_inputs(int) : The size of input vector
        activation_fn(callable) : The activation function used
    Attributes:
        W (ndarray): The weight array.
        b (float): The bias value.
        activation_fn (callable) : The activation function.
    """
    
    def __init__(self, num_inputs, activation_fn):
        super().__init__()
        # Random initialization of weights and bias values
        self.W = np.random.rand(num_inputs)
        self.b = np.random.rand(1)
        self.activation_fn = activation_fn
        
    def propagate(self, x):
        """ Forward Propagation of input in the neuron"""
        z = np.dot(x, self.W) + self.b
        return self.activation_fn(z)<jupyter_output><empty_output><jupyter_text>Instantiation of a neuron<jupyter_code>np.random.seed(5)

# Random input column vector x

x = np.random.rand(3).reshape(1,3)
print(x)


def sigmoid(z):
    """ A famous activation function."""
    
    return 1/(1+np.exp(-z))

# Instantiation of neuron

neuron = Neuron(num_inputs=x.size, activation_fn=sigmoid)
print("Neuron Weights (Random) : ", neuron.W )
print("Neuron Bias (Random) :", neuron.b)

out = neuron.propagate(x)

print("Predicted output is : ", out)<jupyter_output>Neuron Weights (Random) :  [0.51841799 0.2968005  0.18772123]
Neuron Bias (Random) : [0.08074127]
Predicted output is :  [0.62082841]
{'fraction_non_alphanumeric': 0.11865524060646011, 'fraction_numerical': 0.03361898483849703, 'mean_word_length': 3.276056338028169, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '560108', 'license': 'MIT', 'n_tokens_mistral': 556, 'n_tokens_neox': 508, 'n_words': 127, 'path': 'TensorFlow2/1-ArtificialNeuralNets/Neuron.ipynb', 'repo_name': 'kartik4020/DeepLearning-EarlySteps', 'size': '1517'}