Ejemplo n.º 1
0
def sample_gp(length, sigma, n=1, noise=0.001):
    """ sample a function from a Gaussian process with Gaussian kernel """
    X = np.linspace(0, 1, length, False).reshape([1, length])
    zeroY = np.zeros(length)
    K = maxdiv_util.calc_gaussian_kernel(
        X, sigma / length) + noise * np.eye(X.shape[1])
    return np.random.multivariate_normal(zeroY, K, n)
Ejemplo n.º 2
0
def sample_gp(length, dim=1, sigma=0.02, noise=0.001):
    """ sample a function from a Gaussian process with Gaussian kernel """
    X = np.arange(0, length / 250.0, 0.004)
    X = np.reshape(X, [1, len(X)])
    meany = np.zeros(X.shape[1])
    K = maxdiv_util.calc_gaussian_kernel(X, sigma) + noise * np.eye(X.shape[1])
    return np.random.multivariate_normal(meany, K, dim)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
        # Add a constant offset to avoid negative scores
        base_score = min(score for _, _, score in norm_scores) - 0.01
        for i, (a, b, score) in enumerate(norm_scores):
            norm_scores[i] = (a, b, score - base_score)
        scores[meth] = norm_scores
    elif meth == 'gaussian_cov_ts':
        scores[meth] = maxdiv.maxdiv_gaussian(pts, proposals, mode = 'TS', gaussian_mode = 'COV')
        # de-normalize
        chi_mean = (pts.shape[0] * (pts.shape[0] + 3)) / 2
        chi_sd = np.sqrt(2 * chi_mean)
        for i, (a, b, score) in enumerate(scores[meth]):
            scores[meth][i] = (a, b, score * chi_sd + chi_mean)
    elif meth.startswith('gaussian'):
        scores[meth] = maxdiv.maxdiv_gaussian(pts, proposals, mode = 'I_OMEGA', gaussian_mode = meth[9:].upper())
    elif meth == 'parzen':
        K = maxdiv_util.calc_gaussian_kernel(pts)
        scores[meth] = maxdiv.maxdiv_parzen(K, proposals, mode = 'I_OMEGA')
    else:
        print('Unknown method: {}'.format(meth))
        exit()

if method != 'compare':

    # Plot top 5 detections
    detections = maxdiv.find_max_regions(scores[method])
    eval.plotDetections(ts, detections[:5])

    # Plot histogram of the length of detected intervals
    plt.title('Histogram of the Length of Detected Intervals for Method "{}"'.format(method))
    plt.hist([b - a for a, b, score in detections])
    plt.show()