Tutorial 2c – Python likelihood function

In this tutorial we formulate the likelihood function of the problem introduced in Tutorial 2 in Python and use Fesslix to perform the Bayesian inference. BUS-SuS is employed as inference method.

This tutorial is based on Tutorial 2a. Please perform Tutorial 2a before you start with this tutorial. The code given in this tutorial (Tutorial 2c) replaces the code given in Section 1.3 of Tutorial 2a. The code given in Sections 1.1 and 1.2 of Tutorial 2a precedes all code given in this tutorial (Tutorial 2c); and the code given in Sections 1.4 and 1.5 of Tutorial 2a succeedes all code given in this tutorial (Tutorial 2c).


For this tutorial you must have a 64-bit version of Python 2.7 installed on your system. You can download the latest 2.7 release from here: https://www.python.org/downloads/windows/.

1   Step by Step Instruction

1.1   Python file

We begin with expressing the likelihood function in Python. We create a file tutorial_2c_likeli.py with content:

Python code "tutorial_2c_likeli.py"
import flx
import math

h1 = 3.13;       # the 1st observed eigenfrequency
h2 = 9.83;       # the 2nd observed eigenfrequency
sgma_e = 1./16.; # the standard deviation associated with the observation errors
k = 29.7e6;    # multiplying this value with the random variables x1 and x2 gives the stiffness values
m1 = 16.531e3;   # the lumped mass associated with the 1st DOF
m2 = 16.131e3;   # the lumped mass associated with the 2nd DOF
a = m1*m2;       # a constant that is needed in the model

def PyLikeli( x1, x2 ):
  k1 = x1*k;
  k2 = x2*k;
  b = -m1*k2-m2*(k1+k2);
  c = math.sqrt(b*b-4*a*k1*k2);
  f1 = math.sqrt((-b-c)/(2*a))/2/math.pi;
  f2 = math.sqrt((-b+c)/(2*a))/2/math.pi;
  J = math.pow(math.pow(f1/h1,2)-1,2)+math.pow(math.pow(f2/h2,2)-1,2);
  res = math.exp(-J/(2*math.pow(sgma_e,2)));
  return res

What is done in this file? First, we load the module flx. This module provides an interface that allows us retrieving data from the current Fesslix session. In the function above, we use the function flx.vec to retrieve a tuple from Fesslix that contains the components of vector rv_vec.

1.2   Fesslix parameter file

First, we need to load the Python interface in Fesslix:

Fesslix parameter file
loadlib "python";


Next, we link the Python function PyLimit in file tutorial_2c_likeli.py to Fesslix as FlxFunction likeli.

Fesslix parameter file
# add current path to Python search path
  python_path $pwd();
# load the module 'tutorial_2c_likeli'
  python_module tutorial_2c_likeli;
# link the Python function to Fesslix
  python_fun likeli = tutorial_2c_likeli.PyLikeli;

2   The complete input files of this tutorial

fesslix.org – Home  |  Contact  |  Impressum  |  © 2015-2017 Wolfgang Betz