# Path: geepee/utils.py
# def unflatten_dict(params, params_args):
#     keys, indices, shapes = params_args[0], params_args[1], params_args[2]
#     vals = np.split(params, indices)
#     params_dict = {}
#     for i, key in enumerate(sorted(keys)):
#         params_dict[key] = np.reshape(vals[i], shapes[key])
#     return params_dict


import sys
import geepee.vfe_models as vfe
import math
import numpy as np
import time
import argparse
import os
from geepee.utils import unflatten_dict
from metrics import *
    print 'running split', i

    train_ind_file = datapath + 'index_train_' + str(i) + '.txt'
    test_ind_file = datapath + 'index_test_' + str(i) + '.txt'
    index_train = np.loadtxt(train_ind_file, dtype=np.int32)
    index_test = np.loadtxt(test_ind_file, dtype=np.int32)
    X_train = X[index_train, :]
    y_train = y[index_train, :]
    X_test = X[index_test, :]
    y_test = y[index_test, :]
    y_test = y_test[:, 0]

    if normalise_x:
        # we normalise the train input
        std_X_train = np.std(X_train, 0)
        std_X_train[ std_X_train == 0 ] = 1
        mean_X_train = np.mean(X_train, 0)
        X_train = (X_train - mean_X_train) / std_X_train
        X_test = (X_test - mean_X_train) / std_X_train

    # We create the sparse gp object
    model = vfe.SGPR(X_train, y_train, M, lik='probit')

    def callback(params, iteration, args):
        global X_test
        global y_test
        if (iteration + 1) in test_iters:
            idx = np.where(test_iters == (iteration + 1))[0][0]
            outfile1 = outfile1s[idx]
            outfile2 = outfile2s[idx]

# Path: geepee/utils.py
# def unflatten_dict(params, params_args):
#     keys, indices, shapes = params_args[0], params_args[1], params_args[2]
#     vals = np.split(params, indices)
#     params_dict = {}
#     for i, key in enumerate(sorted(keys)):
#         params_dict[key] = np.reshape(vals[i], shapes[key])
#     return params_dict


# Path: exps/gpc/vfe/run_sparse_cla.py
import sys
import geepee.vfe_models as vfe
import math
import numpy as np
import time
import argparse
import os
from geepee.utils import unflatten_dict
from metrics import *

    print 'running split', i

    train_ind_file = datapath + 'index_train_' + str(i) + '.txt'
    test_ind_file = datapath + 'index_test_' + str(i) + '.txt'
    index_train = np.loadtxt(train_ind_file, dtype=np.int32)
    index_test = np.loadtxt(test_ind_file, dtype=np.int32)
    X_train = X[index_train, :]
    y_train = y[index_train, :]
    X_test = X[index_test, :]
    y_test = y[index_test, :]
    y_test = y_test[:, 0]

    if normalise_x:
        # we normalise the train input
        std_X_train = np.std(X_train, 0)
        std_X_train[ std_X_train == 0 ] = 1
        mean_X_train = np.mean(X_train, 0)
        X_train = (X_train - mean_X_train) / std_X_train
        X_test = (X_test - mean_X_train) / std_X_train

    # We create the sparse gp object
    model = vfe.SGPR(X_train, y_train, M, lik='probit')

    def callback(params, iteration, args):
        global X_test
        global y_test
        if (iteration + 1) in test_iters:
            idx = np.where(test_iters == (iteration + 1))[0][0]
            outfile1 = outfile1s[idx]
            outfile2 = outfile2s[idx]

            params_dict = unflatten_dict(params, args[0])