def __init__(self,
                 training_data,
                 weight_decay_p,
                 epsilon,
                 label_count,
                 numerical=False):
        self.training_data = training_data
        self.n, self.m = training_data[0][0].shape
        self.wd = weight_decay_p  # NOTE: WEIGHT DECAY PARAMETER --> what should this be set at??
        self.label_count = label_count
        self.W = np.random.normal(0.0, epsilon**2,
                                  (self.n * self.m + 1) * self.label_count)

        print "training model..."
        if numerical:
            x, f, d = l_bfgs(self.get_J, self.W, None, (), True)
        else:
            x, f, d = l_bfgs(self.get_J, self.W, self.get_J_gradient)
        print "minimum found, J = " + str(f)
        #self.W = np.array(x[:self.n*self.m]).reshape((self.n,self.m))

        # FOR DEBUG
        self.x = x
        self.f = f
        self.d = d
 def __init__(self, training_data, weight_decay_p, epsilon, label_count, numerical=False):
   self.training_data = training_data
   self.n, self.m = training_data[0][0].shape
   self.wd = weight_decay_p  # NOTE: WEIGHT DECAY PARAMETER --> what should this be set at??
   self.label_count = label_count
   self.W = np.random.normal(0.0,epsilon**2,(self.n*self.m+1)*self.label_count)
   
   print "training model..." 
   if numerical:
     x, f, d = l_bfgs(self.get_J, self.W, None, (), True)
   else:
     x, f, d = l_bfgs(self.get_J, self.W, self.get_J_gradient)
   print "minimum found, J = " + str(f)
   #self.W = np.array(x[:self.n*self.m]).reshape((self.n,self.m))
   
   # FOR DEBUG
   self.x = x
   self.f = f
   self.d = d
예제 #3
0
def train_params(training_trees, wd, epsilon, picloud=True, num_cores=0, bf=2, numerical=False):
    training = initialize_trees(training_trees, bf)

    # get the param dimensions
    t = training[0]
    while len(t) > 0:
        t = t[0]
    encoding_size = len(t.node)
    decoded_size = bf * encoding_size

    # train the model with backprop + L-BFGS-B
    x0 = np.random.normal(0.0, epsilon ** 2, 2 * encoding_size * decoded_size + encoding_size + decoded_size)
    print "training model..."

    if picloud:
        x, f, d = l_bfgs(J, x0, Jgrad_picloud, [encoding_size, decoded_size, training, wd, num_cores])
    elif numerical:
        x, f, d = l_bfgs(J, x0, None, [encoding_size, decoded_size, training, wd], True)
    else:
        x, f, d = l_bfgs(J, x0, Jgrad, [encoding_size, decoded_size, training, wd])
    print "minimum found, J = " + str(f)
    # save_params(x, '_final')
    return x