Pairwise CRF with features/strength associated to each edge.
Pairwise potentials are asymmetric and shared over all edges. They are weighted by an edge-specific features, though. This allows for contrast sensitive potentials or directional potentials (using a {-1, +1} encoding of the direction for example).
More complicated interactions are also possible, of course.
Node features and edge features are given as a tuple of shape (n_nodes, n_features) and (n_edges, n_edge_features) respectively.
An instance x is represented as a tuple (node_features, edges, edge_features) where edges is an array of shape (n_edges, 2), representing the graph.
Labels y are given as array of shape (n_features)
Parameters : | n_states : int, default=2
n_features : int, default=None
n_edge_features : int, default=1
inference_method : string, default=”lp”
class_weight : None, or array-like
symmetric_edge_features : None or list
antisymmetric_edge_features : None or list
|
---|
Methods
batch_inference(X, w[, relaxed]) | |
batch_loss(Y, Y_hat) | |
batch_loss_augmented_inference(X, Y, w[, ...]) | |
batch_psi(X, Y[, Y_true]) | |
continuous_loss(y, y_hat) | |
get_edges(x) | |
get_features(x) | |
get_pairwise_potentials(x, w) | Computes pairwise potentials for x and w. |
get_unary_potentials(x, w) | Computes unary potentials for x and w. |
inference(x, w[, relaxed, return_energy]) | Inference for x using parameters w. |
loss(y, y_hat) | |
loss_augmented_inference(x, y, w[, relaxed, ...]) | Loss-augmented Inference for x relative to y using parameters w. |
max_loss(y) | |
psi(x, y) | Feature vector associated with instance (x, y). |
Computes pairwise potentials for x and w.
Parameters : | x : tuple
w : ndarray, shape=(size_psi,)
|
---|---|
Returns : | pairwise : ndarray, shape=(n_states, n_states)
|
Computes unary potentials for x and w.
Parameters : | x : tuple
w : ndarray, shape=(size_psi,)
|
---|---|
Returns : | unary : ndarray, shape=(n_states)
|
Inference for x using parameters w.
Finds (approximately) armin_y np.dot(w, psi(x, y)) using self.inference_method.
Parameters : | x : tuple
w : ndarray, shape=(size_psi,)
relaxed : bool, default=False
return_energy : bool, default=False
|
---|---|
Returns : | y_pred : ndarray or tuple
|
Loss-augmented Inference for x relative to y using parameters w.
Finds (approximately) armin_y_hat np.dot(w, psi(x, y_hat)) + loss(y, y_hat) using self.inference_method.
Parameters : | x : tuple
y : ndarray, shape (n_nodes,)
w : ndarray, shape=(size_psi,)
relaxed : bool, default=False
return_energy : bool, default=False
|
---|---|
Returns : | y_pred : ndarray or tuple
|
Feature vector associated with instance (x, y).
Feature representation psi, such that the energy of the configuration (x, y) and a weight vector w is given by np.dot(w, psi(x, y)).
Parameters : | x : tuple
y : ndarray or tuple
|
---|---|
Returns : | p : ndarray, shape (size_psi,)
|