using HDF5
using MultivariateStats
using Random
using CSV
using NPZ
using DPMMSubClusters
import YAML



# Define data params:
cfg = YAML.load_file("/home/vlad/projects/DPMMSubClusters.jl/benchmarks/configs/basic.yaml")

Ns = cfg["data"]["Ns"]
Ds = cfg["data"]["Ds"]
Ks = cfg["data"]["Ks"]
SEED = cfg["data"]["seed"]
DS_PATH = cfg["data"]["path"]
datavar = 10

# Define path:
mkpath(DS_PATH)

# utils function

function create_gaussian_data(path, seed, N, D, K, data_var)
	Random.seed!(seed) #generate same data
    x,y,clusters =  DPMMSubClusters.generate_gaussian_data(N, D, K, data_var)

    file_name = path * "/gaussian_D=" * string(D) *"_K=" * string(K)
    file_name_h5 = file_name*".h5"

    ispath(file_name_h5) && rm(file_name_h5)
    h5write(file_name_h5, "data", x)
    h5write(file_name_h5, "labels", y)

	npzwrite(file_name*"_x.npy", x')
	npzwrite(file_name*"_y.npy", y)


end


# generate and save data:

data_gen_path = DS_PATH * "/seed_" * string(SEED) 
mkpath(data_gen_path)



# iterate over number of points:
for l in 1:length(Ns)
    N = Ns[l]

    # iterate over dimensions:
    for i in 1:length(Ds)
        D = Ds[i]

        # iterate over number of clusters
        for j in 1:length(Ks)
            K = Ks[j]

            create_gaussian_data(data_gen_path, SEED, N, D, K, datavar*j*2)


        end
    end
end
