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


Java VectorWritable类代码示例

本文整理汇总了Java中org.apache.hama.commons.io.VectorWritable的典型用法代码示例。如果您正苦于以下问题:Java VectorWritable类的具体用法?Java VectorWritable怎么用?Java VectorWritable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: calculateItemSimilarity

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
public double calculateItemSimilarity(long item1, long item2) {
  VectorWritable itm1 = this.m_modelUserFactorizedValues.get(Long
      .valueOf(item1));
  VectorWritable itm2 = this.m_modelUserFactorizedValues.get(Long
      .valueOf(item2));
  if (itm1 == null || itm2 == null) {
    return Double.MAX_VALUE;
  }

  DoubleVector itm1Vector = itm1.getVector();
  DoubleVector itm2Vector = itm2.getVector();

  // Euclidean distance
  return Math.pow(
      itm1Vector.subtract(itm2Vector)
          .applyToElements(new SquareVectorFunction()).sum(), 0.5);
}
 
开发者ID:millecker,项目名称:applications,代码行数:18,代码来源:OnlineCF.java

示例2: cleanup

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
@Override
public final void cleanup(BSPPeer<Text, Text, Text, Text, VectorWritable> peer) throws IOException {
	if (master) {
		int numPrint = 0;
		if (query.equalsIgnoreCase("topk")) {
			numPrint = paraK;
		}
		else if (query.equalsIgnoreCase("distance")) {
			numPrint = joinedPairs.size();
		}
		if ((joinedPairs.size() >= paraK && query.equalsIgnoreCase("topk")) || query.equalsIgnoreCase("distance")) {
			for (int i = 0; i < numPrint; i++) {
				JoinedPair pair = joinedPairs.pollFirst();
				peer.write(new Text(String.valueOf(i)), new Text(pair.toString()));
			}
		}
		else peer.write(new Text("Error"), new Text(String.valueOf(beforeComputationThreshold)));
	}
}
 
开发者ID:jinhuang,项目名称:melody-join,代码行数:20,代码来源:BaselineBSP.java

示例3: createJob

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
public static BSPJob createJob(Configuration configuration, Path in, Path out) throws IOException {
	HamaConfiguration conf = new HamaConfiguration(configuration);
	BSPJob job = new BSPJob(conf, BaselineBSP.class);
	job.setJobName("Baseline Top-k Join");
	job.setJarByClass(BaselineBSP.class);
	job.setBspClass(BaselineBSP.class);
	job.setInputPath(in);
	job.setOutputPath(out);
	job.setInputFormat(KeyValueTextInputFormat.class);
	job.setOutputFormat(TextOutputFormat.class);
	job.setInputKeyClass(VectorWritable.class);
	job.setInputValueClass(NullWritable.class);
	job.setOutputKeyClass(Text.class);
	job.setOutputValueClass(Text.class);
	return job;
}
 
开发者ID:jinhuang,项目名称:melody-join,代码行数:17,代码来源:BaselineBSP.java

示例4: process

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
private void process(BSPPeer<Text, Text, Text, Text, VectorWritable> peer) 
		throws IOException {
	if (nativeDone) {
		guestJoin(peer);
	}
	else {
		nativeJoin(peer);
		peer.reopenInput();
	}
	
	if (receiveDone && sentFlag == numRecord) {
		sendDone = true;
		sendFinalMessage(peer);
		LOG.info("peer " + peer.getPeerIndex() + " at step " + peer.getSuperstepCount() + " sends final message");
	}
	else {
		sendMessage(peer);
	}
}
 
开发者ID:jinhuang,项目名称:melody-join,代码行数:20,代码来源:BaselineBSP.java

