Wednesday, July 3, 2013

Tip: Explain to others your finding

The first tip is a general tip that applies to mostly every field where you need to solve a problem. Basically sometime you really need to explain the ideas of a possible solution to someone to really understand it yourself. This can also work using writing but of course the colleague can give you also useful input and ideas. This helps mostly people that like me have a general picture of the whole system but with a not clear knowledge of the specific code we are working on due to inexperience with that code. People that like me prefer a picture rather then a text explaination tend to use more the side of the brain typically used for artistic and visual skills. Unfortunately programming is not a visual rappresentation of an algorithm but a sequence of logic steps. Forcing yourself to explain or write down what's happening in the system helps to convert the wide but opaque visual image you have in your brain to a more specific logical view where all the connection between elements gets explained. It will be like seeing a painting from the distance and discover that is actually a mosaic when we move near to it, where small pieces are connected together to form a single shape.

Tuesday, July 2, 2013

It's doing the wrong thing but everything looks fine....seems magic!!!

I'm working for 1 year for a big company in the embedded engineering field and I have faced some bugs that make me tell to colleagues: "It's doing the wrong thing but everything looks fine....seems magic!!!".
Unfortunately or not, there is no magic. Everything happens from a reason and there are few many cases where this is due to HW issues. Often the bug depends on particular time or configuration that makes it appear or disappear simply adding a safe printf. Also a stressfull day is not the best friend when facing these issues and probably it is better to have a break or simply tackle it the day after. In this way, all the "polarization" your mind has about how the things are (not) working are kind of released and a fresh mind can easily find new views of the problem. Asking for help is also a good way have a new point of view and ideas to solve the issue.
 
 I will publish time to time some "tip" about what to look at when facing a difficult bug and how to approach them, hoping that sharing what turned to be my solution can help someone on their debugging journey.


Thursday, April 11, 2013

21st Century C - Book Review


In few words this book is a collection of brief introductions of all the aspects regarding programming in C using methods and tools gained probably from the author experience with open or closed source projects. First, this is not a book about C programming language. It is a book for people who start to program in C and want to learn how to start using it in a proper and efficient way to create something more than programming exercises. The main idea that the author want to tell is that C is not only a system level programming language and can be used for other general purpose applications. The book is splitted in 2 main parts: the former talks about setting a C environment that automates most of the tasks as compiling, documenting, testing, releasing, source control and process flow. The latter is about tips of the C language that can be usefull to speed up the work.

The first part is the more detailed and covers most of the aspects of compiling C programs

- Chapter 1: Set yourself for compilation
- Chapter 2: Debug, test, Document
- Chapter 3: Packaging your project
- Chapter 4: Version Control
- Chapter 5: Playing nice with others


Those chapter titles explain most of the content of this first part of the book. They try to guide the reader to have a functional environment that covers all the
steps of the software development.

The tools briefly descripted in this chapter are:

- compilers for different OSes.
- GDB for debugging
- Valgrind for memory problems checking
- Doxygen and CWEB for automated documentation
- Shell, make and Autotools for automatic and easy compiling
- Git for source control
- Tips for write understandable and clean code

The second part of the book is about bits and pieces of the C language:

- Chapter 6: Your Pal pointer
- Chapter 7: C syntax you can ignore
- Chapter 8: Obstacles and opportunities
- Chapter 9: Text
- Chapter 10: Better structures
- Chapter 11: Object-oriented C
- Chapter 12: Libraries


This chapter contains mostly some tips about pointers, string, sintax and data-structure management. It covers some high-level stuff like databases and network connection but really briefly.


In my opinion the author tries to explaino too many things in one single book. He wants to give to C more visibility to the Application Engineers that typically use high abstraction. At the same time he wants to give guidelines about the environment and give hint on some pieces of the language. Except for the first part that covers enough the argument proposed in the chapter title, the second part seems to be a collection of blog tips glued together chosing within the most strange aspects and missing of C. I think as a programmer but even more as bad DIY mechanic that the tool is the most important part of the job. It's fine to use C if you really need to use the performance and the feature it only has, if you don't need those simply don't use it. Java, C#, Python and so on are more easy to use for some applications and should be used instead. Probably application engineers can benefit from this book to have some idea or have a start with C. Newstarters in C and programming can found it useful but they will need to integrate with other resources all the brief description given for some tools (I suggest to read Pragmatic Programmer)

Friday, August 24, 2012

Programming Computer Vision with Python - Book Review

What a great book!!!!!

