private void prepareDayUserWords() { final MLSparse arr = (MLSparse) this.content.get(mainMatrixKey); final Double[] realVals = arr.exportReal(); final int[] rows = arr.getIR(); final int[] cols = arr.getIC(); if(voc == null){ this.nwords = arr.getN(); } else{ this.nwords = this.voc.size(); } this.nusers = arr.getM() / this.ndays; dayWords = new ArrayList<Matrix>(); for (int i = 0; i < ndays; i++) { final Matrix userWord = SparseMatrixFactoryMTJ.INSTANCE.createMatrix(this.nwords, this.nusers); dayWords.add(userWord); } for (int i = 0; i < rows.length; i++) { if (filter && !this.keepIndex.contains(cols[i])) continue; int wordIndex = cols[i]; if(this.indexToVoc!=null){ wordIndex = this.indexToVoc.get(wordIndex); } final int dayIndex = rows[i] / this.nusers; final int userIndex = rows[i] - (dayIndex * this.nusers); dayWords.get(dayIndex).setElement(wordIndex, userIndex, realVals[i]); } }
@Override public String contentToString() { StringBuffer sb = new StringBuffer(); sb.append(name + " = \n"); for (IndexMN i : indexSet) { sb.append("\t("); sb.append(i.m + "," + i.n); sb.append(")"); sb.append("\t" + getReal(i.m, i.n)); if (isComplex()) { sb.append("+" + getImaginary(i.m, i.n)); } sb.append("\n"); } return sb.toString(); }
public Double buldFromBytes(byte[] bytes) { if ( bytes.length != getBytesAllocated() ) { throw new IllegalArgumentException( "To build from byte array I need array of size: " + getBytesAllocated() ); } return ByteBuffer.wrap( bytes ).getDouble(); } public byte[] getByteArray(Double value)
break; case MLArray.mxSPARSE_CLASS: MLSparse sparse = new MLSparse(name, dims, attributes, nzmax); int[] jc = tag.readToIntArray(); if (sparse.isComplex()) { for (int column = 0; column < sparse.getN(); column++) { while (count < jc[column + 1]) { sparse.setReal(ad1[count], ir[count], column); count++; for (int column = 0; column < sparse.getN(); column++) { while (count < jc[column + 1]) { sparse.setImaginary(ad2[count], ir[count], column); count++; double[] ad1 = tag.readToDoubleArray(); int count = 0; for (int column = 0; column < sparse.getN(); column++) { while (count < jc[column + 1]) { sparse.set(ad1[count], ir[count], column); count++;
ai = ((MLSparse)array).getIR(); for ( int i : ai ) ai = ((MLSparse)array).getJC(); for ( int i : ai ) bufferDOS = new DataOutputStream(buffer); Double[] ad = ((MLSparse)array).exportReal(); ad = ((MLSparse)array).exportImaginary(); for ( int i = 0; i < ad.length; i++ )
double[][] referenceImaginary = new double[][]{{0.0, 0.0}, {2.0, 0.0}, {0.0, 6.0}}; MLSparse mlSparse = new MLSparse(name, new int[]{3, 2}, MLArray.mtFLAG_COMPLEX, 5); mlSparse.setReal(1.3, 0, 0); mlSparse.setReal(4.0, 0, 1); mlSparse.setReal(2.0, 1, 0); mlSparse.setImaginary(2.0, 1, 0); mlSparse.setImaginary(6.0, 2, 1); for (int j = 0; j < referenceReal[i].length; j++) { assertEquals("2D array mismatch (real)", referenceReal[i][j], (double) ((MLSparse) mlArrayRetrived).getReal(i, j), 0.001); for (int j = 0; j < referenceImaginary[i].length; j++) { assertEquals("2D array mismatch (imaginary)", referenceImaginary[i][j], (double) ((MLSparse) mlArrayRetrived).getImaginary(i, j), 0.001);
private void createWriteToMatlab(LongWritable timeslot, Iterable<BytesWritable> manylines) throws IOException { System.out.println("Creating matlab file for timeslot: " + timeslot); MLSparse matarr = new MLSparse(String.format("values_%d", timeslot.get()), new int[] { wordIndex.size(), 2 }, 0, wordIndex.size() * 2); long Ttf = 0; long tf = 0; throw new IOException("Error writing matlab file, Ttf doesn't match"); matarr.set((double) idf.wf, wordI, 0); matarr.set((double) idf.Twf, wordI, 1);
/** * Gets column indices. * * <tt>jc</tt> points to an integer array of length N+1 that contains column index information. * For j, in the range <tt>0<=j<=N</tt>, <tt>jc[j]</tt> is the index in ir and <tt>pr</tt> (and <tt>pi</tt> * if it exists) of the first nonzero entry in the jth column and <tt>jc[j+1]?????????1</tt> index * of the last nonzero entry. As a result, <tt>jc[N]</tt> is also equal to nnz, the number * of nonzero entries in the matrix. If nnz is less than nzmax, then more nonzero * entries can be inserted in the array without allocating additional storage * * @return */ public int[] getJC() { int[] jc = new int[getN() + 1]; // jc[j] is the number of nonzero elements in all preceeding columns for (IndexMN index : indexSet) { for (int column = index.n + 1; column < jc.length; column++) { jc[column]++; } } return jc; }
break; case MLArray.mxSPARSE_CLASS: MLSparse sparse = new MLSparse(name, dims, attributes, nzmax); int[] jc = tag.readToIntArray(); if (sparse.isComplex()) { for (int column = 0; column < sparse.getN(); column++) { while (count < jc[column + 1]) { sparse.setReal(ad1[count], ir[count], column); count++; for (int column = 0; column < sparse.getN(); column++) { while (count < jc[column + 1]) { sparse.setImaginary(ad2[count], ir[count], column); count++; double[] ad1 = tag.readToDoubleArray(); int count = 0; for (int column = 0; column < sparse.getN(); column++) { while (count < jc[column + 1]) { sparse.set(ad1[count], ir[count], column); count++;
ai = ((MLSparse)array).getIR(); for ( int i : ai ) ai = ((MLSparse)array).getJC(); for ( int i : ai ) bufferDOS = new DataOutputStream(buffer); Double[] ad = ((MLSparse)array).exportReal(); ad = ((MLSparse)array).exportImaginary(); for ( int i = 0; i < ad.length; i++ )
private void createWriteToMatlab(LongWritable timeslot, Iterable<BytesWritable> manylines) throws IOException { System.out.println("Creating matlab file for timeslot: " + timeslot); MLSparse matarr = new MLSparse(String.format("values_%d", timeslot.get()), new int[] { wordIndex.size(), 2 }, 0, wordIndex.size() * 2); long Ttf = 0; long tf = 0; throw new IOException("Error writing matlab file, Ttf doesn't match"); matarr.set((double) idf.wf, wordI, 0); matarr.set((double) idf.Twf, wordI, 1);
/** * Gets column indices. * * <tt>jc</tt> points to an integer array of length N+1 that contains column index information. * For j, in the range <tt>0<=j<=N</tt>, <tt>jc[j]</tt> is the index in ir and <tt>pr</tt> (and <tt>pi</tt> * if it exists) of the first nonzero entry in the jth column and <tt>jc[j+1]?????????1</tt> index * of the last nonzero entry. As a result, <tt>jc[N]</tt> is also equal to nnz, the number * of nonzero entries in the matrix. If nnz is less than nzmax, then more nonzero * entries can be inserted in the array without allocating additional storage * * @return */ public int[] getJC() { int[] jc = new int[getN() + 1]; // jc[j] is the number of nonzero elements in all preceeding columns for (IndexMN index : indexSet) { for (int column = index.n + 1; column < jc.length; column++) { jc[column]++; } } return jc; }
break; case MLArray.mxSPARSE_CLASS: MLSparse sparse = new MLSparse(name, dims, attributes, nzmax); double[] ad1 = tag.readToDoubleArray(); int count = 0; for (int column = 0; column < sparse.getN(); column++) { while(count < jc[column+1]) { sparse.setReal(ad1[count], ir[count], column); count++; if ( sparse.isComplex() ) for (int column = 0; column < sparse.getN(); column++) { while(count < jc[column+1]) { sparse.setImaginary(ad2[count], ir[count], column); count++;
ai = ((MLSparse)array).getIR(); for ( int i : ai ) ai = ((MLSparse)array).getJC(); for ( int i : ai ) bufferDOS = new DataOutputStream(buffer); Double[] ad = ((MLSparse)array).exportReal(); ad = ((MLSparse)array).exportImaginary(); for ( int i = 0; i < ad.length; i++ )
@Override public String contentToString() { StringBuffer sb = new StringBuffer(); sb.append(name + " = \n"); for (IndexMN i : indexSet) { sb.append("\t("); sb.append(i.m + "," + i.n); sb.append(")"); sb.append("\t" + getReal(i.m, i.n)); if (isComplex()) { sb.append("+" + getImaginary(i.m, i.n)); } sb.append("\n"); } return sb.toString(); }
reader = new BufferedReader(new InputStreamReader(new FileInputStream(valuesIn), "UTF-8")); final int nValues = wordIndex.size() * timeIndex.size(); final MLSparse matarr = new MLSparse("values", new int[] { wordIndex.size(), timeIndex.size() }, 0, nValues); System.out.println("... reading values"); String wholeLine = null; wtd.idf.Ttf = Integer.parseInt(line[5]); matarr.set(wtd.idf.dfidf(), wtd.word, wtd.time);
public Double buldFromBytes(byte[] bytes) { if ( bytes.length != getBytesAllocated() ) { throw new IllegalArgumentException( "To build from byte array I need array of size: " + getBytesAllocated() ); } return ByteBuffer.wrap( bytes ).getDouble(); } public byte[] getByteArray(Double value)
/** * Gets column indices. * * <kbd>jc</kbd> points to an integer array of length N+1 that contains column index information. * For j, in the range <kbd>0<=j<=N 1</kbd>, <kbd>jc[j]</kbd> is the index in ir and <kbd>pr</kbd> (and <kbd>pi</kbd> * if it exists) of the first nonzero entry in the jth column and <kbd>jc[j+1] 1</kbd> index * of the last nonzero entry. As a result, <kbd>jc[N]</kbd> is also equal to nnz, the number * of nonzero entries in the matrix. If nnz is less than nzmax, then more nonzero * entries can be inserted in the array without allocating additional storage * * @return column indices */ public int[] getJC() { int[] jc = new int[getN()+1]; // jc[j] is the number of nonzero elements in all preceeding columns for ( IndexMN index : indexSet ) { for (int column = index.n + 1; column < jc.length; column++) { jc[column]++; } } return jc; }
break; case MLArray.mxSPARSE_CLASS: MLSparse sparse = new MLSparse(name, dims, attributes, nzmax); double[] ad1 = tag.readToDoubleArray(); int count = 0; for (int column = 0; column < sparse.getN(); column++) { while(count < jc[column+1]) { sparse.setReal(ad1[count], ir[count], column); count++; if ( sparse.isComplex() ) for (int column = 0; column < sparse.getN(); column++) { while(count < jc[column+1]) { sparse.setImaginary(ad2[count], ir[count], column); count++;
ai = ((MLSparse)array).getIR(); for ( int i : ai ) ai = ((MLSparse)array).getJC(); for ( int i : ai ) bufferDOS = new DataOutputStream(buffer); Double[] ad = ((MLSparse)array).exportReal(); ad = ((MLSparse)array).exportImaginary(); for ( int i = 0; i < ad.length; i++ )