示例5: readInput

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
private List<DoubleVector> readInput(BSPPeer<Text, Text,  Text, Text, VectorWritable> peer) throws IOException {
	if (cache != null && cache.isEmpty() || cache == null) {
		List<DoubleVector> histograms = new ArrayList<DoubleVector>();
		Text key = new Text();
		Text val = new Text();
		while (peer.readNext(key, val)) {
			DoubleVector each = BSPUtil.toDoubleVector(key);
			histograms.add(each);
			if (cache != null) {
				cache.add(each.deepCopy());
			}
		}
		numRecord = histograms.size();
		if (cache == null) {
			peer.reopenInput();
		}
		return histograms;
	}
	else return cache;
}
 
开发者ID:jinhuang,项目名称:melody-join,代码行数:21,代码来源:BaselineBSP.java

示例6: bsp

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
@Override
	public void bsp(
			BSPPeer<Text, Text, Text, Text, VectorWritable> peer)
			throws IOException, SyncException, InterruptedException {
		while(true) {
//			LOG.info("peer " + peer.getPeerIndex() + " sc: " + peer.getSuperstepCount());
			process(peer);
			peer.sync();
			if (seenSendDone == peer.getNumPeers() && seenFinal == peer.getNumPeers()) {
				if (master) {
					mergeResult(peer);
				}
				break;
			}
		}
	}
 
开发者ID:jinhuang,项目名称:melody-join,代码行数:17,代码来源:NormalBSP.java

示例7: createJob

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
public static BSPJob createJob(Configuration configuration, Path in, Path out) throws IOException {
	HamaConfiguration conf = new HamaConfiguration(configuration);
	BSPJob job = new BSPJob(conf, NormalBSP.class);
	job.setJobName("Normal Top-k Join");
	job.setJarByClass(NormalBSP.class);
	job.setBspClass(NormalBSP.class);
	job.setInputPath(in);
	job.setOutputPath(out);
	job.setInputFormat(KeyValueTextInputFormat.class);
	job.setOutputFormat(TextOutputFormat.class);
	job.setInputKeyClass(VectorWritable.class);
	job.setInputValueClass(NullWritable.class);
	job.setOutputKeyClass(Text.class);
	job.setOutputValueClass(Text.class);
	return job;
}
 
开发者ID:jinhuang,项目名称:melody-join,代码行数:17,代码来源:NormalBSP.java

示例8: process

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
public void process(BSPPeer<Text, Text, Text, Text, VectorWritable> peer) 
			throws IOException {
		if (nativeDone) {
			guestJoin(peer);
		}
		else {
			nativeJoin(peer);
			peer.reopenInput();
		}
		
		if (sentFlag == numRecord && !sendDone) {
			sendDone = true;
			sendSeenMessage(peer);
		}
		else if(sentFlag == numRecord && sendDone && !finalDone) {
			finalDone = true;
			sendFinalMessage(peer);
		}
		else {
			sendMessage(peer);
		}
		
//		peer.write(new Text(String.valueOf(peer.getSuperstepCount())), new Text("Send: " + seenSendDone + " ; Final " + seenFinal));
		LOG.info(peer.getSuperstepCount() + ": send " + seenSendDone + ", final " + seenFinal);
	}
 
开发者ID:jinhuang,项目名称:melody-join,代码行数:26,代码来源:NormalBSP.java

示例9: setup

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
@Override
final public void setup(
    BSPPeer<LongWritable, VectorWritable, NullWritable, NullWritable, Synapse<DoubleWritable, DoubleWritable>> peer)
    throws IOException, SyncException, InterruptedException {
  conf = peer.getConfiguration();
  featureTransformer = new FloatFeatureTransformer();
  this.extraSetup(peer);
}
 
开发者ID:apache,项目名称:incubator-horn,代码行数:9,代码来源:AbstractNeuralNetworkTrainer.java

示例10: cleanup

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
@Override
public void cleanup(
    BSPPeer<LongWritable, VectorWritable, NullWritable, NullWritable, Synapse<DoubleWritable, DoubleWritable>> peer)
    throws IOException {
  this.extraCleanup(peer);
  // write model to modelPath
}
 
