Euler Problem 1 using Theano

Posted on by James Thomas.

Solving Euler Problem 1 using an arithmetic progression method with Python and Theano.

A few months ago I began learning Theano and reading through its documentation. While I still don’t fully understand Theano, I wanted to share some of my code that was an attempt to use Theano in order to solve the first Euler problem.

I did my best to document the code. I will start out by pointing out that tensors in the context of Theano are n-dimensional vectors, and in this particular example the scalars are just real numbers. The dscalar is a float64 with no dimensions which means that its basically just a single number.

My variable names with "ap" stands for arithmetic progression. These variables define the graph that Theano will use. ’sum_ap_limit’ could be named better, but its just the sum of the arithmetic progression using the limit obtained from the previous graphs (equations).

theano.function compiles the graphs and runs everything when its called. The function method is the real beast of Theano. I will continue to play with it and explain more as the opportunity arises.

So why did I choose to learn Theano? The Theano community pioneered the graph idea that is a staple in most machine learning frameworks you see today. It’s fairly old and everyone seems to want to build varying levels of abstraction on top of it. What better way to learn why those frameworks exist and what people are using machine learning for, than by learning what Theano does and why they needed to alter its functionality for their use?

I made an effort to print the graphs before and after optimization was made, however due to a recent problem with a particular package I was unable to explore the graph in depth this time. I apologize and will attempt to explain that better in a future post.