I have a vector of data of 100000 examples. The values are -1 and 1. I want to get from this data 16 distinct mini-batches randomly, each one of 6250.
Here is my code to generate the vector of 100000 examples which is stored in a file.
The question of how to divide my data to different parts is answered by Dan.
Now, l want to store [X[p] for p in parts] in p files. l mean by that : if l have 3 parts , l want to create and store the values of p. How can l do that ?
workspace()
using JLD, HDF5
#import HTreeRBM
function gen_random(m,k)
# m the length of the vector , for instance m=100000 and k the number of partitions let's set k=16
s = rand(m)
# Pkg.add("JLD"), Pkg.add("HDF5") these two packages are needed in order to store our vectors in files under the extension jld
# allow to convert each random number to -1 or 1
X=float_to_binary(s)
parts= kfoldperm(length(X),k)
for p in 1:length(parts)
file =jldopen(@sprintf("my path to file/mini_batch%d.jld", p),"w")
write(file, "X", [X[p] for p in parts])
close(file)
end
return [X[p] for p in parts]
function float_to_binary(s,level=0.4)
for i=1:length(s)
s[i] = s[i] > level ? 1.0 : -1.0
end
file = jldopen("/home/anelmad/Desktop/stage-inria/code/HTreeRBM.jl/artificial_data/mydata.jld", "w")
write(file, "s", s) # alternatively, say "@write file A"
close(file)
return s
end
function kfoldperm(l,k)
n,r = divrem(l,k)
b = collect(1:n:l+1)
for i in 1:length(b)
b[i] += i > r ? r : i-1
end
p = randperm(l)
return [p[r] for r in [b[i]:b[i+1]-1 for i=1:k]]
end