DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Join us today at 1 PM EST: "3-Step Approach to Comprehensive Runtime Application Security"
Save your seat
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. MachineX: Artificial Neural Networks (Part 2)

MachineX: Artificial Neural Networks (Part 2)

This article shows us more about artificial neural networks and forward and backpropagation.

Shubham Goyal user avatar by
Shubham Goyal
·
May. 22, 19 · Tutorial
Like (3)
Save
Tweet
Share
5.17K Views

Join the DZone community and get the full member experience.

Join For Free

If you are reading this article, you have probably already read Part 1. If not, you can find it here!

We got a basic understanding of neural networks, so let’s dive even deeper.

Once you got the dataset and problem identified, you can follow the below steps:

  1. Pick the network architecture (initialize with random weights)
  2. Do a forward pass (forward propagation)
  3. Calculate the total error (we need to minimize this error)
  4. Backpropagate the error and update weights (backpropagation)
  5. Repeat the process (2-4) for no of epochs/until error is minimum

Step 1: Pick the Network Architecture

Let's take a toy dataset (XOR) and pick the architecture with 2 inputs, 2 outputs, and 1 hidden of 3 neurons.

Step 2: Forward Propagation

This is an easy process. We need to feed forward the inputs through each layer within the network, and the outputs from the previous layer become the inputs to the next layer (first, we need to feed our data as the inputs).

First, we provide the inputs(example) from our dataset:

dataset (XOR table) 
 X     y
1 1    0 --> X1=1 and X2=1 
1 0    1     H1 = Sigmoid(X1*w1+X2*w2) = 0.5(assume with random                                  
0 1    1                                                 weights)
0 0    0     similarly H2, H3 and O1, O2

Step 3: Calculate the Total Error

Assume random weights and Activation (A1,2…) we get the errors for each neuron.

sum = inputs*weights and A = activation (sum) here Sigmoid (sum)

Out cost function according to Andrew Ng is:

Note: we take partial derivative w.r.t result (by using the Chain rule in calculus)

Step 4: Backpropagation

Don’t worry, it’s easy! Or I will make it easy.

The main goal of backpropagation is to update each of the weights within the network so they cause the predicted output to be nearer the target output, thereby minimizing the error for every output neuron and the network as a whole.

So far, we have the total error, which needs to be minimized.

If you know how gradient descent work, the rest is pretty easy. If you don’t know, here is an article that talks about gradient descent.

We need to calculate the below:

  1. How much does the total error change with respect to the result (or how much is a change in results. We already did in the picture above)?
  2. Next, how much does the result of change with respect to its sum (or how much is a change in sum)?
  3. Finally, how much is the sum of change with respect to weights (or how much is a change in weights)?

And that's it.

Step 5: Repeat Steps 2-4 for Number of Epochs Until Error Is Minimized

We repeat the process of forwarding the weights (FP) and change weights (BP) for the number of epochs or when we reach the minimum error.

Once the training process is completed, we are able to do the prediction by feed-forwarding the input to the trained network.

In the next part, I will build a neural network from scratch.

Stay tuned!

neural network Network

Published at DZone with permission of Shubham Goyal. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Fraud Detection With Apache Kafka, KSQL, and Apache Flink
  • How Do the Docker Client and Docker Servers Work?
  • Real-Time Stream Processing With Hazelcast and StreamNative
  • Java Development Trends 2023

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: