Program: 64406
Project: 64406
Buggy source:
/** 
 * Trains the classifier with the given instance.
 * @param instance    the new training instance to include in the model
 */
@Override public void trainOnInstanceImpl(Instance instance){
  if (m_weights == null) {
    m_weights=new DoubleVector();
    m_gradients=new DoubleVector();
    m_velocity=new DoubleVector();
    m_weights.setValue(instance.numAttributes(),0);
  }
  if (instance.classIsMissing()) {
    return;
  }
  double z=dotProd(instance,m_weights,instance.classIndex()) + m_bias;
  double y;
  double yhat;
  double dldz;
  if (instance.classAttribute().isNominal()) {
    y=(instance.classValue() == 0) ? 0 : 1;
    if (m_loss == LOGLOSS) {
      yhat=1.0 / (1.0 + Math.exp(-z));
      dldz=(yhat - y) * (yhat * (1.0 - yhat));
    }
 else {
      y=y * 2 - 1;
      yhat=z > 0.0 ? 1.0 : -1.0;
      if (y * z < 1.0) {
        dldz=-y;
      }
 else {
        dldz=0;
      }
    }
  }
 else {
    y=instance.classValue();
    yhat=z;
    dldz=z - y;
  }
  for (int i=0; i < m_weights.numValues(); i++) {
    m_gradients.setValue(i,(m_lambda / m_t) * m_weights.getValue(i));
  }
  int n=instance.numValues();
  for (int i=0; i < n; i++) {
    m_gradients.addToValue(instance.index(i),instance.valueSparse(i) * dldz);
  }
  double biasGradient=dldz;
  m_biasVelocity+=biasGradient * biasGradient;
  m_bias-=(m_learningRate / (Math.sqrt(m_biasVelocity) + m_epsilon)) * biasGradient;
  for (int i=0; i < m_weights.numValues(); i++) {
    double g=m_gradients.getValue(i);
    m_velocity.addToValue(i,g * g);
    m_weights.addToValue(i,-(m_learningRate / (Math.sqrt(m_velocity.getValue(i)) + m_epsilon)) * g);
  }
  m_t+=1.0;
}

Fixed version (ground truth):
/** 
 * Trains the classifier with the given instance.
 * @param instance    the new training instance to include in the model
 */
@Override public void trainOnInstanceImpl(Instance instance){
  if (m_weights == null) {
    m_weights=new DoubleVector();
    m_gradients=new DoubleVector();
    m_velocity=new DoubleVector();
    m_weights.setValue(instance.numAttributes(),0);
  }
  if (instance.classIsMissing()) {
    return;
  }
  double z=dotProd(instance,m_weights,instance.classIndex()) + m_bias;
  double y;
  double dldz;
  if (instance.classAttribute().isNominal()) {
    y=(instance.classValue() == 0) ? 0 : 1;
    if (m_loss == LOGLOSS) {
      double yhat=1.0 / (1.0 + Math.exp(-z));
      dldz=(yhat - y);
    }
 else {
      y=y * 2 - 1;
      if (y * z < 1.0) {
        dldz=-y;
      }
 else {
        dldz=0;
      }
    }
  }
 else {
    y=instance.classValue();
    dldz=z - y;
  }
  for (int i=0; i < m_weights.numValues(); i++) {
    m_gradients.setValue(i,(m_lambda / m_t) * m_weights.getValue(i));
  }
  int n=instance.numValues();
  for (int i=0; i < n; i++) {
    m_gradients.addToValue(instance.index(i),instance.valueSparse(i) * dldz);
  }
  double biasGradient=dldz;
  m_biasVelocity+=biasGradient * biasGradient;
  m_bias-=(m_learningRate / (Math.sqrt(m_biasVelocity) + m_epsilon)) * biasGradient;
  for (int i=0; i < m_weights.numValues(); i++) {
    double g=m_gradients.getValue(i);
    m_velocity.addToValue(i,g * g);
    m_weights.addToValue(i,-(m_learningRate / (Math.sqrt(m_velocity.getValue(i)) + m_epsilon)) * g);
  }
  m_t+=1.0;
}