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


Java Link类代码示例

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


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

示例1: writeEdgeList

import org.nodes.Link; //导入依赖的package包/类
/**
 * 
 * @param graph
 * @param file
 * @param fromOne If true, the lowest index is 1, otherwise it's 0
 * @throws IOException
 */
public static <L> void writeEdgeList(Graph<L> graph, File file, boolean fromOne) 
	throws IOException
{
	BufferedWriter writer = new BufferedWriter(new FileWriter(file));
	int p = fromOne ? 1 : 0;
	int max = -1;
	
	for(Link<L> link : graph.links())
	{
		
		int from = (link.first().index() + p);
		int to = (link.second().index() + p);
		
		writer.write(from + "\t" + to + "\n");
		
		max = Math.max(from, max);
		max = Math.max(to,  max);
	}
	
	// Global.log().info("Graph written. Largest index: " + max);
	
	writer.close();
}
 
开发者ID:Data2Semantics,项目名称:nodes,代码行数:31,代码来源:Data.java

示例2: undirected

import org.nodes.Link; //导入依赖的package包/类
public static <N> double undirected(Graph<N> graph, boolean withPrior)
{

	OnlineModel<Integer> model = new OnlineModel<Integer>(Series.series(graph.size()));
	
	double bits = 0;
	
	if(withPrior)
	{
		bits += Functions.prefix(graph.size());
		bits += Functions.prefix(graph.numLinks());
	}
					
	for(Link<N> link : graph.links())
	{
		double p = model.observe(link.first().index()) * model.observe(link.second().index());
		if(! link.first().equals(link.second()))
			p *= 2.0;
		
		bits += -log2(p);
	}
	
	return bits - logFactorial(graph.numLinks(), 2.0);
}
 
开发者ID:Data2Semantics,项目名称:nodes,代码行数:25,代码来源:EdgeListCompressor.java

示例3: directed

import org.nodes.Link; //导入依赖的package包/类
public static <N> double directed(DGraph<N> graph, boolean withPrior)
{
	OnlineModel<Integer> source = new OnlineModel<Integer>(series(graph.size()));
	OnlineModel<Integer> target = new OnlineModel<Integer>(series(graph.size()));
	
	double bits = 0;
	
	if(withPrior)
	{
		bits += Functions.prefix(graph.size());
		bits += Functions.prefix(graph.numLinks());
	}

	for(Link<N> link : graph.links())
	{
		double p = 
			source.observe(link.first().index()) * 
			target.observe(link.second().index());
								
		bits += -log2(p);
	}
	
	bits -= logFactorial(graph.numLinks(), 2.0);
	
	return bits;
}
 
开发者ID:Data2Semantics,项目名称:nodes,代码行数:27,代码来源:EdgeListCompressor.java

示例4: wiringBitsDirect

import org.nodes.Link; //导入依赖的package包/类
public static <L> double wiringBitsDirect(Graph<L> graph, Graph<?> sub, List<List<Integer>> occurrences,
		boolean reset)
{
	OnlineModel<Integer> om = new OnlineModel<Integer>(Series.series(sub.size()));
	
	double wiringBits = 0.0;
	
	for (List<Integer> occurrence : occurrences)
	{			
		if(reset)
			om = new OnlineModel<Integer>(Series.series(sub.size()));
		
		// * The index of the node within the occurrence
		for (int indexInSubgraph : series(occurrence.size()))
		{
			Node<L> node = graph.get(occurrence.get(indexInSubgraph));
			
			for(Link<L> link : node.links())
			{
				Node<L> neighbor = link.other(node);
				
				if(! occurrence.contains(neighbor.index()))
					wiringBits += - log2(om.observe(indexInSubgraph));
			}
		}
	}	
	
	return wiringBits;
}
 
开发者ID:pbloem,项目名称:motive,代码行数:30,代码来源:MotifModel.java

示例5: speed

import org.nodes.Link; //导入依赖的package包/类
public void speed()
{
	DGraph<String> data = org.nodes.random.RandomGraphs.preferentialAttachmentDirected(10000, 3);

	tic();
	for(Link<String> link : data.links())
	{
		int i = 3+5;
	}
	System.out.println(toc());
}
 
