├── .gitignore ├── .requirements.txt ├── .travis.sh ├── .travis.yml ├── LICENSE.txt ├── MANIFEST.in ├── README.rst ├── bin ├── pylearn2-plot-monitor ├── pylearn2-print-monitor ├── pylearn2-show-examples ├── pylearn2-show-weights └── pylearn2-train ├── doc ├── LICENSE.txt ├── api_change.txt ├── cluster.txt ├── conf.py ├── faq.txt ├── features.txt ├── index.txt ├── internal │ ├── api_coding_style.txt │ ├── data_specs.txt │ ├── dev_start_guide.txt │ ├── index.txt │ ├── metadocumentation.txt │ └── pull_request_checklist.txt ├── large_data.txt ├── library │ ├── alex.txt │ ├── config.txt │ ├── corruption.txt │ ├── costs.txt │ ├── datasets.txt │ ├── devtools.txt │ ├── distributions.txt │ ├── energy_functions.txt │ ├── expr.txt │ ├── format.txt │ ├── gui.txt │ ├── index.txt │ ├── linear.txt │ ├── misc.txt │ ├── models.txt │ ├── monitor.txt │ ├── optimization.txt │ ├── scripts.txt │ ├── space.txt │ ├── termination_criteria.txt │ ├── train.txt │ └── utils.txt ├── overview.txt ├── scripts │ └── docgen.py ├── theano_to_pylearn2_tutorial.txt ├── themes │ └── solar │ │ ├── layout.html │ │ ├── static │ │ ├── solar.css │ │ ├── solarized-dark.css │ │ └── subtle_dots.png │ │ └── theme.conf ├── tutorial │ ├── index.txt │ ├── notebook_tutorials.txt │ └── with_jobman.txt ├── vision.txt └── yaml_tutorial │ ├── __init__.py │ ├── autoencoder.py │ └── index.txt ├── pylearn2 ├── __init__.py ├── blocks.py ├── compat.py ├── config │ ├── __init__.py │ ├── old_config.py │ ├── tests │ │ ├── __init__.py │ │ └── test_yaml_parse.py │ └── yaml_parse.py ├── corruption.py ├── costs │ ├── __init__.py │ ├── autoencoder.py │ ├── cost.py │ ├── dbm.py │ ├── ebm_estimation.py │ ├── gated_autoencoder.py │ ├── gsn.py │ ├── mlp │ │ ├── __init__.py │ │ ├── dropout.py │ │ └── missing_target_cost.py │ ├── tests │ │ ├── test_lp_penalty_cost.py │ │ ├── test_sparse_activation.py │ │ └── test_term_1_0_l1_penalty.py │ └── vae.py ├── cross_validation │ ├── __init__.py │ ├── blocks.py │ ├── dataset_iterators.py │ ├── mlp.py │ ├── subset_iterators.py │ ├── tests │ │ ├── test_cross_validation.py │ │ ├── test_dataset_iterators.py │ │ ├── test_subset_iterators.py │ │ └── test_train_cv_extensions.py │ └── train_cv_extensions.py ├── dataset_get │ ├── README.rst │ ├── dataset-get │ ├── dataset-get.py │ ├── dataset_resolver.py │ ├── example-package │ │ └── fake-dataset │ │ │ ├── docs │ │ │ ├── license.txt │ │ │ └── other.txt │ │ │ ├── fake-dataset │ │ │ └── data │ │ │ │ ├── ff009bf24412862511cf7eeeab5aa134.jpg │ │ │ │ ├── ff191fc088d491f6b54871339f114b7f.jpg │ │ │ │ ├── ff26a864b8b8ee1aa01413a4fc7b2b93.jpg │ │ │ │ ├── ff3b264a0ccf9b366e87f4b8eeb1c3a4.jpg │ │ │ │ ├── ff40c2792e53fdbc3bc849028f304c00.jpg │ │ │ │ ├── ff455d3fb4e8bebb5ea14dcb6630d32d.jpg │ │ │ │ ├── ff6848ee9d56b4dc36376f4b998662fe.jpg │ │ │ │ ├── ff749d5d9c03e59b6cb4b09081df95df.jpg │ │ │ │ ├── ff7edaf73cb4a5f6ca6fc7341a59a618.jpg │ │ │ │ ├── ff8c52a9e96d57fa35e6c6b7959cc70a.jpg │ │ │ │ ├── ff91bb2abc9b4225711bd45941c304d3.jpg │ │ │ │ ├── ff9c870d7f75c979c8ae200f5cd5d246.jpg │ │ │ │ ├── ff9e25c7a059d40866fdb6848ed75134.jpg │ │ │ │ ├── ffa361ac89f7ecd07a313b672a752c20.jpg │ │ │ │ ├── ffb68ce0546a24f0dd4a52cb7b95a1b6.jpg │ │ │ │ └── ffbea58fd0203a343f87ad4e799e9fa0.jpg │ │ │ ├── readme.1rst │ │ │ └── scripts │ │ │ ├── getscript │ │ │ ├── postinst │ │ │ ├── postrm │ │ │ └── prerm │ └── helper-scripts │ │ ├── make-archive.py │ │ └── make-sources.py ├── datasets │ ├── __init__.py │ ├── adult.py │ ├── avicenna.py │ ├── binarized_mnist.py │ ├── binarizer.py │ ├── cache.py │ ├── cifar10.py │ ├── cifar100.py │ ├── config.py │ ├── control.py │ ├── cos_dataset.py │ ├── csv_dataset.py │ ├── dataset.py │ ├── debug.py │ ├── dense_design_matrix.py │ ├── exc.py │ ├── filetensor.py │ ├── four_regions.py │ ├── hdf5.py │ ├── hdf5_deprecated.py │ ├── hepatitis.py │ ├── icml07.py │ ├── iris.py │ ├── matlab_dataset.py │ ├── mnist.py │ ├── mnistplus.py │ ├── new_norb.py │ ├── norb.py │ ├── norb_small.py │ ├── npy_npz.py │ ├── ocr.py │ ├── preprocessing.py │ ├── retina.py │ ├── sparse_dataset.py │ ├── stl10.py │ ├── svhn.py │ ├── tests │ │ ├── __init__.py │ │ ├── test.csv │ │ ├── test_adult.py │ │ ├── test_avicenna.py │ │ ├── test_cifar10.py │ │ ├── test_cifar100.py │ │ ├── test_cos_dataset.py │ │ ├── test_csv_dataset.py │ │ ├── test_dense_design_matrix.py │ │ ├── test_four_regions.py │ │ ├── test_hdf5.py │ │ ├── test_hepatitis.py │ │ ├── test_icml07.py │ │ ├── test_imports.py │ │ ├── test_iris.py │ │ ├── test_mnist.py │ │ ├── test_mnist_rotated.py │ │ ├── test_mnistplus.py │ │ ├── test_norb.py │ │ ├── test_norb_small.py │ │ ├── test_npy_npz.py │ │ ├── test_ocr.py │ │ ├── test_preprocessing.py │ │ ├── test_retina.py │ │ ├── test_sparse_dataset.py │ │ ├── test_stl10.py │ │ ├── test_tfd.py │ │ ├── test_tl_challenge.py │ │ ├── test_transformer_dataset.py │ │ ├── test_utlc.py │ │ ├── test_vector_spaces_dataset.py │ │ ├── test_wiskott.py │ │ └── test_zca_dataset.py │ ├── tfd.py │ ├── tl_challenge.py │ ├── transformer_dataset.py │ ├── utlc.py │ ├── vector_spaces_dataset.py │ ├── wiskott.py │ └── zca_dataset.py ├── devtools │ ├── __init__.py │ ├── list_files.py │ ├── nan_guard.py │ ├── run_pyflakes.py │ └── tests │ │ ├── __init__.py │ │ ├── docscrape.py │ │ ├── pep8 │ │ ├── __init__.py │ │ └── pep8.py │ │ ├── test_format.py │ │ ├── test_shebangs.py │ │ └── test_via_pyflakes.py ├── distributions │ ├── __init__.py │ ├── mnd.py │ ├── multinomial.py │ ├── parzen.py │ ├── tests │ │ └── test_mnd.py │ └── uniform_hypersphere.py ├── energy_functions │ ├── __init__.py │ ├── energy_function.py │ ├── rbm_energy.py │ └── tests │ │ ├── __init__.py │ │ └── test_rbm_energy.py ├── expr │ ├── __init__.py │ ├── activations.py │ ├── basic.py │ ├── coding.py │ ├── evaluation.py │ ├── image.py │ ├── information_theory.py │ ├── nnet.py │ ├── normalize.py │ ├── preprocessing.py │ ├── probabilistic_max_pooling.py │ ├── sampling.py │ ├── stochastic_pool.py │ └── tests │ │ ├── test_basic.py │ │ ├── test_coding.py │ │ ├── test_evaluation.py │ │ ├── test_nnet.py │ │ ├── test_normalize.py │ │ ├── test_preprocessing.py │ │ ├── test_probabilistic_max_pooling.py │ │ └── test_stochastic_pool.py ├── format │ ├── __init__.py │ ├── target_format.py │ └── tests │ │ └── test_target_format.py ├── gui │ ├── __init__.py │ ├── get_weights_report.py │ ├── graph_2D.py │ ├── patch_viewer.py │ └── tangent_plot.py ├── linear │ ├── __init__.py │ ├── conv2d.py │ ├── conv2d_c01b.py │ ├── cudnn2d.py │ ├── linear_transform.py │ ├── local_c01b.py │ ├── matrixmul.py │ └── tests │ │ ├── test_conv2d.py │ │ ├── test_conv2d_c01b.py │ │ ├── test_cudnn.py │ │ ├── test_local_c01b.py │ │ └── test_matrixmul.py ├── misc │ └── do_nightly_build ├── model_extensions │ ├── __init__.py │ ├── model_extension.py │ ├── norm_constraint.py │ └── tests │ │ ├── test_model_extension.py │ │ └── test_norm_constraint.py ├── models │ ├── __init__.py │ ├── _kmeans.pyx │ ├── autoencoder.py │ ├── dbm │ │ ├── __init__.py │ │ ├── dbm.py │ │ ├── inference_procedure.py │ │ ├── ising.py │ │ ├── layer.py │ │ └── sampling_procedure.py │ ├── differentiable_sparse_coding.py │ ├── gated_autoencoder.py │ ├── gsn.py │ ├── independent_multiclass_logistic.py │ ├── kmeans.py │ ├── local_coordinate_coding.py │ ├── lwta.py │ ├── maxout.py │ ├── mlp.py │ ├── mnd.lyx │ ├── mnd.py │ ├── model.py │ ├── normalized_ebm.py │ ├── pca.py │ ├── rbm.py │ ├── s3c.py │ ├── setup.py │ ├── softmax_regression.py │ ├── sparse_autoencoder.py │ ├── svm.py │ ├── tests │ │ ├── config │ │ │ ├── cae.yaml │ │ │ └── hcae.yaml │ │ ├── conv_elemwise_rect.yaml │ │ ├── conv_elemwise_sigm.yaml │ │ ├── conv_elemwise_tanh.yaml │ │ ├── dbm.mat │ │ ├── dbm_data.mat │ │ ├── lwta.yaml │ │ ├── test_autoencoder.py │ │ ├── test_convelemwise_cost.py │ │ ├── test_convelemwise_rect.py │ │ ├── test_convelemwise_sigm.py │ │ ├── test_convelemwise_tanh.py │ │ ├── test_dbm.py │ │ ├── test_dropout.py │ │ ├── test_gsn.py │ │ ├── test_kmeans.py │ │ ├── test_lwta.py │ │ ├── test_maxout.py │ │ ├── test_mlp.py │ │ ├── test_mnd.py │ │ ├── test_model.py │ │ ├── test_rbm.py │ │ ├── test_reflection_clip.py │ │ ├── test_s3c_inference.py │ │ ├── test_s3c_misc.py │ │ ├── test_svm.py │ │ ├── test_vae.py │ │ ├── test_vae_cost_is_criterion.yaml │ │ ├── test_vae_cost_vae_criterion.yaml │ │ └── test_windowlayer.py │ └── vae │ │ ├── __init__.py │ │ ├── conditional.py │ │ ├── kl.py │ │ └── prior.py ├── monitor.py ├── optimization │ ├── __init__.py │ ├── batch_gradient_descent.py │ ├── feature_sign.py │ ├── linear_cg.py │ ├── linesearch.py │ ├── minres.py │ ├── test_batch_gradient_descent.py │ ├── test_feature_sign.py │ ├── test_linear_cg.py │ ├── test_linesearch.py │ └── test_minres.py ├── packaged_dependencies │ ├── __init__.py │ └── theano_linear │ │ ├── README │ │ ├── __init__.py │ │ ├── conv2d.py │ │ ├── imaging.py │ │ ├── linear.py │ │ ├── linearmixin.py │ │ ├── pyramid.py │ │ ├── spconv.py │ │ ├── test_linear.py │ │ ├── test_matrixmul.py │ │ ├── test_spconv.py │ │ ├── unshared_conv │ │ ├── README │ │ ├── __init__.py │ │ ├── filter_acts.cu │ │ ├── gpu_unshared_conv.py │ │ ├── img_acts.cu │ │ ├── localdot.py │ │ ├── raw_img_acts.cu │ │ ├── test_gpu_unshared_conv.py │ │ ├── test_localdot.py │ │ ├── test_unshared_conv.py │ │ ├── unshared_conv.py │ │ └── weight_acts.cu │ │ └── util.py ├── rbm_tools.py ├── sandbox │ ├── __init__.py │ ├── cuda_convnet │ │ ├── __init__.py │ │ ├── base_acts.py │ │ ├── bench.py │ │ ├── code_templates.py │ │ ├── conv_util.cu │ │ ├── conv_util.cuh │ │ ├── convnet_compile.py │ │ ├── cudaconv2.cuh │ │ ├── cutil.h │ │ ├── cutil_inline.h │ │ ├── cutil_inline_bankchecker.h │ │ ├── cutil_inline_drvapi.h │ │ ├── cutil_inline_runtime.h │ │ ├── debug.py │ │ ├── drvapi_error_string.h │ │ ├── filter_acts.cu │ │ ├── filter_acts.py │ │ ├── helper_string.h │ │ ├── img_acts.cu │ │ ├── img_acts.py │ │ ├── nvmatrix.cu │ │ ├── nvmatrix.cuh │ │ ├── nvmatrix_kernels.cu │ │ ├── nvmatrix_kernels.cuh │ │ ├── nvmatrix_operators.cuh │ │ ├── pool.py │ │ ├── pool_rop.cuh │ │ ├── probabilistic_max_pooling.py │ │ ├── pthreads.py │ │ ├── response_norm.py │ │ ├── shared_code.py │ │ ├── specialized_bench.py │ │ ├── stochastic_pool.py │ │ ├── tests │ │ │ ├── profile_probabilistic_max_pooling.py │ │ │ ├── test_common.py │ │ │ ├── test_filter_acts.py │ │ │ ├── test_filter_acts_strided.py │ │ │ ├── test_image_acts_strided.py │ │ │ ├── test_img_acts.py │ │ │ ├── test_pool.py │ │ │ ├── test_probabilistic_max_pooling.py │ │ │ ├── test_response_norm.py │ │ │ ├── test_rop_pool.py │ │ │ ├── test_stochastic_pool.py │ │ │ ├── test_weight_acts.py │ │ │ └── test_weight_acts_strided.py │ │ ├── weight_acts.cu │ │ ├── weight_acts.cuh │ │ └── weight_acts.py │ ├── lisa_rl │ │ ├── __init__.py │ │ └── bandit │ │ │ ├── __init__.py │ │ │ ├── agent.py │ │ │ ├── algorithm.py │ │ │ ├── average_agent.py │ │ │ ├── classifier_agent.py │ │ │ ├── classifier_bandit.py │ │ │ ├── environment.py │ │ │ ├── experiments │ │ │ ├── basic_bandit_001.yaml │ │ │ ├── basic_bandit_002.yaml │ │ │ ├── mnist_bandit_001.yaml │ │ │ ├── mnist_bandit_001_gpu.yaml │ │ │ ├── mnist_bandit_002.yaml │ │ │ ├── mnist_bandit_003.yaml │ │ │ ├── mnist_bandit_003a.yaml │ │ │ ├── mnist_bandit_004.yaml │ │ │ ├── mnist_bandit_005.yaml │ │ │ ├── mnist_bandit_005a.yaml │ │ │ ├── mnist_bandit_006.yaml │ │ │ └── mnist_bandit_full_train.yaml │ │ │ ├── gaussian_bandit.py │ │ │ ├── plot_reward.py │ │ │ ├── simulate.py │ │ │ └── simulator.py │ ├── nlp │ │ ├── __init__.py │ │ ├── datasets │ │ │ ├── __init__.py │ │ │ ├── penntree.py │ │ │ └── text.py │ │ ├── linear │ │ │ ├── __init__.py │ │ │ ├── matrixmul.py │ │ │ └── tests │ │ │ │ └── test_matrixmul.py │ │ ├── models │ │ │ ├── __init__.py │ │ │ ├── mlp.py │ │ │ └── tests │ │ │ │ ├── composite.yaml │ │ │ │ └── test_mlp.py │ │ └── scripts │ │ │ └── language_model │ │ │ └── language_model.yaml │ ├── rnn │ │ ├── __init__.py │ │ ├── costs │ │ │ ├── __init__.py │ │ │ ├── gradient_clipping.py │ │ │ └── tests │ │ │ │ └── test_gradient_clipping.py │ │ ├── models │ │ │ ├── __init__.py │ │ │ ├── mlp_hook.py │ │ │ ├── rnn.py │ │ │ └── tests │ │ │ │ └── test_rnn.py │ │ ├── scripts │ │ │ └── language_model.yaml │ │ ├── space │ │ │ └── __init__.py │ │ └── utils │ │ │ ├── __init__.py │ │ │ └── iteration.py │ └── tuple_var.py ├── scripts │ ├── __init__.py │ ├── autoencoder_example │ │ ├── dae.yaml │ │ └── hcae.yaml │ ├── benchmark │ │ └── time_relu.py │ ├── browse_conv_weights.py │ ├── datasets │ │ ├── browse_norb.py │ │ ├── browse_small_norb.py │ │ ├── download_binarized_mnist.py │ │ ├── download_cifar10.sh │ │ ├── download_mnist.py │ │ ├── download_svhn.sh │ │ ├── make_cifar100_gcn_whitened.py │ │ ├── make_cifar100_patches.py │ │ ├── make_cifar100_patches_8x8.py │ │ ├── make_cifar100_whitened.py │ │ ├── make_cifar10_gcn_whitened.py │ │ ├── make_cifar10_whitened.py │ │ ├── make_downsampled_stl10.py │ │ ├── make_mnistplus.py │ │ ├── make_stl10_patches.py │ │ ├── make_stl10_patches_8x8.py │ │ ├── make_stl10_whitened.py │ │ ├── make_svhn_pytables.py │ │ ├── step_through_norb_foveated.py │ │ └── step_through_small_norb.py │ ├── dbm │ │ ├── README │ │ ├── __init__.py │ │ ├── dbm_metrics.py │ │ ├── show_negative_chains.py │ │ ├── show_reconstructions.py │ │ ├── show_samples.py │ │ └── top_filters.py │ ├── diff_monitor.py │ ├── example_convolution.yaml │ ├── find_gpu_fields.py │ ├── get_version.py │ ├── gpu_pkl_to_cpu_pkl.py │ ├── gsn_example.py │ ├── icml_2013_wrepl │ │ ├── __init__.py │ │ ├── black_box │ │ │ ├── README │ │ │ ├── __init__.py │ │ │ ├── black_box_dataset.py │ │ │ ├── learn_zca.py │ │ │ ├── make_submission.py │ │ │ ├── mlp.yaml │ │ │ └── zca_mlp.yaml │ │ ├── emotions │ │ │ ├── README │ │ │ ├── __init__.py │ │ │ ├── convolutional_net.yaml │ │ │ ├── emotions_dataset.py │ │ │ ├── emotions_public_test.yaml │ │ │ ├── emotions_train.yaml │ │ │ ├── make_submission.py │ │ │ └── softmax.yaml │ │ └── multimodal │ │ │ ├── README │ │ │ ├── __init__.py │ │ │ ├── extract_kmeans_features.py │ │ │ ├── extract_layer_2_kmeans_features.py │ │ │ ├── lcn.py │ │ │ ├── make_submission.py │ │ │ └── make_wordlist.py │ ├── jobman │ │ ├── __init__.py │ │ ├── experiment.py │ │ └── tester.py │ ├── lcc_tangents │ │ └── make_dataset.py │ ├── mlp │ │ ├── __init__.py │ │ └── predict_csv.py │ ├── num_parameters.py │ ├── papers │ │ ├── README │ │ ├── __init__.py │ │ ├── dropout │ │ │ ├── README │ │ │ ├── mnist.yaml │ │ │ ├── mnist_fast.yaml │ │ │ ├── mnist_valid.yaml │ │ │ ├── mnist_valid_fast.yaml │ │ │ └── tests │ │ │ │ └── test_dropout.py │ │ ├── jia_huang_wkshp_11 │ │ │ ├── README │ │ │ ├── assemble.py │ │ │ ├── evaluate.py │ │ │ ├── extract_features.py │ │ │ ├── extract_features.yaml │ │ │ ├── extract_test_features.yaml │ │ │ ├── fit_final_model.py │ │ │ ├── kmeans.yaml │ │ │ └── npy2mat.py │ │ ├── maxout │ │ │ ├── README │ │ │ ├── cifar10.yaml │ │ │ ├── cifar10_no_aug.yaml │ │ │ ├── cifar10_no_aug_valid.yaml │ │ │ ├── cifar10_old_small.yaml │ │ │ ├── cifar10_valid.yaml │ │ │ ├── compute_test_err.py │ │ │ ├── mnist.yaml │ │ │ ├── mnist_continued.yaml │ │ │ ├── mnist_pi.yaml │ │ │ ├── mnist_pi_continued.yaml │ │ │ ├── notes │ │ │ ├── svhn.yaml │ │ │ ├── svhn2.yaml │ │ │ ├── svhn_preprocessing.py │ │ │ └── tests │ │ │ │ └── test_mnist.py │ │ └── mpdbm │ │ │ ├── README │ │ │ └── mpdbm.yaml │ ├── pkl_inspector.py │ ├── plot_monitor.py │ ├── print_channel_doc.py │ ├── print_model.py │ ├── print_monitor.py │ ├── print_monitor_cv.py │ ├── show_binocular_greyscale_examples.py │ ├── show_examples.py │ ├── show_weights.py │ ├── summarize_model.py │ ├── tests │ │ ├── __init__.py │ │ ├── test_autoencoder.py │ │ ├── test_dbm.py │ │ ├── test_print_monitor_cv.py │ │ ├── test_show_examples.py │ │ ├── test_show_weights.py │ │ ├── test_summarize_model.py │ │ ├── test_train.py │ │ └── yaml_testing.py │ ├── train.py │ ├── tutorials │ │ ├── README │ │ ├── __init__.py │ │ ├── constrained_optimization.txt │ │ ├── convolutional_network │ │ │ ├── README │ │ │ ├── conv.conf │ │ │ ├── conv.yaml │ │ │ ├── convolutional_network.ipynb │ │ │ └── tests │ │ │ │ └── test_convnet.py │ │ ├── dbm_demo │ │ │ ├── README │ │ │ ├── __init__.py │ │ │ ├── rbm.yaml │ │ │ └── train_dbm.py │ │ ├── deep_trainer │ │ │ ├── __init__.py │ │ │ ├── readme.txt │ │ │ ├── run_deep_trainer.py │ │ │ └── test_deep_trainer.py │ │ ├── gae_demo │ │ │ ├── README │ │ │ ├── __init__.py │ │ │ ├── gae_random.yaml │ │ │ ├── make_random_dataset.py │ │ │ ├── test_gae.py │ │ │ └── train_gae.ipynb │ │ ├── grbm_smd │ │ │ ├── README │ │ │ ├── __init__.py │ │ │ ├── cifar_grbm_smd.yaml │ │ │ ├── make_dataset.py │ │ │ └── test_grbm_smd.py │ │ ├── jobman_demo │ │ │ ├── __init__.py │ │ │ ├── mlp.conf │ │ │ ├── mlp.yaml │ │ │ └── utils.py │ │ ├── jobman_integration.ipynb │ │ ├── mlp_nested.yaml │ │ ├── momentum.txt │ │ ├── multilayer_perceptron │ │ │ ├── README │ │ │ ├── mlp_tutorial_part_2.yaml │ │ │ ├── mlp_tutorial_part_3.yaml │ │ │ ├── mlp_tutorial_part_4.yaml │ │ │ ├── multilayer_perceptron.ipynb │ │ │ └── tests │ │ │ │ └── test_mlp.py │ │ ├── predicting.txt │ │ ├── regression.txt │ │ ├── softmax_regression │ │ │ ├── README │ │ │ ├── softmax_regression.ipynb │ │ │ ├── sr_algorithm.yaml │ │ │ ├── sr_dataset.yaml │ │ │ ├── sr_model.yaml │ │ │ ├── sr_train.yaml │ │ │ └── tests │ │ │ │ └── test_softmaxreg.py │ │ ├── stacked_autoencoders │ │ │ ├── README │ │ │ ├── dae_l1.yaml │ │ │ ├── dae_l2.yaml │ │ │ ├── dae_mlp.yaml │ │ │ ├── stacked_autoencoders.ipynb │ │ │ └── tests │ │ │ │ └── test_dae.py │ │ ├── tests │ │ │ ├── test_dbm.py │ │ │ └── test_mlp_nested.py │ │ └── variational_autoencoder │ │ │ └── vae.yaml │ └── yaml_dryrun.py ├── space │ ├── __init__.py │ └── tests │ │ └── test_space.py ├── termination_criteria │ ├── __init__.py │ └── tests │ │ └── test_init.py ├── testing │ ├── __init__.py │ ├── cost.py │ ├── datasets.py │ ├── prereqs.py │ ├── skip.py │ └── tests │ │ ├── test.py │ │ └── test_datasets.py ├── tests │ ├── rbm │ │ ├── mnistvh.mat │ │ └── test_ais.py │ ├── test_blocks.py │ ├── test_dbm_metrics.py │ ├── test_monitor.py │ ├── test_theano.py │ └── test_train.py ├── train.py ├── train_extensions │ ├── __init__.py │ ├── best_params.py │ ├── live_monitoring.py │ ├── plots.py │ ├── roc_auc.py │ ├── tests │ │ ├── live_monitor_test.yaml │ │ ├── test_live_monitor.py │ │ ├── test_monitor_based_save_best.py │ │ ├── test_roc_auc.py │ │ ├── test_window_flip.py │ │ └── test_wmape_channel.py │ ├── window_flip.py │ └── wmape_channel.py ├── training_algorithms │ ├── __init__.py │ ├── bgd.py │ ├── default.py │ ├── learning_rule.py │ ├── sgd.py │ ├── tests │ │ ├── test_bgd.py │ │ ├── test_default.py │ │ ├── test_learning_rule.py │ │ ├── test_monitoring_batch_size.py │ │ └── test_sgd.py │ └── training_algorithm.py └── utils │ ├── __init__.py │ ├── _video.pyx │ ├── _window_flip.pyx │ ├── bit_strings.py │ ├── call_check.py │ ├── common_strings.py │ ├── compile.py │ ├── data_specs.py │ ├── datasets.py │ ├── exc.py │ ├── general.py │ ├── image.py │ ├── insert_along_axis.py │ ├── iteration.py │ ├── logger.py │ ├── mem.py │ ├── mnist_ubyte.py │ ├── pooling.py │ ├── python26.py │ ├── rng.py │ ├── serial.py │ ├── setup.py │ ├── shell.py │ ├── string_utils.py │ ├── testing.py │ ├── tests │ ├── example_bin_lush │ │ ├── double_3tensor.lushbin │ │ ├── float_3tensor.lushbin │ │ ├── int_3tensor.lushbin │ │ ├── ubyte_3tensor.lushbin │ │ └── ubyte_scalar.lushbin │ ├── example_image │ │ └── mnist0.jpg │ ├── test_bit_strings.py │ ├── test_compile.py │ ├── test_data_specs.py │ ├── test_general.py │ ├── test_image.py │ ├── test_insert_along_axis.py │ ├── test_iteration.py │ ├── test_logger_utils.py │ ├── test_mem.py │ ├── test_mnist_ubyte.py │ ├── test_model.yaml │ ├── test_pooling.py │ ├── test_rng.py │ ├── test_serial.py │ ├── test_string_utils.py │ ├── test_utlc.py │ └── test_video.py │ ├── theano_graph.py │ ├── timing.py │ ├── track_version.py │ ├── utlc.py │ └── video.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *~ 3 | *.swp 4 | *.bak 5 | 6 | #Don't track the binary data files: 7 | *.npy 8 | *.pkl 9 | *.pickle 10 | 11 | #Don't track the image files: 12 | *.png 13 | *.jpg 14 | 15 | #Don't track mac file 16 | .DS_Store 17 | 18 | #Don't track mac/linux .inputrc files 19 | .inputrc 20 | 21 | #Don't track Pycharm .idea folder 22 | .idea 23 | 24 | # Don't track pylint users' pylintrc files 25 | pylintrc 26 | 27 | # Don't track backup files generated by merge tools like meld 28 | *.orig 29 | 30 | # Don't track setuptools directories 31 | /build/ 32 | /pylearn2.egg-info/ 33 | 34 | # Don't track files generated by utils/setup.py 35 | pylearn2/utils/_video.c 36 | pylearn2/utils/_video.so 37 | pylearn2/utils/_window_flip.c 38 | pylearn2/utils/_window_flip.so 39 | pylearn2/utils/build/ 40 | -------------------------------------------------------------------------------- /.requirements.txt: -------------------------------------------------------------------------------- 1 | # This is for readthedocs.org to be able to build the documentation, 2 | # ignore otherwise 3 | numpydoc 4 | git+git://github.com/Theano/Theano.git 5 | -------------------------------------------------------------------------------- /.travis.sh: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | 3 | set -x -e 4 | 5 | if [ "x$TEST_DOC" = "xYES" ]; then 6 | export PYTHONPATH=${PYTHONPATH}:`pwd` 7 | python ./doc/scripts/docgen.py --test 8 | else 9 | # We can't build the test dataset as the original is not 10 | # present. We can't download the original as it is too big to 11 | # download each time. If present run: python make_dataset.py 12 | cd pylearn2/scripts/tutorials/grbm_smd; { wget -t 1 http://www.iro.umontreal.ca/~lisa/datasets/cifar10_preprocessed_train.pkl && export PKL=true || export PKL=false; } 13 | cd - 14 | THEANO_FLAGS="$FLAGS",-warn.ignore_bug_before=all,on_opt_error=raise,on_shape_error=raise theano-nose -v $PART 15 | fi 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: python 3 | before_install: 4 | - wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh 5 | - chmod +x miniconda.sh 6 | - ./miniconda.sh -b 7 | - export PATH=/home/travis/miniconda/bin:/home/travis/miniconda2/bin:$PATH 8 | - conda update --yes conda 9 | install: 10 | - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then conda create --yes -q -n pyenv python=2.7 mkl pyzmq cython=0.21.1 pillow numpy=1.9.1 numpydoc scipy=0.14.0 pytables=3.1.1 numexpr=2.3.1 nose=1.3.4 pyyaml sphinx pyflakes pip matplotlib scikit-learn h5py libgfortran=1; fi 11 | - if [[ $TRAVIS_PYTHON_VERSION == '3.4' ]]; then conda create --yes -q -n pyenv python=3.4 mkl pyzmq cython=0.21.1 pillow numpy=1.9.1 numpydoc scipy=0.14.0 pytables=3.1.1 numexpr=2.3.1 nose=1.3.4 pyyaml sphinx pyflakes pip matplotlib scikit-learn h5py libgfortran=1; fi 12 | - source activate pyenv 13 | - pip install -q nose-parameterized==0.5.0 14 | - pip install -q git+git://git.assembla.com/jobman.git 15 | - pip install -q --no-deps git+git://github.com/Theano/Theano.git 16 | - pip install -q nose-exclude 17 | - python setup.py develop 18 | matrix: 19 | include: 20 | - python: "2.7" 21 | env: FLAGS=floatX=float64 PART="--exclude-dir=pylearn2/models" 22 | - python: "2.7" 23 | env: FLAGS=floatX=float64 PART=pylearn2/models 24 | - python: "2.7" 25 | env: TEST_DOC=YES 26 | - python: "3.4" 27 | env: FLAGS=floatX=float32 PART="--exclude-dir=pylearn2/models" 28 | - python: "3.4" 29 | env: FLAGS=floatX=float32 PART=pylearn2/models 30 | script: 31 | - sh .travis.sh 32 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011--2017, Université de Montréal 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst 2 | recursive-include doc * 3 | 4 | -------------------------------------------------------------------------------- /bin/pylearn2-plot-monitor: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- encoding: utf-8 -*- 3 | from theano.compat.six import exec_ 4 | 5 | from pylearn2.scripts import plot_monitor 6 | filename = plot_monitor.__file__ 7 | f = open(filename[:-1 if filename.endswith('.pyc') else None]) 8 | exec_(f.read()) 9 | -------------------------------------------------------------------------------- /bin/pylearn2-print-monitor: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- encoding: utf-8 -*- 3 | from theano.compat.six import exec_ 4 | 5 | from pylearn2.scripts import print_monitor 6 | filename = print_monitor.__file__ 7 | f = open(filename[:-1 if filename.endswith('.pyc') else None]) 8 | exec_(f.read()) 9 | -------------------------------------------------------------------------------- /bin/pylearn2-show-examples: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- encoding: utf-8 -*- 3 | from theano.compat.six import exec_ 4 | 5 | from pylearn2.scripts import show_examples 6 | filename = show_examples.__file__ 7 | f = open(filename[:-1 if filename.endswith('.pyc') else None]) 8 | exec_(f.read()) 9 | -------------------------------------------------------------------------------- /bin/pylearn2-show-weights: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- encoding: utf-8 -*- 3 | from theano.compat.six import exec_ 4 | 5 | from pylearn2.scripts import show_weights 6 | filename = show_weights.__file__ 7 | f = open(filename[:-1 if filename.endswith('.pyc') else None]) 8 | exec_(f.read()) 9 | -------------------------------------------------------------------------------- /bin/pylearn2-train: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- encoding: utf-8 -*- 3 | from theano.compat.six import exec_ 4 | 5 | from pylearn2.scripts import train 6 | filename = train.__file__ 7 | f = open(filename[:-1 if filename.endswith('.pyc') else None]) 8 | exec_(f.read()) 9 | -------------------------------------------------------------------------------- /doc/LICENSE.txt: -------------------------------------------------------------------------------- 1 | .. _license: 2 | 3 | LICENSE 4 | ======= 5 | 6 | Copyright (c) 2008--2011, Theano Development Team 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | 12 | * Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | * Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | * Neither the name of Theano nor the names of its contributors may be 18 | used to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 22 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /doc/internal/index.txt: -------------------------------------------------------------------------------- 1 | 2 | .. _internal: 3 | 4 | ====================== 5 | Internal Documentation 6 | ====================== 7 | 8 | .. toctree:: 9 | :maxdepth: 2 10 | 11 | dev_start_guide 12 | data_specs 13 | pull_request_checklist 14 | -------------------------------------------------------------------------------- /doc/library/alex.txt: -------------------------------------------------------------------------------- 1 | ============ 2 | Cuda-Convnet 3 | ============ 4 | 5 | .. contents:: 6 | :depth: 3 7 | 8 | 9 | ##### 10 | Intro 11 | ##### 12 | 13 | These are wrappers around some of the GPU code from Alex Krizhevsky cuda-convnet project. 14 | http://code.google.com/p/cuda-convnet/ 15 | 16 | Sander Dieleman wrote an `excellent blog post 17 | `_ 18 | that describes how to use this module without the rest of Pylearn2. 19 | 20 | ####### 21 | Modules 22 | ####### 23 | 24 | Convolution 25 | =========== 26 | .. automodule:: pylearn2.sandbox.cuda_convnet.filter_acts 27 | :members: 28 | .. automodule:: pylearn2.sandbox.cuda_convnet.img_acts 29 | :members: 30 | .. automodule:: pylearn2.sandbox.cuda_convnet.weight_acts 31 | :members: 32 | 33 | Pool 34 | ==== 35 | .. automodule:: pylearn2.sandbox.cuda_convnet.pool 36 | :members: 37 | .. automodule:: pylearn2.sandbox.cuda_convnet.probabilistic_max_pooling 38 | :members: 39 | .. automodule:: pylearn2.sandbox.cuda_convnet.stochastic_pool 40 | :members: 41 | 42 | Response Normalization 43 | ======================= 44 | .. automodule:: pylearn2.sandbox.cuda_convnet.response_norm 45 | :members: 46 | 47 | 48 | -------------------------------------------------------------------------------- /doc/library/config.txt: -------------------------------------------------------------------------------- 1 | ============= 2 | Configuration 3 | ============= 4 | 5 | YAML parser 6 | =========== 7 | .. automodule:: pylearn2.config.yaml_parse 8 | :members: 9 | 10 | Old configuration 11 | ================= 12 | .. automodule:: pylearn2.config.old_config 13 | :members: -------------------------------------------------------------------------------- /doc/library/corruption.txt: -------------------------------------------------------------------------------- 1 | ========== 2 | Corruption 3 | ========== 4 | 5 | .. automodule:: pylearn2.corruption 6 | :members: 7 | -------------------------------------------------------------------------------- /doc/library/costs.txt: -------------------------------------------------------------------------------- 1 | ===== 2 | Costs 3 | ===== 4 | 5 | Basic 6 | ===== 7 | .. automodule:: pylearn2.costs.cost 8 | :members: 9 | 10 | MLP 11 | === 12 | 13 | Basic 14 | ##### 15 | .. automodule:: pylearn2.costs.mlp 16 | :members: 17 | 18 | Dropout 19 | ####### 20 | .. automodule:: pylearn2.costs.mlp.dropout 21 | :members: 22 | 23 | Missing target cost 24 | ################### 25 | .. automodule:: pylearn2.costs.mlp.missing_target_cost 26 | :members: 27 | 28 | Auto Encoder 29 | ============ 30 | .. automodule:: pylearn2.costs.autoencoder 31 | :members: 32 | 33 | DBM 34 | === 35 | .. automodule:: pylearn2.costs.dbm 36 | :members: 37 | 38 | EBM 39 | === 40 | .. automodule:: pylearn2.costs.ebm_estimation 41 | :members: 42 | 43 | GSN 44 | === 45 | .. automodule:: pylearn2.costs.gsn 46 | :members: 47 | 48 | -------------------------------------------------------------------------------- /doc/library/devtools.txt: -------------------------------------------------------------------------------- 1 | =============== 2 | Developer tools 3 | =============== 4 | 5 | List Files 6 | ========== 7 | .. automodule:: pylearn2.devtools.list_files 8 | :members: 9 | 10 | Run pyflakes 11 | ============ 12 | .. automodule:: pylearn2.devtools.run_pyflakes 13 | :members: 14 | 15 | 16 | -------------------------------------------------------------------------------- /doc/library/distributions.txt: -------------------------------------------------------------------------------- 1 | ============= 2 | Distributions 3 | ============= 4 | 5 | Multivariate Normal Distribution 6 | ================================ 7 | .. automodule:: pylearn2.distributions.mnd 8 | :members: 9 | 10 | Multinomial 11 | =========== 12 | .. automodule:: pylearn2.distributions.multinomial 13 | :members: 14 | 15 | Parzen 16 | ====== 17 | .. automodule:: pylearn2.distributions.parzen 18 | :members: 19 | 20 | Uniform Hypersphere 21 | =================== 22 | .. automodule:: pylearn2.distributions.uniform_hypersphere 23 | :members: 24 | 25 | 26 | -------------------------------------------------------------------------------- /doc/library/energy_functions.txt: -------------------------------------------------------------------------------- 1 | ================ 2 | Energy Functions 3 | ================ 4 | 5 | Basic 6 | ===== 7 | .. automodule:: pylearn2.energy_functions.energy_function 8 | :members: 9 | 10 | RBM Energy 11 | ========== 12 | .. automodule:: pylearn2.energy_functions.rbm_energy 13 | :members: 14 | -------------------------------------------------------------------------------- /doc/library/expr.txt: -------------------------------------------------------------------------------- 1 | =========== 2 | Expressions 3 | =========== 4 | 5 | Activations 6 | =========== 7 | .. automodule:: pylearn2.expr.activations 8 | :members: 9 | 10 | Basic 11 | ===== 12 | .. automodule:: pylearn2.expr.basic 13 | :members: 14 | 15 | Coding 16 | ====== 17 | .. automodule:: pylearn2.expr.coding 18 | :members: 19 | 20 | Image 21 | ===== 22 | .. automodule:: pylearn2.expr.image 23 | :members: 24 | 25 | Information Theory 26 | ================== 27 | .. automodule:: pylearn2.expr.information_theory 28 | :members: 29 | 30 | Neural Network 31 | ============== 32 | .. automodule:: pylearn2.expr.nnet 33 | :members: 34 | 35 | Normalization 36 | ============= 37 | .. automodule:: pylearn2.expr.normalize 38 | :members: 39 | 40 | Preprocessing 41 | ============= 42 | .. automodule:: pylearn2.expr.preprocessing 43 | :members: 44 | 45 | Probabilistic Max Pooling 46 | ========================= 47 | .. automodule:: pylearn2.expr.probabilistic_max_pooling 48 | :members: 49 | 50 | Sampling 51 | ======== 52 | .. automodule:: pylearn2.expr.sampling 53 | :members: 54 | 55 | Stochastic Pool 56 | =============== 57 | .. automodule:: pylearn2.expr.stochastic_pool 58 | :members: -------------------------------------------------------------------------------- /doc/library/format.txt: -------------------------------------------------------------------------------- 1 | ========== 2 | Formatting 3 | ========== 4 | 5 | Target format 6 | ============= 7 | .. automodule:: pylearn2.format.target_format 8 | :members: 9 | -------------------------------------------------------------------------------- /doc/library/gui.txt: -------------------------------------------------------------------------------- 1 | ======================== 2 | Graphical User Interface 3 | ======================== 4 | 5 | Weights report 6 | ============== 7 | .. automodule:: pylearn2.gui.get_weights_report 8 | :members: 9 | 10 | 2D graphs 11 | ========= 12 | .. automodule:: pylearn2.gui.graph_2D 13 | :members: 14 | 15 | Patch viewer 16 | ============ 17 | .. automodule:: pylearn2.gui.patch_viewer 18 | :members: 19 | -------------------------------------------------------------------------------- /doc/library/index.txt: -------------------------------------------------------------------------------- 1 | .. _libdoc: 2 | 3 | ===================== 4 | Library Documentation 5 | ===================== 6 | 7 | .. toctree:: 8 | :maxdepth: 3 9 | 10 | datasets 11 | models 12 | corruption 13 | train 14 | costs 15 | monitor 16 | linear 17 | alex 18 | scripts 19 | config 20 | devtools 21 | distributions 22 | energy_functions 23 | expr 24 | format 25 | gui 26 | optimization 27 | utils 28 | termination_criteria 29 | space 30 | misc 31 | 32 | -------------------------------------------------------------------------------- /doc/library/linear.txt: -------------------------------------------------------------------------------- 1 | ================ 2 | Linear Transform 3 | ================ 4 | 5 | .. contents:: 6 | :depth: 3 7 | 8 | 9 | ##### 10 | Intro 11 | ##### 12 | 13 | .. automodule:: pylearn2.linear 14 | :members: 15 | 16 | ######### 17 | Functions 18 | ######### 19 | 20 | 2D Convolution 21 | ============== 22 | .. automodule:: pylearn2.linear.conv2d 23 | :members: 24 | 25 | 2D Convolution C01B 26 | =================== 27 | .. automodule:: pylearn2.linear.conv2d_c01b 28 | :members: 29 | 30 | 31 | Matrix Multiplication 32 | ===================== 33 | .. automodule:: pylearn2.linear.matrixmul 34 | :members: 35 | 36 | Linear Transformation 37 | ===================== 38 | .. automodule:: pylearn2.linear.linear_transform 39 | :members: 40 | 41 | Local C01B 42 | ========== 43 | .. automodule:: pylearn2.linear.local_c01b 44 | :members: 45 | 46 | -------------------------------------------------------------------------------- /doc/library/misc.txt: -------------------------------------------------------------------------------- 1 | ============= 2 | Miscellaneous 3 | ============= 4 | 5 | .. contents:: 6 | :depth: 3 7 | 8 | Blocks 9 | ====== 10 | .. automodule:: pylearn2.blocks 11 | :members: 12 | 13 | RBM tools 14 | ========= 15 | .. automodule:: pylearn2.rbm_tools 16 | :members: 17 | 18 | -------------------------------------------------------------------------------- /doc/library/monitor.txt: -------------------------------------------------------------------------------- 1 | ========== 2 | Monitoring 3 | ========== 4 | 5 | Monitor 6 | ======= 7 | .. automodule:: pylearn2.monitor 8 | :members: 9 | 10 | -------------------------------------------------------------------------------- /doc/library/optimization.txt: -------------------------------------------------------------------------------- 1 | ============ 2 | Optimization 3 | ============ 4 | 5 | Batch Gradient Descent 6 | ====================== 7 | .. automodule:: pylearn2.optimization.batch_gradient_descent 8 | :members: 9 | 10 | Feature Sign 11 | ============ 12 | .. automodule:: pylearn2.optimization.feature_sign 13 | :members: 14 | 15 | Linear conjugate 16 | ================ 17 | .. automodule:: pylearn2.optimization.linear_cg 18 | :members: 19 | 20 | Linesearch 21 | ========== 22 | .. automodule:: pylearn2.optimization.linesearch 23 | :members: 24 | 25 | Minimum Residual Norm 26 | ===================== 27 | .. automodule:: pylearn2.optimization.minres 28 | :members: -------------------------------------------------------------------------------- /doc/library/space.txt: -------------------------------------------------------------------------------- 1 | ===== 2 | Space 3 | ===== 4 | 5 | .. contents:: 6 | :depth: 3 7 | 8 | Basic 9 | ===== 10 | .. automodule:: pylearn2.space.__init__ 11 | :members: -------------------------------------------------------------------------------- /doc/library/termination_criteria.txt: -------------------------------------------------------------------------------- 1 | ==================== 2 | Termination Criteria 3 | ==================== 4 | 5 | .. contents:: 6 | :depth: 3 7 | 8 | Basic 9 | ===== 10 | .. automodule:: pylearn2.termination_criteria.__init__ 11 | :members: -------------------------------------------------------------------------------- /doc/library/train.txt: -------------------------------------------------------------------------------- 1 | ======== 2 | Training 3 | ======== 4 | 5 | 6 | .. contents:: 7 | :depth: 3 8 | 9 | ################# 10 | pylearn2.train.py 11 | ################# 12 | .. automodule:: pylearn2.train 13 | :members: 14 | 15 | ######################### 16 | pylearn2.scripts.train.py 17 | ######################### 18 | 19 | See :ref:`train-script`. 20 | 21 | 22 | ################### 23 | Training Algorithms 24 | ################### 25 | 26 | Base Class 27 | ========== 28 | .. automodule:: pylearn2.training_algorithms.training_algorithm 29 | :members: 30 | 31 | Default 32 | ======= 33 | .. automodule:: pylearn2.training_algorithms.default 34 | :members: 35 | 36 | Learning rule 37 | ============= 38 | .. automodule:: pylearn2.training_algorithms.learning_rule 39 | :members: 40 | 41 | Stochastic Gradient Descent 42 | =========================== 43 | .. automodule:: pylearn2.training_algorithms.sgd 44 | :members: 45 | 46 | Batch Gradient Descent 47 | =========================== 48 | .. automodule:: pylearn2.training_algorithms.bgd 49 | :members: 50 | 51 | 52 | ################ 53 | Train Extensions 54 | ################ 55 | 56 | Basic 57 | ===== 58 | .. automodule:: pylearn2.train_extensions.__init__ 59 | :members: 60 | 61 | Best Params 62 | =========== 63 | .. automodule:: pylearn2.train_extensions.best_params 64 | :members: 65 | 66 | Window Flip 67 | =========== 68 | .. automodule:: pylearn2.train_extensions.window_flip 69 | :members: 70 | -------------------------------------------------------------------------------- /doc/themes/solar/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "basic/layout.html" %} 2 | 3 | {%- block doctype -%} 4 | 5 | {%- endblock -%} 6 | 7 | {%- block extrahead -%} 8 | 9 | 10 | {%- endblock -%} 11 | 12 | {# put the sidebar before the body #} 13 | {% block sidebar1 %}{{ sidebar() }}{% endblock %} 14 | {% block sidebar2 %}{% endblock %} 15 | 16 | {%- block footer %} 17 | 32 | {%- endblock %} 33 | -------------------------------------------------------------------------------- /doc/themes/solar/static/subtle_dots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/doc/themes/solar/static/subtle_dots.png -------------------------------------------------------------------------------- /doc/themes/solar/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | stylesheet = solar.css 4 | pygments_style = none 5 | -------------------------------------------------------------------------------- /doc/tutorial/notebook_tutorials.txt: -------------------------------------------------------------------------------- 1 | .. _notebook_tutorials: 2 | 3 | ========================== 4 | IPython Notebook Tutorials 5 | ========================== 6 | 7 | For more thorough tutorials on different models you can look at the ipython notebook tutorials at 8 | "pylearn2/scripts/tutorials/" 9 | 10 | How to Run 11 | ========== 12 | 13 | `Here `_ is a tutorial on ipython notebooks. But basically you can move to the tutorial folder and 14 | start the ipython notebook engine as follow:: 15 | 16 | $ ipython notebook 17 | 18 | 19 | View Static Versions Online 20 | ============================ 21 | 22 | Here are the links to the static versions of the notebooks that you can view online: 23 | 24 | * `Softmax Regression `_ 25 | * `Multilayer Perceptron `_ 26 | * `Convolutional Network `_ 27 | * `Stacked Autoencoders `_ 28 | -------------------------------------------------------------------------------- /doc/yaml_tutorial/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/doc/yaml_tutorial/__init__.py -------------------------------------------------------------------------------- /pylearn2/__init__.py: -------------------------------------------------------------------------------- 1 | # By default, we configure logging to be non-silent. Use `restore_defaults()` 2 | # from `pylearn2.utils.logger` to revert this behaviour. 3 | 4 | from pylearn2.utils.logger import configure_custom 5 | 6 | # TODO: make it configurable whether we pass debug=True here. By default 7 | # debug=False. 8 | configure_custom() 9 | 10 | # Remove this from the top-level namespace. 11 | del configure_custom 12 | 13 | 14 | -------------------------------------------------------------------------------- /pylearn2/compat.py: -------------------------------------------------------------------------------- 1 | """ 2 | Compatibility layer 3 | """ 4 | from theano.compat import six 5 | 6 | 7 | __all__ = ('OrderedDict', ) 8 | 9 | 10 | if six.PY3: 11 | from collections import OrderedDict 12 | else: 13 | from theano.compat import OrderedDict 14 | 15 | 16 | def first_key(obj): 17 | """ Return the first key 18 | 19 | Parameters 20 | ---------- 21 | obj: dict-like object 22 | """ 23 | return six.next(six.iterkeys(obj)) 24 | 25 | 26 | def first_value(obj): 27 | """ Return the first value 28 | 29 | Parameters 30 | ---------- 31 | obj: dict-like object 32 | """ 33 | return six.next(six.itervalues(obj)) 34 | -------------------------------------------------------------------------------- /pylearn2/config/__init__.py: -------------------------------------------------------------------------------- 1 | from .yaml_parse import initialize 2 | -------------------------------------------------------------------------------- /pylearn2/config/old_config.py: -------------------------------------------------------------------------------- 1 | import yaml 2 | import inspect 3 | import types 4 | 5 | from pylearn2.utils.exc import reraise_as 6 | 7 | global resolvers 8 | 9 | def load(json_file_path): 10 | """ given a file path to a json file, returns the dictionary definde by the json file """ 11 | 12 | f = open(json_file_path) 13 | lines = f.readlines() 14 | f.close() 15 | 16 | content = ''.join(lines) 17 | 18 | return yaml.load(content) 19 | 20 | def get_field(d, key): 21 | try: 22 | rval = d[key] 23 | except KeyError: 24 | reraise_as(ValueError('Could not access "'+key+'" in \n'+str(d))) 25 | return rval 26 | 27 | def get_str(d, key): 28 | rval = get_field(d, key) 29 | 30 | if not isinstance(rval,str): 31 | raise TypeError('"'+key+'" entry is not a string in the following: \n'+str(d)) 32 | 33 | return rval 34 | 35 | def get_tag(d): 36 | return get_str(d, 'tag') 37 | 38 | def resolve(d): 39 | """ given a dictionary d, returns the object described by the dictionary """ 40 | 41 | tag = get_tag(d) 42 | 43 | try: 44 | resolver = resolvers[tag] 45 | except KeyError: 46 | reraise_as(TypeError('config does not know of any object type "'+tag+'"')) 47 | 48 | return resolver(d) 49 | 50 | def resolve_model(d): 51 | assert False 52 | 53 | def resolve_dataset(d): 54 | import pylearn2.datasets.config 55 | return pylearn2.datasets.config.resolve(d) 56 | 57 | def resolve_train_algorithm(d): 58 | assert False 59 | 60 | resolvers = { 61 | 'model' : resolve_model, 62 | 'dataset' : resolve_dataset, 63 | 'train_algorithm' : resolve_train_algorithm 64 | } 65 | 66 | 67 | -------------------------------------------------------------------------------- /pylearn2/config/tests/__init__.py: -------------------------------------------------------------------------------- 1 | """Tests for the YAML config system.""" 2 | -------------------------------------------------------------------------------- /pylearn2/costs/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Cost classes used to represent the objective functions we minimize 3 | during training. 4 | """ 5 | -------------------------------------------------------------------------------- /pylearn2/costs/mlp/missing_target_cost.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MissingTargetCost class. 3 | """ 4 | __author__ = 'Vincent Archambault-Bouffard' 5 | 6 | from functools import wraps 7 | 8 | import theano.tensor as T 9 | 10 | from pylearn2.costs.cost import Cost 11 | from pylearn2.space import CompositeSpace 12 | 13 | 14 | class MissingTargetCost(Cost): 15 | """ 16 | Dropout but with some targets optionally missing. The missing target is 17 | indicated by a value of -1. 18 | 19 | Parameters 20 | ---------- 21 | dropout_args : WRITEME 22 | """ 23 | 24 | supervised = True 25 | 26 | def __init__(self, dropout_args=None): 27 | self.__dict__.update(locals()) 28 | del self.self 29 | 30 | @wraps(Cost.expr) 31 | def expr(self, model, data): 32 | space, sources = self.get_data_specs(model) 33 | space.validate(data) 34 | (X, Y) = data 35 | if self.dropout_args: 36 | Y_hat = model.dropout_fprop(X, **self.dropout_args) 37 | else: 38 | Y_hat = model.fprop(X) 39 | costMatrix = model.layers[-1].cost_matrix(Y, Y_hat) 40 | # This sets to zero all elements where Y == -1 41 | costMatrix *= T.neq(Y, -1) 42 | return model.cost_from_cost_matrix(costMatrix) 43 | 44 | @wraps(Cost.get_data_specs) 45 | def get_data_specs(self, model): 46 | space = CompositeSpace([model.get_input_space(), 47 | model.get_output_space()]) 48 | sources = (model.get_input_source(), model.get_target_source()) 49 | return (space, sources) 50 | -------------------------------------------------------------------------------- /pylearn2/costs/tests/test_lp_penalty_cost.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test LpPenalty cost 3 | """ 4 | import numpy 5 | import theano 6 | from pylearn2.models.mlp import Linear 7 | from pylearn2.models.mlp import Softmax 8 | from pylearn2.models.mlp import MLP 9 | from pylearn2.costs.cost import LpPenalty 10 | 11 | 12 | def test_correctness(): 13 | """ 14 | Test that the Theano implementation matches a numpy implementation. 15 | """ 16 | model = MLP( 17 | layers=[Linear(dim=10, layer_name='linear', irange=1.0), 18 | Softmax(n_classes=2, layer_name='softmax', irange=1.0)], 19 | batch_size=10, 20 | nvis=10 21 | ) 22 | 23 | cost = LpPenalty(variables=model.get_params(), p=2) 24 | 25 | penalty = cost.expr(model, None) 26 | 27 | penalty_function = theano.function(inputs=[], outputs=penalty) 28 | 29 | p = penalty_function() 30 | 31 | actual_p = 0 32 | for param in model.get_params(): 33 | actual_p += numpy.sum(param.get_value() ** 2) 34 | 35 | assert numpy.allclose(p, actual_p) 36 | 37 | 38 | if __name__ == '__main__': 39 | test_correctness() 40 | -------------------------------------------------------------------------------- /pylearn2/costs/tests/test_sparse_activation.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test autoencoder sparse activation cost. 3 | """ 4 | from pylearn2.config import yaml_parse 5 | 6 | 7 | def test_sparse_activation(): 8 | """Test autoencoder sparse activation cost.""" 9 | trainer = yaml_parse.load(test_yaml) 10 | trainer.main_loop() 11 | 12 | test_yaml = """ 13 | !obj:pylearn2.train.Train { 14 | dataset: &train 15 | !obj:pylearn2.testing.datasets.random_one_hot_dense_design_matrix 16 | { 17 | rng: !obj:numpy.random.RandomState { seed: 1 }, 18 | num_examples: 10, 19 | dim: 5, 20 | num_classes: 2, 21 | }, 22 | model: !obj:pylearn2.models.autoencoder.Autoencoder { 23 | nvis: 5, 24 | nhid: 10, 25 | act_enc: sigmoid, 26 | act_dec: linear, 27 | }, 28 | algorithm: !obj:pylearn2.training_algorithms.bgd.BGD { 29 | batch_size: 5, 30 | line_search_mode: exhaustive, 31 | conjugate: 1, 32 | cost: !obj:pylearn2.costs.cost.SumOfCosts { 33 | costs: [ 34 | !obj:pylearn2.costs.autoencoder.MeanSquaredReconstructionError { 35 | }, 36 | !obj:pylearn2.costs.autoencoder.SparseActivation { 37 | coeff: 0.5, 38 | p: 0.2, 39 | }, 40 | ], 41 | }, 42 | monitoring_dataset: { 43 | 'train': *train, 44 | }, 45 | termination_criterion: !obj:pylearn2.termination_criteria.EpochCounter 46 | { 47 | max_epochs: 1, 48 | }, 49 | }, 50 | } 51 | """ 52 | -------------------------------------------------------------------------------- /pylearn2/dataset_get/dataset-get: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # wrapper to make it more like a system 4 | # command (does not require +x on dataset-get.py 5 | # nor invoking python explicitly) 6 | # 7 | 8 | python dataset-get.py ${@} 9 | exit $? 10 | -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/docs/license.txt: -------------------------------------------------------------------------------- 1 | contains the license statement, 2 | or a link to the license statement 3 | -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/docs/other.txt: -------------------------------------------------------------------------------- 1 | contains something else. Doesn't have to be named "other" either. 2 | -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff009bf24412862511cf7eeeab5aa134.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff009bf24412862511cf7eeeab5aa134.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff191fc088d491f6b54871339f114b7f.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff191fc088d491f6b54871339f114b7f.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff26a864b8b8ee1aa01413a4fc7b2b93.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff26a864b8b8ee1aa01413a4fc7b2b93.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff3b264a0ccf9b366e87f4b8eeb1c3a4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff3b264a0ccf9b366e87f4b8eeb1c3a4.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff40c2792e53fdbc3bc849028f304c00.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff40c2792e53fdbc3bc849028f304c00.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff455d3fb4e8bebb5ea14dcb6630d32d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff455d3fb4e8bebb5ea14dcb6630d32d.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff6848ee9d56b4dc36376f4b998662fe.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff6848ee9d56b4dc36376f4b998662fe.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff749d5d9c03e59b6cb4b09081df95df.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff749d5d9c03e59b6cb4b09081df95df.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff7edaf73cb4a5f6ca6fc7341a59a618.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff7edaf73cb4a5f6ca6fc7341a59a618.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff8c52a9e96d57fa35e6c6b7959cc70a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff8c52a9e96d57fa35e6c6b7959cc70a.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff91bb2abc9b4225711bd45941c304d3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff91bb2abc9b4225711bd45941c304d3.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff9c870d7f75c979c8ae200f5cd5d246.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff9c870d7f75c979c8ae200f5cd5d246.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff9e25c7a059d40866fdb6848ed75134.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ff9e25c7a059d40866fdb6848ed75134.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ffa361ac89f7ecd07a313b672a752c20.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ffa361ac89f7ecd07a313b672a752c20.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ffb68ce0546a24f0dd4a52cb7b95a1b6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ffb68ce0546a24f0dd4a52cb7b95a1b6.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ffbea58fd0203a343f87ad4e799e9fa0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/dataset_get/example-package/fake-dataset/fake-dataset/data/ffbea58fd0203a343f87ad4e799e9fa0.jpg -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/readme.1rst: -------------------------------------------------------------------------------- 1 | This contains the readme first text. 2 | -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/scripts/getscript: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # script that fetches the data, if needed 4 | # 5 | echo "$0: [some package-specific output goes here]" 6 | 7 | exit 0 8 | -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/scripts/postinst: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # script that does stuff after the data is available, 4 | # maybe preprocess/convert 5 | # 6 | echo "$0: [some package-specific output goes here]" 7 | 8 | exit 0 9 | -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/scripts/postrm: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # script that does stuff after removing, if needed 4 | # 5 | echo "$0: [some package-specific output goes here]" 6 | 7 | exit 0 8 | -------------------------------------------------------------------------------- /pylearn2/dataset_get/example-package/fake-dataset/scripts/prerm: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # script that does stuff before removing, if needed 4 | # 5 | echo "$0: [some package-specific output goes here]" 6 | 7 | exit 0 8 | -------------------------------------------------------------------------------- /pylearn2/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | from pylearn2.datasets.dataset import Dataset 2 | from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix 3 | -------------------------------------------------------------------------------- /pylearn2/datasets/avicenna.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. todo:: 3 | 4 | WRITEME 5 | """ 6 | from pylearn2.datasets import utlc 7 | import numpy as N 8 | 9 | 10 | class Avicenna(object): 11 | 12 | """ 13 | .. todo:: 14 | 15 | WRITEME 16 | 17 | Parameters 18 | ---------- 19 | which_set : WRITEME 20 | standardize : WRITEME 21 | """ 22 | 23 | def __init__(self, which_set, standardize): 24 | train, valid, test = utlc.load_ndarray_dataset('avicenna') 25 | 26 | if which_set == 'train': 27 | self.X = train 28 | elif which_set == 'valid': 29 | self.X = valid 30 | elif which_set == 'test': 31 | self.X = test 32 | else: 33 | assert False 34 | 35 | if standardize: 36 | union = N.concatenate([train, valid, test], axis=0) 37 | # perform mean and std in float64 to avoid losing 38 | # too much numerical precision 39 | self.X -= union.mean(axis=0, dtype='float64') 40 | std = union.std(axis=0, dtype='float64') 41 | std[std < 1e-3] = 1e-3 42 | self.X /= std 43 | 44 | def get_design_matrix(self): 45 | """ 46 | .. todo:: 47 | 48 | WRITEME 49 | """ 50 | return self.X 51 | -------------------------------------------------------------------------------- /pylearn2/datasets/binarizer.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. todo:: 3 | 4 | WRITEME 5 | """ 6 | __authors__ = "Ian Goodfellow" 7 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 8 | __credits__ = ["Ian Goodfellow"] 9 | __license__ = "3-clause BSD" 10 | __maintainer__ = "LISA Lab" 11 | __email__ = "pylearn-dev@googlegroups" 12 | 13 | from pylearn2.datasets.transformer_dataset import TransformerDataset 14 | from pylearn2.expr.sampling import SampleBernoulli 15 | 16 | 17 | class Binarizer(TransformerDataset): 18 | 19 | """ 20 | A TransformerDataset that takes examples with features in the interval 21 | [0,1], and uses these as Bernoulli parameters to sample examples 22 | with features in {0,1}. 23 | 24 | Parameters 25 | ---------- 26 | raw : pylearn2 Dataset 27 | It must provide examples with features in the interval [0,1]. 28 | seed : integer or list of integers, optional 29 | The seed passed to MRG_RandomStreams to make the Bernoulli 30 | samples. If not specified, all class instances default to 31 | the same seed so two instances can be run synchronized side 32 | by side. 33 | """ 34 | 35 | def __init__(self, raw, seed=None): 36 | transformer = SampleBernoulli(seed=seed) 37 | 38 | super(Binarizer, self).__init__( 39 | raw, transformer, space_preserving=True) 40 | 41 | def get_design_matrix(self, topo=None): 42 | """ 43 | .. todo:: 44 | 45 | WRITEME 46 | """ 47 | if topo is not None: 48 | return self.raw.get_design_matrix(topo) 49 | X = self.raw.get_design_matrix() 50 | return self.transformer.perform(X) 51 | -------------------------------------------------------------------------------- /pylearn2/datasets/config.py: -------------------------------------------------------------------------------- 1 | from pylearn2.utils.exc import reraise_as 2 | """ 3 | .. todo:: 4 | 5 | WRITEME 6 | """ 7 | global resolvers 8 | 9 | 10 | def resolve(d): 11 | """ 12 | .. todo:: 13 | 14 | WRITEME 15 | """ 16 | tag = pylearn2.config.get_tag(d) 17 | 18 | if tag != 'dataset': 19 | raise TypeError('pylearn2.datasets.config asked to resolve a config ' 20 | 'dictionary with tag "%s"' % tag) 21 | 22 | typename = pylearn2.config.get_str(d, 'typename') 23 | 24 | try: 25 | resolver = resolvers[typename] 26 | except KeyError: 27 | reraise_as(TypeError('pylearn2.datasets does not know of a dataset ' 28 | 'type "%s"' % typename)) 29 | 30 | return resolver(d) 31 | 32 | 33 | def resolve_avicenna(d): 34 | """ 35 | .. todo:: 36 | 37 | WRITEME 38 | """ 39 | import pylearn2.datasets.avicenna 40 | return pylearn2.config.checked_call(pylearn2.datasets.avicenna.Avicenna, d) 41 | 42 | resolvers = { 43 | 'avicenna': resolve_avicenna 44 | } 45 | 46 | import pylearn2.config 47 | -------------------------------------------------------------------------------- /pylearn2/datasets/control.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. todo:: 3 | 4 | WRITEME 5 | """ 6 | __authors__ = "Ian Goodfellow" 7 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 8 | __credits__ = ["Ian Goodfellow"] 9 | __license__ = "3-clause BSD" 10 | __maintainer__ = "LISA Lab" 11 | __email__ = "pylearn-dev@googlegroups" 12 | 13 | 14 | load_data = [True] 15 | 16 | 17 | def pop_load_data(): 18 | """ 19 | .. todo:: 20 | 21 | WRITEME 22 | """ 23 | global load_data 24 | 25 | del load_data[-1] 26 | 27 | 28 | def push_load_data(setting): 29 | """ 30 | .. todo:: 31 | 32 | WRITEME 33 | """ 34 | global load_data 35 | 36 | load_data.append(setting) 37 | 38 | 39 | def get_load_data(): 40 | """ 41 | .. todo:: 42 | 43 | WRITEME 44 | """ 45 | return load_data[-1] 46 | -------------------------------------------------------------------------------- /pylearn2/datasets/debug.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. todo:: 3 | 4 | WRITEME 5 | """ 6 | import numpy as N 7 | from pylearn2.datasets import dense_design_matrix 8 | 9 | 10 | class DebugDataset(dense_design_matrix.DenseDesignMatrix): 11 | 12 | """ 13 | .. todo:: 14 | 15 | WRITEME 16 | """ 17 | 18 | def __init__(self): 19 | """ 20 | .. todo:: 21 | 22 | WRITEME 23 | """ 24 | 25 | view_converter = dense_design_matrix.DefaultViewConverter((32, 32, 3)) 26 | 27 | super(DebugDataset, self).__init__(X=N.asarray([[1.0, 0.0], 28 | [0.0, 1.0]]), 29 | view_converter=view_converter) 30 | 31 | assert not N.any(N.isnan(self.X)) 32 | -------------------------------------------------------------------------------- /pylearn2/datasets/exc.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. todo:: 3 | 4 | WRITEME 5 | """ 6 | __author__ = "Ian Goodfellow" 7 | """ 8 | Exceptions related to datasets 9 | """ 10 | 11 | from pylearn2.utils.exc import EnvironmentVariableError, NoDataPathError 12 | from pylearn2.utils.common_strings import environment_variable_essay 13 | 14 | 15 | class NotInstalledError(Exception): 16 | 17 | """ 18 | Exception raised when a dataset appears not to be installed. 19 | This is different from an individual file missing within a dataset, 20 | the file not loading correctly, etc. 21 | This exception is used to make unit tests skip testing of datasets 22 | that haven't been installed. 23 | We do want the unit test to run and crash if the dataset is installed 24 | incorrectly. 25 | """ 26 | -------------------------------------------------------------------------------- /pylearn2/datasets/matlab_dataset.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. todo:: 3 | 4 | WRITEME 5 | """ 6 | import numpy as N 7 | import warnings 8 | try: 9 | from scipy import io 10 | except ImportError: 11 | warnings.warn("Could not import scipy") 12 | from pylearn2.datasets import dense_design_matrix 13 | from theano import config 14 | 15 | 16 | class MatlabDataset(dense_design_matrix.DenseDesignMatrix): 17 | 18 | """ 19 | .. todo:: 20 | 21 | WRITEME 22 | """ 23 | 24 | def __init__(self, path, which_set): 25 | """ 26 | .. todo:: 27 | 28 | WRITEME 29 | """ 30 | Xs = io.loadmat(path) 31 | X = Xs[which_set] 32 | super(MatlabDataset, self).__init__(X=N.cast[config.floatX](X)) 33 | assert not N.any(N.isnan(self.X)) 34 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Dataset testing classes 3 | """ 4 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test.csv: -------------------------------------------------------------------------------- 1 | 0,1,2,3 2 | 1,4,5,6 3 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_adult.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test code for adult.py 3 | ======= 4 | Testing class that simply checks to see if the adult dataset 5 | is loadable 6 | """ 7 | import numpy 8 | from pylearn2.datasets.adult import adult 9 | from pylearn2.testing.skip import skip_if_no_data 10 | 11 | 12 | def test_adult(): 13 | """ 14 | Tests if it will work correctly for train and test set. 15 | """ 16 | skip_if_no_data() 17 | adult_train = adult(which_set='train') 18 | assert (adult_train.X >= 0.).all() 19 | assert adult_train.y.dtype == bool 20 | assert adult_train.X.shape == (30162, 104) 21 | assert adult_train.y.shape == (30162, 1) 22 | 23 | adult_test = adult(which_set='test') 24 | assert (adult_test.X >= 0.).all() 25 | assert adult_test.y.dtype == bool 26 | assert adult_test.X.shape == (15060, 103) 27 | assert adult_test.y.shape == (15060, 1) 28 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_avicenna.py: -------------------------------------------------------------------------------- 1 | """module for testing datasets.avicenna""" 2 | import unittest 3 | import numpy as np 4 | from pylearn2.datasets.avicenna import Avicenna 5 | from pylearn2.testing.skip import skip_if_no_data 6 | 7 | 8 | def test_avicenna(): 9 | """test that train/valid/test sets load (when standardize=False/true).""" 10 | skip_if_no_data() 11 | data = Avicenna(which_set='train', standardize=False) 12 | assert data.X.shape == (150205, 120) 13 | 14 | data = Avicenna(which_set='valid', standardize=False) 15 | assert data.X.shape == (4096, 120) 16 | 17 | data = Avicenna(which_set='test', standardize=False) 18 | assert data.X.shape == (4096, 120) 19 | 20 | # test that train/valid/test sets load (when standardize=True). 21 | data_train = Avicenna(which_set='train', standardize=True) 22 | assert data_train.X.shape == (150205, 120) 23 | 24 | data_valid = Avicenna(which_set='valid', standardize=True) 25 | assert data_valid.X.shape == (4096, 120) 26 | 27 | data_test = Avicenna(which_set='test', standardize=True) 28 | assert data_test.X.shape == (4096, 120) 29 | 30 | dt = np.concatenate([data_train.X, data_valid.X, data_test.X], axis=0) 31 | # Force double precision to compute mean and std, otherwise the test 32 | # fails because of precision. 33 | assert np.allclose(dt.mean(dtype='float64'), 0) 34 | assert np.allclose(dt.std(dtype='float64'), 1.) 35 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_cos_dataset.py: -------------------------------------------------------------------------------- 1 | """Test code for cos dataset.""" 2 | import numpy 3 | from pylearn2.datasets.cos_dataset import CosDataset 4 | from pylearn2.testing.skip import skip_if_no_data 5 | 6 | 7 | def test_cos_dataset(): 8 | """Tests if the dataset generator yields the desired value.""" 9 | skip_if_no_data() 10 | dataset = CosDataset() 11 | 12 | sample_batch = dataset.get_batch_design(batch_size=10000) 13 | assert sample_batch.shape == (10000, 2) 14 | assert sample_batch[:, 0].min() >= dataset.min_x 15 | assert sample_batch[:, 0].max() <= dataset.max_x 16 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_csv_dataset.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pylearn2 3 | from pylearn2.datasets.csv_dataset import CSVDataset 4 | import numpy as np 5 | 6 | 7 | def test_loading_classification(): 8 | test_path = os.path.join(pylearn2.__path__[0], 9 | 'datasets', 'tests', 'test.csv') 10 | d = CSVDataset(path=test_path, expect_headers=False) 11 | assert(np.array_equal(d.X, np.array([[1., 2., 3.], [4., 5., 6.]]))) 12 | assert(np.array_equal(d.y, np.array([[0.], [1.]]))) 13 | 14 | 15 | def test_loading_regression(): 16 | test_path = os.path.join(pylearn2.__path__[0], 17 | 'datasets', 'tests', 'test.csv') 18 | d = CSVDataset(path=test_path, task="regression", expect_headers=False) 19 | assert(np.array_equal(d.X, np.array([[1., 2., 3.], [4., 5., 6.]]))) 20 | assert(np.array_equal(d.y, np.array([[0.], [1.]]))) 21 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_four_regions.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from pylearn2.datasets.four_regions import FourRegions 3 | 4 | 5 | def test_four_regions(): 6 | dataset = FourRegions(5000) 7 | X = dataset.get_design_matrix() 8 | np.testing.assert_(((X < 1.) & (X > -1.)).all()) 9 | y = dataset.get_targets() 10 | np.testing.assert_equal(np.unique(y), [0, 1, 2, 3]) 11 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_hepatitis.py: -------------------------------------------------------------------------------- 1 | """module for testing datasets.hepatitis""" 2 | import numpy as np 3 | import pylearn2.datasets.hepatitis as hepatitis 4 | from pylearn2.testing.skip import skip_if_no_data 5 | 6 | 7 | def test_hepatitis(): 8 | """test hepatitis dataset""" 9 | skip_if_no_data() 10 | data = hepatitis.Hepatitis() 11 | assert data.X is not None 12 | assert np.all(data.X != np.inf) 13 | assert np.all(data.X != np.nan) 14 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_imports.py: -------------------------------------------------------------------------------- 1 | 2 | def test_mnist_imports(): 3 | 4 | from pylearn2.datasets.mnist import MNIST 5 | MNIST.shut_up_the_syntax_highlighting = 1 6 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_iris.py: -------------------------------------------------------------------------------- 1 | """module for testing datasets.iris""" 2 | import numpy as np 3 | import pylearn2.datasets.iris as iris 4 | from pylearn2.testing.skip import skip_if_no_data 5 | 6 | 7 | def test_iris(): 8 | """Load iris dataset""" 9 | skip_if_no_data() 10 | data = iris.Iris() 11 | assert data.X is not None 12 | assert np.all(data.X != np.inf) 13 | assert np.all(data.X != np.nan) 14 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_mnist_rotated.py: -------------------------------------------------------------------------------- 1 | """ 2 | Testing class that simply checks to see if the class is 3 | loadable 4 | """ 5 | from pylearn2.datasets.mnist import MNIST_rotated_background 6 | from pylearn2.datasets.tests.test_mnist import TestMNIST 7 | from pylearn2.testing.skip import skip_if_no_data 8 | 9 | 10 | class TestMNIST_rotated(TestMNIST): 11 | """ 12 | Parameters 13 | ---------- 14 | None 15 | 16 | Notes 17 | ----- 18 | Testing class that simply checks to see if the rotated mnist is 19 | loadable 20 | """ 21 | def setUp(self): 22 | """ 23 | Attempts to load train and test 24 | """ 25 | skip_if_no_data() 26 | self.train = MNIST_rotated_background(which_set='train') 27 | self.test = MNIST_rotated_background(which_set='test') 28 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_npy_npz.py: -------------------------------------------------------------------------------- 1 | from pylearn2.datasets.npy_npz import NpyDataset, NpzDataset 2 | import unittest 3 | from pylearn2.testing.skip import skip_if_no_data 4 | import numpy as np 5 | import os 6 | 7 | 8 | def test_npy_npz(): 9 | skip_if_no_data() 10 | arr = np.array([[3, 4, 5], [4, 5, 6]]) 11 | np.save('test.npy', arr) 12 | np.savez('test.npz', arr) 13 | npy = NpyDataset(file='test.npy') 14 | npy._deferred_load() 15 | npz = NpzDataset(file='test.npz', key='arr_0') 16 | assert np.all(npy.X == npz.X) 17 | os.remove('test.npy') 18 | os.remove('test.npz') 19 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_stl10.py: -------------------------------------------------------------------------------- 1 | """module for testing datasets.stl10""" 2 | import unittest 3 | from pylearn2.datasets import stl10 4 | from pylearn2.testing.skip import skip_if_no_data 5 | 6 | 7 | class TestSTL10(unittest.TestCase): 8 | 9 | """ 10 | This is a unittest for stl10.py. 11 | 12 | Parameters 13 | ---------- 14 | none 15 | 16 | """ 17 | 18 | def setUp(self): 19 | """This loads train and test sets.""" 20 | skip_if_no_data() 21 | data = stl10.STL10(which_set='train') 22 | data = stl10.STL10(which_set='test') 23 | 24 | def test_restrict(self): 25 | """This tests the restrict function on each fold of the train set.""" 26 | for fold in range(10): 27 | train = stl10.STL10(which_set='train') 28 | stl10.restrict(train, fold) 29 | 30 | # def disabled_test_unlabeled(self): 31 | # """The unlabeled data is 2.4GiB. This test is disabled by default.""" 32 | # data = stl10.STL10(which_set='unlabeled') 33 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_tl_challenge.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import numpy as np 3 | from pylearn2.datasets.tl_challenge import TL_Challenge 4 | from pylearn2.space import Conv2DSpace 5 | from pylearn2.testing.skip import skip_if_no_data 6 | 7 | 8 | class TestTL_Challenge(unittest.TestCase): 9 | 10 | def setUp(self): 11 | skip_if_no_data() 12 | 13 | def test_load(self): 14 | TL_Challenge(which_set='unlabeled') 15 | TL_Challenge(which_set='test') 16 | 17 | def test_topo(self): 18 | """Tests that a topological batch has 4 dimensions""" 19 | train = TL_Challenge(which_set='train') 20 | topo = train.get_batch_topo(1) 21 | assert topo.ndim == 4 22 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_transformer_dataset.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for ../transformer_dataset.py 3 | """ 4 | 5 | import os 6 | 7 | import pylearn2 8 | from pylearn2.blocks import Block 9 | from pylearn2.datasets.csv_dataset import CSVDataset 10 | from pylearn2.datasets.transformer_dataset import TransformerDataset 11 | 12 | 13 | def test_transformer_iterator(): 14 | """ 15 | Tests whether TransformerIterator is iterable 16 | """ 17 | 18 | test_path = os.path.join(pylearn2.__path__[0], 19 | 'datasets', 'tests', 'test.csv') 20 | raw = CSVDataset(path=test_path, expect_headers=False) 21 | block = Block() 22 | dataset = TransformerDataset(raw, block) 23 | iterator = dataset.iterator('shuffled_sequential', 3) 24 | try: 25 | iter(iterator) 26 | except TypeError: 27 | assert False, "TransformerIterator isn't iterable" 28 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_vector_spaces_dataset.py: -------------------------------------------------------------------------------- 1 | # Currently this test file does nothing but make sure the module can be 2 | # imported. 3 | from pylearn2.datasets import vector_spaces_dataset 4 | -------------------------------------------------------------------------------- /pylearn2/datasets/tests/test_wiskott.py: -------------------------------------------------------------------------------- 1 | """module to test datasets.wiskott""" 2 | from pylearn2.datasets.wiskott import Wiskott 3 | import unittest 4 | from pylearn2.testing.skip import skip_if_no_data 5 | from pylearn2.utils import isfinite 6 | import numpy as np 7 | 8 | 9 | def test_wiskott(): 10 | """loads wiskott dataset""" 11 | skip_if_no_data() 12 | data = Wiskott() 13 | assert isfinite(data.X) 14 | -------------------------------------------------------------------------------- /pylearn2/datasets/wiskott.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. todo:: 3 | 4 | WRITEME 5 | """ 6 | __authors__ = "Ian Goodfellow" 7 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 8 | __credits__ = ["Ian Goodfellow"] 9 | __license__ = "3-clause BSD" 10 | __maintainer__ = "LISA Lab" 11 | __email__ = "pylearn-dev@googlegroups" 12 | 13 | import numpy as N 14 | from pylearn2.datasets import dense_design_matrix 15 | from pylearn2.utils.serial import load 16 | 17 | 18 | class Wiskott(dense_design_matrix.DenseDesignMatrix): 19 | 20 | """ 21 | .. todo:: 22 | 23 | WRITEME 24 | """ 25 | 26 | def __init__(self): 27 | path = "${PYLEARN2_DATA_PATH}/wiskott/wiskott"\ 28 | + "_fish_layer0_15_standard_64x64_shuffled.npy" 29 | 30 | X = 1. - load(path) 31 | 32 | view_converter = dense_design_matrix.DefaultViewConverter((64, 64, 1)) 33 | 34 | super(Wiskott, self).__init__(X=X, view_converter=view_converter) 35 | 36 | assert not N.any(N.isnan(self.X)) 37 | -------------------------------------------------------------------------------- /pylearn2/devtools/__init__.py: -------------------------------------------------------------------------------- 1 | __authors__ = "Ian Goodfellow" 2 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 3 | __credits__ = ["Ian Goodfellow"] 4 | __license__ = "3-clause BSD" 5 | __maintainer__ = "LISA Lab" 6 | __email__ = "pylearn-dev@googlegroups" 7 | -------------------------------------------------------------------------------- /pylearn2/devtools/nan_guard.py: -------------------------------------------------------------------------------- 1 | """ 2 | Functionality for detecting NaNs in a Theano graph. 3 | """ 4 | __authors__ = "Ian Goodfellow" 5 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 6 | __credits__ = ["Ian Goodfellow"] 7 | __license__ = "3-clause BSD" 8 | __maintainer__ = "LISA Lab" 9 | __email__ = "pylearn-dev@googlegroups" 10 | 11 | import logging 12 | import theano.compile.nanguardmode 13 | 14 | logger = logging.getLogger(__name__) 15 | 16 | 17 | class NanGuardMode(theano.compile.nanguardmode.NanGuardMode): 18 | """ 19 | A Theano compilation Mode that makes the compiled function automatically 20 | detect NaNs and Infs and detect an error if they occur. This mode is now in 21 | theano, thus it is depreciated in pylearn2. 22 | 23 | Parameters 24 | ---------- 25 | nan_is_error : bool 26 | If True, raise an error anytime a NaN is encountered 27 | inf_is_error: bool 28 | If True, raise an error anytime an Inf is encountered. Note that some 29 | pylearn2 modules currently use np.inf as a default value (e.g. 30 | mlp.max_pool) and these will cause an error if inf_is_error is True. 31 | big_is_error: bool 32 | If True, raise an error when a value greater than 1e10 is encountered. 33 | """ 34 | def __init__(self, nan_is_error, inf_is_error, big_is_error=True): 35 | super(NanGuardMode, self).__init__( 36 | self, nan_is_error, inf_is_error, big_is_error=big_is_error 37 | ) 38 | logger.warning("WARNING: NanGuardMode has been moved to theano. It is " 39 | "depreciated in pylearn2. Importing from theano. ") 40 | -------------------------------------------------------------------------------- /pylearn2/devtools/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/devtools/tests/__init__.py -------------------------------------------------------------------------------- /pylearn2/devtools/tests/pep8/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/devtools/tests/pep8/__init__.py -------------------------------------------------------------------------------- /pylearn2/devtools/tests/test_shebangs.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | __author__ = "Ian Goodfellow" 4 | 5 | from pylearn2.devtools.list_files import list_files 6 | 7 | def test_shebangs(): 8 | # Make sure all scripts that use shebangs use /usr/bin/env 9 | # (instead of the non-standard /bin/env or hardcoding the path to 10 | # the interpreter). This test allows any shebang lines that start 11 | # with /usr/bin/env. Examples: 12 | # "#!/usr/bin/env python" 13 | # "#! /usr/bin/env python" 14 | # "#!/usr/bin/env ipython" 15 | # "#!/usr/bin/env ipython --pylab --" 16 | # etc. 17 | files = list_files('.py') 18 | for f in files: 19 | fd = open(f, 'r') 20 | l = fd.readline() 21 | fd.close() 22 | if l.startswith("#!"): 23 | if not l[2:].strip().startswith("/usr/bin/env"): 24 | print(l) 25 | print(f) 26 | raise AssertionError("Bad shebang") 27 | -------------------------------------------------------------------------------- /pylearn2/devtools/tests/test_via_pyflakes.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | from pylearn2.devtools.run_pyflakes import run_pyflakes 4 | __authors__ = "Ian Goodfellow" 5 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 6 | __credits__ = ["Ian Goodfellow"] 7 | __license__ = "3-clause BSD" 8 | __maintainer__ = "LISA Lab" 9 | __email__ = "pylearn-dev@googlegroups" 10 | 11 | def test_via_pyflakes(): 12 | d = run_pyflakes(True) 13 | if len(d.keys()) != 0: 14 | print('Errors detected by pyflakes') 15 | for key in d.keys(): 16 | print(key+':') 17 | for l in d[key].split('\n'): 18 | print('\t',l) 19 | 20 | raise AssertionError("You have errors detected by pyflakes") 21 | -------------------------------------------------------------------------------- /pylearn2/distributions/__init__.py: -------------------------------------------------------------------------------- 1 | __authors__ = "Ian Goodfellow" 2 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 3 | __credits__ = ["Ian Goodfellow"] 4 | __license__ = "3-clause BSD" 5 | __maintainer__ = "LISA Lab" 6 | __email__ = "pylearn-dev@googlegroups" 7 | -------------------------------------------------------------------------------- /pylearn2/distributions/multinomial.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. todo:: 3 | 4 | WRITEME 5 | """ 6 | __authors__ = "Ian Goodfellow" 7 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 8 | __credits__ = ["Ian Goodfellow"] 9 | __license__ = "3-clause BSD" 10 | __maintainer__ = "LISA Lab" 11 | __email__ = "pylearn-dev@googlegroups" 12 | import numpy as N 13 | 14 | 15 | class Multinomial(object): 16 | """ 17 | .. todo:: 18 | 19 | WRITEME 20 | """ 21 | 22 | def __init__(self, rng, pi, renormalize=False): 23 | self.pi = pi 24 | assert self.pi.min() >= 0.0 25 | self.rng = rng 26 | if renormalize: 27 | self.pi = self.pi / self.pi.sum() 28 | else: 29 | assert abs(1.0 - self.pi.sum()) < 1e-10 30 | 31 | def sample_integer(self, m): 32 | """ 33 | .. todo:: 34 | 35 | WRITEME 36 | """ 37 | return N.nonzero( 38 | self.rng.multinomial(pvals=self.pi, n=1, size=(m,)) 39 | )[1] 40 | -------------------------------------------------------------------------------- /pylearn2/energy_functions/__init__.py: -------------------------------------------------------------------------------- 1 | __authors__ = "Ian Goodfellow" 2 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 3 | __credits__ = ["Ian Goodfellow"] 4 | __license__ = "3-clause BSD" 5 | __maintainer__ = "LISA Lab" 6 | __email__ = "pylearn-dev@googlegroups" 7 | -------------------------------------------------------------------------------- /pylearn2/energy_functions/energy_function.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. todo:: 3 | 4 | WRITEME 5 | """ 6 | __authors__ = "Ian Goodfellow" 7 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 8 | __credits__ = ["Ian Goodfellow"] 9 | __license__ = "3-clause BSD" 10 | __maintainer__ = "LISA Lab" 11 | __email__ = "pylearn-dev@googlegroups" 12 | import theano.tensor as T 13 | 14 | 15 | class EnergyFunction(object): 16 | """ 17 | .. todo:: 18 | 19 | WRITEME 20 | """ 21 | 22 | def __init__(self): 23 | pass 24 | 25 | def score(self, X): 26 | """ 27 | .. todo:: 28 | 29 | WRITEME 30 | """ 31 | assert X.dtype.find('int') == -1 32 | 33 | X_name = 'X' if X.name is None else X.name 34 | 35 | E = self.free_energy(X) 36 | 37 | #There should be one energy value for each example in the batch 38 | assert len(E.type.broadcastable) == 1 39 | 40 | dummy = T.sum(E) 41 | rval = T.grad(dummy, X) 42 | rval.name = 'score(' + X_name + ')' 43 | return rval 44 | 45 | def free_energy(self, X): 46 | """ 47 | .. todo:: 48 | 49 | WRITEME 50 | """ 51 | raise NotImplementedError(str(type(self)) + 52 | ' has not implemented free_energy(self,X)') 53 | 54 | def energy(self, varlist): 55 | """ 56 | .. todo:: 57 | 58 | WRITEME 59 | """ 60 | raise NotImplementedError(str(type(self)) + 61 | ' has not implemented energy(self,varlist)') 62 | 63 | def __call__(self, varlist): 64 | """ 65 | .. todo:: 66 | 67 | WRITEME 68 | """ 69 | return self.energy(varlist) 70 | -------------------------------------------------------------------------------- /pylearn2/energy_functions/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/energy_functions/tests/__init__.py -------------------------------------------------------------------------------- /pylearn2/expr/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/expr/__init__.py -------------------------------------------------------------------------------- /pylearn2/expr/activations.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. todo:: 3 | 4 | WRITEME 5 | """ 6 | import theano 7 | T = theano.tensor 8 | 9 | 10 | def identity(x): 11 | """ 12 | .. todo:: 13 | 14 | WRITEME properly 15 | 16 | Importable identity function. Created for the purposes of pickling. 17 | """ 18 | return x 19 | 20 | 21 | def relu(x): 22 | """ 23 | .. todo:: 24 | 25 | WRITEME properly 26 | 27 | Rectified linear activation 28 | """ 29 | return T.max(0, x) 30 | 31 | 32 | def _rescale_softmax(sm, min_val): 33 | """ 34 | .. todo:: 35 | 36 | WRITEME 37 | """ 38 | n_classes = sm.shape[-1] 39 | # Avoid upcast to float64 when floatX==float32 and n_classes is int64 40 | n_classes = n_classes.astype(theano.config.floatX) 41 | return sm * (1 - n_classes * min_val) + min_val 42 | 43 | 44 | def rescaled_softmax(x, min_val=1e-5): 45 | """ 46 | .. todo:: 47 | 48 | WRITEME 49 | """ 50 | return _rescale_softmax(T.nnet.softmax(x), min_val=min_val) 51 | -------------------------------------------------------------------------------- /pylearn2/expr/coding.py: -------------------------------------------------------------------------------- 1 | """ Expressions for encoding features """ 2 | 3 | import theano.tensor as T 4 | 5 | 6 | def triangle_code(X, centroids): 7 | """ 8 | Compute the triangle activation function used in Adam Coates' AISTATS 2011 9 | paper. 10 | 11 | Parameters 12 | ---------- 13 | X : theano matrix 14 | design matrix 15 | centroids : theano matrix 16 | k-means dictionary, one centroid in each row 17 | 18 | Returns 19 | ------- 20 | code : theano matrix 21 | A design matrix of triangle code activations 22 | """ 23 | 24 | X_sqr = T.sqr(X).sum(axis=1).dimshuffle(0,'x') 25 | c_sqr = T.sqr(centroids).sum(axis=1).dimshuffle('x',0) 26 | c_sqr.name = 'c_sqr' 27 | Xc = T.dot(X, centroids.T) 28 | Xc.name = 'Xc' 29 | 30 | sq_dists = c_sqr + X_sqr - 2. * Xc 31 | 32 | # TODO: why do I have to do this and Adam doesn't? 33 | # is it just because he uses float64 and I usually use 34 | # float32? or are our libraries numerically unstable somehow, 35 | # or does matlab handle sqrt differently? 36 | sq_dists_safe = T.clip(sq_dists,0.,1e30) 37 | 38 | Z = T.sqrt( sq_dists_safe) 39 | Z.name = 'Z' 40 | 41 | mu = Z.mean(axis=1) 42 | mu.name = 'mu' 43 | 44 | mu = mu.dimshuffle(0,'x') 45 | mu.name = 'mu_broadcasted' 46 | 47 | rval = T.clip( mu - Z, 0., 1e30) 48 | rval.name = 'triangle_code' 49 | 50 | return rval 51 | 52 | 53 | -------------------------------------------------------------------------------- /pylearn2/expr/image.py: -------------------------------------------------------------------------------- 1 | """ Mathematical expressions related to image processing. """ 2 | 3 | 4 | def color_to_gray(color): 5 | """ 6 | .. todo:: 7 | 8 | WRITEME properly 9 | 10 | Standard conversion from color to luma 11 | 12 | Y' = W_R * red_channel + W_G * green_channel + W_B * blue_channel 13 | 14 | with 15 | W_R = 0.299 16 | W_G = 0.587 17 | W_B = 0.114 18 | 19 | Parameters 20 | ---------- 21 | color : numpy or theano 4-tensor 22 | The channel index must be last 23 | 24 | Returns 25 | ------- 26 | tensor 27 | Has the same number of dimensions, but with the final dimension 28 | changed to 1. 29 | 30 | References 31 | ---------- 32 | http://en.wikipedia.org/wiki/YUV#Conversion_to.2Ffrom_RGB 33 | """ 34 | 35 | W_R = 0.299 36 | W_B = 0.114 37 | W_G = 0.587 38 | 39 | red_channel = color[:,:,:,0:1] 40 | blue_channel = color[:,:,:,2:3] 41 | green_channel = color[:,:,:,1:2] 42 | 43 | Y_prime = W_R * red_channel + W_G * green_channel + W_B * blue_channel 44 | 45 | return Y_prime 46 | 47 | -------------------------------------------------------------------------------- /pylearn2/expr/information_theory.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. todo:: 3 | 4 | WRITEME 5 | """ 6 | import theano.tensor as T 7 | from theano.gof.op import get_debug_values 8 | from theano.gof.op import debug_assert 9 | import numpy as np 10 | from theano.tensor.xlogx import xlogx 11 | from pylearn2.utils import contains_nan, isfinite 12 | 13 | 14 | def entropy_binary_vector(P): 15 | """ 16 | .. todo:: 17 | 18 | WRITEME properly 19 | 20 | If P[i,j] represents the probability of some binary random variable X[i,j] 21 | being 1, then rval[i] gives the entropy of the random vector X[i,:] 22 | """ 23 | 24 | for Pv in get_debug_values(P): 25 | assert Pv.min() >= 0.0 26 | assert Pv.max() <= 1.0 27 | 28 | oneMinusP = 1. - P 29 | 30 | PlogP = xlogx(P) 31 | omPlogOmP = xlogx(oneMinusP) 32 | 33 | term1 = - T.sum(PlogP, axis=1) 34 | assert len(term1.type.broadcastable) == 1 35 | 36 | term2 = - T.sum(omPlogOmP, axis=1) 37 | assert len(term2.type.broadcastable) == 1 38 | 39 | rval = term1 + term2 40 | 41 | debug_vals = get_debug_values(PlogP, omPlogOmP, term1, term2, rval) 42 | for plp, olo, t1, t2, rv in debug_vals: 43 | debug_assert(isfinite(plp)) 44 | debug_assert(isfinite(olo)) 45 | 46 | debug_assert(not contains_nan(t1)) 47 | debug_assert(not contains_nan(t2)) 48 | debug_assert(not contains_nan(rv)) 49 | 50 | return rval 51 | -------------------------------------------------------------------------------- /pylearn2/expr/tests/test_basic.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests for pylearn2.expr.basic 3 | """ 4 | 5 | import numpy as np 6 | 7 | from pylearn2.expr.basic import log_sum_exp 8 | from pylearn2.utils import sharedX 9 | 10 | 11 | def test_log_sum_exp_1(): 12 | """ 13 | Tests that the stable log sum exp matches the naive one for 14 | values near 1. 15 | """ 16 | 17 | rng = np.random.RandomState([2015, 2, 9]) 18 | x = 1. + rng.randn(5) / 10. 19 | naive = np.log(np.exp(x).sum()) 20 | x = sharedX(x) 21 | stable = log_sum_exp(x).eval() 22 | assert np.allclose(naive, stable) 23 | 24 | 25 | def test_log_sum_exp_2(): 26 | """ 27 | Tests that the stable log sum exp succeeds for extreme values." 28 | """ 29 | 30 | x = np.array([-100., 100.]) 31 | x = sharedX(x) 32 | stable = log_sum_exp(x).eval() 33 | assert np.allclose(stable, 100.) 34 | -------------------------------------------------------------------------------- /pylearn2/expr/tests/test_coding.py: -------------------------------------------------------------------------------- 1 | from pylearn2.expr.coding import triangle_code 2 | import numpy as np 3 | import theano.tensor as T 4 | from theano import function 5 | from pylearn2.utils import as_floatX 6 | 7 | def test_triangle_code(): 8 | rng = np.random.RandomState([20,18,9]) 9 | 10 | m = 5 11 | n = 6 12 | k = 7 13 | 14 | X = as_floatX(rng.randn(m,n)) 15 | D = as_floatX(rng.randn(k,n)) 16 | 17 | D_norm_squared = np.sum(D**2,axis=1) 18 | X_norm_squared = np.sum(X**2,axis=1) 19 | sq_distance = -2.0 * np.dot(X,D.T) + D_norm_squared + np.atleast_2d(X_norm_squared).T 20 | distance = np.sqrt(sq_distance) 21 | 22 | mu = np.mean(distance, axis = 1) 23 | expected = np.maximum(0.0,mu.reshape(mu.size,1)-distance) 24 | 25 | Xv = T.matrix() 26 | Dv = T.matrix() 27 | 28 | code = triangle_code(X = Xv, centroids = Dv) 29 | actual = function([Xv,Dv],code)(X,D) 30 | 31 | assert np.allclose(expected, actual) 32 | -------------------------------------------------------------------------------- /pylearn2/expr/tests/test_evaluation.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests of expr.evaluation 3 | """ 4 | 5 | import numpy as np 6 | 7 | from theano.compat.six.moves import xrange 8 | 9 | from pylearn2.expr.evaluation import all_pr 10 | 11 | 12 | def test_all_pr(): 13 | """ 14 | Tests that all_pr matches a hand-obtained solution. 15 | """ 16 | 17 | pos_scores = [-1., 0., 2.] 18 | neg_scores = [-2., 0., 1.] 19 | 20 | # scores: [2., 1., 0., 0., -1., -2.] 21 | # labels: [1, 0, 1, 0, 1, 0 ] 22 | 23 | precision = [1., 1., .5, .5, .6, 3. / 6.] 24 | recall = [0., 1. / 3., 1. / 3., 2. / 3., 1., 1.] 25 | 26 | p, r = all_pr(pos_scores, neg_scores) 27 | assert len(p) == len(precision) 28 | assert len(r) == len(recall) 29 | 30 | # The actual function should do exactly the same arithmetic on 31 | # integers so we should get exactly the same floating point values 32 | for i in xrange(len(p)): 33 | assert p[i] == precision[i], (i, p[i], precision[i]) 34 | assert recall[i] == recall[i] 35 | -------------------------------------------------------------------------------- /pylearn2/expr/tests/test_preprocessing.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | from pylearn2.expr.preprocessing import global_contrast_normalize 3 | 4 | 5 | def test_basic(): 6 | rng = numpy.random.RandomState(0) 7 | X = abs(rng.randn(50, 70)) 8 | Y = global_contrast_normalize(X) 9 | numpy.testing.assert_allclose((Y ** 2).sum(axis=1), 1) 10 | numpy.testing.assert_allclose(Y.mean(axis=1), 0, atol=1e-10) 11 | 12 | 13 | def test_scale(): 14 | rng = numpy.random.RandomState(0) 15 | X = abs(rng.randn(50, 70)) 16 | Y = global_contrast_normalize(X, scale=5) 17 | numpy.testing.assert_allclose(numpy.sqrt((Y ** 2).sum(axis=1)), 5) 18 | numpy.testing.assert_allclose(Y.mean(axis=1), 0, atol=1e-10) 19 | 20 | 21 | def test_subtract_mean_false(): 22 | rng = numpy.random.RandomState(0) 23 | X = abs(rng.randn(50, 70)) 24 | Y = global_contrast_normalize(X, subtract_mean=False, scale=5) 25 | numpy.testing.assert_allclose(numpy.sqrt((Y ** 2).sum(axis=1)), 5) 26 | numpy.testing.assert_raises(AssertionError, 27 | numpy.testing.assert_allclose, 28 | Y.mean(axis=1), 0, atol=1e-10) 29 | 30 | 31 | def test_std_norm(): 32 | rng = numpy.random.RandomState(0) 33 | X = abs(rng.randn(50, 70)) 34 | Y = global_contrast_normalize(X, use_std=True, scale=5) 35 | numpy.testing.assert_allclose(Y.std(axis=1, ddof=1), 5) 36 | 37 | 38 | def test_min_divisor(): 39 | rng = numpy.random.RandomState(0) 40 | X = abs(rng.randn(50, 70)) 41 | X[0] *= 1e-15 42 | Y = global_contrast_normalize(X, subtract_mean=False, use_std=True) 43 | numpy.testing.assert_array_equal(X[0], Y[0]) 44 | -------------------------------------------------------------------------------- /pylearn2/format/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/format/__init__.py -------------------------------------------------------------------------------- /pylearn2/gui/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/gui/__init__.py -------------------------------------------------------------------------------- /pylearn2/linear/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | LinearTransform classes and convenience methods for creating them. 3 | LinearTransform classes are used to linearly transform between vector 4 | spaces. By instantiating different derived classes the same model can 5 | work by dense matrix multiplication, convolution, etc. without needing 6 | to rewrite any of the model's code. 7 | """ 8 | __authors__ = "Ian Goodfellow" 9 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 10 | __credits__ = ["Ian Goodfellow"] 11 | __license__ = "3-clause BSD" 12 | __maintainer__ = "LISA Lab" 13 | __email__ = "pylearn-dev@googlegroups" 14 | -------------------------------------------------------------------------------- /pylearn2/model_extensions/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Extensions (plugins) for Model classes 3 | """ 4 | -------------------------------------------------------------------------------- /pylearn2/model_extensions/model_extension.py: -------------------------------------------------------------------------------- 1 | """ 2 | Base class for model extensions 3 | """ 4 | 5 | 6 | class ModelExtension(object): 7 | """ 8 | An object that may be plugged into a model to add some functionality 9 | to it. 10 | """ 11 | 12 | def post_modify_updates(self, updates, model): 13 | """" 14 | Modifies the parameters before a learning update is applied. 15 | This method acts *after* the model subclass' _modify_updates 16 | method and any ModelExtensions that come earlier in the 17 | extensions list. 18 | 19 | Parameters 20 | ---------- 21 | updates : dict 22 | A dictionary mapping shared variables to symbolic values they 23 | will be updated to. 24 | model : Model 25 | The Model to act on 26 | """ 27 | 28 | pass 29 | -------------------------------------------------------------------------------- /pylearn2/model_extensions/tests/test_model_extension.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests for model_extensions. 3 | """ 4 | 5 | from theano.compat.six.moves import xrange 6 | from pylearn2.models import Model 7 | from pylearn2.model_extensions.model_extension import ModelExtension 8 | 9 | 10 | def test_model_extension(): 11 | """ 12 | Test that the base class Model passes tests when given a list of 13 | ModelExtension instances. 14 | """ 15 | class DummyModelExtension(ModelExtension): 16 | """Simplest instance of ModelExtension""" 17 | class DummyModel(Model): 18 | """Simplest instance of Model""" 19 | 20 | extensions = (DummyModelExtension()) 21 | try: 22 | """ 23 | This should cause an assertion error for passing a tuple instead of 24 | a list 25 | """ 26 | model = DummyModel(extensions=extensions) 27 | except AssertionError: 28 | pass 29 | 30 | extensions = [DummyModelExtension(), None] 31 | try: 32 | """ 33 | This should cause an assertion error for passing a list where each 34 | element is not an instance of ModelExtension 35 | """ 36 | model = DummyModel(extensions=extensions) 37 | except AssertionError: 38 | pass 39 | 40 | extensions = [] 41 | for i in xrange(3): 42 | extensions.append(DummyModelExtension()) 43 | """ 44 | This should not cause an assertion 45 | """ 46 | model = DummyModel(extensions=extensions) 47 | -------------------------------------------------------------------------------- /pylearn2/models/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Machine learning models. 3 | """ 4 | 5 | from pylearn2.models.model import Model 6 | -------------------------------------------------------------------------------- /pylearn2/models/setup.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. todo:: 3 | 4 | WRITEME 5 | """ 6 | from distutils.core import setup 7 | from distutils.extension import Extension 8 | from Cython.Distutils import build_ext 9 | 10 | import numpy as np 11 | 12 | setup(cmdclass={'build_ext': build_ext}, 13 | ext_modules=[Extension("_kmeans", ["_kmeans.pyx"], 14 | include_dirs=[np.get_include()], 15 | extra_compile_args=['-fopenmp'], 16 | extra_link_args=['-fopenmp']) 17 | ]) 18 | -------------------------------------------------------------------------------- /pylearn2/models/sparse_autoencoder.py: -------------------------------------------------------------------------------- 1 | import theano 2 | import theano.sparse 3 | from theano import tensor 4 | from pylearn2.models.autoencoder import DenoisingAutoencoder 5 | from pylearn2.space import VectorSpace 6 | from theano.sparse.sandbox.sp2 import sampling_dot 7 | 8 | from pylearn2.expr.basic import theano_norms 9 | 10 | class SparseDenoisingAutoencoder(DenoisingAutoencoder): 11 | """ 12 | Denoising autoencoder working with only sparse inputs and efficient 13 | reconstruction sampling 14 | 15 | Parameters 16 | ---------- 17 | corruptor : WRITEME 18 | nvis : WRITEME 19 | nhid : WRITEME 20 | act_enc : WRITEME 21 | act_dec : WRITEME 22 | tied_weights : WRITEME 23 | irange : WRITEME 24 | rng : WRITEME 25 | 26 | References 27 | ---------- 28 | Y. Dauphin, X. Glorot, Y. Bengio. Large-Scale Learning of Embeddings with 29 | Reconstruction Sampling. In Proceedings of the 28th International 30 | Conference on Machine Learning (ICML 2011). 31 | """ 32 | 33 | def __init__(self): 34 | raise NotImplementedError( 35 | 'This class has been deprecated since 2012.'\ 36 | 'In Feb, 2015, all historical codes are hence removed.') 37 | 38 | -------------------------------------------------------------------------------- /pylearn2/models/tests/config/cae.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.train.Train { 2 | dataset: &train !obj:pylearn2.testing.datasets.random_one_hot_dense_design_matrix { 3 | rng: !obj:numpy.random.RandomState { seed: [2013, 3, 16] }, 4 | num_examples: 10, 5 | dim: 5, 6 | num_classes: 5 7 | }, 8 | model: !obj:pylearn2.models.autoencoder.ContractiveAutoencoder { 9 | nvis: 5, 10 | nhid: 5, 11 | irange: 0.05, 12 | act_enc: "sigmoid", 13 | act_dec: "sigmoid" 14 | }, 15 | algorithm: !obj:pylearn2.training_algorithms.sgd.SGD { 16 | batch_size: 10, 17 | learning_rate: .1, 18 | monitoring_dataset: 19 | { 20 | 'train' : *train 21 | }, 22 | cost: !obj:pylearn2.costs.cost.SumOfCosts { 23 | costs: [ 24 | !obj:pylearn2.costs.autoencoder.MeanBinaryCrossEntropy {}, 25 | [0.1, !obj:pylearn2.costs.cost.MethodCost { method: contraction_penalty }] 26 | ] 27 | }, 28 | termination_criterion: !obj:pylearn2.termination_criteria.EpochCounter { 29 | max_epochs: 1, 30 | }, 31 | }, 32 | } 33 | -------------------------------------------------------------------------------- /pylearn2/models/tests/config/hcae.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.train.Train { 2 | dataset: &train !obj:pylearn2.testing.datasets.random_one_hot_dense_design_matrix { 3 | rng: !obj:numpy.random.RandomState { seed: [2013, 3, 16] }, 4 | num_examples: 10, 5 | dim: 5, 6 | num_classes: 5 7 | }, 8 | model: !obj:pylearn2.models.autoencoder.HigherOrderContractiveAutoencoder { 9 | nvis: 5, 10 | nhid: 5, 11 | irange: 0.05, 12 | act_enc: "sigmoid", 13 | act_dec: "sigmoid", 14 | num_corruptions: 2, 15 | corruptor: !obj:pylearn2.corruption.BinomialCorruptor { 16 | corruption_level: 0.5 17 | } 18 | }, 19 | algorithm: !obj:pylearn2.training_algorithms.sgd.SGD { 20 | batch_size: 10, 21 | learning_rate: .1, 22 | monitoring_dataset: 23 | { 24 | 'train' : *train 25 | }, 26 | cost: !obj:pylearn2.costs.cost.SumOfCosts { 27 | costs: [ 28 | !obj:pylearn2.costs.autoencoder.MeanBinaryCrossEntropy {}, 29 | [0.1, !obj:pylearn2.costs.cost.MethodCost { method: higher_order_penalty }] 30 | ] 31 | }, 32 | termination_criterion: !obj:pylearn2.termination_criteria.EpochCounter { 33 | max_epochs: 1, 34 | }, 35 | }, 36 | } 37 | -------------------------------------------------------------------------------- /pylearn2/models/tests/dbm.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/models/tests/dbm.mat -------------------------------------------------------------------------------- /pylearn2/models/tests/dbm_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/models/tests/dbm_data.mat -------------------------------------------------------------------------------- /pylearn2/models/tests/lwta.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.train.Train { 2 | dataset: !obj:pylearn2.datasets.dense_design_matrix.DenseDesignMatrix &dataset { 3 | "X" : !obj:numpy.random.normal { 'size':[5,6] }, 4 | "y" : !obj:numpy.random.normal { 'size':[5,6] }, 5 | }, 6 | model: !obj:pylearn2.models.mlp.MLP { 7 | nvis: 6, 8 | layers: [ 9 | !obj:pylearn2.models.lwta.LWTA { 10 | block_size: 2, 11 | layer_name: 'h0', 12 | dim: 4, 13 | irange : 0.05, 14 | }, !obj:pylearn2.models.mlp.Linear { 15 | layer_name: 'y', 16 | dim: 6, 17 | irange : 0.05, 18 | } 19 | ], 20 | }, 21 | algorithm: !obj:pylearn2.training_algorithms.sgd.SGD { 22 | "learning_rate" : 1e-3, 23 | "batch_size" : 5, 24 | "monitoring_dataset" : *dataset, 25 | "termination_criterion" : !obj:pylearn2.termination_criteria.EpochCounter { 26 | "max_epochs": 1, 27 | }, 28 | }, 29 | } 30 | -------------------------------------------------------------------------------- /pylearn2/models/tests/test_convelemwise_rect.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test for rectifier convolutional layer. 3 | """ 4 | 5 | import os 6 | 7 | from theano import config 8 | from theano.sandbox import cuda 9 | 10 | from pylearn2.config import yaml_parse 11 | import pylearn2 12 | 13 | 14 | def test_conv_rectifier_basic(): 15 | """ 16 | Tests that we can load a convolutional rectifier model 17 | and train it for a few epochs (without saving) on a dummy 18 | dataset-- tiny model and dataset. 19 | 20 | """ 21 | yaml_file = os.path.join(pylearn2.__path__[0], 22 | "models/tests/conv_elemwise_rect.yaml") 23 | with open(yaml_file) as yamlh: 24 | yaml_lines = yamlh.readlines() 25 | yaml_str = "".join(yaml_lines) 26 | 27 | train = yaml_parse.load(yaml_str) 28 | train.main_loop() 29 | 30 | if __name__ == "__main__": 31 | test_conv_rectifier_basic() 32 | -------------------------------------------------------------------------------- /pylearn2/models/tests/test_convelemwise_tanh.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test for Tanh convolutional layer. 3 | """ 4 | 5 | import os 6 | 7 | from theano import config 8 | from theano.sandbox import cuda 9 | 10 | from pylearn2.config import yaml_parse 11 | import pylearn2 12 | 13 | 14 | def test_conv_tanh_basic(): 15 | """ 16 | Tests that we can load a convolutional tanh model 17 | and train it for a few epochs (without saving) on a dummy 18 | dataset-- tiny model and dataset 19 | """ 20 | yaml_file = os.path.join(pylearn2.__path__[0], 21 | "models/tests/conv_elemwise_tanh.yaml") 22 | 23 | with open(yaml_file) as yamlh: 24 | yaml_lines = yamlh.readlines() 25 | yaml_str = "".join(yaml_lines) 26 | 27 | train = yaml_parse.load(yaml_str) 28 | train.main_loop() 29 | 30 | if __name__ == "__main__": 31 | test_conv_tanh_basic() 32 | -------------------------------------------------------------------------------- /pylearn2/models/tests/test_dropout.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests of the dropout functionality. 3 | """ 4 | __authors__ = "Ian Goodfellow" 5 | __copyright__ = "Copyright 2013, Universite de Montreal" 6 | __credits__ = ["Ian Goodfellow"] 7 | __license__ = "3-clause BSD" 8 | __maintainer__ = "LISA Lab" 9 | 10 | import warnings 11 | 12 | warnings.warn(""" 13 | TODO: add test that dropout_fprop with all include probabilities and scales set 14 | to 1 is equivalent to fprop. 15 | TODO: add a test file to the corresponding cost module and make sure that the 16 | dropout cost with everything set to 1 is equivalent to the Default cost 17 | """) 18 | -------------------------------------------------------------------------------- /pylearn2/models/tests/test_gsn.py: -------------------------------------------------------------------------------- 1 | """ 2 | No tests for now, but there is an example of use in 3 | pylearn2/scripts/gsn_example.py 4 | """ 5 | -------------------------------------------------------------------------------- /pylearn2/models/tests/test_kmeans.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests of ../kmeans.py 3 | """ 4 | 5 | import numpy as np 6 | 7 | from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix 8 | from pylearn2.models.kmeans import KMeans 9 | from pylearn2.train import Train 10 | 11 | 12 | def test_kmeans(): 13 | """ 14 | Tests kmeans.Kmeans by using it as a model in a Train object. 15 | """ 16 | 17 | X = np.random.random(size=(100, 10)) 18 | Y = np.random.randint(5, size=(100, 1)) 19 | 20 | dataset = DenseDesignMatrix(X, y=Y) 21 | 22 | model = KMeans( 23 | k=5, 24 | nvis=10 25 | ) 26 | 27 | train = Train(model=model, dataset=dataset) 28 | train.main_loop() 29 | -------------------------------------------------------------------------------- /pylearn2/models/tests/test_lwta.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests of the LWTA functionality. 3 | """ 4 | __author__ = "Ian Goodfellow, Minh Ngoc Le" 5 | 6 | import os 7 | import numpy as np 8 | import pylearn2 9 | from pylearn2.utils import sharedX 10 | from pylearn2.models.lwta import lwta 11 | from pylearn2.scripts.tests.yaml_testing import limited_epoch_train 12 | 13 | 14 | def test_lwta_simple(): 15 | 16 | """Test simple cases.""" 17 | 18 | example_input = np.zeros((2, 6)) 19 | 20 | # begin block 21 | example_input[0, 0] = -2.5 22 | example_input[0, 1] = 1.3 # max 23 | example_input[0, 2] = 0.9 24 | # begin block 25 | example_input[0, 3] = -0.1 # tied for max 26 | example_input[0, 4] = -0.2 27 | example_input[0, 5] = -0.1 # tied for max 28 | # begin block 29 | example_input[1, 0] = 5.0 # max 30 | example_input[1, 1] = 4.0 31 | example_input[1, 2] = 3.0 32 | # begin block 33 | example_input[1, 3] = 0.0 34 | example_input[1, 4] = 1.0 35 | example_input[1, 5] = 2.0 # max 36 | 37 | output = lwta(sharedX(example_input), block_size=3).eval() 38 | 39 | num_zeros = (output == 0).sum() 40 | assert num_zeros == 8 41 | 42 | assert np.allclose(output[0, 1], 1.3), output[0, 1] 43 | assert np.allclose(output[0, 3], -0.1) or np.allclose(output[0, 5], -0.1) 44 | assert np.allclose(output[1, 0], 5.0) 45 | assert np.allclose(output[1, 5], 2.0) 46 | 47 | 48 | def test_lwta_yaml(): 49 | """Test simple model on random data.""" 50 | limited_epoch_train(os.path.join(pylearn2.__path__[0], 51 | "models/tests/lwta.yaml")) 52 | -------------------------------------------------------------------------------- /pylearn2/models/tests/test_model.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests for functionality from model.py 3 | """ 4 | 5 | import numpy as np 6 | 7 | from pylearn2.models import Model 8 | from pylearn2.utils import sharedX 9 | 10 | 11 | def test_get_set_vector(): 12 | """ 13 | Tests that get_vector and set_vector use the same 14 | format. 15 | """ 16 | 17 | rng = np.random.RandomState([2014, 5, 8]) 18 | 19 | class DummyModel(Model): 20 | """ 21 | A Model that exercises this test by having a few different 22 | parameters with different shapes and dimensionalities. 23 | 24 | Don't instantiate more than one of these because the parameters 25 | are class-level attributes. 26 | """ 27 | 28 | _params = [sharedX(rng.randn(5)), sharedX(rng.randn(5, 3)), 29 | sharedX(rng.randn(4, 4, 4))] 30 | 31 | model = DummyModel() 32 | 33 | vector = model.get_param_vector() 34 | model.set_param_vector(0. * vector) 35 | assert np.allclose(0. * vector, model.get_param_vector()) 36 | model.set_param_vector(vector) 37 | assert np.allclose(model.get_param_vector(), vector) 38 | 39 | 40 | def test_tag(): 41 | """Test that the tag attribute works correctly.""" 42 | class DummyModel(Model): 43 | """The simplest instance of Model possible.""" 44 | x = DummyModel() 45 | x.tag['foo']['bar'] = 5 46 | 47 | assert len(x.tag.keys()) == 1 48 | assert len(x.tag['foo'].keys()) == 1 49 | assert x.tag['foo']['bar'] == 5 50 | 51 | assert 'bar' not in x.tag 52 | x.tag['bar']['baz'] = 3 53 | assert 'bar' in x.tag 54 | assert 'baz' in x.tag['bar'] 55 | assert len(x.tag.keys()) == 2 56 | -------------------------------------------------------------------------------- /pylearn2/models/tests/test_rbm.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | import theano.sandbox.rng_mrg 4 | RandomStreams = theano.sandbox.rng_mrg.MRG_RandomStreams 5 | from theano import tensor as T 6 | 7 | from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix 8 | from pylearn2.models.rbm import RBM 9 | from pylearn2.training_algorithms.default import DefaultTrainingAlgorithm 10 | from pylearn2.utils.rng import make_theano_rng 11 | 12 | 13 | def test_get_weights(): 14 | # Tests that the RBM, when constructed 15 | # with nvis and nhid arguments, supports the 16 | # weights interface 17 | 18 | model = RBM(nvis=2, nhid=3) 19 | W = model.get_weights() 20 | 21 | 22 | def test_get_input_space(): 23 | # Tests that the RBM supports 24 | # the Space interface 25 | 26 | model = RBM(nvis=2, nhid=3) 27 | space = model.get_input_space() 28 | 29 | 30 | def test_gibbs_step_for_v(): 31 | # Just tests that gibbs_step_for_v can be called 32 | # without crashing 33 | 34 | model = RBM(nvis=2, nhid=3) 35 | 36 | theano_rng = make_theano_rng(17, which_method='binomial') 37 | 38 | X = T.matrix() 39 | 40 | Y = model.gibbs_step_for_v(X, theano_rng) 41 | 42 | 43 | def test_train_batch(): 44 | # Just tests that train_batch can be called without crashing 45 | 46 | m = 1 47 | dim = 2 48 | rng = np.random.RandomState([2014, 3, 17]) 49 | X = rng.randn(m, dim) 50 | train = DenseDesignMatrix(X=X) 51 | 52 | rbm = RBM(nvis=dim, nhid=3) 53 | trainer = DefaultTrainingAlgorithm(batch_size=1, batches_per_iter=10) 54 | trainer.setup(rbm, train) 55 | trainer.train(train) 56 | -------------------------------------------------------------------------------- /pylearn2/models/tests/test_reflection_clip.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from pylearn2.models.s3c import reflection_clip 3 | from theano.compat.six.moves import xrange 4 | from theano import function 5 | from theano import shared 6 | from pylearn2.utils.rng import make_np_rng 7 | 8 | def test_reflection_clip(): 9 | N = 5 10 | m = 10 11 | 12 | rng = make_np_rng([1,2,3], which_method='randn') 13 | 14 | Mu1_old = rng.randn(m,N) 15 | Mu1_new = rng.randn(m,N) 16 | 17 | rho = .6 18 | 19 | Mu1_clipped = function([],reflection_clip( \ 20 | shared(Mu1_old), shared(Mu1_new), rho))() 21 | 22 | case1 = False 23 | case2 = False 24 | case3 = False 25 | case4 = False 26 | 27 | for i in xrange(m): 28 | for j in xrange(N): 29 | old = Mu1_old[i,j] 30 | new = Mu1_new[i,j] 31 | clipped = Mu1_clipped[i,j] 32 | 33 | if old > 0.: 34 | if new < - rho * old: 35 | case1 = True 36 | assert abs(clipped-(-rho*old)) < 1e-6 37 | else: 38 | case2 = True 39 | assert new == clipped 40 | elif old < 0.: 41 | if new > - rho * old: 42 | case3 = True 43 | assert abs(clipped-(-rho*old)) < 1e-6 44 | else: 45 | case4 = True 46 | assert new == clipped 47 | else: 48 | assert new == clipped 49 | 50 | #if any of the following fail, it doesn't necessarily mean 51 | #that reflection_clip is broken, just that the test needs 52 | #to be adjusted to have better coverage 53 | assert case1 54 | assert case2 55 | assert case3 56 | assert case4 57 | -------------------------------------------------------------------------------- /pylearn2/models/tests/test_svm.py: -------------------------------------------------------------------------------- 1 | """Tests for DenseMulticlassSVM""" 2 | from __future__ import print_function 3 | 4 | from pylearn2.datasets.mnist import MNIST 5 | from pylearn2.testing.skip import skip_if_no_sklearn, skip_if_no_data 6 | import numpy as np 7 | from theano.compat.six.moves import xrange 8 | import unittest 9 | DenseMulticlassSVM = None 10 | 11 | 12 | class TestSVM(unittest.TestCase): 13 | """ 14 | Test class for DenseMulticlassSVM 15 | 16 | Parameters 17 | ---------- 18 | Inherited from unittest.TestCase 19 | """ 20 | def setUp(self): 21 | """ 22 | Set up test for DenseMulticlassSVM. 23 | 24 | Imports DenseMulticlassSVM if available, skips the test otherwise. 25 | """ 26 | global DenseMulticlassSVM 27 | skip_if_no_sklearn() 28 | skip_if_no_data() 29 | import pylearn2.models.svm 30 | DenseMulticlassSVM = pylearn2.models.svm.DenseMulticlassSVM 31 | 32 | def test_decision_function(self): 33 | """ 34 | Test DenseMulticlassSVM.decision_function. 35 | """ 36 | dataset = MNIST(which_set='train') 37 | 38 | X = dataset.X[0:20, :] 39 | y = dataset.y[0:20] 40 | 41 | for i in xrange(10): 42 | assert (y == i).sum() > 0 43 | 44 | model = DenseMulticlassSVM(kernel='poly', C=1.0).fit(X, y) 45 | 46 | f = model.decision_function(X) 47 | 48 | print(f) 49 | 50 | yhat_f = np.argmax(f, axis=1) 51 | 52 | yhat = np.cast[yhat_f.dtype](model.predict(X)) 53 | 54 | print(yhat_f) 55 | print(yhat) 56 | 57 | assert (yhat_f != yhat).sum() == 0 58 | -------------------------------------------------------------------------------- /pylearn2/optimization/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/optimization/__init__.py -------------------------------------------------------------------------------- /pylearn2/optimization/test_linear_cg.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import theano 4 | from theano import tensor, config 5 | import numpy 6 | from pylearn2.optimization import linear_cg 7 | import warnings 8 | from pylearn2.testing.skip import skip_if_no_scipy 9 | try: 10 | import scipy.linalg 11 | except ImportError: 12 | warnings.warn("Could not import scipy.linalg") 13 | import time 14 | 15 | def test_linear_cg(): 16 | rng = numpy.random.RandomState([1,2,3]) 17 | n = 5 18 | M = rng.randn(2*n,n) 19 | M = numpy.dot(M.T,M).astype(config.floatX) 20 | b = rng.randn(n).astype(config.floatX) 21 | c = rng.randn(1).astype(config.floatX)[0] 22 | x = theano.tensor.vector('x') 23 | f = 0.5 * tensor.dot(x,tensor.dot(M,x)) - tensor.dot(b,x) + c 24 | sol = linear_cg.linear_cg(f,[x]) 25 | 26 | fn_sol = theano.function([x], sol) 27 | 28 | start = time.time() 29 | sol = fn_sol( rng.randn(n).astype(config.floatX))[0] 30 | my_lcg = time.time() -start 31 | 32 | eval_f = theano.function([x],f) 33 | cgf = eval_f(sol) 34 | print("conjugate gradient's value of f:", str(cgf), 'time (s)', my_lcg) 35 | skip_if_no_scipy() 36 | spf = eval_f( scipy.linalg.solve(M,b) ) 37 | print("scipy.linalg.solve's value of f: "+str(spf)) 38 | 39 | abs_diff = abs(cgf - spf) 40 | if not (abs_diff < 1e-5): 41 | raise AssertionError("Expected abs_diff < 1e-5, got abs_diff of " + 42 | str(abs_diff)) 43 | 44 | 45 | if __name__ == '__main__': 46 | test_linear_cg() 47 | -------------------------------------------------------------------------------- /pylearn2/packaged_dependencies/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/packaged_dependencies/__init__.py -------------------------------------------------------------------------------- /pylearn2/packaged_dependencies/theano_linear/README: -------------------------------------------------------------------------------- 1 | This package has diverged from James Bergstra's original repo. 2 | 3 | Some of it has been updated for Windows support, but this refers to parts 4 | of pylearn2 outside of TheanoLinear so can't be pushed back to the original 5 | repo. 6 | 7 | matrixmul.py has been removed because it adds more ops than just matrix 8 | multiplication into the graph. It was trying to implicitly do Space conversion. 9 | pylearn2.linear has a replacement, but this can't really be pushed back to 10 | the TheanoLinear repo because TheanoLinear doesn't have Spaces. 11 | 12 | See unshared_conv/README for notes about modifications to that functionality. 13 | 14 | -------------------------------------------------------------------------------- /pylearn2/packaged_dependencies/theano_linear/__init__.py: -------------------------------------------------------------------------------- 1 | from .linear import ( 2 | dot, 3 | dot_shape, 4 | LinearTransform, 5 | TransposeTransform, 6 | #Concat, ## unready 7 | #Sum, ## unready 8 | ) 9 | from .conv2d import Conv2d 10 | -------------------------------------------------------------------------------- /pylearn2/packaged_dependencies/theano_linear/linearmixin.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. todo:: 3 | 4 | WRITEME 5 | """ 6 | class LinearMixin(object): 7 | """ 8 | This class can be mixed in to an Op that is linear in its first input. 9 | 10 | Supposing this Op takes two inputs: x, y. It can be written as a 11 | linear operation in x: z = x W(y) 12 | """ 13 | 14 | def transpose(zlike, *inputs_1_to_n): 15 | """ 16 | This function returns (zlike) transpose(W(y)) 17 | 18 | Parameters 19 | ---------- 20 | zlike : WRITEME 21 | *inputs_1_to_n : WRITEME 22 | 23 | Returns 24 | ------- 25 | WRITEME 26 | """ 27 | raise NotImplementedError('override-me') 28 | 29 | def grads_1_to_n(inputs, gzlist): 30 | """ 31 | .. todo:: 32 | 33 | WRITEME 34 | """ 35 | raise NotImplementedError('override-me') 36 | 37 | def grad(self, inputs, gzlist): 38 | """ 39 | .. todo:: 40 | 41 | WRITEME 42 | """ 43 | if len(gzlist) > 1: 44 | raise NotImplementedError() 45 | g_input0 = self.transpose(gzlist[0], *inputs[1:]) 46 | return [g_input0] + self.grads_1_to_n(inputs, gzlist) 47 | 48 | 49 | -------------------------------------------------------------------------------- /pylearn2/packaged_dependencies/theano_linear/unshared_conv/README: -------------------------------------------------------------------------------- 1 | Note from IG: James (and/or his collaborator?) have modified the .cu files 2 | here from Alex's original code, it's not just a wrapper. James doesn't remember 3 | what they changed, and his commit messages just say things like "mega-commit". 4 | 5 | I've made some bug fixes here and haven't bothered to push them back to 6 | TheanoLinear, so when handling updates from TheanoLinear, merge them carefully. 7 | This includes: 8 | 1) Removed "border_mode" argument which had no effect 9 | 2) Fixed some unit tests that weren't passing enough arguments 10 | -------------------------------------------------------------------------------- /pylearn2/packaged_dependencies/theano_linear/unshared_conv/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/packaged_dependencies/theano_linear/unshared_conv/__init__.py -------------------------------------------------------------------------------- /pylearn2/packaged_dependencies/theano_linear/util.py: -------------------------------------------------------------------------------- 1 | 2 | from imaging import tile_slices_to_image 3 | 4 | _ndarray_status_fmt='%(msg)s shape=%(shape)s min=%(min)f max=%(max)f' 5 | 6 | 7 | def ndarray_status(x, fmt=_ndarray_status_fmt, msg="", **kwargs): 8 | kwargs.update(dict( 9 | msg=msg, 10 | min=x.min(), 11 | max=x.max(), 12 | mean=x.mean(), 13 | var = x.var(), 14 | shape=x.shape)) 15 | return fmt%kwargs 16 | 17 | -------------------------------------------------------------------------------- /pylearn2/sandbox/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | A module for comparatively experimental or in-development code. 3 | """ 4 | __authors__ = "Ian Goodfellow" 5 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 6 | __credits__ = ["Ian Goodfellow"] 7 | __license__ = "3-clause BSD" 8 | __maintainer__ = "LISA Lab" 9 | __email__ = "pylearn-dev@googlegroups" 10 | -------------------------------------------------------------------------------- /pylearn2/sandbox/cuda_convnet/cutil_inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is copied from the CUDA SDK, version 4.2 for Linux 3 | * Copyright 1993-2012 NVIDIA Corporation. All rights reserved. 4 | * 5 | * Please refer to the NVIDIA end user license agreement (EULA) associated 6 | * with this source code for terms and conditions that govern your use of 7 | * this software. Any use, reproduction, disclosure, or distribution of 8 | * this software and related documentation outside the terms of the EULA 9 | * is strictly prohibited. 10 | * 11 | */ 12 | 13 | #ifndef _CUTIL_INLINE_H_ 14 | #define _CUTIL_INLINE_H_ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | inline void print_NVCC_min_spec(const char *sSDKsample, const char *sNVCCReq, const char *sDriverReq) 25 | { 26 | printf("CUDA %d.%02d Toolkit built this project.\n", CUDART_VERSION/1000, (CUDART_VERSION%100)); 27 | printf(" [ %s ] requirements:\n", sSDKsample); 28 | printf(" -> CUDA %s Toolkit\n" , sNVCCReq); 29 | printf(" -> %s NVIDIA Display Driver.\n", sDriverReq); 30 | } 31 | 32 | #define ALIGN_OFFSET(offset, alignment) offset = (offset + (alignment-1)) & ~((alignment-1)) 33 | 34 | 35 | #endif // _CUTIL_INLINE_H_ 36 | -------------------------------------------------------------------------------- /pylearn2/sandbox/cuda_convnet/cutil_inline_bankchecker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1993-2012 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | #ifndef _CUTIL_INLINE_BANKCHECKER_H_ 13 | #define _CUTIL_INLINE_BANKCHECKER_H_ 14 | 15 | #define cutilBankChecker(array, idx) array[idx] 16 | 17 | // Interface for bank conflict checker 18 | inline void __cutilBankChecker(unsigned int tidx, unsigned int tidy, unsigned int tidz, 19 | unsigned int bdimx, unsigned int bdimy, unsigned int bdimz, 20 | char *aname, int index, char *file, int line) 21 | { 22 | cutCheckBankAccess( tidx, tidy, tidz, bdimx, bdimy, bdimz, file, line, aname, index); 23 | } 24 | 25 | #endif // _CUTIL_INLINE_BANKCHECKER_H_ 26 | -------------------------------------------------------------------------------- /pylearn2/sandbox/cuda_convnet/pthreads.py: -------------------------------------------------------------------------------- 1 | from theano.configparser import AddConfigVar, StrParam 2 | 3 | AddConfigVar('pthreads.inc_dir', 4 | "location of pthread.h", 5 | StrParam("")) 6 | 7 | AddConfigVar('pthreads.lib_dir', 8 | "location of library implementing pthreads", 9 | StrParam("")) 10 | 11 | AddConfigVar('pthreads.lib', 12 | 'name of the library that implements pthreads (e.g. "pthreadVC2" if using pthreadVC2.dll/.lib from pthreads-win32)', 13 | StrParam("")) 14 | 15 | -------------------------------------------------------------------------------- /pylearn2/sandbox/cuda_convnet/shared_code.py: -------------------------------------------------------------------------------- 1 | """ 2 | Convenience methods for accessing C code shared by the code 3 | generators in different parts of this module. 4 | """ 5 | 6 | __authors__ = "Ian Goodfellow" 7 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 8 | __credits__ = ["Ian Goodfellow"] 9 | __license__ = "3-clause BSD" 10 | __maintainer__ = "LISA Lab" 11 | __email__ = "pylearn-dev@googlegroups" 12 | 13 | import pylearn2 14 | pylearn2_path, = pylearn2.__path__ 15 | this_dir = pylearn2_path + "/sandbox/cuda_convnet/" 16 | 17 | def load_code(local_path): 18 | 19 | path = this_dir + local_path 20 | f = open(path) 21 | return f.read() 22 | 23 | def get_NVMatrix_code(): 24 | header = '#include "nvmatrix.cuh"' 25 | source1 = load_code("nvmatrix.cu") 26 | source2 = load_code("nvmatrix_kernels.cu") 27 | 28 | source = source1 + source2 29 | 30 | rval = header + source 31 | 32 | return rval 33 | 34 | -------------------------------------------------------------------------------- /pylearn2/sandbox/lisa_rl/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module contains code used for the LISA lab's reinforcement learning 3 | reading group. Currently it is *very* sandbox-y... none of us has a real 4 | reinforcement learning background, and this isn't our main research work, 5 | just hacking around to learn. 6 | """ 7 | 8 | -------------------------------------------------------------------------------- /pylearn2/sandbox/lisa_rl/bandit/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = "Ian Goodfellow" 2 | 3 | """ 4 | Bandit functionality. 5 | """ 6 | -------------------------------------------------------------------------------- /pylearn2/sandbox/lisa_rl/bandit/agent.py: -------------------------------------------------------------------------------- 1 | __author__ = "Ian Goodfellow" 2 | 3 | class Agent(object): 4 | pass 5 | -------------------------------------------------------------------------------- /pylearn2/sandbox/lisa_rl/bandit/environment.py: -------------------------------------------------------------------------------- 1 | __author__ = "Ian Goodfellow" 2 | 3 | class Environment(object): 4 | pass 5 | -------------------------------------------------------------------------------- /pylearn2/sandbox/lisa_rl/bandit/experiments/basic_bandit_001.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.sandbox.lisa_rl.bandit.simulator.Simulator { 2 | environment: !obj:pylearn2.sandbox.lisa_rl.bandit.gaussian_bandit.GaussianBandit { 3 | num_arms: &num_arms 10, 4 | }, 5 | agent: !obj:pylearn2.sandbox.lisa_rl.bandit.average_agent.AverageAgent { 6 | # Optimistic initialization to encourage exploration 7 | init_reward_estimate: 5., 8 | num_arms: *num_arms 9 | }, 10 | algorithm: !obj:pylearn2.sandbox.lisa_rl.bandit.algorithm.Algorithm {}, 11 | save_path: "experiments/basic_bandit_001.pkl" 12 | } 13 | -------------------------------------------------------------------------------- /pylearn2/sandbox/lisa_rl/bandit/experiments/basic_bandit_002.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.sandbox.lisa_rl.bandit.simulator.Simulator { 2 | environment: !obj:pylearn2.sandbox.lisa_rl.bandit.gaussian_bandit.GaussianBandit { 3 | num_arms: &num_arms 10, 4 | std_std: .01 5 | }, 6 | agent: !obj:pylearn2.sandbox.lisa_rl.bandit.average_agent.AverageAgent { 7 | # Optimistic initialization to encourage exploration 8 | init_reward_estimate: 5., 9 | num_arms: *num_arms 10 | }, 11 | algorithm: !obj:pylearn2.sandbox.lisa_rl.bandit.algorithm.Algorithm {}, 12 | save_path: "experiments/basic_bandit_002.pkl" 13 | } 14 | -------------------------------------------------------------------------------- /pylearn2/sandbox/lisa_rl/bandit/gaussian_bandit.py: -------------------------------------------------------------------------------- 1 | __author__ = "Ian Goodfellow" 2 | 3 | import numpy as np 4 | 5 | from theano import config 6 | from theano import function 7 | from theano import tensor as T 8 | 9 | from pylearn2.sandbox.lisa_rl.bandit.environment import Environment 10 | from pylearn2.utils import sharedX 11 | from pylearn2.utils.rng import make_np_rng, make_theano_rng 12 | 13 | 14 | class GaussianBandit(Environment): 15 | """ 16 | An n-armed bandit whose rewards are drawn from a different Gaussian 17 | distribution for each arm. 18 | The mean and standard deviation of the reward for each arm is drawn 19 | at initialization time from N(0, ). 20 | (For the standard deviation we use the absolute value of the Gaussian 21 | sample) 22 | 23 | .. todo:: 24 | 25 | WRITEME : parameter list 26 | """ 27 | 28 | def __init__(self, num_arms, mean_std = 1.0, std_std = 1.0): 29 | self.rng = make_np_rng(None, [2013, 11, 12], which_method="randn") 30 | self.means = sharedX(self.rng.randn(num_arms) * mean_std) 31 | self.stds = sharedX(np.abs(self.rng.randn(num_arms) * std_std)) 32 | self.theano_rng = make_theano_rng(None, self.rng.randint(2 ** 16), which_method="normal") 33 | 34 | def get_action_func(self): 35 | """ 36 | Returns a theano function that takes an action and returns a reward. 37 | """ 38 | 39 | action = T.iscalar() 40 | reward_mean = self.means[action] 41 | reward_std = self.stds[action] 42 | reward = self.theano_rng.normal(avg=reward_mean, std=reward_std, 43 | dtype=config.floatX, size=reward_mean.shape) 44 | rval = function([action], reward) 45 | return rval 46 | -------------------------------------------------------------------------------- /pylearn2/sandbox/lisa_rl/bandit/plot_reward.py: -------------------------------------------------------------------------------- 1 | __author__ = "Ian Goodfellow" 2 | 3 | from matplotlib import pyplot 4 | import sys 5 | from theano.compat.six.moves import xrange 6 | pyplot.hold(True) 7 | 8 | from pylearn2.utils import serial 9 | 10 | model_paths = sys.argv[1:] 11 | 12 | smoothing = 1 13 | try: 14 | smoothing = int(model_paths[0]) 15 | model_paths = model_paths[1:] 16 | except Exception: 17 | pass 18 | 19 | count = 0 20 | style = '-' 21 | for model_path in model_paths: 22 | model = serial.load(model_path) 23 | smoothed_reward_record = [] 24 | count += 1 25 | if count > 7: 26 | style = '+' 27 | for i in xrange(smoothing - 1, len(model.reward_record)): 28 | smoothed_reward_record.append(sum(model.reward_record[i - smoothing + 1:i + 1]) / float(smoothing)) 29 | pyplot.plot(smoothed_reward_record, style, label=model_path) 30 | pyplot.legend() 31 | pyplot.show() 32 | 33 | 34 | -------------------------------------------------------------------------------- /pylearn2/sandbox/lisa_rl/bandit/simulate.py: -------------------------------------------------------------------------------- 1 | __author__ = "Ian Goodfellow" 2 | 3 | from pylearn2.config import yaml_parse 4 | import sys 5 | 6 | _, path = sys.argv 7 | 8 | simulator = yaml_parse.load_path(path) 9 | 10 | simulator.main_loop() 11 | -------------------------------------------------------------------------------- /pylearn2/sandbox/lisa_rl/bandit/simulator.py: -------------------------------------------------------------------------------- 1 | __author__ = "Ian Goodfellow" 2 | 3 | import logging 4 | import numpy as np 5 | 6 | from pylearn2.utils import serial 7 | from pylearn2.utils import contains_nan, contains_inf 8 | 9 | 10 | logger = logging.getLogger(__name__) 11 | 12 | 13 | class Simulator(object): 14 | """ 15 | .. todo:: 16 | 17 | WRITEME : parameter list 18 | """ 19 | def __init__(self, agent, environment, algorithm, save_path): 20 | self.__dict__.update(locals()) 21 | del self.self 22 | 23 | def main_loop(self): 24 | self.algorithm.setup(agent=self.agent, environment=self.environment) 25 | i = 0 26 | for param in self.agent.get_params(): 27 | assert not contains_nan(param.get_value()), (i, param.name) 28 | assert not contains_inf(param.get_value()), (i, param.name) 29 | while True: 30 | rval = self.algorithm.train() 31 | assert rval is None 32 | i += 1 33 | for param in self.agent.get_params(): 34 | assert not contains_nan(param.get_value()), (i, param.name) 35 | assert not contains_inf(param.get_value()), (i, param.name) 36 | if i % 1000 == 0: 37 | serial.save(self.save_path, self.agent) 38 | logger.info('saved!') 39 | -------------------------------------------------------------------------------- /pylearn2/sandbox/nlp/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Sandbox for developing natural language processing (NLP) tools for 3 | Pylearn2, including datasets and models 4 | """ 5 | -------------------------------------------------------------------------------- /pylearn2/sandbox/nlp/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Sandbox datasets for natural language processing (NLP) 3 | """ 4 | -------------------------------------------------------------------------------- /pylearn2/sandbox/nlp/linear/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Sandbox linear operators for natural language processing (NLP) 3 | """ 4 | -------------------------------------------------------------------------------- /pylearn2/sandbox/nlp/linear/matrixmul.py: -------------------------------------------------------------------------------- 1 | """ 2 | Sandbox projection operator for natural language processing (NLP) 3 | """ 4 | from pylearn2.linear import matrixmul 5 | 6 | 7 | class MatrixMul(matrixmul.MatrixMul): 8 | """ 9 | Operations which can be represented as matrix multiplications. 10 | 11 | Parameters 12 | ---------- 13 | W : WRITEME 14 | """ 15 | def project(self, x): 16 | """ 17 | Takes a sequence of integers and projects (embeds) these labels 18 | into a continuous space by concatenating the correspending 19 | rows in the projection matrix W i.e. [2, 5] -> [W[2] ... W[5]] 20 | 21 | Parameters 22 | ---------- 23 | x : theano.tensor, int dtype 24 | A vector of labels (or a matrix where each row is a sample in 25 | a batch) which will be projected 26 | """ 27 | 28 | assert 'int' in str(x.dtype) 29 | 30 | if x.ndim == 2: 31 | shape = (x.shape[0], x.shape[1] * self._W.shape[1]) 32 | return self._W[x.flatten()].reshape(shape) 33 | elif x.ndim == 1: 34 | return self._W[x].flatten() 35 | else: 36 | assert ValueError("project needs 1- or 2-dimensional input") 37 | -------------------------------------------------------------------------------- /pylearn2/sandbox/nlp/linear/tests/test_matrixmul.py: -------------------------------------------------------------------------------- 1 | """ 2 | Sandbox tests for the projection operator 3 | """ 4 | import numpy as np 5 | import theano 6 | 7 | from pylearn2.sandbox.nlp.linear.matrixmul import MatrixMul 8 | from pylearn2.utils import sharedX 9 | from theano import tensor 10 | 11 | 12 | def test_matrixmul(): 13 | """ 14 | Tests for projection 15 | """ 16 | rng = np.random.RandomState(222) 17 | dtypes = [ 18 | 'int16', 'int32', 'int64' 19 | ] 20 | tensor_x = [ 21 | tensor.wmatrix(), 22 | tensor.imatrix(), 23 | tensor.lmatrix(), 24 | tensor.wvector(), 25 | tensor.ivector(), 26 | tensor.lvector() 27 | ] 28 | np_W, np_x = [], [] 29 | for dtype in dtypes: 30 | np_W.append(rng.rand(10, np.random.randint(1, 10))) 31 | np_x.append(rng.randint( 32 | 0, 10, (rng.random_integers(5), 33 | rng.random_integers(5)) 34 | ).astype(dtype)) 35 | for dtype in dtypes: 36 | np_W.append(rng.rand(10, np.random.randint(1, 10))) 37 | np_x.append( 38 | rng.randint(0, 10, (rng.random_integers(5),)).astype(dtype) 39 | ) 40 | 41 | tensor_W = [sharedX(W) for W in np_W] 42 | matrixmul = [MatrixMul(W) for W in tensor_W] 43 | assert all(mm.get_params()[0] == W for mm, W in zip(matrixmul, tensor_W)) 44 | 45 | fn = [theano.function([x], mm.project(x)) 46 | for x, mm in zip(tensor_x, matrixmul)] 47 | for W, x, f in zip(np_W, np_x, fn): 48 | W_x = W[x] 49 | if x.ndim == 2: 50 | W_x = W_x.reshape((W_x.shape[0], np.prod(W_x.shape[1:]))) 51 | else: 52 | W_x = W_x.flatten() 53 | np.testing.assert_allclose(f(x), W_x) 54 | -------------------------------------------------------------------------------- /pylearn2/sandbox/nlp/models/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Sandbox models for natural language processing (NLP) 3 | """ 4 | -------------------------------------------------------------------------------- /pylearn2/sandbox/nlp/models/tests/test_mlp.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests for MLP 3 | """ 4 | __authors__ = "Minh Ngoc Le" 5 | __copyright__ = "Copyright 2010-2015, Universite de Montreal" 6 | __credits__ = ["Minh Ngoc Le"] 7 | __license__ = "3-clause BSD" 8 | __maintainer__ = "LISA Lab" 9 | __email__ = "pylearn-dev@googlegroups" 10 | 11 | import os 12 | from pylearn2.config import yaml_parse 13 | 14 | 15 | def test_projection_layer_yaml(): 16 | """Test loading and running a complex model with ProjectionLayer.""" 17 | test_dir = os.path.dirname(__file__) 18 | with open(os.path.join(test_dir, 'composite.yaml')) as f: 19 | train = yaml_parse.load(f.read()) 20 | train.main_loop() 21 | -------------------------------------------------------------------------------- /pylearn2/sandbox/rnn/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | The RNN framework. It extends the standard MLP framework in 3 | several ways, most notably: 4 | 5 | - Wrap the set_input_space, get_output_space and fprop methods to 6 | deal with sequential data. It does so by reshaping the data from 7 | a ND [time, batch, data, ..., data] tensor to a (N-1)D tensor, 8 | [time * batch, data, ..., data] and reshaping the data back before 9 | passing the output to the next layer. 10 | 11 | - Recurrent layers are introduced. 12 | 13 | - A SequenceSpace is defined, which can be a sequence of any other space 14 | e.g. SequenceSpace(VectorSpace(dim=100)). 15 | 16 | - The dataset iterators are adapted to deal with sequential data, either 17 | by creating batches which are uniform in sequence length, or by 18 | providing a mask along with zero-padded data, describing the length of 19 | the sequences. 20 | """ 21 | -------------------------------------------------------------------------------- /pylearn2/sandbox/rnn/costs/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Costs specific to the RNN framework. 3 | """ 4 | -------------------------------------------------------------------------------- /pylearn2/sandbox/rnn/costs/tests/test_gradient_clipping.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for the gradient clipping cost 3 | """ 4 | import unittest 5 | 6 | import numpy as np 7 | from theano import function 8 | 9 | from pylearn2.costs.mlp import Default 10 | from pylearn2.models.mlp import MLP, Linear 11 | from pylearn2.sandbox.rnn.costs.gradient_clipping import GradientClipping 12 | 13 | 14 | class TestGradientClipping(unittest.TestCase): 15 | """ 16 | Test cases for the gradient clipping cost 17 | 18 | Parameters 19 | ---------- 20 | None 21 | """ 22 | def test_gradient_clipping(self): 23 | """ 24 | Create a known gradient and check whether it is being clipped 25 | correctly 26 | """ 27 | mlp = MLP(layers=[Linear(dim=1, irange=0, layer_name='linear')], 28 | nvis=1) 29 | W, b = mlp.layers[0].get_params() 30 | W.set_value([[10]]) 31 | 32 | X = mlp.get_input_space().make_theano_batch() 33 | y = mlp.get_output_space().make_theano_batch() 34 | 35 | cost = Default() 36 | gradients, _ = cost.get_gradients(mlp, (X, y)) 37 | 38 | clipped_cost = GradientClipping(20, Default()) 39 | clipped_gradients, _ = clipped_cost.get_gradients(mlp, (X, y)) 40 | 41 | # The MLP defines f(x) = (x W)^2, with df/dW = 2 W x^2 42 | f = function([X, y], [gradients[W].sum(), clipped_gradients[W].sum()], 43 | allow_input_downcast=True) 44 | 45 | # df/dW = df/db = 20 for W = 10, x = 1, so the norm is 20 * sqrt(2) 46 | # and the gradients should be clipped to 20 / sqrt(2) 47 | np.testing.assert_allclose(f([[1]], [[0]]), [20, 20 / np.sqrt(2)]) 48 | 49 | if __name__ == '__main__': 50 | unittest.main() 51 | -------------------------------------------------------------------------------- /pylearn2/sandbox/rnn/models/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Layers specific to the RNN framework. These can be layers with 3 | recurrency, but also MLP layers that have been optimized 4 | for use with sequence-data. 5 | """ 6 | -------------------------------------------------------------------------------- /pylearn2/sandbox/rnn/utils/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Utilities for RNN framework 3 | """ 4 | -------------------------------------------------------------------------------- /pylearn2/scripts/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Some scripts define objects that we want to import via yaml files 3 | that we pass to the script, so this directory must be a python 4 | module, rather than just a directory full of scripts. 5 | """ 6 | -------------------------------------------------------------------------------- /pylearn2/scripts/autoencoder_example/dae.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.train.Train { 2 | "dataset": !obj:pylearn2.datasets.dense_design_matrix.DenseDesignMatrix &dataset { 3 | "X" : !obj:numpy.random.normal { 'size':[5,3] }, 4 | }, 5 | "model": !obj:pylearn2.models.autoencoder.DenoisingAutoencoder { 6 | "nvis" : 3, 7 | "nhid" : 4, 8 | "irange" : 0.05, 9 | "corruptor": !obj:pylearn2.corruption.BinomialCorruptor { 10 | "corruption_level": 0.5, 11 | }, 12 | "act_enc": "tanh", 13 | "act_dec": null, # Linear activation on the decoder side. 14 | }, 15 | "algorithm": !obj:pylearn2.training_algorithms.sgd.SGD { 16 | "learning_rate" : 1e-3, 17 | "batch_size" : 5, 18 | "monitoring_dataset" : *dataset, 19 | "cost" : !obj:pylearn2.costs.autoencoder.MeanSquaredReconstructionError {}, 20 | "termination_criterion" : !obj:pylearn2.termination_criteria.EpochCounter { 21 | "max_epochs": 1, 22 | }, 23 | }, 24 | "save_path": "./garbage.pkl" 25 | } 26 | -------------------------------------------------------------------------------- /pylearn2/scripts/autoencoder_example/hcae.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.train.Train { 2 | "dataset": !obj:pylearn2.datasets.dense_design_matrix.DenseDesignMatrix &dataset { 3 | "X" : !obj:numpy.random.normal { 'size':[5,3] }, 4 | }, 5 | "model": !obj:pylearn2.models.autoencoder.HigherOrderContractiveAutoencoder { 6 | "nvis" : 3, 7 | "nhid" : 4, 8 | "irange" : 0.05, 9 | "corruptor": !obj:pylearn2.corruption.BinomialCorruptor { 10 | "corruption_level": 0.5, 11 | }, 12 | "num_corruptions": 5, 13 | "act_enc": "sigmoid", 14 | "act_dec": "sigmoid", # Linear activation on the decoder side. 15 | }, 16 | "algorithm": !obj:pylearn2.training_algorithms.sgd.SGD { 17 | "learning_rate" : 1e-3, 18 | "batch_size" : 5, 19 | "monitoring_dataset" : *dataset, 20 | "cost" : !obj:pylearn2.costs.cost.SumOfCosts { 21 | "costs": [ 22 | [1.0, !obj:pylearn2.costs.autoencoder.MeanBinaryCrossEntropy {} ], 23 | [0.5, !obj:pylearn2.costs.cost.MethodCost { "method": 'contraction_penalty' } ], 24 | [0.5, !obj:pylearn2.costs.cost.MethodCost { "method": 'higher_order_penalty' } ], 25 | ] 26 | }, 27 | 28 | "termination_criterion" : !obj:pylearn2.termination_criteria.EpochCounter { 29 | "max_epochs": 1, 30 | }, 31 | }, 32 | } 33 | -------------------------------------------------------------------------------- /pylearn2/scripts/datasets/download_cifar10.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This script downloads CIFAR-10 dataset to $PYLEARN2_DATA_PATH/cifar10 3 | #set -e 4 | [ -z "$PYLEARN2_DATA_PATH" ] && echo "PYLEARN2_DATA_PATH is not set" && exit 1 5 | CIFAR10_DIR=$PYLEARN2_DATA_PATH/cifar10 6 | 7 | which wget > /dev/null 8 | WGET=$? 9 | which curl > /dev/null 10 | CURL=$? 11 | 12 | if [ "$WGET" -eq 0 ]; then 13 | DL_CMD="wget --no-verbose -O -" 14 | elif [ "$CURL" -eq 0 ]; then 15 | DL_CMD="curl --silent -o -" 16 | else 17 | echo "You need wget or curl installed to download" 18 | exit 1 19 | fi 20 | 21 | [ -d $CIFAR10_DIR ] && echo "$CIFAR10_DIR already exists." && exit 1 22 | mkdir -p $CIFAR10_DIR 23 | 24 | echo "Downloading and unzipping CIFAR-10 dataset into $CIFAR10_DIR..." 25 | pushd $CIFAR10_DIR > /dev/null 26 | $DL_CMD http://www.cs.utoronto.ca/~kriz/cifar-10-python.tar.gz | tar xvzf - 27 | popd > /dev/null 28 | -------------------------------------------------------------------------------- /pylearn2/scripts/datasets/download_mnist.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import os 4 | import urllib 5 | import gzip 6 | assert 'PYLEARN2_DATA_PATH' in os.environ, "PYLEARN2_DATA_PATH not defined" 7 | mnist_path = os.path.join(os.environ['PYLEARN2_DATA_PATH'], "mnist") 8 | 9 | if not os.path.isdir(mnist_path): 10 | print("creating path: " + mnist_path) 11 | os.makedirs(mnist_path) 12 | 13 | in_dir = os.listdir(mnist_path) 14 | mnist_files = ["t10k-images-idx3-ubyte", "t10k-labels-idx1-ubyte", 15 | "train-images-idx3-ubyte", "train-labels-idx1-ubyte"] 16 | mnist_url = "http://yann.lecun.com/exdb/mnist/" 17 | 18 | if not all([f in in_dir for f in mnist_files]) or in_dir == []: 19 | print("Downloading MNIST data...") 20 | gz_in = [os.path.join(mnist_path, f + ".gz") for f in mnist_files] 21 | gz_out = [os.path.join(mnist_path, f)for f in mnist_files] 22 | mnist_url = ["".join([mnist_url, f, ".gz"]) for f in mnist_files] 23 | 24 | for g_in, g_out, m_url in zip(gz_in, gz_out, mnist_url): 25 | print("Downloading " + m_url + "...", end='') 26 | urllib.urlretrieve(m_url, filename=g_in) 27 | print(" Done") 28 | 29 | with gzip.GzipFile(g_in) as f_gz: 30 | data = f_gz.read() 31 | 32 | with open(g_out, 'wb') as f_out: 33 | f_out.write(data) 34 | 35 | print("Done downloading MNIST") 36 | else: 37 | print("MNIST files already in PYLEARN2_DATA_PATH") 38 | -------------------------------------------------------------------------------- /pylearn2/scripts/datasets/download_svhn.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This script downloads SVHN Format 2 dataset to $PYLEARN2_DATA_PATH/SVHN/format2 3 | #set -e 4 | [ -z "$PYLEARN2_DATA_PATH" ] && echo "PYLEARN2_DATA_PATH is not set" && exit 1 5 | SVHN_DIR=$PYLEARN2_DATA_PATH/SVHN/format2 6 | 7 | which wget > /dev/null 8 | WGET=$? 9 | which curl > /dev/null 10 | CURL=$? 11 | 12 | if [ "$WGET" -eq 0 ]; then 13 | DL_CMD="wget " 14 | elif [ "$CURL" -eq 0 ]; then 15 | DL_CMD="curl " 16 | else 17 | echo "You need wget or curl installed to download" 18 | exit 1 19 | fi 20 | 21 | [ -d $SVHN_DIR ] && echo "$SVHN_DIR already exists." && exit 1 22 | mkdir -p $SVHN_DIR 23 | 24 | echo "Downloading SVHN dataset into $SVHN_DIR..." 25 | pushd $SVHN_DIR > /dev/null 26 | $DL_CMD http://ufldl.stanford.edu/housenumbers/train_32x32.mat 27 | $DL_CMD http://ufldl.stanford.edu/housenumbers/test_32x32.mat 28 | $DL_CMD http://ufldl.stanford.edu/housenumbers/extra_32x32.mat 29 | popd > /dev/null 30 | echo "Downloading Completed. Note: The dataset is for non-commercial use only" 31 | -------------------------------------------------------------------------------- /pylearn2/scripts/datasets/make_svhn_pytables.py: -------------------------------------------------------------------------------- 1 | """ 2 | Script to split the downloaded SVHN .mat files to 'test', 'valid', and 'train' 3 | sets and save them as pytables. Ensure that you have set the PYLEARN2_DATA_PATH 4 | environment variable and downloaded the .mat files to the path 5 | ${PYLEARN2_DATA_PATH}/SVHN/format2/ 6 | """ 7 | import os 8 | from pylearn2.datasets.svhn import SVHN 9 | from pylearn2.utils.string_utils import preprocess 10 | 11 | assert 'PYLEARN2_DATA_PATH' in os.environ, "PYLEARN2_DATA_PATH not defined" 12 | 13 | orig_path = preprocess('${PYLEARN2_DATA_PATH}/SVHN/format2/') 14 | 15 | # Check if MAT files have been downloaded 16 | if not os.path.isdir(orig_path): 17 | raise IOError("You need to download the SVHN format2 dataset MAT files " 18 | "before running this conversion script.") 19 | 20 | # Create directory in which to save the pytables files 21 | local_path = orig_path 22 | if not os.path.isdir(os.path.join(local_path, 'h5')): 23 | os.makedirs(os.path.join(local_path, 'h5')) 24 | 25 | print("***************************************************************\n" 26 | "Please ignore the warning produced during this MAT -> Pytables\n" 27 | "conversion for the SVHN dataset. If you are creating the\n" 28 | "pytables for the first time then no files are modified/over-written,\n" 29 | "they are simply written for the first time.\n" 30 | "***************************************************************\n") 31 | 32 | test = SVHN('test', path=local_path) 33 | 34 | valid = SVHN('valid', path=local_path) 35 | 36 | train = SVHN('splitted_train', path=local_path) 37 | -------------------------------------------------------------------------------- /pylearn2/scripts/datasets/step_through_norb_foveated.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | __author__ = "Ian Goodfellow" 4 | """ 5 | A script for sequentially stepping through FoveatedNORB, viewing each image 6 | and its label. 7 | """ 8 | import numpy as np 9 | 10 | from theano.compat.six.moves import input 11 | 12 | from pylearn2.datasets.norb_small import FoveatedNORB 13 | from pylearn2.gui.patch_viewer import PatchViewer 14 | from pylearn2.utils import get_choice 15 | 16 | print('Use test set?') 17 | choices = {'y': 'test', 'n': 'train'} 18 | which_set = choices[get_choice(choices)] 19 | 20 | dataset = FoveatedNORB(which_set=which_set, center=True) 21 | 22 | topo = dataset.get_topological_view() 23 | 24 | b, r, c, ch = topo.shape 25 | 26 | assert ch == 2 27 | 28 | pv = PatchViewer((1, 2), (r, c), is_color=False) 29 | 30 | i = 0 31 | while True: 32 | patch = topo[i, :, :, :] 33 | patch = patch / np.abs(patch).max() 34 | 35 | pv.add_patch(patch[:, :, 1], rescale=False) 36 | pv.add_patch(patch[:, :, 0], rescale=False) 37 | 38 | pv.show() 39 | 40 | print(dataset.y[i]) 41 | 42 | choices = {'g': 'goto image', 'q': 'quit'} 43 | 44 | if i + 1 < b: 45 | choices['n'] = 'next image' 46 | 47 | choice = get_choice(choices) 48 | 49 | if choice == 'q': 50 | quit() 51 | 52 | if choice == 'n': 53 | i += 1 54 | 55 | if choice == 'g': 56 | i = int(input('index: ')) 57 | -------------------------------------------------------------------------------- /pylearn2/scripts/dbm/README: -------------------------------------------------------------------------------- 1 | Scripts related to the pylearn2.models.dbm.DBM class 2 | -------------------------------------------------------------------------------- /pylearn2/scripts/dbm/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/scripts/dbm/__init__.py -------------------------------------------------------------------------------- /pylearn2/scripts/find_gpu_fields.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | .. todo:: 4 | 5 | WRITEME 6 | """ 7 | #argument: path to a pkl file 8 | #loads the pkl file and figures out which fields are CudaNDArrays 9 | 10 | from __future__ import print_function 11 | 12 | import sys 13 | 14 | if __name__ == "__main__": 15 | path = sys.argv[1] 16 | 17 | from pylearn2.utils import serial 18 | import inspect 19 | 20 | obj = serial.load(path) 21 | 22 | from theano.sandbox.cuda import CudaNdarray 23 | 24 | visited = set([]) 25 | 26 | def find(cur_obj, cur_name): 27 | global visited 28 | 29 | if isinstance(cur_obj, CudaNdarray): 30 | print(cur_name) 31 | print(cur_name) 32 | for field, new_obj in inspect.getmembers(cur_obj): 33 | 34 | if new_obj in visited: 35 | continue 36 | 37 | visited = visited.union([new_obj]) 38 | 39 | print(visited) 40 | 41 | find(new_obj,cur_name+'.'+field) 42 | 43 | find(obj,'') 44 | -------------------------------------------------------------------------------- /pylearn2/scripts/icml_2013_wrepl/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example code for the ICML 2013 Workshop on Representation Learning 3 | """ 4 | -------------------------------------------------------------------------------- /pylearn2/scripts/icml_2013_wrepl/black_box/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example code for the black box challenge 3 | """ 4 | -------------------------------------------------------------------------------- /pylearn2/scripts/icml_2013_wrepl/black_box/learn_zca.py: -------------------------------------------------------------------------------- 1 | from pylearn2.datasets.preprocessing import ZCA 2 | from pylearn2.utils import serial 3 | 4 | from black_box_dataset import BlackBoxDataset 5 | 6 | extra = BlackBoxDataset('extra') 7 | 8 | zca = ZCA(filter_bias=.1) 9 | 10 | zca.fit(extra.X) 11 | 12 | serial.save('zca.pkl', zca) 13 | -------------------------------------------------------------------------------- /pylearn2/scripts/icml_2013_wrepl/emotions/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example code for the emotion recognition challenge 3 | """ 4 | -------------------------------------------------------------------------------- /pylearn2/scripts/icml_2013_wrepl/emotions/emotions_public_test.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.scripts.icml_2013_wrepl.emotions.emotions_dataset.EmotionsDataset { 2 | which_set: 'public_test' 3 | } 4 | -------------------------------------------------------------------------------- /pylearn2/scripts/icml_2013_wrepl/emotions/emotions_train.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.scripts.icml_2013_wrepl.emotions.emotions_dataset.EmotionsDataset { 2 | which_set: 'train' 3 | } 4 | -------------------------------------------------------------------------------- /pylearn2/scripts/icml_2013_wrepl/multimodal/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example code for the multimodal learning challenge 3 | """ 4 | -------------------------------------------------------------------------------- /pylearn2/scripts/icml_2013_wrepl/multimodal/make_wordlist.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import os 4 | from pylearn2.utils.string_utils import preprocess 5 | 6 | 7 | def main(): 8 | base = '${PYLEARN2_DATA_PATH}/esp_game/ESPGame100k/labels/' 9 | base = preprocess(base) 10 | paths = sorted(os.listdir(base)) 11 | assert len(paths) == 100000 12 | 13 | words = {} 14 | 15 | for i, path in enumerate(paths): 16 | 17 | if i % 1000 == 0: 18 | print(i) 19 | path = base+path 20 | f = open(path, 'r') 21 | lines = f.readlines() 22 | for line in lines: 23 | word = line[: -1] 24 | if word not in words: 25 | words[word] = 1 26 | else: 27 | words[word] += 1 28 | 29 | ranked_words = sorted(words.keys(), key=lambda x: -words[x]) 30 | 31 | ranked_words = [word_ + '\n' for word_ in ranked_words[0:4000]] 32 | 33 | f = open('wordlist.txt', 'w') 34 | f.writelines(ranked_words) 35 | f.close() 36 | 37 | if __name__ == "__main__": 38 | main() 39 | -------------------------------------------------------------------------------- /pylearn2/scripts/jobman/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /pylearn2/scripts/lcc_tangents/make_dataset.py: -------------------------------------------------------------------------------- 1 | # replicate the preprocessing described in 2 | # Kai Yu's paper Improving LCC with Local Tangents 3 | from pylearn2.utils import serial 4 | from pylearn2.datasets import cifar10 5 | from pylearn2.datasets import preprocessing 6 | 7 | 8 | def main(): 9 | train = cifar10.CIFAR10(which_set="train", center=True) 10 | 11 | pipeline = preprocessing.Pipeline() 12 | pipeline.items.append(preprocessing.GlobalContrastNormalization( 13 | subtract_mean=False, sqrt_bias=0.0, use_std=True)) 14 | pipeline.items.append(preprocessing.PCA(num_components=512)) 15 | 16 | test = cifar10.CIFAR10(which_set="test") 17 | 18 | train.apply_preprocessor(preprocessor=pipeline, can_fit=True) 19 | test.apply_preprocessor(preprocessor=pipeline, can_fit=False) 20 | 21 | serial.save('cifar10_preprocessed_train.pkl', train) 22 | serial.save('cifar10_preprocessed_test.pkl', test) 23 | 24 | if __name__ == "__main__": 25 | main() 26 | -------------------------------------------------------------------------------- /pylearn2/scripts/mlp/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/scripts/mlp/__init__.py -------------------------------------------------------------------------------- /pylearn2/scripts/num_parameters.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Usage: python num_parameters.py .pkl 4 | 5 | Prints the number of parameters in a saved model (total number of scalar 6 | elements in all the arrays parameterizing the model). 7 | """ 8 | from __future__ import print_function 9 | 10 | __author__ = "Ian Goodfellow" 11 | 12 | import sys 13 | 14 | from pylearn2.utils import serial 15 | 16 | 17 | def num_parameters(model): 18 | """ 19 | .. todo:: 20 | 21 | WRITEME 22 | """ 23 | params = model.get_params() 24 | return sum(map(lambda x: x.get_value().size, params)) 25 | 26 | if __name__ == '__main__': 27 | _, model_path = sys.argv 28 | model = serial.load(model_path) 29 | print(num_parameters(model)) 30 | -------------------------------------------------------------------------------- /pylearn2/scripts/papers/README: -------------------------------------------------------------------------------- 1 | The scripts in this directory are aimed at reproducing results from published 2 | papers. 3 | 4 | Each subdirectory corresponds to a different paper. Some of these papers were 5 | originally written using pylearn2, while others were written using different 6 | libraries and languages but the pylearn2 developers have made an attempt to 7 | reproduce them here. 8 | 9 | The papers partially reproduced so far are: 10 | 11 | dbm: Salakhutdinov, R. and Hinton, G. (2009). Deep Boltzmann machines. In 12 | AISTATS 2009. 13 | 14 | jia_huang_wkshp_11: Jia, Yangqing and Huang, Chang. Beyon spatial pyramids: 15 | Receptive field learning for pooled image features, 2011. NIPS 2011 16 | Workshop on Deep Learning and Unsupervised Feature Learning. 17 | 18 | maxout: Goodfellow, I.J., Warde-Farley, D., Mirza, M., Courville, A. and 19 | Bengio, Y. Maxout Networks. 2013. arXiv:1302.4389v3 20 | 21 | -------------------------------------------------------------------------------- /pylearn2/scripts/papers/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Some paper reproduction projects define useful classes one might want to 3 | access through yaml strings, so we make this directory a python module. 4 | """ 5 | -------------------------------------------------------------------------------- /pylearn2/scripts/papers/dropout/README: -------------------------------------------------------------------------------- 1 | The two yaml files in this folder are to reproduce MNIST results of the original dropout paper http://arxiv.org/abs/1207.0580. 2 | 3 | mnist_valid.yaml: use some portion of data for validation and reaches 1.08% error rate. 4 | mnist.yaml uses same hyperparameters as above but uses the whole training set. It will stop at the same epoch that mnist_valid.yaml reaches its best validation error. And results in 1.05% test error. 5 | 6 | 1.10% is the error reported in original dropout paper. 7 | 1.05% is the error reported in Nitish Srivastava's master thesis. 8 | -------------------------------------------------------------------------------- /pylearn2/scripts/papers/jia_huang_wkshp_11/extract_features.yaml: -------------------------------------------------------------------------------- 1 | !obj:extract_features.FeatureExtractor { 2 | #I use a really small batch_size so it will work on gpu 3 | batch_size : 1, 4 | kmeans_path : "kmeans.pkl", 5 | save_path: "features.npy", 6 | dataset_family: extract_features.cifar100, 7 | which_set: "train", 8 | #This is the value from the paper 9 | num_output_features: 6400, 10 | #Do the processing in 10,000 example chunks to 11 | #reduce host memory footprint 12 | chunk_size: 10000, 13 | #I'm not sure which kind of pooling was used in the paper 14 | pool_mode: 'max' 15 | } 16 | -------------------------------------------------------------------------------- /pylearn2/scripts/papers/jia_huang_wkshp_11/extract_test_features.yaml: -------------------------------------------------------------------------------- 1 | !obj:extract_features.FeatureExtractor { 2 | #I use a really small batch_size so it will work on gpu 3 | batch_size : 1, 4 | kmeans_path : "kmeans.pkl", 5 | save_path: "test_features.npy", 6 | dataset_family: extract_features.cifar100, 7 | which_set: "test", 8 | #This is the value from the paper 9 | num_output_features: 6400, 10 | #I'm not sure which kind of pooling was used in the paper 11 | pool_mode: 'max' 12 | } 13 | -------------------------------------------------------------------------------- /pylearn2/scripts/papers/jia_huang_wkshp_11/kmeans.yaml: -------------------------------------------------------------------------------- 1 | # 2 | 3 | 4 | !obj:pylearn2.train.Train { 5 | dataset : !obj:pylearn2.datasets.dense_design_matrix.from_dataset { 6 | # This dataset consists of 6x6 patches, with approximate contrast normalization 7 | # and approximate ZCA whitening, following Adam Coates' ICML '11 paper. 8 | 9 | # I have e-mail confirmation from the authors that they used 6x6 patches, contrast 10 | # normalization, and approximate ZCA whitening. I am not sure if they used the same 11 | # softening parameters as Adam did. Here I use the softening parameters from Adam's 12 | # AISTATS '11 / ICML '11 paper. 13 | dataset: !pkl: "${PYLEARN2_DATA_PATH}/cifar100/cifar100_patches/data.pkl", 14 | # I'm not sure how many examples the authors used. Here I use 400,000 following 15 | # the k-means demo accompanying Adam Coates' AISTATS '11 paper. """ 16 | num_examples: 400000 17 | }, 18 | model : !obj:pylearn2.models.kmeans.KMeans { 19 | # This is the number of filters used in the paper 20 | k : 1600, 21 | nvis: 108, 22 | verbose : 1 23 | }, 24 | save_freq: 1 25 | } 26 | -------------------------------------------------------------------------------- /pylearn2/scripts/papers/jia_huang_wkshp_11/npy2mat.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import sys 4 | in_path, out_path = sys.argv[1:] 5 | from scipy import io 6 | import numpy as np 7 | print('loading') 8 | X = np.load(in_path) 9 | if len(X.shape) > 2: 10 | print('reshaping') 11 | X = X.reshape(X.shape[0],X.shape[1] * X.shape[2] * X.shape[3]) 12 | assert len(X.shape) == 2 13 | print('saving') 14 | io.savemat(out_path,{'X':X}) 15 | 16 | if X.shape[1] > 14400: 17 | print('reloading to make sure it worked') 18 | print('(matlab format can fail for large arrays)') 19 | X = io.loadmat(out_path) 20 | print('success') 21 | -------------------------------------------------------------------------------- /pylearn2/scripts/papers/maxout/compute_test_err.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | from pylearn2.utils import py_integer_types 4 | from pylearn2.utils import serial 5 | from pylearn2.config import yaml_parse 6 | import sys 7 | 8 | _, model_path = sys.argv 9 | 10 | model = serial.load(model_path) 11 | 12 | src = model.dataset_yaml_src 13 | batch_size = 100 14 | model.set_batch_size(batch_size) 15 | 16 | assert src.find('train') != -1 17 | test = yaml_parse.load(src) 18 | test = test.get_test_set() 19 | assert test.X.shape[0] == 10000 20 | 21 | test.X = test.X.astype('float32') 22 | 23 | import theano.tensor as T 24 | 25 | Xb = model.get_input_space().make_batch_theano() 26 | Xb.name = 'Xb' 27 | yb = model.get_output_space().make_batch_theano() 28 | yb.name = 'yb' 29 | 30 | ymf = model.fprop(Xb) 31 | ymf.name = 'ymf' 32 | 33 | from theano import function 34 | 35 | yl = T.argmax(yb,axis=1) 36 | 37 | mf1acc = 1.-T.neq(yl , T.argmax(ymf,axis=1)).mean() 38 | 39 | batch_acc = function([Xb,yb],[mf1acc]) 40 | 41 | # The averaging math assumes batches are all same size 42 | assert test.X.shape[0] % batch_size == 0 43 | 44 | 45 | def accs(): 46 | mf1_accs = [] 47 | assert isinstance(test.X.shape[0], py_integer_types) 48 | assert isinstance(batch_size, py_integer_types) 49 | iterator = test.iterator(mode = 'even_sequential', 50 | batch_size = batch_size, 51 | data_specs = model.cost_from_X_data_specs()) 52 | for item in iterator: 53 | x_arg, y_arg = item 54 | mf1_accs.append(batch_acc(x_arg, y_arg)[0]) 55 | return sum(mf1_accs) / float(len(mf1_accs)) 56 | 57 | 58 | result = accs() 59 | 60 | print(1. - result) 61 | 62 | -------------------------------------------------------------------------------- /pylearn2/scripts/papers/maxout/notes: -------------------------------------------------------------------------------- 1 | All of pylearn2's dependencies (theano / scipy / numpy / etc.) make reproducibility 2 | very difficult. As such, we are not currently going to make any effort to ensure that 3 | all results are widely reproducible on a variety of platforms. Instead, we will 4 | record the platform on which they were verified to be correct. 5 | 6 | MNIST_PI: 7 | Last verified for: 8 | pylearn2 at commit b94519e83aa50c67dd1db7cee1d00aff54188e89 9 | theano at commit 42c16ccfe87103db9021e58c37bc3199813ca517 10 | GPU: GTX 580 11 | CPU: Intel(R) Xeon(R) CPU E5620 @ 2.40GHz 12 | numpy and python provided by EPD 7.1.2 13 | Operating system: Fedora Core 14 14 | This was on the machine barney0 at the lisa lab. 15 | 16 | cifar-10 no data augmentation: 17 | pylearn2 bc25998da3693ca6d9776c0d8e6644bf00bea1a3 18 | theano 11781d77c479f1e2438b722ac896d2b9a54e4702 19 | machine: eos4 at the lisa lab 20 | numpy and python provided by EPD 7.1.2 21 | Operating system: Fedora Core 14 22 | 23 | with data augmentation, it was on eos6, and probably 24 | a slightly newer version of theano and pylearn2. 25 | -------------------------------------------------------------------------------- /pylearn2/scripts/papers/mpdbm/README: -------------------------------------------------------------------------------- 1 | This is a demo of the model described in "Multi-Prediction Deep Boltzmann 2 | Machines," Ian J. Goodfellow, Mehdi Mirza, Aaron Courville, and Yoshua 3 | Bengio, NIPS 2013 4 | 5 | Please cite that paper if you use this code in your research work. 6 | -------------------------------------------------------------------------------- /pylearn2/scripts/print_channel_doc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | .. todo:: 4 | 5 | WRITEME 6 | """ 7 | from __future__ import print_function 8 | 9 | __authors__ = "Ian Goodfellow" 10 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 11 | __credits__ = ["Ian Goodfellow"] 12 | __license__ = "3-clause BSD" 13 | __maintainer__ = "LISA Lab" 14 | __email__ = "pylearn-dev@googlegroups" 15 | 16 | import sys 17 | from pylearn2.utils import serial 18 | 19 | if __name__ == "__main__": 20 | for model_path in sys.argv[1:]: 21 | if len(sys.argv) > 2: 22 | print(model_path) 23 | model = serial.load(model_path) 24 | monitor = model.monitor 25 | channels = monitor.channels 26 | for key in sorted(channels.keys()): 27 | print(key) 28 | value = channels[key] 29 | if not hasattr(value, 'doc'): 30 | print("\tOld pkl file, written before doc system.") 31 | else: 32 | doc = value.doc 33 | if doc is None: 34 | print("No doc available.") 35 | else: 36 | print(doc) 37 | print() 38 | -------------------------------------------------------------------------------- /pylearn2/scripts/print_model.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Usage: print_model.py 4 | Prints out a saved model. 5 | """ 6 | from __future__ import print_function 7 | 8 | __author__ = "Ian Goodfellow" 9 | 10 | import sys 11 | 12 | from pylearn2.utils import serial 13 | 14 | if __name__ == "__main__": 15 | _, model_path = sys.argv 16 | 17 | model = serial.load(model_path) 18 | 19 | print(model) 20 | -------------------------------------------------------------------------------- /pylearn2/scripts/print_monitor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | .. todo:: 4 | 5 | WRITEME 6 | """ 7 | from __future__ import print_function 8 | 9 | __authors__ = "Ian Goodfellow" 10 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 11 | __credits__ = ["Ian Goodfellow"] 12 | __license__ = "3-clause BSD" 13 | __maintainer__ = "LISA Lab" 14 | __email__ = "pylearn-dev@googlegroups" 15 | 16 | def print_monitor(args): 17 | from pylearn2.utils import serial 18 | import gc 19 | for model_path in args: 20 | if len(args) > 1: 21 | print(model_path) 22 | model = serial.load(model_path) 23 | monitor = model.monitor 24 | del model 25 | gc.collect() 26 | channels = monitor.channels 27 | if not hasattr(monitor, '_epochs_seen'): 28 | print('old file, not all fields parsed correctly') 29 | else: 30 | print('epochs seen: ', monitor._epochs_seen) 31 | print('time trained: ', max(channels[key].time_record[-1] for key in 32 | channels)) 33 | for key in sorted(channels.keys()): 34 | print(key, ':', channels[key].val_record[-1]) 35 | 36 | 37 | if __name__ == '__main__': 38 | import sys 39 | print_monitor(sys.argv[1:]) 40 | -------------------------------------------------------------------------------- /pylearn2/scripts/show_weights.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Visualizes the weight matrices of a pickled model 4 | """ 5 | import argparse 6 | 7 | from pylearn2.gui import get_weights_report 8 | 9 | 10 | def show_weights(model_path, rescale="individual", 11 | border=False, out=None): 12 | """ 13 | Show or save weights to an image for a pickled model 14 | 15 | Parameters 16 | ---------- 17 | model_path : str 18 | Path of the model to show weights for 19 | rescale : str 20 | WRITEME 21 | border : bool, optional 22 | WRITEME 23 | out : str, optional 24 | Output file to save weights to 25 | """ 26 | pv = get_weights_report.get_weights_report(model_path=model_path, 27 | rescale=rescale, 28 | border=border) 29 | 30 | if out is None: 31 | pv.show() 32 | else: 33 | pv.save(out) 34 | 35 | 36 | def make_argument_parser(): 37 | """ 38 | Creates an ArgumentParser to read the options for this script from 39 | sys.argv 40 | """ 41 | parser = argparse.ArgumentParser() 42 | 43 | parser.add_argument("--rescale", default="individual") 44 | parser.add_argument("--out", default=None) 45 | parser.add_argument("--border", action="store_true", default=False) 46 | parser.add_argument("path") 47 | return parser 48 | 49 | if __name__ == "__main__": 50 | parser = make_argument_parser() 51 | args = parser.parse_args() 52 | show_weights(args.path, args.rescale, args.border, args.out) 53 | -------------------------------------------------------------------------------- /pylearn2/scripts/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/scripts/tests/__init__.py -------------------------------------------------------------------------------- /pylearn2/scripts/tests/test_autoencoder.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests for the pylearn2 autoencoder module. 3 | """ 4 | import os 5 | 6 | from pylearn2.scripts.tests.yaml_testing import limited_epoch_train 7 | import pylearn2 8 | 9 | 10 | def test_hcae_yaml(): 11 | """ 12 | Train a higher order contractive autoencoder for a single epoch 13 | """ 14 | limited_epoch_train(os.path.join(pylearn2.__path__[0], 15 | "scripts/autoencoder_example/hcae.yaml")) 16 | 17 | 18 | def test_dae_yaml(): 19 | """ 20 | Train a denoising autoencoder for a single epoch 21 | """ 22 | limited_epoch_train(os.path.join(pylearn2.__path__[0], 23 | "scripts/autoencoder_example/dae.yaml")) 24 | -------------------------------------------------------------------------------- /pylearn2/scripts/tests/test_show_examples.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests for the show_examples.py script 3 | """ 4 | import os 5 | 6 | from pylearn2.testing.skip import skip_if_no_matplotlib, skip_if_no_data 7 | from pylearn2.scripts.show_examples import show_examples 8 | 9 | 10 | def test_show_examples(): 11 | """ 12 | Create a YAML file of the MNIST dataset and show examples 13 | """ 14 | skip_if_no_matplotlib() 15 | skip_if_no_data() 16 | with open('temp.yaml', 'w') as f: 17 | f.write(""" 18 | !obj:pylearn2.datasets.mnist.MNIST { 19 | which_set: 'train' 20 | } 21 | """) 22 | show_examples('temp.yaml', 28, 28, out='garbage.png') 23 | os.remove('temp.yaml') 24 | -------------------------------------------------------------------------------- /pylearn2/scripts/tests/test_show_weights.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests for the show_weights.py script 3 | """ 4 | from theano.compat.six.moves import cPickle 5 | import os 6 | 7 | from pylearn2.testing.skip import skip_if_no_matplotlib 8 | from pylearn2.models.mlp import MLP, Linear 9 | from pylearn2.scripts.show_weights import show_weights 10 | 11 | 12 | def test_show_weights(): 13 | """ 14 | Create a pickled model and show the weights 15 | """ 16 | skip_if_no_matplotlib() 17 | with open('model.pkl', 'wb') as f: 18 | model = MLP(layers=[Linear(dim=1, layer_name='h0', irange=0.1)], 19 | nvis=784) 20 | model.dataset_yaml_src = """ 21 | !obj:pylearn2.datasets.mnist.MNIST { 22 | which_set: 'train' 23 | } 24 | """ 25 | cPickle.dump(model, f, protocol=cPickle.HIGHEST_PROTOCOL) 26 | show_weights('model.pkl', rescale='individual', 27 | border=True, out='garbage.png') 28 | os.remove('model.pkl') 29 | os.remove('garbage.png') 30 | -------------------------------------------------------------------------------- /pylearn2/scripts/tests/test_summarize_model.py: -------------------------------------------------------------------------------- 1 | """ 2 | A unit test for the summarize_model.py script 3 | """ 4 | from theano.compat.six.moves import cPickle 5 | import os 6 | 7 | from pylearn2.testing.skip import skip_if_no_matplotlib 8 | from pylearn2.models.mlp import MLP, Linear 9 | from pylearn2.scripts.summarize_model import summarize 10 | 11 | 12 | def test_summarize_model(): 13 | """ 14 | Asks the summarize_model.py script to inspect a pickled model and 15 | check that it completes succesfully 16 | """ 17 | skip_if_no_matplotlib() 18 | with open('model.pkl', 'wb') as f: 19 | cPickle.dump(MLP(layers=[Linear(dim=5, layer_name='h0', irange=0.1)], 20 | nvis=10), f, protocol=cPickle.HIGHEST_PROTOCOL) 21 | summarize('model.pkl') 22 | os.remove('model.pkl') 23 | -------------------------------------------------------------------------------- /pylearn2/scripts/tests/test_train.py: -------------------------------------------------------------------------------- 1 | """ 2 | A unit test for the train.py script 3 | """ 4 | import os 5 | 6 | import pylearn2 7 | from pylearn2.scripts.train import train 8 | 9 | 10 | def test_train_cmd(): 11 | """ 12 | Calls the train.py script with a short YAML file 13 | to see if it trains without error 14 | """ 15 | train(os.path.join(pylearn2.__path__[0], 16 | "scripts/autoencoder_example/dae.yaml")) 17 | -------------------------------------------------------------------------------- /pylearn2/scripts/tests/yaml_testing.py: -------------------------------------------------------------------------------- 1 | """ 2 | Methods for testing YAML files 3 | """ 4 | from pylearn2.utils.serial import load_train_file 5 | from pylearn2.termination_criteria import EpochCounter 6 | 7 | 8 | def limited_epoch_train(file_path, max_epochs=1): 9 | """ 10 | This method trains a given YAML file for a single epoch 11 | 12 | Parameters 13 | ---------- 14 | file_path : str 15 | The path to the YAML file to be trained 16 | max_epochs : int 17 | The number of epochs to train this YAML file for. 18 | Defaults to 1. 19 | """ 20 | train = load_train_file(file_path) 21 | train.algorithm.termination_criterion = EpochCounter(max_epochs=max_epochs) 22 | train.main_loop() 23 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/README: -------------------------------------------------------------------------------- 1 | There are two kinds of tutorials in this directory. 2 | 3 | Some tutorials are just subdirectories containing python scripts and yaml 4 | files. To work through these tutorials, just cd into the subdirectory, 5 | and open the README. 6 | 7 | Some tutorials are ipython notebooks. These tutorials are single files with 8 | extension .ipynb. Run these tutorials using ipython, e.g. 9 | 10 | ipython notebook softmax_regression.ipynb 11 | 12 | If you get an error message that looks like: 13 | WARNING:root:500 GET /notebooks/b4261b8b-9d9a-477c-b370-b57f6143ea27?_=1363474284017 (127.0.0.1): Unreadable JSON notebook. 14 | ERROR:root:500 GET /notebooks/b4261b8b-9d9a-477c-b370-b57f6143ea27?_=1363474284017 (127.0.0.1) 67.73ms 15 | 16 | You are using too old of a version of ipython. 17 | These notebooks require version 0.13 to work. 18 | 19 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/scripts/tutorials/__init__.py -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/constrained_optimization.txt: -------------------------------------------------------------------------------- 1 | Safari Books Online has published this blog post, which is a short tutorial 2 | on how to use constrained optimization in Pylearn2: 3 | 4 | http://blog.safaribooksonline.com/2014/02/13/constrained-optimization-pylearn2/ 5 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/convolutional_network/README: -------------------------------------------------------------------------------- 1 | This folder contains an IPython notebook that will teach you the basics of how convolutional networks work, and show you how to use multilayer perceptrons in pylearn2. 2 | 3 | Guide on how to load IPython notebooks: 4 | http://deeplearning.net/software/pylearn2/tutorial/notebook_tutorials.html#notebook-tutorials 5 | 6 | The yaml files in this folder are yaml file templates that would be loaded inside the notebook. For details on how to load them, read the notebook. 7 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/convolutional_network/conv.conf: -------------------------------------------------------------------------------- 1 | yaml_template:=@__builtin__.open('conv.yaml').read() 2 | 3 | hyper_parameters.train_stop=50000 4 | hyper_parameters.valid_stop=60000 5 | hyper_parameters.test_stop=10000 6 | hyper_parameters.batch_size=100 7 | hyper_parameters.output_channels_h2=64 8 | hyper_parameters.output_channels_h3=64 9 | hyper_parameters.max_epochs=500 10 | hyper_parameters.save_path='.' 11 | 12 | extract_results = 'pylearn2.scripts.jobman.experiment.results_extractor' 13 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/dbm_demo/README: -------------------------------------------------------------------------------- 1 | This directory contains examples of how to use pylearn2 DBMs 2 | 3 | 1. How to train a single layer DBM, aka an RBM 4 | 5 | There is a module called pylearn2.models.rbm, but it is 6 | somewhat redundant with pylearn2.models.dbm since an RBM 7 | is just a single layer DBM. In the future, maybe the RBM 8 | class should be rewritten as a single layer subclass of 9 | the DBM. 10 | 11 | For now, you can train an RBM model using either the RBM 12 | class or the DBM class. This directory contains an example 13 | of how to do the latter. Just run 14 | 15 | python train_dbm.py 16 | 17 | This sets hyperparameters(hyper_params) and then runs the 18 | experiment defined in rbm.yaml with those hyper_parameter values. 19 | 20 | See rbm.yaml for further comments. 21 | 22 | After you have trained this, you should be able to run some of 23 | the scripts in pylearn2/scripts/dbm on it. For example, the 24 | show_negative_chains.py script will let you see the last state 25 | of the fantasy particles used for the PCD training. 26 | 27 | Some of the more generic scripts in pylearn2/scripts also apply. 28 | For example, show_weights.py will let you see the learned filters. 29 | 30 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/dbm_demo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/scripts/tutorials/dbm_demo/__init__.py -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/dbm_demo/train_dbm.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module trains dbm_demo/rbm.yaml 3 | """ 4 | 5 | import os 6 | 7 | from pylearn2.testing import skip 8 | from pylearn2.testing import no_debug_mode 9 | from pylearn2.config import yaml_parse 10 | 11 | 12 | @no_debug_mode 13 | def train_yaml(yaml_file): 14 | 15 | train = yaml_parse.load(yaml_file) 16 | train.main_loop() 17 | 18 | 19 | def train(yaml_file_path, save_path): 20 | 21 | yaml = open("{0}/rbm.yaml".format(yaml_file_path), 'r').read() 22 | hyper_params = {'detector_layer_dim': 500, 23 | 'monitoring_batches': 10, 24 | 'train_stop': 50000, 25 | 'max_epochs': 300, 26 | 'save_path': save_path} 27 | 28 | yaml = yaml % (hyper_params) 29 | train_yaml(yaml) 30 | 31 | 32 | def train_dbm(): 33 | 34 | skip.skip_if_no_data() 35 | 36 | yaml_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 37 | '../dbm_demo')) 38 | save_path = os.path.dirname(os.path.realpath(__file__)) 39 | 40 | train(yaml_file_path, save_path) 41 | 42 | if __name__ == '__main__': 43 | train_dbm() 44 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/deep_trainer/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/scripts/tutorials/deep_trainer/__init__.py -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/deep_trainer/test_deep_trainer.py: -------------------------------------------------------------------------------- 1 | """ 2 | A simple unit test of 'run_deep_trainer.py' 3 | """ 4 | from .run_deep_trainer import main 5 | 6 | 7 | def test_deep_trainer(): 8 | # pass args=[] so we can pass options to nosetests on the command line 9 | main(args=[]) 10 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/gae_demo/__init__.py: -------------------------------------------------------------------------------- 1 | """A demo of the GAE.""" -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/grbm_smd/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/scripts/tutorials/grbm_smd/__init__.py -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/grbm_smd/test_grbm_smd.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from nose.plugins.skip import SkipTest 4 | from theano import config 5 | 6 | import pylearn2 7 | from pylearn2.testing import no_debug_mode 8 | from pylearn2.utils.serial import load_train_file 9 | 10 | 11 | @no_debug_mode 12 | def test_train_example(): 13 | """ tests that the grbm_smd example script runs correctly """ 14 | 15 | assert config.mode != "DEBUG_MODE" 16 | path = pylearn2.__path__[0] 17 | train_example_path = os.path.join(path, 'scripts', 'tutorials', 'grbm_smd') 18 | if not os.path.isfile(os.path.join(train_example_path, 19 | 'cifar10_preprocessed_train.pkl')): 20 | raise SkipTest 21 | cwd = os.getcwd() 22 | try: 23 | os.chdir(train_example_path) 24 | train_yaml_path = os.path.join(train_example_path, 25 | 'cifar_grbm_smd.yaml') 26 | train_object = load_train_file(train_yaml_path) 27 | 28 | # Make the termination criterion really lax so that it is quick 29 | train_object.algorithm.termination_criterion.prop_decrease = 0.5 30 | train_object.algorithm.termination_criterion.N = 1 31 | 32 | train_object.main_loop() 33 | finally: 34 | os.chdir(cwd) 35 | 36 | if __name__ == '__main__': 37 | test_train_example() 38 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/jobman_demo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/scripts/tutorials/jobman_demo/__init__.py -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/jobman_demo/mlp.conf: -------------------------------------------------------------------------------- 1 | yaml_template:=@__builtin__.open('jobman_demo/mlp.yaml').read() 2 | 3 | hyper_parameters.learning_rate:=@jobman_demo.utils.log_uniform(1e-5, 1e-1) 4 | hyper_parameters.init_momentum:=@jobman_demo.utils.log_uniform(0.5, 1.0) 5 | 6 | extract_results = "jobman_demo.utils.results_extractor" 7 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/jobman_demo/mlp.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.train.Train { 2 | dataset: &train !obj:pylearn2.datasets.mnist.MNIST { 3 | which_set: 'train', 4 | start: 0, 5 | stop: 50000 6 | }, 7 | model: !obj:pylearn2.models.mlp.MLP { 8 | layers: [ 9 | !obj:pylearn2.models.mlp.Sigmoid { 10 | layer_name: 'h0', 11 | dim: 500, 12 | sparse_init: 15, 13 | }, !obj:pylearn2.models.mlp.Softmax { 14 | layer_name: 'y', 15 | n_classes: 10, 16 | irange: 0. 17 | } 18 | ], 19 | nvis: 784, 20 | }, 21 | algorithm: !obj:pylearn2.training_algorithms.sgd.SGD { 22 | batch_size: 100, 23 | learning_rate: %(learning_rate)f, 24 | learning_rule: !obj:pylearn2.training_algorithms.learning_rule.Momentum { 25 | init_momentum: %(init_momentum)f, 26 | }, 27 | monitoring_batches: 10, 28 | monitoring_dataset : *train, 29 | termination_criterion: !obj:pylearn2.termination_criteria.EpochCounter { 30 | max_epochs: 1 31 | }, 32 | }, 33 | save_path: "mlp.pkl", 34 | save_freq : 5 35 | } 36 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/momentum.txt: -------------------------------------------------------------------------------- 1 | Safari Books Online has published this blog post, which is a short tutorial 2 | on how to use momemntum in Pylearn2: 3 | 4 | http://blog.safaribooksonline.com/2014/02/14/using-momentum-pylearn2/ 5 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/multilayer_perceptron/README: -------------------------------------------------------------------------------- 1 | This folder contains an IPython notebook that will teach you the basics of how multilayer perceptrons work, and show you how to use multilayer perceptrons in pylearn2. 2 | 3 | Guide on how to load IPython notebooks: 4 | http://deeplearning.net/software/pylearn2/tutorial/notebook_tutorials.html#notebook-tutorials 5 | 6 | The yaml files in this folder are yaml file templates that would be loaded inside the notebook. For details on how to load them, read the notebook. 7 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/predicting.txt: -------------------------------------------------------------------------------- 1 | FastML.com has a few articles on Pylearn2, among them this tutorial 2 | on how to get predictions for a classification task: 3 | 4 | http://fastml.com/how-to-get-predictions-from-pylearn2/ 5 | 6 | It explains the process step by step. The corresponding code is in 7 | scripts/mlp/predict_csv.py. 8 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/regression.txt: -------------------------------------------------------------------------------- 1 | Safari Books Online has published this blog post, which is a short tutorial 2 | on how to do regression (learning problems with continuous valued output) 3 | and use 3rd party data in Pylearn2: 4 | 5 | http://blog.safaribooksonline.com/2014/02/10/pylearn2-regression-3rd-party-data/ 6 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/softmax_regression/README: -------------------------------------------------------------------------------- 1 | This folder contains an IPython notebook that will teach you the basics of how softmax regression works, and show you how to do softmax regression in pylearn2. 2 | 3 | Guide on how to load IPython notebooks: 4 | http://deeplearning.net/software/pylearn2/tutorial/notebook_tutorials.html#notebook-tutorials 5 | 6 | The yaml files in this folder are yaml file templates that would be loaded inside the notebook. For details on how to load them, read the notebook. 7 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/softmax_regression/sr_algorithm.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.training_algorithms.bgd.BGD { 2 | batch_size: %(batch_size)i, 3 | line_search_mode: 'exhaustive', 4 | conjugate: 1, 5 | monitoring_dataset: 6 | { 7 | 'train' : *train, 8 | 'valid' : !obj:pylearn2.datasets.mnist.MNIST { 9 | which_set: 'train', 10 | start: 50000, 11 | stop: %(valid_stop)i 12 | }, 13 | 'test' : !obj:pylearn2.datasets.mnist.MNIST { 14 | which_set: 'test', 15 | } 16 | }, 17 | termination_criterion: !obj:pylearn2.termination_criteria.MonitorBased { 18 | channel_name: "valid_y_misclass" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/softmax_regression/sr_dataset.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.datasets.mnist.MNIST { 2 | which_set: 'train', 3 | start: 0, 4 | stop: %(train_stop)i 5 | } 6 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/softmax_regression/sr_model.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.models.softmax_regression.SoftmaxRegression { 2 | n_classes: 10, 3 | irange: 0., 4 | nvis: 784, 5 | } 6 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/softmax_regression/sr_train.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.train.Train { 2 | dataset: &train %(dataset)s, 3 | model: %(model)s, 4 | algorithm: %(algorithm)s, 5 | extensions: [ 6 | !obj:pylearn2.train_extensions.best_params.MonitorBasedSaveBest { 7 | channel_name: 'valid_y_misclass', 8 | save_path: "%(save_path)s/softmax_regression_best.pkl" 9 | }, 10 | ], 11 | save_path: "%(save_path)s/softmax_regression.pkl", 12 | save_freq: 1 13 | } 14 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/softmax_regression/tests/test_softmaxreg.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test for softmax_regression.ipynb 3 | """ 4 | 5 | import os 6 | 7 | from pylearn2.testing.skip import skip_if_no_data 8 | from pylearn2.config import yaml_parse 9 | from theano import config 10 | 11 | 12 | def test(): 13 | skip_if_no_data() 14 | 15 | dirname = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..') 16 | 17 | with open(os.path.join(dirname, 'sr_dataset.yaml'), 'r') as f: 18 | dataset = f.read() 19 | 20 | if config.mode == "DEBUG_MODE": 21 | hyper_params = {'train_stop': 10} 22 | else: 23 | hyper_params = {'train_stop': 50} 24 | dataset = dataset % (hyper_params) 25 | 26 | with open(os.path.join(dirname, 'sr_model.yaml'), 'r') as f: 27 | model = f.read() 28 | 29 | with open(os.path.join(dirname, 'sr_algorithm.yaml'), 'r') as f: 30 | algorithm = f.read() 31 | 32 | if config.mode == "DEBUG_MODE": 33 | hyper_params = {'batch_size': 10, 34 | 'valid_stop': 50010} 35 | else: 36 | hyper_params = {'batch_size': 10, 37 | 'valid_stop': 50050} 38 | algorithm = algorithm % (hyper_params) 39 | 40 | with open(os.path.join(dirname, 'sr_train.yaml'), 'r') as f: 41 | train = f.read() 42 | 43 | save_path = os.path.dirname(os.path.realpath(__file__)) 44 | train = train % locals() 45 | 46 | train = yaml_parse.load(train) 47 | train.main_loop() 48 | 49 | try: 50 | os.remove("{}/softmax_regression.pkl".format(save_path)) 51 | os.remove("{}/softmax_regression_best.pkl".format(save_path)) 52 | except OSError: 53 | pass 54 | 55 | if __name__ == '__main__': 56 | test() 57 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/stacked_autoencoders/README: -------------------------------------------------------------------------------- 1 | This folder contains an IPython notebook that will teach you how to do layer-wise pre-training using denoising auto-encoders and then stack them together to form a MLP and do supervised fine-tuning on it. 2 | 3 | Guide on how to load IPython notebooks: 4 | http://deeplearning.net/software/pylearn2/tutorial/notebook_tutorials.html#notebook-tutorials 5 | 6 | The yaml files in this folder are yaml file templates that would be loaded inside the notebook. For details on how to load them, read the notebook. 7 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/stacked_autoencoders/dae_l1.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.train.Train { 2 | dataset: &train !obj:pylearn2.datasets.mnist.MNIST { 3 | which_set: 'train', 4 | start: 0, 5 | stop: %(train_stop)i 6 | }, 7 | model: !obj:pylearn2.models.autoencoder.DenoisingAutoencoder { 8 | nvis : 784, 9 | nhid : %(nhid)i, 10 | irange : 0.05, 11 | corruptor: !obj:pylearn2.corruption.BinomialCorruptor { 12 | corruption_level: .2, 13 | }, 14 | act_enc: "tanh", 15 | act_dec: null, # Linear activation on the decoder side. 16 | }, 17 | algorithm: !obj:pylearn2.training_algorithms.sgd.SGD { 18 | learning_rate : 1e-3, 19 | batch_size : %(batch_size)i, 20 | monitoring_batches : %(monitoring_batches)i, 21 | monitoring_dataset : *train, 22 | cost : !obj:pylearn2.costs.autoencoder.MeanSquaredReconstructionError {}, 23 | termination_criterion : !obj:pylearn2.termination_criteria.EpochCounter { 24 | max_epochs: %(max_epochs)i, 25 | }, 26 | }, 27 | save_path: "%(save_path)s/dae_l1.pkl", 28 | save_freq: 1 29 | } 30 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/stacked_autoencoders/dae_l2.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.train.Train { 2 | dataset: &train !obj:pylearn2.datasets.transformer_dataset.TransformerDataset { 3 | raw: !obj:pylearn2.datasets.mnist.MNIST { 4 | which_set: 'train', 5 | start: 0, 6 | stop: %(train_stop)i 7 | }, 8 | transformer: !pkl: "%(save_path)s/dae_l1.pkl" 9 | }, 10 | model: !obj:pylearn2.models.autoencoder.DenoisingAutoencoder { 11 | nvis : %(nvis)i, 12 | nhid : %(nhid)i, 13 | irange : 0.05, 14 | corruptor: !obj:pylearn2.corruption.BinomialCorruptor { 15 | corruption_level: .3, 16 | }, 17 | act_enc: "tanh", 18 | act_dec: null, # Linear activation on the decoder side. 19 | }, 20 | algorithm: !obj:pylearn2.training_algorithms.sgd.SGD { 21 | learning_rate : 1e-3, 22 | batch_size : %(batch_size)i, 23 | monitoring_batches : %(monitoring_batches)i, 24 | monitoring_dataset : *train, 25 | cost : !obj:pylearn2.costs.autoencoder.MeanSquaredReconstructionError {}, 26 | termination_criterion : !obj:pylearn2.termination_criteria.EpochCounter { 27 | max_epochs: %(max_epochs)i, 28 | }, 29 | }, 30 | save_path: "%(save_path)s/dae_l2.pkl", 31 | save_freq: 1 32 | } 33 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/tests/test_dbm.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module tests dbm_demo/rbm.yaml 3 | """ 4 | 5 | import os 6 | 7 | from pylearn2.testing import skip 8 | from pylearn2.testing import no_debug_mode 9 | from pylearn2.config import yaml_parse 10 | 11 | 12 | @no_debug_mode 13 | def train_yaml(yaml_file): 14 | 15 | train = yaml_parse.load(yaml_file) 16 | train.main_loop() 17 | 18 | 19 | def train(yaml_file_path, save_path): 20 | 21 | yaml = open("{0}/rbm.yaml".format(yaml_file_path), 'r').read() 22 | hyper_params = {'detector_layer_dim': 5, 23 | 'monitoring_batches': 2, 24 | 'train_stop': 500, 25 | 'max_epochs': 7, 26 | 'save_path': save_path} 27 | 28 | yaml = yaml % (hyper_params) 29 | train_yaml(yaml) 30 | 31 | 32 | def test_dbm(): 33 | 34 | skip.skip_if_no_data() 35 | 36 | yaml_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 37 | '../dbm_demo')) 38 | save_path = os.path.dirname(os.path.realpath(__file__)) 39 | 40 | train(yaml_file_path, save_path) 41 | 42 | try: 43 | os.remove("{}/dbm.pkl".format(save_path)) 44 | except: 45 | pass 46 | 47 | if __name__ == '__main__': 48 | test_dbm() 49 | -------------------------------------------------------------------------------- /pylearn2/scripts/tutorials/tests/test_mlp_nested.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test for multilayer_perceptron.ipynb 3 | """ 4 | 5 | from __future__ import print_function 6 | 7 | import os 8 | 9 | import pylearn2 10 | from pylearn2.termination_criteria import EpochCounter 11 | from pylearn2.testing.skip import skip_if_no_data 12 | from pylearn2.config import yaml_parse 13 | 14 | 15 | def test_nested(): 16 | skip_if_no_data() 17 | with open(os.path.join(pylearn2.__path__[0], 'scripts', 'tutorials', 18 | 'mlp_nested.yaml'), 'r') as f: 19 | train_3 = f.read() 20 | hyper_params = {'train_stop': 50, 21 | 'valid_stop': 50050, 22 | 'dim_h0': 5, 23 | 'dim_h1': 20, 24 | 'dim_h2': 30, 25 | 'dim_h3': 40, 26 | 'sparse_init_h1': 2, 27 | 'max_epochs': 1} 28 | train_3 = train_3 % (hyper_params) 29 | print(train_3) 30 | train_3 = yaml_parse.load(train_3) 31 | train_3.main_loop() 32 | 33 | if __name__ == '__main__': 34 | test_nested() 35 | -------------------------------------------------------------------------------- /pylearn2/testing/__init__.py: -------------------------------------------------------------------------------- 1 | """ Functionality for supporting unit tests. """ 2 | __authors__ = "Ian Goodfellow" 3 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 4 | __credits__ = ["Ian Goodfellow"] 5 | __license__ = "3-clause BSD" 6 | __maintainer__ = "LISA Lab" 7 | __email__ = "pylearn-dev@googlegroups" 8 | 9 | import functools 10 | 11 | from theano import config 12 | 13 | def no_debug_mode(fn): 14 | """ 15 | A decorator used to say a test is too slow to run in debug 16 | mode. 17 | """ 18 | 19 | # Use functools.wraps so that wrapped.func_name matches 20 | # fn.func_name. Otherwise nosetests won't recognize the 21 | # returned function as a test. 22 | @functools.wraps(fn) 23 | def wrapped(*args, **kwargs): 24 | orig_mode = config.mode 25 | if orig_mode in ["DebugMode", "DEBUG_MODE"]: 26 | config.mode = "FAST_RUN" 27 | 28 | try: 29 | return fn(*args, **kwargs) 30 | finally: 31 | config.mode = orig_mode 32 | 33 | return wrapped 34 | 35 | -------------------------------------------------------------------------------- /pylearn2/testing/prereqs.py: -------------------------------------------------------------------------------- 1 | """ Objects to be used as Monitor prereqs during testing. """ 2 | 3 | 4 | class ReadVerifyPrereq(object): 5 | """ 6 | Part of tests/test_monitor.py. Just put here so it be serialized. 7 | 8 | Parameters 9 | ---------- 10 | counter_idx : WRITEME 11 | counter : WRITEME 12 | """ 13 | def __init__(self, counter_idx, counter): 14 | self.counter_idx = counter_idx 15 | self.counter = counter 16 | 17 | def __call__(self, *data): 18 | # We set up each dataset with a different batch size 19 | # check here that we're getting the right one 20 | X, = data 21 | assert X.shape[0] == self.counter_idx + 1 22 | # Each dataset has different content, make sure we 23 | # get the right one 24 | assert X[0,0] == self.counter_idx 25 | prereq_counter = self.counter 26 | prereq_counter.set_value(prereq_counter.get_value() + 1) 27 | -------------------------------------------------------------------------------- /pylearn2/testing/skip.py: -------------------------------------------------------------------------------- 1 | """ 2 | Helper functions for determining which tests to skip. 3 | """ 4 | 5 | __authors__ = "Ian Goodfellow" 6 | __copyright__ = "Copyright 2010-2012, Universite de Montreal" 7 | __credits__ = ["Ian Goodfellow"] 8 | __license__ = "3-clause BSD" 9 | __maintainer__ = "LISA Lab" 10 | __email__ = "pylearn-dev@googlegroups" 11 | from nose.plugins.skip import SkipTest 12 | import os 13 | from theano.sandbox import cuda 14 | 15 | scipy_works = True 16 | try: 17 | import scipy 18 | except ImportError: 19 | # pyflakes gets mad if you set scipy to None here 20 | scipy_works = False 21 | 22 | sklearn_works = True 23 | try: 24 | import sklearn 25 | except ImportError: 26 | sklearn_works = False 27 | 28 | h5py_works = True 29 | try: 30 | import h5py 31 | except ImportError: 32 | h5py_works = False 33 | 34 | matplotlib_works = True 35 | try: 36 | from matplotlib import pyplot 37 | except ImportError: 38 | matplotlib_works = False 39 | 40 | 41 | def skip_if_no_data(): 42 | if 'PYLEARN2_DATA_PATH' not in os.environ: 43 | raise SkipTest() 44 | 45 | 46 | def skip_if_no_scipy(): 47 | if not scipy_works: 48 | raise SkipTest() 49 | 50 | 51 | def skip_if_no_sklearn(): 52 | if not sklearn_works: 53 | raise SkipTest() 54 | 55 | 56 | def skip_if_no_gpu(): 57 | if cuda.cuda_available == False: 58 | raise SkipTest('Optional package cuda disabled.') 59 | 60 | 61 | def skip_if_no_h5py(): 62 | if not h5py_works: 63 | raise SkipTest() 64 | 65 | 66 | def skip_if_no_matplotlib(): 67 | if not matplotlib_works: 68 | raise SkipTest("matplotlib and pyplot are not available") 69 | -------------------------------------------------------------------------------- /pylearn2/testing/tests/test.py: -------------------------------------------------------------------------------- 1 | from pylearn2.testing import no_debug_mode 2 | 3 | from theano import config 4 | 5 | @no_debug_mode 6 | def assert_not_debug_mode(): 7 | assert config.mode != "DEBUG_MODE" 8 | 9 | def test_no_debug_mode(): 10 | orig_mode = config.mode 11 | config.mode = "DEBUG_MODE" 12 | try: 13 | # make sure the decorator gets rid of DEBUG_MODE 14 | assert_not_debug_mode() 15 | finally: 16 | # make sure the decorator restores DEBUG_MODE when it's done 17 | assert config.mode == "DEBUG_MODE" 18 | config.mode = orig_mode 19 | 20 | -------------------------------------------------------------------------------- /pylearn2/testing/tests/test_datasets.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module contains a serie of tests for the datasets in testing.datasets 3 | """ 4 | 5 | from pylearn2.datasets.preprocessing import RemoveMean 6 | from pylearn2.testing.datasets import ArangeDataset 7 | 8 | 9 | def test_arangedataset(): 10 | """ 11 | This test will verify if ArangeDataset can be used with preprocessors 12 | """ 13 | preprocessor = RemoveMean() 14 | dataset = ArangeDataset(1000, preprocessor=preprocessor, 15 | fit_preprocessor=True) 16 | dataset_no_preprocessing = ArangeDataset(1000) 17 | assert (dataset.get_data() != 18 | dataset_no_preprocessing.get_data()).any() 19 | -------------------------------------------------------------------------------- /pylearn2/tests/rbm/mnistvh.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/tests/rbm/mnistvh.mat -------------------------------------------------------------------------------- /pylearn2/tests/test_blocks.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for blocks 3 | """ 4 | 5 | from pylearn2.models.autoencoder import Autoencoder 6 | from pylearn2.blocks import Block, StackedBlocks 7 | 8 | 9 | def test_stackedblocks_with_params(): 10 | """ 11 | Test StackedBlocks when all layers have trainable params 12 | """ 13 | 14 | aes = [Autoencoder(100, 50, 'tanh', 'tanh'), 15 | Autoencoder(50, 10, 'tanh', 'tanh')] 16 | sb = StackedBlocks(aes) 17 | _params = set([p for l in sb._layers for p in l._params]) 18 | 19 | assert sb._params == _params 20 | 21 | 22 | def test_stackedblocks_without_params(): 23 | """ 24 | Test StackedBlocks when not all layers have trainable params 25 | """ 26 | 27 | sb = StackedBlocks([Block(), Block()]) 28 | 29 | assert sb._params is None 30 | -------------------------------------------------------------------------------- /pylearn2/train_extensions/tests/live_monitor_test.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.train.Train { 2 | dataset: &train !obj:pylearn2.testing.datasets.random_dense_design_matrix { 3 | rng: !obj:numpy.random.RandomState { seed: 1}, 4 | num_examples: 50000, 5 | dim: 784, 6 | num_classes: 10 7 | }, 8 | model: !obj:pylearn2.models.softmax_regression.SoftmaxRegression { 9 | n_classes: 10, 10 | nvis: 784, 11 | irange: 0.01, 12 | batch_size: 20 13 | }, 14 | algorithm: !obj:pylearn2.training_algorithms.sgd.SGD { 15 | learning_rate: 0.01, 16 | monitoring_batches: 10, 17 | monitoring_dataset: 18 | { 19 | 'train' : *train, 20 | }, 21 | termination_criterion: !obj:pylearn2.termination_criteria.EpochCounter { 22 | max_epochs: 3 23 | } 24 | }, 25 | extensions: [ 26 | !obj:pylearn2.train_extensions.live_monitoring.LiveMonitoring {} 27 | ] 28 | } -------------------------------------------------------------------------------- /pylearn2/training_algorithms/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Machine learning training algorithms. 3 | """ 4 | 5 | from pylearn2.training_algorithms.training_algorithm import TrainingAlgorithm 6 | -------------------------------------------------------------------------------- /pylearn2/training_algorithms/tests/test_monitoring_batch_size.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests for monitoring_batch_size. 3 | """ 4 | from pylearn2.config import yaml_parse 5 | 6 | 7 | def test_monitoring_batch_size(): 8 | """Test monitoring_batch_size.""" 9 | trainer = yaml_parse.load(test_yaml) 10 | trainer.main_loop() 11 | 12 | test_yaml = """ 13 | !obj:pylearn2.train.Train { 14 | dataset: 15 | &train !obj:pylearn2.testing.datasets.random_one_hot_dense_design_matrix 16 | { 17 | rng: !obj:numpy.random.RandomState {}, 18 | num_examples: 1000, 19 | dim: 15, 20 | num_classes: 2, 21 | }, 22 | model: !obj:pylearn2.models.mlp.MLP { 23 | nvis: 15, 24 | layers: [ 25 | !obj:pylearn2.models.mlp.Sigmoid { 26 | layer_name: 'h0', 27 | dim: 15, 28 | sparse_init: 15, 29 | }, 30 | !obj:pylearn2.models.mlp.Softmax { 31 | layer_name: 'y', 32 | n_classes: 2, 33 | irange: 0.005, 34 | } 35 | ], 36 | }, 37 | algorithm: !obj:pylearn2.training_algorithms.bgd.BGD { 38 | monitoring_dataset: { 39 | 'train': *train, 40 | }, 41 | monitoring_batch_size: 500, 42 | batch_size: 100, 43 | termination_criterion: !obj:pylearn2.termination_criteria.And { 44 | criteria: [ 45 | !obj:pylearn2.termination_criteria.EpochCounter { 46 | max_epochs: 1, 47 | }, 48 | ], 49 | }, 50 | }, 51 | } 52 | """ 53 | -------------------------------------------------------------------------------- /pylearn2/utils/_video.pyx: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | cimport cython 4 | cimport numpy as np 5 | 6 | ctypedef np.uint8_t DTYPE_t 7 | cdef int DTYPE_NUM = np.NPY_UINT8 8 | 9 | np.import_array() 10 | 11 | @cython.boundscheck(False) 12 | @cython.wraparound(False) 13 | cpdef np.ndarray rgb_to_gray(np.ndarray[DTYPE_t, ndim=4] video): 14 | """ 15 | rgb_to_gray(video) 16 | 17 | Converts a color video stored as a 4-dimensional uint8 array to 18 | grayscale using standard YCvCr weighting. 19 | 20 | Parameters 21 | ---------- 22 | video : ndarray, 4-dimensional, uint8 23 | Dimensions are (time, row, column, channel). Along the last axis, 24 | channels are assumed to be ordered (R, G, B). 25 | 26 | Returns 27 | ------- 28 | out : ndarray, 3-dimensional, uint8 29 | Same dimensions as video with the RGB channel dimension removed. 30 | """ 31 | cdef np.ndarray[DTYPE_t, ndim=3] out 32 | out = np.PyArray_ZEROS(3, video.shape, DTYPE_NUM, 0) 33 | cdef np.npy_intp i, j, k 34 | for i in xrange(video.shape[0]): 35 | for j in xrange(video.shape[1]): 36 | for k in xrange(video.shape[2]): 37 | # These are the standard values for the Y channel of 38 | # the YCvCr color map (the 'luma').` 39 | out[i, j, k] = ( 40 | (video[i, j, k, 0] * 0.2125 + 41 | video[i, j, k, 1] * 0.7154 + 42 | video[i, j, k, 2] * 0.0721) 43 | ) 44 | return out 45 | -------------------------------------------------------------------------------- /pylearn2/utils/bit_strings.py: -------------------------------------------------------------------------------- 1 | """Utilities for manipulating binary strings/masks.""" 2 | __author__ = "David Warde-Farley" 3 | __copyright__ = "Copyright 2012, Universite de Montreal" 4 | __credits__ = ["David Warde-Farley"] 5 | __license__ = "3-clause BSD" 6 | __email__ = "wardefar@iro" 7 | __maintainer__ = "David Warde-Farley" 8 | 9 | import numpy as np 10 | from theano.compat.six.moves import xrange 11 | 12 | 13 | def all_bit_strings(bits, dtype='uint8'): 14 | """ 15 | Create a matrix of all binary strings of a given width as the rows. 16 | 17 | Parameters 18 | ---------- 19 | bits : int 20 | The number of bits to count through. 21 | 22 | dtype : str or dtype object 23 | The dtype of the returned array. 24 | 25 | Returns 26 | ------- 27 | bit_strings : ndarray, shape (2 ** bits, bits) 28 | The numbers from 0 to 2 ** bits - 1 as binary numbers, most 29 | significant bit first. 30 | 31 | Notes 32 | ----- 33 | Obviously the memory requirements of this are exponential in the first 34 | argument, so use with caution. 35 | """ 36 | return np.array([[int(x) for x in np.binary_repr(i, width=bits)] 37 | for i in xrange(0, 2 ** bits)], dtype=dtype) 38 | -------------------------------------------------------------------------------- /pylearn2/utils/common_strings.py: -------------------------------------------------------------------------------- 1 | environment_variable_essay = """ 2 | Platform-specific instructions for setting environment variables: 3 | 4 | Linux 5 | ===== 6 | On most linux setups, you can define your environment variable by adding this 7 | line to your ~/.bashrc file: 8 | 9 | export PYLEARN2_VIEWER_COMMAND="eog --new-instance" 10 | 11 | *** YOU MUST INCLUDE THE WORD "export". DO NOT JUST ASSIGN TO THE ENVIRONMENT VARIABLE *** 12 | If you do not include the word "export", the environment variable will be set 13 | in your bash shell, but will not be visible to processes that you launch from 14 | it, like the python interpreter. 15 | 16 | Don't forget that changes from your .bashrc file won't apply until you run 17 | 18 | source ~/.bashrc 19 | 20 | or open a new terminal window. If you're seeing this from an ipython notebook 21 | you'll need to restart the ipython notebook, or maybe modify os.environ from 22 | an ipython cell. 23 | 24 | Mac OS X 25 | ======== 26 | 27 | Environment variables on Mac OS X work the same as in Linux, except you should 28 | modify and run the "source" command on ~/.profile rather than ~/.bashrc. 29 | """ 30 | -------------------------------------------------------------------------------- /pylearn2/utils/python26.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. todo:: 3 | 4 | WRITEME 5 | """ 6 | import functools 7 | import sys 8 | 9 | 10 | if sys.version_info[:2] < (2, 7): 11 | def cmp_to_key(mycmp): 12 | """Convert a cmp= function into a key= function""" 13 | class K(object): 14 | __slots__ = ['obj'] 15 | def __init__(self, obj, *args): 16 | self.obj = obj 17 | def __lt__(self, other): 18 | return mycmp(self.obj, other.obj) < 0 19 | def __gt__(self, other): 20 | return mycmp(self.obj, other.obj) > 0 21 | def __eq__(self, other): 22 | return mycmp(self.obj, other.obj) == 0 23 | def __le__(self, other): 24 | return mycmp(self.obj, other.obj) <= 0 25 | def __ge__(self, other): 26 | return mycmp(self.obj, other.obj) >= 0 27 | def __ne__(self, other): 28 | return mycmp(self.obj, other.obj) != 0 29 | def __hash__(self): 30 | raise TypeError('hash not implemented') 31 | return K 32 | else: 33 | from functools import cmp_to_key 34 | -------------------------------------------------------------------------------- /pylearn2/utils/setup.py: -------------------------------------------------------------------------------- 1 | import warnings 2 | 3 | warnings.warn("pylearn2/utils/setup.py has been deprecated. Please run python " 4 | "setup.py develop in the root directory instead.") 5 | -------------------------------------------------------------------------------- /pylearn2/utils/shell.py: -------------------------------------------------------------------------------- 1 | """ 2 | Utilities for running shell scripts and interacting with the terminal 3 | """ 4 | import subprocess as sp 5 | import sys 6 | 7 | 8 | def run_shell_command(cmd): 9 | """ 10 | Runs cmd as a shell command. Waits for it to finish executing, 11 | then returns all output printed to standard error and standard out, 12 | and the return code. 13 | 14 | Parameters 15 | ---------- 16 | cmd : str 17 | The shell command to run 18 | 19 | Returns 20 | ------- 21 | output : str 22 | The string output of the process 23 | rc : WRITEME 24 | The numeric return code of the process 25 | """ 26 | child = sp.Popen(cmd, shell=True, stdout=sp.PIPE, stderr=sp.STDOUT) 27 | output = child.communicate()[0] 28 | rc = child.returncode 29 | return output, rc 30 | 31 | 32 | def print_progression(percent, width=50, delimiters=['[', ']'], symbol='#'): 33 | """ 34 | Prints a progress bar to the command line 35 | 36 | Parameters 37 | ---------- 38 | percent : float 39 | Completion value between 0 and 100 40 | width : int, optional 41 | Number of symbols corresponding to a 100 percent completion 42 | delimiters : list of str, optional 43 | Character delimiters for the progression bar 44 | symbol : str, optional 45 | Symbol representing one unit of progression 46 | """ 47 | n_symbols = int(percent/100.0*width) 48 | progress_bar = delimiters[0] + n_symbols * symbol \ 49 | + (width - n_symbols) * ' ' \ 50 | + delimiters[1] + " " 51 | sys.stdout.write("\r" + progress_bar + str(percent) + "%") 52 | sys.stdout.flush() 53 | -------------------------------------------------------------------------------- /pylearn2/utils/testing.py: -------------------------------------------------------------------------------- 1 | """ 2 | These are helper methods that provide assertions with informative error 3 | messages, and also avoid the builtin 'assert' statement in their 4 | implementation (which makes them more appropriate for testing, as they 5 | run even with assertions disabled, and even in "python -O" mode). 6 | """ 7 | 8 | __author__ = "David Warde-Farley" 9 | __copyright__ = "Copyright 2012, Universite de Montreal" 10 | __credits__ = ["David Warde-Farley"] 11 | __license__ = "3-clause BSD" 12 | __email__ = "wardefar@iro" 13 | __maintainer__ = "David Warde-Farley" 14 | 15 | from numpy.testing import assert_ 16 | 17 | 18 | def assert_equal(expected, actual): 19 | """ 20 | Equality assertion with a more informative error message. 21 | 22 | Parameters 23 | ---------- 24 | expected : WRITEME 25 | actual : WRITEME 26 | """ 27 | if expected != actual: 28 | raise AssertionError("values not equal, expected: %r, actual: %r" % 29 | (expected, actual)) 30 | 31 | 32 | def assert_same_object(expected, actual): 33 | """ 34 | Asserting object identity. 35 | 36 | Parameters 37 | ---------- 38 | expected : WRITEME 39 | actual : WRITEME 40 | """ 41 | if expected is not actual: 42 | raise AssertionError("values not identical, expected %r, actual %r" % 43 | (expected, actual)) 44 | 45 | 46 | def assert_contains(haystack, needle): 47 | """ 48 | Check if `needle` is in `haystack`. 49 | 50 | Parameters 51 | ---------- 52 | haystack : WRITEME 53 | needle : WRITEME 54 | """ 55 | if needle not in haystack: 56 | raise AssertionError("item %r not found in collection %r" % 57 | (needle, haystack)) 58 | -------------------------------------------------------------------------------- /pylearn2/utils/tests/example_bin_lush/double_3tensor.lushbin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/utils/tests/example_bin_lush/double_3tensor.lushbin -------------------------------------------------------------------------------- /pylearn2/utils/tests/example_bin_lush/float_3tensor.lushbin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/utils/tests/example_bin_lush/float_3tensor.lushbin -------------------------------------------------------------------------------- /pylearn2/utils/tests/example_bin_lush/int_3tensor.lushbin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/utils/tests/example_bin_lush/int_3tensor.lushbin -------------------------------------------------------------------------------- /pylearn2/utils/tests/example_bin_lush/ubyte_3tensor.lushbin: -------------------------------------------------------------------------------- 1 | UL=(4+7".:)5 ,8#/; -------------------------------------------------------------------------------- /pylearn2/utils/tests/example_bin_lush/ubyte_scalar.lushbin: -------------------------------------------------------------------------------- 1 | UL= -------------------------------------------------------------------------------- /pylearn2/utils/tests/example_image/mnist0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lisa-lab/pylearn2/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/utils/tests/example_image/mnist0.jpg -------------------------------------------------------------------------------- /pylearn2/utils/tests/test_bit_strings.py: -------------------------------------------------------------------------------- 1 | from pylearn2.utils.bit_strings import all_bit_strings 2 | import numpy as np 3 | 4 | def test_bit_strings(): 5 | np.testing.assert_equal((all_bit_strings(3) * 6 | (2 ** np.arange(2, -1, -1))).sum(axis=1), 7 | np.arange(2 ** 3)) 8 | -------------------------------------------------------------------------------- /pylearn2/utils/tests/test_compile.py: -------------------------------------------------------------------------------- 1 | """Tests for compilation utilities.""" 2 | import theano 3 | import pickle 4 | 5 | from pylearn2.utils.compile import ( 6 | compiled_theano_function, HasCompiledFunctions 7 | ) 8 | 9 | 10 | class Dummy(HasCompiledFunctions): 11 | const = 3.14159 12 | 13 | @compiled_theano_function 14 | def func(self): 15 | val = theano.tensor.as_tensor_variable(self.const) 16 | return theano.function([], val) 17 | 18 | 19 | def test_simple_compilation(): 20 | x = Dummy() 21 | f = x.func 22 | g = x.func 23 | assert f is g 24 | assert abs(x.func() - Dummy.const) < 1e-6 25 | 26 | 27 | def test_pickling(): 28 | a = Dummy() 29 | assert abs(a.func() - Dummy.const) < 1e-6 30 | serialized = pickle.dumps(a) 31 | b = pickle.loads(serialized) 32 | assert not hasattr(b, '_compiled_functions') 33 | assert abs(b.func() - Dummy.const) < 1e-6 34 | assert not (a.func is b.func) 35 | -------------------------------------------------------------------------------- /pylearn2/utils/tests/test_general.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests for pylearn2.utils.general functions. 3 | """ 4 | from pylearn2.utils import contains_nan, contains_inf, isfinite 5 | import numpy as np 6 | 7 | 8 | def test_contains_nan(): 9 | """ 10 | Tests that pylearn2.utils.contains_nan correctly 11 | identifies `np.nan` values in an array. 12 | """ 13 | arr = np.random.random(100) 14 | assert not contains_nan(arr) 15 | arr[0] = np.nan 16 | assert contains_nan(arr) 17 | 18 | 19 | def test_contains_inf(): 20 | """ 21 | Tests that pylearn2.utils.contains_inf correctly 22 | identifies `np.inf` values in an array. 23 | """ 24 | arr = np.random.random(100) 25 | assert not contains_inf(arr) 26 | arr[0] = np.nan 27 | assert not contains_inf(arr) 28 | arr[1] = np.inf 29 | assert contains_inf(arr) 30 | arr[1] = -np.inf 31 | assert contains_inf(arr) 32 | 33 | 34 | def test_isfinite(): 35 | """ 36 | Tests that pylearn2.utils.isfinite correctly 37 | identifies `np.nan` and `np.inf` values in an array. 38 | """ 39 | arr = np.random.random(100) 40 | assert isfinite(arr) 41 | arr[0] = np.nan 42 | assert not isfinite(arr) 43 | arr[0] = np.inf 44 | assert not isfinite(arr) 45 | arr[0] = -np.inf 46 | assert not isfinite(arr) 47 | -------------------------------------------------------------------------------- /pylearn2/utils/tests/test_image.py: -------------------------------------------------------------------------------- 1 | """Tests for compilation utilities.""" 2 | 3 | import os 4 | from nose.tools import eq_, assert_raises 5 | 6 | import pylearn2 7 | from pylearn2.utils.image import load 8 | 9 | 10 | def test_image_load(): 11 | """ 12 | Test utils.image.load 13 | """ 14 | assert_raises(AssertionError, load, 1) 15 | 16 | path = os.path.join(pylearn2.__path__[0], 'utils', 17 | 'tests', 'example_image', 'mnist0.jpg') 18 | img = load(path) 19 | eq_(img.shape, (28, 28, 1)) -------------------------------------------------------------------------------- /pylearn2/utils/tests/test_logger_utils.py: -------------------------------------------------------------------------------- 1 | """Tests for logger utils methods.""" 2 | 3 | import logging 4 | from pylearn2.utils.logger import newline 5 | 6 | logger = logging.getLogger(__name__) 7 | 8 | 9 | def test_newline(): 10 | """ 11 | Test the state of a the logger passed to the newline function. 12 | The state has to be the same. 13 | """ 14 | # Save current properties 15 | handlers = logger.handlers 16 | level = logger.getEffectiveLevel() 17 | 18 | newline(logger) 19 | 20 | # Ensure that the logger didn't change 21 | assert handlers == logger.handlers 22 | assert level == logger.getEffectiveLevel() 23 | -------------------------------------------------------------------------------- /pylearn2/utils/tests/test_mem.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests for pylearn2.utils.mem functions and classes. 3 | """ 4 | 5 | 6 | from pylearn2.utils.mem import ( 7 | TypicalMemoryError, 8 | improve_memory_error_message 9 | ) 10 | 11 | 12 | def test_typical_memory_error(): 13 | """ 14 | A dummy test that instantiates a TypicalMemoryError 15 | to see if there is no bugs. 16 | """ 17 | try: 18 | raise TypicalMemoryError("test") 19 | except TypicalMemoryError as e: 20 | pass 21 | 22 | 23 | def test_improve_memory_error_message(): 24 | """ 25 | Tests that the MemoryError's message is improved correctly 26 | """ 27 | 28 | try: 29 | improve_memory_error_message(MemoryError(), "test") 30 | except MemoryError as e: 31 | # message has been "improved" 32 | assert len(str(e)) 33 | 34 | try: 35 | improve_memory_error_message(MemoryError("test"), "should not") 36 | except MemoryError as e: 37 | assert str(e) == "test" 38 | -------------------------------------------------------------------------------- /pylearn2/utils/tests/test_model.yaml: -------------------------------------------------------------------------------- 1 | !obj:pylearn2.train.Train { 2 | dataset: &train !obj:pylearn2.datasets.dataset.Dataset {}, 3 | model: !obj:pylearn2.models.mlp.MLP { 4 | layers: [ 5 | !obj:pylearn2.models.mlp.Sigmoid { 6 | layer_name: 'h0', 7 | dim: 500, 8 | sparse_init: 15, 9 | }, !obj:pylearn2.models.mlp.Softmax { 10 | layer_name: 'y', 11 | n_classes: 10, 12 | irange: 0. 13 | } 14 | ], 15 | nvis: 784, 16 | }, 17 | algorithm: !obj:pylearn2.training_algorithms.bgd.BGD { 18 | batch_size: 10000, 19 | line_search_mode: 'exhaustive', 20 | conjugate: 1, 21 | updates_per_batch: 10, 22 | monitoring_dataset: { 23 | 'train': *train 24 | }, 25 | termination_criterion: !obj:pylearn2.termination_criteria.And { 26 | criteria: [ 27 | !obj:pylearn2.termination_criteria.EpochCounter { 28 | max_epochs: 10000 29 | } 30 | ] 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /pylearn2/utils/tests/test_rng.py: -------------------------------------------------------------------------------- 1 | from pylearn2.utils.rng import make_np_rng, make_theano_rng 2 | import numpy 3 | 4 | import theano 5 | from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams 6 | 7 | 8 | def test_np_rng(): 9 | """ 10 | Tests that the four possible ways of creating 11 | a numpy RNG give the same results with the same seed 12 | """ 13 | 14 | rngs = [make_np_rng(rng_or_seed=42, which_method='uniform'), 15 | make_np_rng(rng_or_seed=numpy.random.RandomState(42), 16 | which_method='uniform'), 17 | make_np_rng(default_seed=42), 18 | make_np_rng()] 19 | 20 | random_numbers = rngs[0].uniform(size=(100,)) 21 | equals = numpy.ones((100,)) 22 | for rng in rngs[1:]: 23 | equal = random_numbers == rng.uniform(size=(100,)) 24 | equals *= equal 25 | 26 | assert equals.all() 27 | 28 | 29 | def test_theano_rng(): 30 | """ 31 | Tests that the four possible ways of creating 32 | a theano RNG give the same results with the same seed 33 | """ 34 | 35 | rngs = [make_theano_rng(rng_or_seed=42, which_method='uniform'), 36 | make_theano_rng(rng_or_seed=RandomStreams(42), 37 | which_method='uniform'), 38 | make_theano_rng(default_seed=42), 39 | make_theano_rng()] 40 | 41 | functions = [theano.function([], rng.uniform(size=(100,))) 42 | for rng in rngs] 43 | 44 | random_numbers = functions[0]() 45 | equals = numpy.ones((100,)) 46 | for function in functions[1:]: 47 | equal = random_numbers == function() 48 | equals *= equal 49 | 50 | assert equals.all() 51 | -------------------------------------------------------------------------------- /pylearn2/utils/tests/test_utlc.py: -------------------------------------------------------------------------------- 1 | # Right now this file just tests that the utlc module can be imported 2 | from pylearn2.utils import utlc 3 | --------------------------------------------------------------------------------