Friday, 24 November 2017

Moore-Penrose Pseudoinverse

Generalization of the inverse of a matrix.

I believe, we pay too much attention to implementation, and too less
attention in the study of the concept that is implemented. I have been
on then teams of many Data Science and Machine Learning projects, and
I would always reiterate on one simple idea; that is, “If you do not
know the math, you don’t know it at all.”
This is a piece of philosophy I deeply believe in. With the advent of packages like numpy, matplotlib, scikit-learn etc., implementing a machine learning model with a moderately difficult data set and problem is fairly simple.
The magic then stays in being able to tweak the algorithm and getting something new (or weird) out of the model. And, for you to be capable of doing so, you will have to know the mechanism behind it.
The Moore-Penrose pseudoinverse in the soul of PCA (Principal Component Analysis), one of the most popularly used Dimensionality reduction techniques.


How do we define the inverse of a matrix?
Provided that the matrix is a square matrix and non-singular, we simple divide the adjoint of the matrix with its determinant.
Mathematically, for and , the inverse of is defined as,




Of course, the above method is computationally very expensive. Hence, we can get the inverse of the matrix recursively using the Fadeev-LeVerrier equation ( Read about that in this blog of mine).


Now, how do we deal with matrices that are non-square? How do you find the inverse of a matrix that looks like this,

This is where the Generalization of inverse of a matrix happens, named the Moore-Penrose Pseudoinverse.


For every , there exists a pseudoinverse . ( is read as “A dagger”).
is mathematically defined as,

This is dimensionally consistent. Please check and verify.


Now, say we have,

It is impossible to find by the conventional method . So, we use the Generalized Inverse at .
So,

So, comes out to be . So, comes out to be .
Hence,
which is the pseudoinverse or the generalized inverse.


For a square matrix (i.e., ),

In detail,



Some properties of the generalized inverse are,
1.
2.
3.
One important point to remember is, always exists and is unique.



Cheers!

Friday, 17 November 2017

The Linear Quadratic Regulator

Optimal Control and Linear-Quadratic-Regulator (LQR)

Today, I will not write an introductory passage to write off my blog. Because, writing an introduction to Optimal Control in itself will required a blog. However, I will add in small tidbits as and when needed.
To understand the topic, we need some basic definitions with us.

1.
A control system can be represented in terms of State Space, as follows,

In the above formulation,
is the state vector; .
is the output vector; .
is the input vector; .
is the System Matrix; .
is the Input Matrix; .
is the Output Matrix; .
is the Feed-forward Matrix; .
Now, for a system to be controllable, we first define a matrix , called the controllability matrix, such that,

The system is controllable if has full row rank (i.e. rank() ).

We will assume that we deal with Controllable systems only.

Usually, a single input system’s state feedback controller is designed using the Eigen-value method, or Pole Placement method.

2.
Pole placement method is the methodology of finding the control vector in the form
So, the state space representation changes as,

is found as,

Here, are the desired pole locations. Note that is defined as

However, for a multi-input system the feedback gain i.e. is not unique.
Linear Quadratic Control strategy is used to deal with this issue.

Now, we dive into the Linear Quadratic Regulator (LQR) formulation, for an -input and -state system with ,. Consider a system,

Our aim is to find an open loop control , for such that we minimize:

where and are symmetric positive semi-definite matrices.
is a symmetric positive definite matrix. Note that , and are fixed and given data.
The controller aim is to basically keep close to 0 especially at , which is the final time.
In ,
  • works against the transient response.
  • works against the finite state.
  • works against the control effort.
The above formulation can regulate the output near .
Note that, we can define, and as where,
We can now have a theorem as follows,
For a system with fixed initial and final conditions, ; and clearly . We define our time horizon as such that . We find such that our cost function, is minimized. is defined as,

Here, the first term of is the final cost and the second term is the recurring cost.


Now, we will formulate some important functions that will convert the which is a constrained optimal control problem to a unconstrained optimal control problem. [THIS MAY NOT MAKE SENSE TO YOU, WHICH IS NATURAL. HOLD ON].

Note that, ( ) is called the Lagrangian.
is the Hamiltonian operator. Defined in terms of and as in . Or it can be defined as,

