public int[][] prepClean() { final int L = 2; boolean[][] used = new boolean[W][L]; int[][] map = new int[W][L]; int[] cts = new int[L]; for (int j = 0; j < x.length; j++) { for (int l = 0; l < L; l++) { for (int w : x[j][l].keySet()) { if (!used[w][l]) { used[w][l] = true; map[w][l] = cts[l]++; } } } } System.err.println("Cts: " + Arrays.toString(cts)); return map; }
public int[][] prepClean() { final int L = 2; boolean[][] used = new boolean[W][L]; int[][] map = new int[W][L]; int[] cts = new int[L]; for (int j = 0; j < x.length; j++) { for (int l = 0; l < L; l++) { for (int w : x[j][l].keySet()) { if (!used[w][l]) { used[w][l] = true; map[w][l] = cts[l]++; } } } } System.err.println("Cts: " + Arrays.toString(cts)); return map; }
@Override public double[] toDoubleArray() { double[] d = new double[n]; if (defaultValue != 0) { Arrays.fill(d, defaultValue); } for (int i : this.keySet()) { d[i] = this.get(i); } return d; }
public double[] calculateSalience(Vector<Integer> termVec, int l) { double[] salience = new double[J]; for (int j = 0; j < J; j++) { final double xDocLength = x[j][l].sum().doubleValue(); for (int w : x[j][l].keySet()) { if (ctTotal[l][w] != 0) { salience[j] += termVec.doubleValue(w) * x[j][l].doubleValue(w) / ctTotal[l][w]; } } if (xDocLength != 0.0) { salience[j] /= xDocLength; } } // print(topKwords(salience, 10)); return salience; } //
@Override public Vector<Double> simVecSource(Vector<Integer> termVec) { final double[] predicted = new double[W]; final double[] salience = calculateSalience(termVec, 0); for(int j = 0; j < J; j++) { for(int w : x[j][1].keySet()) { if((double)ctTotal[1][w] - alpha * x[j][1].get(w) != 0.0) { predicted[w] += salience[j] * x[j][1].get(w) / ((double)ctTotal[1][w] - alpha * x[j][1].get(w)); } } } return RealVector.make(predicted); // return RealVector.make(salience); }
for (int w : x[j][1].keySet()) { sim[w] += cosSim * x[j][1].get(w) / sum;
public BetaLMImpl(SparseIntArray[][] x, int W) { this.x = x; this.W = W; this.mu = new SparseRealArray(W); this.mu_f = new SparseRealArray(W); this.sumMu2 = initMu(x, this.W); if (method == Method.DF_DICE || method == Method.DF_JACCARD) { df = null; this.dfSp = new SparseRealArray(W); for (int j = 0; j < x.length; j++) { for (int w : x[j][0].keySet()) { dfSp.inc(w); } } for (int w = 0; w < this.W; w++) { dfSp.divide(w, x.length); } } else { df = null; dfSp = null; } }
public BetaLMImpl(File data) throws IOException { final ParallelReader pr = ParallelReader.fromFile(data); this.W = pr.W(); this.x = pr.x; this.mu = new RealVector(this.W); this.mu_f = new RealVector(this.W); this.sumMu2 = initMu(x, this.W); if (method == Method.DF_DICE || method == Method.DF_JACCARD) { df = new RealVector(this.W); this.dfSp = null; for (int j = 0; j < x.length; j++) { for (int w : x[j][0].keySet()) { df.add(w, 1); } } for (int w = 0; w < this.W; w++) { df.divide(w,x.length); } } else { df = null; dfSp = null; } }