开发者ID:pbloem,项目名称:motive,代码行数:12,代码来源:MotifCompressorTest.java

示例6: toString

import org.nodes.Link; //导入依赖的package包/类
public static <L> String toString(Graph<L> graph)
{
	StringBuffer bf = new StringBuffer();
	
	bf.append("graph [ \n");
	
	bf.append("\tdirected " + ((graph instanceof DGraph<?>) ? 1 : 0)+"\n");
	
	// * Nodes
	for(Node<L> node : graph.nodes())
	{
		bf.append("\tnode [ \n");
		bf.append("\t\tid " + node.index()+"\n");
		bf.append("\t\tlabel \"" + esc(node.label().toString()) + "\"\n");
		bf.append("\t]\n");
	}
	
	// * Links
	for(Link<L> link : graph.links())
	{
		bf.append("\tedge [ \n");
		bf.append("\t\tsource " + link.first().index()+"\n");
		bf.append("\t\ttarget " + link.second().index()+"\n");
		if(link instanceof TLink<?,?>)
			bf.append("\t\tlabel \"" + esc( Functions.toString( ((TLink<L, ?>)link).tag() )) + "\"\n");
		bf.append("\t]\n");
	}
	
	bf.append("]\n");
	
	return bf.toString();
}
 
开发者ID:Data2Semantics,项目名称:nodes,代码行数:33,代码来源:GML.java

示例7: degree

import org.nodes.Link; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <L, T> int degree(Node<L> from, List<Node<L>> to, T tag)
{
	int sum = 0;
	
	for(Node<L> node : to) // * this should automatically work right for directed/undirected
		for(Link<L> link : from.links(node))
			if(link instanceof TLink<?, ?>)
				if(Functions.equals(((TLink<Object, Object>)link).tag(), tag))
					sum++;

	return sum;
}
 
开发者ID:Data2Semantics,项目名称:nodes,代码行数:14,代码来源:Nauty.java

示例8: avoid

import org.nodes.Link; //导入依赖的package包/类
private boolean avoid(Link<L> link)
{
	if(toAvoid.contains(link.first()))
		return true;
	if(toAvoid.contains(link.second()))
		return true;

	return false;
}
 
开发者ID:Data2Semantics,项目名称:nodes,代码行数:10,代码来源:SubgraphGenerator.java

示例9: Result

import org.nodes.Link; //导入依赖的package包/类
public Result(List<Node<L>> nodes, List<Link<L>> linkTrail)
{
	this.nodes = nodes;
	this.trail = linkTrail;
	
	indices = new ArrayList<Integer>(nodes.size());
	for(Node<L> node : nodes)
	{
		indices.add(node.index());
		// System.out.println(toAvoid.contains(node) + "++ " + node.degree());
	}
	
	calculateProbability();
}
 
开发者ID:Data2Semantics,项目名称:nodes,代码行数:15,代码来源:SubgraphGenerator.java

示例10: common

import org.nodes.Link; //导入依赖的package包/类
private Node<L> common(Link<L> a, Link<L> b)
{
	List<Node<L>> nodes = new ArrayList<Node<L>>(a.nodes());
	nodes.retainAll(b.nodes());
	
	if(nodes.isEmpty())
		return null;
	
	return nodes.get(0);
}
 
开发者ID:Data2Semantics,项目名称:nodes,代码行数:11,代码来源:SubgraphGenerator.java

示例11: size