I know I'm not impartial because I like computer vision, but this book really is a big supplement to computer vision classes you can have in college. The choice of the language used is also great for both the amount of programmers that use it, that also for the fluency of the programs created. Has to be mentioned that this book is for intermediate students how wants to do some other advanced stuff of computer vision usually not covered by specific classes. If you are kind of a mathematical person who like formulas and demostrations and wants to know more about the theory behind some example, it would be preferable complement this book with others (I remember Multiple View Geometry for example) that explains much better details the theory used.

Below you can find a brief explaination of each chapter in the book:

Chapter 1 - Basic Image Handling and Processing
This chapter simply explains what functionality are available for handle images using python and the PIL library provided. It also explains the other libraries used as Numpy, Scipy, Matplotlib

Chapter 2 - Local Image Descriptors
After a brief explanation of what are local image descriptor, the chapter explains the Harris and the Sift descriptors. The example of this chapter is to create a graph of relation between geotagged information retrived on panoramio.

Chapter 3 - Image to Image Mappings
In this chapter, homographies and affine transformation are explained. The method of Direct Linear Transformation Algorithm to find the homography based on correspondent points is explained. In case of affine transformation, fasted way to find the matrix with less correspondencies are described. In this chapter the example guide the lecturer to create a panorama creation system based on multiple images. As contour of this example RANSAC and Delaunay triangulation algorithms are briefly explained.

Chapter 4 - Cameras and Augmented Reality
Really interesting chapter on modeling cameras through its projection properties and use this properties to create an augmented reality application. Camera Calibration is also explained in this chapter that is completed by an example of augmented reality using PyOpenGL to load a model in the image correctly aligned to a reference image.

Chapter 5 - Multiple View Geometry
Chapter about epipolar geometry and 3D recostruction using multiple images and different sets of matrices available to describe their relation. It also explain theory behind the stereo images system and concludes the chapter and example of 3D recostruction.

Chapter 6 - Clustering Images
This chapter introduces some clustering methods (as K-means) and explains how to use them to find relations between groups of images. Techniques as Hierarchical and Spectral clustering are explained and using to divide images into related  groups.

Chapter 7 - Searching Images
How to find an images in the fast way is a problem that has to be solved in application with an huge knowledge base and sometimes the only use of reduction techniques as PCA is not enough. In this chapter techniques derived from text mining are performed to find "visual" words inside images that can be easily search in a "vocabulary"

Chapter 8 - Classify Image Content
Classification is the process of deciding to which class a sample belongs based on some measurment executed on it. Starting explaing the K-nearest algorithm, the chapter continues describing a method to use Dense Sift feature as classification measure together with Bayes classifiers and SVM classifiers. The chapter ends with an interesting example on resolving sudoku's after have classified all the fixed numbers.

Chapter 9 - Image Segmentation
The segmentation of an image consist in separate regions of the image that are likely to have a similar mean (ex. Background vs Foreground). The techniques used are Graph Cuts, Segmentation with clustering and Variational methods

Chapter 10 - OpenCV
Very straightforward chapter about the functionality provided by the opencv library.

To conclude, this book is actually great. For me that I am interested in computer vision, this book explained the newest and coolest methods that can be used to build powerful and appealing application in the era of powerfull smartphones and huge images datasets freely available.

Wednesday, July 4, 2012

Safe C++ - Book Review

Everybody knows how is tricky to manage all the complexity and the feature that c++ provides. From memory allocation to copy constructor ending up with address manipulation, It's very easy to make a mistake and sometimes is difficult to find the reason of it.

Safe C++ is a book for intermediate C++ users who wants avoid common mistakes that usually happens. From memory leaks to comparison operator, the book explains how a simple macro definition can help you to remove problems. The book is easy to read for who is practical with C++ and the 140  pages that composes it flows very fast. The book is composed by 17 short chapters, each of which tackles a specific issue:


The first 3 chapters are sort of introduction to the specific issues treated later in the book:
 Chapter 1: Where does c++ bugs come from?
 Chapter 2: When to catch a bug?
 Chapter 3: What to do when we encounter an error at runtime.


The middle chapters are more specific and tackles a specific issue:
 Chapter 4: Index out of bounds
 Chapter 5: Pointer Arithmetic
 Chapter 6: Invalid Pointers, References and Iterators
 Chapter 7: Uninitialized Variables
 Chapter 8: Memory Leaks
 Chapter 9: Deferencing NULL pointers
 Chapter 10: Copy Constructors and Assignment operators
 Chapter 11: Avoid writing code in the destructors
 Chapter 12: How to write consistent comparison operators
 Chapter 13: Errors when using Standard C libraries

