Skip to content

Commit 4c5620b

Browse files
committed
use direct assignment instead of setattr
1 parent 77b364e commit 4c5620b

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

basicrta/cluster.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ def reprocess(self, nproc=1):
119119

120120
taus = np.array(taus)
121121
bars = get_bars(taus)
122-
setattr(self, 'taus', taus[:, 1])
123-
setattr(self, 'bars', bars)
124-
setattr(self, 'residues', np.array(residues))
125-
setattr(self, 'files', np.array(results))
122+
self.taus = taus[:, 1]
123+
self.bars = bars
124+
self.residues = np.array(residues)
125+
self.files = np.array(results)
126126

127127
def get_taus(self, nproc=1):
128128
r"""Get :math:`\tau` and 95\% confidence interval bounds for the slowest
@@ -158,10 +158,10 @@ def get_taus(self, nproc=1):
158158

159159
taus = np.array(taus)
160160
bars = get_bars(taus)
161-
setattr(self, 'taus', taus[:, 1])
162-
setattr(self, 'bars', bars)
163-
setattr(self, 'residues', np.array(residues))
164-
setattr(self, 'files', np.array(results))
161+
self.taus = taus[:, 1]
162+
self.bars = bars
163+
self.residues = np.array(residues)
164+
self.files = np.array(results)
165165
return taus[:, 1], bars
166166

167167
def write_data(self, fname='tausout'):

basicrta/gibbs.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ def cluster(self, method="GaussianMixture", **kwargs):
301301
pindicator[tmpind, mapinds[i]] += 1
302302

303303
pindicator = (pindicator.T / pindicator.sum(axis=1)).T
304-
setattr(self.processed_results, 'indicator', pindicator)
305-
setattr(self.processed_results, 'labels', all_labels)
304+
self.processed_results.indicator = pindicator
305+
self.processed_results.labels = all_labels
306306

307307
def process_gibbs(self, show=True):
308308
r"""
@@ -329,9 +329,8 @@ def process_gibbs(self, show=True):
329329

330330
self.cluster(n_init=117, n_components=lmode)
331331
labels, presorts = mixture_and_plot(self, show=show)
332-
setattr(self.processed_results, 'labels', labels)
333-
setattr(self.processed_results, 'indicator',
334-
self.processed_results.indicator[:, presorts])
332+
self.processed_results.labels = labels
333+
self.processed_results.indicator = self.processed_results.indicator[:, presorts]
335334

336335
attrs = ["weights", "rates", "ncomp", "residue", "iteration", "niter"]
337336
values = [fweights, frates, lmode, self.residue, indices, self.niter]
@@ -364,7 +363,7 @@ def _sample_indicator(self):
364363
# sample indicator
365364
s = np.argmax(rng.multinomial(1, z), axis=1)
366365
indicator[i] = s
367-
setattr(self, 'indicator', indicator)
366+
self.indicator = indicator
368367
return indicator[burnin_ind::self.gskip]
369368

370369
def save(self):
@@ -719,8 +718,8 @@ def _estimate_params(self):
719718
params = np.array([[wh[1][np.argmax(wh[0])], rh[1][np.argmax(rh[0])]]
720719
for wh, rh in zip(whists, rhists)])
721720

722-
setattr(rp, 'parameters', params)
723-
setattr(rp, 'intervals', np.array([wbounds, rbounds]))
721+
rp.parameters = params
722+
rp.intervals = np.array([wbounds, rbounds])
724723

725724
def estimate_tau(self):
726725
r"""

0 commit comments

Comments
 (0)