New Post

Markov Chains || Step-By-Step || ~xRay Pixy

Image
Learn Markov Chains step-by-step using real-life examples. Click Here   Video Link Video Chapters: Markov Chains 00:00 Introduction 00:19 Topics Covered 01:49 Markov Chains Applications 02:04 Markov Property 03:18 Example 1 03:54 States, State Space, Transition Probabilities 06:17 Transition Matrix 08:17 Example 02 09:17 Example 03 10:26 Example 04 12:25 Example 05 14:16 Example 06 16:49 Example 07 18:11 Example 08 24:56 Conclusion In computer science, Markov problems are typically associated with Markov processes or Markov models . These are related to topics involving stochastic processes and probabilistic systems where future states depend only on the current state, not on the sequence of states that preceded it. Artificial Intelligence (AI): Markov Decision Processes (MDP): Used in decision-making problems, especially in reinforcement learning. Hidden Markov Models (HMM): Widely used in speech recognition, handwriting recognition, and natural language processing. Machine Le...

PSO Python Code || Particle Swarm Optimization in Python || ~xRay Pixy


Particle Swarm Optimization Implementation in Python Video Chapters: 00:00 Introduction 02:01 Code 05:55 Position Initialization 08:06 PSO Main Loop 08:42 Velocity Calculation 10:02 Position Update 10:36 Fitness Evaluation 13:21 Objective Function 17:44 Result 19:00 Conclusion

.....................................................SOURCE CODE.........................................................................
import random import numpy as np from tkinter import messagebox #Define Class Particles class Particle: def __init__ (self,position): self.position=position self.velocity=np.zeros_like(position) self.best_position=position self.best_fitness=float('inf') def PSO(ObjF,Pop_Size,D,MaxT): swarm_best_position=None swarm_best_fitness=float('inf') particles=[] #Posotion Initialization position=np.random.uniform(-0.5,0.5,D) particle=Particle(position) particles.append(particle) #Fitness Update fitness=ObjF(position) if fitness<swarm_best_fitness: swarm_best_fitness=fitness swarm_best_position=position particle.best_position=position particle.best_fitness=fitness #PSO Main Loop for itr in range(MaxT): for particle in particles: #Update Velocity w = 0.8 c1 = 1.2 c2 = 1.2 r1=random.random() r2=random.random() #Velocity Calculation particle.velocity =(w*particle.velocity+c1*r1*(particle.best_position-particle.position)+c2*r2+(swarm_best_position-particle.position)) #New Position particle.position += particle.velocity #Evaluate Fitness fitness = ObjF(particle.position) #Update PBest if fitness<particle.best_fitness: particle.best_fitness=fitness particle.best_position=particle.position #Update GBest if fitness<swarm_best_fitness: swarm_best_fitness=fitness swarm_best_position=particle.position return swarm_best_position,swarm_best_fitness #Define ObjFunction def F1(x): return np.sum(x**2) def F2(x): return np.max(np.abs(x)) Objective_Function ={'F1':F1,'F2':F2} #Parameters Pop_Size=100 MaxT=100 D=2 # Iterate over each objective function and run PSO for funName, ObjF in Objective_Function.items(): Output = "Running Function = " + funName + "\n" best_position,best_fitness = PSO(ObjF,Pop_Size,D,MaxT) Output += "BEST POSITION : " + str(best_position)+"\n" Output += "BEST COST : " + str(best_fitness) Output += "\n" messagebox.showinfo("PSO RUN",Output)



Comments

Popular Post

PARTICLE SWARM OPTIMIZATION ALGORITHM NUMERICAL EXAMPLE

Cuckoo Search Algorithm for Optimization Problems

Particle Swarm Optimization (PSO)

PSO (Particle Swarm Optimization) Example Step-by-Step

how is the LBP |Local Binary Pattern| values calculated? Step-by-Step with Example

Grey Wolf Optimization Algorithm

Bat algorithm Explanation Step by Step with example

Grey Wolf Optimization Algorithm Numerical Example

Whale Optimization Algorithm Code Implementation || WOA CODE || ~xRay Pixy