Custom (Empirical) Distribution

If none of the probability distributions supported by AnyLogic fits your data, you can define your own custom (empirical) distribution.

 To define a custom distribution

  1. Drag the Custom Distribution element from the  Agent palette onto the agent diagram.
  2. Go to the element properties to define the distribution by entering data.
  3. First, choose the Type of the distribution. Type means the type of values the distribution returns, and can be one of the following: ContinuousDiscrete, or Options. Options means that you specify probabilities for every alternative option of the chosen Option list.
  4. Define the data for a custom distribution in the Data section of the element's properties. There are three alternative options:
       Data for different distribution types is defined in different ways. We will cover them in the following topics:

Properties

General

Name – The name of the custom distribution. The name is used to access the custom distribution. You call the distribution like a function, e.g.: myDistribution().

Show name – If selected, the element is displayed on the graphical diagram.

Ignore – If selected, the custom distribution is excluded from the model.

Visible – Here you specify whether the element is visible on the presentation at the model runtime, or not. Choose yes or no using the control.

Type – The type of values the distribution returns:
Continuous – Distribution returns continuous type of data.
Discrete – Distribution returns discrete type of data.
Options –  Allows to specify probabilities for every alternative option of the chosen option list.

Define using – [Visible only if Continuous or Discrete is selected in the Type option] Specify what the distribution will be defined by:
Ranges – Defines distribution with ranges.
Frequency table – [Active only if Continuous is selected in the Type option]. Defines distribution with frequency table.
Observed samples – Loads the observed values as they are.

Option list – [Visible only if Options is selected in the Type option] Here you select the option list for this custom distribution. The distribution will define the occurrence probabilities for every option of this list.

Data
Here you define data for the custom distribution. Data can be specified in the table (see the instructions below), or loaded from the AnyLogic database.

Loaded from database
- If set, allows to load data from the existing AnyLogic database defined by the user.

Table – Here you can select the table of the AnyLogic database that contains the required data.

Choice conditions
 – Here you define one or several conditions that will specify the particular values to be selected from the specified table column. You can add , duplicate , delete and arrange the conditions ( , ).

Value column  [Visible if Frequency table or Observed samples is selected in the Define using option] The column of the database table that contains values.

Weight column 
 [Visible only if Frequency table is selected in the Define using option] The probabilities for the corresponding values in the Value column.

Start column
 – [Visible if Ranges is selected in the Define using option] The column of the database table that contains values the data ranges start from.

End column
 – [Visible if Ranges is selected in the Define using option] The column of the database table that contains values the data ranges end with.

Option column 
– [Visible only if Options is selected in the Type option] The column of the database table that contains options of the option list. This column's Type should be exactly the same option list that is specified in the Option list property of this custom distribution.

Number of observations column 
[Visible if Ranges is selected in the Define using option, or if Options is selected in the Type option] The column of the database table that contains the data (numbers of observations for corresponding ranges, or options of the option list). This column must contain only numeric values.
Preview

Here you can see the custom distribution preview.

Advanced

Static – If selected, the custom distribution is static. Static distribution is initialized once and has the same data for all instances of this agent type. This is very useful in agent based models, in case your agents have some distributions defined. Making a custom distribution static, AnyLogic engine does not waste time on initializing it several times for numerous agents. 

Do not use static custom distribution, if you plan to run iterations of complex experiments (optimization, parameter variation, etc.) in parallel on different processor cores (this is set by the experiment's advanced option Allow parallel evaluations).

Static custom distribution are not saved into a snapshot file when you save/restore a state of a running model. If you do not alter the data of a static custom distribution in your model, the state of the restored model will be exactly the same as you saved it into the snapshot. However, if you somehow change the data of a static custom distribution (e.g. in agent's On startup code), the modified data will not be saved into a snapshot, and the restored state of the model will differ from the state you have previously saved.


Defining the data for a discrete distribution

There are two alternative ways to define the distribution data for a discrete distribution. You choose the definition mode in the Define as property of the custom distribution. 

Ranges. You define ranges and probabilities (weights) for these ranges. The ranges should follow one another.

Discrete distribution defined using Ranges

Observed samples. In this mode you just load the observed values as they are. The frequency of the particular value depends on the number of times this value is met in the table (i.e. number of times this value was observed). Use this mode if you have a table of observed data. The easiest way to load data into the model is to copy it to the clipboard in the data source file or a program and paste the data here by clicking the Paste from Clipboard button below the table in the Data property section.

Open the Preview properties section to see the distribution preview built for the data you have entered.

     

Discrete distribution defined using Observed samples. Data and Preview sections..

Defining the data for a continuous distribution

There are three alternative ways to define the distribution data for a continuous distribution:

Ranges. You define ranges and probabilities (weights) for these ranges. The ranges should follow one another.

Frequency table. Here you define the values in the first column of the table and the corresponding weights in the second column. 

    There are three Interpolation types: None, Step, Linear

    If None is selected, you define single weighted values. 

    If Step is selected, you define the same things as in the Range definition mode.

    If Linear is selected, you define Sloped ranges.

   

Continuous distribution defined using the Frequency table with Linear Interpolation. You can see sloped ranges in the Preview.

Observed samples. In this mode you just load the observed values as they are. The frequency of the particular value depends on the number of times this value is met in the table (i.e. number of times this value was observed). Use this mode if you have the table of observed data. The easiest way to load data in the model is to copy it to the clipboard in the data source file or a program and paste the data here by clicking the Paste from Clipboard button below the table in the Data property section.

Defining the data for options distribution

Use Options type to define probabilities for alternative options of the chosen Option list.

Here you can see the usage example of the distribution defining the probabilities for Male and Female options of the Sex option list.

Creating a custom distribution programmatically

AnyLogic provides three constructors for creating an empirical distribution (CustomDistribution class):