Showing posts with label Ashraf. Show all posts
Showing posts with label Ashraf. Show all posts

Monday, October 21, 2013

Bibliophilia: Asimov, Milton and More...


Been reading some real hard-copy books now a days after a long long time. The last hard-copy book I read out of my college curriculum was "Mysterious Mr.Quin" by Agatha Christie, a collection of mystery and crime themed short stories with a mystical twist. That was way back in '09, I believe. Since then I read a few e-books, but, nothing beats the smell and touch of printed paper. The feel of a book in my hands actually starts background thought processes, I feel, within me that gives me an immersive experience. Ideas, imagination and links with existing knowledge is formed. Meanwhile reading a digitized e-book version is an ersatz; It maintains an elusive detachment and requires greater concentration and effort to grasp the text. I'll blog in another post on my recently read e-books.

  

I picked up two books from an airport bookstore on my way back to Patna from Delhi. The first was an earlier read book, "33 Strategies of War" by Robert Greene; A very good book which assimilates and distills 33 strategies of war from history. Superfluous with facts and beautifully informative side-notes running parallel stories, from history, in depth with relation to references in the main text. I had read this book earlier when in High School. I had borrowed it for almost a year from my elder cousin brother and had to return it with a lot of text unread, not understood or, now, forgotten. This time, I am working through it slowly and memorizing the narrated stories and strategies for longer retention. (Thanks to a couple of memorization tricks and techniques I've mastered. Though, I'll not be
able to memorize the text verbatim.) 

 

The second book I bought was "The Rest of The Robots" by Isaac Asimov, the classic science-fiction writer. His works mostly have a robot theme with a socio-philosophical premise. It is a collection of short stories by Asimov. There was an offer going that time of 3 books for the price of 2 by the publishers Harper Collins, but, I did not find any other intriguing book by Asimov or any other author that would've made a set of three. (The other book with multiple copies was I,Robot by Asimov which I had seen as a movie starring Will Smith.) Hence, I settled for this one only. 

I, a few minutes ago, completed it's 1st set of stories from it's three groups; "The Coming of The Robots". Novel and decently humorous, I'll rate them. A lot of fancy science buzz-words have been sprinkled, as was common in those days (I'm talking about the 1940s, people!), which does not quite impress or affect me as was it's intention for readers then. Maybe due to my exposure and understanding of a lot of modern day science and science-fiction, makes it taste a little bland. Still, the stories do give an entertaining experience, considering the time they were written in, and ignoring my encyclopaedic knowledge of science-fiction.

This book that I bought also combines introductions by Isaac Asimov, himself, which explains the themes and premise he has structured his stories upon. He refers to Frankenstein and Faust to have primarily forced his thoughts and story themes to go in the direction they took. I am very much aware and know of both Frankenstein and Faust but, personally have not read any of these works (other than in cartoon and comic variants, especially in DC Comics). Faust is primarily a supernatural, moral and horror themed story while Frankenstein is based in horror and rudimentary science.

Personally, I found the short, "Victory Unintentional", quite amusing considering people of the characteristics and mindset of the Jovians (Dwellers of Jupiter) do exist. Go read the story if you want to know. Here's a link to the book on Amazon. (And, that is because some good products are Fulfilled Amazon; which means they personally package, send/receive in case of returns for free and is eligible for cash on delivery. Meanwhile, Flipkart still sucks. Good luck paying extra 
while you could've saved it for some other book.) 

 

I've also picked up John Milton's poem-book, "Paradise Lost", which makes it a difficult read. (But, thankfully not as difficult as "You're not a Gadget".) Old style poem-prose with Biblical theme and cast of characters, unknown to the modern eastern reader, would make it an instant turn-off. Though my knowledge of the myths, supernatural and religious materials is great enough to create sensory overloads, the book still is a slow read. The prime reason I'm reading this is due to its protagonist. The protagonist of the story is Satan and the entire Biblical chain of events and theology is narrated and shown from his perspective which makes for an interesting read. Plus, it has some really fancy texts. Take this for instance;


