def weighted_neighbors_loss(train_data, valid_data, kernel):
    'Computes the negative log prob per data point.'
    (X_train, T_train) = train_data
    (X_valid, T_valid) = valid_data
    weight_mat = kernel(X_valid, X_train)
    label_probs = np.dot(weight_mat, T_train)
    label_probs = (label_probs / np.sum(label_probs, axis=1, keepdims=True))
    mean_neg_log_prob = (- np.mean(np.log(np.sum((label_probs * T_valid), axis=1)), axis=0))
    return mean_neg_log_prob
Computes the negative log prob per data point.
def weighted_neighbors_loss(train_data, valid_data, kernel):
    
    (X_train, T_train) = train_data
    (X_valid, T_valid) = valid_data
    weight_mat = kernel(X_valid, X_train)
    label_probs = np.dot(weight_mat, T_train)
    label_probs = (label_probs / np.sum(label_probs, axis=1, keepdims=True))
    mean_neg_log_prob = (- np.mean(np.log(np.sum((label_probs * T_valid), axis=1)), axis=0))
    return mean_neg_log_prob