Posts

New blog!!!

join the mathspp mailing list Pt En My blog is being migrated to mathspp.com !! O meu blogue está a ser migrado para o meu novo site: mathspp.com !! &nbsp&nbsp- RGS join the mathspp mailing list

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...

Generating (better) random mazes

Image
Pt En In this previous post I shared some code and animations of an algorithm that created random mazes. I shared it with you and I got some feedback on Facebook, saying that even the stupidly large mazes I gave you were really easy to solve (I think this link can show you what I am talking about). So it was about time I got you some new mazes! And this time, I don't think they are as easy to solve as the old ones. The mazes I am sharing today were created by code found in this GitHub repo . The README will tell you to run the wilson_generator.py file. You can also download the (windows) executable that is zipped inside the wilsonExe rar. (please notice that in both cases, you can use the wilsonconfig.ini file to change the size of the maze) The way our algorithm works is really simple. It will start a random walk on the top left corner of the window. Whenever the random walk intersects itself (creating a loop), it removes the loop from the walk, and then c...

Pocket maths: folding halves into thirds

Image
Pt En I have folded a piece of paper in half hundreds of times in my life. And probably so did you. Folding a piece of paper in half is fairly easy: just bend the piece of paper until the corners meet, and then crease. That is it. And with this method one can also fold a piece of paper in $4$, in $8$, etc. We just have to successively divide the sections of the paper in half. But what if we wanted to fold a piece of paper into thirds, as in the picture above? Some people are good at doing that, but they don't really measure anything: they just do it approximately by looking at the paper and folding where it seems about right. I guess it goes without saying, but mathematicians don't like things to be "about right", they want them right... and even though I wasn't a mathematician, when I was a child I thought that maybe there was a way for me to successively fold different parts of the paper in half, until one of the creases would be the crease at...

Pocket maths: how to compute averages in your head

Pt En Being able to do basic arithmetic calculations in your head is a great skill. Not because it is sexy but because it is useful in your daily life: it can help you check the change you are given when shopping, it can help you know if you will have enough money to pay for your groceries, it can help you estimate how much things cost after the discounts, etc... This often reduces to being able to sum and subtract decently; sometimes you need to make a couple of small multiplications, but that is it. More likely than not, you don't need to compute averages every day. But sometimes you just want the scoring average of your team for the past few games, or the average price per person of a given meal, or the average time you spent stuck in traffic this past week... And averages may appear nastier than simply adding or subtracting, because averages also require you to perform a division: in fact, you have to add all the numbers you want and then divide the total by ho...

Introduction to the Hill Cipher

Image
Pt En The Hill cipher is a very simple cipher that works by using modular arithmetic and matrices. In a nutshell, your key is a matrix in some $\mathbb{Z}_m$ and you encrypt messages by breaking them up into pieces and then multiplying the pieces by the key matrix. That's it. I will be giving a workshop on this subject in a near future, and so I decided to write a Python notebook with a brief explanation of how the Hill cipher works, as well as providing an implementation of said cipher. The notebook can be downloaded and read here . I will be glad if you leave any suggestions/comments in the section below! A cifra de Hill é uma cifra simples que faz uso de noções de aritmética modular e de álgebra linear (mais concretamente, matrizes). Em duas frases, a cifra de Hill tem como chave uma matriz num dado $\mathbb{Z}_m$ e o modo como encripta mensagens é partindo-a em bocados com o mesmo tamanho e depois multiplicando a matriz chave por esses bocados. Num...

DumbFire, a simple shooting game

Image
Pt En DumbFire is a very simple shooting game that I created with Python and pygame and you can find the code here . As of now, the game does not have a menu whatsoever nor it has any kind of instructions... (btw, to play it use the WASD keys to move and the space bar to shoot; if the coloured balls hit you, you lose health; if you shoot them, you get health back) I have been incredibly busy so I am not sure I will tidy this up any time soon but feel free to fork the repo in GitHub and to add different types of enemies and maybe some kind of power-up or whatnot. Actually, I would be very interested in hearing from you the answer to: if I could only add one single extra functionality to the game, what would that be? O jogo DumbFire é um jogo simplecíssimo de tiros que eu fiz com Python e com pygame. O código está no repo usual e convido-vos a fazerem uma cópia do mesmo para experimentarem alterar os tipos de inimigos, talvez juntar um ou outro power-up, etc. De mome...