예제 #1
0
파일: vis.py 프로젝트: 3lectrologos/Gpy
def plot1(gp, ngrid=100, lim=None, k=range(-3, 4)):
    k = sorted(k)
    if lim is None:
        lim = (np.amin(gp.x[:, 1]), np.amax(gp.x[:, 1]))
    x = np.linspace(lim[0], lim[1], ngrid).T
    (m, v) = gp.inf(x)
    m = np.asarray(m).squeeze()
    v = np.asarray(v).squeeze()
    plt.plot(x, m,
             color=DARKBLUE,
             linewidth=2)
    for i in k:
        if i == 0: continue
        lo = m - i*np.sqrt(v)
        hi = m + i*np.sqrt(v)
        plt.fill_between(x, lo, hi,
                         linestyle='solid',
                         edgecolor=DARKGRAY,
                         facecolor=LIGHTGRAY,
                         alpha=0.2)
    plt.plot(gp.x, gp.y,
             'o',
             markersize=8,
             markeredgewidth=1,
             markeredgecolor=DARKGRAY,
             markerfacecolor=LIGHTBLUE)
    plt.xlim(lim)
예제 #2
0
파일: autoencoder.py 프로젝트: ali01/qjam
  def __init__(self, trainingSet, outputFile):
    self.trainingSet_ = trainingSet
    self.outputFile_ = outputFile

    # initialize weights
    self.weights1_ = matlib.rand(self.HIDDEN, self.FEATURES)
    self.weights1_ = self.weights1_ / matlib.sqrt(self.FEATURES)

    self.weights2_ = matlib.rand(self.FEATURES, self.HIDDEN)
    self.weights2_ = self.weights2_ / matlib.sqrt(self.HIDDEN)

    # initialize bias
    self.bias1_ = matlib.zeros((self.HIDDEN, ))
    self.bias2_ = matlib.zeros((self.FEATURES, ))

    # initialize rho estimate vector
    self.rho_est_ = matlib.zeros((self.HIDDEN, )).T
예제 #3
0
 def auclidic_distance(x: pn.DataFrame, y: pn.DataFrame) -> float:
     sum = 0
     params = [
         'Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness',
         'Insulin', 'BMI', 'DiabetesPedigreeFunction', 'Age'
     ]
     for p in params:
         sum += abs(x[p] - y[p])**2
     return np.sqrt(sum)
예제 #4
0
    def __init_learner(self, outputFile):

        self.outputFile_ = outputFile

        # initialize weights
        self.weights1_ = matlib.rand(self.HIDDEN, self.FEATURES)
        self.weights1_ = self.weights1_ / matlib.sqrt(self.FEATURES)

        self.weights2_ = matlib.rand(self.FEATURES, self.HIDDEN)
        self.weights2_ = self.weights2_ / matlib.sqrt(self.HIDDEN)

        # initialize bias
        self.bias1_ = matlib.zeros((self.HIDDEN, ))
        self.bias2_ = matlib.zeros((self.FEATURES, ))

        # initialize rho estimate vector
        self.rho_est_ = matlib.zeros((self.HIDDEN, )).T
        self.errors = []
    def __init_learner(self, outputFile):

        self.outputFile_ = outputFile

        # initialize weights
        self.weights1_ = matlib.rand(self.HIDDEN, self.FEATURES)
        self.weights1_ = self.weights1_ / matlib.sqrt(self.FEATURES)

        self.weights2_ = matlib.rand(self.FEATURES, self.HIDDEN)
        self.weights2_ = self.weights2_ / matlib.sqrt(self.HIDDEN)

        # initialize bias
        self.bias1_ = matlib.zeros((self.HIDDEN,))
        self.bias2_ = matlib.zeros((self.FEATURES,))

        # initialize rho estimate vector
        self.rho_est_ = matlib.zeros((self.HIDDEN,)).T
        self.errors = []
예제 #6
0
    def __init_projector(self, inputFile):

        handle = open(inputFile, "r+")

        # initialize weights
        self.weights1_ = matlib.zeros((self.HIDDEN, self.FEATURES))
        self.weights1_ = self.weights1_ / matlib.sqrt(self.FEATURES)

        for r, line in enumerate(handle.readlines()):
            for c, col in enumerate(line.strip().split(" ")):
                self.weights1_[r, c] = float(col)

        handle.close()
        # initialize bias
        self.bias1_ = matlib.zeros((self.HIDDEN, ))
