2.2 Optimized Search Algorithm
2.2 Optimized Search Algorithm
Optimization is the process of finding the best solution from all possible choices. We seek to
minimize or maximize a specific objective.
1. Deterministic Optimization
Definition:
Deterministic optimization assumes that the problem’s constraints and objective functions are
known with certainty. There is no randomness involved, meaning the solution is predictable
given the input data.
Characteristics:
Key Methods:
Applications:
Imagine you are blindfolded on a hilly landscape and want to find the lowest point (the
minimum of the function).
You feel the ground around you to determine the steepest downward direction. This direction
is given by the gradient, a vector pointing uphill.
You take a small step in the opposite direction of the gradient, moving in the direction that
decreases the altitude the most.
4. Repeat:
You continue to feel the slope and take steps until you reach the bottom of a valley, which
represents the minimum of the function.
1. Initialization:
Start with initial, often random, values for the model's parameters.
Calculate the cost (or loss) for the current parameters, which measures the error between the
model's predictions and the actual data.
3. Gradient Calculation:
Compute the gradient (the first derivative) of the cost function with respect to each
parameter. This tells you the direction of the steepest increase in the cost function.
4. Parameter Update:
Adjust the parameters by taking a small step in the direction opposite to the gradient. The size
of this step is controlled by a learning rate, a hyperparameter.
5. Iteration:
Repeat steps 2-4 until the model's loss can no longer be reduced or a predetermined number
of iterations is reached.
Why is it used?
Minimizing Errors:
It finds the optimal parameters for a model by minimizing the cost function, thereby reducing
the model's errors.
Learning in AI:
It's the fundamental algorithm for training machine learning and deep learning models,
including neural networks, to learn from data.
Complex Functions:
It's essential for finding the minimum of complex, high-dimensional functions where finding
the minimum analytically is difficult or impossible.
Problem:
We have a machine learning model (e.g., linear regression), and we want to minimize the loss
function (e.g., Mean Squared Error).
Function:
Let’s say our objective function is the Mean Squared Error (MSE) of a linear regression
model:
The significance of the learning rate in Machine Learning (ML) is that it controls the step size during
the model's optimization process, determining how quickly and effectively the model learns from
data.
A low learning rate leads to slow convergence and can cause the model to get stuck in a local
minimum, while a high learning rate risks overshooting the optimal solution, causing instability and
slow, or failed, convergence. An appropriately set learning rate is crucial for achieving high model
performance by balancing the speed of convergence with the accuracy of the solution.
Training a linear regression model to predict house prices based on features like size,
number of rooms, etc.
Linear programming is a mathematical technique used for optimization where the objective
function and the constraints are linear. LP deals with problems that can be expressed as linear
equations.
Linear programming (LP) is a method used in mathematics and optimization to achieve the
best outcome (like maximum profit or lowest cost) in a mathematical model whose
requirements are represented by linear relationships.
1. Objective function: The function you want to maximize or minimize (e.g., maximize
profit, minimize cost).
2. Decision variables: The variables that decide the outcome (e.g., how many units of
product A and B to produce).
3. Constraints: Linear inequalities or equations that restrict the values of decision
variables (e.g., resource limits).
4. Non-negativity restrictions: Decision variables are usually required to be zero or
positive.
Simplex Algorithm: A popular method for solving LP problems, though it’s not
polynomial-time in the worst case.
Interior Point Methods: More efficient for large problems, used in modern solvers
like CPLEX and Gurobi.
Applications:
Strengths:
Problem:
You run a factory and need to allocate resources (e.g., machines, workers) to maximize
profit. The problem is subject to constraints such as limited resources (machines, time) and
specific requirements (how much time each worker spends on each machine).
Formulation:
1. Labor hours:
Product A requires 2 hours per unit
Product B requires 1 hour per unit
Maximum available labor hours = 100 hours
2. Material units:
Product A requires 3 units of material per unit
Product B requires 2 units of material per unit
Maximum available material = 120 units
Goal:
Maximize total profit by deciding how many units of Product A and Product B to produce.
Maximize Z=40x+30y
Step 1: Plot the Constraints
Definition:
A subset of linear programming where some or all of the variables are restricted to integer
values. This is useful when the decision variables represent discrete choices (e.g., selecting a
facility, number of workers).
Types:
Methods:
Branch and Bound: A tree-based search method to explore feasible solutions, often
used for solving integer programming problems.
Cutting Plane Method: Iteratively refines the feasible region of the problem to
converge toward the optimal solution.
Applications:
Challenges:
NP-hard, meaning the solution time grows exponentially with problem size.
Solvers often need to balance performance and computational resources (e.g., Gurobi,
IBM CPLEX).
Solution Using Branch and Bound:
You can use the Branch and Bound method or solvers like Gurobi to find the
optimal solution (which job goes to which machine to minimize makespan).
Use Case:
4. Stochastic Optimization
Definition:
Key Methods:
Applications:
Pros:
Cons:
Problem:
Training a neural network with large datasets where calculating the gradient over the entire
dataset is computationally expensive.
Method:
Stochastic Gradient Descent (SGD) uses a subset (mini-batch) of data to compute the
gradient and update weights, making it computationally more feasible.
5. Simulated Annealing
Definition:
How it Works:
Applications:
Strengths:
Challenges:
Problem:
Given a set of cities, find the shortest possible route that visits each city exactly once and
returns to the starting city.
6. Evolutionary Algorithms
Definition:
Evolutionary algorithms are a family of optimization techniques that mimic the process of
natural evolution. They work by iteratively improving a population of candidate solutions
through processes inspired by natural selection, crossover, and mutation.
Key Methods:
Applications:
Strengths:
Problem:
We want to select the best subset of features from a large set of features to improve a
machine learning model’s performance.
Steps:
algorithm to a tree search method, which will require inspecting the entire tree. Consequently, this reduces the total
memory resources to be used. Space is what matters; solutions should occupy a convenient area to consume as little
as possible.
o When it comes to the acceleration of the hill up, most of the time it brings a closure in the local maximum straight
away. This is the route if having quickly getting a quick solution, outshining acquiring a global maximum, is an
incentive.
Disadvantages of Hill Climbing Algorithm
o Concerning hill climbing, it seems that some solutions do not find the optimum point and remain stuck at a
local peak, particularly where the optimization needs to be done in complex environments with many objective funct
o It is also superficial because it just seeks for the surrounding solution and does not get farther than that.
It could be on a wrong course which is based on a locally optimal solution, and consequently Godbole needs to
move far away from current position in the first place.
o It is highly likely that the end result will largely depend on the initial setup and state, with a precedent of it
being the most sensitive factor. It implies that in this case, time is the perimeter of the sphere within which people
develop their skills dynamically, determining their success.
Features of Hill Climbing:
The following are some main features of the Hill Climbing Algorithm:
o Generate and Test variant: Hill Climbing is a variant of the Generate and Test method. The Generate and Test
method produces feedback that helps to decide which direction to move in the search space.
o Greedy approach: Hill-climbing algorithm search moves in the direction that optimizes the cost.
o No backtracking: It does not backtrack the search space, as it does not remember the previous states.
o Deterministic Nature: Hill Climbing is a deterministic optimization algorithm, which means that given the same
initial conditions and the same problem, it will always produce the same result. There is no randomness or uncertaint
operation.
o Local Neighborhood: Hill Climbing is a technique that operates within a small area around the current solution.
It explores solutions that are closely related to the current state by making small, gradual changes. This approach
allows it to find a solution that is better than the current one, although it may not be the global optimum.
State-space Diagram for Hill Climbing:
The state-space landscape is a graphical representation of the hill-climbing algorithm which is showing a graph between
various states of algorithm and Objective function/Cost.
On Y-axis we have taken the function which can be an objective function or cost function, and state-space on the x-axis.
If the function on Y-axis is cost then, the goal of search is to find the global minimum and local minimum. If the function
of Y-axis is Objective function, then the goal of the search is to find the global maximum and local maximum.
objective function.
o Current State: It is a state in a landscape diagram where an agent is currently present.
o Flat local maximum: It is a flat space in the landscape where all the neighboring states of the current state have
o Step 2: Loop until a solution is found or there is no new operator left to apply.
o Else if it is better than the current state, then assign the new state as the current state.
o Else if not better than the current state, then return to step 2.
o Step 5:
as initial state.
o Step 2: Loop until a solution is found or the current state does not change.
o Let SUCC be a state such that any successor of the current state will be better than it.
2. Plateau: A plateau is the flat area of the search space in which all the neighbor states of the current state cont
same value, because of this algorithm does not find any best direction to move. A hill-climbing search might
the plateau area.
Solution: The solution for the plateau is to take big steps or very little steps while searching, to solve the problem.
Randomly select a state which is far away from the current state so it is possible that the algorithm could find non-plateau re
3. Ridges: A ridge is a special form of the local maximum. It has an area which is higher than its surrounding ar
has a slope, and cannot be reached in a single move.
Solution: With the use of bidirectional search, or by moving in different directions, we can improve this problem.
Simulated Annealing:
A hill-climbing algorithm that never makes a move towards a lower value is guaranteed to be incomplete because it can
get stuck on a local maximum. And if algorithm applies a random walk, by moving a successor, then it may complete but
not efficient. Simulated Annealing is an algorithm which yields both efficiency and completeness.
In mechanical terms, Annealing is a process of hardening a metal or glass to a high temperature, then cooling gradually, so
this allows the metal to reach a low-energy crystalline state. The same process is used in simulated annealing, in which the
algorithm picks a random move, instead of picking the best move. If the random move improves the state, then it follows
the same path. Otherwise, the algorithm follows the path that has a probability of less than 1, or it moves downhill and
chooses another path.
Applications of Hill Climbing Algorithm
The hill-climbing technique has seen widespread usage in artificial intelligence and optimization, respectively. It
methodically solves those problems via coupled research activities by systematically testing options and picking out the
most appropriate one. Some of the applications are as follows:
Some of the application are as follows:
1. Machine Learning:
Fine tuning of machine learning models frequently is doing the hyper parameter optimization that provides the model with
guidance on how it learns and behaves. Another exercise which serves the same purpose is hill training. Gradual
adjustment of hyperparameters and their evaluation according to the respectively reached the essence of the hill climbing
method.
2. Robotics:
In robotics, hill climbing technique turns out to be useful for an artificial agent roaming through a physical environment
where its path is adjusted before arriving at the destination.
3. Network Design:
The tool may be employed for improvement of network forms, processes, and topologies in the telecommunications
industry and computer networks. This approach erases the redundancy thus the efficiency of the networks are increased by
studying and adjusting their configurations. It facilitates better cooperation, efficiency, and the reliability of diverse
communication system.
4. Game playing:
Altough the hill climbing can be optimal in game playing AI by developing the strategies which helps to get the maximum
scores.
5. Natural language processing:
The software assists in adjusting the algorithms to enable the software to be efficient at dealing with the tasks at hand such
as summarizing text, translating languages and recognizing speech. These abilities owing to it as a significant tool for many
applications.
Implementation
Now we will try to maximize the function with the help of the Hill Climbing algorithm: f (x) = -x2 + 5
Code:
1. # Importing the libraries
2. import random
3. import matplotlib.pyplot as plt
4.
5. # Defining the function to maximize
6. def function_target(val):
7. return -val**2 + 5 # A parabola with maximum at x = 0
8.
9. # Visualizing the hill-climbing algorithm
10. def hill_climbing_with_plot(
11. steps_max=1000, step_range=0.1, x_min=-10, x_max=10
12. ):
13. # Starting with some random solution
14. point_current = random.uniform(x_min, x_max)
15. value_current = function_target(point_current)
16.
17. # Tracking the progress for the purpose of visualization
18. history_x = [point_current]
19. history_y = [value_current]
20.
21. for step in range(steps_max):
22. # Generating a neighboring point by adding a small random step
23. point_neighbor = point_current + random.uniform(-step_range, step_range)
24.
25. # Ensuring that the neighbor stays within limits
26. point_neighbor = max(min(point_neighbor, x_max), x_min)
27. value_neighbor = function_target(point_neighbor)
28.
29. # If the neighbor is better, move to it
30. if value_neighbor > value_current:
31. point_current = point_neighbor
32. value_current = value_neighbor
33.
34. # Recording the current best point
35. history_x.append(point_current)
36. history_y.append(value_current)
37.
38. return point_current, value_current, history_x, history_y
39.
40. # Running the algorithm
41. opt_x, opt_y, path_x, path_y = hill_climbing_with_plot()
42.
43. # Getting the final result
44. print(f"Optimal x: {opt_x:.4f}, f(x): {opt_y:.4f}")
45.
46. # Plotting the function and the hill climbing path
47. x_vals = [x / 100.0 for x in range(-1000, 1000)]
48. y_vals = [function_target(x) for x in x_vals]
49.
50. plt.figure(figsize=(10, 6))
51. plt.plot(x_vals, y_vals, label="Target Function: f(x) = -x² + 5", color='blue')
52. plt.plot(path_x, path_y, marker='o', color='red', label='Search Path')
53. plt.title("Hill Climbing Optimization Path")
54. plt.xlabel("x")
55. plt.ylabel("f(x)")
56. plt.legend()
57. plt.grid(True)
58. plt.show()
59. <textarea>
Output:
Optimal x: -0.0001, f(x): 5.0000
This shows the algorithm has found a value of x close to 0, where the function achieves its maximum.
1. Overview of PSO
Particles:
Each particle represents a potential solution in the search space. Particles have:
Each particle keeps track of the best position it has ever visited (its personal best).
Inertia:
To avoid the particles from overshooting the optimal solution, inertia is introduced. It
prevents drastic changes in the velocity and helps particles to explore the search space
effectively.
5. PSO Hyperparameters
6. Advantages of PSO
1. Simplicity:
o PSO is easy to implement and has a minimal set of parameters to tune.
2. Flexible:
o It can be applied to continuous and discrete optimization problems.
o PSO works well in high-dimensional spaces and is suitable for a variety of
optimization tasks.
3. Global Search:
o PSO has a strong ability to avoid local minima due to the swarm's exploration
of the search space.
4. Parallelism:
o Since each particle operates independently, PSO can be easily parallelized for
distributed computation, making it scalable for large optimization problems.
7. Disadvantages of PSO
1. Premature Convergence:
o PSO may converge too early to a suboptimal solution, especially if the
particles get stuck in local optima.
2. Sensitive to Parameter Settings:
o The performance of PSO depends on the settings of the inertia weight www
and the acceleration coefficients c1,c2c_1, c_2c1,c2. Choosing good values
can require trial and error.
3. No Guarantee of Global Optimality:
o As a heuristic method, PSO cannot guarantee finding the global optimum,
particularly in very complex, highly multimodal objective functions.
8. Applications of PSO
1. Engineering Design:
o PSO is used in optimizing parameters in various engineering fields such as
structural design, circuit design, and aerodynamics.
2. Machine Learning:
o Hyperparameter optimization (e.g., tuning neural network weights and
parameters).
o Feature selection for improving model performance.
3. Robotics:
o Path planning and optimization for autonomous vehicles and robots.
4. Signal Processing:
o PSO is used for optimizing filters and signal estimators.
5. Economics and Finance:
o Portfolio optimization, asset management, and risk assessment.
7. Let’s implement a basic example where PSO is used to minimize a simple function
Explanation:
10. Conclusion
In this detailed explanation, we will cover each of these methods, their working principles,
and practical applications.
PSO is inspired by the social behavior of birds flocking or fish schooling, where individuals
adjust their positions based on the experiences of themselves and their neighbors.
Key Features:
Algorithm Steps:
Example:
ACO is inspired by the foraging behavior of ants. Ants find the shortest path from their
colony to a food source by depositing pheromones along the path. The intensity of the
pheromone is used to guide other ants towards the food source, reinforcing the path.
Key Features:
Algorithm Steps:
Example:
Traveling Salesman Problem (TSP): Finding the shortest possible route that visits
each city exactly once and returns to the starting city.
Vehicle Routing Problems (VRP): Optimizing delivery routes for trucks or
distribution systems.
The ABC algorithm mimics the foraging behavior of honeybees. In this approach, scout bees
search the solution space, while employed bees search locally for food sources. The best food
sources are communicated to other bees, who then exploit the best solutions found.
Key Features:
Employed Bees: Search within the local neighborhood for better solutions.
Scout Bees: Explore new regions of the solution space when the local search becomes
stuck.
Food Source: Represents a candidate solution.
Fitness: The quality of a solution (e.g., based on the objective function).
Algorithm Steps:
Example:
The Cuckoo Search algorithm is inspired by the parasitic behavior of cuckoo birds, which
lay their eggs in the nests of other birds. The eggs hatch and replace the original eggs, leading
to the reproduction of the cuckoo's genes. This behavior is mimicked by generating new
candidate solutions and evaluating them.
Key Features:
Algorithm Steps:
Example:
The Firefly Algorithm is inspired by the flashing behavior of fireflies. Fireflies use light to
attract mates, and the intensity of the light correlates with their attractiveness. This principle
is used in the algorithm to guide the swarm toward brighter (better) solutions.
Key Features:
Algorithm Steps:
Example:
1. Engineering Design:
o Shape optimization (e.g., aerodynamics or structural design).
o Resource allocation in manufacturing systems.
2. Machine Learning:
o Hyperparameter optimization in neural networks.
o Feature selection and dimensionality reduction.
3. Robotics:
o Multi-robot coordination for tasks like exploration and path planning.
4. Supply Chain Management:
o Vehicle routing problems, optimizing delivery routes and schedules.
5. Telecommunication:
o Network optimization, such as routing in mobile networks.
Conclusion
-----------------------------------------------------------------------------------------
What is Optimization?
o Definition: Finding the best solution from a set of feasible solutions.
o In AI: Optimization helps AI algorithms to improve their performance by
adjusting parameters or variables to achieve specific goals.
Why Optimization in AI?
o Speed up decision-making
o Improve model accuracy
o Enhance problem-solving capabilities in complex systems
Deterministic Optimization:
o Gradient Descent
o Linear Programming
o Integer Programming
Stochastic Optimization:
o Genetic Algorithms
o Simulated Annealing
o Particle Swarm Optimization (PSO)
o Ant Colony Optimization (ACO)
Hybrid Optimization Methods:
o Combining methods like Genetic Algorithms and Simulated Annealing for
better results.
Overview:
o An iterative method for finding the minimum of a function by moving in the
opposite direction of the gradient.
Applications in AI:
o Training machine learning models (e.g., linear regression, neural networks).
Key Steps:
o Start with an initial guess.
o Update parameters iteratively using the formula:
o Repeat until convergence.
Overview:
o A method to optimize a linear objective function subject to linear equality and
inequality constraints.
Applications in AI:
o Resource allocation, operations research, and decision-making models.
Example:
o Solving supply chain optimization problems.
Overview:
o Inspired by the process of annealing in metallurgy, where materials are heated
and then cooled to find the most stable state.
Applications in AI:
o Solving combinatorial optimization problems (e.g., TSP, job scheduling).
Key Idea:
o Explore the search space probabilistically, accepting worse solutions to escape
local minima.
Slide 8: Particle Swarm Optimization (PSO)
Overview:
o A nature-inspired algorithm mimicking the social behavior of birds or fish.
Key Elements:
o Position: Represents a potential solution.
o Velocity: Controls movement through the solution space.
o pbest & gbest: Best known positions for each particle and the entire swarm.
Applications:
o Continuous function optimization, machine learning model tuning.
Overview:
o Mimics the process of natural selection, involving selection, crossover, and
mutation to evolve solutions.
Applications:
o Feature selection, optimization problems in finance and robotics.
Key Components:
o Selection: Choose best solutions based on fitness.
o Crossover: Combine solutions to create new solutions.
o Mutation: Randomly alter solutions to introduce variety.
Overview:
o Inspired by the foraging behavior of ants, where they find the shortest path by
leaving pheromones.
Applications:
o Combinatorial optimization problems like TSP, VRP.
Key Idea:
o Pheromone updating guides future search paths towards optimal solutions.
Machine Learning:
o Hyperparameter tuning (e.g., optimizing neural networks).
o Feature selection and dimensionality reduction.
Robotics:
o Path planning and control systems.
Operations Research:
o Resource allocation, logistics, and supply chain optimization.
Premature Convergence:
o The algorithm may get stuck in a local optimum and fail to explore better
solutions.
Scalability:
o Optimization becomes difficult for high-dimensional spaces or large datasets.
Parameter Sensitivity:
o Optimization algorithms like PSO or Genetic Algorithms are sensitive to the
choice of parameters (e.g., learning rates, population size).
Quantum Optimization:
o Emerging field where quantum computing is used to solve optimization
problems faster.
Metaheuristics and Machine Learning:
o Hybrid methods combining AI and optimization techniques to solve complex
real-world problems (e.g., optimization of reinforcement learning agents).
Key Takeaways:
o AI optimization techniques play a crucial role in improving decision-making
and problem-solving in AI applications.
o Different techniques like Gradient Descent, PSO, and ACO have distinct
advantages depending on the problem.
o Future trends in optimization involve combining multiple techniques and
leveraging emerging technologies like quantum computing.
Any questions?
o Open the floor for discussion.
This outline gives you a strong framework for building a professional and informative
presentation on AI optimization techniques. You can customize it with visuals,
animations, and real-world examples to make it more engaging. Let me know if you'd
like more details on any specific section or need help with slides!