示例#1
0
        def grad_stability(X):
            (dim, _) = np.shape(X)
            G = np.zeros(np.shape(X))
            A_1 = get_entries(X, A_1_cds)
            diff1 = 2 * np.dot(A_1, mu)
            grad1 = np.tile(mu.T, (block_dim, 1))
            # (block_dim,1) * (block_dim,block_dim) across rows
            grad1 = diff1 * grad1
            set_entries(G, A_1_cds, grad1)

            A_T_1 = get_entries(X, A_T_1_cds)
            diffT1 = 2 * np.dot(A_T_1.T, mu)
            gradT1 = np.tile(mu.T, (block_dim, 1))
            gradT1 = diffT1 * gradT1
            set_entries(G, A_T_1_cds, gradT1.T)

            A_2 = get_entries(X, A_2_cds)
            diff2 = 2 * np.dot(A_2, mu)
            grad2 = np.tile(mu.T, (block_dim, 1))
            grad2 = diff2 * grad2
            set_entries(G, A_2_cds, grad2)

            A_T_2 = get_entries(X, A_T_2_cds)
            diffT2 = 2 * np.dot(A_T_2.T, mu)
            gradT2 = np.tile(mu.T, (block_dim, 1))
            gradT2 = diffT2 * gradT2
            set_entries(G, A_T_2_cds, gradT2.T)
            return (1./dim**2) * G
示例#2
0
def grad_batch_linear_equals(X, c, P_coords, Q, R_coords):
    grad = np.zeros(np.shape(X))
    grad += grad_l2_batch_equals(X, c*get_entries(X, P_coords) + Q,
            R_coords)
    if c != 0:
        grad += grad_l2_batch_equals(X,(1./c)*get_entries(X, R_coords) - Q,
                                    P_coords)
    return grad
示例#3
0
def grad_many_batch_linear_equals(X, constraints):
    grad = np.zeros(np.shape(X))
    (dim, _) = np.shape(X)
    for c, P_coords, Q, R_coords in constraints:
        grad += grad_l2_batch_equals(X, c*get_entries(X, P_coords) + Q,
                    R_coords)
        if c != 0:
            grad += grad_l2_batch_equals(X,
                    (1./c)*(get_entries(X, R_coords) - Q), P_coords)

    return (1./dim**2) * grad
示例#4
0
        def stability(X):
            (dim, _) = np.shape(X)
            A_1 = get_entries(X, A_1_cds)
            diff1 = np.dot(A_1, mu)

            A_T_1 = get_entries(X, A_T_1_cds)
            diffT1 = np.dot(A_T_1.T, mu)

            A_2 = get_entries(X, A_2_cds)
            diff2 = np.dot(A_2, mu)

            A_T_2 = get_entries(X, A_T_2_cds)
            diffT2 = np.dot(A_T_2.T, mu)

            return (1./dim**2) * (np.dot(diff1.T, diff1)
                                + np.dot(diffT1.T, diffT1)
                                + np.dot(diff2.T, diff2)
                                + np.dot(diffT2.T, diffT2))
示例#5
0
 def get_entries(self, start_index):
     json = utils.download_json(self.search_terms, start_index)
     return utils.get_entries(json)
#!/usr/bin/env python3

from etym_patterns import check_etymology
from utils import extract_etymology, get_entries

success = 0
failure = 0
errors = []

for etymology in sorted((extract_etymology(entry) for entry in get_entries()),
                        key=lambda x: (len(x), x)):
    if etymology:
        c = check_etymology(etymology)
        if c:
            success += 1
        else:
            failure += 1
            errors.append(etymology)

print(f"{success} successes; {failure} failures")
if errors:
    for error in errors[:10]:
        print(error)
示例#7
0
#!/usr/bin/env python3

from entry_patterns import check_entry
from utils import get_entries

success = 0
failure = 0
errors = []

for entry in sorted(get_entries(), key=lambda x: (len(x), x)):
    if entry:
        c = check_entry(entry)
        if c:
            success += 1
        else:
            failure += 1
            errors.append(entry)

print(f"{success} successes; {failure} failures")
if errors:
    print()
    for error in errors[:10]:
        print(error)
    print()
示例#8
0
def batch_linear_equals(X, c, P_coords, Q, R_coords):
    """
    Performs operation R_coords = c * P_coords + Q
    """
    val = l2_batch_equals(X, c*get_entries(X, P_coords) + Q, R_coords)
    return val
示例#9
0
def grad_l2_batch_equals(X, A, coord):
    # Upper right
    grad_piece = 2*(get_entries(X,coord) - A)
    grad = np.zeros(np.shape(X))
    set_entries(grad, coord, grad_piece)
    return grad
示例#10
0
def l2_batch_equals(X, A, coord):
    c = np.sum((get_entries(X,coord) - A)**2)
    return c
示例#11
0
def l1_batch_equals(X, A, coord):
    c = np.sum(np.abs(get_entries(X,coord) - A))
    return c