예제 #1
0
파일: nn.py 프로젝트: Luke-A-Wendt/QP
    def __init__(self, x, y, m):
        """
            m is a vector of integers giving each layer dimension
            
            z_i ∈ R^{m_i}, i ∈ [0,n-1]

            x ∈ R^{ x.shape[0], q }
            y ∈ R^{ m[n-1] , q }

            A[i] ∈ R^{ m[i], m[i-1] }
            A[0] ∈ R^{ m[0], x.shape[0] }

            b[i] ∈ R^{ m[i] }

        """
        self.sigmoid = sig.poly1()
        assert x.shape[1] == y.shape[1]
        assert y.shape[0] == m[-1]
        self.x = x
        self.y = y
        self.n = len(m)
        self.z = []
        self.A = []
        self.b = []
        for i in range(self.n):
            if i == 0:
                self.A.append(randn(m[0], x.shape[0]))
            else:
                self.A.append(randn(m[i], m[i - 1]))
            self.b.append(randn(m[i]))
            self.z.append(randn(m[i]))
        self.train()
예제 #2
0
파일: misc.py 프로젝트: Luke-A-Wendt/QP
 def test():
     n = 2
     a = randn(n)
     b = randn(1)
     c = randn(n)
     d = randn(1)
     P = poly.rand(n,1,1)
     problem = linear_fractional(a,b,c,d,P)
     problem.solve()
     print(problem)
예제 #3
0
파일: misc.py 프로젝트: Luke-A-Wendt/QP
 def test():
     print('\n'+'_'*80 + '\nk_means [see ./fig/k_means.png]')
     import random
     n = 2
     m = 20
     k = 4
     s = randn(n,m)+np.kron(ones(1,m),10*randn(n,1))
     for i in range(k-1):
         s = np.hstack((s,randn(n,m)+np.kron(ones(1,m),10*randn(n,1))))
     k_means(s,k).plot()
예제 #4
0
파일: misc.py 프로젝트: Luke-A-Wendt/QP
 def __init__(self,s,k):
     # s = vectors
     # x = means
     m = s.shape[1]
     n = s.shape[0]# s[i] = column vector as matrix in R^n
     x = randn(n,k)
     for loop in range(10):
         d = zeros(k,m)
         for j in range(m):
             for i in range(k):
                     d[i,j] = norm.l_p(s[:,j] - x[:,i], 2)
         min_d = np.full((m), np.inf)
         for j in range(m):
             for i in range(k):
                 if d[i,j] < min_d[j]:
                     min_d[j] = d[i,j]
         b = zeros(k,m)
         for j in range(m):
             for i in range(k):
                 if d[i,j] == min_d[j]:
                     b[i,j] = 1
                 else:
                     b[i,j] = 0
         for i in range(k):
             num = zeros(n,1)
             den = 0
             for j in range(m):
                 num += b[i,j]*s[:,j]
                 den += b[i,j]
             if den != 0:
                 x[:,i] = num / den
             else:
                 x[:,i] += random.gauss(0,1) # random walk
     self.s = s
     self.x = x
예제 #5
0
파일: misc.py 프로젝트: Luke-A-Wendt/QP
 def test():
     print('\n'+'_'*80 + '\npoly_cells [see ./fig/Voronoi.png]')
     n = 2
     m = 100
     x = randn(n,m)
     obj = poly_cells(x)
     obj.plot_poly_cells()
     obj.plot_poly_center()
예제 #6
0
파일: misc.py 프로젝트: Luke-A-Wendt/QP
 def test():
     n = 5
     m = 10
     q = 100
     x = randn(n,q)
     y = zeros(m,q)
     while True:
         A,r = sprandn(m,n,0.1)
         if r < m*n:
             break
     for i in range(q):
         y[:,i] = A * x[:,i]
     print(min_complexity_model(x,y,1))
     print('\nA_data = \n' + str(sparse(A))+'\n')
예제 #7
0
파일: nn.py 프로젝트: Luke-A-Wendt/QP
def test():
    x = randn(2, 100)
    y = randn(3, 100)
    m = (2, 2, y.shape[0])
    nn(x, y, m)
예제 #8
0
파일: misc.py 프로젝트: Luke-A-Wendt/QP
 def test():
     n = 2
     s = randn(n,100)
     sampled_convex_set(s)