Sunday, September 26, 2021

Solving SICP

بسم الله الرحمن الرحيم 

In my quest to become a competent programmer, I had a lot of false starts and took many wrong turns. In hindsight, I feel that I didn't really know what I needed to be capable at programming, as programming to me was mastering a programming language.  That was the dominant take-away from almost all the tutorial websites which turned up in Google searches. It was supposed to be super easy to be a programmer. 

I was mostly convinced. I used to think, what is there to programming other than using conditional statements, loops and functions, constructs, which are after all, common to all programming languages?

I could solve complex numerical problems from chemical thermodynamics in C using the said facilities and I could use the terminal to compile my programs so what else could I need?  I could use Xcode to make a chemical engineering calculator app for iOS, albeit with basic UI, but who cares about UI (Apple does)? Here's a fine app which will calculate bubble and dew points, so it should doubtless sell like hot cakes. 

Programming was never a big deal, to me it was just fleshing out my numerical algorithms into code, and all that I had to ensure was that the code had the correct syntax and did what I wanted it to. If the program compiled and output the expected answers, what happened under the hood was immaterial.

But programming has more to it than performing engineering and scientific computations, which I realised when I found that there was essentially no market for chemical engineering tools other than those by big corporations, and that I had no skills beyond those that would aid in doing numerical calculations.

So I felt like a beginner again.

But, Praise be to Allaah, I found a thread on Hacker News, where people praised this book, SICP. It was also mentioned in websites like teachyourselfcs, and was quite popular on Internet forums. I trusted Allaah and attempted to study it. I started doing it in December 2020, and now 10 months later, Alhamdulillaah, I have reached section 5.4 of the book. I feel that I benefited from it very much.

I did not do all the exercises, but what I did I will In Shaa Allaah post on this blog.



Sunday, August 23, 2020

Effect of the number of hidden nodes on the ability of an MLP to perform regression

بسم الله الرحمن الرحيم

Alhamdulillaah, I am learning Machine Learning and I am mostly looking at Neural Networks. I started off with modelling the logical OR using a perceptron. By Grace of الله, I was able to move to the Multi Layer Perceptron (MLP), which can handle much more complicated problems, like regression and classification of "non linear" data. 

There's a term called Linear Separability, which is the peculiar characteristic of a dataset which can be separated by a line (or a plane/hyperplane if there are more than 2 features in the input). Most data is non linear, such that even for modelling the logical XOR, the perceptron proves to be inadequate. 

Using the MLP,  I was, by the Grace of الله, able to train a neural network to predict correct outputs for XOR. Then I tried the regression problem. I attempted to train the MLP to regress the data which was generated using a sinusoidal function. الحمد لله, I learnt quite a few things from it.

One is that as more nodes are added in the hidden layer, the network gets closer to the data. 

The thin green curve is the actual function which the MLP tries to regress. The thin red curve is the MLP's prediction with two nodes in the hidden layer. The thick blue curve is the MLP with 5 nodes in the hidden layer. I used only one hidden layer for both MLPs. So it can be seen that the red curve, though it does not predict the data as well as the blue curve, especially on the left side, it still manages to generate values which more or less represent the average values of the data. 



Sunday, October 30, 2016

Using leaks(1) to tackle memory leaks in macOS Sierra

I am going through Learn C The Hard Way trying to finally master C (I hope that will happen).

There is a program called Valgrind which is used to detect memory leaks in C programs. It works well on Linux and sometimes works with macOS. I had installed Valgrind when I was using El Capitan but the upgrade to Sierra made Valgrind useless. The book tells us that lldb is also a debugger but thats not really useful for detecting memory leaks. I tried reinstalling Valgrind but it would not install.

Alhamdulillaah, I found a macOS command line tool called leaks which mimics the functionality of Valgrind to some extent. eg. If I have an executable named exec, I will have to run it from the command line by setting MallocStackLogging = 1, like this:

~: pro$ MallocStackLogging=1 ./exec

And then, I have to run leaks command in another terminal tab by giving the leaks command the process PID as argument, like this:

~: pro$ leaks 19009

We can get the process PID from the activity monitor. In the above command it is assumed that the process PID is 19009.

But it has also to be ensured that the program doesn't quit before leaks can complete its analysis. So for that we should have an atexit() function call in our program which calls a function which makes the program wait.

The called function has to be of return type void. eg.

void exitFn(){
    while(1) sleep(60);
}

Then from within the main function of our program, we might call atexit like this:

atexit(exitFn);

This will ensure that our program waits while leaks is checking for memory leaks.

Thursday, March 26, 2015

Rebooting with CSE

Bismillaahir Rahmanir Raheem.

I am about to graduate Insha Allaah in the summer of 2015.
From IIT Bombay.
Chemical Engineering. 

And this blog is supposed to document my experiences and attempts at trying to get another degree. But this won't be an M.Tech or a PhD in Chemical Engineering. It would be in CSE. 

Why do I have such a plan?

Well because its an amazing thing. An amazing discipline. 

And because hardly anyone from chemical engineering would have gotten a job- had not some banks and startups, catering to financial sectors- come to hire. 

And they did not hire Chemies because they were good at chemical. Nor were they hired because they were smart. They were hired because of their ability to do Odd Jobs. They can dance. They can organise events. After all they have been mess secys. So with a bit of help they can manage the office canteen. They pulled off that great victory in Inter IIT. Wow. Pick them before anyone else does.

Recruiters look for these very qualities. They don't need a nerd. They want fun loving people. Who can double up as office boys when the company needs less of glamour.  People who can meet all sorts of deadlines through jugaad.

They need them because they would be able to create back-of-the-envelope websites.  And because they know a smattering of Photoshop and Sony Vegas, they might prove to be useful in making advertisements. They can play music. All things that go into making " a well rounded" personality. Its all on their resume.

Also an IITian would look so good as a  manager in a call taxi company. 

These IIT chaps are just street with an IIT wrapper around them. Why would companies like Axis Bank and Flipkart and Meru Cabs hire Chemical Engineering grads? Do they see some real use in them? They don't need chemies. 

The truth is that they take them only because they are IITians. Its mostly because they need to add weight to their employee pool by adding the Big Guns from IITB. 

But I don't think an IITian deserves Odd Jobs. If you disagree, good luck to you.

If you don't get a job it doesn't mean you do Odd Jobs. Unless thats what you dreamt of doing out of IIT in the first place.

I didn't get a job and its not that I am unhappy. I don't regret any decision in my life.

I begin everyday thanking Allaah. And thanks to Allaah that I do thank Him.

But long story short: I like CSE. I don't hate chemical. 

Hope I complete it within as short a time span as possible.