# Path: tests/context.py

# 
# Path: tests/context.py

# 
# Path: tests/context.py



import numpy as np
import copy
import pdb
import os
import time
import matplotlib
import matplotlib.pylab as plt
from scipy.optimize import check_grad
from .context import vfe, aep
from .context import flatten_dict, unflatten_dict
from .context import PROP_MC, PROP_MM
    

def test_gpssm_linear_gaussian_kink_MM(nat_param=True):
    np.random.seed(0)
    def kink_true(x):
        fx = np.zeros(x.shape)
        for t in range(x.shape[0]):
            xt = x[t]
            if xt < 4:
                fx[t] = xt + 1
            else:
                fx[t] = -4 * xt + 21
        return fx

    def kink(T, process_noise, obs_noise, xprev=None):
        if xprev is None:
            xprev = np.random.randn()
        y = np.zeros([T, ])
        x = np.zeros([T, ])
        xtrue = np.zeros([T, ])
        for t in range(T):
            if xprev < 4:
                fx = xprev + 1
            else:
                fx = -4 * xprev + 21

            xtrue[t] = fx
            x[t] = fx + np.sqrt(process_noise) * np.random.randn()
            xprev = x[t]
            y[t] = x[t] + np.sqrt(obs_noise) * np.random.randn()

# Path: tests/context.py

# 
# Path: tests/context.py

# 
# Path: tests/context.py



# Path: tests/test_aep_vfe_limits.py
import numpy as np
import copy
import pdb
import os
import time
import matplotlib
import matplotlib.pylab as plt
from scipy.optimize import check_grad
from .context import vfe, aep
from .context import flatten_dict, unflatten_dict
from .context import PROP_MC, PROP_MM

    

def test_gpssm_linear_gaussian_kink_MM(nat_param=True):
    np.random.seed(0)
    def kink_true(x):
        fx = np.zeros(x.shape)
        for t in range(x.shape[0]):
            xt = x[t]
            if xt < 4:
                fx[t] = xt + 1
            else:
                fx[t] = -4 * xt + 21
        return fx

    def kink(T, process_noise, obs_noise, xprev=None):
        if xprev is None:
            xprev = np.random.randn()
        y = np.zeros([T, ])
        x = np.zeros([T, ])
        xtrue = np.zeros([T, ])
        for t in range(T):
            if xprev < 4:
                fx = xprev + 1
            else:
                fx = -4 * xprev + 21

            xtrue[t] = fx
            x[t] = fx + np.sqrt(process_noise) * np.random.randn()
            xprev = x[t]
            y[t] = x[t] + np.sqrt(obs_noise) * np.random.randn()

        return xtrue, x, y