Buggy code:
public abstract class VotedPerceptron extends WeightLearningApplication { private static final Logger log = LoggerFactory . getLogger ( VotedPerceptron . class ) ; public static final String CONFIG_PREFIX = "votedperceptron" ; public static final String AUGMENT_LOSS_KEY = ( VotedPerceptron . CONFIG_PREFIX ) + ".augmentloss" ; public static final boolean AUGMENT_LOSS_DEFAULT = false ; public static final String L2_REGULARIZATION_KEY = ( VotedPerceptron . CONFIG_PREFIX ) + ".l2regularization" ; public static final double L2_REGULARIZATION_DEFAULT = 0.0 ; public static final String L1_REGULARIZATION_KEY = ( VotedPerceptron . CONFIG_PREFIX ) + ".l1regularization" ; public static final double L1_REGULARIZATION_DEFAULT = 0.0 ; public static final String STEP_SIZE_KEY = ( VotedPerceptron . CONFIG_PREFIX ) + ".stepsize" ; public static final double STEP_SIZE_DEFAULT = 1.0 ; public static final String STEP_SCHEDULE_KEY = ( VotedPerceptron . CONFIG_PREFIX ) + ".schedule" ; public static final boolean STEP_SCHEDULE_DEFAULT = true ; public static final String SCALE_GRADIENT_KEY = ( VotedPerceptron . CONFIG_PREFIX ) + ".scalegradient" ; public static final boolean SCALE_GRADIENT_DEFAULT = false ; public static final String AVERAGE_STEPS_KEY = ( VotedPerceptron . CONFIG_PREFIX ) + ".averagesteps" ; public static final boolean AVERAGE_STEPS_DEFAULT = true ; public static final String NUM_STEPS_KEY = ( VotedPerceptron . CONFIG_PREFIX ) + ".numsteps" ; public static final int NUM_STEPS_DEFAULT = 25 ; protected double [ ] numGroundings ; private double loss ; private final double stepSize ; private final int numSteps ; private final double l2Regularization ; private final double l1Regularization ; private final boolean augmentLoss ; private final boolean scheduleStepSize ; private final boolean scaleGradient ; private final boolean averageSteps ; protected boolean toStop = false ; public VotedPerceptron ( Model model , Database rvDB , Database observedDB , ConfigBundle config ) { } private void addLossAugmentedKernels ( ) { } private double getStepSize ( int iter ) { } @ Override protected void doLearn ( ) { double [ ] avgWeights ; double [ ] truthIncompatibility ; double [ ] expectedIncompatibility ; double [ ] scalingFactor ; avgWeights = new double [ kernels . size ( ) ] ; truthIncompatibility = computeObservedIncomp ( ) ; if ( augmentLoss ) addLossAugmentedKernels ( ) ; for ( Map . Entry < RandomVariableAtom , ObservedAtom > e : trainingMap . getTrainingMap ( ) . entrySet ( ) ) e . getKey ( ) . setValue ( 0.0 ) ; for ( RandomVariableAtom atom : trainingMap . getLatentVariables ( ) ) atom . setValue ( 0.0 ) ; for ( int step = 0 ; step < ( numSteps ) ; step ++ ) { VotedPerceptron . log . debug ( "Starting<seq2seq4repair_space>iter<seq2seq4repair_space>{}" , ( step + 1 ) ) ; expectedIncompatibility = computeExpectedIncomp ( ) ; scalingFactor = computeScalingFactor ( ) ; loss = 0 ; for ( int i = 0 ; i < ( kernels . size ( ) ) ; i ++ ) { double currentStep = ( ( ( ( expectedIncompatibility [ i ] ) - ( truthIncompatibility [ i ] ) ) - ( ( l2Regularization ) * ( kernels . get ( i ) . getWeight ( ) . getWeight ( ) ) ) ) - ( l1Regularization ) ) // ( scalingFactor [ i ] ) ; <START_BUG> loss += ( kernels . get ( i ) . getWeight ( ) . getWeight ( ) ) * ( ( expectedIncompatibility [ i ] ) - ( truthIncompatibility [ i ] ) ) ; <END_BUG> currentStep *= getStepSize ( step ) ; VotedPerceptron . log . debug ( "Step<seq2seq4repair_space>of<seq2seq4repair_space>{}<seq2seq4repair_space>for<seq2seq4repair_space>kernel<seq2seq4repair_space>{}" , currentStep , kernels . get ( i ) ) ; VotedPerceptron . log . debug ( "<seq2seq4repair_space>---<seq2seq4repair_space>Expected<seq2seq4repair_space>incomp.:<seq2seq4repair_space>{},<seq2seq4repair_space>Truth<seq2seq4repair_space>incomp.:<seq2seq4repair_space>{}" , expectedIncompatibility [ i ] , truthIncompatibility [ i ] ) ; double weight = ( kernels . get ( i ) . getWeight ( ) . getWeight ( ) ) + currentStep ; weight = Math . max ( weight , 0.0 ) ; avgWeights [ i ] += weight ; kernels . get ( i ) . setWeight ( new PositiveWeight ( weight ) ) ; } reasoner . changedGroundKernelWeights ( ) ; setChanged ( ) ; notifyObservers ( new VotedPerceptron . IntermidateState ( step , numSteps ) ) ; if ( toStop ) { break ; } } if ( averageSteps ) { for ( int i = 0 ; i < ( kernels . size ( ) ) ; i ++ ) { kernels . get ( i ) . setWeight ( new PositiveWeight ( ( ( avgWeights [ i ] ) // ( numSteps ) ) ) ) ; } } if ( augmentLoss ) { List < LossAugmentingGroundKernel > lossKernels = new ArrayList < LossAugmentingGroundKernel > ( ) ; for ( LossAugmentingGroundKernel k : Iterables . filter ( reasoner . getGroundKernels ( ) , LossAugmentingGroundKernel . class ) ) lossKernels . add ( k ) ; for ( LossAugmentingGroundKernel k : lossKernels ) reasoner . removeGroundKernel ( k ) ; lossKernels = new ArrayList < LossAugmentingGroundKernel > ( ) ; } } protected double [ ] computeObservedIncomp ( ) { } protected abstract double [ ] computeExpectedIncomp ( ) { } protected double [ ] computeScalingFactor ( ) { } public void stop ( ) { } public double getLoss ( ) { } public class IntermidateState { public final int step ; public final int maxStep ; public IntermidateState ( int currStep , int numSteps ) { } } }

Fix:
loss += ( kernels . get ( i ) . getWeight ( ) . getWeight ( ) ) * ( ( truthIncompatibility [ i ] ) - ( expectedIncompatibility [ i ] ) ) ;