A mind not to be changed by place or time. The mind is its own place, and in itself Can make a Heaven of Hell, a Hell of Heaven.
Then there is one really strong rebellious dialogue worth thought;
Better to reign in Hell than serve Heaven.
But, what a great/foolish/masochistic decision, I'd say!! Reminds me of the concluding conversation between Dean Winchester and Castiel in Supernatural TV Series Season 5 Episode 22: Swan Song. (I'd recommend you to see the series from the start but, you can also gather enough emotion for this thought provoking reply by watching only seasons 2/3 to 5). Owning a hard copy of Paradise Lost does make it good for underlining texts. So, here's the link; (Be forewarned! I don't know which themes does it touch as I've not read it entirely yet. Just gotten my feet wet and this is a freaking long poem running 280 pages and was initially published as a set of 10 books back in the year 1667, and you thought Harry Potter was unnecessarily long?) Finally, I've been skimming the various models in the book, "The Decision Book" by Mikael Krogerus and Roman Tschappeler, another non-fictional semi-technical book. Got it from Amazon, hardcover and all at only Rs149!! (One, of the reasons for my new allegiance to Amazon India.) Good book but, not for everyone. So, watch out and make sure it's worth your cash. For (a confused, a million thoughts & ideas a moment - brainstorm afflicted guy) me, it was totally worth it. Learned and tried out the first Eisenhower Matrix.
Books Discussed:
  1. 33 Strategies of War by Robert Greene (Non-Fiction, History, Strategy)
  2. The Rest of The Robots by Isaac Asimov (Science-Fiction, Classic, Robots)
  3. Paradise Lost by John Milton (Long Poem, Classic, Biblical)
Books Mentioned:
  1. The Mysterious Mr.Quin by Agatha Christie (Mystery, Crime, Enigma/Paranormal)
  2. Frankenstein by Mary Shelly (Science-Fiction, Horror) - I must read later.
  3. Faust by Johann Wolfgang Von Goethe (Supernatural, Horror ??)- I must read later.
  4. The Decision Book by Mikael Krogerus and Roman Tschappeler (Non-Fiction, Meta-thinking, Life, Mind)

Monday, July 15, 2013

My Experiments with JUNG 2.0 (Java Universal Network/Graph Framework)

My first minor project was a major disaster. But, in hindsight I can salvage out some simple nifty tools from the graveyard of codes on my laptop. I had to settle for a simple "Simpletron: A Simulated Microprocessor in Java." (I've blogged about it earlier here.) All it took was firing one of our three team members and the remaining duo pair-programmed into the night.....or at least for a few hours until he too quit and went away to see a movie. We ended up showing this little nifty tool and anther tool which Chitransh had designed to go together with this one. I then finally completed and perfected Simpletron on my own.

Nexus Grapher was a tool to be added to a data-mining project which we failed to complete due to broken team dynamics and interaction, as well as, pressing deadlines. I coded this small tool from Open Source, JUNG 2.0 API. That's "Java Universal Network/Graph Framework" Version 2.0.

This project had a lot of potential and planned features that were never realized. Nexus - as we named it, was supposed to be a suite of various data mining tools which can be used on a directory full of web-pages (preferably from Wikipedia & news-sites) and text files etc documents.

Initially we planned to adopt Stanford NLP Parser to perform NER tagging (Named Entity Recognition - This link is a Wikipedia page). This would produce a Penn-treebank structure which would be parsed by a method of my nexus-grapher to generate a visible, click able, interactive graph of inter-relating facts and texts from across the webpages and texts saved in the directory.

Selecting a node with the label of a named entity would invoke another method that I wrote with my team-mate Harshdeep Sokhey which will open a window displaying a consolidated text file with (that label) related texts collected from all over the mined directory. (Like a dynamically generated Wikipedia page).

But, this consolidation and compaction method was in it's nascent state without much intelligent features of context aware auto-data updates (on comparison with recent file save) and even basic features like text-redundancy. All it could do was get paragraphs and lines, consisting of the keywords, from all over the directory and order them by file creation date.

The connecting edges of the graph was also meant to be click able to pull up a consolidated file with paragraphs of texts where both these named entities would appear simultaneously. Another feature we failed to implement. I tried switching to Apache Lucene but due to approaching dead-line I didn't have enough time to learn Lucene.

Currently, the nexus-grapher reads from a CSV of preselected named entities to generate the graph.

If you want to know more of my plans for "Nexus: An interactive data-mining & visualization suite." send me an email. If you're able to implement such a suite, very well, do inform me.

Directions/Code Walk through::
--------------------------------

This small tool is built with open source JUNG 2.0. My knowledge and expertise with it is... limited. If you encounter any troubles and have questions relating the graph and its subsequent visualization, please contact them. Here's a tutorial of JUNG 2.0, as a PDF, which I found handy and it should be enough for the Java noob to get his feet wet.


Before I get into the details of my Java project, let's first go over the basics of my C.S.V formatting and rules for, what I call, "nexusft"; nexus-format-textfile.

The first token of the C.S.V is the available roots that can be searched and all other succeeding tokens are it's children.

Now, onto Java! The project package is split into three classes:

1) naseemgraphexp2.java
2) ReadFile.java
3) search.java

