Polynomial Regression is a form of linear regression model but fits a non-linear relationship between the value X and Y. Basically we have to add new features to the final equation. But what features? It’s simple we can add the X1 feature as new feature: X1^2 or X1^3. If we have some input features (X1,X2,X3) also we can add new features as X1*X2 or X1^2*X3^2. So, the polynomial regression model is:
![]()
As you can see in the following figure you can get a linear regression (red line) or you can get a non-linear regression (blue and yellow) if you add more features to your equation. The type of curve of non-linear regression model depends of the grade of your polynomial. If the grade of the polynomial is near 1 the model fits to traditional linear regression model. Instead, if the grade of the polynomial is high the model fits to training points.
OverFitting is the term that it’s used to describe when your linear regression model don’t have capacity to predict because the model fits very near of the training points. This fact can happen if the model is very complex or the grade of equation is high. You notice that over-fitting is bad for your model and you should avoid it because the predictions will be very similar or equals to the training points.
You can play in live with this concept about polynomial regression in the following link: http://www.arachnoid.com/polysolve/index.html
Also you can get the source code of this example from my GIT repository.
I need to record some screencast with audio for my online classes of Android. It’s a good way to explain all the topics about programming and android development. Slides, exercises, moodle and screencast is a cool combination to create high-quality online courses. Also I use a digital tablet to write in the desktop/slides to clarify the explication. Finally I’m used to manage openShot as video editor, it’s simple and very powerful.
I use the following ffmpeg command to record screencast (audio+video) of the desktop and Android emulator:
ffmpeg -f alsa -i plughw:0 -f x11grab -s 1680x1050 -r 24 -b 200k -bf 2 -g 300 -i :0.0 -ar 11050 -ab 64k -acodec libmp3lame -vcodec libxvid -aspect 1.555 -sameq outputFile.avi
To avoid problems with the audio recording you must configurate your android emulator with the following keys:
Audio PlayBack Support = NO / FALSE Audio Recording Support = NO / FALSE
19 Apr
Posted by: rocapal in: codigo, floss, libresoft, machine-learning
I continue working with machine learning algorithms. In a previous post I talked about linear regression with one variable and I described different algorithms to predict hypothesis.
In this case, I’m playing with linear regression but, with some features. Linear regression only have one input feature and one output feature. For example, you can predict the price of a house give the house’s size. But imagine that you want predict the price of a house using size and rooms features. When you have more than one input feature is called ‘multi-variable linear regression’.
In the following figure we can see the two input features (size and rooms), the training data (red dots), and the predictions (blue dots). In this case, we can represent the information with a 3D model. If your model have more than three features you must research the way to represent all the data.
For a house with 70m and 2 rooms, we predict a price of 143496.23€ For a house with 100m and 3 rooms, we predict a price of 203095.22€ For a house with 175m and 4 rooms, we predict a price of 363570.19€
It’s important notice that in this case we are working in 3D space, so the regression model is represented by a plane (instead of line, as one-variable linear regression model). In the following figures you can see how the predictions dots are on the plane. We obtain always a plane regression if we are using three variables and none of them are quadratic or cubic features. Thanks to mplot3d library you can render 3D graphics and move the perspective of the figure to see the regression plane from different points of view.
17 Apr
Posted by: rocapal in: floss, libresoft, machine-learning
Since two months ago I’m researching about machine learning and its algorithms. The goal is get a good unsupervised and clustering algorithm to analyze every android applications and predict what application you want to install or use in a particular time. The first step is learn and understand the theory of machine learning. For this, I began to study the Machine Learning Course of Stanford. It’s a great and practical course with videos and material to help understand the classes.
The first model that I have studied is linear regression. This model consist in have a relation between two or more variables. For example, in my example I have a training data about the prices of the houses and its size in square meters. This training data is used to build a linear regression model to predict the prices of the house give the size of the house. As you can see in the following figure, the black dots show the training data (I did web crawling to get real data). The blue line represents the trend line of the model, and the red dots show the predicts for two size of houses.
You can see the prediction values that are represented by red dots in the figure.
For a house with 100 meters, we predict a price of 202906.39 euros For a house with 175 meters, we predict a price of 354343.54 euros
You can use Octave or R to practice and implement machine learning algorithms. Personally, I prefer to use a great and FLOSS library that I found, scitik-learn. This library has several implementations of linear models: LinearRegression, RidgeRegression, Lasso, Elastic Net, …. For this example, I have used the SGDRegressor model but, I want to test other models more smooth like Lasso or Elastic models.
You can get the source code of this example in my GIT repository
Decompile is a process to revert the compile operation. I main, decompile converts the low level code in high level code. The Android application is compiled in APK container that groups files as: xml, images and class. APK containers are actually ZIP containers. An interest thing is can see the xml configuration or some source code of others applications. If this applications are Free Software is not a problem, but if this applications are privated we can’t see its configuration. The next application help you to decompile an APK file to see xml configuration and source code.
Some tools I’ve found:
ESTUFAÂ is a framework that provides several ways to connect and re-use mobile applications (in previous post I already presented this idea). The system allow build “execution chains” to connect and plumb two applications.
This project is based in the idea of re-use and compose new applications using components (in this case Alchemist). It has a strong context with “end-user software engieneer”, we want implement a solution from end-user non-developers to build new applications without technical knowledge.
See the video to know how it’s possible connect IO FileManager with Twitter or GMail. For this, we use an execution chain that create a file zip from files of File Manager, upload it to dropbox, obtains a tiny URL pointing to dropbox and finally send this url to GMail or Twitter. The power of ESTUFA resides in its alchemists and the compatibility between these and applications.
If all goes well, this project will be my PhD thesis over the next 2 years
The next video shows how is possible read/write an analog I/O (values between 0 and 1023) and read/write digital I/O (values 0 and 1). We have connected three leds to digital outputs and one potentiometer in an analog input. The potentiometer simulated all possibles values (0-1023 ~ 0-5v).
Arduino Source Code: ExampleBoardArduino.zip
Android Source Code: ExampleBoard.zip
26 Jul
Posted by: rocapal in: android, arduino, augmented_reality, libresoft
During the next months I will work in three interesting topics. The first of them is the creation of a new architecture based in Android that allow communicate and integrate applications. The second  is the port of ARviewer to iPhone platform using phoneGap. And the last one is the very well-know Arduino and its possibilities with Android USB Host.
Some months ago we have started to developed a new idea about “create new android apps easily”. The magic idea is that the user can connect two o more applications with “connectors” (your way), although this applications haven’t been developed for that purpose. For example, imagine that you can (as user) configure twitter to show the all contents in ARviewer application, or you can configure to show this twitts in an amazing map. The developers don’t know the use of his data, only they configure some outputs and inputs and the final user is the responsible of link this applications. Numerous filters also are incorporated into the platform, so the final user can modify the data exchanged between applications. All the ideas are early but I wish tell you in more detail in the next posts.
Currently, ARviewer is the best FLOSS augmented reality viewer. The last year, we began the port of ARviewer to other platforms (iPhone) using a multi-platform framework. In the previous post I talked about the implementation in Android using PhoneGap. In short, we will have the development completed to run in iPhone platform. Some people have shown interest about this project, so we are very exciting about this and we are looking forward to show our work!
Google announced  in the last Google I/O a new feature: Android Open Accessory Development Kit. The new amazing feature allow communicate the Android devices with the Arduino boards using a USB HOST! This is a cool idea! New projects are shaping up using this technology to communicate micro-systems with Android devices. For example, imagine a little electronic circuit with Arduino that control a cooling system. You could connect your android phone to Arduino board to control and recollect all the information about the system. See an example of this idea [video]
The next 6 months I will work in these topics, so I wish tell you all the results about this interesting topics before the end of the year!
Security and Surveillance Systems have always been demand in the industrial and home environment. The cameras, which human eyes are able to collect all visual information from the environment. Extensions necessary and highly desirable in these systems, and that few possess, are integration and interconnection with other systems, video surveillance and display all the information on a mobile device, which lately is becoming essential in a peripheral daily life. Most existing surveillance systems are based on the hardware, and software is old and have not a good design, so it’s difficult allowing scalability and increased functionality.
This project, called Surveillance, raises the development of a distributed video system integrated in mobile device based on Android. For this we have designed a distributed system, multi-platform, multi-lenguage and high scalability. The system performs records through the cameras installed and it is associated with an alarm generation by motion detection. All this is managed and viewed from a mobile device based on Android with intelligent touchscreen. One of the most important features has been developed is receiving real-time video in mobile device, both the cameras and recordings made.
The system has been experimentally validated and proven correct operation. For the implementation of this project is used software platform architecture and JDEROBOT, distributed component programming six main functions that are: get the images from the camera, motion analysis, centralize the management of the recordings, making the recordings, display information on mobile and manage logical recordings and alarms. It has also opted to use frameworks, consolidated libraries and tools (ICE, GStreamer and VLC) to provide robustness to the system. Finally, we have integrated and improved several components of this infrastructure, obtaining a correct and efficient functioning.
Of sourse, this project is a FLOSS (Free Libre Open Source Software) project. You can obtain the source code and documentation in the next links:
Three months ago I wrote a post describing the plan that Raúl Roman and I are involved: build an augmented reality interface using PhoneGap. Today, we have uploaded a beta version (0.1.0) of ARviewer-PhoneGap to Android Market. This version works fine and shows the geolocated nodes obtained from libregeosocial server. The next steps are:
Are very very similar the next images, right? Only we have found a critical problem with the refresh of nodes in the WebView using PhoneGap. We will study and analyze this behavior.
ARviewer PhoneGap

ARviewer Android (native)
More info: http://www.libregeosocial.org/node/24
Source Code (GPL):Â http://git.libresoft.es/ARviewer-phoneGap/
Android Market:Â https://market.android.com/details?id=com.libresoft.arviewer.phonegap