Program: 3451
Project: 3451
Buggy source:
/** 
 * Generic scoring function
 * @param labels            the labels to score
 * @param lossFunction      the loss function to use
 * @param z                 the output function
 * @param l2                the l2 coefficient
 * @param useRegularization whether to use regularization
 * @return the score for the given parameters
 */
public static double score(INDArray labels,LossFunction lossFunction,INDArray z,double l2,boolean useRegularization){
  double ret=0.0;
  double reg=0.5 * l2;
  if (!Arrays.equals(labels.shape(),z.shape()))   throw new IllegalArgumentException("String_Node_Str");
switch (lossFunction) {
case RECONSTRUCTION_CROSSENTROPY:
    INDArray xEntLogZ2=log(z);
  INDArray xEntOneMinusLabelsOut2=labels.rsub(1);
INDArray xEntOneMinusLogOneMinusZ2=log(z).rsubi(1);
ret=labels.mul(xEntLogZ2).add(xEntOneMinusLabelsOut2).muli(xEntOneMinusLogOneMinusZ2).sum(1).mean(Integer.MAX_VALUE).getDouble(0);
break;
case MCXENT:
INDArray columnSums=labels.mul(log(z));
ret=columnSums.mean(1).mean(Integer.MAX_VALUE).getDouble(0);
break;
case XENT:
INDArray xEntLogZ=log(z);
INDArray xEntOneMinusLabelsOut=labels.rsub(1);
INDArray xEntOneMinusLogOneMinusZ=log(z).rsubi(1);
ret=labels.mul(xEntLogZ).add(xEntOneMinusLabelsOut).muli(xEntOneMinusLogOneMinusZ).sum(1).sum(Integer.MAX_VALUE).getDouble(0);
break;
case RMSE_XENT:
INDArray rmseXentDiff=labels.sub(z);
INDArray squaredrmseXentDiff=pow(rmseXentDiff,2.0);
INDArray sqrt=sqrt(squaredrmseXentDiff);
ret=sqrt.sum(1).mean(Integer.MAX_VALUE).getDouble(0);
break;
case MSE:
INDArray mseDelta=labels.sub(z);
ret=0.5 * pow(mseDelta,2).sum(1).sum(Integer.MAX_VALUE).getDouble(0);
break;
case EXPLL:
INDArray expLLLogZ=log(z);
ret=z.sub(labels.mul(expLLLogZ)).sum(1).sum(Integer.MAX_VALUE).getDouble(0);
break;
case SQUARED_LOSS:
ret=pow(labels.sub(z),2).sum(1).sum(Integer.MAX_VALUE).getDouble(0);
break;
case NEGATIVELOGLIKELIHOOD:
ret=-Nd4j.mean(Nd4j.sum(labels.mul(log(z)).addi(labels.rsub(1).muli(log(z.rsub(1)))),1)).getDouble(0);
break;
}
if (useRegularization) ret+=reg;
ret/=(double)labels.rows();
return ret;
}

Fixed version (ground truth):
/** 
 * Generic scoring function
 * @param labels            the labels to score
 * @param lossFunction      the loss function to use
 * @param z                 the output function
 * @param l2                the l2 coefficient
 * @param useRegularization whether to use regularization
 * @return the score for the given parameters
 */
public static double score(INDArray labels,LossFunction lossFunction,INDArray z,double l2,boolean useRegularization){
  double ret=0.0;
  double reg=0.5 * l2;
  if (!Arrays.equals(labels.shape(),z.shape()))   throw new IllegalArgumentException("String_Node_Str");
switch (lossFunction) {
case RECONSTRUCTION_CROSSENTROPY:
    INDArray xEntLogZ2=log(z);
  INDArray xEntOneMinusLabelsOut2=labels.rsub(1);
INDArray xEntOneMinusLogOneMinusZ2=log(z).rsubi(1);
ret=labels.mul(xEntLogZ2).add(xEntOneMinusLabelsOut2).muli(xEntOneMinusLogOneMinusZ2).sum(1).mean(Integer.MAX_VALUE).getDouble(0);
break;
case MCXENT:
INDArray columnSums=labels.mul(log(z));
ret=columnSums.mean(1).mean(Integer.MAX_VALUE).getDouble(0);
break;
case XENT:
INDArray xEntLogZ=log(z);
INDArray xEntOneMinusLabelsOut=labels.rsub(1);
INDArray xEntOneMinusLogOneMinusZ=log(z).rsubi(1);
ret=labels.mul(xEntLogZ).add(xEntOneMinusLabelsOut).muli(xEntOneMinusLogOneMinusZ).sum(1).sum(Integer.MAX_VALUE).getDouble(0);
break;
case RMSE_XENT:
INDArray rmseXentDiff=labels.sub(z);
INDArray squaredrmseXentDiff=pow(rmseXentDiff,2.0);
INDArray sqrt=sqrt(squaredrmseXentDiff);
ret=sqrt.sum(1).sum(Integer.MAX_VALUE).getDouble(0);
break;
case MSE:
INDArray mseDelta=labels.sub(z);
ret=0.5 * pow(mseDelta,2).sum(1).sum(Integer.MAX_VALUE).getDouble(0);
break;
case EXPLL:
INDArray expLLLogZ=log(z);
ret=z.sub(labels.mul(expLLLogZ)).sum(1).sum(Integer.MAX_VALUE).getDouble(0);
break;
case SQUARED_LOSS:
ret=pow(labels.sub(z),2).sum(1).sum(Integer.MAX_VALUE).getDouble(0);
break;
case NEGATIVELOGLIKELIHOOD:
ret=-Nd4j.mean(Nd4j.sum(labels.mul(log(z)).addi(labels.rsub(1).muli(log(z.rsub(1)))),1)).getDouble(0);
break;
}
if (useRegularization) ret+=reg;
ret/=(double)labels.rows();
return ret;
}