How to carry out an operator with probability p – Optimization Algorithms

When implementing optimization algorithms, we often bump into this phrase: “an operator needs to be carried out with probability P”. For instance, this can happen when implementing the crossover or mutation phases in Evolutionary Algorithms. It means that you want to select an operation with a specific probability (chance). Let’s have an example: If we want to increase a variable, x, by one unit with probability of p = 0.2. This means that 20% of times we want to carry out this operation and 80% of times we prefer not to. To achieve this behavior, the easiest way is to use a uniform distribution and sample a value in range [0 1]. If the sample is less than the probability p then we can carry out the operation. In MATLAB, the code would be as follows:

x = 0;
p = 0.2;
if rand < p
x = x + 1;
end

 

About machinelearning1

This weblog is about Machine Learning and all related topics that one needs to challenge real world with artificial intelligence.
This entry was posted in Linux, Machine Learning, MATLAB, Optimization, programming, Reinforcement Learning, Robotics, Software, Statistics, Ubuntu and tagged , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a comment