Closed DanqingZ closed 7 years ago
We unfortunately don’t have an elegant way to incorporate two sets of edges to the same set of nodes, but I do think there are workarounds you can use.
Your code will overwrite any previous edges between those two nodes, so that won't work. Instead, if edge_ij has both types (social and spatial), you'll have to add them simultaneously - i.e. something like gvx.AddEdge(i,j,Objective=L1_norm(src['x']-dst['x']) + L2_square(src['x'] - dst['x']).
It might take a bit longer to set up the problem, but scalability-wise it shouldn't affect the runtime.
As for the combined backtracking error, it might go away once you change the code. If not, it depends on your optimization problem, but it looks like it might be due to this: https://github.com/embotech/ecos/issues/134 (ECOS is the underlying solver we call for the ADMM subproblems). If that continues being an issue, let us know and I can help you call another solver.
what is i and j in gvx.AddEdge(i,j,Objective=L1norm(src['x']-dst['x']) + L2square(src['x'] - dst['x'])? It seems they node index here, but src in src['x'] is the node class. how could I return to node class when I just have node index? just go over snap.py,but could not find one...
This is the current code I have, but stuck on the step how to add objectives and constraints of edges through a loop
num_nodes = 500
temp = GenRndDegK(num_nodes, 3)
gvx2= TGraphVX()
for i in range(500):
W = Variable(3,name='W')
b = Variable(1,name='b')
# obj = logistic(-y[i]*x.T*A[i,:])
obj = logistic(A[i,:].T*W+b-y[i])
gvx2.AddNode(i, Objective=obj)
L1 = 0.02
for EI in temp.Edges():
count = count +1
if count % epoch ==0:
print "edge (%d, %d)" % (EI.GetSrcNId(), EI.GetDstNId())
a = EI.GetSrcNId()
b = EI.GetDstNId()
gvx2.AddEdge(a,b,Objective=L1*norm(a['b']-b['b']),Constraints=[a['W']-b['W']])
edges = []
for EI in temp.Edges():
count = count +1
if count % epoch ==0:
print "edge (%d, %d)" % (EI.GetSrcNId(), EI.GetDstNId())
edges.append([EI.GetSrcNId(), EI.GetDstNId()])
count = 0
for i in range(500):
if [i,i+1] not in edges and [i+1,i] not in edges:
count +=1
j = i+1
gvx2.AddEdge(i,j,Constraints=[i['W']-j['W']])
print count
when I just have the node_id, I do not know how to get node variables to use them in edge objectives and edge constraints. That is exactly my question.
To get the node variable from the node id, you use gvx.GetNodeVariables(node_id). It will return a dictionary of 'var_name':variable, so to get the variable 'x' from node 3, you would do
temp = gvx.GetNodeVariables(3) varX = temp['x']
Hi all,
I have a general question about SnapVX.
Currently I have a social network with location information of each individual, which mean apart from the social network, I also have neighborhood based on geographical information. My assumptions of the model is that: the people who are connected have similar coefficients, the people who are in the same neighborhood have similar coefficients.
That means I have two sets of edges based on current nodes, then I can add two sets of network lasso terms.I am wondering if current SnapVX package can handle this problem?
My current implementation is that I add that I construct graph based on social network and first add edge constraints:
Add then loop within neighborhood to add neighborhood effect:
But it seems but implementation is not working anyway: