How to simulate a model for a genetic oscillator

In the previous post, I showed how to efficiently solve SDEs using python. Today we will use that knowledge to explore a well known model in systems biology: the repressilator.

The repressilator was described in detail by Elowitz and Leibler in Nature. It is essentially a simple way for a cell to create an oscillator by changing the concentration of a number of proteins by the mechanism of gene expression. It has proven to be a difficult model to recreate in practice using synthetic biology, so nobody knows if it is an accurate model of what actually happens inside the cells. But it’s simple to model using differential equations and we’re physicists (yes, you too! for now at least) so let’s have a go at it! The system is composed of N proteins, each of which is repressed by another in the set cyclically. Following the usual hill equation model for gene expression and taking into account that proteins degrade after some time, we can write the sde for the system as such: Continue reading “How to simulate a model for a genetic oscillator”

Solving stochastic differential equations with theano

In systems biology we often need to solve diffusion equations of the type $$df = f(x,t) dt + g(x,t)dW$$ where W is a white noise process; they’re the most common example of a stochastic differential equation (SDE). There are only very few cases for which we can analytically solve this equation, such as when either f or g are constant or just depend linearly on x. Of course most interesting cases involve complicated f and g functions, so we need to solve them numerically.

One way to solve this is to use a straightforward variant of the Euler method. You just need to do the usual time discretization $\delta t = T/N$ (with T the total time and N the number of steps) and then update your current value with the deterministic contribution $\delta t \times f$ and the stochastic contribution $\sqrt{\delta t} \times g$. If you are not familiar with stochastic calculus you may be wondering why is the time step multiplier $\sqrt{\delta t}$ for the stochastic part.

Continue reading “Solving stochastic differential equations with theano”

Implementing a recurrent neural network in python

In one of my recent projects I was interested in learning a regression for a quite complicated data set (I will detail the model in a later post, for now suffice to say it is a high dimensional time series). The goal is to have a model which given an input time series and an initial condition is able to predict the output at subsequent times. One good tool to tackle this problem is the recurrent neural network. Let’s look at how it works and how to implement it easily in python using the excellent theano library.

A simple feed forward neural network consists of several layers of neurons: units which sum up the input from the previous layer and a constant bias and pass it through a nonlinear function (usually a sigmoid). Neural networks of this kind are known to be universal function approximators (i.e. for an arbitrary number of layers and/or neurons you can approximate any function sufficiently well). This means that when you don’t have an explicit probabilistic model for your data but just want to find a nonparametric model for the input output relation a neural network is (in theory, not necessarily in practice) a great choice. Continue reading “Implementing a recurrent neural network in python”

Facelift

So it was time to update the visual of this blog, as the default twenty twelve wordpress theme was starting to show its age. I started finding it visually boring a few months ago and the fact that it is not a responsive design let me to decide that a redesign was in order. My original idea was to just create a new responsive template using foundation, but after some research it turns out creating a wordpress there is quite an involved process. Not only would I have to create all the theming HTML/CSS, I’d also have to integrate them in the necessary PHP code scaffolding. As most tasks that require a significant time investment, I put this off indefinitely.

Luckily a few weeks back with a new wordpress came a new default theme, twenty thirteen. This is a nice responsive theme which places visual emphasis on the actual posts with larger fonts and no cumbersome sidebar (all that stuff is now in the footer, which is a great idea). This meant I only had to edit the CSS to get something which fulfills my requirements and has at least some identity.

The process started by creating a child theme. Since I am quite happy with the base layout, all I needed to do was to edit the colors to my heart’s content. Like all color challenged engineers I had to resort to some cheating. The usual place to cheat is to pick a pallete from colourlovers; but I find it is still an overwhelming experience. There is still simply too much to choose from. What I need is a very constrained set of good looking colors. To the rescue: flatUI colors. I picked the midnight blue as the main color for the header as a nod to the visual design my homepage had during my teenage years (nostalgia time). Then I desaturated it for the other blues I needed. For some contrasty accents, I went with the alizarin, which is also a pretty cool name for a color. Here is the pallete I built:

Alizarin
Midnight blue
Random blue #1
Random blue #2

Even though a real graphic designer is probably appalled by these choices, I’m pretty proud of how the visuals turned out. I have recently started paying more attention to design, which I think is an often overlooked area by scientists and engineers. It is already hard enough to communicate our work to a wide audience  and boring designs aren’t helping one bit.