Monday, February 27, 2017

Probability: Difference between "exactly..." and "at least..."

In probability, I have to pay close attention to the problem statement because I easily make errors. As an example, let's say I toss a fair coin n times. What is the probability of
  1. Exacly 1 head
  2. At least 1 head
The figure below has n as the x axis and the two different probabilites as y axis. As you can see, the "exactly 1 head" probability decreases with n while the "at least 1 head" probability increases with n.

Matlab script for generating the plot:
n = 1:16;
pExactly1 = n./2.^n;
plot(n, pExactly1); grid on
hold on
pAtLeast1 = 1-(1-0.5).^n;
plot(n, pAtLeast1)
legend('exactly 1 heads', 'at least 1 heads')
xlabel('n'); ylabel('p')
Note that you can also get probability of at least 1 heads with this sum: pExactly1Head + pExactly2Heads + ... + pExactlyNHeads, where
pExactlyKHeads = nchoosek(n,k) * ph^k * (1-ph)^(n-k)
Even simpler: 1 - pExactly0Heads = 1 - nchoosek(n,0) * ph^0 * (1-ph)^(n-0).

For more information, visit Khan Academy.

Car IoT

As aircraft have become software with wings, so are cars on their way to become software on wheels. Self driving and IoT have accelerated this trend. Yesterday, when I was talking with my friends we envisioned a design that could improve driving comfort: Cars could collect vibration data measured by their sensors and transmit it together with location information to servers. This data would indicate road quality. The server could process and broadcast data to all cars. Other cars could adjust suspension settings in advance that would maximize comfort on that road.

With this technique, only the first few cars that collected data would suffer and the rest would benefit. Data would be current at all times. I think Google Maps uses a similar approach to guess traffic congestion by collecting data from smartphones.

To collect data we need:
  • Vibration sensors on car.
  • Access to internet and access to central data server
To adapt to road conditions we need:
  • Adaptable suspension on car (i.e. actuators and sensors)
  • Access to internet and data server by car.
If we could protect privacy, we could automatically tap into the intelligence of the swarm.

Note to self: Do a simpler version of this concept as a hobby project.

How to evaluate personnel

It would be easy to evaluate performance if everybody (including the evaluator) was of high quality and there was no Dunning–Kruger effect. Your only criteria would be years of experience. Unfortunately, real life is more complex than that and there are large differences between employees.

The next best thing might be to have three bins: low, average, high. The low bin might be for fresh graduates who just started to work. The high bin consists of people who are highly productive and experienced.

You divide your staff according to their general level into these bins. Each bin has a lower and upper salary bound. Then you rank the people in each bin according to their productivity. I know that realistically measuring productivity is a tough problem but there is no escaping from it. For example, you have to decide if the person with 3 months of overtime had really productive overtimes or was just producing 8 hours of work in 12 hours. In each bin, at the top of the pyramid should be people with high productive overtime and at the bottom should be persons with no or low productive overtime. That way, you assure that everybody gets their fair share and productive individuals get their extra.

Tuesday, February 21, 2017

Android development tips

When developing Android apps with Android Studio, I get strange errors from time to time, whose solutions were not obvious to me:

Problem: When you create a Google Maps demo and run it using an emulator of API level 24 (e.g. Nexus 5 API 24), the app opens on the emulator with the message "...won’t run unless you update Google Play services".

Solution:  In \app\build.gradle file, version might be 10.2.0. Change it to 9.8.0 and your app will run fine.

Problem: In Android Studio, when I try to generate signed APK, I get "android execution failed for task validatesigningrelease" error.

Solution: Make sure you specify full path of key file.

Problem: When I try to generate signed APK, I get “Execution failed… method ID not in [0, 0xffff]: 65536” error.

Solution: If you are using Google Maps, limit the number of libraries you use by replacing in your gradle file the line compile ‘’ with
compile '' and
compile ''

Sunday, February 19, 2017

Better WhatsApp Group Chat

Group chat is widely used in WhatsApp. As the size of the group gets bigger, communication is dominated by few people who usually generate a lot of noise. I had to leave groups because I was fed up with the endless nonesense of these few people. Arguing with them makes matters worse. Almost everyone I know has similar experiences.

I can silence a whole group in WhatsApp so that I do not get notifications. What I need is the ability to mark people in a group as important and unimportant. Messages from people that I mark important should be easy to spot when I scroll through the messages. They could have yellow background and bold font. Messages from people I mark as unimportant should be shown collapsed and become only visible in full when I click on the message. That would allow me to quickly see important messages.