0

A pseudocode for the data split implementation:
inds= 1...n; // divide randomly to N slots
for k=1...N n(k)= round(n/(N-k+1)); // size of this chunk
n= n-n(k); // number of samples left to divide later…
slotInds(k)= chooseNfromSet(inds, n(k)); // chooses n(k) samples from inds!
inds= setdifference(inds, slotInds(k)); // samples left to divide later…
end
assert: sum(k=1...5, n(k)) == N // this should hold true now!

chooseNfromSet(inds,n) ==  
    randsample(inds,n) % in matlab  
#

My response to the pseudocode above in Matlab is:

inds=1:n;
    for k=1:N
        n(k)= round(n/(N-k+1));   
        n= n-n(k);  
        slotInds(k)= randsample(inds,n); 
        inds= setdifference(inds, slotInds(k)); 
    end 
#

However there is error

In an assignment  A(:) = B, the number of elements in A and B must be the same.

and i cant understand the last line of pseudocode

assert: sum(k=1...5, n(k)) == N
  • At least for the assert, it is saying the sum of the elements of K (which contains the numbers 1 through 5) and the elements in the array n in the indices from 1 to 5 are equal to whatever integer N is. For the first part of your question, is there any code you are leaving out from what you have shown here? – lmcphers Dec 11 '15 at 22:16
  • X= [ones(n,1),data(:,1:(end-1))]; global X; y= data(:,end); global y; m= size(X,2); % number of prediction features (wine quality not counted!) Iin= randsample(I0,round(n*4/5)); % just one teaching set... Iout= setdiff(I0,Iin); f= @(beta)(g(beta,Iin)); % a function of one argument beta to be minimized! beta0= zeros(m,1); #############this was for one set to generate insample and out sample error but replacing it with for loop with 5 iteration to generate new in sample and out sample error – user3023871 Dec 11 '15 at 22:21
  • Iin= randsample(I0,round(n*4/5)) is insample error and Iout= setdiff(I0,Iin); is out sample error for one teaching set. The function is same f= @(beta)(g(beta,Iin)); – user3023871 Dec 11 '15 at 22:27
  • In the line `slotInds(k)=randsample(inds,n);` the right-hand-side is an `n`-length vector, which you are trying to assign to a single array element, `slotInds(k)`. This is exactly what your error is trying to tell you. – Andras Deak -- Слава Україні Dec 11 '15 at 23:28

0 Answers0