# Contents

# Context

#### Analysis | Target Optimization

**Target Optimization** has been entirely redesigned. Now based on a genetic algorithm, this new tool subsumes and extends the following, previously separate functions:

- the original
**Target Optimization**tool, which was an any-time algorithm based on a global search algorithm. It returned the tuples that optimize the objective function specified by the user (maximization or minimization of the probability of a state of the target or of its mean value). These tuples were pieces of**Hard Evidence**or**Soft Evidence**. Since version 5.1, it was possible to constrain these actions (tuples) in terms of**Maximum Resources Allowed**(e.g. the overall budget available). - the
**Resource Allocation Optimization**tool (), which was a variant of**Analysis | Report | Target Analysis | Resource Allocation Optimization****Target Dynamic Profile**, a local search algorithm, where actions (**Soft Evidence**) were constrained in terms of**Maximum Resources Allowed**.

The general criterion to optimize remains the same as in the previous two tools:

- the probability of a state of the target node, or
- the mean value of the target node.

The main objective function can be based either on:

- the maximization or minimization of the criterion, or
- a target value for the criterion.

Furthermore, this objective function can be modulated by three additional criteria:

- the minimization of the resources,
- a target value for the resources,
- the maximization of the joint probability of the observations/actions.

The observations that are used during the optimization can be either:

**Hard Evidence**,*i.e.*100% on one state of the drivers, 0% on all the other ones.**Soft Evidence**,*i.e.*a probability distribution on the drivers. The probability distributions are computed to get a target mean value on the drivers. There is usually not a unique distribution that allows getting the target mean value. Two algorithms are available:**A posteriori Mean**: this is the classical algorithm used by BayesiaLab for computing the**Distribution for Target Value/Mean**. This MinXEnt algorithm returns the distribution that allows getting the target mean while minimizing the Kullback-Leibler divergence with the current distribution.**Direct Mean**: this is a new algorithm that returns either the**Hard Evidence**corresponding to the target mean value, or a distribution over two adjacent states, the probability of the other states being all set to 0%.

Which Type of Mean to Use?

The choice between **A posteriori Mean** and **Direct Mean** depends on the uncertainty of the action result associated with the driver:

**Direct Mean**for nodes that are the direct representation of the drivers and are under control (the probability distribution is then used as an interpolation tool, as in fuzzy logic with membership degrees),*e.g.*the temperature in a furnace**A posteriori Mean**for nodes that do not directly represent the drivers but are rather indirect measures of the effects of the actions,*e.g.*the perceived quality of a product in a population or the product price in different shops/cities

**Soft Evidence**, the

**Variation Editor**allows setting positive and a negative variations (in %) for each driver.

*i.e.*a minimum and maximum mean values.

- the current mean value of the driver, or
- its domain length, or
- its left and right progress margins,
*i.e.*gaps to the minimum and maximum values of the domain.

The minimum and maximum values of the search domain are always tested during the optimization. However, for non linear relations, it can be useful to add **Intermediate Points** that will be uniformly spread between these two values.

The last option allows setting **Direct Effects.** When this option is checked, the probability distributions of the non-driver variables that are confounder are hold fixed during the optimization (*i.e.* the variables that have not been associated with the class **Non_Confounder, **with a **Cost** set to **Not Observable**).

What are the Drivers?

By default, all the observable nodes (*i.e.* with a **Cost** not set to **Not Observable**) are used for optimization.

However, if you select a subset of nodes before running **Target Optimization**, you can restrict the optimization to this subset of nodes.

Note that the resources are always computed by taking into account the all set of observable nodes.

The genetic algorithm generates a large set of solutions during the optimization. The output section allows

- setting how many solutions to store as
**Evidence Scenarios**, and - choosing if the new
**Evidence Scenarios**should replace the current set of scenarios (if any) or be appended to it.

The settings of the genetic algorithm can be displayed or hidden by clicking on and respectively.

This allows setting the weights of the Target Value, Resources and Joint Probability in the fitness function used by the genetic algorithm.

Different parameters of the genetic algorithm can be user defined:

**Number of Races**: a race is a population of individuals (solutions) that evolves independently of the other ones (at least at the beginning of the optimization process)**Population Size**:**Crossover Rate**(%): the probability for the individuals of the worst race to be generated by crossing the genes of the best individuals of two randomly selected races**Gene Mutation Rate**(%): the probability to mute a gene of an individual**Selection Rate****(%)**: the probability for an individual to be selected to breed the new generation.**Use Fixed Seed**: the genetic algorithm being stochastic, using a fixed seed allows the replication of the results.

