All posts by laimonas

AI Nano degree update: Project One

First project required to write an AI agent capable of solving a Sudoku puzzle. The key goals of the exercise: familiarize students with concepts of constraint propagation and search for solving problems.

I would summarize constraint propagation as follows. In abstract, when you have a function that needs to pick a solution given multiple of choices, it can narrow down the answers by coming up with strategies that eliminate the subset of given solutions until a single solution remains or the number of potential solutions is smaller than the input solution space.

In Sudoku project, the three strategies for eliminating the solutions employed were as follows:

  • straight up elimination – find boxes that are solved, and then remove that box’s value from its peers (rows, cols, squares)

  • only-choice – given a box with multiple possible digits, for each of those digits, see if it is not present in other unit’s of that box thus making that number the only viable choice for the box

  • Naked twins – sometimes you have units that have two boxes with the same possible solutions, so that means those two squares will have either one of those digits. Thus those digits can be eliminated from other units of the box. There are variations of this called naked triplets, and so on. Twins seemed to be the most effective.

Now you can imagine that one can run through the solution elimination sequence in a loop, with each pass applying all the elimination techniques. You stop looping if none of the techniques are reducing the solution space further. You are stalled.

What now? Well, brute force search. Pick un unsolved box, and iterate through its solutions, in each pass applying the constraint elimination sequence until you either solve the problem or you stall. If you stall – the initially picked solution is not a good choice, move on to the next until solution is found.

The project was a very fun exercise. I never was much into Sudoku before so at the very least it gave me an excuse to try the puzzles out. It quickly became a fun exercise of finding patterns. And once you mix in writing Python code to solve the problem automatically, it was nothing but a delight.

Here is a screenshot of AI agent in action:

AI agent in action solving a sudoku puzzle
AI agent in action solving a Sudoku puzzle

To generalize the idea: when you have a function which has a set of possible solutions to choose from – go ahead and think through how you could constrain possible solutions to reduce the search space. Then brute force search through each until the answer is discovered.

Besides a great warm up into search, the first project also gave me a great intro into Anaconda, “Leading Open Data Science Platform Powered by Python.” Think of it as a Python environment that is loaded with data science libraries and tools. If that is not enough, it can “containerize” your Python environments that are entirely isolated and across machines/platforms. You can setup a Python 2 environment and Python 3 environments, load it on the same machine, and neither will impact each other. And again, not to mention that it comes pre-installed with a variety of data/ml related packages.

On to the second project, which goes much deeper into general AI ideas around search and advanced game-playing techniques. I am done with that project two and should have a write up for it shortly.

Machine Learning update – Feb 2017

In the last update on my machine learning journey, I had just finished the Udacity’s intro and started with the Coursera / Stanford Intro to Machine Learning. I am happy to say that this course is now complete as well!

It feels slightly surreal to reach this point. When I first setup my plan for ML, Coursera’s course was something I had marked as being challenging and a “maybe if time allowed.” The reviews and the feedback mentioned how great the course was, but also many people seemed to drop off at the neural network chapters. Essentially I had my doubts about being able to finish it on time while doing it part time. There is no time limit to the course, and you could transfer to the next cohort, but I wanted to make sure I did it in the same session I had started. Once you start delaying an online course, there is a chance you will delay it indefinitely.

In retrospect, the course was indeed challenging but not as bad as I expected it to be. The hardest part was to get comfortable with Octave environment and translating lecture notes and formulas into matrix equivalents. I am quite happy that I stuck to the end, and with 100% grade to boot.

If I had to compare the intro courses from Udacity and Coursera, I would still recommend Udacity to start and then use Coursera to augment and deepen the understanding of the basics. I had quite a few “aha!” moments when taking Coursera’s course, but Udacity makes ML more practical and attainable. I thought it demystified the Machine Learning field. After taking the course, you see the application opportunities and the landscape which you should further study. Perhaps best is to combine the two classes – they are drastically different – and learn and compare the concepts between the two.