开发者ID:apache,项目名称:incubator-horn,代码行数:8,代码来源:AbstractNeuralNetworkTrainer.java

示例11: trainInternal

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
@Override
protected BSPJob trainInternal(HamaConfiguration conf) throws IOException,
    InterruptedException, ClassNotFoundException {
  this.conf = conf;
  this.fs = FileSystem.get(conf);

  String modelPath = conf.get("model.path");
  if (modelPath != null) {
    this.modelPath = modelPath;
  }
  // modelPath must be set before training
  if (this.modelPath == null) {
    throw new IllegalArgumentException(
        "Please specify the modelPath for model, "
            + "either through setModelPath() or add 'modelPath' to the training parameters.");
  }
  this.writeModelToFile();

  // create job
  BSPJob job = new BSPJob(conf, LayeredNeuralNetworkTrainer.class);
  job.setJobName("Neural Network training");
  job.setJarByClass(LayeredNeuralNetworkTrainer.class);
  job.setBspClass(LayeredNeuralNetworkTrainer.class);

  job.getConfiguration().setInt(Constants.ADDITIONAL_BSP_TASKS, 1);

  job.setBoolean("training.mode", true);
  job.setInputPath(new Path(conf.get("training.input.path")));
  job.setInputFormat(org.apache.hama.bsp.SequenceFileInputFormat.class);
  job.setInputKeyClass(LongWritable.class);
  job.setInputValueClass(VectorWritable.class);
  job.setOutputKeyClass(NullWritable.class);
  job.setOutputValueClass(NullWritable.class);
  job.setOutputFormat(org.apache.hama.bsp.NullOutputFormat.class);

  return job;
}
 
开发者ID:apache,项目名称:incubator-horn,代码行数:38,代码来源:LayeredNeuralNetwork.java

示例12: trainInternal

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
@Override
protected BSPJob trainInternal(HamaConfiguration conf) throws IOException,
    InterruptedException, ClassNotFoundException {
  this.conf = conf;
  this.fs = FileSystem.get(conf);

  String modelPath = conf.get("model.path");
  if (modelPath != null) {
    this.modelPath = modelPath;
  }
  // modelPath must be set before training
  if (this.modelPath == null) {
    throw new IllegalArgumentException(
        "Please specify the modelPath for model, "
            + "either through setModelPath() or add 'modelPath' to the training parameters.");
  }
  this.setRecurrentStepSize(conf.getInt("training.recurrent.step.size", 1));
  this.initializeWeightMatrixLists();
  this.writeModelToFile();

  // create job
  BSPJob job = new BSPJob(conf, RecurrentLayeredNeuralNetworkTrainer.class);
  job.setJobName("Neural Network training");
  job.setJarByClass(RecurrentLayeredNeuralNetworkTrainer.class);
  job.setBspClass(RecurrentLayeredNeuralNetworkTrainer.class);

  job.getConfiguration().setInt(Constants.ADDITIONAL_BSP_TASKS, 1);

  job.setBoolean("training.mode", true);
  job.setInputPath(new Path(conf.get("training.input.path")));
  job.setInputFormat(org.apache.hama.bsp.SequenceFileInputFormat.class);
  job.setInputKeyClass(LongWritable.class);
  job.setInputValueClass(VectorWritable.class);
  job.setOutputKeyClass(NullWritable.class);
  job.setOutputValueClass(NullWritable.class);
  job.setOutputFormat(org.apache.hama.bsp.NullOutputFormat.class);

  return job;
}
 
开发者ID:apache,项目名称:incubator-horn,代码行数:40,代码来源:RecurrentLayeredNeuralNetwork.java

示例13: setupGpu

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
/********************************* GPU *********************************/
@Override
public void setupGpu(
    BSPPeer<IntWritable, VectorWritable, IntWritable, VectorWritable, MatrixRowMessage> peer)
    throws IOException, SyncException, InterruptedException {

  setup(peer); // use CPU implementation
}
 
