(calibration_classes_functions_observations_data_and_distance)= # Defining data, distance and likelihood functions The different distance and likelihood functions already embedded in {{uranie}} can be found in [](#calibration_introduction_distance_compare_model) and are further discussed from a theoretical point of view in {{metho}}. From the user point of view, on the other hand, every distance or likelihood function inherits from the class `TDistanceLikelihoodFunction`, as can be seen in {numref}`calibration_Calibration_Class_Hierarchy`, which is purely virtual (meaning that no object can be instantiated as `TDistanceLikelihoodFunction`) and serves several main purposes: - it loads the reference data once and stores them internally as a vector of vectors (or as a vector of `TMatrixD`, depending on the chosen formalism used to compute the distance or likelihood); - once done, the following loop is executed as long as new configurations need to be tested (a configuration being defined as a new set of values for vector $\theta$): 1. it runs the chosen model regardless of the nature of the object (`TRun`, `TCode`, etc.) on the full reference dataset to get the new predictions; 2. it loads the new model predictions for the configuration under study into a vector of vectors (or as a vector of `TMatrixD` depending on the chosen formalism); 3. it computes the distance or likelihood using both vectors as statd by the equations in [](#calibration_introduction_distance_compare_model). This computation is done within the `localeval` method (which is the only method that should be redefined if a user wants to create its own distance or likelihood function, see dedicated discussion in [](#calibration_classes_functions_observations_data_and_distance_distance_func)). From a technical point of view, the `TDistanceLikelihoodFunction` inherits from the `TDoubleEval` class which is a part of the **Relauncher** module. This inheritance is not very important as its main appeal is to **considerably** simplify the implementation of the minimisation methods with the **Reoptimizer** module, allowing the straightforward use of all **TNlopt** algorithms as well as **Vizir** solutions (see [](#calibration_minimisation)). Regardless of the calibration method considered, a distance or likelihood function must be used to compare data and model predictions. This is even true for the `TLinearBayesian` class, which directly computes the analytical posterior distribution, as the residuals are computed both *a priori* and *a posteriori* to assess the improvement of the prediction and their consistency within the uncertainty model (see discussion in {{metho}}). In most cases the object will be constructed with a recommended way (discussed in [](#calibration_classes_functions_observations_data_and_distance_recommended_distance)). Another possibility is also discussed in [](#calibration_classes_functions_observations_data_and_distance_distance_func) Whatever the situation, once a calibration instance is created (for the sake of generality, we will use an instance named `cal`, of the mock class `TCalClass`, as if it inherited from the `TCalibration` class), the first method to be called is the `setDistance` or `setLikelihood` depending on the framework used (see the corresponding section), as this is the method which defines both the type of distance or likelihood function and the observation dataset. ```{toctree} data_and_distance/recommended_distance data_and_distance/distance_func data_and_distance/option_distance_func ```