The above definition is in terms of as defined in the theorem. So, we define in the same lines. Just for convenience of computation.

can be written as
Equation , and together form a set of differential equations (in and , obviously) with split boundary conditions at and . Now, we can easily define in terms of or/and .
As mentioned earlier, the solution is found by converting from a constrained optimal problem to a constrained optimal problem using a Lagrange multiplier function :

Notice that,

Therefore,

As the Hamiltonian Function is defined in , thus,

The necessary condition for an optimal solution is of the modified cost with respect to all variations of the system be minimal at all times from to .
We will define analytically in the next post and formulate the Riccati Equation that will lay the foundation to some amazing control strategies.
Cheers!

Sunday, 5 November 2017

i!

Define the Factorial of a Complex number.

In usual sense, factorial is defined as,

Now, the not so usual definition is based on the famous Gamma Function,

There is an unique and very useful property,

To extend into the complex domain, we will first have to go through Analytic Continuation, please read about Analytic Continuation here.
Therefore, after analytic continuation, we can write it as,

For,
So, now, clearly,

By

Clearly,

For easier computation, please catch that,

Let’s break it down,


If you have reached this far, you obviously know how to solve the above integral.
Cheers!

Saturday, 26 August 2017

A new Kilogram? What? How?

A new Kilogram? What? How?

To understand this, let us see how time is defined. We all know the SI unit of time is seconds, and it is defined as the international unit of time, the second, is defined by measuring the electronic transition frequency of caesium atoms. Similarly length (SI unit metre) is defined as the length traveled by light in seconds or to be more precise seconds.
The inspiration to write this blog was derived from Veritasium|How We’re Redefining the kg.
We see that, all these are fundamental quantities are define on a given/fixed standard.
However, the kilogram is set as the weight of a metal cylinder in Paris. That is not that ideal, huh!
So, the NIST is trying to define the unit of mass, i.e., kilogram using some already standardized quantities like the Planck’s constant and the Avogadro’s number. The Planck’s constant takes a dive into advanced applied physics (no, not Quantum physics :p ); therefore, demands my blog’s space and time.
The engineering behind it is pretty simple, to put it in the simplest of the terms;
There is a balancing device, which has a mass unit and a coil
unit. The mass unit is balanced with the magnetic field from
the coil using a motor fixed to it, unit and unless, . To know more, read Watt Balance or Kibble Balance.
Let’s look into the working now, in this process we will generate some cool equations and in the process will learn some new concepts, as and when required.
First, the watt balance, the principle of operation itself says that,

Taking into account all the usual scientific nomenclature, we can write,

Here, is the mass, is the acceleration due to gravity, is the magnetic flux density (in Tesla()), is the current in the coil and length of the conductor in the field.
Equation is for the weighing mode operation of Watt Balance. In which, the weights are matched on both sides.
There is another mode, called the velocity mode in which the mass() is lifted at a height and then the coil is moved back and forth in the magnetic field. This motion induces a voltage, , in the coil. By Faraday’s motional emf expression,

Here, is the velocity of the conductor in the magnetic field.
Now, can be written as,

and can be written as,

Equating and , we have,

Which can be written as,

Interestingly, is the mechanical power (refer Encyclopedia of Electrochemical Power Sources for more info) and is the electrical power.
You must all be thinking, how does Planck’s constant come to play. Well, please hold your horses. We are almost there.
To measure in , we go into a concept of superconductivity. Called the Josephson Phenomenon. Please read up on its working here. It is also significant because of being the standard of Voltage.
When DC voltage is applied to a Josephson Junction, the junction experiences an oscillation of frequency(read more),

Here, is the frequency, is the elementary charge, and is the Planck’s constant().
The above equation can be written as,

For many Junctions ( say ) it is,

The Voltage measure here is accurate to parts, refer this.
Now, if we write, as (where is the resistance offerered by the junction), then, changes to,

Another question now is how do we measure ?, for that we will use the idea of Quantum Hall Effect. Quantum Hall effect is the standard for resistance, please refer the paper for more information. But suffice to say, the resistance is defined as,

Here, is
Please note that, without the integer fraction i.e., is called the von-Klitzing constant, this guy got a Nobel for this. Please read more here.

Using the above equation in we get,

Which comes to,



This is for a single Josephson Junction, for junctions, it becomes,

