本文整理汇总了Python中graph_tool.Graph.vertex_properties['confidence']方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.vertex_properties['confidence']方法的具体用法?Python Graph.vertex_properties['confidence']怎么用?Python Graph.vertex_properties['confidence']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph_tool.Graph
的用法示例。
在下文中一共展示了Graph.vertex_properties['confidence']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_graph
# 需要导入模块: from graph_tool import Graph [as 别名]
# 或者: from graph_tool.Graph import vertex_properties['confidence'] [as 别名]
def build_graph(df_list, sens='ST', top=410, min_sens=0.01,
edge_cutoff=0.0):
"""
Initializes and constructs a graph where vertices are the parameters
selected from the first dataframe in 'df_list', subject to the
constraints set by 'sens', 'top', and 'min_sens'. Edges are the second
order sensitivities of the interactions between those vertices,
with sensitivities greater than 'edge_cutoff'.
Parameters
-----------
df_list : list
A list of two dataframes. The first dataframe should be
the first/total order sensitivities collected by the
function data_processing.get_sa_data().
sens : str, optional
A string with the name of the sensitivity that you would
like to use for the vertices ('ST' or 'S1').
top : int, optional
An integer specifying the number of vertices to display (
the top sensitivity values).
min_sens : float, optional
A float with the minimum sensitivity to allow in the graph.
edge_cutoff : float, optional
A float specifying the minimum second order sensitivity to
show as an edge in the graph.
Returns
--------
g : graph-tool object
a graph-tool graph object of the network described above. Each
vertex has properties 'param', 'sensitivity', and 'confidence'
corresponding to the name of the parameter, value of the sensitivity
index, and it's confidence interval. The only edge property is
'second_sens', the second order sensitivity index for the
interaction between the two vertices it connects.
"""
# get the first/total index dataframe and second order dataframe
df = df_list[0]
df2 = df_list[1]
# Make sure sens is ST or S1
if sens not in set(['ST', 'S1']):
raise ValueError('sens must be ST or S1')
# Make sure that there is a second order index dataframe
try:
if not df2:
raise Exception('Missing second order dataframe!')
except:
pass
# slice the dataframes so the resulting graph will only include the top
# 'top' values of 'sens' greater than 'min_sens'.
df = df.sort_values(sens, ascending=False)
df = df.ix[df[sens] > min_sens, :].head(top)
df = df.reset_index()
# initialize a graph
g = Graph()
vprop_sens = g.new_vertex_property('double')
vprop_conf = g.new_vertex_property('double')
vprop_name = g.new_vertex_property('string')
eprop_sens = g.new_edge_property('double')
g.vertex_properties['param'] = vprop_name
g.vertex_properties['sensitivity'] = vprop_sens
g.vertex_properties['confidence'] = vprop_conf
g.edge_properties['second_sens'] = eprop_sens
# keep a list of all the vertices
v_list = []
# Add the vertices to the graph
for i, param in enumerate(df['Parameter']):
v = g.add_vertex()
vprop_sens[v] = df.ix[i, sens]
vprop_conf[v] = 1 + df.ix[i, '%s_conf' % sens] / df.ix[i, sens]
vprop_name[v] = param
v_list.append(v)
# Make two new columns in second order dataframe that point to the vertices
# connected on each row.
df2['vertex1'] = -999
df2['vertex2'] = -999
for vertex in v_list:
param = g.vp.param[vertex]
df2.ix[df2['Parameter_1'] == param, 'vertex1'] = vertex
df2.ix[df2['Parameter_2'] == param, 'vertex2'] = vertex
# Only allow edges for vertices that we've defined
df_edges = df2[(df2['vertex1'] != -999) & (df2['vertex2'] != -999)]
# eliminate edges below a certain cutoff value
pruned = df_edges[df_edges['S2'] > edge_cutoff]
pruned.reset_index(inplace=True)
# Add the edges for the graph
for i, sensitivity in enumerate(pruned['S2']):
v1 = pruned.ix[i, 'vertex1']
v2 = pruned.ix[i, 'vertex2']
#.........这里部分代码省略.........