Mercurial > pylearn
changeset 1451:8110ca3cec3f
merge
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Thu, 31 Mar 2011 18:29:11 -0400 |
parents | c421bac46a97 (diff) fbe470217937 (current diff) |
children | d862047c2fe7 |
files | |
diffstat | 2 files changed, 22 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/pylearn/io/image_tiling.py Wed Mar 16 20:20:02 2011 -0400 +++ b/pylearn/io/image_tiling.py Thu Mar 31 18:29:11 2011 -0400 @@ -11,9 +11,9 @@ ndar *= 1.0 / max(ndar.max(),eps) return ndar -def tile_raster_images(X, img_shape, +def tile_raster_images(X, img_shape, tile_shape=None, tile_spacing=(1,1), - scale_rows_to_unit_interval=True, + scale_rows_to_unit_interval=True, output_pixel_vals=True, min_dynamic_range=1e-4, ): @@ -40,7 +40,19 @@ :rtype: a 2-d array with same dtype as X. """ - if isinstance(X, tuple): + if len(img_shape)==3 and img_shape[2]==3: + # make this save an rgb image + + return tile_raster_images( + (X[:,0::3], X[:,1::3], X[:,2::3], None), + img_shape=img_shape[:2], + tile_shape=tile_shape, + tile_spacing=tile_spacing, + scale_rows_to_unit_interval=scale_rows_to_unit_interval, + output_pixel_vals=output_pixel_vals, + min_dynamic_range=min_dynamic_range) + + if isinstance(X, tuple): n_images_in_x = X[0].shape[0] else: n_images_in_x = X.shape[0]
--- a/pylearn/preprocessing/pca.py Wed Mar 16 20:20:02 2011 -0400 +++ b/pylearn/preprocessing/pca.py Thu Mar 31 18:29:11 2011 -0400 @@ -72,7 +72,8 @@ return w,v -def pca_from_examples(X, max_components=None, max_energy_fraction=None, x_centered=False): +def pca_from_examples(X, max_components=None, max_energy_fraction=None, + x_centered=False, inplace=False): """Return ((eigvals, eigvecs), centered_X) of observations `X` (1-per-row) This function exists to wrap several algorithms for getting the principle components. @@ -90,10 +91,11 @@ :returns: ((eigvals, eigvecs), centered_X) of PCA decomposition """ - if x_centered: - centered_X = X - else: - centered_X = X - numpy.mean(X, axis=0) + if not inplace: + X = X.copy() + centered_X = X + if not x_centered: + centered_X -= numpy.mean(centered_X, axis=0) cov_X = numpy.dot(centered_X.T, centered_X) / (len(X)- 1) evals, evecs = pca_from_cov(cov_X, max_components=max_components, max_energy_fraction=max_energy_fraction)