当前位置: 首页>>代码示例>>Java>>正文


Java VectorWritable.set方法代码示例

本文整理汇总了Java中org.apache.mahout.math.VectorWritable.set方法的典型用法代码示例。如果您正苦于以下问题:Java VectorWritable.set方法的具体用法?Java VectorWritable.set怎么用?Java VectorWritable.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mahout.math.VectorWritable的用法示例。


在下文中一共展示了VectorWritable.set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeMatrix

import org.apache.mahout.math.VectorWritable; //导入方法依赖的package包/类
static void writeMatrix(Matrix origMatrix,
     Path outPath, Path tmpPath, String label) throws IOException {
   Configuration conf = new Configuration();
   Path outputDir = new Path(outPath, label + origMatrix.numRows() + "x"
       + origMatrix.numCols());
   FileSystem fs = FileSystem.get(outputDir.toUri(), conf);
   if (!fs.exists(outputDir)) {
     Path outputFile = new Path(outputDir, "singleSliceMatrix");
     SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf,
         outputFile, IntWritable.class, VectorWritable.class);
     VectorWritable vectorWritable = new VectorWritable();
     try {
       for (int r = 0; r < origMatrix.numRows(); r++) {
         Vector vector = origMatrix.viewRow(r);
         vectorWritable.set(vector);
         writer.append(new IntWritable(r), vectorWritable);
       }
     } finally {
       writer.close();
     }
   } else {
     log.warn("----------- Skip matrix " + outputDir + " - already exists");
   }
}
 
开发者ID:SiddharthMalhotra,项目名称:sPCA,代码行数:25,代码来源:SPCADriver.java

示例2: toDistributedVector

import org.apache.mahout.math.VectorWritable; //导入方法依赖的package包/类
static Path toDistributedVector(Vector vector, Path outputDir, String label,
    Configuration conf) throws IOException {
  Path outputFile = new Path(outputDir, "Vector-" + label);
  FileSystem fs = FileSystem.get(outputDir.toUri(), conf);
  if (fs.exists(outputFile)) {
    log.warn("----------- OVERWRITE " + outputFile + " already exists");
    fs.delete(outputFile, false);
  }
  SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, outputFile,
      IntWritable.class, VectorWritable.class);
  VectorWritable vectorWritable = new VectorWritable();
  vectorWritable.set(vector);
  writer.append(new IntWritable(0), vectorWritable);
  writer.close();
  return outputFile;
}
 
开发者ID:SiddharthMalhotra,项目名称:sPCA,代码行数:17,代码来源:PCACommon.java

示例3: cleanup

import org.apache.mahout.math.VectorWritable; //导入方法依赖的package包/类
@Override
public void cleanup(Context context) throws InterruptedException,
    IOException {
  // 2. Y' * X ----combiner part
  AtxBCombiner(ytxMatrix, ym, xm, sumxi, totalRows);
  // 3. X' * X ----combiner part
  AtxBCombiner(xtxMatrix, xm, xm, sumxi, totalRows);

  VectorWritable outVector = new VectorWritable();
  CompositeWritable ytxCompositeKey = new CompositeWritable(
      CompositeWritable.YTX_TYPE);
  for (int i = 0; i < ytxMatrix.numRows(); i++) {
    ytxCompositeKey.set(i);
    outVector.set(ytxMatrix.viewRow(i));
    context.write(ytxCompositeKey, outVector);
  }
  // for all XtX rows the key is the same
  // the last column of the value vector determines the row id
  CompositeWritable xtxSingleKey = new CompositeWritable(
      CompositeWritable.XTX_TYPE);
  int idCol = xtxMatrix.numCols() - 1;// last is id column
  for (int i = 0; i < xtxMatrix.numRows(); i++) {
    xtxMatrix.setQuick(i, idCol, i);
    outVector.set(xtxMatrix.viewRow(i));
    context.write(xtxSingleKey, outVector);
  }
}
 
开发者ID:SiddharthMalhotra,项目名称:sPCA,代码行数:28,代码来源:CompositeJob.java

示例4: toDistributedRowMatrix

import org.apache.mahout.math.VectorWritable; //导入方法依赖的package包/类
/**
 * Convert an in-memory representation of a matrix to a distributed version It
 * then can be used in distributed jobs
 * 
 * @param oriMatrix
 * @return path that contains the matrix files
 * @throws IOException
 */
