Bayes Server has a .NET library for Bayesian networks and Dynamic Bayesian networks.

This tutorial shows the steps required to compile and run one of the help samples that performs parameter learning from a database.


1 - Bayes Server

Bayes Server must be installed, before starting this walkthrough.


An evaluation version can be downloaded from the Bayes Server website.

2 - Development environment

To use the Bayes Server libraries, a software development environment is required. Microsoft provides free software that can be used if required, such as Microsoft C# Express, Microsoft VB.NET Express, and Microsoft VC++ Express. Many other languages also support the .NET framework and are therefore capable of using Bayes Server. For the purposes of this tutorial we will use Microsoft C# Express.

3 - Sql Server Express Database

A Sql Server express database (2008 or later) must be installed, before starting this walkthrough.


The database must be setup (once) using the database script that accompanies the course notes.

Create a new project

  1. Open the development environment (Microsoft C# Express)

  2. Click File->New Project...

  3. Select Console Application

  4. Call your new project BayesServerDemo

  5. Click OK

Add Bayes Server .NET references

  1. Open Solution explorer and expand your new project.

  2. Right click on the references folder and click 'Add Reference...'

  3. Click the Browse Tab and navigate to the installation directory for Bayes Server.


    If you installed Bayes Server to the default location this is 'C:\Program Files\Bayes Server\Bayes Server x.x\' or 'C:\Program Files (x86)\Bayes Server\Bayes Server x.x\'.

  4. Select the following dlls, then click OK.

    1. BayesServer.dll
    2. BayesServer.Inference.dll
    3. BayesServer.Data.dll
    4. BayesServer.Learning.Parameters.dll

Add Bayes Server native references

  1. In addition to the .NET references, BayesServer.Native.dll and BayesServer.Native64.dll are also required to use the Bayes Server API, however they will not be indirectly referenced automatically, as they are not .NET dlls. To ensure that BayesServer.Native.dll and BayesServer.Native64.dll are added to your output directory complete the following steps...

    Right click on your Visual Studio project and click Add->Add Existing....

  2. Select both BayesServer.Native.dll and BayesServer.Native64.dll from the Bayes Server installation folder.


    You may need to change the file filter drop down to All Files(*.*).

  3. Instead of clicking the Add button, click the drop down next to the Add button and click Add as link.

  4. Set the following properties on the linked files you just added to your project.

    Build Action=None

    Copy To Output Directory = Copy always (or Copy if newer)


    If you create an installer, you must explicity add BayesServer.Native.dll and BayesServer.Native64.dll, as they will not be automatically detected as a required reference.

Copy sample code

  1. Open the help file BayesServer.chm from the installation location, or from the User Interface using the keyboard shortcut F1.


    If you installed Bayes Server to the default location this can be found in 'C:\Program Files\Bayes Server\Bayes Server x.x\' or 'C:\Program Files (x86)\Bayes Server\Bayes Server x.x\'.

  2. Naviagte to the class BayesServer.Learning.Parameters.ParameterLearning in the Class library help, and copy the source code from the first sample entitled 'Learning a mixture model'.

  3. Open Program.cs in your new console project and paste the source code into the file, replacing the existing code.


    If you are using a licensed copy of Bayes Server you will also need to call Validate(String) at the start, passing in your license/activation code.

  4. Change the name of the database in the code to BSTRX.

    The code should now read:

    string database = "BSTRX";

    You may also need to change the sqlServer name from its default value of localhost\sqlexpress if you are using a standard Sql Server database or a custom install.

    Now Program.cs should look something like this:

    Bayes ServerAPIParameter Learning

Run the project

  1. You are now ready to run the project.

    From the Debug menu either click Start Debugging (F5) or Start Without Debugging (Ctrl+F5).

  2. Your output should look similar to this.

    Bayes ServerAPIParameter Learning Output