Solved

Positions of Selected Individuals different from thier original position

Posted on 2013-06-07
12
275 Views
Last Modified: 2013-11-25
Am trying to plot the selected individual in This Code and the code for selecting the  top individuals in the population is this:
top_x  = pop(b(1:options.topSize),:)

Open in new window

The code for Generating the initial population is This:
M = 50;   % population size
n = 2;
pop = -50 + 100.*rand(M,n);

Open in new window

. This is done in a for loop. See Here for the entire code

but anytime i look at the plot of the initial population and the selected population, i.e plot for pop and top_x, they look different. The position of the selected ones are different from their position in the initial population. Why is this happening. The concern code is in ID: 39196865.

The plot are outside the loop.

The code for the two plots are here:
figure;
scatter(pop(:,1), pop(:,2), 'x'); and 

figure;
scatter(top_x(:,1),top_x(:,2), 'x');

Open in new window

0
Comment
Question by:wish_C
  • 6
  • 4
12 Comments
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 39229927
You sort eval, but not pop. So it looks like you rearrange the values without rearranging the initial object. This would mean you would be scrambling the data.

Does that seem correct?
0
 

Author Comment

by:wish_C
ID: 39230113
Yes you are right, TommySzalapski, Now am able to correct the position issue, but the selected individuals are not correct. I need to select points that have best fitness values, but the above code is just selecting points randomly. How can i select points with the best fitness values according to the fitness evaluation.
0
 

Author Comment

by:wish_C
ID: 39232023
Best Fitness values are selected base on the eval. That is why i am sorting eval in descending order and select the top 25% as the best individuals. Any help please?
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 39232924
Note that sort can optionally return the order it sorted by so you can use that for the other array.

Try something like this:
[SortIndex, b] = sort(eval, 'descend');
pop = pop(SortIndex)
0
 

Author Comment

by:wish_C
ID: 39232964
I have modified This part of the code to include your suggestion:

% Criteria for selecting top 'topSize' individuals based on fitness
% values(eval)
 if strcmp(options.optmType, 'min')
   [void, b] = sort(eval, 'descend');  % maximising
 else
   [void, b] = sort(eval, 'ascend');   % minimising
 end
 pop = pop(void);
 top_x  = pop(b(1:options.topSize),:); % select top individuals
 optm_x = pop(b(1),:);                 % save optimal parameter
 fv     = eval(b(1));                  % save optimal func. value

Open in new window


but it gives the the following error:
Subscript indices must either be real positive integers or logicals.

Error in ==> Imp
 pop = pop(void);

Its seems i am indexing into a matrix or vector using a set of indices that include a number that is not a positive integer or a logical value. when i use

void = round(void)
 pop = pop(void)

Open in new window


It gives me another error Thus:
??? Index exceeds matrix dimensions.

Error in ==> Imp at
 pop = pop(void);

Any idea to solve this?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 37

Expert Comment

by:TommySzalapski
ID: 39235281
Sorry. I tried to post a comment, but it must not have gotten through.

What are the values of pop, eval, and void? (set M to something low like 10 please).

You may need to just use a for loop to swap all the values around.
0
 

Author Comment

by:wish_C
ID: 39236174
Actually i am using a for loop as you can see in the whole code here Here. I have fix the position issue, the problem is i have calculated the mean and covariance of the top_x (top 25% selected) and sample them again with the same size M as shown here:
 pop = mvnrnd(mu,Sigma,M)

Open in new window


Now i want to plot the result of this sample. Any idea?
0
 

Accepted Solution

by:
wish_C earned 0 total points
ID: 39237852
I have managed to do it. Thanks so much for your help, especially TommySzalapski, you really kind.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 39238084
Did my comments not help at all? You can accept multiple comments if something I did helped you figure it out.

Sorry that line didn't work, I must have a different version of MATLAB.
0
 

Author Closing Comment

by:wish_C
ID: 39251043
I solve the problem by myself.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count11 challenge 6 47
Magic Software info 18 102
wordcount challenge 11 75
silent install of security banner via msiexec command 4 48
A short article about problems I had with the new location API and permissions in Marshmallow
Article by: Nicole
This is a research brief on the potential colonization of humans on Mars.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now