本文整理了Java中org.apache.giraph.graph.Vertex.setValue()
方法的一些代码示例,展示了Vertex.setValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vertex.setValue()
方法的具体详情如下:
包路径:org.apache.giraph.graph.Vertex
类名称:Vertex
方法名:setValue
[英]Set the vertex data (immediately visible in the computation)
[中]设置顶点数据(在计算中立即可见)
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<LongWritable, NullWritable, NullWritable> vertex,
Iterable<Writable> messages) throws IOException {
vertex.setValue(NullWritable.get());
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<WritableComparable, Writable, Writable> vertex,
Iterable<WritableComparable> messages) throws IOException {
int count = 0;
for (WritableComparable msg : messages) {
// If this vertex has a neighbor with this ID, then this means it
// participates in a triangle.
if (vertex.getEdgeValue(msg)!=null) {
count++;
}
}
if (count>0) {
vertex.setValue(new IntWritable(count));
}
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex,
Iterable<LongIdDoubleValueFriendsList> messages) throws IOException {
DoubleWritable vertexValue = new DoubleWritable(0.0);
if (vertex.getNumEdges() > 0) {
vertexValue.set(Math.log(1.0 / (double) vertex.getNumEdges()));
}
vertex.setValue(vertexValue);
}
代码示例来源:origin: grafos-ml/okapi
void applyUpdate(FloatMatrix deltaUpdate, Vertex<CfLongId, FloatMatrixWritable, FloatWritable> vertex) {
vertex.setValue(new FloatMatrixWritable(vertex.getValue().add(deltaUpdate)));
}
代码示例来源:origin: org.apache.giraph/giraph-examples
@Override
public void compute(Vertex<IntWritable, IntWritable, NullWritable> vertex,
Iterable<IntWritable> messages) throws IOException {
boolean changed = false;
for (IntWritable message : messages) {
if (vertex.getValue().get() < message.get()) {
vertex.setValue(message);
changed = true;
}
}
if (getSuperstep() == 0 || changed) {
sendMessageToAllEdges(vertex, vertex.getValue());
}
vertex.voteToHalt();
}
}
代码示例来源:origin: org.apache.giraph/giraph-examples
@Override
public void compute(
Vertex<LongWritable, LongWritable, DoubleWritable> vertex,
Iterable<DoubleWritable> messages) throws IOException {
LongWritable vertexValue = vertex.getValue();
vertexValue.set(vertex.getNumEdges());
vertex.setValue(vertexValue);
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
protected void initFactorsIfNeeded(Vertex<CfLongId, FloatMatrixWritable, FloatWritable> vertex) {
if (null == vertex.getValue() || vertex.getValue().columns != d){
vertex.setValue(new FloatMatrixWritable(FloatMatrix.rand(d)));
}
}
代码示例来源:origin: org.apache.giraph/giraph-examples
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
Iterable<DoubleWritable> messages) throws IOException {
double oldSum = getSuperstep() == 0 ? 0 : vertex.getValue().get();
double newValue = this.<DoubleWritable>getAggregatedValue(SMC_AGG).get();
double newSum = oldSum + newValue;
vertex.setValue(new DoubleWritable(newSum));
SimpleMasterComputeWorkerContext workerContext = getWorkerContext();
workerContext.setFinalSum(newSum);
LOG.info("Current sum: " + newSum);
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<CfLongId, FloatMatrixWritable, FloatWritable> vertex,
Iterable<FloatMatrixMessage> messages) throws IOException {
FloatMatrixWritable vector =
new FloatMatrixWritable(getContext().getConfiguration().getInt(
VECTOR_SIZE, VECTOR_SIZE_DEFAULT));
Random randGen = new Random();
for (int i=0; i<vector.length; i++) {
vector.put(i, 0.01f*randGen.nextFloat());
}
vertex.setValue(vector);
for (Edge<CfLongId, FloatWritable> edge : vertex.getEdges()) {
FloatMatrixMessage msg = new FloatMatrixMessage(
vertex.getId(), vertex.getValue(), edge.getValue().get());
sendMessage(edge.getTargetVertexId(), msg);
}
vertex.voteToHalt();
}
}
代码示例来源:origin: org.apache.giraph/giraph-examples
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
Iterable<DoubleWritable> messages) throws IOException {
double oldSum = getSuperstep() == 0 ? 0 : vertex.getValue().get();
double newValue = this.<DoubleWritable>getAggregatedValue(SMC_AGG).get();
double newSum = oldSum + newValue;
vertex.setValue(new DoubleWritable(newSum));
SimpleMigrationMasterWorkerContext workerContext = getWorkerContext();
workerContext.setFinalSum(newSum);
LOG.info("Current sum: " + newSum);
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
Iterable<DoubleWritable> messages) {
double oldSum = getSuperstep() == 0 ? 0 : vertex.getValue().get();
double newValue = this.<DoubleWritable>getAggregatedValue(SMC_AGG).get();
double newSum = oldSum + newValue;
vertex.setValue(new DoubleWritable(newSum));
SimpleMasterComputeWorkerContext workerContext =
(SimpleMasterComputeWorkerContext) getWorkerContext();
workerContext.setFinalSum(newSum);
LOG.info("Current sum: " + newSum);
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<CfLongId, FloatMatrixWritable, FloatWritable> vertex,
Iterable<FloatMatrixMessage> messages) throws IOException {
FloatMatrixWritable vector =
new FloatMatrixWritable(getContext().getConfiguration().getInt(
VECTOR_SIZE, VECTOR_SIZE_DEFAULT));
Random randGen = new Random();
for (int i=0; i<vector.length; i++) {
vector.put(i, 0.01f*randGen.nextFloat());
}
vertex.setValue(vector);
for (Edge<CfLongId, FloatWritable> edge : vertex.getEdges()) {
FloatMatrixMessage msg = new FloatMatrixMessage(
vertex.getId(), vertex.getValue(), edge.getValue().get());
sendMessage(edge.getTargetVertexId(), msg);
}
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<CfLongId, FloatMatrixWritable, FloatWritable> vertex,
Iterable<FloatMatrixMessage> messages) throws IOException {
FloatMatrixWritable vector =
new FloatMatrixWritable(getContext().getConfiguration().getInt(
VECTOR_SIZE, VECTOR_SIZE_DEFAULT));
Random randGen = new Random();
for (int i=0; i<vector.length; i++) {
vector.put(i, 0.01f*randGen.nextFloat());
}
vertex.setValue(vector);
for (FloatMatrixMessage msg : messages) {
DefaultEdge<CfLongId, FloatWritable> edge =
new DefaultEdge<CfLongId, FloatWritable>();
edge.setTargetVertexId(msg.getSenderId());
edge.setValue(new FloatWritable(msg.getScore()));
vertex.addEdge(edge);
}
// The score does not matter at this point.
sendMessageToAllEdges(vertex,
new FloatMatrixMessage(vertex.getId(), vertex.getValue(), 0.0f));
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
/**
* We override this function as we need a special treatment for item biases. See the class documentation for the explanation.
*/
protected void initFactorsIfNeeded(Vertex<CfLongId,FloatMatrixWritable,FloatWritable> vertex) {
if (null == vertex.getValue() || vertex.getValue().columns != d+1){
vertex.setValue(new FloatMatrixWritable(FloatMatrix.rand(d + 1)));
}
if (vertex.getId().isUser()){//In BPR the first factor of the user is always 1, its to have item baselines
vertex.getValue().put(0, 1f);
}
}
代码示例来源:origin: org.apache.giraph/giraph-core
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex,
Iterable<DoubleWritable> messages) throws IOException {
if (getSuperstep() == 0) {
vertex.setValue(new DoubleWritable(Double.MAX_VALUE));
}
double minDist = isSource(vertex) ? 0d : Double.MAX_VALUE;
for (DoubleWritable message : messages) {
minDist = Math.min(minDist, message.get());
}
if (minDist < vertex.getValue().get()) {
vertex.setValue(new DoubleWritable(minDist));
for (Edge<LongWritable, DoubleWritable> edge : vertex.getEdges()) {
double distance = minDist + edge.getValue().get();
sendMessage(edge.getTargetVertexId(),
new DoubleWritable(distance));
}
}
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<CfLongId, FloatMatrixWritable,
FloatWritable> vertex, Iterable<FloatMatrixMessage> messages)
throws IOException {
FloatMatrixWritable vector =
new FloatMatrixWritable(getContext().getConfiguration().getInt(
VECTOR_SIZE, VECTOR_SIZE_DEFAULT));
Random randGen = new Random();
for (int i=0; i<vector.length; i++) {
vector.put(i, 0.01f*randGen.nextFloat());
}
vertex.setValue(vector);
for (FloatMatrixMessage msg : messages) {
DefaultEdge<CfLongId, FloatWritable> edge =
new DefaultEdge<CfLongId, FloatWritable>();
edge.setTargetVertexId(msg.getSenderId());
edge.setValue(new FloatWritable(msg.getScore()));
vertex.addEdge(edge);
}
// The score does not matter at this point.
sendMessageToAllEdges(vertex,
new FloatMatrixMessage(vertex.getId(), vertex.getValue(), 0.0f));
vertex.voteToHalt();
}
}
代码示例来源:origin: org.apache.giraph/giraph-examples
@Override
public void compute(
Vertex<LongWritable, LongWritable, DoubleWritable> vertex,
Iterable<DoubleWritable> messages) throws IOException {
if (getSuperstep() == 0) {
Iterable<Edge<LongWritable, DoubleWritable>> edges = vertex.getEdges();
for (Edge<LongWritable, DoubleWritable> edge : edges) {
sendMessage(edge.getTargetVertexId(), new DoubleWritable(1.0));
}
} else {
long sum = 0;
for (DoubleWritable message : messages) {
sum++;
}
LongWritable vertexValue = vertex.getValue();
vertexValue.set(sum);
vertex.setValue(vertexValue);
vertex.voteToHalt();
}
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<CfLongId, FloatMatrixWritable, FloatWritable> vertex, Iterable<FloatMatrixMessage> messages) throws IOException {
vertex.setValue(new FloatMatrixWritable(FloatMatrix.rand(DIM)));
if(getSuperstep() == 0){
Iterable<Edge<CfLongId, FloatWritable>> edges = vertex.getEdges();
sendMessage(vertex.getId(), emptyMsg); //send message to myself in order to be executed in the next super step
for (Edge<CfLongId, FloatWritable> edge : edges) {
sendMessage(edge.getTargetVertexId(), new FloatMatrixMessage(vertex.getId(), emptyList, edge.getValue().get()));
}
}
vertex.voteToHalt();
}
代码示例来源:origin: org.apache.giraph/giraph-examples
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
Iterable<DoubleWritable> messages) throws IOException {
if (getSuperstep() >= 1) {
double sum = 0;
for (DoubleWritable message : messages) {
sum += message.get();
}
DoubleWritable vertexValue =
new DoubleWritable((0.15f / getTotalNumVertices()) + 0.85f * sum);
vertex.setValue(vertexValue);
aggregate(MAX_AGG, vertexValue);
aggregate(MIN_AGG, vertexValue);
aggregate(SUM_AGG, new LongWritable(1));
LOG.info(vertex.getId() + ": PageRank=" + vertexValue +
" max=" + getAggregatedValue(MAX_AGG) +
" min=" + getAggregatedValue(MIN_AGG));
}
if (getSuperstep() < MAX_SUPERSTEPS) {
long edges = vertex.getNumEdges();
sendMessageToAllEdges(vertex,
new DoubleWritable(vertex.getValue().get() / edges));
} else {
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<CfLongId, FloatMatrixWritable, FloatWritable> vertex, Iterable<FloatMatrixMessage> messages) throws IOException {
if (getSuperstep() == 0){//send empty message with the count
vertex.setValue(new FloatMatrixWritable(FloatMatrix.ones(1))); //set all users to 1
if (vertex.getId().isUser()){
Iterable<Edge<CfLongId, FloatWritable>> edges = vertex.getEdges();
sendMessage(vertex.getId(), emptyMsg); //send message to myself in order to be executed in the next super step
for (Edge<CfLongId, FloatWritable> edge : edges) {
sendMessage(edge.getTargetVertexId(), new FloatMatrixMessage(vertex.getId(), emptyList, edge.getValue().get()));
}
}
}else if(getSuperstep() == 1){//compute how many messages were received by an item (how many users rated this item)
if (vertex.getId().isItem()){
int cnt = 0;
for (@SuppressWarnings("unused") FloatMatrixMessage msg : messages) {
cnt+= 1;
}
FloatMatrix output = FloatMatrix.zeros(1);
output.put(0, cnt);
vertex.setValue(new FloatMatrixWritable(output));
}
}
vertex.voteToHalt();
}
}
内容来源于网络,如有侵权,请联系作者删除!