"naseemgraphexp2.java" is the core class with a Main  method to run a simple graph visualization. The code is self-explanatory with comments.

A name (search-token) is sought from the user when the program runs and calls the readnexus() method. The searched nexusft file address is passed as a parameter for the class ReadFile.

This ReadFile returns the arraylist of lines of texts in the nexusft file which is tokenized and searched against the entered keywords. Only the first token of the C.S.V (if matched) is considered the root and all others are considered children. Else the method returns an error message.

The constructor method "naseemgraphexp2()" is where my iterative loop adds the tokens as vertices and their names as labels. Only the searched central/root node of the graph is connected to its relatives.

The rest of the code in the Main method is self-explanatory and JUNG specific, to build a graph and visualize it. The geniuses behind JUNG kept very clean and clear examples for me to hack with my shoddy programming skills. I've left behind some original code of JUNG examples, which has been commented, I know it's bad practice (I read in one of them, Pragmatic Programmer/Publishers book), but, it is there for all those who are new to JUNG 2.0, to see and realize the available features I did not use.

"ReadFile.java" is a straight forward file reading program to read and add each line of text into a String[] array which is returned to the calling method in naseemgraphexp2.java.

Finally, in "search.java" is the small program to tokenize each string that we previously stored in our String[] array to be matched with our search token. If a match is found, then a true Boolean is returned to  nexusgraphexp2.java's method "readnexus()" which then proceeds to tokenize this string to create nodes for the graph.

I hope, you find it useful despite this poor hacking. If you polish it and go onto implementing better features do e-mail me and credit me for this shoddy hack.

Your,
Md.Naseem Ashraf
iam.legend.n@gmail.com

Source Available at:


https://docs.google.com/file/d/0B4e1TZA7mwrNVTYyTk9fOGVuT1E/edit?usp=sharing

Screen Shot:

 

 

 

Creative Commons License

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.

Sunday, July 7, 2013

Image degradation and noise by Md.Naseem Ashraf



I had made a small presentation on types of noise and image degradation in Digital Image Processing with small MATLAB examples for my Digital Image Processing subject in seventh semester of my undergraduate study in Computer Science Engineering. I shared this on SlideShare sometime earlier. I am blogging it here to increase its search-ability for those who are searching for it. I hope it’s helpful to others.

My Presentation on "Switiching & Forwarding in Computer Networks"


Switching & Forwarding in Computer Networks by Md.Naseem Ashraf from Naseem Ashraf

I had made a small presentation for my Computer Networks subject in sixth semester of my undergraduate study in Computer Science Engineering. I shared this on SlideShare sometime earlier. I am blogging it here to increase its search-ability for those who are searching for it. I hope it's helpful to others.

Saturday, July 6, 2013

Coding the Confusing Circular Convolution and other DSP Woes

Image

I remember in my fifth  semester of Computer Science Engineering we had a subject called Digital Image Processing. It was initially a God darned subject. But, I soon began to understand the text about discrete signals and its manipulations. Unfortunately, the only way to survive the tests for this subject was to commit its various mathematical formulas for conversion and manipulation of signals to memory, a task I hate to date.
Maybe I believed in Einstein's idea (even before I came to know about it), as it is a logical deduction/conclusion every intelligent and creative soul must come to. Here's what Einstein said;


A link to a lifehacker blog post is attached to it, where you may go and read more on it. This is where the idea of Third Party APIs, extensible classes, refactoring, code reuse etc similar concepts came from. It is also the corner stone of Object Oriented Programming.

Most of you will agree to the fact that, "Programmers can be lazy." as said by Larry Wall. Hence, we reuse, refactor, inherit and incorporate others solutions in order to reduce the amount of effort required.

Now, returning to topic at hand. What I observed was that, most of my classmates were hard-coding such methodologies for each step of the computation, as taught in the theoretical classes, to solve such problems on paper. My progress was very slow in the first few lab sessions while most of my lab mates breezed past me. I was taken aback by my friend's approach trying to mimic each manual step into a hundred line code. I abhorred such menial labor irrespective of the fact that, you've "done the job" or not. It was an abuse to the community of scientific programming. Later I learned it violated the KISS (Keep it simple, stupid!) rule of modern programming.

I began seeking for a more streamlined and intuitive way to do such programs. In my search, I returned to the textbook and started coding the various formulas instead of each step we computed by hand (like in the age old days of the Intel 8085 and other obsolete microprocessors). For a first time programmer it may be a little confusing to produce an algorithmic form of the formula. This was a very good self-learning experience for me! I could run the textbook examples on my program and verify the solutions, too! It was the feeling of creating something working, elegant and new (at least for me) for the first time!
The added advantage of such an approach is that formulas, being flexible as they are, also made my functions flexible to handle any alteration in the questions they were to compute.

