#!/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 }