Example of code for learning Loopy CRF exactly

125 views
Skip to first unread message

Alessandro Ferrari

unread,
Oct 31, 2015, 3:38:25 PM10/31/15
to pystruct
Is there any example on how implement learning similarly as in Ch.6 of Andreas Muellur thesis, so to switch inference to ad3?
Thank you a lot,
Alessandro

Andreas Mueller

unread,
Nov 1, 2015, 9:33:54 PM11/1/15
to pyst...@googlegroups.com
Hi Alessandro.
There is an example here:
http://pystruct.github.io/auto_examples/plot_exact_learning.html#example-plot-exact-learning-py

If you want the full code from the thesis, let me know.
I should be able to dig it up.

Cheers,
Andy
--
You received this message because you are subscribed to the Google Groups "pystruct" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pystruct+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alessandro Ferrari

unread,
Dec 3, 2015, 8:42:13 AM12/3/15
to pystruct
Hi Andreas,
                 does this support EdgeFeaturesGraphCRF models?
I have tried to call it like:

crf = EdgeFeatureGraphCRF(inference_method="qpbo")
ssvm = OneSlackSSVM(model=crf, n_jobs=1, inference_cache = 100, show_loss_every = 10,switch_to=("ad3",{"branch_and_bound":True}),tol=0.0001)
ssvm.fit(X_train,y_train)

and I get this error:

Traceback (most recent call last):
  File "/home/imaging/workspace/virtualenv_ale/libCHunter/source/tools/cnn_colonies_identification/train_edge_graph_crf.py", line 32, in <module>
    ssvm.fit(X_train,y_train)
  File "/usr/local/lib/python2.7/dist-packages/pystruct/learners/one_slack_ssvm.py", line 429, in fit
    joint_feature_gt = self.model.batch_joint_feature(X, Y)
  File "/usr/local/lib/python2.7/dist-packages/pystruct/models/base.py", line 40, in batch_joint_feature
    joint_feature_ += self.joint_feature(x, y)
  File "/usr/local/lib/python2.7/dist-packages/pystruct/models/edge_feature_graph_crf.py", line 190, in joint_feature
    class_pair_ind = (y[edges[:, 1]] + self.n_states *
IndexError: too many indices

while if I call with the same dataset:

everything worked like a charm.

Thank you,
Ale

Andy

unread,
Dec 5, 2015, 5:52:17 PM12/5/15
to pyst...@googlegroups.com
Hi Ale.
Yes, it does. But you need to construct X in a way that is compatible with EdgeFeatureGraphCRF,
see the docstring here:
http://pystruct.github.io/generated/pystruct.models.EdgeFeatureGraphCRF.html#pystruct.models.EdgeFeatureGraphCRF

You need to provide node-features, edges and edge-features in this order for each x.

Hth,
Andy
Reply all
Reply to author
Forward
0 new messages