What’s next? Feb 16th I am starting AI Engineer Nano Degree on Udacity. The same feeling again, a bit daunting and challenging. Hopefully, I will hang in there and power through it. I am sure to post the update as I go.

Before the course starts, I am taking a quick detour back to stats and statistical analysis, to make sure I grasp the basic concepts of analyzing data. Trying to go deeper into kernels and data sets on, familiarizing myself with pandas framework, etc. Basically having fun before AI degree ruins it all.

View story at

Book Review: The Richest Man in Babylon

Rating: 4 stars.

Amazon Link

I wish I had read this book sooner.  I found it very useful, despite its unusual, parable-like, story style. The stories teach the reader how to achieve financial success. Even though the setting is ancient times, the advice conveyed is very practical and applies today as well.

When we think about “financial success,” we often think of immediate and big gains: stocks that multiple overnight, big payday, bonus, etc. The reality is quite different: financial success comes to those that work hard and smart, plan for it, and then take patient and steady approach.

The book, which was written in the 1920s by an American author, shares stories that are mostly about a wise man Arkad and how he achieved financial wellness.

Arkad’s main rules are simple:

  • Save 10% of your income

  • Spend less than you earn, after you put away that 10%

  • Once you have a nice amount of money saved up, don’t keep it idle but instead make it work for you. i.e., invest it somewhere so it earns money.

  • Invest it wisely, don’t invest in the areas you don’t understand without an expert guiding your way. Make sure you can get the principal back safely.

  • Own the place you live in, i.e., don’t pay rent

  • Insure your life, your earnings where applicable

  • Increase your capacity to earn by acquiring skills and knowledge.

Now you could argue with some of the points here, but the principles in general are very sound. Save part your income, don’t spend lavishly, then start investing and get back principal AND interest, while keeping insurance around and all the time seeking for ways to improve your ability to earn. Can’t go wrong with that.

Some of the other things that caught my eye were around how you go about saving money. When you start to save, don’t go crazy and frugal to the max, just make sure you start with 10% savings, and that’s a good enough start.

However do analyze your spending and see if there are expenses there that can be cut (but again, within reason). Sometimes we forget subscriptions/services that we keep, and perhaps those can be avoided.

And one of my favorite: “Opportunity is a haughty goddess who wastes no time with those who are unprepared.” When the opportunity comes, those that take it benefit, and to take it you have to be ready – you just never know when it will come.

Parkinson’s Law

Human psychology and various inefficiencies that we build into our behaviors are fascinating. Here is one that I have come across recently that resonated on many levels: Parkinson’s Law

“work expands so as to fill the time available for its completion”.

An interesting variation of this law is: the complexity of a solution to a problem increases to fit our initial assumption about how complicated the solution should be. I can recall many times feeling very uneasy and uncomfortable the moment somebody emphasizes the complexity of a task being worked on as opposed to breaking the task down to simplify it. Most likely the anguish is from knowing that such behavior leads to things being made complicated without having it to be that way. High complexity means unnecessary work and wasted time, two things that should always be avoided.

The next time a problem statement comes along, I will keep Parkinson’s Law in mind. Instead of hailing the complexity of a task, we should focus on understanding the problem by breaking it up into small pieces and simplify each part of the solution. If a job sounds complicated, we haven’t thought about it long enough to simplify it and break it up.

Other lessons to be learned from Parkinson’s Law:

  • If a task is perceived to be unimportant, it will take longer to complete. Make sure that the “why” behind a task is understood and emphasized.
  • If you change nothing about the task itself and instead change your attitude and perception on how complicated you deem the task to be, you will increase your chances of not only completing a task but will end up doing it sooner, and in a simpler and efficient fashion.

A start of machine learning journey

Early in September, I started taking a course on learning. Essentially it is a course on how to be a better learner. Learning about learning might sound silly, but it was a great course with many great strategies to employ when trying to master new material or acquire new skills.

