> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Hypotheses and trees of hypotheses

> Hypotheses in ABBYY FlexiLayout Studio are candidate matches for elements: see how quality is calculated, what null hypotheses are, and a worked example.

A **hypothesis** is an assumption made by the program that the detected object(s) correspond(s) to a particular element, that is, meet(s) the properties and search criteria specified for the element.

<Warning>
  There may be several objects or sets of objects in the element’s search area, all of which correspond to the element. In this case, the program will formulate a hypothesis for each detected object.
</Warning>

Hypotheses are characterized by their **quality**.

The quality of a hypothesis measures how well the detected object matches the description contained in the corresponding element and is a numerical value from 0 to 1.

The quality of a hypothesis is calculated as \[ Pre-search quality ]\*\[ Post-search quality ], where

* Pre-search quality is the quality of the settings made in the **Properties** dialog box and in the **Advanced pre-search relations** field.
* Post-search quality is the result of applying the conditions specified in the **Advanced post-search relations** field.

The quality of a hypothesis for a Group element is calculated by multiplying the qualities of the hypotheses for all the constituent elements.

For [optional elements](/flexi-capture/fls/template/elements-optional) the program formulates a null hypothesis.

A **null hypothesis** is a hypothesis which the program formulates if it has detected no objects corresponding to an optional element in the search area.

This means that if the program does not find any objects corresponding to an optional element, it does not stop matching the FlexiLayout, but formulates a null hypothesis and assigns it a quality set by the user when creating the optional element.

For convenience, the term *hypothesis* is also used to refer to the set of objects included in a particular hypothesis.

## Hypotheses: a practical example

Suppose you need to create two elements which will be used to find two static texts on your images. The first static text is "mother", the second static text is "father", and the text "father" is always located below the text "mother". The first Static Text element, **StaticText1**, will be used to look for the text "mother", and the second Static Text element, **StaticText2**, will be used to look for the text "father". Assume also that both elements are optional and that the quality of the null hypothesis for each of them is set to 0.97.

No constraints are set on the search area for **StaticText1**. Because the text "father" is always located below the text "mother", you can specify that **StaticText2** must always be located below **StaticText1**. To do this, type the corresponding constraint on the **Relations** tab in the **Properties** dialog box of the **StaticText2** element: `Below: SearchElements.StaticText1;`.

The following figure displays the results of matching the FlexiLayout with an image on which the word "mother" occurs twice (above and below the word "father") and one OCR error has been made in the word "mother" located above the word "father".

<img src="https://mintcdn.com/abbyy/fmgRWFNHKYN2MLSg/images/flexi-capture/fls/Example_Father_Mother.gif?fit=max&auto=format&n=fmgRWFNHKYN2MLSg&q=85&s=9daad26cd814a1feb2fd5f58f07a9a0e" alt="" width="549" height="486" data-path="images/flexi-capture/fls/Example_Father_Mother.gif" />

Matching the FlexiLayout has generated two hypotheses for the **StaticText1** element. The first hypothesis corresponds to the word "mother" recognized with one OCR error and located above the word "father" and has a quality of 0.98. The second hypothesis corresponds to the word "mother" located below the word "father" and has a quality of 1.

At this stage, the quality of each chain is the same as the quality of the corresponding hypothesis. Therefore, the best chain consists of the hypothesis with a quality of 1.

Since the **StaticText2** element must be located below the **StaticText1** element and since the program has generated two hypotheses for the **StaticText1** element, the program now tries to find the required static text in two search areas. If the program pursues the second hypothesis with a quality of 1, which has found the word "mother" below the word "father", it will fail to find the **StaticText2** element below the **StaticText1** element and, consequently, it will generate a null hypothesis with a quality of 0.97. The quality of the resulting chain of hypotheses will be 1x0.97=0.97.

If the program pursues the first hypothesis with a quality of 0.98, which has found the word "mother" above the word "father", it will successfully detect the **StaticText2** element below the **StaticText1** element and generate a hypothesis with a quality of 1. The quality of the resulting chain of hypotheses will be 0.98x1=0.98.

As a result, the program selects the chain with an overall quality of 0.98.
