rmed theano implementation