Ignore:
Timestamp:
11/05/13 01:26:23 (8 years ago)
Author:
Ivan Raikov
Message:

9ML-toolkit: additions to electrical synapses infrastructure

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/9ML-toolkit/trunk/templates/Network.sml.elec.tmpl

    r29944 r29994  
     1
     2signature NODE_GRAPH =
     3sig
     4    type symbol = Symbol.symbol
     5    type nindex = int
     6    type rangemap = (int * int) list
     7
     8    val nodeGraph : (symbol * SparseMatrix.matrix * rangemap) ->
     9                    (nindex, real, unit) Graph.graph
     10                   
     11    val junctionMatrix : ((nindex, real, unit) Graph.graph) -> SparseMatrix.matrix
     12
     13
     14end
     15
     16structure NodeGraph: NODE_GRAPH =
     17struct
     18
     19type symbol   = Symbol.symbol
     20type index    = int
     21type rangemap = {localStart: int, localEnd: int, globalStart: int} list
     22
     23exception Index
     24
     25fun nodeGraph (S, rangemap) =
     26    let
     27        val mapIndex m i = case List.find (fn (({localStart,localEnd,globalStart} =>
     28                                                i >= localStart andalso i < localEnd)) m of
     29                               SOME ({localStart,localEnd,globalStart}) => globalStart + (i-localStart)
     30                             | NONE => raise Index
     31       
     32        val [N,_] = SparseMatrix.shape S
     33       
     34        val G as Graph.GRAPH g =
     35            DirectedGraph.graph(Symbol.name modelname,(),N) :
     36            (index,real,unit) Graph.graph
     37
     38        val idxs  = List.tabulate (N, fn (i) => i)
     39        val gidxs = List.tabulate (N, fn (i) => mapIndex rangemap i)
     40
     41        val _ = ListPair.app (#add_node g) (gidxs,idxs)
     42
     43        val add_edge = #add_edge g
     44
     45        val _ List.app
     46              (fn (s) =>
     47                  let
     48                      val sl = SparseMatrix.slice (S,1,i)
     49                  in
     50                      SparseMatrix.sliceAppi
     51                          (fn (t,v) => add_edge (mapIndex rangemap s, mapIndex rangemap t,v))
     52                          sl
     53                  end)
     54              idxs
     55
     56    in
     57        G
     58    end
     59
     60fun junctionMatrix (Graph.GRAPH g) =
     61    let
     62        fun nodeCoeffs n =
     63            let
     64                val out  = (#out_edges g) n
     65                val self = Real.- (~1.0, foldl (fn ((s,t,v),ax) => Real.+(v,ax)) 0.0 out)
     66            in
     67                (n, (n,self) :: (map (fn (s,t,v) => (t,v)) out))
     68            end
     69
     70        val lst = ref []
     71           
     72    in
     73        ((#forall_nodes g) (fn (n,_) => (lst := ((nodeCoeffs n) :: !lst)));
     74         SparseMatrix.fromLists (!lst))
     75    end
     76
     77end
    178
    279structure {{group.name}} =
Note: See TracChangeset for help on using the changeset viewer.