Skip to content

Commit bec1d6a

Browse files
committed
PEP 8 compliance and tsfresh version compatibility fix
1 parent cc45036 commit bec1d6a

File tree

6 files changed

+38
-36
lines changed

6 files changed

+38
-36
lines changed

sciope/features/feature_extraction.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ def _wrapper(data):
7171
return total
7272

7373
res = np.array(_wrapper(data))
74-
return res.reshape(-1, res.shape[1]*res.shape[2])
74+
return res.reshape(-1, res.shape[1] * res.shape[2])
75+
7576

7677
def _get_tsfresh_features_names(features):
7778
"""
@@ -93,11 +94,10 @@ def _get_tsfresh_features_names(features):
9394
shape: Nr of total features
9495
"""
9596
f_names = []
96-
97+
9798
for key in features.keys():
9899
assert hasattr(feature_calculators, key), "%s does not exist as a feature supported by tsfresh" % key
99100

100-
101101
for function_name, parameter_list in features.items():
102102
func = getattr(feature_calculators, function_name)
103103
if parameter_list:
@@ -108,7 +108,8 @@ def _get_tsfresh_features_names(features):
108108

109109
return f_names
110110

111-
def remove_nan_features(x, features): # pragma: no cover
111+
112+
def remove_nan_features(x, features): # pragma: no cover
112113
"""
113114
Method to remove features containing NaN values.
114115

sciope/inference/smc_abc.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
from dask.distributed import futures_of, as_completed, wait
3131
from dask import delayed
3232

33+
3334
class PerturbationPrior(PriorBase):
3435

3536
def __init__(self, ref_prior, samples, normalized_weights, perturbation_kernel,
36-
use_logger = False):
37+
use_logger=False):
3738

3839
self.name = 'Perturbation Prior'
3940
self.ref_prior = ref_prior
@@ -42,7 +43,7 @@ def __init__(self, ref_prior, samples, normalized_weights, perturbation_kernel,
4243
self.perturbation_kernel = perturbation_kernel
4344
super(PerturbationPrior, self).__init__(self.name, use_logger)
4445

45-
def draw(self, n = 1, chunk_size = 1):
46+
def draw(self, n=1, chunk_size=1):
4647

4748
assert n >= chunk_size
4849

@@ -57,9 +58,9 @@ def draw(self, n = 1, chunk_size = 1):
5758
return generated_samples
5859

5960
@delayed
60-
def _weighted_draw_perturb(self,m):
61+
def _weighted_draw_perturb(self, m):
6162
idxs = np.random.choice(self.samples.shape[0], m,
62-
p = self.normalized_weights)
63+
p=self.normalized_weights)
6364
s0 = [self.samples[idx] for idx in idxs]
6465
s = []
6566
for z in s0:
@@ -72,6 +73,7 @@ def _weighted_draw_perturb(self,m):
7273

7374
return np.asarray(s)
7475

76+
7577
class SMCABC(InferenceBase):
7678
"""
7779
SMC - Approximate Bayesian Computation
@@ -145,19 +147,20 @@ def infer(self, num_samples, batch_size, chunk_size=10, ensemble_size=1, normali
145147

146148
# Generate an initial population from the first epsilon
147149
abc_instance = abc_inference.ABC(self.data, self.sim, prior_function,
148-
epsilon = self.epsilons[0],
149-
summaries_function = self.summaries_function,
150-
distance_function = self.distance_function,
151-
summaries_divisor = self.summaries_divisor,
152-
use_logger = self.use_logger)
150+
epsilon=self.epsilons[0],
151+
summaries_function=self.summaries_function,
152+
distance_function=self.distance_function,
153+
summaries_divisor=self.summaries_divisor,
154+
use_logger=self.use_logger)
153155

154156
print("Starting epsilon={}".format(self.epsilons[0]))
155-
abc_instance.compute_fixed_mean(chunk_size = chunk_size)
156-
abc_results = abc_instance.infer(num_samples = t, batch_size = batch_size, chunk_size = chunk_size, normalize = normalize)
157+
abc_instance.compute_fixed_mean(chunk_size=chunk_size)
158+
abc_results = abc_instance.infer(num_samples=t, batch_size=batch_size, chunk_size=chunk_size,
159+
normalize=normalize)
157160

158161
final_results = abc_results
159162
population = np.vstack(abc_results['accepted_samples'])[:t]
160-
normalized_weights = np.ones(t)/t
163+
normalized_weights = np.ones(t) / t
161164
d = population.shape[1]
162165

