State initialization

With the swarm and chart created and initialized, we now focus on initializing the state of the application itself. This means we are going to collect all the user-defined values and use them to initialize the hyperparameters themselves. We will delve into each in more detail in our chapter on hyperparameters, but for now you just need to be aware that they exist. Let's talk about each as it relates to state initialization.

First, we will determine the strategy we will use to initialize our function optimization. We will store this choice in a variable labeled PSO_Type. Our two choices of strategy are Minimization and Maximization. We determine the type like this:

switch (combType.SelectedIndex)
{
case 0:
PSO_Type = PSOType.Minimization;
break;
case 1:
PSO_Type = PSOType.Maximization;
break;
}

Next, we will initialize the number of dimensions, upper and lower bounds, and speed limits:

dimSize = Convert.ToInt32(txtdimSize.Text);
ub_domXi = Convert.ToDouble(txtUBXi.Text);
lb_domXi = Convert.ToDouble(txtLBXi.Text);
ub_SpeedXi = Convert.ToDouble(txtUbSpeedXi.Text);
lb_SpeedXi = Convert.ToDouble(txtLbSpeedXi.Text);
decP = Convert.ToInt32(txtdecP.Text);

We continue with initializing our inertia, cognitive, and social intelligence weights:

maxIter = Convert.ToInt32(txtmaxIter.Text);
Intertia = Convert.ToDouble(txtW.Text);
CognitiveWeight = Convert.ToDouble(txtC1.Text);
SocialWeight = Convert.ToDouble(txtC2.Text);
wMira = Convert.ToDouble(txtwMira.Text);

One of our most critical hyperparameters relates to our swarm and its population size – how many particles will be in the swarm. Remember, even though we have not placed boundary checks in the source code itself, this value should ideally be a value between 5 and 40. I often use a value of 5 to start my testing. We determine the swarm size by looking at the value that the user entered like this:

SwarmSize = Convert.ToInt32(txtSwarmSize.Text);
Swarm = new Particle[SwarmSize];

Finally, we initialize our global variables to track the maximum efficiency of the swarm:

PlotSwarm = new double[maxIter, SwarmSize, 2];
PlotGlobal = new double[maxIter, 2];
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset