added loss matrix and matrix dimensions