pystruct.models.ChainCRF(n_states=None, n_features=None, inference_method=None, class_weight=None, directed=True)[source]¶Linear-chain CRF.
Pairwise potentials are symmetric and the same for all edges.
This leads to n_classes parameters for unary potentials.
If directed=True, there are n_classes * n_classes parameters
for pairwise potentials, if directed=False, there are only
n_classes * (n_classes + 1) / 2 (for a symmetric matrix).
Unary evidence x is given as array of shape (n_nodes, n_features), and
labels y are given as array of shape (n_nodes,). Chain lengths do not
need to be constant over the dataset.
| Parameters: | n_states : int, default=None
inference_method : string or None, default=None
class_weight : None, or array-like
directed : boolean, default=False
|
|---|
Methods
batch_inference(X, w[, relaxed]) |
|
batch_joint_feature(X, Y[, Y_true]) |
|
batch_loss(Y, Y_hat) |
|
batch_loss_augmented_inference(X, Y, w[, ...]) |
|
continuous_loss(y, y_hat) |
|
inference(x, w[, relaxed, return_energy]) |
Inference for x using parameters w. |
initialize(X, Y) |
|
joint_feature(x, y) |
Feature vector associated with instance (x, y). |
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) |
__init__(n_states=None, n_features=None, inference_method=None, class_weight=None, directed=True)[source]¶inference(x, w, relaxed=False, return_energy=False)¶Inference for x using parameters w.
Finds (approximately) armin_y np.dot(w, joint_feature(x, y)) using self.inference_method.
| Parameters: | x : tuple
w : ndarray, shape=(size_joint_feature,)
relaxed : bool, default=False
return_energy : bool, default=False
|
|---|---|
| Returns: | y_pred : ndarray or tuple
|
joint_feature(x, y)¶Feature vector associated with instance (x, y).
Feature representation joint_feature, such that the energy of the configuration (x, y) and a weight vector w is given by np.dot(w, joint_feature(x, y)).
| Parameters: | x : tuple
y : ndarray or tuple
|
|---|---|
| Returns: | p : ndarray, shape (size_joint_feature,)
|
loss_augmented_inference(x, y, w, relaxed=False, return_energy=False)¶Loss-augmented Inference for x relative to y using parameters w.
Finds (approximately) armin_y_hat np.dot(w, joint_feature(x, y_hat)) + loss(y, y_hat) using self.inference_method.
| Parameters: | x : tuple
y : ndarray, shape (n_nodes,)
w : ndarray, shape=(size_joint_feature,)
relaxed : bool, default=False
return_energy : bool, default=False
|
|---|---|
| Returns: | y_pred : ndarray or tuple
|