/** * Decide if the dense vector contains features which are not covered by the * dense vector * * @param fv * @return */ public boolean needAllocateSpace(DenseVector dv) { boolean ret = (dv.getVectorLength() >= u.length); return ret; }
public int getWeightVectorLength(){ return super.getVectorLength(); }
/** * Return the dot product of a dense feature vector and the dense vector * itself * * @param df * @return */ public double dotProduct(DenseVector df) { double res = 0.0; int l = df.getVectorLength(); if (u.length < l) { l = u.length; } for (int i = 0; i < l; i++) { res += u[i] * df.u[i]; } return res; }
/** * Add a dense vector back into the dense vector itself * <p> * * w = w + alpha * dv * * @param dv * the dense vector * @param alpha * the scalar */ public synchronized void addDenseVector(DenseVector dv, double alpha) { if (this.isExtendable() && this.needAllocateSpace(dv)) { this.allocateSpace(dv.getVectorLength()); } int n = dv.getVectorLength(); for (int i = 0; i < n; i++) { u[i] += alpha * dv.u[i]; } }