User Tools

Site Tools


chicoutimi_2016:focus_context_graph

Visual Analytics Course

Instructor: Guy Melançon (email: Guy dot Melancon at labri dot fr)

Chicoutimi Summer 2016 roadmap / May 27, 9am course

DOI sur un graphe (van Ham) et affichage du contexte

Attention

Cet algorithme calcule la valeur DOI des sommets en fonction d'un focus, d'une fonction d'intérêt utilisateur et de la distance au focus.

Contrairement au DOA sur les graphes (implémenté ici), on ne calcule pas une vue abstraite du graphe, mais un sous-graphe apportant un contexte au focus.

Une version calculant un contexte élargi avec méta-sommets va suivre.

DOIContext.py
from tulip import *
 
class DOIContext(object):
	"""docstring for DOIContexte"""
	def __init__(self, graph, name_original_graph = 'original_graph'):
		super(DOIContext, self).__init__()
		self.graph = graph
		self.original_graph = self.graph.getSubGraph(name_original_graph)
 
		self.API_metric = self.original_graph.getDoubleProperty('API')
		self.API_metric.setAllNodeValue(1.0)
		self.UI_metric = self.original_graph.getDoubleProperty('UI')
		self.UI_metric.setAllNodeValue(1.0)
		self.DOI_metric = self.original_graph.getDoubleProperty('DOI')
 
	def get_focus_node(self):
		selection = self.original_graph.getBooleanProperty('viewSelection')
		focus = None
		for n in self.original_graph.getNodes():
			if selection[n]:
				focus = n
				break
		return focus
 
	def set_API(self, double_property):
		for n in self.original_graph.getNodes():
			self.API_metric[n] = double_property[n]
 
	def compute_DOI(self, focus_node):
		dist = self.original_graph.getIntegerProperty('distance_to_focus')
		tlp.maxDistance(self.original_graph, focus_node, dist, tlp.UNDIRECTED)
		for n in self.original_graph.getNodes():
			self.DOI_metric[n] = self.API_metric[n] + self.UI_metric[n] - dist[n]
 
	def compute_context_subgraph(self, focus_node, max_size = 20):
		color = self.original_graph.getColorProperty('viewColor')
		color.setAllNodeValue(tlp.Color(255,64,64))
		focus_node = self.get_focus_node()
		self.compute_DOI(focus_node)
		focus_nodeset = set()
		candidates = [focus_node]
		while len(candidates) > 0 and  len(focus_nodeset) < 20:
			c = sorted(candidates, key=lambda x: self.DOI_metric[x]).pop()
			candidates.pop(candidates.index(c))
			focus_nodeset.add(c)
			color[c] = tlp.Color(0, 0, 255)
			for n in self.original_graph.getInOutNodes(c):
				if not n in focus_nodeset and not n in candidates:
					candidates.append(n)
		context_subgraph = self.original_graph.inducedSubGraph(focus_nodeset)
		context_subgraph.setName('context')
		return context_subgraph
 
	def show_context_subgraph(self, context_subgraph):
		context_view = None
		for v in tlpgui.getOpenedViews():
			if type(v) == tlpgui.NodeLinkDiagramComponent and v.graph().getName() == 'context':
				context_view = v
				context_view.setGraph(context_subgraph)
		if context_view == None:
			# need to create view
			context_view = tlpgui.createNodeLinkDiagramView(context_subgraph)
 
def main(graph):
	doi = DOIContext(graph)
 
	dataset = tlp.getDefaultPluginParameters('Degree', graph)
	degree = doi.original_graph.getDoubleProperty('degree')
	graph.applyDoubleAlgorithm('Degree', degree, dataset)
 
	dataset = tlp.getDefaultPluginParameters('Betweenness Centrality', graph)
	bc = doi.original_graph.getDoubleProperty('betweenness')
	graph.applyDoubleAlgorithm('Betweenness Centrality', bc, dataset)
 
	doi.set_API(bc)
 
	f = doi.get_focus_node()
	doi.compute_DOI(f)
	context_subgraph = doi.compute_context_subgraph(f)
	doi.show_context_subgraph(context_subgraph)
/net/html/perso/melancon/Visual_Analytics_Course/data/pages/chicoutimi_2016/focus_context_graph.txt · Last modified: 2016/05/28 15:23 by melancon