123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441 |
- #!/usr/bin/tclsh
- package require Tk
- set SimDataDir "$env(HOME)/data/sim/csim/basecircuits/"
- puts "$env(DISPLAY)"
- set SimDir "$env(HOME)/prog/objsim/basecircuits/"
- set SimName ${SimDir}simbasecircuits
- puts "SimName= $SimName"
- puts "DataDirectory= $SimDataDir"
- set FileName "mydump.dat"
- set WeightFileName "outputweight.dat"
- set WeightFileName2 "conExInputweights.dat"
- set WeightFileList "$WeightFileName $WeightFileName2"
- set FilePattern "$SimDataDir*weight*"
- puts $FilePattern
- set filelist [glob $FilePattern]
- puts "WeightFiles:"
- foreach f $filelist {
- puts $f
- }
- wm minsize . 350 400
- set WeightFileList $filelist
- set CurWeightFileNr 0
- set CurWeightFile [lindex $WeightFileList $CurWeightFileNr]
- set NWeightFiles [llength $WeightFileList]
- proc NextWeightFile {} {
- incr ::CurWeightFileNr
- if {$::CurWeightFileNr < $::NWeightFiles} {
- } else {set ::CurWeightFileNr 0}
- set ::CurWeightFile [lindex $::WeightFileList $::CurWeightFileNr]
- }
- set None -9999
- proc MakeList2D {x y {DefaultValue 0}} {
- set tmprow {}
- for {set i 0} {$i < $y} {incr i} {
- lappend tmprow $DefaultValue
- }
- set arr2d {}
- for {set j 0} {$j < $x} {incr j} {
- lappend arr2d $tmprow
- }
- return $arr2d
- }
- proc MakeList3D {x y z {DefaultValue 0}} {
- set tmprow [MakeList2D $y $z]
- set arr3d {}
- for {set j 0} {$j < $x} {incr j} {
- lappend arr3d $tmprow
- }
- return $arr3d
- }
- proc List2DToArray2D {OriList} {
- set i 0
- array set OutputArray {}
- foreach Row $OriList {
- set j 0
- foreach Elm $Row {
- set OutputArray($i,$j) $Elm
- incr j
- }
- incr i
- }
- set OutputArray(x) $i
- set OutputArray(y) $j
- return [array get OutputArray]
- }
- proc Array2DToList2D {ParaArray} {
- array set OriArray $ParaArray
- set OutputList {}
- for {set i 0} {$i < $OriArray(x)} {incr i} {
- set tmprow {}
- for {set j 0} {$j < $OriArray(y)} {incr j} {
- lappend tmprow $OriArray($i,$j)
- }
- lappend OutputList $tmprow
- }
- return $OutputList
- }
- proc L1Dincr {MyList x} {
- upvar $MyList UpList
- lset UpList $x [expr [lindex $UpList $x]+1]
- }
- proc L2Dincr {MyList x y} {
- upvar $MyList UpList
- lset UpList $x $y [expr [lindex $UpList $x $y]+1]
- }
- #nicht effizient, aber allgemein
- # evtl. mit case-Abfrage die Länge von args berücksichtigen
- proc lincr {MyList args} {
- upvar $MyList UpList
- eval lset [concat UpList $args [expr [eval lindex [concat [list $UpList] $args]] +1]]
- }
- proc ReadCSimWeightFile {WeightFileName} {
- puts $WeightFileName
- set fh [open $WeightFileName "r"]
- set tt 0
- fconfigure $fh -encoding binary -translation binary
- binary scan [read $fh 12] "iii" NSource SNx SNy
- binary scan [read $fh 12] "iii" NTarget TNx TNy
- binary scan [read $fh 12] "iii" M MaximumDelay MaxNPre
-
- array set WeightStructure {}
- set WeightStructure("NSource") $NSource
- set WeightStructure("SNx") $SNx
- set WeightStructure("SNy") $SNy
- set WeightStructure("NTarget") $NTarget
- set WeightStructure("TNx") $TNx
- set WeightStructure("TNy") $TNy
-
- set Post {}
- for {set i 0} {$i < $NSource} {incr i} {
- binary scan [read $fh [expr $M*4]] "i$M" tmprow
- lappend Post $tmprow
- }
- set Weights {}
- for {set i 0} {$i < $NSource} {incr i} {
- binary scan [read $fh [expr $M*4]] "f$M" tmprow
- lappend Weights $tmprow
- }
- set Delays_Length {}
- for {set i 0} {$i < $NSource} {incr i} {
- binary scan [read $fh [expr $MaximumDelay*2]] "s$MaximumDelay" tmprow
- lappend Delays_Length $tmprow
- }
- set Delays {}
- for {set i 0} {$i < $NSource} {incr i} {
- set SecondTmp {}
- for {set j 0} {$j < $MaximumDelay} {incr j} {
- binary scan [read $fh [expr $M*2]] "s$M" tmprow
- lappend SecondTmp $tmprow
- }
- lappend Delays $SecondTmp
- }
- # puts $Delays
- close $fh
- #calculate 2d weight and delay matrices
- set DelayMatrix2D [MakeList2D $NSource $NTarget $::None]
- set WeightMatrix2D [MakeList2D $NSource $NTarget $::None]
- for {set i 0} {$i < $NSource} {incr i} {
- for {set j 0} {$j < $MaximumDelay} {incr j} {
- for {set k 0} {$k < [lindex $Delays_Length $i $j]} {incr k} {
- lset DelayMatrix2D $i [lindex $Post $i [lindex $Delays $i $j $k]] $j
- lset WeightMatrix2D $i [lindex $Post $i [lindex $Delays $i $j $k]] [lindex $Weights $i [lindex $Delays $i $j $k]]
- }
- }
- }
-
- set WeightStructure("DelayMatrix") $DelayMatrix2D
- set WeightStructure("WeightMatrix") $WeightMatrix2D
- return [array get WeightStructure]
- }
- proc WriteCSimWeightFile {WeightFileArr {WeightFileName "editweight.dat"}} {
- # puts $WeightFileName
- array set WeightFile $WeightFileArr
- set ns $WeightFile("NSource")
- set nt $WeightFile("NTarget")
- set weights $WeightFile("WeightMatrix")
- set dmatrix $WeightFile("DelayMatrix")
-
- # calc Post array
- set M 0
- set MaxNPre 0
- set MaximumDelay 0
- set NPost {}
- array set NPre {}
- for {set t 0} {$t < $nt} {incr t} {
- set NPre($t) 0
- }
- for {set s 0} {$s < $ns} {incr s} {
- set CurNPost 0
- for {set t 0} {$t < $nt} {incr t} {
- if {[lindex $weights $s $t] != $::None} {
- incr CurNPost
- if {[lindex $dmatrix $s $t] > $MaximumDelay} {
- set MaximumDelay [lindex $dmatrix $s $t]
- }
- incr NPre($t)
- }
- }
- lappend NPost $CurNPost
- if {$CurNPost > $M} {set M $CurNPost}
- }
- for {set t 0} {$t < $nt} {incr t} {
- if {$NPre($t) > $MaxNPre} {
- set MaxNPre $NPre($t)
- }
- }
- incr MaximumDelay
- # puts "M= $M MaximumDelay=$MaximumDelay MaxNPre=$MaxNPre"
- set delays [MakeList3D $ns $MaximumDelay $M]
- set delays_length [MakeList2D $ns $MaximumDelay]
- set Post [MakeList2D $ns $M]
- for {set s 0} {$s < $ns} {incr s} {
- set CurNPost 0
- for {set t 0} {$t < $nt} {incr t} {
- # puts "$s $t $CurNPost [lindex $dmatrix $s $t] [lindex $delays_length $s [lindex $dmatrix $s $t]]"
- if {[lindex $weights $s $t] != $::None} {
- lset Post $s $CurNPost $t
- lset delays $s [lindex $dmatrix $s $t] [lindex $delays_length $s [lindex $dmatrix $s $t]] $CurNPost
- incr CurNPost
- L2Dincr delays_length $s [lindex $dmatrix $s $t]
- }
- }
- }
- set fh [open $WeightFileName "w"]
- fconfigure $fh -encoding binary -translation binary
- puts -nonewline $fh [binary format "iii" $ns $WeightFile("SNx") $WeightFile("SNy")]
- puts -nonewline $fh [binary format "iii" $nt $WeightFile("TNx") $WeightFile("TNy")]
- puts -nonewline $fh [binary format "iii" $M $MaximumDelay $MaxNPre]
- #write Post
- for {set s 0} {$s < $ns} {incr s} {
- for {set m 0} {$m < $M} {incr m} {
- puts -nonewline $fh [binary format "i" [lindex $Post $s $m]]
- }
- }
- #write Weights
- for {set s 0} {$s < $ns} {incr s} {
- for {set m 0} {$m < $M} {incr m} {
- puts -nonewline $fh [binary format "f" [lindex $weights $s [lindex $Post $s $m]]]
- }
- }
- #write Delays_Length
- for {set s 0} {$s < $ns} {incr s} {
- for {set m 0} {$m < $MaximumDelay} {incr m} {
- puts -nonewline $fh [binary format "s" [lindex $delays_length $s $m]]
- }
- }
- #write Delays
- for {set s 0} {$s < $ns} {incr s} {
- for {set d 0} {$d < $MaximumDelay} {incr d} {
- for {set m 0} {$m < $M} {incr m} {
- puts -nonewline $fh [binary format "s" [lindex $delays $s $d $m]]
- }
- }
- }
- close $fh
- }
- array set vals {}
- array set vdelay {}
- set KillingList {}
- proc Destroy {} {
- foreach w $::KillingList {
- destroy $w
- }
- }
- proc ShowWeightMatrix {} {
- Destroy
- array set ::vals [List2DToArray2D $::WeightFile("WeightMatrix")]
- array set ::vdelay [List2DToArray2D $::WeightFile("DelayMatrix")]
- set nr_rows $::WeightFile("NSource")
- set nr_cols $::WeightFile("NTarget")
- set FileWithoutPath [regexp -inline "/\[^/]*dat$" $::CurWeightFile]
- label .filenameLabel -text "Switch to next WeightFile"
- lappend ::KillingList .filenameLabel
- pack .filenameLabel -anchor sw
- pack [button .changewf -command "ShowWM1" -text $FileWithoutPath] -anchor sw
- lappend ::KillingList .changewf
- label .weightLabel -text "Weights"
- lappend ::KillingList .weightLabel
- pack .weightLabel -anchor sw
- for {set i 0} {$i < $nr_rows} {incr i} {
- frame .row$i
- set curframe .row$i
- lappend ::KillingList $curframe
- for {set j 0} {$j < $nr_cols} {incr j} {
- # set vals($i,$j) 0
- # set mybut [button ${curframe}.but${i}x$j -text "$i $j"]
- set mybut [entry ${curframe}.but${i}x$j -textvariable vals($i,$j) -width 7 -bg white -relief flat -border 5 -highlightcolor green]
- pack $mybut -side left
- }
- pack $curframe -side top
- }
- label .delayLabel -text "Delays (max=119)"
- lappend ::KillingList .delayLabel
- pack .delayLabel -anchor sw
- for {set i 0} {$i < $nr_rows} {incr i} {
- destroy .delayrow$i
- frame .delayrow$i
- set curframe .delayrow$i
- lappend ::KillingList $curframe
- for {set j 0} {$j < $nr_cols} {incr j} {
- # set vdelay($i,$j) 0
- # set mybut [button ${curframe}.but${i}x$j -text "$i $j"]
- set mybut [entry ${curframe}.but2${i}x$j -textvariable vdelay($i,$j) -width 7 -bg white -relief flat -border 5 -highlightcolor green]
- pack $mybut -side left
- }
- pack $curframe -side top
- }
- pack [button .dump -command "Save" -text "Save Weight File"] -anchor sw
- lappend ::KillingList .dump
- }
- proc ShowWM1 {} {
- NextWeightFile
- array set ::WeightFile [ReadCSimWeightFile "$::CurWeightFile"]
- ShowWeightMatrix
- }
- set NType 0
- set InputStrength 0.03
- proc Sim {} {
- puts $::SimName
- # open "$::SimName -L" "r+"
- set ::inout [open "|$::SimName -L --NeuronType $::NType --InputStrength $::InputStrength" "r+"]
- puts "Neuronentyp: $::NType"
- fconfigure $::inout
- # puts "Hallo"
- puts [read $::inout]
- ShowSim
- }
- # look at http://wiki.tcl.tk/1241
- proc OpenIDL {} {
- set ::idl [open "|idl-console-start" "w"]
- fconfigure $::idl -blocking 0 -buffering line -translation crlf -eofchar {}
- puts "OpenIDL"
- }
- proc ShowSim {} {
- set ShowOptions {}
- if {$::NType == 0} {
- append ShowOptions ",CutSpikes=$::CutSpikePot "
- }
- # set Command "csim_showsimspikes, dirname=\"$::SimDataDir\", /sec \n"
- # set Command "csim_showsimspikes, dirname=\"$::SimDataDir\", /sec $ShowOptions \n"
- set Command "gklearn_showsimspikes, /showspikes, showpotentials=1, dirname=\"$::SimDataDir\", /sec"
- puts $Command
- puts $::idl $Command
- }
- proc ResetIDL {} {
- puts $::idl "retall"
- puts $::idl "widget_control,/reset"
- puts $::idl "close,/all"
- puts $::idl "heap_gc,/verbose"
- # close $::idl
- # OpenIDL
- }
- proc RestartIDL {} {
- close $::idl
- OpenIDL
- }
- OpenIDL
- # pack [button .dummy -command "ReadIDL" -text "ReadIDL"]
- # pack [button .showsim -command "ShowSim" -text "ShowSim"]
- frame .but0 -width 1500 -height 100
- pack .but0
- set curframe .but0
- # pack [button ${curframe}.test -command "ShowWM1" -text "ChangeWeightFile"] -side left
- # pack [button ${curframe}.test2 -command "ShowWM1" -text "ChangeWeightFile"] -side left
- #pack [button ${curframe}.change -command "ShowWM1" -text "ChangeWeightFile"] -side left
- pack [button ${curframe}.sim -command "Sim" -text "Sim"] -side left
- pack [button ${curframe}.resetidl -command "ResetIDL" -text "ResetIDL"] -side left
- frame .modelchose
- pack .modelchose
- pack [radiobutton .modelchose.one -value 0 -text "Izhikevich-Neuron" -variable NType] -anchor sw
- pack [radiobutton .modelchose.two -value 1 -text "Marburg-Model-Neuron" -variable NType] -anchor sw
- #pack [checkbutton .modelchose.yrange
- set CutSpikePot 30
- label .modelchose.spcutlabel -text "CutSpikes="
- pack .modelchose.spcutlabel -anchor sw -side left
- set mybut [entry .modelchose.spcut -textvariable CutSpikePot -width 7 -bg white -relief flat -border 5 -highlightcolor green]
- pack $mybut -side left -side left
- label .modelchose.istrlabel -text "InputStrength="
- pack .modelchose.istrlabel -anchor sw -side left
- set mybut [entry .modelchose.setistrength -textvariable InputStrength -width 7 -bg white -relief flat -border 5 -highlightcolor green]
- pack $mybut -side left -side left
- ShowWM1
- frame .but
- pack .but
- frame .but2
- pack .but2
- proc Save {} {
- set ::WeightFile("WeightMatrix") [Array2DToList2D [array get ::vals]]
- set ::WeightFile("DelayMatrix") [Array2DToList2D [array get ::vdelay]]
- WriteCSimWeightFile [array get ::WeightFile] $::CurWeightFile
- }
|