Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: State Monad for neurons? (Ertugrul Soeylemez)
2. Re: Re: State Monad for neurons? (Amy de Buitl?ir)
3. Re: Why is this function that slow? (Andreas Flierl)
4. Re: Why is this function that slow? (David Virebayre)
5. Re: MonadPlus (Brent Yorgey)
6. lazy database queries (Michael Hendricks)
----------------------------------------------------------------------
Message: 1
Date: Thu, 29 Jul 2010 06:45:03 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: [Haskell-beginners] Re: State Monad for neurons?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
Amy de Buitléir <[email protected]> wrote:
> I'm implementing a cyclic neural network. At time t, each neuron will
> update its output based on the outputs (at time t-1) of the neurons
> that it's connected to. It will also update the weights for its
> connections according to some learning rule, and it may destroy a
> connection or create a new one.
>
> So far, the best way I can think of to do this is to have a master
> list of neurons, and each neuron would know the indices for the other
> neurons it connects to. I'd write a function to update the neuron
> (actually returning a "new" neuron), and then do a "map" over the list
> with that function.
>
> That seems OK, but I wonder if there's a better way. I suspect the
> State monad could be used for this, but I can't figure out how to put
> the pieces of the puzzle together. Here's what I was thinking:
> - A connection could be a State monad, where the state is the source
> neuron and the current weight, and the result would be the weighted
> input.
> - A neuron could also be a State Monad, where the state is a list of
> connections, and the result is the neuron's output.
When using a State monad, the state is going to be your entire network
together with all neurons and connection weights. At least this is how
I have done it some time ago. Just use something like an IntMap and
give the neurons unique names. Then you can use something like this:
type NeunetT = StateT NeuralNetwork
learn :: Monad m =>
[(Vector Double, Vector Double)] -> NeunetT m Double
or:
run :: Monad m => Vector Double -> NeunetT m (Vector Double)
A very different, probably more elegant approach to implement ANNs is to
use functional reactive programming. The 'elerea' library seems to be
suitable for this.
> I've read dozens of monad tutorials, but I can't figure out how to
> trigger all the neurons to update themselves. Is the State Monad
> appropriate for this problem?
A State monad just encodes functions of the following type:
s -> (a, s)
Unlike a regular function, it passes the state around implicitly.
Instead of accessing function arguments, you 'get' the state. You
change the state not by returning a new state, but by using the
'set'/'put' functions. You get a mutable variable-like interface to the
state, but under the hood you really just encode a function of the above
type.
Greets,
Ertugrul
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
------------------------------
Message: 2
Date: Thu, 29 Jul 2010 06:09:41 +0100
From: Amy de Buitl?ir <[email protected]>
Subject: Re: [Haskell-beginners] Re: State Monad for neurons?
To: Ertugrul Soeylemez <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Thank you so much, Ertugrul. I am going to have a look at functional
reactive programming!
------------------------------
Message: 3
Date: Thu, 29 Jul 2010 09:32:59 +0200
From: Andreas Flierl <[email protected]>
Subject: Re: [Haskell-beginners] Why is this function that slow?
To: <[email protected]>
Message-ID:
<3c616a6ef6541f94cc7babf6dd9a4d2a-ehvcxlliqqrxrwgedbcnwrwwfgflv15yqubgaefyw0c3v1kkqvxyh1rdxefeqeftxlhrqftdua9yvg==-webmail...@server08.webmailer.hosteurope.de>
Content-Type: text/plain; charset=UTF-8
Thanks Daniel for the explanation, that was really helpful, and thanks
Bryce for sharing your solution.
I know that the algorithm itself can be improved vastly (especially
interesting for bigger palindromes..) but here, I was only worried about
the loss of speed after the more or less direct port from Scala to Haskell.
But since the Haskell solution now runs 4 times faster than my previous
Scala version, I'm happy. :)
Thanks again
Andreas
------------------------------
Message: 4
Date: Thu, 29 Jul 2010 09:51:02 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] Why is this function that slow?
To: Bryce Verdier <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Jul 29, 2010 at 2:02 AM, Bryce Verdier <[email protected]> wrote:
> main :: IO ()
> main = print . maximum $ [ x * y | x <- nums, y <- nums, is_palimdrome (x *
> y)]
> Â where nums main :: IO ()
This version of main is faster for me.
main :: IO ()
main = print . maximum $ [ x * y | x <- [100..1000], y <- [100..x],
is_palimdrome (x * y)]
David.
------------------------------
Message: 5
Date: Thu, 29 Jul 2010 10:02:39 +0100
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] MonadPlus
To: Johann Bach <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1
On Wed, Jul 28, 2010 at 12:56:58PM -0700, Johann Bach wrote:
> On Wed, Jul 28, 2010 at 3:51 AM, Brent Yorgey <[email protected]> wrote:
> > On Wed, Jul 28, 2010 at 03:03:01AM -0700, Johann Bach wrote:
> >> I'm looking at Douglas Auclair's MonadPlus article, here
> >> http://www.haskell.org/sitewiki/images/6/6a/TMR-Issue11.pdf
> >>
> >> So consider an example like
> >>
> >> t2 = do
> >> x <- [1,2,3]
> >> y <- [1,2]
> >> guard $ x+y > 2
> >> return (x,y)
> >>
> >> This uses the list instance of MonadPlus.
> >>
> >> Now, Douglas is talking about his own code, not the above example, but
> >> his own code is similar. And he says "the entire computation is
> >> chained by mplus". I'm confused because I thought it was chained by
> >> >>=. In fact, I can't see where the above code makes use of mplus. The
> >> definition of "guard" uses mzero.
> >
> > You are correct. That sentence is an error. Indeed, it ought to say
> > "since the entire computation is chained with (>>=), a failure of one
> > test voids the entire branch". This is because of the required law
>
> Brent -- also, in his example (similar to my example above) it looks
> like the only benefit of the list instance of MonadPlus in this case
> is to use the pre-existing definition of guard. Is that true? His
> example is indeed more complex... it's in TMR issue 11.
Yes, that's true in a sense, since mzero = [] and mplus = (++) are
rather trivial for the list instance of MonadPlus. Of course, you
also gain the generality of having code that will work in any
MonadPlus. For example, if you have written some search code in a
MonadPlus style and decide you only want the first solution rather
than collecting all of them, you can just switch the type from [] to
Maybe without changing any of the actual code.
-Brent
------------------------------
Message: 6
Date: Thu, 29 Jul 2010 08:04:35 -0600
From: Michael Hendricks <[email protected]>
Subject: [Haskell-beginners] lazy database queries
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
I have a data structure roughly like
data Prices = Prices {
today :: [Price],
thisYear :: [Price]
}
Both today and thisYear are initially populated by database queries
using HDBC. I then have functions which call today and possibly call
thisYear. thisYear is not called often and the query to retrieve that
data is very expensive.
I thought I could use HDBC's laziness to postpone actually running the
slow query until thisYear was required. Attempts with quickQuery
suggest that the query is executed immediately and the only laziness
is with fetching the results.
Is it possible to make thisYear a lazy list which only executes the
query if thisYear's values are required?
Thank you.
--
Michael
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 25, Issue 56
*****************************************