Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e55a870

Browse files
committed
update website for 0.2.2, add better installation instruction
1 parent 148e089 commit e55a870

File tree

160 files changed

+12920
-21422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+12920
-21422
lines changed

_downloads/multi_label.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
2-
=========================
3-
Mult-label classification
4-
=========================
2+
==========================
3+
Multi-label classification
4+
==========================
55
This example shows how to use structured support vector machines
66
(or structured prediction in general) to do multi-label classification.
77
@@ -26,11 +26,7 @@
2626
from sklearn.metrics import hamming_loss
2727
from sklearn.datasets import fetch_mldata
2828
from sklearn.metrics import mutual_info_score
29-
try:
30-
from sklearn.utils import minimum_spanning_tree
31-
except ImportError:
32-
raise ImportError("Please install a recent version of scikit-learn or"
33-
"scipy to build minimum spanning trees.")
29+
from scipy.sparse.csgraph import minimum_spanning_tree
3430

3531
from pystruct.learners import OneSlackSSVM
3632
from pystruct.models import MultiLabelClf
@@ -51,7 +47,7 @@ def chow_liu_tree(y_):
5147

5248

5349
dataset = "scene"
54-
#dataset = "yeast"
50+
# dataset = "yeast"
5551

5652
if dataset == "yeast":
5753
yeast = fetch_mldata("yeast")
@@ -74,7 +70,7 @@ def chow_liu_tree(y_):
7470

7571
full_model = MultiLabelClf(edges=full, inference_method='qpbo')
7672
independent_model = MultiLabelClf(inference_method='unary')
77-
tree_model = MultiLabelClf(edges=tree)
73+
tree_model = MultiLabelClf(edges=tree, inference_method="max-product")
7874

7975
full_ssvm = OneSlackSSVM(full_model, inference_cache=50, C=.1, tol=0.01)
8076

_downloads/plot_binary_svm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
We don't really have a chance to beat LibSVM but that's ok ;)
1111
1212
"""
13-
print __doc__
13+
print(__doc__)
1414

1515
from time import time
1616
import numpy as np

_downloads/plot_directional_grid.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
===========================================
33
Learning directed interactions on a 2d grid
44
===========================================
5+
56
Simple pairwise model with arbitrary interactions on a 4-connected grid.
67
There are different pairwise potentials for the four directions.
78
All the examples are basically the same, three vertical stripes.

_downloads/plot_grid_crf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
X, Y = generate_crosses_explicit(n_samples=50, noise=10)
2323
crf = GridCRF(neighborhood=4)
24-
clf = ssvm.OneSlackSSVM(model=crf, C=100, n_jobs=-1, inference_cache=100,
24+
clf = ssvm.OneSlackSSVM(model=crf, C=100, inference_cache=100,
2525
tol=.1)
2626
clf.fit(X, Y)
2727
Y_pred = np.array(clf.predict(X))

_downloads/plot_latent_crf.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@
2424

2525

2626
X, Y = generate_crosses(n_samples=20, noise=5, n_crosses=1, total_size=8)
27-
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=.5)
27+
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=.5,
28+
force_arrays=False)
2829

2930
crf = LatentGridCRF(n_states_per_label=[1, 2])
3031
base_ssvm = OneSlackSSVM(model=crf, C=10., n_jobs=-1, inference_cache=20,
3132
tol=.1)
3233
clf = LatentSSVM(base_ssvm=base_ssvm)
3334
clf.fit(X_train, Y_train)
34-
print("loss training set: %f" % clf.score(X_train, Y_train))
35-
print("loss test set: %f" % clf.score(X_test, Y_test))
35+
print("Score training set: %f" % clf.score(X_train, Y_train))
36+
print("Score test set: %f" % clf.score(X_test, Y_test))
3637

3738
Y_pred = clf.predict(X_test)
3839

_downloads/plot_latent_node.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
=================================
33
Latent Variable Hierarchical CRF
44
=================================
5+
56
Solving a 2d grid toy problem by introducing an additional layer of latent
67
variables.
78
"""
@@ -62,7 +63,7 @@ def plot_boxes(boxes, size=4, title=""):
6263
latent_crf = LatentNodeCRF(n_labels=2, n_features=1, n_hidden_states=2,
6364
inference_method='lp')
6465