开发者ID:millecker,项目名称:applications,代码行数:9,代码来源:MatrixMultiplicationHybridBSP.java

示例14: createMatrixMultiplicationHybridBSPConf

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
public static BSPJob createMatrixMultiplicationHybridBSPConf(
    Configuration conf, Path matrixAPath, Path transposedMatrixBPath,
    Path matrixCPath, int tileWidth, boolean isDebugging) throws IOException {

  BSPJob job = new BSPJob(new HamaConfiguration(conf),
      MatrixMultiplicationHybridBSP.class);
  // Set the job name
  job.setJobName("MatrixMultiplicationHybridBSP");
  // set the BSP class which shall be executed
  job.setBspClass(MatrixMultiplicationHybridBSP.class);
  // help Hama to locale the jar to be distributed
  job.setJarByClass(MatrixMultiplicationHybridBSP.class);

  job.setInputFormat(SequenceFileInputFormat.class);
  job.setInputKeyClass(IntWritable.class);
  job.setInputValueClass(VectorWritable.class);
  job.setInputPath(matrixAPath);

  job.setOutputFormat(SequenceFileOutputFormat.class);
  job.setOutputKeyClass(IntWritable.class);
  job.setOutputValueClass(VectorWritable.class);
  job.setOutputPath(matrixCPath);

  job.setMessageClass(MatrixRowMessage.class);

  job.set("bsp.child.java.opts", "-Xms1G -Xmx1G");

  // Order message by row index
  job.set(MessageManager.RECEIVE_QUEUE_TYPE_CLASS,
      "org.apache.hama.bsp.message.queue.SortedMemoryQueue");

  job.set(CONF_MATRIX_B_PATH, transposedMatrixBPath.toString());
  job.set(CONF_TILE_WIDTH, "" + tileWidth);
  job.setBoolean(CONF_DEBUG, isDebugging);

  return job;
}
 
开发者ID:millecker,项目名称:applications,代码行数:38,代码来源:MatrixMultiplicationHybridBSP.java

示例15: createMatrixMultiplicationBSPGpuConf

import org.apache.hama.commons.io.VectorWritable; //导入依赖的package包/类
public static BSPJob createMatrixMultiplicationBSPGpuConf(Configuration conf,
    Path aPath, Path bPath, Path outPath) throws IOException {

  BSPJob job = new BSPJob(new HamaConfiguration(conf));
  // Set the job name
  job.setJobName("MatrixMultiplicationBSP GPU");
  // set the BSP class which shall be executed
  job.setBspClass(MatrixMultiplicationBSPGpuNew.class);
  // help Hama to locale the jar to be distributed
  job.setJarByClass(MatrixMultiplicationBSPGpuNew.class);

  job.setInputFormat(SequenceFileInputFormat.class);
  job.setInputPath(aPath);

  job.setOutputFormat(SequenceFileOutputFormat.class);
  job.setOutputKeyClass(IntWritable.class);
  job.setOutputValueClass(VectorWritable.class);
  job.setOutputPath(outPath);

  job.set(CONF_MATRIX_MULT_B_PATH, bPath.toString());
  job.set("bsp.child.java.opts", "-Xmx4G");

  // Order message by row index
  // job.set(MessageManager.TRANSFER_QUEUE_TYPE_CLASS,
  // "org.apache.hama.bsp.message.queue.SortedMemoryQueueTransfer");

  LOG.info("DEBUG: NumBspTask: " + job.getNumBspTask());
  LOG.info("DEBUG: bsp.job.split.file: " + job.get("bsp.job.split.file"));
  LOG.info("DEBUG: bsp.tasks.maximum: " + job.get("bsp.tasks.maximum"));
  LOG.info("DEBUG: bsp.input.dir: " + job.get("bsp.input.dir"));

  return job;
}
 
开发者ID:millecker,项目名称:applications,代码行数:34,代码来源:MatrixMultiplicationBSPGpuNew.java


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