Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All factors as scalar multiple of ONE function #503

Open
ynandwan opened this issue Aug 17, 2018 · 0 comments
Open

All factors as scalar multiple of ONE function #503

ynandwan opened this issue Aug 17, 2018 · 0 comments

Comments

@ynandwan
Copy link

ynandwan commented Aug 17, 2018

While creating a graphical model for solving computer vision problems, we often use contrast sensitive weights for edges in the graph - i.e., each edge factor is alpha*(some standard function, say potts). Is it possible to add only ONE function (potts) to the graphical model and create all the factors as some scalar multiplication of that function where the scalar is different for different edges?

In the examples that I found on GitHub python examples, factor corresponding to all the edges is always the same function. Right now I am doing the following, which takes a lot of time and memory -

Code snipet -

#edges is a numpy array with dim - e x 3. edges[i] is an edge b/w nodes - edges[i,0] and edges[i,1]. Contrast sensitive wt is edges[i,2]

e = len(edges)
P1 = 1
P2 = 12
k = 128
n = 375*1245
gm = opengm.gm(np.ones(n, dtype=opengm.label_type)*k,operator='adder')
for i in range(e):
    cs_wt = edges[i,2]
    f = opengm.SparseFunction(shape=[k,k],defaultValue=cs_wt*P2)
    p1 = P1*cs_wt
    for j in range(k):
        f[j,j] = 0
        f[j,j+1] = p1
        f[j,j-1] = p1
    #
    pf_id = gm.addFunction(f)
    gm.addFactor(pf_id, [int(edges[i, 0]), int(edges[i, 1])])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant