Skip to main content

Newton–Raphson method - Introduction

This page only deals with the algorithm theory for example of this theory 

check out  

newtons-raphson-method-for-arriving-at.html

 

Alright  the theory says for a function 

y = x - a , the optimization of parameter ' x ' where y = 0 /close to zero

a technique  used for optimization of parameters in machine learning problem,

 consider a = 5 , x = 5 , y will be zero but this case is not straight forward 


the value for x is obtained using Newton–Raphson method, which is via iteration

says  xn+1 = xn - f(x)/f '(x)

 f(x) = y = x- a

f '(x) = partial derivative of x  = dy/dx = 1

consider 2 iterations here n =0 ,1

it starts with assuming a initial value for x which is n =0

x0  , y0 plotting the values in graph


 from the graph u can see i have plotted the x0, y0 

tangent line to the point cuts the x - axis at x1 where the y is '0'

says loss is zero at iteration x1, u may now wonder the the value

of X has moved from X0 to X1 minimize the value of X where the loss here y =0.


U might be still confused why all this talks don't worry will try to explain in detail

OK is i said i will start with assumption for x0

then how to move on or arrive at x1 or some other direction or some other point x2....xn

this is a blinder , according to the theory and the diagram 

there is a triangle  formed ,which is a right angled triangle ,OK then

I started with X0 ,then Y0 ,then finding the tangent 

meaning the tangent line which is a line equation ,don't worry if u don't have an idea of line equation jus stay with me 

 tangent line eq y = mx + b 

y0  = m* x0 +b 

 what is ' m ' ,it is called the slope of the above line 

by formula m = y2-y1/x2-x1

here we have x0 , y0 , next iteration x1 , corresponding y 1

so m = y1- y0 /x1- x0  

 

alright the equation of the curve is y = x -a

what is the slope of the equation which is the partial derivative 

so dy/dx  = 1 

now the step is to find the next iteration value that is x1 , y 1 

from the know values that is x0 , y0 and the slope which we found using

derivative ,so why all these drama ,the idea to find

line equation of the tangent line y = mx +b that passes through (x0, y 0) 

ok then y0 = m * x0 + b

since the slope is 1 which is m =1 

y 0 = x0 +b ,here value of b is the y -intercept ,don't worry y- intercept is nothing

but the tangent line cuts the y -axis at some value which is our case is 'b ' 

see the diagram below ,how we values are arrived one by one




jus a recap 

1 . random  x0 , get the yo from y = x-a

2. find the tangent line equation 

3. find x1 

since slope m = y1-y0/x1- x0 

re arranging the equation x1 -x0  = y1 -y0 /m

m is the derivative dy/dx or f '(x) ,so 

x1 = x0 +  (y1- y0)/f' (x)

since from the findings we have y1= 0 from the graph 

x1 = x0 + (0 - y0)/f '(x)

y0 = f(x0) 

x1 = x0 - f(x0)/ f '(x) is the Newton–Raphson method.


check out the sample page too for a better understanding of the equation

and the results.

in the upcoming lessons we will talk about failures of the method.




Comments

Popular posts from this blog

Node and Auth0 - Integration

 so now we have completed all the steps for integration  since we have the node and auth0 as two separate things the integration happens in the app.js  we need to modify the app.js with some auth0 code  app.js / const http = require('http'); const express = require('express'); var router = require('express').Router(); const { auth } = require('express-openid-connect'); const app = express(); app.use('/', router); const hostname = '127.0.0.1'; const port = 3000; http.createServer(app)   .listen(port, () => {     console.log(`Listening on `);   }); const config = {   authRequired: false,   auth0Logout: true,   secret: 'a long, randomly-generated string stored in env',   baseURL: 'http://localhost:3000',   clientID: 'QxpAXsXkzy0Vm2VdT6dFFS0VOKdrah67',   issuerBaseURL: 'https://dev-bnga041p.us.auth0.com' }; console.log(config) // auth router attaches /login, /logout, and /callback routes to the baseURL app.u

Auth0

You might be wondering what is this auth0  it is used for authentication of you applications  could be any apps  1.SPA - Angular , React  2.web app 3.Node  here we will talk about the node use case and go with example  moving ahead for now  if your are not familiar with node dont worry its a funny exercise for now walk with me  we dont have to worry too much for authentication as the service is  provided from auth0   create your node app  install node  https://nodejs.org/en/download/package-manager/  choose your os and do the installation once installed check for the version ' node -v  ' i assume u have installed so that u wil get the version for now  since iam using LINUX this will look like root@strings-desktop:/home/strings/js# node -v v16.13.0 moving on to creating node app for now    create a file app.js and paste the contents  app.js/ const http = require('http'); const express = require('express'); const app = express(); const hostname = '127.0.0.1&#