How to use PSO (Particle swarm optimization) to optimize objective function containing two terms one of them kmeans clustering?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
Hi
I used PSO before to optimize an objective function.Now I have an objective(fitness) function containing two terms; one of them described by k-means clustering ..Euclidean distance?
Accepted Answer
Walter Roberson
on 19 Jan 2019
You have to pass a function handle as the objective function, but it does not have to be an anonymous function. You can pass the handle to a function that does extensive computation based on the inputs. The only requirement is that the output has to be a scalar.
If you are trying to minimize two distinct things simultaneously then you either need to decide their relative weighting to combine them into a scalar, or else you need to use gamultiobj() to find pareto fronts.
14 Comments
I do not understand that image?
You saw what is written in??
If you read it
You will see the objective function phi
the first term I made and I want to know how to implement the second term??
If any information you need I will give
This is what your image looks like at my end:

No phi, no first or second term.
that looks like weighted Euclidean not plain Euclidean .
Yes
Now ,how to make as code in MATLAB?
I have the Wi matrix so how to implement this weighted Euclidean distance?
To get results like these in the images

Walter Roberson
on 21 Jan 2019
Edited: Walter Roberson
on 21 Jan 2019
Use a nested for loop if you need to.
total = 0;
for j = 1 : K
for i = 1 : N2
total = total + sum(sum((W(i) * bsxfun(@minus, V(mu(j)).^i, mu(j)))).^2));
end
end
Here I assume that V_(mu_j) must indicate a function named V that is being passed a scalar mu(j) and is returning a vector or array -- if V_mu_j is a scalar then it makes less sense to talk about a Euclidean distance. If mu(j) represents a vector or array, or Wi is a vector or array, the code might need to be revised. If we had information about the relative dimensions we might potentially be able to write much more compact code.
Wi : is vector
See the attached for more
information
informationDear Walter Roberson,
Is there is compact code after the description in the last two images?
More Answers (0)
Categories
Find more on Particle Swarm in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)



