On Jun 9, 11:07 am, "alfred.morgan.al...@gmail.com"
<alfred.morgan.al...@gmail.com> wrote:
> Thanks for the advice, but at present I'm simply aiming to get the
> very basics of a neural net up and running without having to worry
> about a training algorithm at all.  Here's what I have so far (again,
> very basic)
>
> ;; Net0
>
> (def nodes {})
>
> (defn insertNode [node]
>   (do (def nodes (assoc nodes (:name node) node)) node) )

You really don't want to re-def the nodes map.  Instead define the
nodes as an atom and swap the value.

(def nodes (atom {}))

(defn insert-node [node] (swap! nodes assoc (:name node) node))

Don't forget that manipulating a collection returns a new collection;
the original one will remain unchanged.  As such, I'm not sure if this
is a good way to ultimately do what you want.


>
> (defn addNode [#^String name]
>   (let [node {:inputs {}, :outputs {}, :activation 0, :name name}]
>     (insertNode node) ))
>
> (defn connectNode [a b weight]
>   (do
>     (insertNode (assoc a :outputs (assoc (:outputs a) (:name b)
> weight)))
>     (insertNode (assoc b :inputs  (assoc (:inputs  b) (:name a)
> weight))) ))
>
> (defn getWeight [a b]
>   (get (:outputs a) (:name b)) )
>
> ; Now, we do some actual testing:
>
> (def n1 (addNode "Node1"))
> (def n2 (addNode "Node2"))
> (connectNode n1 n2 40)
> (println (getWeight (nodes "Node1") (nodes "Node2")))
>
> I've had a look at the concurrent ant simulation Rich Hickey
> presented, but the code's a little more advanced than my own reading-
> are 'sync' and 'alter' the sort of things I should be looking into,
> and, if so, is there any way I can abstract them away with macros?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to