Skip to content

Commit ba450f8

Browse files
committed
Minor fixes
1 parent d2de145 commit ba450f8

Some content is hidden

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

42 files changed

+62
-21
lines changed

examples/rbm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def print_curve(rbm):
1313
def moving_average(a, n=25):
1414
ret = np.cumsum(a, dtype=float)
1515
ret[n:] = ret[n:] - ret[:-n]
16-
return ret[n - 1 :] / n
16+
return ret[n - 1:] / n
1717

1818
plt.plot(moving_average(rbm.errors))
1919
plt.show()

examples/rl_deep_q_learning.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def mlp_model(n_actions, batch_size=64):
3131
# You can stop training process using Ctrl+C signal
3232
# Read more about this problem: https://gym.openai.com/envs/CartPole-v0
3333
model.train(render=False)
34-
except:
34+
except KeyboardInterrupt:
3535
pass
3636
# Render trained model
3737
model.play(episodes=100)

mla/base/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# coding:utf-8
12
from .base import *

mla/base/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import numpy as np
23

34

mla/datasets/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# coding:utf-8
12
from mla.datasets.base import *

mla/datasets/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import os
23
import numpy as np
34

@@ -60,7 +61,7 @@ def load_nietzsche():
6061
sentences = []
6162
next_chars = []
6263
for i in range(0, len(text) - maxlen, step):
63-
sentences.append(text[i : i + maxlen])
64+
sentences.append(text[i: i + maxlen])
6465
next_chars.append(text[i + maxlen])
6566

6667
X = np.zeros((len(sentences), maxlen, len(chars)), dtype=np.bool)

mla/ensemble/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# coding:utf-8
12
from .random_forest import RandomForestClassifier, RandomForestRegressor

mla/ensemble/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import numpy as np
23
from scipy import stats
34

mla/ensemble/gbm.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import numpy as np
23

34
# logistic function

mla/ensemble/random_forest.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import numpy as np
23

34
from mla.base import BaseEstimator

mla/ensemble/tree.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import random
23

34
import numpy as np

mla/fm.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding:utf-8
2+
13
from mla.base import BaseEstimator
24
from mla.metrics import mean_squared_error, binary_crossentropy
35
import autograd.numpy as np

mla/gaussian_mixture.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding:utf-8
2+
13
import random
24
import numpy as np
35
from scipy.stats import multivariate_normal
@@ -65,7 +67,7 @@ def _initialize(self):
6567
self.weights = np.ones(self.K)
6668
if self.init == "random":
6769
self.means = [self.X[x] for x in random.sample(range(self.n_samples), self.K)]
68-
self.covs = [np.cov(self.X.T) for _ in range(K)]
70+
self.covs = [np.cov(self.X.T) for _ in range(self.K)]
6971

