I would like to translate a matlab function into R code. Here is the part of the code I am most confused about:
obj = (Pv*v)'*double(ttv(Xhat,Pv*v,2))*(Pu*u);
ind = 1; iter = 1;
while ind>thr & maxit>iter
oldo = obj(end);
uhat = Pu*double(ttv(Xhat,v,1))'*v;
u = uhat/norm(uhat);
[v,tmp] = eigs(Pv*double(ttv(Xhat,u,3))*Pv,1);
obj = [obj (Pv*v)'*double(ttv(Xhat,Pv*v,2))*(Pu*u)];
ind = abs((obj(end) - oldo)/obj(1));
iter = iter + 1;
end
d = v'*double(ttv(Xhat,u,3))*v;
1) First question is with line 4 oldo = obj(end)
. Can someone explain to me this syntax? (I think that it will end the while loop?) This is also in line 9.
2) Line 7: [v,tmp] = eigs(Pv*double(ttv(Xhat,u,3))*Pv,1);
. I do not understand what [v, tmp]
is. "v" is a previously defined variable, but tmp is not. Can someone explain this data structure?
3) Line 8: obj = [obj (Pv*v)'*double(ttv(Xhat,Pv*v,2))*(Pu*u)];
. I am confused about what operations are occuring within the brackets - e.g., there is a space but no operator between "obj" and "(Pv*v)...". Do the brackets act as some sort of operator here?
FYI, ttv() is a function from Tensor Toolbox. If anyone can help with any of these questions, that would help me greatly. I know this is sort of a vague/multi-part question, but I figured if someone could answer one of these, they could answer them all. Also, if you just explain what these lines of code do in matlab without translating them to R, that would be very helpful, too. The full code is available here: https://github.com/zhengwu/TensorNetwork_PCA/blob/master/hopca_popNet_new.m
Thank you for your help!