65-
ssvm = OneSlackSSVM(model=latent_crf, max_iter=200, C=100, verbose=1,
66+
ssvm = OneSlackSSVM(model=latent_crf, max_iter=200, C=100,
6667
n_jobs=-1, show_loss_every=10, inference_cache=50)
6768
latent_svm = LatentSSVM(ssvm)
6869

_downloads/plot_letters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
# Train linear chain CRF
5757
model = ChainCRF()
58-
ssvm = OneSlackSSVM(model=model, C=.1, inference_cache=50, tol=0.1, verbose=3)
58+
ssvm = OneSlackSSVM(model=model, C=.1, inference_cache=50, tol=0.1)
5959
ssvm.fit(X_train, y_train)
6060

6161
print("Test score with chain CRF: %f" % ssvm.score(X_test, y_test))

_downloads/plot_potts_model.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
=================================================
3+
Comparing inference times on a simple Potts model
4+
=================================================
5+
6+
Simple exmaple comparing inference times on a Potts model.
7+
"""
8+
9+
import numpy as np
10+
import matplotlib.pyplot as plt
11+
12+
from time import time
13+
14+
from pystruct.inference import inference_dispatch, compute_energy
15+
from pystruct.utils import make_grid_edges
16+
17+
size = 20
18+
n_states = 5
19+
20+
rnd = np.random.RandomState(2)
21+
x = rnd.normal(size=(size, size, n_states))
22+
pairwise = np.eye(n_states)
23+
edges = make_grid_edges(x)
24+
unaries = x.reshape(-1, n_states)
25+
26+
fig, ax = plt.subplots(1, 6)
27+
for a, inference_method in zip(ax, ['ad3', ('ad3', {'branch_and_bound': True}),
28+
'qpbo', 'max-product', 'lp']):
29+
start = time()
30+
y = inference_dispatch(unaries, pairwise, edges,
31+
inference_method=inference_method)
32+
took = time() - start
33+
a.matshow(y.reshape(size, size))
34+
energy = compute_energy(unaries, pairwise, edges, y)
35+
a.set_title("time: %.2f energy %.2f" % (took, energy))
36+
a.set_xticks(())
37+
a.set_yticks(())
38+
plt.show()

_downloads/plot_snakes.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@
4040
from pystruct.datasets import load_snakes
4141
from pystruct.utils import make_grid_edges, edge_list_to_features
4242
from pystruct.models import EdgeFeatureGraphCRF
43-
from pystruct.inference import get_installed
4443

4544

4645
def one_hot_colors(x):
4746
x = x / 255
48-
flat = np.dot(x.reshape(-1, 3), 2 ** np.arange(3))
47+
flat = np.dot(x.reshape(-1, 3), 2 ** np.arange(3))
4948
one_hot = label_binarize(flat, classes=[1, 2, 3, 4, 6])
5049
return one_hot.reshape(x.shape[0], x.shape[1], 5)
5150

@@ -93,7 +92,7 @@ def prepare_data(X):
9392
return X_directions, X_edge_features
9493

9594

96-
print("Please be patient. Will take 5-20 minutes.")
95+
print("Please be patient. Learning will take 5-20 minutes.")
9796
snakes = load_snakes()
9897
X_train, Y_train = snakes['X_train'], snakes['Y_train']
9998

@@ -102,10 +101,7 @@ def prepare_data(X):
102101

103102
X_train_directions, X_train_edge_features = prepare_data(X_train)
104103

105-
if 'ogm' in get_installed():
106-
inference = ('ogm', {'alg': 'fm'})
107-
else:
108-
inference = 'qpbo'
104+
inference = 'qpbo'
109105
# first, train on X with directions only:
110106
crf = EdgeFeatureGraphCRF(inference_method=inference)
111107
ssvm = OneSlackSSVM(crf, inference_cache=50, C=.1, tol=.1, max_iter=100,

_downloads/plot_svm_objectives.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
max_iter=100, tol=0.001, inference_cache=50)
2929
subgradient_svm = SubgradientSSVM(crf, learning_rate=0.001, max_iter=20,
3030
decay_exponent=0, momentum=0)
31-
bcfw_svm = FrankWolfeSSVM(crf, max_iter=50, verbose=2, check_dual_every=4)
31+
bcfw_svm = FrankWolfeSSVM(crf, max_iter=50, check_dual_every=4)
3232

3333
#n-slack cutting plane ssvm
3434
n_slack_svm.fit(X, Y)

0 commit comments

Comments
 (0)