This crux of today's blog is - "Never hard-code! Never!".
 
I'm sure you'll see many, many coders "getting the job done" by some arcane code vomit on their editors but, in the end, it is not scalable. A true programmer always exploits the logic in a problem to come up with a flexible minimalist simple program while a true hacker exploits the logic in others programs to solder together a solution system that does more than the existing systems set of features/functions and solves the problem at hand.

One may hard code if his/her initial research (Google, books, StackOverflow etc aids) has returned a negative. He/She should also keep others informed of their approach and progress in order to attract outside review and improvements (An idea practiced in Pair Programming). Then find a general algorithm to improve such a solution. If the programmer succeeds in digitizing a solution for such a problem then he/she should give a pat on his/her back and share there achievements with others via a blog, open-sourcing or getting this algorithm published in a paper, if it's truly novel. After all, there is no intellectual achievement in re-inventing the wheel.

CIRCULAR CONVOLUTION CODIFIED -

Sorry for my previous meandering rant, if you're in a hurry. I just wanted you to know what you should know. Here's the Circular Convolution mathematical formula for discrete sequences with period N of functions h and x as:
Image

Observe the expanded mathematical statement uses two summations across elements of the two sets, thus we require to run two loops: one nested in another, to access each element of h for calculation with each element of x limited to the number of elements in the sets.

MATLAB source code for circular convolution is here.

Note:-

Other added programs are for DIFFT (Discrete Inverse Fast Fourier Transform), Ladder Form Generation , Poles and Order Calculation & Jury's Stability Test . I apologize,  for a semi-hard coded program for Jury's stability test. It is a shared work with my smart friend Chitransh Saurabh. I seem to have lost a lot of my DSP source-codes from yore. If you've implemented a simpler code with the KISS principle in mind (some of which I'm sure is floating around in the web), then please do share it with me and others. Also, I apologize for the stark lack of comments to the code, as I was a beginner then.

OTHER IMPORTANT SOURCE CODES:

MATLAB source code for DIFFT (Discrete Inverse Fast Fourier Transform) is here.

MATLAB source code for Ladder Form Generation is here.

MATLAB source code for Poles and Order Calculation is here.

MATLAB source code for Jury's Stability Test is here.

[*I'll be thankful for your appreciation and thank yous if you drop it in my comments below. Also, I know somehow this blog may aid my juniors and successors at BIT Mesra and it's extension centers or any other college in India, with a quick code to copy-paste for their lab tests, when no one's looking at them looking on the web for answers. Well then good luck for the test.]

Saturday, June 29, 2013

Simpletron: A Simple Computer\Microprocessor

Simpletron: A Simple Computer\Microprocessor

In my early days of learning Java I had been provided with "Java How to Program" by Deitel from my college library. I wondered the initial week as to why we had been given this book instead of the standard Sun Microsystems Press Series, "Core Java 2 Volume 1 Fundamentals" by Dr. Cay S. Horstmann and Gary Cornell. Now, I realize in hindsight that it was a good choice on behalf of the library for us, who had first time exposure to Java in our engineering curriculum.


I don't mean to say that Core Java Volume 1 Fundamentals is not a good book, but its for programmers (already drilled with the art of programming, looking to learn Java for the first time) and those with at least one programming language familiarity. It doesn't contain enough large/complex real life examples as in Java How to Program. Also, Java How to Program was a somewhat composite book with a brief introduction of Advanced concepts which has been separated by Sun Microsystems Press into Volume 2 Advanced Concepts. Deitel also contains lots and lots of exercises for practice to hone your Java skills to a very high degree of perfection.

Now, returning to the topic of this blog. The thickness/volume of this book initially made it quite and intimidating task to initiate the learning process.


After my initiation into Java and a few months of tinkering of code on Netbeans IDE (Yeah, one of the first mistakes I did as a beginner was to use an IDE. Should've used the Terminal/Command Prompt and I'd have become better quicker), I was introduced by a friend of mine to "Head First Java" from O'Reilly by Kathy Sierra & Bert Bates. It is an excellent book for beginners!

While cementing my concepts, juggling between the three books and two IDEs (I started using Eclipse. It is the most widely used IDE), I frequently returned to Java How to Program for examples and exercises and one day I stumbled upon question number 7.35 Special Section: Building Your Own Computer (Page Number 309). I was instantly intrigued by the question and support material it contained to create a program which I would in later classes and years will come to know as a Microprocessor. If I'd have realized it at that time, it may have had become a daunting task (It's true that, ignorance is bliss).