The last three chapters talks about testing and how to help the debugging process:
 Chapter 14: General testing principles
 Chapter 15: Debug-On-Error strategy
 Chapter 16: Making your code debugger-friendly   

 This book explains how to avoid most common mistakes and bad pratices when programming in C/C++. It's a good book for intermidiate and can help also beginners to understand some tricky behaviour of C++. Together with other more general books as the pragmatic programmers series and so on, can be a good reading to master a good coding style.

Thursday, June 21, 2012

Android Cookbook - Book Review

This book talks about the new mobile OS Android. This OS (even if Framework is more appropriate) is widespreading through mobile and embedded devices. As the title suggest, this book use a Cookbook style for explain the concepts. Each problem is treated as a Recipe and is composed by 3 parts:

  • Problem: few rows to describe the problem that needs to be solved. 
  • Solution: few rows that explains briefly what must be done for solve the problem. After reading the book, this is kind of a bookmark for future research in the book and allows the reader to remember how to solve a problem simply reading few lines. 
  • Discussion: Here is described the solution in all of its aspect. The code is widely described and everything is covered to let the reader understand the solution.


Because this book covers a lot of problems with their relative solution, I prefered to copy the description of the chapters as appears in the preface of the book instead of described them myself.
What’s in This Book?
  • Chapter 1, Getting Started, takes you through the steps of setting up the Android development environment and building several simple applications of the well-known Hello, World” type pioneered by Brian Kernighan.
  • Chapter 2, Designing a Successful Application, covers some of the differences in mobile computing that will hit developers coming from desktop and enterprise software environments, and talks about how mobile design (in particular, Android design) differs from those other environments.
  • Chapter 3, Testing. Not so that you’ll skip it, but so that you’ll read and heed. We talk about unit testing individual components as well as testing out your entire application in a well-controlled way. Android provides a variety of mechanisms for communicating within an application and across applications.

  • In Chapter 4, Inter-/Intra-Process Communication we discuss intents and broadcast receivers, services, AsyncTasks, and handlers. Another communication mechanism is about allowing controlled access to data that is usually in an SQL database. 
  • In Chapter 5, Content Providers, we show you how to make an application that can be used by other applications through something as simple but ubiquitous (in Android) as the URL.
  •  Chapter 6, Graphics, covers a range of topics related to graphics, including use of the graphical drawing and compositing facilities in Android as well as using desktop tools to develop graphical images, textures, icons, and so on that will be incorporated into your finished application.
  • Chapter 7, Graphical User Interface, covers the main ins and outs of GUI development for Android. Examples are given both in XML and, in a few cases, in Java-coded GUI development.
  • Chapter 8, GUI Alerts: Menus, Dialogs, Toasts, and Notifications, covers all the pop-up mechanisms—menus, dialogs, and toasts—and one that doesn’t pop up but is also for interaction outside your application’s window, Android’s notification mechanism.
  • Chapter 9, GUI: ListView, focuses on one of the most important GUI components in Android, the ListView. Android is rich in multimedia capabilities.

  • Chapter 10, Multimedia, shows how to use the most important of these.
  • Chapter 11, Data Persistence, shows how to save data into files, databases, and so on. And how to retrieve it later, of course. Android started out as an operating system for mobile telephones.

  • Chapter 12, Telephone Applications, shows how to control and react to the telephone device that is in most mobile devices nowadays.Mobile devices are, for the most part, always-on and always-connected. This has a major impact on how people use them and think about them.
  • Chapter 13, Networked Applications, shows the coding for traditional networked applications.

  • Chapter 14, Gaming and Animation.

  • Chapter 15, Social Networking.

  • Chapter 16, Location and Map Applications, discusses how to find your location, how to get map data from Google and OpenStreetMap, and how applications can be location-aware in ways that are just now being explored.

  • Chapter 17, Accelerometer, talks about the sensors built into most Android devices and allow to use them. 
  • Chapter 18, Bluetooth, talks about the low-energy very-local area networking that Bluetooth enables, going beyond connecting your Bluetooth headset to your phone.

  • Chapter 19, System and Device Control. Since Android is Linux-based, a few of the recipes in this chapter deal with traditional Unix/Linux commands and facilities. 
  • In Chapter 20, Other Programming Languages and Frameworks, we explore the use of other programming languages to write all or part of your Android application. Examplesinclude C, Perl, Python, Lisp, and other languages.
  • Chapter 21, Strings and Internationalization, goes over the
    issues of language and culture and how they relate to Android.

  • Chapter 22, Packaging, Deploying, and Distributing/
    Selling Your App, shows how to prepare your application for distribution via
    the Android Market, and to use that as well as other markets to get your application
    out to the people who will use it.

