List of usage examples for weka.core AlgVector AlgVector
public AlgVector(Instance instance) throws Exception
From source file:moa.reduction.bayes.OFSGDAttributeEval.java
License:Open Source License
public void updateEvaluator(Instance inst) throws Exception { if (weights == null) { weights = new AlgVector(new double[inst.numAttributes() - 1]); for (int i = 0; i < weights.numElements(); i++) weights.setElement(i, 0);/*from w w w . j a va2 s . c o m*/ } double[] rawx = Arrays.copyOfRange(inst.toDoubleArray(), 0, inst.numAttributes() - 1); AlgVector x = new AlgVector(rawx); double pred = weights.dotMultiply(x); if (pred * inst.classValue() <= 1) { x.scalarMultiply(eta * inst.classValue()); weights = weights.add(x); weights.scalarMultiply(Math.min(1.0, 1 / (Math.sqrt(lambda) * weights.norm()))); int counts = 0; Pair[] array = new Pair[weights.numElements()]; for (int i = 0; i < weights.numElements(); i++) { array[i] = new Pair(i, weights.getElement(i)); if (weights.getElement(i) != 0) counts++; } // Truncate if (counts > numFeatures) { Arrays.sort(array); for (int i = numFeatures + 1; i < array.length; i++) weights.setElement(array[i].index, 0); } } updated = true; }