added loss function by layer