# Path: geepee/config.py
# PROP_MC = 'MC'
# 
# PROP_MM = 'MM'


import matplotlib
import sys
import numpy as np
import scipy.stats
import matplotlib.pylab as plt
import os, sys
import geepee.aep_models as aep
import geepee.vfe_models as vfe
import geepee.ep_models as ep
import pdb
from geepee.config import PROP_MC, PROP_MM
    ax.set_xlim([T_train-5, T_train + T])
    plt.title(plot_title)
    plt.savefig('/tmp/kink_pred_MM_'+plot_title+'.pdf')
    # plt.savefig('/tmp/kink_pred_MM_'+plot_title+'.png')

def find_rank(arr):
    a = np.array(arr)
    r = np.array(a.argsort().argsort(), dtype=float)
    f = a==a
    for i in xrange(len(a)):
        if not f[i]: 
            continue
        s = a == a[i]
        ls = np.sum(s)
        if ls > 1:
            tr = np.sum(r[s])
            r[s] = float(tr)/ls
            f[s] = False
    return r

def compute_log_lik(noise, y_test, prediction):
    loglik = - 0.5 * (prediction - y_test)**2 / noise
    weights = np.arange(y_test.shape[0])**2 + 1
    loglik *= weights
    loglik_sum = np.sum(loglik, axis=1)
    ranks = find_rank(loglik_sum)
    return loglik, (ranks + 1) / np.max(ranks)

def plot_prediction_MC(model, y_train, y_test, plot_title=''):
    T = y_test.shape[0]

# Path: geepee/config.py
# PROP_MC = 'MC'
# 
# PROP_MM = 'MM'


# Path: exps/gpssm/kink_exp.py
import matplotlib
import sys
import numpy as np
import scipy.stats
import matplotlib.pylab as plt
import os, sys
import geepee.aep_models as aep
import geepee.vfe_models as vfe
import geepee.ep_models as ep
import pdb
from geepee.config import PROP_MC, PROP_MM

    ax.set_xlim([T_train-5, T_train + T])
    plt.title(plot_title)
    plt.savefig('/tmp/kink_pred_MM_'+plot_title+'.pdf')
    # plt.savefig('/tmp/kink_pred_MM_'+plot_title+'.png')

def find_rank(arr):
    a = np.array(arr)
    r = np.array(a.argsort().argsort(), dtype=float)
    f = a==a
    for i in xrange(len(a)):
        if not f[i]: 
            continue
        s = a == a[i]
        ls = np.sum(s)
        if ls > 1:
            tr = np.sum(r[s])
            r[s] = float(tr)/ls
            f[s] = False
    return r

def compute_log_lik(noise, y_test, prediction):
    loglik = - 0.5 * (prediction - y_test)**2 / noise
    weights = np.arange(y_test.shape[0])**2 + 1
    loglik *= weights
    loglik_sum = np.sum(loglik, axis=1)
    ranks = find_rank(loglik_sum)
    return loglik, (ranks + 1) / np.max(ranks)

def plot_prediction_MC(model, y_train, y_test, plot_title=''):
    T = y_test.shape[0]

    x_samples, my, vy = model.predict_forward(T, prop_mode=PROP_MC)