import org.nodes.Link; //导入依赖的package包/类
public static <L> double size(Graph<L> graph, Graph<L> sub,
		List<List<Integer>> occurrences, StructureModel<Graph<?>> nullModel, boolean resetWiring)
{
	FrequencyModel<String> bits = new FrequencyModel<String>();

	boolean directed = (graph instanceof DGraph<?>); 

	List<List<Integer>> wiring = new ArrayList<List<Integer>>();
	Set<Integer> motifNodes = new HashSet<Integer>();
	Graph<L> subbed;
	if(directed)
		subbed = subbedGraph((DGraph<L>) graph, occurrences, wiring, motifNodes);
	else
		subbed = subbedGraph((UGraph<L>) graph, occurrences, wiring, motifNodes);
	
	if(nullModel instanceof RestrictedToSimple)
	{
		FrequencyModel<Pair<Integer, Integer>> removals = new FrequencyModel<Pair<Integer,Integer>>();

		if(directed)
			subbed = Graphs.toSimpleDGraph((DGraph<L>)subbed, removals);
		else
			subbed = Graphs.toSimpleUGraph((UGraph<L>)subbed, removals);
		
		List<Integer> additions = new ArrayList<Integer>();
		
		for(Link<L> link : subbed.links())
			if(motifNodes.contains(link.first().index()) || motifNodes.contains((link.second().index())))
			{
				int i = link.first().index(), j = link.second().index();
				
				Pair<Integer, Integer> pair = 
						directed ? Pair.p(i, j) : Pair.p(min(i,  j), max(i, j));
			
				additions.add((int)removals.frequency(pair));
			}
					
		bits.add("multiple-edges", Functions.prefix(additions.isEmpty() ? 0 : (long)Functions.max(additions)));
		bits.add("multiple-edges", OnlineModel.storeIntegers(additions)); 
	}
	
	// * Store the labels
	bits.add("labels", Functions.prefix(occurrences.size()) + log2Choose(occurrences.size(), subbed.size())); 
							
	bits.add("sub", nullModel.codelength(sub));

	bits.add("subbed", nullModel.codelength(subbed));
	
	// * Store the rewiring information
	bits.add("wiring", wiringBits(sub, wiring, resetWiring));
	
	// * Store the insertion order, to preserve the precise ordering of the
	//   nodes in the data 
	bits.add("insertions", log2Factorial(graph.size()) - log2Factorial(subbed.size()));
	
	return bits.total();
}
 
开发者ID:pbloem,项目名称:motive,代码行数:58,代码来源:MotifModel.java

示例12: sizeBetaCopying

import org.nodes.Link; //导入依赖的package包/类
public static <L> double sizeBetaCopying(DGraph<L> graph, DGraph<L> sub,
			List<List<Integer>> occurrences, boolean resetWiring, int iterations, double alpha)
	{		
		int numThreads = Runtime.getRuntime().availableProcessors();
		
		List<List<Integer>> wiring = new ArrayList<List<Integer>>();
		Set<Integer> motifNodes = new HashSet<Integer>();
		DGraph<L> subbed = MotifModel.subbedGraph(graph, occurrences, wiring, motifNodes);
				
		// * the beta model can only store simple graphs, so we translate subbed
		//   to a simple graph and store the multiple edges separately 
		FrequencyModel<Pair<Integer, Integer>> removals = new FrequencyModel<Pair<Integer,Integer>>();
		subbed = Graphs.toSimpleDGraph((DGraph<L>)subbed, removals);
				
		// * The estimated cost of storing the structure of the motif and the 
		//   structure of the subbed graph. 
		List<Double> samples = new ArrayList<Double>(iterations);
		DSequenceEstimator<String> motifModel = new DSequenceEstimator<String>(sub);
		DSequenceEstimator<String> subbedModel = new DSequenceEstimator<String>(subbed);
		motifModel.nonuniform(iterations, numThreads);
		subbedModel.nonuniform(iterations, numThreads);
		
		for(int i : series(iterations))
			samples.add(motifModel.logSamples().get(i) + subbedModel.logSamples().get(i));

		LogNormalCI ci = new LogNormalCI(samples);
		
		// * The rest of the graph (for which we can compute the code length 
		//   directly) 
		FrequencyModel<String> rest = new FrequencyModel<String>();
		
		// * parameters
		rest.add("sub", DegreeSequenceModel.prior((DGraph<?>)sub, Prior.COMPLETE));
		
		// * size of the subbed graph
		// * degree sequence of subbed
		rest.add("subbed", DegreeSequenceModel.prior((DGraph<?>)subbed, Prior.COMPLETE));
		
		// * Store the labels
		rest.add("labels", log2Choose(occurrences.size(), subbed.size())); 
		
		// * Any node pairs with multiple links
		List<Integer> additions = new ArrayList<Integer>();
		for(Link<L> link : subbed.links())
			if(motifNodes.contains(link.first().index()) || motifNodes.contains((link.second().index())))
			{
				int i = link.first().index(), j = link.second().index();
				
				Pair<Integer, Integer> pair =  Pair.p(i, j);
			
				additions.add((int)removals.frequency(pair));
			}
		
		rest.add("multi-edges", Functions.prefix(additions.isEmpty() ? 0 : (long) Functions.max(additions)));
		rest.add("multi-edges", OnlineModel.storeIntegers(additions)); 
				
		// * Store the rewiring information
		rest.add("wiring", MotifModel.wiringBits(sub, wiring, resetWiring));
		
		// * Store the insertion order, to preserve the precise ordering of the
		//   nodes in the data 
		rest.add("insertions", log2Factorial(graph.size()) - log2Factorial(subbed.size()));
		
//		System.out.println("ci : " + ci.upperBound(alpha));
//		rest.print(System.out);
		
		return ci.upperBound(alpha) + rest.total();
	}
 
