If Y is rank difficient, the original formular has to change because it was derived based on the assuption YY^T is not signular. As you said, this only possiblelly happens when measurement errors are ignored. In other words, we can always add very small measurement errors to avoid such singularity. You can always assume Wn = eI with a sufficiently small e to make the code works.
Hope this helps.
Dear Yi Cao, is there a way to make the code work for the case when Y has less than ny independent columns or generally if rank(Y) < ny? This situation occurs for example if the implementation error is disregarded and if nd < ny. In the downward tree it may cause a singular Y2(s,s). From my understanding pruning could be simply omitted and branching could be done based on another criterion (smallest element in diag(G2(s,s))). I made some attempts to modify the code but couldn't make it work. It would be very helpful if you could give advice. Thank you very much in advance!