As part of the course, we had to pick a project that we will use to apply the techniques we were learning. The concept made a lot of sense. In my experience, the best way to learn a practical skill is to combine the theoretical knowledge with practical work, so the project seemed very appropriate.

My project was to take and finish a course on Machine Learning. I knew close to nothing in this area, and it is a field that is hot in software engineering. ML being new to me, it gave me a chance to program using techniques that are completely unknown and that makes things a bit frustrating but also a lot of fun.

The course I went with was Udacity’s Intro to Machine Learning course. So far the intuition to pick that course is proving to be correct. I finished it ahead of my planned scheduled. It took me just a tad over two months, while mostly studying on weekends and occasional early morning.

The most fun part was applying the skills learned from the course at my current job. We do some video processing tasks and such things have been notoriously tricky to estimate how long they will take to complete. With ML, and more specifically regression analysis, it was a breeze to build a model that gave excellent predictions on processing durations. Some of the predicted times were within seconds of the actual times, most within minutes, which was more than sufficient when you consider the processing could last anywhere from 20 to 40 minutes (with some outliers of course shorter or much longer).

My goal was to apply the techniques in some capacity by February 2017, and being able to do that so much earlier was a big boost and motivator to continue going strong. Actually one of the learning course main preaching points was to use what is being learned right away, even if you don’t feel like you know what you are doing. It just strengthens the knowledge and right away deepens your grasp of the concepts that you are learning.

I am highly recommending udacity’s course for the others that might like to start ML journey themselves. It is not very heavy on theory, although one should use the topics presented to dive into more theory online. The examples and mini projects they present are really great, interesting and informative. If you know a bit of python you are pretty much ready to go. Knowing some of the advanced math conceps helps to understand the course better, but it is not necessary in order to use the techniques.

What’s next? I am happy to share that I got accepted to AI nano degree. It does not start until February 2017, so in the meantime, I am taking another ML intro course, this time Stanford’s Machine Learning course which I debated to take before picking Udacity’s option. Stanford course is great, but presents much more theory and is a bit more “drier”, more pedantic. I am on a week 3 now of the course, going ahead as far as I can before Neural Network weeks. That area might prove to be very complicated so it will be good to have as much cushion as possible for quizzes and learning.


That’s it for now. I can’t wait to see where this ML journey will bring me. Hopefully, I will continue to deepen and strengthen my practical skills and start applying it in everyday life with regularity.

Experiment: taking notes while reading

This seems to be a common evolution for non-fiction readers:

  1. A love for reading leads to various fiction books. A thought of reading non-fiction does not enter one’s mind.
  2. Continued love for reading and desire to learn more leads to an occasional non-fiction selection.
  3. Non-fiction starts to dominate the reading list until eventually a fiction book is a rare choice.
  4. The realization that “plowing through” non-fiction in the same fashion as fiction leads to forgetting the content way too easily — some sort of notes / review process is added.
  5. Notes / review process evolves as one gains experience with it.

If you read a lot of non-fiction and haven’t started taking notes, I would highly recommend doing so. It might seem like a daunting task at first, but it is actually not that bad and enhances the overall satisfaction with your reads.

The simplest form of note taking is summarizing the book after you read it. I’ve been doing this for six years and have found it to be very useful. It’s a good way to refresh yourself on what the book was about in case you need to make a recommendation to another reader. Summaries also come in handy when you need information that you know you read about but are not sure which book contains it. Often the summary will remind you which one it was.

I’ve found that doing a summary right after finishing the book is the best way to go about it. Make sure you record it somewhere that you can easily go back to when you need it. Google Docs is good and simple, or you can use something more sophisticated like I wrote a book site for myself that anyone can create an account on and use: Goodreads is too noisy / distracting for me for this purpose.

For a couple months now I’ve been running an experiment of taking notes while reading. It is a much more intense and in-depth process than summarizing a book. I’ve used it for three books so far and I am enjoying the process immensely.