7072
elif self.init == "kmeans":
7173
kmeans = KMeans(K=self.K, max_iters=self.max_iters // 3, init="++")

mla/kmeans.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding:utf-8
2+
13
import random
24
import seaborn as sns
35
import matplotlib.pyplot as plt

mla/knn.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding:utf-8
2+
13
from collections import Counter
24

35
import numpy as np

mla/linear_models.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding:utf-8
2+
13
import logging
24

35
import autograd.numpy as np

mla/metrics/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# coding:utf-8
12
from .metrics import *

mla/metrics/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import numpy as np
23

34

mla/metrics/distance.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import numpy as np
23
import math
34

mla/metrics/metrics.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import autograd.numpy as np
23

34
EPS = 1e-15
@@ -83,5 +84,5 @@ def get_metric(name):
8384
"""Return metric function by name"""
8485
try:
8586
return globals()[name]
86-
except:
87+
except Exception:
8788
raise ValueError("Invalid metric function.")

mla/naive_bayes.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding:utf-8
2+
13
import numpy as np
24
from mla.base import BaseEstimator
35
from mla.neuralnet.activations import softmax

mla/neuralnet/activations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ def get_activation(name):
4747
"""Return activation function by name"""
4848
try:
4949
return globals()[name]
50-
except:
50+
except Exception:
5151
raise ValueError("Invalid activation function.")

mla/neuralnet/initializations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ def get_initializer(name):
7171
"""Returns initialization function by the name."""
7272
try:
7373
return globals()[name]
74-
except:
74+
except Exception:
7575
raise ValueError("Invalid initialization function.")

mla/neuralnet/layers/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
from .basic import *
23
from .convnet import *
34
from .normalization import *

mla/neuralnet/layers/basic.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import autograd.numpy as np
23
from autograd import elementwise_grad
34

mla/neuralnet/layers/convnet.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def image_to_column(images, filter_shape, stride, padding):
145145
y_bound = y + stride[0] * out_height
146146
for x in range(f_width):
147147
x_bound = x + stride[1] * out_width
148-
col[:, :, y, x, :, :] = images[:, :, y : y_bound : stride[0], x : x_bound : stride[1]]
148+
col[:, :, y, x, :, :] = images[:, :, y: y_bound: stride[0], x: x_bound: stride[1]]
149149

150150
col = col.transpose(0, 4, 5, 1, 2, 3).reshape(n_images * out_height * out_width, -1)
151151
return col
@@ -177,9 +177,9 @@ def column_to_image(columns, images_shape, filter_shape, stride, padding):
177177
y_bound = y + stride[0] * out_height
178178
for x in range(f_width):
179179
x_bound = x + stride[1] * out_width
180-
img[:, :, y : y_bound : stride[0], x : x_bound : stride[1]] += columns[:, :, y, x, :, :]
180+
img[:, :, y: y_bound: stride[0], x: x_bound: stride[1]] += columns[:, :, y, x, :, :]
181181

182-
return img[:, :, padding[0] : height + padding[0], padding[1] : width + padding[1]]
182+
return img[:, :, padding[0]: height + padding[0], padding[1]: width + padding[1]]
183183

184184

185185
def convoltuion_shape(img_height, img_width, filter_shape, stride, padding):

mla/neuralnet/layers/normalization.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
from mla.neuralnet.layers import Layer, PhaseMixin, ParamMixin
23
from mla.neuralnet.parameters import Parameters
34
import numpy as np
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
# coding:utf-8
12
from .rnn import *
23
from .lstm import *

mla/neuralnet/layers/recurrent/lstm.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import autograd.numpy as np
23
from autograd import elementwise_grad
34
from six.moves import range

mla/neuralnet/layers/recurrent/rnn.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import autograd.numpy as np
23
from autograd import elementwise_grad
34
from six.moves import range

mla/neuralnet/loss.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
def get_loss(name):
77
"""Returns loss function by the name."""
8-
98
try:
109
return globals()[name]
11-
except:
10+
except KeyError:
1211
raise ValueError("Invalid metric function.")

mla/neuralnet/nnet.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313

1414
"""
1515
Architecture inspired from:
16-
https://github.com/fchollet/keras
17-
https://github.com/andersbll/deeppy
16+
17+
https://github.com/fchollet/keras
18+
https://github.com/andersbll/deeppy
1819
"""
1920

2021

mla/neuralnet/optimizers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
"""
1111
References:
12-
Gradient descent optimization algorithms http://sebastianruder.com/optimizing-gradient-descent/index.html
12+
13+
Gradient descent optimization algorithms http://sebastianruder.com/optimizing-gradient-descent/index.html
1314
"""
1415

1516

mla/neuralnet/parameters.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import numpy as np
23

34
from mla.neuralnet.initializations import get_initializer

mla/pca.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
from scipy.linalg import svd
23
import numpy as np
34
import logging
@@ -47,8 +48,8 @@ def _decompose(self, X):
4748

4849
s_squared = s ** 2
4950
variance_ratio = s_squared / (s_squared).sum()
50-
logging.info("Explained variance ratio: %s" % (variance_ratio[0 : self.n_components]))
51-
self.components = Vh[0 : self.n_components]
51+
logging.info("Explained variance ratio: %s" % (variance_ratio[0: self.n_components]))
52+
self.components = Vh[0: self.n_components]
5253

5354
def transform(self, X):
5455
X = X.copy()

mla/rbm.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import logging
23

34
from mla.base import BaseEstimator
@@ -52,7 +53,7 @@ def _init_weights(self):
5253
self.errors = []
5354

5455
def _train(self):
55-
"""Use CD-1 training procedure, basically an exact inference for `positive_associations`,
56+
"""Use CD-1 training procedure, basically an exact inference for `positive_associations`,
5657
followed by a "non burn-in" block Gibbs Sampling for the `negative_associations`."""
5758

5859
for i in range(self.max_epochs):

mla/rl/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
# coding:utf-8

mla/rl/dqn.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import logging
23
import random
34

mla/svm/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
# coding:utf-8

mla/svm/kernerls.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import numpy as np
23
import scipy.spatial.distance as dist
34

mla/tsne.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding:utf-8
12
import logging
23

34
import numpy as np

setup.cfg

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
universal=1
33

44
[metadata]
5-
description-file=README.md
5+
description-file=README.md
6+
7+
[flake8]
8+
max-line-length = 120

0 commit comments

Comments
 (0)