def W(data, point, r, derivative=None): W = [] if not derivative: for index, row in enumerate(data): d2d = row[0:2] # (x,y) leftZeroes = np.zeros([1, index]) # 0 0 0 ... 0 } index times rightZeroes = np.zeros([1, len(data) - index - 1]) weightfunction = w.gaussian_with_radius(np.subtract(d2d, point), r) newRow = np.concatenate( [leftZeroes, [[weightfunction]], rightZeroes], axis=1)[0] W.append(newRow) return W else: for index, row in enumerate(data): d2d = row[0:2] # (x,y) leftZeroes = np.zeros([1, index]) # 0 0 0 ... 0 } index times rightZeroes = np.zeros([1, len(data) - index - 1]) weight = w.gaussian_with_radius(np.subtract(d2d, point), r, derivative) newRow = np.concatenate([leftZeroes, [[weight]], rightZeroes], axis=1)[0] W.append(newRow) return W
import weight as w import matplotlib.pyplot as plt import numpy as np # Plot Gaussian with radius and derivatives fig = plt.figure("peso -gaussiana com raio") xs = np.arange(-100, 100, 10) ys = np.arange(-100, 100, 10) X, Y = np.meshgrid(xs, ys) zs = np.array([ w.gaussian_with_radius([x, y], 80) for x, y in zip(np.ravel(X), np.ravel(Y)) ]) Z = zs.reshape(X.shape) mesh_plot = fig.add_subplot(111, projection='3d') mesh_plot.plot_surface(X, Y, Z) fig = plt.figure("peso -gaussiana com raio - Primeira derivada") xs = np.arange(-100, 100, 10) ys = np.arange(-100, 100, 10) X, Y = np.meshgrid(xs, ys) zs = np.array([ w.gaussian_with_radius([x, y], 80, { 'order': 1, 'var': 'x' }) for x, y in zip(np.ravel(X), np.ravel(Y)) ]) Z = zs.reshape(X.shape)
def test_gaussian_derivative_y_limit(): assert (w.gaussian_with_radius(point_test[3], radius, { 'order': 1, 'var': 'y' }) + 0.00941088536234) <= 0.0000001
def test_gaussian_derivative_y_medium(): assert (w.gaussian_with_radius(point_test[2], radius, { 'order': 1, 'var': 'y' }) + 0.0122891880563) <= 0.0000001
def test_gaussian_derivative_y_maximum(): assert w.gaussian_with_radius(point_test[1], radius, { 'order': 1, 'var': 'y' }) == 0
def test_gaussian_derivative_y_out(): assert (w.gaussian_with_radius(point_test[0], radius, { 'order': 1, 'var': 'y' }) - 0.0057259621009) <= 0.0000001
def test_gaussian_limit(): assert w.gaussian_with_radius(point_test[3], radius) == 0
def test_gaussian_derivative_xy_limit(): assert (w.gaussian_with_radius(point_test[3], radius, { 'order': 2, 'var': 'xy' }) - 0.000150574165798) <= 0.0000001
def test_gaussian_derivative_xy_medium(): assert (w.gaussian_with_radius(point_test[2], radius, { 'order': 2, 'var': 'xy' }) - 0.0000983135044506) <= 0.0000001
def test_gaussian_medium(): assert (w.gaussian_with_radius(point_test[2], radius) - 0.420675747852) <= 0.00001
def test_gaussian_derivative_xy_out(): assert (w.gaussian_with_radius(point_test[0], radius, { 'order': 2, 'var': 'xy' }) - 0.000114519242018) <= 0.0000001
def test_gaussian_derivative_yy_limit(): assert (w.gaussian_with_radius(point_test[3], radius, { 'order': 2, 'var': 'y' }) - 0.0000329380987683) <= 0.0000001
def test_gaussian_maximum(): assert w.gaussian_with_radius(point_test[1], radius) == 1
def test_gaussian_derivative_yy_medium(): assert (w.gaussian_with_radius(point_test[2], radius, { 'order': 2, 'var': 'y' }) + 0.000208916196958) <= 0.0000001
def test_gaussian_derivative_yy_maximum(): assert (w.gaussian_with_radius(point_test[1], radius, { 'order': 2, 'var': 'y' }) + 0.000423094551838) <= 0.0000001
def test_gaussian_out(): assert w.gaussian_with_radius(point_test[0], radius) == 0