What held me back from taking notes while reading was fear that it will prolong the reading time greatly, and make it less enjoyable. However, if you change how you read books and combine it with the constant analysis, review, and questioning of the material it leads to a greater understanding, and greater enjoyment. You really start to “feel” the book instead of passing it through your thoughts. And instead of simply reading the book from start to finish, now I do this:

  • Quickly review the book online either on Amazon or Wikipedia to see what is a point the author is trying to make.
  • Get some quick info on the author and what is the author known for.
  • Look at the table of contents and note the name of each chapter so you familiarize with how the book will flow
  • Now read through each chapter: look at the title, for each paragraph read first and last sentences to see if you get the idea of the paragraph and if it is necessary to dig in more.
  • While doing this, summarize what you are reading in your notes, but in your own words. Ask questions, verify the strong points author tries to make: do you agree or disagree? does the point make sense? what are others saying about it? The actual place where I take notes right now is a simple paper notebook. Not sure how that will hold up and how I will go about digitizing this.

Essentially you are studying the material. I am still a rookie at this and I am sure my note process will change as I go. My notes might still be too passive, still follow the book too much vs being my own voice. Or maybe not, I just need to continue doing this and evaluate how I feel about the process as I go, and adjust.

Some of the interesting links I found when researching how others take notes:

I think the key is to start simple, not too worry too much if you have the right approach, just pick one and evaluate and then adjust as you go. Personally, I will continue to develop the note taking approach and looking forward to seeing where it will take me.

A great Quora question and answer

Resurrecting the habit of writing regularly on this blog by using it as a place to share and document some of the more interesting content I find.

There was a question on Quora recently: “What are some of the best life tips?” and this answer by Dean Yeong is excellent. It contains number of points and I would like to highlight some of my favorite ones below:

#4. Stop complaining – “it changes nothing at all” – so true. I think all of us go through a phase where our first instinct when things don’t go our way is to turn to complaining. Luckily some realize how wasteful such a habit is and get past it. You are better off spending your energy else where.

#7 Detach your emotions with external things – meaning don’t allow others to influence how you feel and how you go about your business. I think part of this includes surrounding yourself with people who are less concerned about controlling / influencing your feelings and instead are there to share their ideas and support you when necessary.

#12 Take tiny actions, celebrate small wins – this one is big for me personally. Often I witness how people are very dismissive of small steps thinking that they are simply too small to make an impact. When we see people accomplish big things we don’t see the paths that got them there and in truth it often starts with a tiny step. For instance, one Stanford professor seems to have dedicated his all career to this idea with of tiny habits as a way to bring a positive change to your life.

#21 Fail hard, fail often – in my world I translate this to “do not be afraid to deploy” 🙂 Honestly, I don’t do this enough in my life, but when I do, the benefits are very visible. Failing hard and often means trying often and if you combine that with learning from failures that means you are just getting better at what you are doing.