In a few weeks I had completed the project and then went on to add a mnemonic conversion facility. It was a very good experience, I'll admit.

So, without further delay. Here's the source code to my Simpletron.

Download Source Code

Oh! And do comment and critique.

Screen Shots

[Note: I've not posted other screen-shots due to their intimidating and disturbing nature, especially with a lot of doubles printed in 2D Arrays may look a lot like advanced mathematics. Trust me it's easier. Also, try my code after you've attempted to built your.]

Wednesday, June 26, 2013

Simmunity: A New Game of Life

Simmunity: A New Game of Life

Conway invented the Game of Life in 1970; A "zero-player"game which demonstrated that a complex and sophisticated system can be created by a simple set of rules on a cellular automaton given only its initial condition. It is one of the most amazing AI experiments I've studied.

I was inspired by an entry in the list of Under Graduate Research Projects by CS Department of the Princeton University, to build a variant of Conway's Game of Life to Simulate an Immunity System [which has been now removed in recent updates; someone may have done it or it may have become archaic, don't know].

I then began studying about Conway's Game of Life and it's extrapolated conclusions on Evolutionary Science. A simple program with a beautiful visual display with a nostalgic video-game style simulation, made me very happy and interested to do this project. It's graphic display would also be a good project to show-off to non-computer science people. And, thus began my journey.

On the way, I found a lot of knowledge missing in me and had to improvise to generate, share and visualize the Immunity System as a Game of Life. I did not have enough know how to build GUIs in Java (one of my strong and comfortable languages) and thus had to generate universe matrix in Java and then write them to text files in CSV(Comma Separated Values) format. This CSV was next read by a MATLAB program and visualized in a colored grid. The series of grids were saved as frames and animated to show each step of change in the universe step-by-step.

The Rules of Simmunity are:

  1. Regeneration Step: 10% RBC (Red Blood Cells) are regenerated in a random fashion in empty places (i.e occupied by Blood-Plasma) after every step.
  2. Regeneration Step: 10% WBC (White Blood Cells) are regenerated in a random fashion in empty places (i.e occupied by Blood-Plasma) after every step.
  3. Pathogen Spread Step: Pathogen (denoted by black in the graphics grid) eats and replaces (i.e.copies itself in) any one of the 8 neighboring adjacent cell if populated by an RBC.
  4. WBC Spread Step:  WBC eats and replaces (i.e.copies itself in) any one of the 8 neighboring adjacent cell if populated by Pathogen.
  5. Starvation Death Step:  When a Pathogen cell is not surrounded by any RBC for more than three steps/iterations the Pathogen dies to leave Plasma (empty cell) behind.
  6. Starvation Death Step:  When a WBC is not surrounded by any Pathogen cell for more than three steps/iterations the WBC dies to leave Plasma (empty cell) behind.
  7. Natural Death Step: A RBC dies after a few iterations simulating natural death of RBCs.

 The Outcomes:

The body/system/universe heals successfully or fights off the disease/infection and no pathogen is left in the system. The WBC and RBC attain maximum levels flooding the universe and then attain an equilibrium of death and regeneration.

 OR

The body/system/universe succumbs to the disease and the pathogen spreads to dominate the universe for the stipulated number of iterations. Note: The body/system/universe will recover in later steps when the pathogen starts dying out of starvation and regenerating WBC will strike back with a vengeance. Also the RBC count will increase by regenration.

OR

The fight is still going on and the stipulated number of steps by the user has to be increased.

Additions:

I later added the facility to choose the size of the universe (i.e. grid/matrix) and the number of steps to be iterated. Another MATLAB program, I wrote, would count the number of RBCs, WBCs, Blood-Plasma(water) and Pathogen(virus etc) and record its step by step statistics which would be displayed as a net graphical outcome of the set of rules applied to the system and observe outliers or deviations.

***Addendum***

 I recently re-run my Simmunity program and found a few of my folders misplaced from the Desktop which may cause trouble. Thus, I'm adding this note here;
"You need to create a Directory called SIMMUNITY on the Desktop with two sub-directories, Outputs and Universes Collection."
 The Outputs sub-directory will contain FirstStat.txt and SimData.txt files auto-generated by the Java AI program. These contain a CSV matrix for processing by Matlab M-Files. The Universes Collection sub-directory will contain a Random Universe.txt file that will contain the size of the simulated cellular universe (i.e the grid or matrix) for the Matlab M-Files to run loops accordingly and create a simulation. You do not need to create these text files.

Screen Shots: 




 Download Source Code:

*Comments/Critiques are welcomed and appreciated.