Simulation of Artificial Neural Networks Gaming Project in C++

Explanation

  1. Headers:
    • <iostream>: For input and output operations.
    • <vector>: For using the std::vector container.
    • <cmath>: For mathematical functions like exp().
    • <cstdlib>: For rand() and srand() functions.
    • <ctime>: For time() function to seed the random number generator.
  2. Activation Function:
    • double sigmoid(double x): Computes the sigmoid activation function.
    • double sigmoidDerivative(double x): Computes the derivative of the sigmoid function (not used in this simple example but essential for learning).
  3. NeuralNetwork Class:
    • Attributes:
      • weights: 2D vector holding the weights of the neurons.
      • biases: Vector holding the biases for each neuron.
      • outputs: Vector to store the output of each neuron.
    • Constructor:
      • Initializes weights and biases with random values.
    • Methods:
      • void forward(const vector<double>& inputs): Performs forward propagation by computing the weighted sum of inputs, adding the bias, and applying the sigmoid activation function.
      • void printOutputs() const: Prints the output of the network.
  4. Main Function:
    • Initialization:
      • Creates a NeuralNetwork object with a specified input size and output size.
      • Defines a vector of inputs.
    • Simulation:
      • Runs forward propagation with the example inputs.
      • Prints the network outputs.

Notes:

  • Simple ANN: This example uses a single-layer neural network with randomly initialized weights and biases. It demonstrates basic forward propagation.
  • No Training: This program does not include training or backpropagation; it only shows how to perform forward propagation with a neural network.
  • Activation Function: The sigmoid function is used for activation, which is common in binary classification tasks.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top