Esempio n. 1
0
    def test_apply_softmax(self):
        x = np.random.randn(100, 10)
        eig_x = mat.EigenMatrix(x)
        eig_y = mat.empty((100, 10))

        eig_x.apply_softmax(target=eig_y)

        y = np.exp(x - x.max(axis=0))
        y /= y.sum(axis=0)

        diff = ((eig_y.asarray() - y)**2).sum()
        self.assertAlmostEqual(diff, 0, places=5)
Esempio n. 2
0
    def test_add(self):
        x = np.random.randn(10, 10)
        y = np.random.randn(10, 10)
        eig_x = mat.EigenMatrix(x)
        eig_y = mat.EigenMatrix(y)
        eig_z = mat.empty(x.shape)

        z = x + y  # Numpy add.
        eig_x.add(eig_y, target=eig_z)  # EigenMat add.

        diff = ((eig_z.asarray() - z)**2).sum()
        self.assertAlmostEqual(diff, 0)
Esempio n. 3
0
    def test_dot_transposed(self):
        x = np.random.randn(500, 1000)
        y = np.random.randn(600, 1000)
        eig_x = mat.EigenMatrix(x)
        eig_y = mat.EigenMatrix(y)
        eig_z = mat.empty((x.shape[0], y.shape[0]))

        z = x.dot(y.T)
        mat.dot(eig_x, eig_y.T, target=eig_z)

        diff = ((eig_z.asarray() - z)**2).sum()
        self.assertAlmostEqual(diff, 0, places=5)
Esempio n. 4
0
  def test_add(self):
    x = np.random.randn(10, 10)
    y = np.random.randn(10, 10)
    eig_x = mat.EigenMatrix(x)
    eig_y = mat.EigenMatrix(y)
    eig_z = mat.empty(x.shape)

    z = x + y  # Numpy add.
    eig_x.add(eig_y, target=eig_z)  # EigenMat add.
    
    diff = ((eig_z.asarray() - z)**2).sum()
    self.assertAlmostEqual(diff, 0)
Esempio n. 5
0
  def test_apply_softmax(self):
    x = np.random.randn(100, 10)
    eig_x = mat.EigenMatrix(x)
    eig_y = mat.empty((100, 10))

    eig_x.apply_softmax(target=eig_y)
    
    y = np.exp(x - x.max(axis=0))
    y /= y.sum(axis=0)

    diff = ((eig_y.asarray() - y)**2).sum()
    self.assertAlmostEqual(diff, 0, places=5)
Esempio n. 6
0
  def test_dot_transposed(self):
    x = np.random.randn(500, 1000)
    y = np.random.randn(600, 1000)
    eig_x = mat.EigenMatrix(x)
    eig_y = mat.EigenMatrix(y)
    eig_z = mat.empty((x.shape[0], y.shape[0]))

    z = x.dot(y.T)
    mat.dot(eig_x, eig_y.T, target=eig_z)

    diff = ((eig_z.asarray() - z)**2).sum()
    self.assertAlmostEqual(diff, 0, places=4)
Esempio n. 7
0
import matplotlib.pyplot as plt
import numpy as np
plt.ion()
import eigenmat as mat
mat.EigenMatrix.init_random(seed=1)
plt.figure(1)
plt.clf()
x = mat.empty((100, 100))
x.fill_with_randn()
plt.hist(x.asarray().flatten(), 100)

plt.figure(2)
plt.clf()
y = np.random.randn(100, 100)
plt.hist(y.flatten(), 100)

raw_input('Press Enter.')