Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #531 from markovmodel/rename_transformer_functions
Browse files Browse the repository at this point in the history
Rename transformer functions
  • Loading branch information
franknoe committed Aug 31, 2015
2 parents f3631da + 514df8a commit 9e827d1
Show file tree
Hide file tree
Showing 20 changed files with 192 additions and 93 deletions.
2 changes: 0 additions & 2 deletions pyemma/_base/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ def _estimate_param_scan_worker(estimator, params, X, evaluate, evaluate_args,

def estimate_param_scan(estimator, X, param_sets, evaluate=None, evaluate_args=None, failfast=True,
return_estimators=False, n_jobs=1, progress_reporter=None):
# TODO: parallelize. For options see http://scikit-learn.org/stable/modules/grid_search.html
# TODO: allow to specify method parameters in evaluate
""" Runs multiple estimations using a list of parameter settings
Parameters
Expand Down
2 changes: 1 addition & 1 deletion pyemma/coordinates/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ def pca(data=None, dim=2, var_cutoff=0.95, stride=1, mean=None):
indim = data.dimension()
mean = _types.ensure_ndarray(mean, shape=(indim,), dtype=_np.float)

res = _PCA(dim=dim, var_cutoff=var_cutoff)
res = _PCA(dim=dim, var_cutoff=var_cutoff, mean=mean)
return _param_stage(data, res, stride=stride)


Expand Down
2 changes: 1 addition & 1 deletion pyemma/coordinates/clustering/assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _param_add_data(self, X, itraj, t, first_chunk, last_chunk_in_traj,
self._dtrajs.append(np.empty(n, dtype=self.output_type()))

L = np.shape(X)[0]
self._dtrajs[itraj][t:t+L] = self._map_array(X).squeeze()
self._dtrajs[itraj][t:t+L] = self._transform_array(X).squeeze()

if last_chunk:
return True
4 changes: 2 additions & 2 deletions pyemma/coordinates/clustering/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def sample_indexes_by_cluster(self, clusters, nsample, replace=True):

return sample_indexes_by_state(self._index_states[clusters], nsample, replace=replace)

def _map_array(self, X):
def _transform_array(self, X):
"""get closest index of point in :attr:`clustercenters` to x."""
dtraj = np.empty(X.shape[0], dtype=self.output_type())
regspatial.assign(X.astype(np.float32, order='C', copy=False),
Expand Down Expand Up @@ -192,7 +192,7 @@ def assign(self, X=None, stride=1):
raise ValueError('assign accepts either X or stride parameters, but not both. If you want to map '+
'only a subset of your data, extract the subset yourself and pass it as X.')
# map to column vector(s)
mapped = self.map(X)
mapped = self.transform(X)
# flatten
if isinstance(mapped, np.ndarray):
mapped = np.transpose(mapped)[0]
Expand Down
6 changes: 3 additions & 3 deletions pyemma/coordinates/data/feature_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,16 @@ def _next_chunk(self, context=None):
shape_2d = (shape[0], shape[1] * shape[2])
return chunk.xyz.reshape(shape_2d)
else:
return self.featurizer.map(chunk)
return self.featurizer.transform(chunk)
else:
if len(self.featurizer.active_features) == 0:
shape_Y = adv_chunk.xyz.shape

X = chunk.xyz.reshape((shape[0], shape[1] * shape[2]))
Y = adv_chunk.xyz.reshape((shape_Y[0], shape_Y[1] * shape_Y[2]))
else:
X = self.featurizer.map(chunk)
Y = self.featurizer.map(adv_chunk)
X = self.featurizer.transform(chunk)
Y = self.featurizer.transform(adv_chunk)
return X, Y

def parametrize(self, stride=1):
Expand Down
85 changes: 80 additions & 5 deletions pyemma/coordinates/data/featurizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@
import warnings
from itertools import combinations as _combinations, count
from itertools import product as _product
from pyemma.util.types import is_iterable_of_int as _is_iterable_of_int
import functools


from six import PY3
from pyemma.util.types import is_iterable_of_int as _is_iterable_of_int
from pyemma.util.log import getLogger
#from pyemma.util.annotators import deprecated
from pyemma.util.annotators import deprecated
from six.moves import map
from six.moves import range
from six.moves import zip
Expand Down Expand Up @@ -285,7 +284,14 @@ def describe(self):
str(self._args) +
str(self._kwargs))]

@deprecated
def map(self, traj):
r"""Deprecated: use transform(traj)
"""
return self.transform(traj)

def transform(self, traj):
feature = self._func(traj, *self._args, **self._kwargs)
if not isinstance(feature, np.ndarray):
raise ValueError("your function should return a NumPy array!")
Expand Down Expand Up @@ -332,7 +338,14 @@ def describe(self):
def dimension(self):
return 3 * self.indexes.shape[0]

@deprecated
def map(self, traj):
r"""Deprecated: use transform(traj)
"""
return self.transform(traj)

def transform(self, traj):
newshape = (traj.xyz.shape[0], 3 * self.indexes.shape[0])
return np.reshape(traj.xyz[:, self.indexes, :], newshape)

Expand Down Expand Up @@ -366,7 +379,14 @@ def describe(self):
def dimension(self):
return self.distance_indexes.shape[0]

@deprecated
def map(self, traj):
r"""Deprecated: use transform(traj)
"""
return self.transform(traj)

def transform(self, traj):
return mdtraj.compute_distances(traj, self.distance_indexes, periodic=self.periodic)

def __hash__(self):
Expand All @@ -386,7 +406,14 @@ def __init__(self, top, distance_indexes, periodic=True):
self, top, distance_indexes, periodic=periodic)
self.prefix_label = "INVDIST:"

@deprecated
def map(self, traj):
r"""Deprecated: use transform(traj)
"""
return self.transform(traj)

def transform(self, traj):
return 1.0 / mdtraj.compute_distances(traj, self.distance_indexes, periodic=self.periodic)

# does not need own hash impl, since we take prefix label into account
Expand Down Expand Up @@ -417,7 +444,14 @@ def describe(self):
for pair in self.distance_indexes]
return labels

@deprecated
def map(self, traj):
r"""Deprecated: use transform(traj)
"""
return self.transform(traj)

def transform(self, traj):
# We let mdtraj compute the contacts with the input scheme
D = mdtraj.compute_contacts(traj, contacts=self.contacts, scheme=self.scheme)[0]
res = np.zeros_like(D)
Expand Down Expand Up @@ -446,7 +480,14 @@ def describe(self):
for pair in self.distance_indexes]
return labels

@deprecated
def map(self, traj):
r"""Deprecated: use transform(traj)
"""
return self.transform(traj)

def transform(self, traj):
# All needed distances
Dall = mdtraj.compute_distances(traj, self.distance_list)
# Just the minimas
Expand All @@ -472,7 +513,14 @@ def __init__(self, top, distance_indexes, threshold=5.0, periodic=True):
self.threshold = threshold
self.periodic = periodic

@deprecated
def map(self, traj):
r"""Deprecated: use transform(traj)
"""
return self.transform(traj)

def transform(self, traj):
dists = mdtraj.compute_distances(
traj, self.distance_indexes, periodic=self.periodic)
res = np.zeros(
Expand All @@ -496,7 +544,6 @@ def __init__(self, top, angle_indexes, deg=False, cossin=False):
self.cossin = cossin

def describe(self):

if self.cossin:
sin_cos = ("ANGLE: COS(%s - %s - %s)",
"ANGLE: SIN(%s - %s - %s)")
Expand All @@ -520,7 +567,14 @@ def dimension(self):
dim *= 2
return dim

@deprecated
def map(self, traj):
r"""Deprecated: use transform(traj)
"""
return self.transform(traj)

def transform(self, traj):
rad = mdtraj.compute_angles(traj, self.angle_indexes)
if self.cossin:
rad = np.dstack((np.cos(rad), np.sin(rad)))
Expand Down Expand Up @@ -576,7 +630,14 @@ def describe(self):
def dimension(self):
return self._dim

@deprecated
def map(self, traj):
r"""Deprecated: use transform(traj)
"""
return self.transform(traj)

def transform(self, traj):
rad = mdtraj.compute_dihedrals(traj, self.dih_indexes)
if self.cossin:
rad = np.dstack((np.cos(rad), np.sin(rad)))
Expand Down Expand Up @@ -719,7 +780,14 @@ def describe(self):
def dimension(self):
return 1

@deprecated
def map(self, traj):
r"""Deprecated: use transform(traj)
"""
return self.transform(traj)

def transform(self, traj):
return np.array(mdtraj.rmsd(traj, self.ref, atom_indices=self.atom_indices), ndmin=2).T

def __hash__(self):
Expand Down Expand Up @@ -1298,7 +1366,14 @@ def dimension(self):
dim = sum(f.dimension for f in self.active_features)
return dim

@deprecated
def map(self, traj):
r"""Deprecated: use transform(traj)
"""
return self.transform(traj)

def transform(self, traj):
"""
Maps an mdtraj Trajectory object to the selected output features
Expand Down Expand Up @@ -1337,7 +1412,7 @@ def map(self, traj):
# perform sanity checks for custom feature input
if isinstance(f, CustomFeature):
# NOTE: casting=safe raises in numpy>=1.9
vec = f.map(traj).astype(np.float32, casting='safe')
vec = f.transform(traj).astype(np.float32, casting='safe')
if vec.shape[0] == 0:
vec = np.empty((0, f.dimension))

Expand All @@ -1357,7 +1432,7 @@ def map(self, traj):
traj.xyz.shape[0],
vec.shape[0]))
else:
vec = f.map(traj).astype(np.float32)
vec = f.transform(traj).astype(np.float32)
feature_vec.append(vec)

