Skip to content

Commit ffbe408

Browse files
committed
Minor fixes
1 parent 9f9e061 commit ffbe408

File tree

7 files changed

+12
-14
lines changed

7 files changed

+12
-14
lines changed

mla/base/base.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
import numpy as np
33

44

5-
class BaseEstimator(object):
6-
X = None
7-
y = None
5+
class BaseEstimator:
86
y_required = True
97
fit_required = True
108

@@ -28,7 +26,7 @@ def _setup_input(self, X, y=None):
2826
X = np.array(X)
2927

3028
if X.size == 0:
31-
raise ValueError("Number of features must be > 0")
29+
raise ValueError("Got an empty matrix.")
3230

3331
if X.ndim == 1:
3432
self.n_samples, self.n_features = 1, X.shape
@@ -45,7 +43,7 @@ def _setup_input(self, X, y=None):
4543
y = np.array(y)
4644

4745
if y.size == 0:
48-
raise ValueError("Number of targets must be > 0")
46+
raise ValueError("The targets array must be no-empty.")
4947

5048
self.y = y
5149

mla/datasets/base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def load(dataset="training", digits=np.arange(10)):
1919
elif dataset == "test":
2020
fname_img = get_filename("data/mnist/t10k-images-idx3-ubyte")
2121
fname_lbl = get_filename("data/mnist/t10k-labels-idx1-ubyte")
22+
else:
23+
raise ValueError("Unexpected dataset name: %r" % dataset)
2224

2325
flbl = open(fname_lbl, "rb")
2426
magic_nr, size = struct.unpack(">II", flbl.read(8))
@@ -36,7 +38,7 @@ def load(dataset="training", digits=np.arange(10)):
3638
images = zeros((N, rows, cols), dtype=uint8)
3739
labels = zeros((N, 1), dtype=int8)
3840
for i in range(len(ind)):
39-
images[i] = array(img[ind[i] * rows * cols : (ind[i] + 1) * rows * cols]).reshape((rows, cols))
41+
images[i] = array(img[ind[i] * rows * cols: (ind[i] + 1) * rows * cols]).reshape((rows, cols))
4042
labels[i] = lbl[ind[i]]
4143

4244
return images, labels

mla/neuralnet/optimizers.py

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ def setup(self, network):
198198
self.ms[i][n] = np.zeros_like(layer.parameters[n])
199199
self.vs[i][n] = np.zeros_like(layer.parameters[n])
200200

201+
201202
class Adamax(Optimizer):
202203
def __init__(self, learning_rate=0.002, beta_1=0.9, beta_2=0.999, epsilon=1e-8):
203204

mla/pca.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _decompose(self, X):
4747
Vh = Vh.T
4848

4949
s_squared = s ** 2
50-
variance_ratio = s_squared / (s_squared).sum()
50+
variance_ratio = s_squared / s_squared.sum()
5151
logging.info("Explained variance ratio: %s" % (variance_ratio[0: self.n_components]))
5252
self.components = Vh[0: self.n_components]
5353

mla/rbm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _train(self):
6464
positive_associations = np.dot(batch.T, positive_hidden)
6565

6666
negative_visible = sigmoid(np.dot(hidden_states, self.W.T) + self.bias_v)
67-
negative_visible = self._sample(negative_visible) # use the samped hidden state h1 to sample v1
67+
negative_visible = self._sample(negative_visible) # use the sampled hidden state h1 to sample v1
6868
negative_hidden = sigmoid(np.dot(negative_visible, self.W) + self.bias_h)
6969
negative_associations = np.dot(negative_visible.T, negative_hidden)
7070

mla/svm/svm.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,11 @@ def _train(self):
7373

7474
# Find intercept
7575
b1 = (
76-
self.b
77-
- e_i
78-
- self.y[i] * (self.alpha[i] - alpha_io) * self.K[i, i]
76+
self.b - e_i - self.y[i] * (self.alpha[i] - alpha_io) * self.K[i, i]
7977
- self.y[j] * (self.alpha[j] - alpha_jo) * self.K[i, j]
8078
)
8179
b2 = (
82-
self.b
83-
- e_j
84-
- self.y[j] * (self.alpha[j] - alpha_jo) * self.K[j, j]
80+
self.b - e_j - self.y[j] * (self.alpha[j] - alpha_jo) * self.K[j, j]
8581
- self.y[i] * (self.alpha[i] - alpha_io) * self.K[i, j]
8682
)
8783
if 0 < self.alpha[i] < self.C:

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ scipy>=0.18.0
66
seaborn>=0.7.1
77
six>=1.10.0
88
autograd>=1.1.7
9+
gym

0 commit comments

Comments
 (0)