def get_current_cost(db): W = db['W_matrix'] iv = np.array(range(db['N'])) jv = iv I = np.eye(W.shape[1]) # Setting up the cost function cost_foo = 0 for i in iv: for j in jv: x_dif = db['data'][i] - db['data'][j] x_dif = x_dif[np.newaxis] gamma_ij = create_gamma_ij(db, db['y_tilde'], i, j) cost_foo = cost_foo - gamma_ij * np.exp( -x_dif.dot(W).dot(W.T).dot(x_dif.T)) return cost_foo
def get_W_gradient(db, y_tilde, previous_gw, w_l): update_direction = 0 updated_magnitude = 0 for i in range(db['N']): for j in range(db['N']): A_ij = create_A_ij_matrix(db,i,j) gamma_ij = create_gamma_ij(db, y_tilde, i, j) part_1 = np.true_divide(np.dot(A_ij, w_l), np.power(db['sigma'],2)) part_2 = np.exp(np.true_divide(np.dot(w_l, part_1),-2)) portion_magnitude = gamma_ij*previous_gw[i,j]*part_2; ij_addition = -portion_magnitude*part_1 updated_magnitude += portion_magnitude update_direction += ij_addition #print 'updated_magnitud : ' , updated_magnitude return [update_direction, updated_magnitude]
def get_W_gradient(db, y_tilde, previous_gw, w_l): update_direction = 0 updated_magnitude = 0 for i in range(db['N']): for j in range(db['N']): A_ij = create_A_ij_matrix(db, i, j) gamma_ij = create_gamma_ij(db, y_tilde, i, j) part_1 = np.true_divide(np.dot(A_ij, w_l), np.power(db['sigma'], 2)) part_2 = np.exp(np.true_divide(np.dot(w_l, part_1), -2)) portion_magnitude = gamma_ij * previous_gw[i, j] * part_2 ij_addition = -portion_magnitude * part_1 updated_magnitude += portion_magnitude update_direction += ij_addition #print 'updated_magnitud : ' , updated_magnitude return [update_direction, updated_magnitude]
def Stochastic_W_gradient(db, y_tilde, previous_gw, w_l, i_values, j_values): update_direction = 0 updated_magnitude = 0 import pdb pdb.set_trace() for i in i_values: for j in j_values: A_ij = create_A_ij_matrix(db, i, j) gamma_ij = create_gamma_ij(db, y_tilde, i, j) part_1 = np.true_divide(np.dot(A_ij, w_l), np.power(db['sigma'], 2)) part_2 = np.exp(np.true_divide(np.dot(w_l, part_1), -2)) portion_magnitude = gamma_ij * previous_gw[i, j] * part_2 updated_magnitude -= portion_magnitude update_direction += portion_magnitude * part_1 #print 'updated_magnitud : ' , updated_magnitude return [update_direction, updated_magnitude]
def Stochastic_W_gradient(db, y_tilde, previous_gw, w_l, i_values, j_values): update_direction = 0 updated_magnitude = 0 for i in i_values: for j in j_values: #import pdb; pdb.set_trace() A_ij = create_A_ij_matrix(db,i,j) gamma_ij = create_gamma_ij(db, y_tilde, i, j) wAw = w_l.T.dot(A_ij).dot(w_l) + previous_gw[i,j] + 1 front_constant_term = gamma_ij*db['poly_order'] polynomial_term = np.power(wAw, db['poly_order'] - 1) derivative_term = (A_ij + A_ij.T).dot(w_l) portion_magnitude = gamma_ij*np.power(wAw, db['poly_order']) updated_magnitude += portion_magnitude update_direction += front_constant_term*polynomial_term*derivative_term #print 'updated_magnitud : ' , updated_magnitude return [update_direction, updated_magnitude]
def create_gamma_ij(self, i, j): if type(self.gamma_array) == type(None): return create_gamma_ij(self.db, self.y_tilde, i, j) else: return self.gamma_array[i, j]
def create_gamma_ij(self, db, i, j): if type(self.gamma_array) == type(None): return create_gamma_ij(db, self.y_tilde, i, j) else: return self.gamma_array[i,j]