if len(feature_vec) > 1:
Expand Down
4 changes: 2 additions & 2 deletions pyemma/coordinates/data/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ def _add_array_to_storage(self, array):
self._data.append(array)

# handle abstract methods and special cases
def map(self, X):
def transform(self, X):
raise NotImplementedError("a reader can not map data, it is a data source")

def _map_array(self, X):
def _transform_array(self, X):
raise NotImplementedError("a reader can not map data, it is a data source")

def _param_add_data(self, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion pyemma/coordinates/data/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def describe(self):
def dimension(self):
return self.data_producer.dimension()

def _map_array(self, X):
def _transform_array(self, X):
pass

def _reset(self, stride=1):
Expand Down
14 changes: 1 addition & 13 deletions pyemma/coordinates/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,7 @@ def set_element(self, index, e):

return replaced

def run(self):
"""deprecated. Identical to parametrize()
"""
import warnings
warnings.warn(
"run() is deprecated and will be disabled in the future. Use parametrize().", DeprecationWarning)
self.parametrize()

# TODO: DISCUSS - renamed run() to parametrize (because run is a bit ambiguous).
# TODO: We could also call it fit() (here and in the transformers).
# TODO: This might be nicer because it's shorter and the spelling is unambiguous
# TODO: (in contrast to parametrize and parameterize and parameterise that
# are all correct in english.
# TODO: to be replaced by fit/estimate
def parametrize(self):
r"""
Reads all data and discretizes it into discrete trajectories.
Expand Down
2 changes: 1 addition & 1 deletion pyemma/coordinates/tests/test_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_iterator(self):

def test_map(self):
c = self.ass
Y = c.map(self.X)
Y = c.transform(self.X)
assert Y.shape[0] == self.T
assert Y.shape[1] == 1
# test if consistent with get_output
Expand Down
2 changes: 1 addition & 1 deletion pyemma/coordinates/tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_iterator(self):

def test_map(self):
for c in self.cl:
Y = c.map(self.X)
Y = c.transform(self.X)
assert Y.shape[0] == self.T
assert Y.shape[1] == 1
# test if consistent with get_output
Expand Down
Loading

0 comments on commit 9e827d1

Please sign in to comment.