163166
# SMC iterations
@@ -175,23 +178,23 @@ def infer(self, num_samples, batch_size, chunk_size=10, ensemble_size=1, normali
175178
try:
176179
# Run ABC on the next epsilon using the proposal prior
177180
abc_instance = abc_inference.ABC(self.data, self.sim, new_prior,
178-
epsilon = eps, summaries_function = self.summaries_function,
179-
distance_function = self.distance_function,
180-
summaries_divisor = self.summaries_divisor,
181-
use_logger = self.use_logger)
182-
abc_instance.compute_fixed_mean(chunk_size = chunk_size)
183-
abc_results = abc_instance.infer(num_samples = t,
184-
batch_size = batch_size,
185-
chunk_size = chunk_size,
186-
normalize = normalize)
181+
epsilon=eps, summaries_function=self.summaries_function,
182+
distance_function=self.distance_function,
183+
summaries_divisor=self.summaries_divisor,
184+
use_logger=self.use_logger)
185+
abc_instance.compute_fixed_mean(chunk_size=chunk_size)
186+
abc_results = abc_instance.infer(num_samples=t,
187+
batch_size=batch_size,
188+
chunk_size=chunk_size,
189+
normalize=normalize)
187190
new_samples = np.vstack(abc_results['accepted_samples'])[:t]
188191

189192
# Compute importance weights for the new samples
190193
prior_weights = self.prior_function.pdf(new_samples)
191194
kweights = self.perturbation_kernel.pdf(population, new_samples)
192195

193-
new_weights = prior_weights / np.sum(kweights * normalized_weights[:, np.newaxis], axis = 0)
194-
new_weights = new_weights/sum(new_weights)
196+
new_weights = prior_weights / np.sum(kweights * normalized_weights[:, np.newaxis], axis=0)
197+
new_weights = new_weights / sum(new_weights)
195198

196199
population = new_samples
197200
normalized_weights = new_weights

sciope/tests/test_features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
def test_generate_tsfresh_features():
8-
X = np.random.randn(2, 2, 100)
8+
x = np.random.randn(2, 2, 100)
99
features = EfficientFCParameters()
10-
test = generate_tsfresh_features(X, features)
10+
test = generate_tsfresh_features(x, features)
1111
assert test.shape == (2, 1500)

sciope/utilities/priors/prior_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self, name, use_logger=False):
3535
self.use_logger = use_logger
3636

3737
@abstractmethod
38-
def pdf(self, x, log = False):
38+
def pdf(self, x, log=False):
3939
"""
4040
Evaluate the PDF of the sample
4141
:param x: the point or collection of points to evaluate the pdf at

sciope/utilities/priors/uniform_prior.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def __init__(self, space_min, space_max, use_logger=False):
3434
Set up a uniform prior corresponding to the space bounded by:
3535
:param space_min: the lowerbound of each variable/dimension
3636
:param space_max: the upperbound of each variable/dimension
37+
:param use_logger: whether logging is enabled or disabled
3738
"""
3839
self.name = 'Uniform'
3940
self.lb = space_min

setup.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""A setuptools based setup module for sciope.
22
See:
3-
http://hellanderlab.research.it.uu.se
3+
https://github.com/sciope/sciope
44
"""
55

66
# Always prefer setuptools over distutils
@@ -27,7 +27,7 @@
2727
long_description=long_description,
2828

2929
# The project's main homepage.
30-
url='https://hellanderlab.research.it.uu.se',
30+
url='https://github.com/sciope/sciope',
3131

3232
# Author details
3333
author='Prashant Singh; Fredrik Wrede; Andreas Hellander',
@@ -76,7 +76,7 @@
7676
'numpy',
7777
'scipy',
7878
'scikit-learn',
79-
'tsfresh',
79+
'tsfresh==0.15.0',
8080
'ipywidgets',
8181
'dask',
8282
'distributed',
@@ -92,9 +92,6 @@
9292
'test': ['coverage'],
9393
},
9494

95-
dependency_links=['https://github.com/GPflow/GPflow/archive/0.5.0.tar.gz#egg=GPflow-0.5.0',
96-
'https://github.com/GPflow/GPflowOpt/archive/v0.1.0.tar.gz#egg=GPflowOpt-0.1.0'],
97-
9895
# If there are data files included in your packages that need to be
9996
# installed, specify them here. If using Python 2.6 or less, then these
10097
# have to be included in MANIFEST.in as well.

0 commit comments

Comments
 (0)