Posts

Showing posts with the label algorithms

Generating natural-looking digits with neural networks

Image
Pt En In this post I will show you how I got a neural network to write digits that look like they've been handwritten. In fact, the digits you can see in the first image of this post where generated by said neural network. The code that did all this is here . It all started when I read, some time ago, about this funny way in which you could use neural networks: you are going to train a neural network to take a vector of size $N$ as input, and you are going to teach your network to do nothing. That is, you are going to teach your neural network to behave as the identity function... but with a twist! If your input size is $N$, somewhere in the middle of the network you want to have a layer with less than $N$ neurons! If this happens, you can think that your vector $x$ that is going in, first has to be squeezed through that tight layer, and then it expands again to be the output of the network. If now you slice your network in half, the part of the network from the...

Pledging to do 100 days of Machine Learning and progress log!

Image
Pt En It is a shame but I kind of dropped this when I was $41\%$ done... I hope I man up and finish this in the near future. After watching this video from Siraj Raval, I decided to jump right on board of the #100daysofMLcode initiative! (even though I am something like 73 days late...) The goal here is to devote (at least) 1h every day, for the next 100 days, to studying ML or writing code! According to the rules posted by Siraj, I must: Make a public pledge for this, which this post is; Make a log of everything, which this post will also be; Whenever I see something related to this #100DaysofMLCode, be supportive! Progress log For the day $0$ I wrote this post and spent quite some time thinking about what I will do throughout. I am thinking of studying several topics about ML and then writing educative posts here, for the blog. For today I wrote this twitter proof , tackling a mathematical property of neural networks with linear activation functions. ...

Random maze generation

Image
Pt En In this post I just want to share a simple algorithm that I used to create random mazes. The idea came from an e-mail I got, about a past competition, where one of the contestants did this exact thing: a program to generate random mazes. I saw the animation of the program working here and I deduced how to do it. All the code can be found on GitHub , as well as an executable of the program, the animations from the beginning and end of this post, an image of a bigger maze, and this other animation: where you can see a different style of maze; a less straight one. The maze starts in the top left red corner and ends wherever the other red square is, which need not be on the bottom right corner. The algorithm is simple: travel randomly inside the black area without ever hitting a white path; whenever no random move can be made, start going back until you find a place where the path can branch out again. While we are creating white paths, keep updating the fin...

How to compute any square root by hand

Image
Pt En Num post anterior mostrei como podemos aproximar a raíz quadrada de um número através de um processo iterativo que começa com um palpite, seguido de vários ajustes. Neste post vou mostrar qual é o algoritmo mencionado pela Mathgurl no vídeo que ela fez em "parceria" comigo. O método que vou descrever pode ser usado com qualquer número real, seja quadrado perfeito ou não, seja inteiro ou não, racional ou não. Vou começar por apresentar um raciocínio que mostra como o algoritmo surge. Para quem não estiver interessado, pode saltar diretamente para a explicação final de como funciona . Para a exposição que se segue, se $a,b$ forem dígitos, então a notação $ab$ representa o número $10a + b$ em vez do número $a\times b$. Começamos por notar que, se quisermos descobrir $\sqrt{N}$ à mão e $\sqrt{N}$ for irracional, então vamos ter de nos contentar com uma aproximação com um número finito de casas decimais. Por outro lado, se $\sqrt{N} = a_0a_1\cdots a_n.b_0\c...

The naturals, the rationals and sets that fit inside themselves

Image
Pt En If I have two groups of kids in front of me, for example two different classes, how can I decide if the two groups have the same size? Of course I can count both groups, but I can also ask every kid from group $A$ to give his hand to a kid from group $B$, so they pair up. If, in the end, everyone is paired up, both groups have the same size. If some kid from group $A$ doesn't manage to give his hand to anybody, because every kid from group $B$ is taken, then the group $A$ had more kids... and if some kid from group $B$ doesn't get the hand from any kid from group $A$, then group $B$ had more kids! When we want to compare the sizes of two sets this is one of the things we can do! Instead of counting the two sets, we can try to pair them up. If we manage to do that, the sets have the same size! Sometimes pairing two sets is a hard task and instead we opt for a different thing: remember that if $a \leq b$ and $b \leq a$ then $a=b$; hence, if a set $A$ is not s...