.. index:: Compile

.. _Compile:

Compile
=======

The *compile* function is activated from :ref:`Edit Mode<edit_mode>` either by pressing the compile tool button (see Figure 1) or by selecting the Run  item of the :ref:`Network Menu<network_menu>`.

.. figure:: images/tool_compile.png

	Figure 1: The compile tool button from the :ref:`Network Window<network_window>` Tool Bar.

You can also activate the compile function from :ref:`Run Mode<run_mode>`. Here, the Run Mode item of the Network Menu is replaced with the Recompile item.

When activating the compile function from Edit Mode, the current network is compiled and Run Mode is entered.

When activating the compile function from Run Mode, the current network is :ref:`recompiled<re_compile>` (this can sometimes be useful). If the color of the compile button changes, then this indicates that a recompilation of the network may be require in order to capture any changes made to the class of the network or to classes of instance nodes in the network. Notice that a compilation of a :ref:`(limited-memory) influence diagram<About_Limited_Memory_Influence_Diagram>` does not compute updated policies. To update policies it is necessary to perform a :ref:`Single Policy Update<single_policy_update>` after compiling the network.

The compilation of a HUGIN network involves a transformation of the network to a :ref:`junction tree<junction_tree>` in which the :ref:`propagations<propagation>` can take place.

You can specify certain properties on the compilation in HUGIN from the :ref:`Network Properties<Network_properties>` item of the Network Menu. Figure 2 shows the Compilation tab of the Network Properties dialog box.

.. figure:: images/Compilation_tab.png

	Figure 2: The Network Properties dialog box showing the Compilation tab.

Generally, it is NP hard (mathematical way to say that it is impossible within reasonable time) to find the best internal representation of a HUGIN network (the junction tree representation). This is basically because it is NP hard to triangulate a graph optimally.

In many cases, however, an optimal (or near-optimal) triangulation can in fact be found. From version 5.4 and onwards, The HUGIN Decision Engine offers a method for optimal triangulation, which in many cases results in junction trees of much lower complexity than those generated using the other (heuristic) triangulation methods provided. The optimal triangulation method works by searching for minimal separators. For some networks this results in extremely many possible optimal separators.

Note on Optimal triangulation options:

.. note:: 

	* *Max separators* - To control the running time of the search for an optimal triangulation, the maximum number of minimal separators to generate can be specified. If this value is set to zero, an unlimited number of separators are allowed to be generated.
 	* |figurehere1| - at each triangulation step a separator that minimize this formula is selected. By specifying values for a, b and c we can tweak the selection criteria - this may be beneficial when searching for triangulations for large networks.
	* *a* - specify how to favor weight of the current separator.
	* *b* - specify how to favor added weight of extra fill-ins imposed by current separator.
	* *c* - influence tolerance for the selection of large separators, delta is the difference in size between the entire graph and the largest sub-graph induced by split using this separator.
	* *Load initial triangulation* - instead of using greedy selection of minimal separators to find the initial triangulation, check this field to load an initial triangulation from file (i.e. load a node elimination order from file). **If a good triangulation is already known, then this can be used to speed up the optimal triangulation process significantly!**

.. |figurehere1| image:: images/triangulateformula.png

The other triangulation methods listed in the Compilation tab are different heuristic methods, which in many cases perform quite well, but, as mentioned above, can result in junction trees that are far from optimal, complexity-wise. Which of the heuristics are the better one depends on the network at hand - so if your network is complex and seems to have poor performance with the current heuristic triangulation method, you might try one of the other heuristics or try the optimal triangulation method.

Finally, a triangulation can be loaded from file (i.e. load a node elimination order from file).

The save-to-memory operation stores a copy of the initial clique potentials in memory. This implies a faster initialization process which may improve efficiency of performing multiple propagations (e.g., as part of the Analysis Wizard).

You can sometimes save some space by using the optimization facilities. These are activated in the bottom half of the Compilation tab. You can choose between ordinary :ref:`compression<compress>` and compression involving :ref:`approximation<approximate>`. The latter will cause less precision while the first will not.

If you select Approximate, you must also specify an epsilon value stating how much loss of precision you will allow. The larger the epsilon value, the less the precision (read more about this in the :ref:`Approximate section<approximate>` ).