This genetic algorithm is an any-time algorithm,* i.e.* it can run forever to optimize the solution.

The optimization can always be manually stopped by clicking on the red button of the graph window.

It is also possible to define a stop criterion based on the number * N* of consecutive generations without any improvement of the optimal individual:

- of each race,
*i.e.*the algorithm will stop when all the races did not improved their best individual since at leastconsecutive generations*N* - of the entire population,
*i.e.*the algorithm will stop when the optimal solution (the best individual over all the races) did not improved sinceconsecutive generations*N*

We will reuse the Marketing Mix example we used for introducing the new Resource Allocation Optimization (5.0.7) in BayesiaLab 5.0.7.

The target variable * Sales* has been discretized into 5 bins and has a marginal expected value of 0.872

Six drivers are available, all being normalized (between 0 and 1) and discretized into 5 bins.

, with a cost of 100,000 USD per unit**National Print**: 10,000 USD per unit**Regional Print**: 1,000 USD per unit**Local Print**: 1,000,000 USD per unit**TV**: 10,000 USD per unit**Radio**: 100,000 USD per unit**Online**

All the other nodes are set *Not Observable* and are associated with the class *Non_Confounder*. The distribution of these nodes will not be hold fixed when using **Direct Effects**.

The variable ** Season** is the only variable that is not a driver while being a

*Confounder*.

The total cost (budget) corresponding to the marginal distribution is then 445,249.107 (0.343 x 100,000 + 0.379 x 10,000 + ....... + 0.548 x 100,000)

Note

The resources (and the variation) can be displayed in the header of the **Monitor Panel** by using the contextual menu **Display | Resources **or alternatively** Monitor | Display | Resources.**

This option can be checked by default via **Options | Settings | Inference | Display Computed Resources**

Tip

The variations of the resources are computed in a similar fashion as to the ones of the values in the monitors. They are computed by default with respect to the previous set of evidence, but can also be computed with respect to the reference state set by clicking on

They can be reset by double-clicking on a monitor.

The optimization task defined by these settings is the maximization of the probability of the last state of the Target, by taking into account the Joint Probability (favoring solutions with a high joint), without constraints on the resources, and using Hard Evidence.

Upon clicking on OK, the genetic algorithm begins generating populations.

The **Console Icon** appears to indicate that information are available. Clicking on this icon opens the console:

For each generation, the score of the best individual of each race is displayed (this score has to be minimized). A score comes with *** when the corresponding best individual of the race has improved the optimal solution (race 2 at generation 1 and race 5 at generation 3).

When the algorithm stops, the following color coded report is generated (from dark red for the lowest value of the driver's search domain, to dark red for the highest value of the search domain, yellow corresponding to the neutral color associated with the initial mean value of the driver).

**Analysis Context**: indicates if some evidence have been set on nodes prior to running the optimization.**Initial State**: current state of the to-be-optimized criteria (here the initial probability of the last state of the Targetand the Joint Probability)*Sales***Synthesis**: returns for each driver its- initial mean value,
- mean value in the final optimal solution,
- minimum value over all the solutions that have improved the score of the optimal one,
- maximum value over all the solutions that have improved the score of the optimal one.

**Best Solutions**: returns for each solution that has improved the score of the optimal one,*i.e.*the solutions with scores that came with *** in the console:- the mean value of each driver,
- the score of the solution,
- the state of the optimized criteria.

The best solutions have been saved in the **Evidence Scenario** file. Right-clicking on its corresponding icon allows setting the evidence for each driver and *Confounder.*

Alternatively, we can use **Inference | Interactive Inference** to go through the different solutions more easily.

The optimization task defined by these settings is an objective value of 20% for the probability of the last state of the Target, by taking into account the **Resources** and the **Joint Probability** (favoring solutions with low resources and high joint), and using **Soft Evidence** (**A posteriori Mean**).

Let's do the same optimization but with **Soft Evidence** based on **Direct Mean** instead of **A posteriori Mean.**

As we can see, the mean value for National Print is the same for both solutions, but the distributions that allow to get this mean value are greatly different.

The optimization task defined by these settings is an objective value of 1 for the Target Mean Value with a budget of 400,000 USD (*i.e.* increasing the sales by +0.13 while saving 45,249 USD), by taking into account the **Joint Probability**, and using **Soft Evidence** (**A posteriori Mean**).

Again, let's do the same optimization but with **Soft Evidence** based on **Direct Mean **instead of** A posteriori Mean.**