Does anyone know what these lines of code are doing? Thanks
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
ma=RandChooseN(probs,M); %function probs with the argument m
pa=RandChooseN(probs,M);
xp=ceil(rand(1,M)*(Nt-1));
pop(1:2:popsiz*e,:)=[pop(ma,1:xp(1)) pop(pa,xp(1)+1:Nt)];
pop(2:2:popsize,:)=[pop(pa,1:xp(1)) pop(ma,xp(1)+1:Nt)];
0 commentaires
Réponses (1)
Adam Danz
le 13 Déc 2018
Modifié(e) : Adam Danz
le 13 Déc 2018
"Does anyone know what these lines of code are doing? "
The short answer: no. No, because we can't be sure what RandChooseN() is doing; We don't know the values of probs, M, Nt, pop, popsiz, or e.
However, we can speculate to a certain point.
Assuming probs is a vector of probabilities and M is an integer, and assuming RandChooseN() is this function (<- link), then ma and pa are vectors of random integers chosen randomly with probabilites listed in probs.
ma=RandChooseN(probs,M); %function probs with the argument m
pa=RandChooseN(probs,M);
Along with the assumptions above, if Nt is a scalar (single number), xp is vector of rounded, integers the same size as M. If Nt is a column vector and M is a row vector (or vise-versa) then xp will be a matrix of rounded, integers. Based on the how Nt is used in the next few lines, I'm guessing it's a scalar and xp is a vector.
xp=ceil(rand(1,M)*(Nt-1));
These next lines look questionable. pop is probably a 2D matrix. Data is being put into the odd numered rows of pop and then different data is being put into the even numered rows. I don't know why the odd rows extend to popsiz*e but the even rows only extend to popsize. The data being put into the pop matrix is also taken from the pop matrix, so the data is being reorganized and some of it, overwritten. The random probability integers taken from the first 2 lines of code above, ma and pa, are used to select the rows of pop.
pop(1:2:popsiz*e,:)=[pop(ma,1:xp(1)) pop(pa,xp(1)+1:Nt)];
pop(2:2:popsize,:)=[pop(pa,1:xp(1)) pop(ma,xp(1)+1:Nt)];
There's not enough context to be able to speculate higher level explanations. If I had to throw a blind dart, I'd say that you have a matrix 'pop' and you're randomly choosing rows according to a probability distribution and shuffling those rows. The columns look like they are subsampled as well.
2 commentaires
Adam Danz
le 13 Déc 2018
Here's my recommendations.
1) Step through the code, line by line, and understand each line. This can be done in debug mode (<- link).
2) for each function that you are unfamiliar with, read the documentation. Use the help or doc command. For example,
help round %to see how the round() function works
doc round
3) when you get stuck, come back here and ask a more specific question.
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!