Which can look more elegant if we write it as,

We have seen that and were measured very accurately. Similarly, there is a need that we measure the factors very accurately as well. The is measured using a Laser Interferometer. The was measured using a Gravimeter.
So, the scientists in NIST, are just putting in some mass and get the , and keep tuning the value of till we get a very accurate .
Cheers!

Monday, 7 August 2017

Study of Brachistochrone Problem.

This blog will deal with one of the most elegant topics in mathematics. The famous Brachistochrone curve. Vsuace did a great job at explaining it in this video. This looks good to me, but it doesn’t feel good; because of course the video does not contain tons of fancy mathematical vocabulary and millions of lines of .

To get started, we will just put forward a small fact that, this topic is from a larger field of mathematics called the Calculus of Variations.

Before we get into the Analysis of Brachistochrone Curve (which happens to be the heart of this post), let us brush-up on some concepts.


Partial Differentiation (advanced preliminary):

Let us look at how we define the derivative of a given function, say we have and we have,

Provided this limit exists.

Now, for a function of many variables it is not easy to compute the total derivative (the usual derivative). Therefore, we calculate the Partial Derivative. You might have already guessed it by now, we define partial derivative as, say we have a function , then,

Let us look into a small example now, say we have,

Now,

similarly,

and,


Idea of Speed and Time (basic preliminary):

Let us consider, the following scenario, (Made using Geogebra)

We have, in the figure we have denoted the path ACB as and the path ADB as .
Consider that, The time taken for a body to move from A to B using path is similarly, the time taken for a body to move from A to B using path is .
Also, consider that the distance for be and the distance for be .

Then,
Speed () == and Speed () = =.

3. Idea of Distance(basic preliminary):

Distance between two points and is given by,

In case, the distance is measured from origin () to some point , we get,


Now that the notion is clear, we shall proceed into the analysis.
[NOTE : Some topics which are new to me (or you) will be explained as and when it is required].


Time needed for a body to travel from to is given by,
for a linear path.

For a curve or a non-linear path, we consider piece-wise linear distance () and speed (). We can define, as,

Now, we must understand a fact that, all distance is composed of and coordinates. We consider the point as the origin () and as . Hence,


Also, since the translation is both in the and axes, we can say that the speed is gained by and equality,


Use and in , we have,

We write

Now, becomes,

Therefore, the function is,


Please notice that, the integral can be written as,

In our case, is .

Equation closely follows the The Euler-Lagrange equation.

It is pretty simple to define,


The Euler-Lagrange equation

For any such that,

Where, , then has an stationary point, if the Euler-Lagrange Equation, given by,

is satisfied.

Therefore, for our analysis,


Stationary value

This is a value at the stationary point.
A stationary point is the point at which the first derivative of a function becomes zero,

Side note :
Find the stationary points of .


Beltrami Identity

Our (from ) is such a cool expression, because does not appear in that; therefore, of course ; this again leads us to another beautiful form, Beltrami Identity, which is given by,


We now find, ,


Use and in equation , we get,




Rearranging a little gives,


This is the equation of the cycloid as per [4], I am yet to figure out how this happened.
The solution of can be found using a parametric equation,

To derive the above equation, please refer Math-stackexchange|Derive the parametric equations of a cycloid.

I have even plotted the solutions at , we can see that it is a cycloid,

If you wish to play with the visualisation please go to Cycloid | Parametric @ Desmos by Pragyaditya

Cheers!


References:
1. Stationary Points
2. Euler Lagrange Equation
3. Derivation of Beltrami Identity
4. Introduction to calculus of variations
5. Brachistochrone @ Wolfram

Saturday, 29 July 2017

A Nice Problem Involving Gamma and Beta Function.

[Playing with Gamma and Beta functions].
Solve :

Let,

Beta function is defined as:

Now, there are many properties of this beautiful mathematical tool, some of them are,

  1. They are symmetric.
  2. We can write Beta Functions in terms of Gamma Functions as follows,
  3. We can obviously add factorial into the mix too,
  4. We can define it in terms of trigonometric angles too,

Now,

We will solve both separately,

Similarly, for the other integral,

Therefore,

Cheers

Friday, 21 July 2017

Integration : Problem 2


: