# Path: maxdiv/maxdiv_util.py
# def enforce_multivariate_timeseries(X):
# def calc_distance_matrix(X, metric='sqeuclidean'):
# def calc_gaussian_kernel(X, kernel_sigma_sq = 1.0, normalized=True):
# def calc_nonstationary_gaussian_kernel(X, kernel_sigma_sq_vec):
# def IoU(start1, len1, start2, len2):
# def td_mutual_information(ts, k, T = 1):
# def context_window_size(X, th = 0.05):
# def m_estimation(A, b, k = 1.345):
# def plot_matrix_with_interval(D, a, b):
#         X = X.reshape((1, len(X)))
#     D = scipy.spatial.distance.squareform(scipy.spatial.distance.pdist(X.T, metric))
#         D = np.ma.MaskedArray(D)
#     D = calc_distance_matrix(X)
#     K = np.exp(-D/(2.0*kernel_sigma_sq))
#         K = K / ((2*np.pi*kernel_sigma_sq) ** (X.shape[0] / 2))
#     D = calc_distance_matrix(X)
#     S = np.tile(kernel_sigma_sq_vec, [n,1])
#     K = np.exp(-D/(0.5*S_sum))*(np.power(S_prod,0.25)/np.sqrt(0.5*S_sum))
#         W = np.diag(np.sqrt(w))


import sys
import numpy as np
import matplotlib.pylab as plt
    import cPickle as pickle
    import pickle
from maxdiv import maxdiv_util
""" Creates Synthetic Test Bench for MaxDiv """

sys.path.append('../..')

try:
except ImportError:
    # cPickle has been "hidden" in Python 3 and will be imported automatically by
    # pickle if available.


def sample_gp(X, meany, sigma, n=1, noise=0.001):
    """ sample a function from a Gaussian process with Gaussian kernel """
    K = maxdiv_util.calc_gaussian_kernel(X, sigma) + noise * np.eye(X.shape[1])
    return np.random.multivariate_normal(meany, K, n)

def sample_gp_nonstat(X, meany, sigmas, n=1, noise=0.001):
    """ sample a function from a non-stationary Gaussian process """
    # http://papers.nips.cc/paper/2350-nonstationary-covariance-functions-for-gaussian-process-regression.pdf

# Path: maxdiv/maxdiv_util.py
# def enforce_multivariate_timeseries(X):
# def calc_distance_matrix(X, metric='sqeuclidean'):
# def calc_gaussian_kernel(X, kernel_sigma_sq = 1.0, normalized=True):
# def calc_nonstationary_gaussian_kernel(X, kernel_sigma_sq_vec):
# def IoU(start1, len1, start2, len2):
# def td_mutual_information(ts, k, T = 1):
# def context_window_size(X, th = 0.05):
# def m_estimation(A, b, k = 1.345):
# def plot_matrix_with_interval(D, a, b):
#         X = X.reshape((1, len(X)))
#     D = scipy.spatial.distance.squareform(scipy.spatial.distance.pdist(X.T, metric))
#         D = np.ma.MaskedArray(D)
#     D = calc_distance_matrix(X)
#     K = np.exp(-D/(2.0*kernel_sigma_sq))
#         K = K / ((2*np.pi*kernel_sigma_sq) ** (X.shape[0] / 2))
#     D = calc_distance_matrix(X)
#     S = np.tile(kernel_sigma_sq_vec, [n,1])
#     K = np.exp(-D/(0.5*S_sum))*(np.power(S_prod,0.25)/np.sqrt(0.5*S_sum))
#         W = np.diag(np.sqrt(w))


# Path: experiments/synthetic/testbench.py
import sys
import numpy as np
import matplotlib.pylab as plt
    import cPickle as pickle
    import pickle
from maxdiv import maxdiv_util

""" Creates Synthetic Test Bench for MaxDiv """

sys.path.append('../..')

try:
except ImportError:
    # cPickle has been "hidden" in Python 3 and will be imported automatically by
    # pickle if available.


def sample_gp(X, meany, sigma, n=1, noise=0.001):
    """ sample a function from a Gaussian process with Gaussian kernel """
    K = maxdiv_util.calc_gaussian_kernel(X, sigma) + noise * np.eye(X.shape[1])
    return np.random.multivariate_normal(meany, K, n)

def sample_gp_nonstat(X, meany, sigmas, n=1, noise=0.001):
    """ sample a function from a non-stationary Gaussian process """
    # http://papers.nips.cc/paper/2350-nonstationary-covariance-functions-for-gaussian-process-regression.pdf

    K = maxdiv_util.calc_nonstationary_gaussian_kernel(X, sigmas) + noise * np.eye(X.shape[1])