from Observer import *
from Stats import *
import numpy as np
from math import *
import matplotlib.pyplot as plt

St = Stats()

N = 50

x1 = np.random.normal(0.0, 1.0, (N, N))
y1 = np.random.normal(0.0, 1.0, (N, N))

xx1, f1 = St.Gaussian1DKDE(x1, [-2.0, 2.0])
xx2, yy2, f2 = St.Gaussian2DKDE(x1, y1, [-2.0, 2.0], [-2.0, 2.0])

X = Observable(
    [x1, N, 'linear', 'x', 'x', None, 'viridis', ['x', 'y'], None, None])
Y = Observable(
    [y1, N, 'linear', 'y', 'y', None, 'viridis', ['x', 'y'], None, None])

xx3, f3 = St.Gaussian1DKDE(X, [-2.0, 2.0])
xx4, yy4, f4 = St.Gaussian2DKDE(X, Y, [-2.0, 2.0], [-2.0, 2.0])

print('plotting')
fig = plt.figure()
plt.plot(xx1, f1, 'r-')
plt.plot(xx3, f3, 'b-')
fig.savefig('1dtest.png')
plt.gca()
fig = plt.figure()
예제 #2
0
St = Stats()

# Lets create a couple random fields to study.
N = 100
x1 = 3.0 * np.random.rand(N) + 2.0
y1 = 1.5 * np.random.rand(N) + 2.0
x2 = 1.5 * np.random.rand(N) - 2.0
y2 = 3.0 * np.random.rand(N) - 2.0

bounds = [-4.0, 6.0]

print('Created random data.')

# Lets do 2D KDE. Some names have changed, so make sure you check that the
# names are correct if you run any old scripts.
xx1, yy1, f1 = St.Gaussian2DKDE(x1, y1, bounds, bounds)
xx2, yy2, f2 = St.Gaussian2DKDE(x2, y2, bounds, bounds)

print('Initial 2DKDE of random data complete.')

# Lets plot this.
fig1 = plt.figure(1)
plt.contour(xx1, yy1, f1, 20, colors='red')
plt.contour(xx2, yy2, f2, 20, colors='blue')
fig1.savefig('statstest.png')

print('First plot complete.')

# Now lets try the saving capability. You have to specify whether you used
# Gaussian or Fast, since the header contains info about what you're saving.
St.Save2DKDE(xx1, yy1, f1, '2DKDE1.dat', 'Gaussian')