Saturday, 17 November 2018

Datarmatics International Coding Festival Comming up...

Datarmtics International Coding Festival Coming up in December.
Program would be provided soon.

Thursday, 15 November 2018

How Bubble Sort Algorithm Works (Implementation in Java)

This would be a very simple explanation with the program in Java on how the Bubble Sort Algorithms works.

Bubble Sort works by iterating through the elements of the array and doing pairwise swap of adjacent elements that are out of order.

We would examine the program in Java and then explain it line by line. The we would actually run the program using Netbeans IDE to see how it works.

The java program is explained as follows: There would be three functions in addition to the main methods

BubbleSort(): This is the function that performs the sorting on an array. This function takes an array as parameter.

    public static void BubbleSort(int[] a)
        int i, j;
        int N = a.length;
        for(j=N-1; j>0; j--) {
            for(i=0; i<j; i++){
                if(a[i]> a[i+1])
                    swap(a, i, i+1);
Listing 1: BubbleSort function

Swap(): This function performs a pairwise swap of two array elements. It take three parameters: the first is the array, the second and third are the indices of the elements to be swapped.

    public static void swap(int[] ar, int x, int y)
        int k = ar[x];
        ar[x] = ar[y];
        ar[y] = k;
Listing 2: Swap Function

Display(): This function displays the elements of the array to the output by looping through the array elements and calling System.out.println().

    public static void Display(int a[])
        int i=0;
        while(i != a.length)
Listing 3: Swap Function

Main(): Runs the program by calling the each of the functions.

    public static void main(String[] args) {
      int a[] = {5,7,3,8,0,2};    //INITIALIZE AN ARRAY WE ARE GOING TO SORT
      Display(a);                 //DISPLAY THE UNSORTED ARRAY
      BubbleSort(a);              //SORT THE ARRAY USING BUBBLESORT     
      System.out.println("The Sorted list is given below:");
      Display(a);                 //DISPLAY THE SORTED ARRAY
Listing 4: Main Program

This short video explains how to put everything together and run it in Netbeans

Monday, 12 November 2018

What is Genetic Algorithm? (A Simple and Detailed Explanation)

Hello guys, I would be happy to give you a clear explanation about the concept of Genetic Algorithm. And this is very interesting because scientists are kind of succeeding in breaching the gab between biology and artificial intelligence.

I would explain the concept in two ways: Simple and clear non-technical overview Some technical details (if you would like to go further!)

You could stop after the first part if you are not a tech pro, but it's alright to take up challenges from time to time.

We would cover the following:
  1. Foundation of Genetic Algorithm
  2. What is Genetic Algorithm?
  3. Why Genetic Algorithm
  4. Phases in Genetic Algorithm
  5. Concept of Heuristics
  6. The Simplified Algorithm
  7. Summary
  8. Final Notes

1. Introduction to Genetic Algorithms (Who did it first?)

Just like you know, the field of technology had made great strides by copying from creation. So you see great inventions actually existed in nature all the while. Take a few examples:
  • Airplanes wings design: existed naturally in birds
  • Air Conditioning Technology: used by termites
  • Antifreeze: existed in some microscopic plants
  • Underwater Breathing technology: used by water beetles
  • Clocks: Many living things keep time naturally
  • Compasses: Used naturally by migrating birds
  • Jet Propulsion: Naturally in squid 
Other are Sonar, lighting, submarines, incubator, electricity and more. For an exhaustive list, you could read chapter 12(Who did it First) of the book 'Creation', published by Jehovah's Witnesses.

The same principle applies to generic algorithm. It is an attempt to mimic the way natural selection occurs  in living things. But what exactly is Genetic Algorithm?

2. What is Genetic Algorithm?

Genetic algorithm is a procedure used in the field of Computer Science and operations research to solve problems of optimization copying the process of natural selection. Genetic Algorithm attempts to generating the best solution by employing operations such as mutation, cross-over and selection.
So the objective is the start with a very large population (or space) and then gradually reduce the size until you have only the best (kind of survival of the fittest)

3. Why Genetic Algorithm?

Genetic algorithm tends to play the same role as Artificial Intelligence. But Genetic Algorithm is sometimes considered to be more robust than AI. This is because, unlike conventional AI systems, GA would adjust on changing inputs and would also be able to handle noisy or fuzzy input. Additionally, GE is able to handle complex problems better.

4. Phases in Genetic Algorithm

Just as was mentioned, GE begins with a large population and gradually reduces it using some heuristics until only the best is left. So let's look at the phases

(a) Initial Population

The process starts with a set of individuals known as the Population. Each individual member of the population represents the solution to the problem that need to be solved. This is the starting point. Each individual is associated with parameters known as Genes which are joined together into a string to form a Chromosome. The set of genes of a particular individual is represented using a string (these set of string represent the chromosome. This is illustrated in the figure below.

Figure 1: Genes, Chromosomes and Population

(b) Fitness Function

The fitness function is the relation that determines how fit an individual member of the population is. There is a fitness score associated with each individual. The more fit an individual is, then the higher the fitness score or vice versa. And the higher the fitness score, the higher the probability that individual will be selected for reproduction to the next generation.

(c) Selection

This is an idea of deciding which member of the existing generation is selected to breed the new generation and this is based on the fitness of that individual. The more fit the individual, the more likely it would be selected. During the selection process, two individuals are selected to serve as "parents" to be used to produce the next generation.

(d) Crossover

Crossover is also called recombination. It is an operation of merging the genetic information from the parents (father and mother) to produce new offspring.
This is illustrated in Figure 2. From the figure, we can see that some of the genes 'crosses-over' to produce new set of genes.

Figure 2: Crossover

(e) Mutation

Mutation just like crossover is a genetic operation. In the case of mutation, the arrangement of the genes in the chromosome kind of alters to produce a totally new chromosome. This happens with very low probability. Evolutionist tent to capitalize on mutation to explain how species evolve into now species. But this is not based on any scientific law.

(f) Termination

Just as you know, an algorithm terminates at some point. This process is also called convergence. So the algorithm repeats until certain termination conditions is reached where the offspring is a new generation is not much different from the previous. At this point not much changes occur and this is called termination.

5. Concept of Heuristics

I would like to mention the concept of heuristics as it relates to genetic algorithms. Heuristics sometimes is called 'rule of thumb'. In case of generic algorithm, other rules  are employed to enhance the process and improve the quality of the final solution.

6. The Simplified Algorithm

I would like to write the simplified algorithm based on what we have discussed so far. This is given in the listing below.

Generate the Initial Population
Compute Fitness
  Perform Selection
  Perform Crossover
  Perform Mutation
  Compute Fitness
UNTIL population converges
Listing 1: Simplified Genetic Algorithm

7 Summary

From this brief discussion, we can see that genetic algorithm claims that you can get a good solution (best members of population) by performing certain operations such as crossover and selection as well as applying certain heuristics. Research in Genetic algorithm is currently being carried out in different areas with the objective of creating better products/processes.

8. Final Notes

We could be sure that there is much dissimilarity in the understanding of what is know and genetic algorithm is natural world and the current trend of research in genetic algorithm. While we can be sure that there is not scientific proof that living organisms evolved into new ones,  the genetic algorithms can be applied today to solve scientific problems and more.

I'll like to thank you for reading and you could let me know if this is been informative for you in the comment box below or the form to the left of this page.

Thursday, 8 November 2018

5 Keys to Getting Project Management Professional(PMP) Certification

I could tell you that of all the certification I've acquired as a Tech Professional, the Project Management Professional (PMP) certification was the toughest to achieve.

This is not tough in terms of just to study effort, but financially as well. I literally spent thousands of dollars as I had to made two international travels (there was not exam center in my country at the time), take the PMP courses as well as join a local PMI chapter.

I sat for the exam twice and passed it at the second sitting and now I would share these five hints with you so you could make it the first time and avoid making the mistake I made. At a different day, I could share my story.

1. Participate in Project Management Activities
2. Set Aside Sufficient Time to Prepare
3. Make Sure You Pass Mock Exams First
4. Write a Full Project Management Plan
5. Complete Reading the PMBOK Guide at Least 3 Times

Let's get started with the first point

1. Participate in Project Management Activities

The truth is that the PMP certification is unique. You really can not memorize the study materials and make it through. You need develop the Project Management mindset. This means that you develop overall view of work role: seeing work activities in terms of cost, resources, budget, schedule, stakeholders, risks etc.
You can only develop this mindset if you get involved to some extent with Project Management activities. So try to reach out to Project Managers in your organization to understand how they do things. You could also leave me a comment below this article if you would need my assistance.

2. Spent Sufficient Time to Prepare

I would recommend you make out at least 6 months for preparation. This means that you could use about 1 hour everyday to read and study for the exam. Remember you have much to learn includes some aspects of cost analysis, so you need some time to get your head around these things.

3. Make Sure you Pass Mock Exams First

The rule of thumb here is simple: 'if you have not passed the mock exams satisfactorily, then don't attempt the real exam'.
The current passing score for the PMP  exam is 80.6%! That is quite high considering the fact that the questions are scenario-based and not easy. Therefore you need to score about 90% on your mock exams a number of times, before you can say you're ready to go for the PMP exam.

4. Write a Project Management Plan

This may actually be the most tasking part of your prep effort. But Trust me, this is a key  to success in the PMP. A Project Management Plan is a document that defines how a project would progress. It contains every bit of details about the project activities.
So go read up Project Management Plan and develop one for a hypothetical project. You could let me know if you have challenges using the form to the left of this page.

5. Complete Reading the PMBOK Guide at Least 3 Times

The PMP exam is based on the PMB Guide, but note that it's just a guide to help you understand the concepts of Project Management. However, the questions are based on how you can apply the concepts in real work scenario. So step 1 is to know the concepts which are actually covered close to 100% in the exam.
I'm sure that with the right effort and motivation, you will make it through the PMP certification path.

I wish you success in your efforts!

Wednesday, 7 November 2018

Java Progamming For Beginners Lesson 3: Your Second Program (Java Basic Syntax)

In this Tutorial 3, we would write a second program and also understand java basic syntax. In Tutorials 1 we installed NetBeans which is the compiler you will be using.
In Tutorial 2, we wrote our first program.

Let's start with a little exercise. (Your Second Program)
Write and run the program below. You already know how to create Java application in NetBeans.

    public static void main(String[] args) {
      String name = "Kindson The Genius"; //You can replace Kindson The Genius with your own name
      String title = "Researcher";
      String location = "Europe";
      int duration = 1;

      System.out.println("My Name is "+ name );
      System.out.println("I am a " + title );
      System.out.println("I live in " + location);
      System.out.println("I have stayed here for " + duration + " year");
Listing 1.0: Your Second Program

If you have written it correctly and run it, the window would be as shown in Figure 1 below.

Figure 1

Let's understand a few things about the program above

1. The first four lines following the main line show a declaration of four variables. The first 3 are strings while the last one is an integer(number). A variable is just a memory location to hold values.

      String name = "Kindson The Genius"; //YOu can replace Kindson The Genius with your own name
      String title = "Researcher";
      String location = "Europe";
      int duration = 1;
Variable declaration in Java

2. Note in the first line that there is a part that starts with // You can replace... This is example of a comment. The compiler ignores comments. Comments are what you add to a program to explain it to someone reading it. The compiler does not execute it.

//YOu can replace Kindson The Genius with your own name
Example of comment in Java

3. Note the use of + sign in the last four lines. This plus sign is called 'concatenation operation' (say in 5 times!). It is used to combine two variable together into a string.

      System.out.println("My Name is "+ name );
      System.out.println("I am a " + title );
      System.out.println("I live in " + location);
      System.out.println("I have stayed here for " + duration + " year");
Concatenation in Java

4. Also note that part of the statement to be printed is enclosed in double quotes. This is called string literal. The next part not enclosed in quotes is called variable (can be string variable or integer variable)

Try to digest this all that have been mentioned here and then Tutorial 4 would be out is couple of days.

Tutorial 1: Introduction to Java and NetBeans Installation
Tutorial 2: Write Your First Java Program in NetBeans

Tuesday, 30 October 2018

Top 10 Free Machine Learning Papers Every Student Researcher Must Read

I have made a list of this 10 research paper I believe very student and researcher in area of Artificial Intelligence and Machine learning must have.

You could learn about how the following is applied: Neural Network, Deep Learning, Convolutional Neural Network, Recurrent Neural Network, Learning algorithms and more

I have provided the links to download this papers for free:

I also found some really good papers that are not free and I'm trying to reach the authors to see if they could make it available to researchers based on some bargain. I'll let you know once it's done.

1. "Show and Tell: A Neural Image Caption Generator".  
In this publication, the authors create a model for image captioning using deep recurrent neural network architecture by applying computer vision and machine translation.
Download this paper

2. "Deep Residual Learning for Image Recognition"
This paper examines the benefits of residual networks which improves accuracy of prediction using increased depth.
Download this paper

3. "A Review of Deep Learning"
This paper is a comprehensive review of Deep Learning as well as application of deep learning is various fields such as image recognition and processing, speech recognition, video and text processing.
Download this paper

4. "Computer Vision Based Date Fruit Grading System: Design and Implementation"
This is a design and implementation research work for a prototype fruit grading system based on computer vision. The system performs feature extraction and then uses a classifier to grade the dates into three pre-defined classes.
Download this paper

5. "Improving Quality Inspection of Food Products by Computer Vision"
This Paper describes a system of adopting computer vision approach to the food industry. Image recognition is used to analyse the quality of different categories of food (bread, milk, pizza, chocolate etc) and assign quality ratings to them.
Download this paper

6. "Machine Vision System for Food Grain Quality Evaluation: A review"
The research proposes the use of machine vision based systems as a replacement for visual methods of inspection.
Download this paper

7. "Fast and Accurate Deep Neural Networks by Exponential Linear Units (ELU)"
This research paper highlights the adoption of "exponential linear unit" as a means of  improving the learning process of deep neural networks. According to the authors, exponential linear units provides better performance than rectified linear unit (RELU) in terms of learning rate and generalization performance.
Download this paper

8. "Application of Counterpropagation Networks"
This introduces a completely novel learning algorithm - counterpropagation as a better alternative the existing algorithms like backpropagation for neural networks.
Download this paper

9. "Exploring Strategies for Training Deep Neural Networks"
The paper focuses on experiments to analyze the performance of various training algorithms as well as relationship between the depth of the network and quality of the model.
Download this paper

10. "Deep Speech 2: End-to-End Speech Recognition in English and Mandarin"
This publication explores a method of recognizing natural language building a Neural Network based model for handling different variation of speech including noise-filtering as well as accent and language variations.
Download this paper

Disclaimer: This papers does not belong to me ( but it's provided by the owners for free. I simply provide links in this website( to the location of the publications and I bear no responsibility with respects to the use of this publications.

Saturday, 27 October 2018

How I Lost My Programming and Machine Learning Research Studio in Nigeria

I still cry when I remember what I lost in the in Nigeria couple of months before I relocated to Budapest.
It's a very long story but I would just tell you a summary of it.

  1. Activities Carried out in the Studio
  2. Studio Equipment
  3. How I Lost Everything
  4. The Aftermath

I started building this research studio by late 2016 in my apartment in Port Harcourt Nigeria, and completed it by early 2017 and I wish I could explain better how much I values this studio. And just as you know, it is a home studio. I actually demarcated the living room(because it has much space) into two parts and used one part for the studio

1. Activities Carried Out

Some of the activities carried out in this studio include:

  1. Training: Online training sessions are conducted for my subscribers and local students
  2. Mobile Application Development/Testing: I worked on a number of Mobile applications for android and IOS 
  3. Tech Video Production: Tutorial videos are produced in this studio for 'The Tech Pro' and 'Kindson The Genius' channel
  4. Research on Artificial Intelligence, Machine Learning, Deep Learning and other related topics
  5. Writing Tech blogs for
  6. Reading, studying etc.

2. Equipment in the Studio

  • Hp Server
  • Magnetic Board
  • IPhone for testing mobile apps
  • IPad for testing Mobile apps
  • Macbook for XCode Development
  • 3 Windows Laptops for .Net and Android Programming
  • Recording Equipment
  • Network Accessories
  • Monitors etc

3. How I Lost Everything

On the night of August 8, 2017, same day I came back from Abuja where I went to the Hungarian embassy for an interview on my visa application. It was a quite night just like every other night.

There were 5 of us at home. Jadon and Shola slept in the second bedroom, Ishuka was in the living room while I was in my bedroom.

What I could remember was a voice in my room (sounded like a dream) asking: "Where is the money?" Before I could raise my head from the bed, I felt the nose of the gun in my neck. So I clearly realized what is happening and simply followed instructions. Now I can't continue with any details.

At the end of about 20 mins when everywhere was calm, we all came out. That was when I realized that almost everything I labored for to build my studio are gone. Phones, tablet, cash, laptops etc

4. Aftermath

Went to the police and all that stuff, but no results. I simply have so auction and give away what was left of my vandalized studio/lab.

The worst part of it all was that I was so much demoralized and lost all motivation for learning and research and I could tell that even now I've not recovered from that night's ordeal. And neither have I recovered from all the valuables that was stolen that nigh. I wish I could still have my home lab again.

Thursday, 25 October 2018

Learn About Cross-Site Request Forgery (CSRF) Attack

In this brief article, I will explain to you how the Cross-Site Request Forgery attack works in a very simple and easy-to-understand way.

We would cover the following topics:
  1. Introduction
  2. Use of HTTP Cookies
  3. How Cookies are Created
  4. Use of HTTP Authentication
  5. What is Cross-Site Request
  6. Steps in CSRF Attack
  7. Recommendation for Protection

1. Introduction

The CSRF attack works by exploiting existing authenticated user sessions. For example, user does not log out of a web portal and visit another site or opens another tab. So he browses another site while the authenticated session is still active.

First let me explain how websites maintain authenticated web sessions:
  • Use of HTTP Cookies
  • Use of HTTP Authentication Credentials (Authentication Tokens)

2. Use of HTTP Cookies

Cookies are text data that the web server sends to the browser. The browser keeps cookies on the client computer and attaches them to subsequent requests made to the web server that sent them.

3. How Cookies a Created

A cookies is created after a website has authenticated a user. In this case the website sends back a cookie that contains a 'session ID' that is unique to that user session. This is what is known as authentication cookie. So every request coming from the user with this authentication cookie is interpreted as coming from the user who has this session.
However, when a website sends a cookie to a browser, the website also provides and 'expires' attribute together with other attributes. The expires attribute indicates the validity period of the cookie of which the cookie is deleted after thee validity period. If the expires attribute is lacking, then this type of cookie is known as session cookie and is normally deleted when the user closes the browser window. Cookies that comes with an expires field are known 'persistent cookies'.

4. Use of HTTP Authentication

This is a somewhat more secure mechanism used in intranet environments and does not make user of cookies.  In this case, when a site is visited by a user, a popup is displayed that requests for user credentials. After the user submits the data, the credentials are encrypted and sent to the server using what is known as authorization request header.
When later the user visit other web pages in the same intranet, then the browser automatically sends the credentials along with the request in the Authorization header.

5. What is Cross-Site Request?

Cross-Site request occurs when a site contains a redirection to another site. In this case, a HTTP request sent to site A could also generate a HTTP request to site B. This is provided in form of hyperlinks in the first site.
So when a user clicks on link or button included in a web page, then the link may actually be directing an external website.

6. Steps of CSRF Attack

Generrally, the CSRF attack exploits the vulnerability of cross-site request for malicious intents. This is how it works:
  • User visits his banks website( and does a transaction.
  • He visits another website without logging from his banking portal
  • creates and submits a request to using the users active session. On sending this request, the user's browser attaches the valid authentication cookie to the request
  • The website interprets this request as coming from the user and processes it.

At this point, the website takes over subsequent communication with so long as the cookie is active. This is illustrated in Figure 2

Figure 2: How CSRF Work

7. Recommendations for Protection

Since this article is for everyone, I would not discuss the the defenses in this article against CSRF as these would require some technical details. I would however like to make the following recommendation which applies to everyone to help you ensure some security.
  • always ensure you log out after using a secure application
  • close the browser window after using a secure application such as you banking website.
  • shut down your system at least everyday as this erases the cookies stored in the system.

Wednesday, 24 October 2018

How Does Single-Sign-On (SSO) Work?

I'm KIndson the Genius and in this short explanation, I would teach you how Single-Sign On (SSO) work.
We would cover the following:

1. What is Single Sign-On

Single Sign-On is a technology that allows a user to log in using a single login page and afterwards have access to different applications and services automatically without having to enter their usernames and passwords repeatedly.

It is normally used in organizations where there is a plethora of applications and services that employees need to use for their daily activities. In this case, for many enterprises, the user logs into his computer using his active directory account and then when he accessed relevant applications in the company's intranet, he is logged in automatically and does not need to enter his credentials.

2. How SSO Work (A Beginner's Explanation)

User login credentials are maintained in a central server (maybe active directory or any other server). This server is called Identity Provider (IdP).
Other applications and services are connected with this IdP.

So what happens is that when you tries to use any of the application connected with the IdP, then that application checks with the IdP to make sure that you are authorized to access the application.
If you are authorized, then that application receives an access token that allows you to access the data you want.

3. Steps of Single Sign-On

The steps in single sign-on is  illustrated in Figure 1.

  1. Client tries to access a secure service. If he already have an access token for the service, then token is added to the request. Then go to step 10
  2. Service connect with IdP to authenticate client
  3. IdP request for user login credentials
  4. Client displays login page to user
  5. User enters login credentials
  6. Client sends the credentials to the IdP which verifies the credentials
  7. If credentials are valid, then Identity Token (IdT) is sent to the Authentication Server (AS). Else return to step 3
  8. AS creates access token and sends back to the client
  9. Client tries to access the secure service using the access token
  10. Service grant client access to the secure service
At this point, the SSO is successfully completed.

Wednesday, 17 October 2018

OAuth 2.0 Authorization Process(Code Grant Flow)

Hello, as you already know, I'm Kindson The Genius and I'm here to help you understand tech concept very easily. You let me know what you would like to learn.

Today I would just outline the OAuth 2.0 Authorization Process, that is the steps and the flow diagram. No much details though.

Find more details here: What is OAuth and OpenID
Video explanation: Vidoe explanation

OAuth 2.0 Authorization Steps
Step 1: User visits a websit eg. (App)
Step 2: App asks user for authentication though Facebook
Step 3: A consent screen is displayed to the user and user accepts to allow access
Step 4: IdP sends a code to the user (IdP stands for Identity Provider)
Step 5: User sends to code to the App via a redirect link
Step 6: App request for access token from the IdP using the code it has received
Step 7: The IdP checks the access code is valid and then send the access token to the App.
Step 8: App then requests access to restricted resources in the resource server by presenting its access token.
Step 9: Resource server checks with the IdP to make sure access token is valid and then grants access to the resources.

  • The flow may  have some variations depending on the particular implementation
  • The IdP is also known as the Authorization Server
  • The IdP and the Resource Server are sometimes in the same place.
Find more details here: What is OAuth and OpenID?
Video explanation: Vidoe explanation

Tuesday, 16 October 2018

What is OAuth? (An Introduction to OAuth and OpenID)

My name is Kindson and in this brief, lesson I would teach you the basics of OAuth 2.0 and OpenID. You will understand what they are and how they work very clearly.

You can watch the video explanation here

We would cover the following:
  1. What is OAuth?
  2. How OAuth Started
  3. OAuth Roles
  4. The OAuth Workflow
  5. Benefits of OAuth
  6. What is OpenID?

1.0 What is OAuth

OAuth is an open standard for authorization which is used for access delegation. This means that users of a web application can grant an application access to their information without having to give them the login credentials.
OAuth provides a secure delegated access to the user's information on behalf of the user.

2.0 Why OAuth was Introduced

Before OAuth 1.0 protocol was published in 2010 access delegation was achieve by providing the third party application with your the login credentials(username and password). This creates a security challenge as there is no control of what the third party application can do with these details. OAuth was created to address this issue.
So in 2010, the OAuth 1.0  protocol was published after a group of researcher have worked on it for about 4 years.

3.0 OAuth Roles and Terminology

Before we explain how it works, it is necessary to understand the roles associated with the OAuth architecture
Resource Owner: This is the user of the resource or the owner of the account the application is requesting to access.
Client: This is the application the requests access to restricted resources.
Authorization Server: Holds account information and used for authorisation.
Resource Server: Contains secure information that need token to access
Authorization Grant: The initial code sent to the requesting application initially. The is the same as the authorization code and is passed through the front channel(browser)
Redirect URI: This is the URI that the would be redirected to after the authorisation grant have been given to the application.
Access Token: The token that is sent to the application and can be used to access resources.

4.0 The OAuth Workflow

The OAuth workflow take the following steps to grant a delegated access to an application:

Step 1: The application request for authorization for access to some resource
Step 2: The authorization server creates and displays a consent screen to the user
Step 3: If the user consents to the request, then the authorization server sends an authorisation code (authorisation grant) back to the requesting application.
Step 4: The application then requests for an access token from the authorisation server using the authorisation code
Step 5: The authorisation server identifies the application and checks if the authentication code is valid. If it's valid, the server issues an access token to the application.
Step 6: The application can now access resources from using the access token
Step 7: If the access token is found valid, the resource server grants the resource to the application.
At this point the cycle is complete. The workflow is shown in Figure 1.

5.0 Benefits of OAuth 2.0

It provides a stronger security and easier to implement
It is an open standard
It is a very robust protocol that relies on SSL (Secure Socket Layer) making data very secure
Allows for expiration of authentication token which make resources more secure
Login credentials are not passed to the requesting application

6.0 What is OpenID

What then is OpenID?
Note that OAuth is a standard for authorisation. OpenID on the other hand is used for authentication to authenticate a single-sign on identity. It is created to be used for federated authentication. This means that a third party can be used to authenticate a user if the users already have some account.
While OAuth can be used for authentication too, that is not what it's designed for. OpenID does that.
There comes OpenID Connect(OIDC) which is an authentication protocol based on the OAuth 2.0 and serves an authentication layer on top of OAuth 2.0.

I hope these brief explanation clarifies the concept.
You can watch the video explanation here

Friday, 12 October 2018

ML.Net Tutorial 2: Building a Machine Learning Model for Classification

This is the Tutorial 2 ML.Net series of tutorials. These tutorials would help you understand and build machine learning models in .Net very easily if you are already a .Net developer.

If you are not a .Net Developer, you could check my tutorial in Machine Learning with TensorFlow using Python.

You could also learn Difference Between Machine Learning and Deep Learning. This tutorial follows from Tutorial 1  where you downloaded your dataset, setup the Visual studio solution and added the ML.Net package to the solution

Take the following steps to create your Machine Learning Model.

Understand the DataSet

Open the iris-data file and view the data. Note that each record is made up of five fields. The first four fields are the features while the last field is the class the iris belongs.
This means that based on the value of the features(SepalLength, SepalWidth, PetalLenght, PetalWidth) we could predict whether the iris belongs to one of the three classes(Iris-setosa, Iris-versicolor, Iris-virginica)
This scenario is a typical classification problem.

Step 1: Class Classes that map to the Dataset

In this step, you need to create the two classes that represents your dataset. The first class represents the features and the second class represents the class.
The codes for the two classes are given below. You will write this code in the Program.cs file.

        //STEP 1: Define your data structure. That is clases to hold the data
        public class IrisData
            public float SepalLength;

            public float SepalWidth;

            public float PetalLength;

            public float PetalWidth;

            public string Label;
Listing 1.0: IrisData class maps to the features of the dataset

The second class shown below just has one attribute that maps the class name (the last field in the dataset)

        //IrisPrediction is the result returned prediction by the model
        public class IrisPrediction
            public string PredictedLabels;
Listing 1.1: Class to hold the prediction

Step 2: Create a Pipeline and Load the Data

What is a Pipeline? A pipeline is a set of classes in ML.Net that allows you to load external data, transform it to format suitable for training and train the model.
Use the code below to load the Iris data set.

      var pipeline = new LearningPipeline();
      string dataPath = "iris-data.txt";
      pipeline.Add(new TextLoader(dataPath).CreateFrom<IrisData>(separator: ','));
Listing 1.3: Create a pipeline and load your data.

Step 3: Transform the Data

Data needs to be transformed from string data to numeric data since training can only be carried out on numeric data. So the column labels are assigned numbers. This is achieved by using a Dictionarizer object
Next the we need to use a ColumnConcatenator to merge all the features into one single string as shown in Listing 1.4.

     pipeline.Add(new Dictionarizer("Label"));
     pipeline.Add(new ColumnConcatenator("Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"));
Listing 1.4: Transform the data

Step 4: Add a Learning Algorithm

Here we add a learning algorithm that can train a classification model. This algorithm is the StochasticDualCoordinateClassifier object.
Then we convert back the numeric label into the original text using PredictedLabelColumnOriginalValueConverter object.

     pipeline.Add(new StochasticDualCoordinateAscentClassifier());
     pipeline.Add(new PredictedLabelColumnOriginalValueConverter() { PredictedLabelColumn = "PredictedLabel" });
Listing 1.5: Add a learning algorithm and covert back

Step 5: Train the Model

In this step, we simple call the Train() method of the pipeline object to train our model. This is achieved by a single line of code shown in Listing 1.6.

     var model = pipeline.Train<IrisData, IrisPrediction>();
Listing 1.6: Train the model

Step 6: Use the Mode to Make Prediction

Now we can now test the model by passing new set of features and then allow the model to predict the class it belongs.
The code is given in Listing 1.7, but you can change the values to see what result you get.

        var prediction = model.Predict(new IrisData()
            SepalLength = 0.3f,
            SepalWidth = 0.6f,
            PetalLength = 1.2f,
            PetalWidth = 1.1f

        Console.WriteLine($"Pridicted flower class is : {prediction.PredictedLabels}");
Listing 1.7: Making prediction with the trained model

The output of this is shown in Figure 1.0

Figure 1.0: Final  Output

Final Notes

If you have come this far then be sure you now know the basics of How to Build a Machine Learning Mode using ML.Net.
This is really interesting for .net developers as you don't need to learn how to use other tools like TensorFlow in Jupyter notebook and the Python Language.
We continues with Tutorial 3.

Subscribe to the Kindson The Genius Video Channel so you get notified when new lessons are made.