예제 #7
0
def plot_cov(mu, sigma):
    mu = np.asarray(mu)
    sigma = np.asarray(sigma)

    t = np.linspace(-math.pi, math.pi, 2*math.pi/.1)
    x = np.sin(t)
    y = np.cos(t)

    D_diag, V = ml.linalg.eigh(sigma)
    D = np.diag(D_diag)
    A = np.real((np.dot(V,ml.sqrt(D))).T)

    z = np.dot(np.vstack((x.T,y.T)).T,A)

    plt.plot(z[:,0]+mu[0], z[:,1]+mu[1], 'y-')
예제 #8
0
def plot_cov(mu, sigma, plotType = 'b-', alpha=1):
    mu = np.asarray(mu)
    sigma = np.asarray(sigma)

    t = np.linspace(-np.pi, np.pi, 2*np.pi/.1)
    x = np.sin(t)
    y = np.cos(t)

    D_diag, V = ml.linalg.eigh(sigma)
    D = np.diag(D_diag)
    A = np.real((np.dot(V,ml.sqrt(D))).T)

    z = np.dot(np.vstack((x.T,y.T)).T,A)

    plt.plot(z[:,0]+mu[0], z[:,1]+mu[1], plotType, alpha=alpha, linewidth=4, mew=2.0)
예제 #9
0
def plot_cov(mu, sigma, plotType='b-', alpha=1):
    mu = np.asarray(mu)
    sigma = np.asarray(sigma)

    t = np.linspace(-math.pi, math.pi, 2 * math.pi / .1)
    x = np.sin(t)
    y = np.cos(t)

    D_diag, V = ml.linalg.eigh(sigma)
    D = np.diag(D_diag)
    A = np.real((np.dot(V, ml.sqrt(D))).T)

    z = np.dot(np.vstack((x.T, y.T)).T, A)

    plt.plot(z[:, 0] + mu[0], z[:, 1] + mu[1], plotType, alpha=alpha)
예제 #10
0
    def __init_projector(self, inputFile):

        handle = open(inputFile, "r+")

        # initialize weights
        self.weights1_ = matlib.zeros((self.HIDDEN, self.FEATURES))
        self.weights1_ = self.weights1_ / matlib.sqrt(self.FEATURES)


        for r, line in enumerate(handle.readlines()):
            for c, col in enumerate(line.strip().split(" ")):
                self.weights1_[r, c] = float(col)

        handle.close()
        # initialize bias
        self.bias1_ = matlib.zeros((self.HIDDEN,))
예제 #11
0
 def auclidic_distance(x: pn.DataFrame, y: pn.DataFrame,
                       subset: list) -> float:
     sum = 0
     params = [
         'Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness',
         'Insulin', 'BMI', 'DiabetesPedigreeFunction', 'Age'
     ]
     modified_params = []
     if subset is None:
         modified_params = params
     elif len(subset) == 1:
         modified_params.append(params[subset[0]])
     else:
         for idx in subset:
             modified_params.append(params[idx])
     for p in modified_params:
         sum += abs(x[p] - y[p])**2
     return np.sqrt(sum)
예제 #12
0
 def return_magnitude(self):
     """Returns the magnitude matrix of this matrixvector"""
     from numpy.matlib import sqrt
     return sqrt(elementwise_dot_product(self, self))
예제 #13
0
def rand_init(fan_in, fan_out):
    ret = np.asarray(rng.uniform(low=-np.sqrt(3. / fan_in),
                                 high=np.sqrt(3. / fan_in),
                                 size=(fan_in, fan_out)),
                     dtype=T.config.floatX)
    return ret
예제 #14
0
def haar_matrix(dim):
    '''
    Generate haar transformation matrix.
    '''
    Q = M.matrix('1 1;-1 1')
    return 1 / M.sqrt(2) * M.kron(M.eye(dim / 2), Q)
예제 #15
0
 def scaleParams(self):
     for con in self.network._containerIterator():
         factor = 1.0 / sqrt(con.indim)
         for param in range(len(con.params)):
             con.params[param] *= factor
예제 #16
0
def rand_init(fan_in, fan_out):
    ret = np.asarray(rng.uniform(
        low = -np.sqrt(3. / fan_in),
        high = np.sqrt(3. / fan_in),
        size = (fan_in, fan_out)), dtype = T.config.floatX)
    return ret
예제 #17
0
def haar_matrix(dim):
    '''
    Generate haar transformation matrix.
    '''
    Q = M.matrix('1 1;-1 1')
    return 1 / M.sqrt(2) * M.kron(M.eye(dim / 2), Q)
예제 #18
0
 def return_magnitude(self) -> matrix:
     """Returns the magnitude matrix of this matrix vector"""
     return sqrt(square(self.x) + square(self.y))