/** * Takes the dot product of the regular, non-averaged, Perceptron weight vector with the * given vector, using the hard coded default weight. * * @param exampleFeatures The example's array of feature indices. * @param exampleValues The example's array of feature values. * @return The computed dot product. **/ public double simpleDot(int[] exampleFeatures, double[] exampleValues) { return super.dot(exampleFeatures, exampleValues, defaultWeight); }
/** * Computes the score for the specified example vector which will be thresholded to make the * binary classification. * * @param exampleFeatures The example's array of feature indices * @param exampleValues The example's array of feature values * @return The score for the given example vector. **/ public double score(int[] exampleFeatures, double[] exampleValues) { return weightVector.dot(exampleFeatures, exampleValues, initialWeight) + bias; }
/** * Takes the dot product of this <code>SparseWeightVector</code> with the argument vector, using * the hard coded default weight. * * @param exampleFeatures The example's feature indices. * @param exampleValues The example's feature values. * @return The computed dot product. **/ public double dot(int[] exampleFeatures, double[] exampleValues) { return dot(exampleFeatures, exampleValues, defaultWeight); }
/** * Takes the dot product of this <code>BiasedWeightVector</code> with the argument vector, using * the specified default weight when one is not yet present in this vector. * * @param exampleFeatures The example's array of feature indices * @param exampleValues The example's array of feature values * @param defaultW The default weight. * @return The computed dot product. **/ public double dot(int[] exampleFeatures, double[] exampleValues, double defaultW) { return super.dot(exampleFeatures, exampleValues, defaultW) + bias; }
/** * Simply computes the dot product of the weight vector and the example * * @param exampleFeatures The example's array of feature indices. * @param exampleValues The example's array of feature values. * @return The computed real value. **/ public double realValue(int[] exampleFeatures, double[] exampleValues) { return weightVector.dot(exampleFeatures, exampleValues) + bias; }
/** * Takes the dot product of the regular, non-averaged, Perceptron weight vector with the * given vector, using the specified default weight when a feature is not yet present in * this vector. * * @param exampleFeatures The example's array of feature indices. * @param exampleValues The example's array of feature values. * @param defaultW An initial weight for new features. * @return The computed dot product. **/ public double simpleDot(int[] exampleFeatures, double[] exampleValues, double defaultW) { return super.dot(exampleFeatures, exampleValues, defaultW); }
/** * Trains the learning algorithm given an object as an example. * * @param exampleFeatures The example's array of feature indices. * @param exampleValues The example's array of feature values. * @param exampleLabels The example's label(s). * @param labelValues The labels' values. **/ public void learn(int[] exampleFeatures, double[] exampleValues, int[] exampleLabels, double[] labelValues) { assert exampleLabels.length == 1 : "Example must have a single label."; double labelValue = labelValues[0]; double multiplier = learningRate * (labelValue - weightVector.dot(exampleFeatures, exampleValues) - bias); weightVector.scaledAdd(exampleFeatures, exampleValues, multiplier); bias += multiplier; }
double m = y * (weightVector.dot(exampleFeatures, exampleValues) + bias);