loss matrix calculation