static DistributedRowMatrix toDistributedRowMatrix(Matrix origMatrix,
    Path outPath, Path tmpPath, String label) throws IOException {
  Configuration conf = new Configuration();
  Path outputDir = new Path(outPath, label + origMatrix.numRows() + "x"
      + origMatrix.numCols());
  FileSystem fs = FileSystem.get(outputDir.toUri(), conf);
  if (!fs.exists(outputDir)) {
    Path outputFile = new Path(outputDir, "singleSliceMatrix");
    SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf,
        outputFile, IntWritable.class, VectorWritable.class);
    VectorWritable vectorWritable = new VectorWritable();
    try {
      for (int r = 0; r < origMatrix.numRows(); r++) {
        Vector vector = origMatrix.viewRow(r);
        vectorWritable.set(vector);
        writer.append(new IntWritable(r), vectorWritable);
      }
    } finally {
      writer.close();
    }
  } else {
    log.warn("----------- Skip matrix " + outputDir + " - already exists");
  }
  DistributedRowMatrix dMatrix = new DistributedRowMatrix(outputDir, tmpPath,
      origMatrix.numRows(), origMatrix.numCols());
  dMatrix.setConf(conf);
  return dMatrix;
}
 
开发者ID:SiddharthMalhotra,项目名称:sPCA,代码行数:37,代码来源:PCACommon.java

示例5: textToSequnceFile

import org.apache.mahout.math.VectorWritable; //导入方法依赖的package包/类
private static void textToSequnceFile(String inputStr) throws IOException {
	BufferedReader inputReader = new BufferedReader(
			new FileReader(inputStr));
	Configuration conf = new Configuration();
	Path inputPath = new Path(inputStr);
	Path outputPath = new Path(inputPath.getParent(), inputPath.getName()
			+ ".formatted");
	FileSystem fs = FileSystem.get(inputPath.toUri(), conf);
	SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf,
			outputPath, IntWritable.class, VectorWritable.class);
	VectorWritable vectorWritable = new VectorWritable();
	String line;
	int index = 0;
	try {
		while ((line = inputReader.readLine()) != null) {
			String[] columns = line.split(" ");
			int shift = 0;
			if (columns[0].isEmpty())
				shift++;
			double[] columnsDouble = new double[columns.length-shift];
			for (int i = 0; i < columnsDouble.length; i++) {
				columnsDouble[i] = Double.valueOf(columns[i+shift]);
			}
			Vector vector = new DenseVector(columnsDouble, true);
			vectorWritable.set(vector);
			writer.append(new IntWritable(index), vectorWritable);
			index++;
		}
	} finally {
		writer.close();
	}
	inputReader.close();
	System.out.println("Finish writing to " + outputPath);
}
 
开发者ID:SiddharthMalhotra,项目名称:sPCA,代码行数:35,代码来源:PrepareInput.java

示例6: main

import org.apache.mahout.math.VectorWritable; //导入方法依赖的package包/类
public static void main(String args[]) throws FileNotFoundException, IOException {

        String input = args[0];
        String output = args[1];
        Configuration conf;
        conf = new Configuration();
        FileSystem fs = FileSystem.get(conf);
        InputStream is = null;
        
        if (args.length>2 && args[2].equals("localInput")){
            System.out.println("Using local file "+input);
            is=(new FileInputStream( new File(input)));
        }            
        else{
            System.out.println("Using HDFS file "+input);
            is=fs.open(new Path(input));
        }

        try (
                BufferedReader reader =  new BufferedReader(new InputStreamReader(is));
                SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, new Path(output), IntWritable.class, VectorWritable.class)) {
            String line;
            int counter = 0;
            while ((line = reader.readLine()) != null) {
                String[] c = line.split(",");
                if (c.length > 1) {
                    double[] d = new double[c.length];
                    for (int i = 0; i < c.length; i++) {
                        d[i] = Double.parseDouble(c[i]);
                    }
                    Vector vec = new RandomAccessSparseVector(c.length);
                    vec.assign(d);

                    VectorWritable writable = new VectorWritable();
                    writable.set(vec);
                    writer.append(new IntWritable(counter++), writable);
                }
            }
            writer.close();
        }
    }
 
开发者ID:project-asap,项目名称:IReS-Platform,代码行数:42,代码来源:CSVLoader.java


注:本文中的org.apache.mahout.math.VectorWritable.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。