Skip to content

Commit

Permalink
Fixed bug in saving variables
Browse files Browse the repository at this point in the history
  • Loading branch information
TenzinCHW committed May 12, 2024
1 parent 8e22544 commit 2829c63
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 6 additions & 6 deletions scripts/blanche_expt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ function trainondata(data, maxiter, winsz, batchsize, arraycast)
input = ordered_window(data, winsz)
# converge on data
output = MEFK.convergedynamics(model, input |> arraycast) |> Array
# TODO instead of returning input and output, return index of traindata and uniqueout
in2inds, ininds = uniqueind(traindata)
# instead of returning input and output, return index of traindata and uniqueout
uniqueout = MEFK.convergedynamics(model, traindata |> arraycast) |> Array
ininds = uniqueinds(traindata, input)
combout, comboutcnt = combine_counts(uniqueout, counts)
out2inds, outinds = uniqueind(combout)
outinds = uniqueinds(combout, output)
cpumodel = modeltocpu(model)
inspkcnt = sum(traindata, dims=2)
comboutspkcnt = sum(combout, dims=2)
Expand Down Expand Up @@ -88,9 +88,9 @@ function runexperiment(binsz, winszs, maxiter, path, batchsize, arraycast, param
println("processing $saveloc")
model, ininds, uniqueinput, inspkcnt, counts, outinds, combout, comboutspkcnt, comboutcnt, losses =
trainondata(data_split[i], maxiter, winsz, batchsize, arraycast)
savedata["$i"] = Dict("ininds"=>ininds, "outinds"=>outinds, "input"=>uniqueinput, "output"=>combout, "net"=>model, "inspikecnt"=>inspkcnt, "incnt"=>counts, "outspikecnt"=>comboutspkcnt, "outcnt"=>comboutcnt, "loss"=>losses)
savedata["$i"] = Dict("ininds"=>ininds, "outinds"=>outinds, "input"=>uniqueinput, "output"=>combout, "net"=>model, "inspikecnt"=>inspkcnt, "incount"=>counts, "outspikecnt"=>comboutspkcnt, "outcount"=>comboutcnt, "loss"=>losses)
MAT.matwrite(joinpath(cdmdir, "input", "$(DrWatson.savename(params))_$(i).mat"),
Dict("inspikecnt"=>inspkcnt, "incnt"=>counts))
Dict("inspikecnt"=>inspkcnt, "counts"=>counts))
MAT.matwrite(joinpath(cdmdir, "complete", "$(DrWatson.savename(params))_$(i).mat"),
Dict("cells"=>model.n, "spike_counts"=>comboutspkcnt, "counts"=>comboutcnt))
end
Expand All @@ -100,7 +100,7 @@ function runexperiment(binsz, winszs, maxiter, path, batchsize, arraycast, param
nulldata = generatebernoulli(data_split[i])
model, ininds, uniqueinput, inspkcnt, counts, outinds, combout, comboutspkcnt, comboutcnt, losses =
trainondata(nulldata, maxiter, winsz, batchsize, arraycast)
savenull["$i"] = Dict("ininds"=>ininds, "outinds"=>outinds, "input"=>uniqueinput, "output"=>combout, "net"=>model, "inspikecnt"=>inspkcnt, "incnt"=>counts, "outspikecnt"=>comboutspkcnt, "outcnt"=>comboutcnt, "loss"=>losses)
savenull["$i"] = Dict("ininds"=>ininds, "outinds"=>outinds, "input"=>uniqueinput, "output"=>combout, "net"=>model, "inspikecnt"=>inspkcnt, "incount"=>counts, "outspikecnt"=>comboutspkcnt, "outcount"=>comboutcnt, "loss"=>losses)
MAT.matwrite(joinpath(cdmdir, "null", "$(DrWatson.savename(params))_$(i).mat"),
Dict("cells"=>model.n, "spike_counts"=>comboutspkcnt, "counts"=>comboutcnt))
end
Expand Down
11 changes: 11 additions & 0 deletions scripts/calculate_entropy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ function uniqueind(data)
end


"""Get ordered array of uniquedata to indices of uniquedata that make up origdata.
uniquedata might not be in same order as unique(origdata, dims=1)."""
function uniqueinds(uniquedata, origdata)
inddict = Dict()
for i in 1:size(uniquedata)[1]
inddict[uniquedata[i, :]] = i
end
[inddict[origdata[i, :]] for i in 1:size(origdata)[1]]
end


uniquecounts(arr) = [count(==(e), arr) for e in unique(arr)]
# TODO figure out why this is so slow compared to the window function in extract_blanche.jl
function uniquecounts(data, dims::Int)
Expand Down

0 comments on commit 2829c63

Please sign in to comment.