开发者ID:pbloem,项目名称:motive,代码行数:69,代码来源:MotifModelTest.java

示例13: svg

import org.nodes.Link; //导入依赖的package包/类
public static <L> SVGDocument svg(Graph<L> graph, Layout<L> layout)
{
	// * Set up an SVG generator
	DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
	SVGDocument doc = (SVGDocument) impl.createDocument(ns, "svg", null);

	Element canvas = doc.getDocumentElement();
	canvas.setAttributeNS(null, "width", "2.0");
	canvas.setAttributeNS(null, "height", "2.0");
	
	Element g = doc.createElementNS(ns, "g");
	g.setAttributeNS(null, "transform", "translate(1,1)");
	canvas.appendChild(g);
			
	// * Draw the edges
	for(Link<L> link : graph.links())
	{
		Point a = layout.point(link.first()),
		      b = layout.point(link.second());
		
		
		Element line = doc.createElementNS(ns, "line");
		line.setAttributeNS(null, "x1", "" + a.get(0));
		line.setAttributeNS(null, "y1", "" + a.get(1));
		line.setAttributeNS(null, "x2", "" + b.get(0));
		line.setAttributeNS(null, "y2", "" + b.get(1));

		line.setAttributeNS(null, "stroke", "black");
		line.setAttributeNS(null, "stroke-opacity", "0.1");
		line.setAttributeNS(null, "stroke-width", "0.005");

		g.appendChild(line);
	}	
	
	// * Draw the nodes
	for(Node<L>  node : graph.nodes())
	{
		Point p = layout.point(node);
		
		Element circle = doc.createElementNS(ns, "circle");
		circle.setAttributeNS(null, "cx", "" + p.get(0));
		circle.setAttributeNS(null, "cy", "" + p.get(1));
		circle.setAttributeNS(null, "r", "0.01");
		circle.setAttributeNS(null, "fill", "red");

		g.appendChild(circle);
	}
	

	
	return doc;
}
 
开发者ID:Data2Semantics,项目名称:nodes,代码行数:53,代码来源:Draw.java

示例14: LinkGenerator

import org.nodes.Link; //导入依赖的package包/类
public LinkGenerator(Graph<T> graph)
{
	links = new ArrayList<Link<T>>((int)graph.numLinks());
	for(Link<T> link : graph.links())
		links.add(link);
}
 
开发者ID:Data2Semantics,项目名称:nodes,代码行数:7,代码来源:LinkGenerators.java

示例15: generate

import org.nodes.Link; //导入依赖的package包/类
@Override
public Link<T> generate()
{	
	int i = Global.random().nextInt(links.size());
	return links.get(i);
}
 
开发者ID:Data2Semantics,项目名称:nodes,代码行数:7,代码来源:LinkGenerators.java


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