Academic people should git and TeX

Mr Torvalds created two amazing things: Linux and Git. Former is an OS kernel; latter is a version control system. Unluckily, none is prevailing in Malaysia.

When I was a lecturer, creating a new programme with various courses is truly exhaustive. The worst case is recording the changes of the documents for the government agency’s accreditation. If you are systematic, you will backup the files. But backing up the files does not tell you what are the changes you had made. Unless you create another note for each changes you made. But that will be double works. If you say you can use Microsoft Word’s feature to compare the documents and see the changes, it is totally impractical if the two documents are big and there have a vast changes.

What is the best solution? In practice, you need to ask your boss to step down and change all your colleagues ­čśë, because your boss doesn’t understand your solution, he and your colleagues will treat you as idiot.

In the condition above, the best solution is using TeX and Git. TeX allows you to create your document in plain text. Plain text is so important for Git. Git allows you to keep track the changes you have made, and you can see the difference of the changes line by line in text format.

Git allows you to work collaboratively with your team members to work on same project by preventing the conflicts. Preventing conflicts doesn’t mean there will have no conflict, but you will detect the conflicts earlier and need to resolve the conflicts manually.

TeX, unlike WYSIWYG application software, such as Microsoft Word or LibreOffice Writer (I don’t think Malaysians use LibreOffice), we create the document using markup language and setup the paper style through some complex TeX statements. Though the setup may be exhaustive and TeX has a steep learning curve, the results can sustain for long-term. The document style can be re-used for the whole institution, especially if the students are provided with the thesis format in TeX form. Moreover, the TeX skill is useful to publish papers to the journals and conferences. You can easily port your content to another TeX style such as IEEE conference paper style.

Sadly, most people take easy learning tools to do the complex tasks, yet feel proud and not open minded to learn useful skills.

An academic institution should offer training to the staff, lecturers, and students to learn TeX. It would be even better to offer Git training, Linux and command-line. Open source software can reduce students financial burden, avoid pirated software, and prevent virus infection.

However these are not implemented in most academic institutions. As a result, the users are spending hours to edit the document style, generating the table of contents, or even preparing table of contents manually. That is sad to create table of contents manually. Any change on the page, you will have to edit the table of contents. However, if you are using TeX, you will focus on the content, instead of the styling.

Lastly, because the culture focuses on the outlook such as styling of the document, instead of the quality of the contents, that is why implementing Git and TeX is just an unrealistic approach. Great Microsoft Word, you are a legend.

Monty Hall problem and frog riddle

Monty Hall paradox

Probability topic is the fundamental concept of the statistics. And machine learning is closely related to statistics. That is why, understand the probability very important if you are doing research, statistics, and machine learning.

Monty Hall is a very interesting problem. It says, if you are given 3 doors to choose. One of them contains a car (which you want), the other two are goats (which you don’t want). After you made your choice, before opening the door, the host will open the door that you didn’t choose yet contains the goat (he knows which door has the goat). Now, if you are given an opportunity to change your choice to another door (which you didn’t choose earlier), are you going to change?

In the first glance, you will feel that whatever you choose, the probability is always 1/3. However, the conditional probability tells you that, if you always make the switch after the host opened the door that has a goat, your probability to win the car will increase to 2/3. What??

In order to prove this, I wrote a Python script.

#!/usr/bin/env python
# This is simulating Monty Hall Paradox

import random

def monty(switch):
    # random shuffle
    doors = [0, 0, 1]  # one of the door contains the car

    openDoor = None

    # choose the first door (not open)
    # if the first door is 1, randomly open the other
    if doors[0] == 1:
        # open the door
        openDoor = random.randint(1, 2)
    else:  # open the door that contains goat
        if doors[1] == 1:
            openDoor = 2
            openDoor = 1

    # now open the last door
    if not switch:
        return doors[0]
        if openDoor == 2:
            return doors[1]
            return doors[2]

def main():
    total = 10000
    car = 0
    for i in range(total):
        car += monty(True)

    print("Always switch the door. Total: {}, car: {}. P = {}".format(total, car, car / total))

    car = 0
    for i in range(total):
        car += monty(False)

    print("No switch the door. Total: {}, car: {}. P = {}".format(total, car, car / total))


Run the code, you will always get the probabilty close to 0.6667 if you always switch the door.

Always switch the door. Total: 10000, car: 6625. P = 0.6625
No switch the door. Total: 10000, car: 3309. P = 0.3309

Frog riddle

Recently I just watched a Youtube about frog riddle.

It also mentions about the conditional probability. Interestingly, quite a lot of comments mentioned that the author is wrong.

In order to prove that the author is correct, I wrote another Python script.

#!/usr/bin/env python

import random

# Frog 0 for female, 1 for male

def create_frog():
    return random.randint(0, 1)

def has_croak(pairs):  # also male
    return 1 in pairs

def has_female(frogs):
    return 0 in frogs

def choose_without_croak(choose_two):
    frogs = [create_frog() for i in range(3)]
    # first frog at the right side
    # second and third at the left side

    if choose_two:
        return has_female(frogs[1:])  # choose two frogs

    return has_female(frogs[0:1])

def main():
    total = 10000
    correct = 0
    for i in range(total):
        correct += choose_without_croak(True)
    print('Just choose two frogs. Total: {}, correct: {}. P = {}'.format(total, correct, correct / total))

    correct = 0
    for i in range(total):
        correct += choose_without_croak(False)
    print('Just choose one frog. Total: {}, correct: {}. P = {}'.format(total, correct, correct / total))

# The exact question is,
# "What is the probability of the frogs in the pair has female,
# given that one of them is male?"
def exact_calculation():
    total = 10000
    croak = 0
    correct = 0
    for i in range(total):
        frogs = [create_frog() for i in range(3)]
        if has_croak(frogs[1:]):
            croak += 1
            if has_female(frogs[1:]):
                correct += 1
    print('Total croak: {}, correct: {}. P = {}'.format(croak, correct, correct / croak))


Running the script, you will get

Just choose two frogs. Total: 10000, correct: 7498. P = 0.7498
Just choose one frog. Total: 10000, correct: 4974. P = 0.4974
Total croak: 7474, correct: 4998. P = 0.6687182231736687

Based on the result, if you choose two frogs, the probability of survive is close to 0.75. If you choose one frog, the probability is 0.5.

Now, the tricky part is the probability 0.67 mentioned in┬áthe video. The question should be “What is the probability of the frogs in the pair has female,┬ágiven that one of them is male?”

So, based on the question, my similuation needs to get the total count of the male (that has croak), and within these pairs, count the female frogs.

To convert this into mathematical expression,

P(\text{female frog}) = 0.5

P(\text{at least one male frog}) = 0.75

P(\text{female frog} | \text{at least one male frog}) = \frac{0.5}{0.75} = 0.6667

Then, based on the simulation and calculation, you will get the 0.6667.