Here are some items on the list that I am reluctant to do, or haven’t done as often as I think I should (#21 is already mentioned above):

#11 Relationship is the place to give – only after having children did I start to learn to live life more selflessly and give to others. It’s still a work in progress and outside of my children I tend to be more reserved and not involved.

#14 Do something that scares you – this one is a tough one. I can count on my one hand how many times I did a scary thing in the last 5 years. That’s a troublesome realization. I need to keep this in mind the next time I get that “this is crazy, let’s not do it” or “I don’t know how to do this or if I should do it” feeling.

#18 Start selling – that’s an interesting one. Couple times in my life I actually did do some selling and was pretty good at it. First experience was selling candy in the market when I was 14-16 years old during summers. Made nice amount of money for cool school supplies and other knickknacks that my parents would not buy. Then later in my life selling my stuff on eBay until I sold all of the things I wanted to get rid off. My first job out of college was private software consulting and writing various programs for a patent lawyer. And then I kind of stopped but I do remember enjoying the process immensely. Just getting a kick out of somebody placing an order and me following through with it and giving back great service and great customer support.

Hope you enjoyed the quora post and my thoughts on it. I am very thankful for people who share their ideas and expertise that they have gathered in their lives. Hopefully all of us can find useful information and learn and share it with the rest of the world.

Having options – not always a good thing

It struck me this past weekend how having options  can be a hindrance to getting things done. I was doing something where a window of “free” time was coming up in the next two hours. As I was about to start reading a book, I thought, “well, what if I did some programming instead?” And of course a debate followed in my head which one to do next. “Couple hours, not a lot of time to do programming, maybe I can respond to emails instead, so I don’t have to do it later? But then reading would be good too. Which one should I do?”

I ended up reading, but this made me think how planning ahead helps to avoid mental debates on what to do next. I usually plan my day a night before but had skipped it for that day and voila. Couple hours might not seem much, but if you are a top performer and keep yourself very busy, couple hours are quite precious.

This situation brought back the memories of times when I was a kid and there usually was only one thing to do. It allowed me to buckle down, and do it. Even if the task was boring, you just kind of did it because there was nothing else to do. It is an extreme in an opposite direction, but something that made me remember how a lack of choice got one moving without too much mental effort in deciding what to do next.

Weekly planning process


Every week, mostly Sundays, I sit down and go over what happened during the last 7 days and what I am planning on doing next. I have been following this weekly planning process for several years now. It helps in several areas. First, I am more prepared and can get done more. Second, taking time to reflect and look ahead keeps me aligned with my goals and challenges I have set for myself. It is another way to take a step back and have an overview of what is going on.

The planning session process has changed over the years, and it continues to change as I learn new things about myself. Its most recent version has these questions:

  • which habits am I working on and how did I do on them in the last week
  • what were the top 3 most important things I did last week
  • what things did I fail to accomplish
  • did I do what I said are my top 3 things from the last week?
  • what are my top 3 things for the next week

And now I have added on more, “What are you most thankful for?”. I have read that it is a good idea to practice gratitude. So I am trying it out and so far I do indeed like it. I actually love it, especially when I take a moment to be thankful for my family and how lucky I am to have them.

So yeah, if you hear people do more planning but not sure where to start, weekly planning sessions might be a good start. Usually you will need an hour, at least to start with. You can get more detail and intense once you get into planning habit and get a better sense of what you can get done in a week. Until then, start small and improve as you go.

Boring stuff first

Our excitement level is really high when we start doing something that we like and is new to us. Be it a new sport that you just started playing, a great book you have been waiting to read, or a project at work that fits your interests really well. At this stage spending the time and energy on a task is easy. You have a high desire to jump in, take action, and run with it. And then of course life happens, obstacles appear, unanticipated findings and other “derailments” come around and the going gets tough. Hopefully you planned well and can navigate around the obstacles to complete whatever you wanted to complete on time. Always be ready for the process to get tough or boring, so to speak.

This initial excitement in the early stages is the reason why I have been starting to do the “boring” stuff first. I know that boring / mundane tasks will get much harder to do once the initial high wears off. Boring tasks can’t be avoided, so best to plan for them and make sure to do them before or together with the things that excite you.

Take software development for instance. I used to leave the monitoring part of a software release as a last piece in the implementation. The excitement of solving the problem was the main priority. After all, monitoring can be a mundane and thus a very boring task. The first time around you are excited to wire up probes and get notified when things fail. But after going through the process several dozen times it gets old pretty quick. You start getting that inkling to release the feature first and then add monitoring pass later. Of course, that is not a good idea. Although it is better than nothing, it can get forgotten or done haphazardly. That’s why whenever possible I layout the monitoring and logging first and then tackle the implementation that I wanted to build.

This rule should not be applied if you are prototyping or trying things out. When you are learning, it is best to remove the boring stuff altogether and focus on the meaty parts. Remove the obstacles for learning. However if you have a good idea of where you are going with the implementation, do yourself a favor and think of the boring stuff you need to do and make sure you get that done as early as possible.