Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hadoop 如何对一个大图进行统一采样?_Hadoop_Mapreduce_Graph Algorithm_Random Sample - Fatal编程技术网

Hadoop 如何对一个大图进行统一采样?

Hadoop 如何对一个大图进行统一采样?,hadoop,mapreduce,graph-algorithm,random-sample,Hadoop,Mapreduce,Graph Algorithm,Random Sample,我有一个很大的图,它有大约4米的节点。图形由两个文件组成,一个包含节点名称,另一个包含边(每行代表一条边)。我想对图节点进行统一采样,并得出一个占整个图15%的样本。考虑到图形的大小,生成此类示例的最佳(或可能的)方法是什么?使用此java代码随机选择15%的顶点: import java.io.IOException; import java.util.*; import org.apache.hadoop.fs.Path; import org.apache.hadoop.conf.*;

我有一个很大的图,它有大约4米的节点。图形由两个文件组成,一个包含节点名称,另一个包含边(每行代表一条边)。我想对图节点进行统一采样,并得出一个占整个图15%的样本。考虑到图形的大小,生成此类示例的最佳(或可能的)方法是什么?

使用此java代码随机选择15%的顶点:

import java.io.IOException;
import java.util.*;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class RandomSample {

 public static class Map extends Mapper<LongWritable, Text, Text, Text> {
    private Text word = new Text();

    public void map(LongWritable key, Text value, Context context)
    throws IOException, InterruptedException {
        if (Math.random()<0.15)
            context.write(value,null);
        else
            context.write(null,null);
    context.write(value,null);
    } 
 }

 public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();

    Job job = new Job(conf, "randomsample");
    job.setJarByClass(RandomSample.class);

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(Text.class);
    job.setInputFormatClass(TextInputFormat.class);
    job.setOutputFormatClass(TextOutputFormat.class);

    job.setNumReduceTasks(0);

    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));

    job.waitForCompletion(true);
 }

}
例如,如果我们将脚本命名为random_sample.sh,要从文件夹/example/中选择15%,只需运行

./random_sample.sh /example/

然后,您可以对第二个文件使用简单的
grep
操作,仅选择包含随机选择的顶点的边

您只想对节点或这些节点定义的子图(节点+对应边)进行采样?实际上是子图,即采样节点形成的图。
./random_sample.sh /example/