I've never read an Android book before this one and I was a little bit suspicious about how this book would be comprehensible compared to other books more focused on the whole framework instead of single problems. I remained surprise of how this book is clear even for new comers in the Android world, each problem is discussed perfectly and the discussion part of each problem covers also the paradigms of the Android framework. Has to be noticed that a strong Java background is needed, together with a basic knowledge of the Eclipse IDE. I suggest this book for both new Android developers and expert ones, the former can find in this book an explanation about the Android framework, how to use the framework with real problems and a lot of examples that can be reused for create the application they imagine. The latter can  improve their knowledge about topics not treated in their current developments and improve with new functionality their apps.

Friday, May 11, 2012

Machine Learning for Hackers - Book Review

I was following the courses in Machine Learning through the Coursera website when i had the chance to review this book. For me it's difficult to start programming without a real motivation or pressure of a deadline and I hate myself for that. Reading or follow only theorical lectures is, of course, useful to improve your knowledge and find similar patterns in different problems but only when you start to practically use what you have learned that your mind stores the information in a more solid way.


This book tries to be less mathematical as possible, diving directly into practice with the R language functionality.
After explain the functionality of the R language, the author explains the main categories of machine learning algorithms as Supervised and Unsupervised learning.
  • Categorization: using a Bayesian Classifier wrote using R, we will be able to categorize Spam messages from good messages
  • Priority Ranking: in this chapter the author describes what features are used by google to define a priority in the received emails and provides the code for write your own ranker based on this features.
  • Linear Regression: this chapter explains one of the powerful tools of Machine Learning, Linear Regression. Using Linear Regression the case of study explains how to create a system that predicts page views of the 1000 top websites. This chapter explains also different measures of error that can be performed to test how our model works.
  • Nonlinear Regression and Regularization: the first part of the chapter explains Nonlinear regression that means when the prediction can't be mapped in the linear formula:                                       Prediction= Constant + X+Y+Z.  The second part of the chapter talks about Regularization that explains how to prevent the overfitting, that means our model fits so good the training data but is no able to fit the test data in the long run.This is due to the fitting of the training data that is so precise that starts to model also the noise (outliers) in the training data.
  • Optimization: After we define a measure of error for the model, we can tune it, optimizing some parameter. This parameters are the result of the minimization of the error measure for example. The case of study of this chapter is to build a Code breaking system. 
  • PCA: This technique allows to reduce the complexity of the data reducing the dimension of the problem and is useful to extract a vectore that resumes all the data set.
  • MDS: Sometimes is difficult to see the relations between different features without a graphical help. The MDS algorithm allows to create a clustering of all the data and is able to plot this clusters in a meaningful way.
  • K-nn nearest neighborhood: Sometimes isn't possible to define a model general for the whole dataset so, we can make a prediction using the nearest possible choices and give a score for each one. This system is used in the case study to realize a recommandations system that suggests packages based on the installed packages.
  • Social Graph: this chapter explains how social website define their connectivity model and explains how to study the relationships realizing a "Who to follow" system for twitter.
  • SVM: the support vector machine is another powerful tool for machine learning and is widely used when isn't possible to define a linear decision boundary. The case of study of this chapter is a comparison of the prediction algorithms used in the previous chapters.
For my point of view, this is a good book for who wants to dive into machine learning without know anything about math, statistic and probability. Honestly I think that this approach doesn't work well, at least for me, because some algorithms are difficult to use correctly or find a relation with our problems without the abstraction that math gives. Also, theory is useful to understand better how some parameters affect the prediction. Sometimes in the book there are notions that needs theory but instead there are explained as "change the value and see what happens" method.
Even if this is not a R programming book, the language is not clearly explain in the text and a previous study of the language is probably necessary or translating the code in a more common language as Python will help understand the problems. I've also notice some incoherence between the text and the code, in fact I've faced some errors using the code in the text while the code in the CD-Rom work perfectly.

As conclusion, I will suggest this book to someone who wants to learn autonomously concepts of machine learning but, I suggest to use the online courses for study the theory behind these algorithms.