lundi 6 février 2017

How to use a random generator-using function with fmap in haskell?

I am researching with evolutionary neural networks, and am using HNN. My first question is if there exist any evolutionary algorithm frameworks in Haskell already, as I was not able to find any?

I am currently struggling to find a way to mutate the weights of the neural network in a general way. At the moment, I am trying to map a random function (of of the form (RandomGen g) => g -> a -> (b,g)) over the HMatrix of weights.

I would like a generalizable way to modify an existing fmap (or fold?) to make use of a random function if it can be done. For example, I might have a function that may or may not add some Gaussian noise to its input, and would like that to apply to the entire network. The problem I'm having is how to work with the random number generators.

For map, I am currently doing the following:

rmap :: (StdGen -> a -> (b,StdGen)) -> StdGen -> [a] -> ([b],StdGen)
rmap _ g [] = ([],g)
rmap f g (x:xs) = let (mapped, g') = rmap f g xs
                      (rVal, g'')  = f g' x
                   in (rVal:mapped, g'')

This seems like a hack to me, and I was hoping some of the better haskellers might have some advice on how to deal with this randomness more effectively?




Aucun commentaire:

Enregistrer un commentaire