code for building the matrix of voids and determinating the optim lambda thresold