

.. _plot_directional_grid.py:


===========================================
Learning directed interactions on a 2d grid
===========================================
Simple pairwise model with arbitrary interactions on a 4-connected grid.
There are different pairwise potentials for the four directions.
All the examples are basically the same, three vertical stripes.
Only the noise differs.
The CRF learns that it can smooth strongly along the vertical axis and that
there is a specific order in the horizontal direction (see off-diagonal).



.. rst-class:: horizontal


    *

      .. image:: images/plot_directional_grid_1.png
            :scale: 47

    *

      .. image:: images/plot_directional_grid_2.png
            :scale: 47


**Script output**::

  Training 1-slack dual structural SVM
  new constraint too weak.
  new constraint too weak.
  new constraint too weak.
  new constraint too weak.
  no additional constraints
  overall accuracy (training set): 0.954167



**Python source code:** :download:`plot_directional_grid.py <plot_directional_grid.py>`

.. literalinclude:: plot_directional_grid.py
    :lines: 12-

**Total running time of the example:**  10.66 seconds
    