@@ -0,0 +1,1380 @@
+import numpy as np%0Afrom scipy import sparse%0A%0Afrom sklearn.cross_validation import train_test_split%0Afrom scipy.sparse.csgraph import minimum_spanning_tree%0A%0Afrom pystruct.learners import SubgradientSSVM%0Afrom pystruct.models import GraphCRF%0A%0A%0Adef make_random_trees(n_samples=50, n_nodes=100, n_states=7, n_features=10):%0A    crf = GraphCRF(inference_method='max-product', n_states=n_states,%0A                   n_features=n_features)%0A    weights = np.random.randn(crf.size_joint_feature)%0A    X, y = %5B%5D, %5B%5D%0A    for i in range(n_samples):%0A        distances = np.random.randn(n_nodes, n_nodes)%0A        features = np.random.randn(n_nodes, n_features)%0A        tree = minimum_spanning_tree(sparse.csr_matrix(distances))%0A        edges = np.c_%5Btree.nonzero()%5D%0A        X.append((features, edges))%0A        y.append(crf.inference(X%5B-1%5D, weights))%0A%0A    return X, y, weights%0A%0A%0AX, y, weights = make_random_trees(n_nodes=1000)%0A%0AX_train, X_test, y_train, y_test = train_test_split(X, y)%0A%0A#tree_model = MultiLabelClf(edges=tree, inference_method=('ogm', %7B'alg': 'dyn'%7D))%0Atree_model = GraphCRF(inference_method='max-product')%0A%0Atree_ssvm = SubgradientSSVM(tree_model, max_iter=4, C=1, verbose=10)%0A%0Aprint(%22fitting tree model...%22)%0Atree_ssvm.fit(X_train, y_train)%0A%0Aprint(%22Training loss tree model: %25f%22 %25 tree_ssvm.score(X_train, y_train))%0Aprint(%22Test loss tree model: %25f%22 %25 tree_ssvm.score(X_test, y_test))%0A

add random tree benchmark