From 8985af2fd6704dbcd3e8362bea996d5889c2ccd7 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Fri, 30 Mar 2018 15:31:54 -0400 Subject: [PATCH] Add license to files. --- src/mlpack/bindings/cli/add_to_po.hpp | 5 + src/mlpack/bindings/cli/default_param.hpp | 5 + .../bindings/cli/default_param_impl.hpp | 5 + .../bindings/cli/delete_allocated_memory.hpp | 5 + src/mlpack/bindings/cli/end_program.hpp | 5 + .../bindings/cli/get_allocated_memory.hpp | 5 + src/mlpack/bindings/cli/get_param.hpp | 5 + .../bindings/cli/get_printable_param.hpp | 5 + .../bindings/cli/get_printable_param_impl.hpp | 5 + .../bindings/cli/get_printable_param_name.hpp | 5 + .../cli/get_printable_param_name_impl.hpp | 5 + .../cli/get_printable_param_value.hpp | 5 + .../cli/get_printable_param_value_impl.hpp | 5 + src/mlpack/bindings/cli/get_raw_param.hpp | 5 + .../bindings/cli/map_parameter_name.hpp | 5 + src/mlpack/bindings/cli/output_param.hpp | 5 + src/mlpack/bindings/cli/output_param_impl.hpp | 5 + src/mlpack/bindings/cli/parameter_type.hpp | 5 + .../bindings/cli/parse_command_line.hpp | 5 + .../bindings/cli/print_doc_functions.hpp | 5 + .../bindings/cli/print_doc_functions_impl.hpp | 5 + src/mlpack/bindings/cli/print_help.cpp | 5 + src/mlpack/bindings/cli/print_help.hpp | 5 + src/mlpack/bindings/cli/set_param.hpp | 5 + src/mlpack/bindings/cli/string_type_param.hpp | 5 + .../bindings/cli/string_type_param_impl.hpp | 5 + src/mlpack/bindings/matlab/CMakeLists.txt | 154 -------- .../bindings/matlab/allkfn/CMakeLists.txt | 19 - src/mlpack/bindings/matlab/allkfn/allkfn.cpp | 194 --------- src/mlpack/bindings/matlab/allkfn/allkfn.m | 58 --- .../bindings/matlab/allknn/CMakeLists.txt | 19 - src/mlpack/bindings/matlab/allknn/allknn.cpp | 279 ------------- src/mlpack/bindings/matlab/allknn/allknn.m | 60 --- .../bindings/matlab/emst/CMakeLists.txt | 19 - src/mlpack/bindings/matlab/emst/emst.cpp | 72 ---- src/mlpack/bindings/matlab/emst/emst.m | 52 --- src/mlpack/bindings/matlab/gmm/CMakeLists.txt | 19 - src/mlpack/bindings/matlab/gmm/gmm.cpp | 129 ------ src/mlpack/bindings/matlab/gmm/gmm.m | 28 -- .../bindings/matlab/hmm/hmm_generate.cpp | 373 ------------------ src/mlpack/bindings/matlab/hmm/hmm_generate.m | 28 -- .../bindings/matlab/kernel_pca/CMakeLists.txt | 19 - .../bindings/matlab/kernel_pca/kernel_pca.cpp | 136 ------- .../bindings/matlab/kernel_pca/kernel_pca.m | 71 ---- .../bindings/matlab/kmeans/CMakeLists.txt | 19 - src/mlpack/bindings/matlab/kmeans/kmeans.cpp | 175 -------- src/mlpack/bindings/matlab/kmeans/kmeans.m | 28 -- .../bindings/matlab/lars/CMakeLists.txt | 19 - src/mlpack/bindings/matlab/lars/lars.cpp | 58 --- src/mlpack/bindings/matlab/lars/lars.m | 48 --- src/mlpack/bindings/matlab/nca/CMakeLists.txt | 19 - src/mlpack/bindings/matlab/nca/nca.cpp | 55 --- src/mlpack/bindings/matlab/nca/nca.m | 24 -- src/mlpack/bindings/matlab/nmf/CMakeLists.txt | 19 - src/mlpack/bindings/matlab/nmf/nmf.cpp | 106 ----- src/mlpack/bindings/matlab/nmf/nmf.m | 58 --- src/mlpack/bindings/matlab/pca/CMakeLists.txt | 19 - src/mlpack/bindings/matlab/pca/pca.cpp | 62 --- src/mlpack/bindings/matlab/pca/pca.m | 33 -- .../matlab/range_search/CMakeLists.txt | 19 - .../matlab/range_search/range_search.cpp | 325 --------------- .../matlab/range_search/range_search.m | 47 --- src/mlpack/bindings/python/copy_artifacts.py | 5 + src/mlpack/bindings/python/get_arma_type.hpp | 5 + .../bindings/python/get_cython_type.hpp | 5 + src/mlpack/bindings/python/get_numpy_type.hpp | 5 + .../bindings/python/get_numpy_type_char.hpp | 5 + src/mlpack/bindings/python/get_param.hpp | 5 + .../bindings/python/get_printable_param.hpp | 5 + .../bindings/python/get_python_type.hpp | 5 + src/mlpack/bindings/python/import_decl.hpp | 5 + src/mlpack/bindings/python/mlpack/__init__.py | 5 + .../bindings/python/mlpack/serialization.hpp | 5 + .../bindings/python/print_class_defn.hpp | 5 + src/mlpack/bindings/python/print_defn.hpp | 5 + src/mlpack/bindings/python/print_doc.hpp | 5 + .../bindings/python/print_doc_functions.hpp | 5 + .../python/print_doc_functions_impl.hpp | 5 + .../python/print_input_processing.hpp | 5 + .../python/print_output_processing.hpp | 5 + .../bindings/python/print_python_version.py | 5 + src/mlpack/bindings/python/print_pyx.cpp | 5 + src/mlpack/bindings/python/print_pyx.hpp | 5 + src/mlpack/bindings/python/py_option.hpp | 5 + src/mlpack/bindings/python/setup.py.in | 5 + src/mlpack/bindings/python/strip_type.hpp | 5 + .../python/tests/dataset_info_test.py | 5 + .../python/tests/test_python_binding.py | 5 + .../python/tests/test_python_binding_main.cpp | 5 + src/mlpack/bindings/tests/clean_memory.cpp | 5 + src/mlpack/bindings/tests/clean_memory.hpp | 5 + .../tests/delete_allocated_memory.hpp | 5 + .../bindings/tests/get_allocated_memory.hpp | 5 + src/mlpack/bindings/tests/get_param.hpp | 5 + .../bindings/tests/get_printable_param.hpp | 5 + .../tests/get_printable_param_impl.hpp | 5 + src/mlpack/bindings/tests/ignore_check.hpp | 5 + src/mlpack/core/data/is_naninf.hpp | 5 + src/mlpack/core/data/load_csv.cpp | 11 + src/mlpack/core/math/make_alias.hpp | 5 + src/mlpack/core/math/shuffle_data.hpp | 5 + src/mlpack/core/optimizers/function.hpp | 5 + .../function/add_decomposable_evaluate.hpp | 5 + .../add_decomposable_evaluate_const.hpp | 5 + ...dd_decomposable_evaluate_with_gradient.hpp | 5 + ...omposable_evaluate_with_gradient_const.hpp | 5 + .../function/add_decomposable_gradient.hpp | 5 + .../core/optimizers/function/add_evaluate.hpp | 5 + .../function/add_evaluate_with_gradient.hpp | 5 + .../core/optimizers/function/add_gradient.hpp | 5 + .../core/optimizers/function/traits.hpp | 5 + src/mlpack/core/util/hyphenate_string.hpp | 5 + src/mlpack/core/util/is_std_vector.hpp | 5 + src/mlpack/core/util/mlpack_main.hpp | 5 + src/mlpack/core/util/param_checks.hpp | 5 + src/mlpack/core/util/param_checks_impl.hpp | 5 + src/mlpack/core/util/param_data.hpp | 5 + src/mlpack/core/util/program_doc.hpp | 11 + .../methods/adaboost/adaboost_model.cpp | 5 + .../methods/adaboost/adaboost_model.hpp | 5 + src/mlpack/methods/ann/layer/glimpse.hpp | 5 + src/mlpack/methods/ann/layer/glimpse_impl.hpp | 5 + .../methods/ann/layer/multiply_constant.hpp | 5 + .../ann/layer/multiply_constant_impl.hpp | 5 + .../methods/ann/layer/reinforce_normal.hpp | 5 + .../ann/layer/reinforce_normal_impl.hpp | 5 + .../methods/ann/layer/vr_class_reward.hpp | 5 + .../ann/layer/vr_class_reward_impl.hpp | 5 + .../decision_tree/all_dimension_select.hpp | 5 + .../multiple_random_dimension_select.hpp | 5 + .../decision_tree/random_dimension_select.hpp | 5 + src/mlpack/methods/gmm/gmm.hpp | 3 +- src/mlpack/methods/hmm/hmm_model.hpp | 5 + .../hoeffding_trees/hoeffding_tree_model.cpp | 5 + .../hoeffding_trees/hoeffding_tree_model.hpp | 5 + .../methods/random_forest/bootstrap.hpp | 5 + .../methods/random_forest/random_forest.hpp | 5 + .../random_forest/random_forest_impl.hpp | 5 + .../random_forest/random_forest_main.cpp | 5 + src/mlpack/tests/main_tests/adaboost_test.cpp | 5 + src/mlpack/tests/main_tests/dbscan_test.cpp | 5 + .../tests/main_tests/hmm_generate_test.cpp | 5 + .../tests/main_tests/hmm_loglik_test.cpp | 5 + .../tests/main_tests/hmm_train_test.cpp | 5 + .../tests/main_tests/hmm_viterbi_test.cpp | 5 + src/mlpack/tests/main_tests/kmeans_test.cpp | 5 + .../main_tests/linear_regression_test.cpp | 6 +- src/mlpack/tests/main_tests/pca_test.cpp | 5 + src/mlpack/tests/mock_categorical_data.hpp | 5 + 149 files changed, 573 insertions(+), 2865 deletions(-) delete mode 100644 src/mlpack/bindings/matlab/CMakeLists.txt delete mode 100644 src/mlpack/bindings/matlab/allkfn/CMakeLists.txt delete mode 100644 src/mlpack/bindings/matlab/allkfn/allkfn.cpp delete mode 100644 src/mlpack/bindings/matlab/allkfn/allkfn.m delete mode 100644 src/mlpack/bindings/matlab/allknn/CMakeLists.txt delete mode 100644 src/mlpack/bindings/matlab/allknn/allknn.cpp delete mode 100644 src/mlpack/bindings/matlab/allknn/allknn.m delete mode 100644 src/mlpack/bindings/matlab/emst/CMakeLists.txt delete mode 100644 src/mlpack/bindings/matlab/emst/emst.cpp delete mode 100644 src/mlpack/bindings/matlab/emst/emst.m delete mode 100644 src/mlpack/bindings/matlab/gmm/CMakeLists.txt delete mode 100644 src/mlpack/bindings/matlab/gmm/gmm.cpp delete mode 100644 src/mlpack/bindings/matlab/gmm/gmm.m delete mode 100644 src/mlpack/bindings/matlab/hmm/hmm_generate.cpp delete mode 100644 src/mlpack/bindings/matlab/hmm/hmm_generate.m delete mode 100644 src/mlpack/bindings/matlab/kernel_pca/CMakeLists.txt delete mode 100644 src/mlpack/bindings/matlab/kernel_pca/kernel_pca.cpp delete mode 100644 src/mlpack/bindings/matlab/kernel_pca/kernel_pca.m delete mode 100644 src/mlpack/bindings/matlab/kmeans/CMakeLists.txt delete mode 100644 src/mlpack/bindings/matlab/kmeans/kmeans.cpp delete mode 100644 src/mlpack/bindings/matlab/kmeans/kmeans.m delete mode 100644 src/mlpack/bindings/matlab/lars/CMakeLists.txt delete mode 100644 src/mlpack/bindings/matlab/lars/lars.cpp delete mode 100644 src/mlpack/bindings/matlab/lars/lars.m delete mode 100644 src/mlpack/bindings/matlab/nca/CMakeLists.txt delete mode 100644 src/mlpack/bindings/matlab/nca/nca.cpp delete mode 100644 src/mlpack/bindings/matlab/nca/nca.m delete mode 100644 src/mlpack/bindings/matlab/nmf/CMakeLists.txt delete mode 100644 src/mlpack/bindings/matlab/nmf/nmf.cpp delete mode 100644 src/mlpack/bindings/matlab/nmf/nmf.m delete mode 100644 src/mlpack/bindings/matlab/pca/CMakeLists.txt delete mode 100644 src/mlpack/bindings/matlab/pca/pca.cpp delete mode 100644 src/mlpack/bindings/matlab/pca/pca.m delete mode 100644 src/mlpack/bindings/matlab/range_search/CMakeLists.txt delete mode 100644 src/mlpack/bindings/matlab/range_search/range_search.cpp delete mode 100644 src/mlpack/bindings/matlab/range_search/range_search.m diff --git a/src/mlpack/bindings/cli/add_to_po.hpp b/src/mlpack/bindings/cli/add_to_po.hpp index 0c3a1d789b..a8bea29fa1 100644 --- a/src/mlpack/bindings/cli/add_to_po.hpp +++ b/src/mlpack/bindings/cli/add_to_po.hpp @@ -4,6 +4,11 @@ * * Utility functions to add options to boost::program_options based on their * type. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_ADD_TO_PO_HPP #define MLPACK_BINDINGS_CLI_ADD_TO_PO_HPP diff --git a/src/mlpack/bindings/cli/default_param.hpp b/src/mlpack/bindings/cli/default_param.hpp index 74347c9601..b4740dd5cc 100644 --- a/src/mlpack/bindings/cli/default_param.hpp +++ b/src/mlpack/bindings/cli/default_param.hpp @@ -3,6 +3,11 @@ * @author Ryan Curtin * * Return the default value of a parameter, depending on its type. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_DEFAULT_PARAM_HPP #define MLPACK_BINDINGS_CLI_DEFAULT_PARAM_HPP diff --git a/src/mlpack/bindings/cli/default_param_impl.hpp b/src/mlpack/bindings/cli/default_param_impl.hpp index 377b25ff16..8c1740c1f7 100644 --- a/src/mlpack/bindings/cli/default_param_impl.hpp +++ b/src/mlpack/bindings/cli/default_param_impl.hpp @@ -3,6 +3,11 @@ * @author Ryan Curtin * * Return the default value of a parameter, depending on its type. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_DEFAULT_PARAM_IMPL_HPP #define MLPACK_BINDINGS_CLI_DEFAULT_PARAM_IMPL_HPP diff --git a/src/mlpack/bindings/cli/delete_allocated_memory.hpp b/src/mlpack/bindings/cli/delete_allocated_memory.hpp index edc1fcf861..298f05eed5 100644 --- a/src/mlpack/bindings/cli/delete_allocated_memory.hpp +++ b/src/mlpack/bindings/cli/delete_allocated_memory.hpp @@ -3,6 +3,11 @@ * @author Ryan Curtin * * If any memory has been allocated by the parameter, delete it. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_DELETE_ALLOCATED_MEMORY_HPP #define MLPACK_BINDINGS_CLI_DELETE_ALLOCATED_MEMORY_HPP diff --git a/src/mlpack/bindings/cli/end_program.hpp b/src/mlpack/bindings/cli/end_program.hpp index 56a3809ebd..031c49d5fb 100644 --- a/src/mlpack/bindings/cli/end_program.hpp +++ b/src/mlpack/bindings/cli/end_program.hpp @@ -4,6 +4,11 @@ * @author Matthew Amidon * * Terminate the program; handle --verbose option; print output parameters. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_END_PROGRAM_HPP #define MLPACK_BINDINGS_CLI_END_PROGRAM_HPP diff --git a/src/mlpack/bindings/cli/get_allocated_memory.hpp b/src/mlpack/bindings/cli/get_allocated_memory.hpp index 2dda83e212..03980bdb14 100644 --- a/src/mlpack/bindings/cli/get_allocated_memory.hpp +++ b/src/mlpack/bindings/cli/get_allocated_memory.hpp @@ -4,6 +4,11 @@ * * If the parameter has a type that may need to be deleted, return the address * of that object. Otherwise return NULL. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_GET_ALLOCATED_MEMORY_HPP #define MLPACK_BINDINGS_CLI_GET_ALLOCATED_MEMORY_HPP diff --git a/src/mlpack/bindings/cli/get_param.hpp b/src/mlpack/bindings/cli/get_param.hpp index 4ddfe7f72b..1580635f72 100644 --- a/src/mlpack/bindings/cli/get_param.hpp +++ b/src/mlpack/bindings/cli/get_param.hpp @@ -3,6 +3,11 @@ * @author Ryan Curtin * * Use template metaprogramming to get the right type of parameter. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_GET_PARAM_HPP #define MLPACK_BINDINGS_CLI_GET_PARAM_HPP diff --git a/src/mlpack/bindings/cli/get_printable_param.hpp b/src/mlpack/bindings/cli/get_printable_param.hpp index 5688dc2209..7f50742887 100644 --- a/src/mlpack/bindings/cli/get_printable_param.hpp +++ b/src/mlpack/bindings/cli/get_printable_param.hpp @@ -4,6 +4,11 @@ * * Print the parameter to stdout, using template metaprogramming to enforce * different behavior for different parameter types. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_HPP #define MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_HPP diff --git a/src/mlpack/bindings/cli/get_printable_param_impl.hpp b/src/mlpack/bindings/cli/get_printable_param_impl.hpp index 6fb65bc48d..60177ca10c 100644 --- a/src/mlpack/bindings/cli/get_printable_param_impl.hpp +++ b/src/mlpack/bindings/cli/get_printable_param_impl.hpp @@ -3,6 +3,11 @@ * @author Ryan Curtin * * Implementation of parameter printing functions. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_IMPL_HPP #define MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_IMPL_HPP diff --git a/src/mlpack/bindings/cli/get_printable_param_name.hpp b/src/mlpack/bindings/cli/get_printable_param_name.hpp index e323d2378a..cd3f9139e2 100644 --- a/src/mlpack/bindings/cli/get_printable_param_name.hpp +++ b/src/mlpack/bindings/cli/get_printable_param_name.hpp @@ -4,6 +4,11 @@ * * Return the parameter name that the user would specify on the command line, * with different behavior for different parameter types. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_NAME_HPP #define MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_NAME_HPP diff --git a/src/mlpack/bindings/cli/get_printable_param_name_impl.hpp b/src/mlpack/bindings/cli/get_printable_param_name_impl.hpp index ee3ef1049c..ae2467a783 100644 --- a/src/mlpack/bindings/cli/get_printable_param_name_impl.hpp +++ b/src/mlpack/bindings/cli/get_printable_param_name_impl.hpp @@ -4,6 +4,11 @@ * * Return the parameter name that the user would specify on the command line, * with different behavior for different parameter types. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_NAME_IMPL_HPP #define MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_NAME_IMPL_HPP diff --git a/src/mlpack/bindings/cli/get_printable_param_value.hpp b/src/mlpack/bindings/cli/get_printable_param_value.hpp index 0110c0dfdc..04e3849c47 100644 --- a/src/mlpack/bindings/cli/get_printable_param_value.hpp +++ b/src/mlpack/bindings/cli/get_printable_param_value.hpp @@ -4,6 +4,11 @@ * * Given a parameter value, print what the user might actually specify on the * command line. Basically this adds ".csv" to types where data must be loaded. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_VALUE_HPP #define MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_VALUE_HPP diff --git a/src/mlpack/bindings/cli/get_printable_param_value_impl.hpp b/src/mlpack/bindings/cli/get_printable_param_value_impl.hpp index 1b639f1ac4..5a013569fd 100644 --- a/src/mlpack/bindings/cli/get_printable_param_value_impl.hpp +++ b/src/mlpack/bindings/cli/get_printable_param_value_impl.hpp @@ -5,6 +5,11 @@ * Return the parameter value that the user would specify on the command line * depending on the type of the option. Basically this adds ".csv" to types * that need to be loaded. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_VALUE_IMPL_HPP #define MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_VALUE_IMPL_HPP diff --git a/src/mlpack/bindings/cli/get_raw_param.hpp b/src/mlpack/bindings/cli/get_raw_param.hpp index a397ffff54..cbd0b77253 100644 --- a/src/mlpack/bindings/cli/get_raw_param.hpp +++ b/src/mlpack/bindings/cli/get_raw_param.hpp @@ -4,6 +4,11 @@ * * Use template metaprogramming to get the right type of parameter, but without * any processing. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_GET_RAW_PARAM_HPP #define MLPACK_BINDINGS_CLI_GET_RAW_PARAM_HPP diff --git a/src/mlpack/bindings/cli/map_parameter_name.hpp b/src/mlpack/bindings/cli/map_parameter_name.hpp index 2d37d6c384..2d6583974c 100644 --- a/src/mlpack/bindings/cli/map_parameter_name.hpp +++ b/src/mlpack/bindings/cli/map_parameter_name.hpp @@ -4,6 +4,11 @@ * * Map a parameter name to what it seen by boost::program_options using template * metaprogramming. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_MAP_PARAMETER_NAME_HPP #define MLPACK_BINDINGS_CLI_MAP_PARAMETER_NAME_HPP diff --git a/src/mlpack/bindings/cli/output_param.hpp b/src/mlpack/bindings/cli/output_param.hpp index 4ed052d55f..cc221b4916 100644 --- a/src/mlpack/bindings/cli/output_param.hpp +++ b/src/mlpack/bindings/cli/output_param.hpp @@ -3,6 +3,11 @@ * @author Ryan Curtin * * Output a parameter of different types using template metaprogramming. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_OUTPUT_PARAM_HPP #define MLPACK_BINDINGS_CLI_OUTPUT_PARAM_HPP diff --git a/src/mlpack/bindings/cli/output_param_impl.hpp b/src/mlpack/bindings/cli/output_param_impl.hpp index a85e55a941..c19b6d0aab 100644 --- a/src/mlpack/bindings/cli/output_param_impl.hpp +++ b/src/mlpack/bindings/cli/output_param_impl.hpp @@ -3,6 +3,11 @@ * @author Ryan Curtin * * Implementations of functions to output parameters of different types. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_CORE_UTIL_OUTPUT_PARAM_IMPL_HPP #define MLPACK_CORE_UTIL_OUTPUT_PARAM_IMPL_HPP diff --git a/src/mlpack/bindings/cli/parameter_type.hpp b/src/mlpack/bindings/cli/parameter_type.hpp index 81568482cf..aecdda41fd 100644 --- a/src/mlpack/bindings/cli/parameter_type.hpp +++ b/src/mlpack/bindings/cli/parameter_type.hpp @@ -4,6 +4,11 @@ * * Template metaprogramming structures to find the type (as seen by * boost::program_options) of a particular option type. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_PARAMETER_TYPE_HPP #define MLPACK_BINDINGS_CLI_PARAMETER_TYPE_HPP diff --git a/src/mlpack/bindings/cli/parse_command_line.hpp b/src/mlpack/bindings/cli/parse_command_line.hpp index b7f7cac0de..db75573d4b 100644 --- a/src/mlpack/bindings/cli/parse_command_line.hpp +++ b/src/mlpack/bindings/cli/parse_command_line.hpp @@ -4,6 +4,11 @@ * @author Matthew Amidon * * Parse the command line options. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_PARSE_COMMAND_LINE_HPP #define MLPACK_BINDINGS_CLI_PARSE_COMMAND_LINE_HPP diff --git a/src/mlpack/bindings/cli/print_doc_functions.hpp b/src/mlpack/bindings/cli/print_doc_functions.hpp index 9cf369b296..cfc024b2ca 100644 --- a/src/mlpack/bindings/cli/print_doc_functions.hpp +++ b/src/mlpack/bindings/cli/print_doc_functions.hpp @@ -5,6 +5,11 @@ * This will generate a string representing what a user should type to invoke a * given option. For the command-line bindings, this will generate strings like * '--param_name=x' or '--param_name'. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_PRINT_DOC_FUNCTIONS_HPP #define MLPACK_BINDINGS_CLI_PRINT_DOC_FUNCTIONS_HPP diff --git a/src/mlpack/bindings/cli/print_doc_functions_impl.hpp b/src/mlpack/bindings/cli/print_doc_functions_impl.hpp index 83c7e5b40d..0f37e7d5e6 100644 --- a/src/mlpack/bindings/cli/print_doc_functions_impl.hpp +++ b/src/mlpack/bindings/cli/print_doc_functions_impl.hpp @@ -5,6 +5,11 @@ * This will generate a string representing what a user should type to invoke a * given option. For the command-line bindings, this will generate strings like * '--param_name=x' or '--param_name'. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_PRINT_DOC_FUNCTIONS_IMPL_HPP #define MLPACK_BINDINGS_CLI_PRINT_DOC_FUNCTIONS_IMPL_HPP diff --git a/src/mlpack/bindings/cli/print_help.cpp b/src/mlpack/bindings/cli/print_help.cpp index 40085966df..c6ef6c90d8 100644 --- a/src/mlpack/bindings/cli/print_help.cpp +++ b/src/mlpack/bindings/cli/print_help.cpp @@ -4,6 +4,11 @@ * @author Ryan Curtin * * Print help for a given function. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #include "print_help.hpp" diff --git a/src/mlpack/bindings/cli/print_help.hpp b/src/mlpack/bindings/cli/print_help.hpp index f5b95e9f31..e2c1d7db55 100644 --- a/src/mlpack/bindings/cli/print_help.hpp +++ b/src/mlpack/bindings/cli/print_help.hpp @@ -3,6 +3,11 @@ * @author Ryan Curtin * * Print help for a command-line program. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_PRINT_HELP_HPP #define MLPACK_BINDINGS_CLI_PRINT_HELP_HPP diff --git a/src/mlpack/bindings/cli/set_param.hpp b/src/mlpack/bindings/cli/set_param.hpp index 64103135c5..8370a62b5e 100644 --- a/src/mlpack/bindings/cli/set_param.hpp +++ b/src/mlpack/bindings/cli/set_param.hpp @@ -3,6 +3,11 @@ * @author Ryan Curtin * * Use template metaprogramming to get the right type of parameter. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_SET_PARAM_HPP #define MLPACK_BINDINGS_CLI_SET_PARAM_HPP diff --git a/src/mlpack/bindings/cli/string_type_param.hpp b/src/mlpack/bindings/cli/string_type_param.hpp index 7110de4e2c..28caa8991e 100644 --- a/src/mlpack/bindings/cli/string_type_param.hpp +++ b/src/mlpack/bindings/cli/string_type_param.hpp @@ -4,6 +4,11 @@ * * Given a util::ParamData object, return a string containing the type of the input * parameter as given on the command-line. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_STRING_TYPE_PARAM_HPP #define MLPACK_BINDINGS_CLI_STRING_TYPE_PARAM_HPP diff --git a/src/mlpack/bindings/cli/string_type_param_impl.hpp b/src/mlpack/bindings/cli/string_type_param_impl.hpp index 76ef532a32..01065086ea 100644 --- a/src/mlpack/bindings/cli/string_type_param_impl.hpp +++ b/src/mlpack/bindings/cli/string_type_param_impl.hpp @@ -3,6 +3,11 @@ * @author Ryan Curtin * * Implementations of StringTypeParam(). + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_BINDINGS_CLI_STRING_TYPE_PARAM_IMPL_HPP #define MLPACK_BINDINGS_CLI_STRING_TYPE_PARAM_IMPL_HPP diff --git a/src/mlpack/bindings/matlab/CMakeLists.txt b/src/mlpack/bindings/matlab/CMakeLists.txt deleted file mode 100644 index 24ddbdec38..0000000000 --- a/src/mlpack/bindings/matlab/CMakeLists.txt +++ /dev/null @@ -1,154 +0,0 @@ -# Build rules for the MATLAB bindings for MLPACK. These may not work well on -# non-Linux systems. - -# We need the mex compiler for this to work. -find_package(MatlabMex REQUIRED) - -# If the mex compiler is wrapping an "unsupported" version, warn the user that -# they may have issues with the produced bindings for a multitude of reasons. -# We can only reasonably check this on a UNIX-like system. -if(UNIX) - # The file test.cpp does not exist, but mex will still print a warning if it's - # using a weird version. - execute_process(COMMAND "${MATLAB_MEX}" test.cpp - RESULT_VARIABLE MEX_RESULT_TRASH - OUTPUT_VARIABLE MEX_OUTPUT - ERROR_VARIABLE MEX_ERROR_TRASH) - - string(REGEX MATCH "Warning: You are using" MEX_WARNING "${MEX_OUTPUT}") - - if(MEX_WARNING) - # We have to find the old compiler version and the new compiler version; if - # the MATLAB version is newer, then we don't need to worry. If this step - # fails somehow, we will just issue the warning anyway (just in case). - string(REGEX REPLACE - ".*using [a-zA-Z]* version \"([0-9.]*)[^\"]*\".*" - "\\1" OTHER_COMPILER_VERSION "${MEX_OUTPUT}") - string(REGEX REPLACE - ".*currently supported with MEX is \"([0-9.]*)[^\"]*\".*" - "\\1" MEX_COMPILER_VERSION "${MEX_OUTPUT}") - - # If MEX_COMPILER_VERSION is greater than OTHER_COMPILER_VERSION, we don't - # need to issue a warning. - set(NEED_TO_WARN 1) - if(MEX_COMPILER_VERSION AND OTHER_COMPILER_VERSION) - # We seem to have read two valid version strings. So we can compare - # them, and maybe we don't need to issue the warning. - if(NOT ("${MEX_COMPILER_VERSION}" VERSION_LESS - "${OTHER_COMPILER_VERSION}")) - # The mex compiler is newer than our version. So no warning is - # needed. - set(NEED_TO_WARN 0) - endif(NOT ("${MEX_COMPILER_VERSION}" VERSION_LESS - "${OTHER_COMPILER_VERSION}")) - endif() - - if(NEED_TO_WARN EQUAL 1) - message(WARNING "The MATLAB runtime glibc is different than the system " - " glibc. This can (and probably will) cause the MLPACK bindings " - "generated by this build script to fail with odd GLIBCXX_a_b_c " - "version complaints when they are run. Assuming that the system " - "glibc is newer than the MATLAB-provided version, the MATLAB version " - "can probably be deleted (always save a copy in case this is wrong!)." - "\nFor more information on this confusing issue, see\n" - "http://dovgalecs.com/blog/matlab-glibcxx_3-4-11-not-found/\nand for " - "an overly-detailed dissertation/rant on why it is not possible to " - "work around this issue in any way, see\n" - "http://www.mlpack.org/trac/ticket/253 for more information.") - endif() - endif() -endif() - -# Ignore the fact that we are setting CMAKE_SHARED_LIBRARY_CXX_FLAGS on CMake -# 2.8.9 and newer. Because we are requiring at least CMake 2.8.5, we only have -# to check the patch version. -if(${CMAKE_PATCH_VERSION} GREATER 8) - cmake_policy(SET CMP0018 OLD) -endif() - -# Use the mex compiler to compile. -set(CMAKE_CXX_COMPILER "${MATLAB_MEX}") - -# Set flags for the mex compiler, because a lot of the default CMake flags -# aren't accepted by mex. The user who wants to customize these things should -# probably modify their mexopts.sh so that mex uses those flags by default. -# There is no easy way to tell mex to compile with profiling symbols, so that is -# not done even if PROFILE is set. -if(DEBUG) - set(CMAKE_CXX_FLAGS "-g") - set(CMAKE_C_FLAGS "-g") -else() - set(CMAKE_CXX_FLAGS "-O") - set(CMAKE_C_FLAGS "-O") -endif() - -# Don't give -fPIC; mex will do that for us. -set(CMAKE_SHARED_LIBRARY_C_FLAGS "") -set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") - -# Don't make 'lib.mexglx'. -set(CMAKE_SHARED_LIBRARY_PREFIX "") -set(CMAKE_SHARED_MODULE_PREFIX "") - -# Set custom commands for mex compilation, because the flags are (in general) -# odd and different. -set(CMAKE_CXX_COMPILE_OBJECT " -outdir -c ") -set(CMAKE_CXX_CREATE_SHARED_MODULE " -cxx -output ") -set(CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_MODULE}") - -# mex is weird because it doesn't respect the -o option, but in general it -# appears to turn .cpp into .o, so CMake needs to know to -# replace the extension. -set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1) - -if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") - set(CMAKE_SHARED_LIBRARY_SUFFIX ".mexa64") - set(CMAKE_SHARED_MODULE_SUFFIX ".mexa64") -elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86" OR ${CMAKE_SYSTEM_PROCESSOR} - STREQUAL "i686") - set(CMAKE_SHARED_LIBRARY_SUFFIX ".mexglx") - set(CMAKE_SHARED_MODULE_SUFFIX ".mexglx") -endif() - -# Place MATLAB bindings in matlab/. -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/matlab/) - -include_directories(${CMAKE_SOURCE_DIR}/src/) # So we can include . - -# Set MATLAB toolbox install directory. -set(MATLAB_TOOLBOX_DIR "${MATLAB_ROOT}/toolbox") - -# CHANGE HERE FOR NEW BINDINGS!!!! -add_subdirectory(allkfn) -add_subdirectory(allknn) -add_subdirectory(emst) -add_subdirectory(kmeans) -add_subdirectory(range_search) -add_subdirectory(gmm) -add_subdirectory(pca) -add_subdirectory(kernel_pca) -add_subdirectory(lars) -add_subdirectory(nca) -add_subdirectory(nmf) - -# Create a target whose sole purpose is to modify the pathdef.m MATLAB file so -# that the MLPACK toolbox is added to the MATLAB default path. -add_custom_target(matlab ALL - # Modify pathdef.m. - COMMAND ${CMAKE_COMMAND} -D MATLAB_ROOT="${MATLAB_ROOT}" -D - PATHDEF_OUTPUT_FILE="${CMAKE_BINARY_DIR}/matlab/pathdef.m" -P - ${CMAKE_SOURCE_DIR}/CMake/ModifyMatlabPathdef.cmake - # Due to the dependencies, 'make matlab' makes all the bindings. - DEPENDS - allknn_mex - allkfn_mex - emst_mex - gmm_mex - kmeans_mex - range_search_mex -) - -install(FILES "${CMAKE_BINARY_DIR}/matlab/pathdef.m" - DESTINATION "${MATLAB_ROOT}/toolbox/local/" -) - diff --git a/src/mlpack/bindings/matlab/allkfn/CMakeLists.txt b/src/mlpack/bindings/matlab/allkfn/CMakeLists.txt deleted file mode 100644 index 42152b549f..0000000000 --- a/src/mlpack/bindings/matlab/allkfn/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# Simple rules for building mex file. The _mex suffix is necessary to avoid -# target name conflicts, and the mex file must have a different name than the .m -# file. -add_library(allkfn_mex SHARED - allkfn.cpp -) -target_link_libraries(allkfn_mex - mlpack - ${LIBXML2_LIBRARIES} -) - -# Installation rule. Install both the mex and the MATLAB file. -install(TARGETS allkfn_mex - LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/" -) -install(FILES - allkfn.m - DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/" -) diff --git a/src/mlpack/bindings/matlab/allkfn/allkfn.cpp b/src/mlpack/bindings/matlab/allkfn/allkfn.cpp deleted file mode 100644 index 1924d9122b..0000000000 --- a/src/mlpack/bindings/matlab/allkfn/allkfn.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/** - * @file allkfn.cpp - * @author Patrick Mason - * - * MEX function for MATLAB All-kFN binding. - */ -#include "mex.h" - -#include -#include - -using namespace std; -using namespace mlpack; -using namespace mlpack::neighbor; -using namespace mlpack::tree; - -void mexFunction(int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[]) -{ - // Check the inputs. - if (nrhs != 6) - { - mexErrMsgTxt("Expecting seven arguments."); - } - - if (nlhs != 2) - { - mexErrMsgTxt("Two outputs required."); - } - - size_t numPoints = mxGetN(prhs[0]); - size_t numDimensions = mxGetM(prhs[0]); - - // Create the reference matrix. - arma::mat referenceData(numDimensions, numPoints); - // setting the values. - double * mexDataPoints = mxGetPr(prhs[0]); - for (int i = 0, n = numPoints * numDimensions; i < n; ++i) - { - referenceData(i) = mexDataPoints[i]; - } - - // getting the leafsize - int lsInt = (int) mxGetScalar(prhs[3]); - - // getting k - size_t k = (int) mxGetScalar(prhs[1]); - - // naive algorithm? - bool naive = (mxGetScalar(prhs[4]) == 1.0); - - // single mode? - bool singleMode = (mxGetScalar(prhs[5]) == 1.0); - - // the query matrix - double * mexQueryPoints = mxGetPr(prhs[2]); - arma::mat queryData; - bool hasQueryData = ((mxGetM(prhs[2]) != 0) && (mxGetN(prhs[2]) != 0)); - - // Sanity check on k value: must be greater than 0, must be less than the - // number of reference points. - if (k > referenceData.n_cols) - { - stringstream os; - os << "Invalid k: " << k << "; must be greater than 0 and less "; - os << "than or equal to the number of reference points ("; - os << referenceData.n_cols << ")." << endl; - mexErrMsgTxt(os.str().c_str()); - } - - // Sanity check on leaf size. - if (lsInt < 0) - { - stringstream os; - os << "Invalid leaf size: " << lsInt << ". Must be greater "; - os << "than or equal to 0." << endl; - mexErrMsgTxt(os.str().c_str()); - } - size_t leafSize = lsInt; - - // Naive mode overrides single mode. - if (singleMode && naive) - { - mexWarnMsgTxt("single_mode ignored because naive is present."); - } - - if (naive) - leafSize = referenceData.n_cols; - - arma::Mat neighbors; - arma::mat distances; - - AllkFN* allkfn = NULL; - - std::vector oldFromNewRefs; - - // Build trees by hand, so we can save memory: if we pass a tree to - // NeighborSearch, it does not copy the matrix. - BinarySpaceTree, QueryStat > - refTree(referenceData, oldFromNewRefs, leafSize); - BinarySpaceTree, QueryStat >* - queryTree = NULL; // Empty for now. - - std::vector oldFromNewQueries; - - if (hasQueryData) - { - // setting the values. - mexDataPoints = mxGetPr(prhs[2]); - numPoints = mxGetN(prhs[2]); - numDimensions = mxGetM(prhs[2]); - queryData = arma::mat(numDimensions, numPoints); - for (int i = 0, n = numPoints * numDimensions; i < n; ++i) - { - queryData(i) = mexDataPoints[i]; - } - - if (naive && leafSize < queryData.n_cols) - leafSize = queryData.n_cols; - - // Build trees by hand, so we can save memory: if we pass a tree to - // NeighborSearch, it does not copy the matrix. - queryTree = new BinarySpaceTree, - QueryStat >(queryData, oldFromNewQueries, - leafSize); - - allkfn = new AllkFN(&refTree, queryTree, referenceData, queryData, - singleMode); - } - else - { - allkfn = new AllkFN(&refTree, referenceData, singleMode); - } - - allkfn->Search(k, neighbors, distances); - - // We have to map back to the original indices from before the tree - // construction. - arma::mat distancesOut(distances.n_rows, distances.n_cols); - arma::Mat neighborsOut(neighbors.n_rows, neighbors.n_cols); - - // Do the actual remapping. - if (hasQueryData) - { - for (size_t i = 0; i < distances.n_cols; ++i) - { - // Map distances (copy a column). - distancesOut.col(oldFromNewQueries[i]) = distances.col(i); - - // Map indices of neighbors. - for (size_t j = 0; j < distances.n_rows; ++j) - { - neighborsOut(j, oldFromNewQueries[i]) = oldFromNewRefs[neighbors(j, i)]; - } - } - } - else - { - for (size_t i = 0; i < distances.n_cols; ++i) - { - // Map distances (copy a column). - distancesOut.col(oldFromNewRefs[i]) = distances.col(i); - - // Map indices of neighbors. - for (size_t j = 0; j < distances.n_rows; ++j) - { - neighborsOut(j, oldFromNewRefs[i]) = oldFromNewRefs[neighbors(j, i)]; - } - } - } - - // Clean up. - if (queryTree) - delete queryTree; - - // constructing matrix to return to matlab - plhs[0] = mxCreateDoubleMatrix(distances.n_rows, distances.n_cols, mxREAL); - plhs[1] = mxCreateDoubleMatrix(neighbors.n_rows, neighbors.n_cols, mxREAL); - - // setting the values - double * out = mxGetPr(plhs[0]); - for (int i = 0, n = distances.n_rows * distances.n_cols; i < n; ++i) - { - out[i] = distances(i); - } - out = mxGetPr(plhs[1]); - for (int i = 0, n = neighbors.n_rows * neighbors.n_cols; i < n; ++i) - { - out[i] = neighbors(i); - } - - // More clean up. - delete allkfn; -} diff --git a/src/mlpack/bindings/matlab/allkfn/allkfn.m b/src/mlpack/bindings/matlab/allkfn/allkfn.m deleted file mode 100644 index b1cd5ba5ac..0000000000 --- a/src/mlpack/bindings/matlab/allkfn/allkfn.m +++ /dev/null @@ -1,58 +0,0 @@ -function [distances, neighbors] = allkfn(dataPoints, k, varargin) -% [distances, neighbors] = allkfn(dataPoints, k, varargin) -% -% Calculate the all k-furthest-neighbors of a set of points. You may specify a -% separate set of reference points and query points, or just a reference set -% which will be used as both the reference and query set. -% -% The output matrices are organized such that row i and column j in the -% neighbors matrix corresponds to the index of the point in the reference set -% which is the i'th furthest neighbor from the point in the query set with index -% j. Row i and column j in the distances output matrix corresponds to the -% distance between those two points. -% -% Parameters: -% -% dataPoints - The reference set of data points. Columns are assumed to -% represent dimensions, with rows representing separate points. -% k - The number of furthest neighbors to find. -% -% Optional parameters (i.e. allkfn(..., 'parameter', value, ...)): -% -% 'queryPoints' - An optional set of query points, if the reference and query -% sets are different. Columns are assumed to represent -% dimensions, with rows representing separate points. -% 'leafSize' - Leaf size in the kd-tree. Defaults to 20. -% 'method' - Algorithm to use. 'naive' uses naive O(n^2) computation; -% 'single' uses single-tree traversal; 'dual' uses the standard -% dual-tree traversal. Defaults to 'dual'. -% -% Examples: -% -% [distances, neighbors] = allkfn(dataPoints, 5); -% [distances, neighbors] = allkfn(dataPoints, 5, 'method', 'single'); -% [distances, neighbors] = allkfn(dataPoints, 5, 'queryPoints', queryPoints); - -% A parser for the inputs. -p = inputParser; -p.addParamValue('queryPoints', zeros(0), @ismatrix); -p.addParamValue('leafSize', 20, @isscalar); -p.addParamValue('naive', false, @(x) (x == true) || (x == false)); -p.addParamValue('singleMode', false, @(x) (x == true) || (x == false)); - -% parsing the varargin options -varargin{:} -p.parse(varargin{:}); -parsed = p.Results; -parsed - -% interfacing with mlpack -[distances neighbors] = mex_allkfn(dataPoints', k, parsed.queryPoints', ... - parsed.leafSize, parsed.naive, parsed.singleMode); - -% transposing results -distances = distances'; -neighbors = neighbors' + 1; % matlab indices began at 1, not zero - -return; - diff --git a/src/mlpack/bindings/matlab/allknn/CMakeLists.txt b/src/mlpack/bindings/matlab/allknn/CMakeLists.txt deleted file mode 100644 index f7df5b88b4..0000000000 --- a/src/mlpack/bindings/matlab/allknn/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# Simple rules for building mex file. The _mex suffix is necessary to avoid -# target name conflicts, and the mex file must have a different name than the .m -# file. -add_library(allknn_mex SHARED - allknn.cpp -) -target_link_libraries(allknn_mex - mlpack - ${LIBXML2_LIBRARIES} -) - -# Installation rule. Install both the mex and the MATLAB file. -install(TARGETS allknn_mex - LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/" -) -install(FILES - allknn.m - DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/" -) diff --git a/src/mlpack/bindings/matlab/allknn/allknn.cpp b/src/mlpack/bindings/matlab/allknn/allknn.cpp deleted file mode 100644 index a13b114071..0000000000 --- a/src/mlpack/bindings/matlab/allknn/allknn.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/** - * @file allknn.cpp - * @author Patrick Mason - * - * MEX function for MATLAB All-kNN binding. - */ -#include "mex.h" - -#include -#include -#include - -using namespace std; -using namespace mlpack; -using namespace mlpack::neighbor; -using namespace mlpack::tree; - -// the gateway, required by all mex functions -void mexFunction(int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[]) -{ - // checking inputs - if (nrhs != 7) - { - mexErrMsgTxt("Expecting seven arguments."); - } - - if (nlhs != 2) - { - mexErrMsgTxt("Two outputs required."); - } - - // getting the dimensions of the reference matrix - size_t numPoints = mxGetN(prhs[0]); - size_t numDimensions = mxGetM(prhs[0]); - - // feeding the referenceData matrix - arma::mat referenceData(numDimensions, numPoints); - // setting the values. - double * mexDataPoints = mxGetPr(prhs[0]); - for (int i = 0, n = numPoints * numDimensions; i < n; ++i) - { - referenceData(i) = mexDataPoints[i]; - } - - // getting the leafsize - int lsInt = (int) mxGetScalar(prhs[3]); - - // getting k - size_t k = (int) mxGetScalar(prhs[1]); - - // naive algorithm? - bool naive = (mxGetScalar(prhs[4]) == 1.0); - - // single mode? - bool singleMode = (mxGetScalar(prhs[5]) == 1.0); - - // the query matrix - double * mexQueryPoints = mxGetPr(prhs[2]); - arma::mat queryData; - bool hasQueryData = ((mxGetM(prhs[2]) != 0) && (mxGetN(prhs[2]) != 0)); - - // cover-tree? - bool usesCoverTree = (mxGetScalar(prhs[6]) == 1.0); - - // Sanity check on k value: must be greater than 0, must be less than the - // number of reference points. - if (k > referenceData.n_cols) - { - stringstream os; - os << "Invalid k: " << k << "; must be greater than 0 and less "; - os << "than or equal to the number of reference points ("; - os << referenceData.n_cols << ")." << endl; - mexErrMsgTxt(os.str().c_str()); - } - - // Sanity check on leaf size. - if (lsInt < 0) - { - stringstream os; - os << "Invalid leaf size: " << lsInt << ". Must be greater " - "than or equal to 0." << endl; - mexErrMsgTxt(os.str().c_str()); - } - size_t leafSize = lsInt; - - // Naive mode overrides single mode. - if (singleMode && naive) - { - mexWarnMsgTxt("single_mode ignored because naive is present."); - } - - if (naive) - leafSize = referenceData.n_cols; - - arma::Mat neighbors; - arma::mat distances; - - //if (!CLI::HasParam("cover_tree")) - if (usesCoverTree) - { - // Because we may construct it differently, we need a pointer. - AllkNN* allknn = NULL; - - // Mappings for when we build the tree. - std::vector oldFromNewRefs; - - // Build trees by hand, so we can save memory: if we pass a tree to - // NeighborSearch, it does not copy the matrix. - - BinarySpaceTree, QueryStat > - refTree(referenceData, oldFromNewRefs, leafSize); - BinarySpaceTree, QueryStat >* - queryTree = NULL; // Empty for now. - - std::vector oldFromNewQueries; - - if (hasQueryData) - { - // setting the values. - mexDataPoints = mxGetPr(prhs[2]); - numPoints = mxGetN(prhs[2]); - numDimensions = mxGetM(prhs[2]); - queryData = arma::mat(numDimensions, numPoints); - for (int i = 0, n = numPoints * numDimensions; i < n; ++i) - { - queryData(i) = mexDataPoints[i]; - } - - if (naive && leafSize < queryData.n_cols) - leafSize = queryData.n_cols; - - // Build trees by hand, so we can save memory: if we pass a tree to - // NeighborSearch, it does not copy the matrix. - if (!singleMode) - { - queryTree = new BinarySpaceTree, - QueryStat >(queryData, oldFromNewQueries, - leafSize); - } - - allknn = new AllkNN(&refTree, queryTree, referenceData, queryData, - singleMode); - } - else - { - allknn = new AllkNN(&refTree, referenceData, singleMode); - } - - arma::mat distancesOut; - arma::Mat neighborsOut; - - allknn->Search(k, neighborsOut, distancesOut); - - // We have to map back to the original indices from before the tree - // construction. - neighbors.set_size(neighborsOut.n_rows, neighborsOut.n_cols); - distances.set_size(distancesOut.n_rows, distancesOut.n_cols); - - // Do the actual remapping. - if ((hasQueryData) && !singleMode) - { - for (size_t i = 0; i < distancesOut.n_cols; ++i) - { - // Map distances (copy a column) and square root. - distances.col(oldFromNewQueries[i]) = sqrt(distancesOut.col(i)); - - // Map indices of neighbors. - for (size_t j = 0; j < distancesOut.n_rows; ++j) - { - neighbors(j, oldFromNewQueries[i]) = - oldFromNewRefs[neighborsOut(j, i)]; - } - } - } - else if ((hasQueryData) && singleMode) - { - // No remapping of queries is necessary. So distances are the same. - distances = sqrt(distancesOut); - - // The neighbor indices must be mapped. - for (size_t j = 0; j < neighborsOut.n_elem; ++j) - { - neighbors[j] = oldFromNewRefs[neighborsOut[j]]; - } - } - else - { - for (size_t i = 0; i < distancesOut.n_cols; ++i) - { - // Map distances (copy a column). - distances.col(oldFromNewRefs[i]) = sqrt(distancesOut.col(i)); - - // Map indices of neighbors. - for (size_t j = 0; j < distancesOut.n_rows; ++j) - { - neighbors(j, oldFromNewRefs[i]) = oldFromNewRefs[neighborsOut(j, i)]; - } - } - } - - // Clean up. - if (queryTree) - delete queryTree; - - delete allknn; - } - else // Cover trees. - { - // Build our reference tree. - CoverTree, tree::FirstPointIsRoot, - QueryStat > referenceTree(referenceData, 1.3); - CoverTree, tree::FirstPointIsRoot, - QueryStat >* queryTree = NULL; - - NeighborSearch, - CoverTree, tree::FirstPointIsRoot, - QueryStat > >* allknn = NULL; - - // See if we have query data. - if (hasQueryData) - { - // setting the values. - mexDataPoints = mxGetPr(prhs[2]); - numPoints = mxGetN(prhs[2]); - numDimensions = mxGetM(prhs[2]); - queryData = arma::mat(numDimensions, numPoints); - for (int i = 0, n = numPoints * numDimensions; i < n; ++i) - { - queryData(i) = mexDataPoints[i]; - } - - // Build query tree. - if (!singleMode) - { - queryTree = new CoverTree, - tree::FirstPointIsRoot, QueryStat >(queryData, - 1.3); - } - - allknn = new NeighborSearch, - CoverTree, tree::FirstPointIsRoot, - QueryStat > >(&referenceTree, queryTree, - referenceData, queryData, singleMode); - } - else - { - allknn = new NeighborSearch, - CoverTree, tree::FirstPointIsRoot, - QueryStat > >(&referenceTree, referenceData, - singleMode); - } - - allknn->Search(k, neighbors, distances); - - delete allknn; - - if (queryTree) - delete queryTree; - } - - // writing back to matlab - // constructing matrix to return to matlab - plhs[0] = mxCreateDoubleMatrix(distances.n_rows, distances.n_cols, mxREAL); - plhs[1] = mxCreateDoubleMatrix(neighbors.n_rows, neighbors.n_cols, mxREAL); - - // setting the values - double * out = mxGetPr(plhs[0]); - for (int i = 0, n = distances.n_rows * distances.n_cols; i < n; ++i) - { - out[i] = distances(i); - } - out = mxGetPr(plhs[1]); - for (int i = 0, n = neighbors.n_rows * neighbors.n_cols; i < n; ++i) - { - out[i] = neighbors(i); - } - -} diff --git a/src/mlpack/bindings/matlab/allknn/allknn.m b/src/mlpack/bindings/matlab/allknn/allknn.m deleted file mode 100644 index e79660210d..0000000000 --- a/src/mlpack/bindings/matlab/allknn/allknn.m +++ /dev/null @@ -1,60 +0,0 @@ -function [distances neighbors] = allknn(dataPoints, k, varargin) -%All K-Nearest-Neighbors -% -% This program will calculate the all k-nearest-neighbors of a set of points -% using kd-trees or cover trees (cover tree support is experimental and may not -% be optimally fast). You may specify a separate set of reference points and -% query points, or just a reference set which will be used as both the reference -% and query set. -% -% For example, the following will calculate the 5 nearest neighbors of eachpoint -% in 'input.csv' and store the distances in 'distances.csv' and the neighbors in -% the file 'neighbors.csv': - -% $ allknn --k=5 --reference_file=input.csv --distances_file=distances.csv -% --neighbors_file=neighbors.csv - -% The output files are organized such that row i and column j in the neighbors -% output file corresponds to the index of the point in the reference set which -% is the i'th nearest neighbor from the point in the query set with index j. -% Row i and column j in the distances output file corresponds to the distance -% between those two points. -% -% Parameters: -% dataPoints - the matrix of data points. Columns are assumed to represent dimensions, -% with rows representing seperate points. -% method - the algorithm for computing the tree. 'naive' or 'boruvka', with -% 'boruvka' being the default algorithm. -% leafSize - Leaf size in the kd-tree. One-element leaves give the -% empirically best performance, but at the cost of greater memory -% requirements. One is default. -% -% Examples: -% result = emst(dataPoints); -% or -% esult = emst(dataPoints,'method','naive'); - -% a parser for the inputs -p = inputParser; -p.addParamValue('queryPoints', zeros(0), @ismatrix); -p.addParamValue('leafSize', 20, @isscalar); -p.addParamValue('naive', false, @(x) (x == true) || (x == false)); -p.addParamValue('singleMode', false, @(x) (x == true) || (x == false)); -p.addParamValue('coverTree', false, @(x) (x == true) || (x == false)); - -% parsing the varargin options -varargin{:} -p.parse(varargin{:}); -parsed = p.Results; -parsed - -% interfacing with mlpack -[distances neighbors] = mex_allknn(dataPoints', k, parsed.queryPoints', ... - parsed.leafSize, parsed.naive, parsed.singleMode, parsed.coverTree); - -% transposing results -distances = distances'; -neighbors = neighbors' + 1; % matlab indices began at 1, not zero - -return; - diff --git a/src/mlpack/bindings/matlab/emst/CMakeLists.txt b/src/mlpack/bindings/matlab/emst/CMakeLists.txt deleted file mode 100644 index 3b79cdfaa4..0000000000 --- a/src/mlpack/bindings/matlab/emst/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# Simple rules for building mex file. The _mex suffix is necessary to avoid -# target name conflicts, and the mex file must have a different name than the .m -# file. -add_library(emst_mex SHARED - emst.cpp -) -target_link_libraries(emst_mex - mlpack - ${LIBXML2_LIBRARIES} -) - -# Installation rule. Install both the mex and the MATLAB file. -install(TARGETS emst_mex - LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/" -) -install(FILES - emst.m - DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/" -) diff --git a/src/mlpack/bindings/matlab/emst/emst.cpp b/src/mlpack/bindings/matlab/emst/emst.cpp deleted file mode 100644 index 24e6c8a02c..0000000000 --- a/src/mlpack/bindings/matlab/emst/emst.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/** - * @file emst.cpp - * @author Patrick Mason - * - * MEX function for MATLAB EMST binding. - */ -#include "mex.h" - -#include -#include - -#include - -using namespace mlpack; -using namespace mlpack::emst; -using namespace mlpack::tree; - -// The gateway, required by all mex functions. -void mexFunction(int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[]) -{ - // Argument checks. - if (nrhs != 3) - { - mexErrMsgTxt("Expecting an datapoints matrix, isBoruvka, and leafSize."); - } - - if (nlhs != 1) - { - mexErrMsgTxt("Output required."); - } - - const size_t numPoints = mxGetN(prhs[0]); - const size_t numDimensions = mxGetM(prhs[0]); - - // Converting from mxArray to armadillo matrix. - arma::mat dataPoints(numDimensions, numPoints); - - // Set the values. - double* mexDataPoints = mxGetPr(prhs[0]); - for (int i = 0, n = numPoints * numDimensions; i < n; ++i) - { - dataPoints(i) = mexDataPoints[i]; - } - - const bool isBoruvka = (mxGetScalar(prhs[1]) == 1.0); - - // Run the computation. - arma::mat result; - if (isBoruvka) - { - // Get the number of leaves. - const size_t leafSize = (size_t) mxGetScalar(prhs[2]); - - DualTreeBoruvka<> dtb(dataPoints, false, leafSize); - dtb.ComputeMST(result); - } - else - { - DualTreeBoruvka<> naive(dataPoints, true); - naive.ComputeMST(result); - } - - // Construct matrix to return to MATLAB. - plhs[0] = mxCreateDoubleMatrix(3, numPoints - 1, mxREAL); - - double* out = mxGetPr(plhs[0]); - for (int i = 0, n = (numPoints - 1) * 3; i < n; ++i) - { - out[i] = result(i); - } -} diff --git a/src/mlpack/bindings/matlab/emst/emst.m b/src/mlpack/bindings/matlab/emst/emst.m deleted file mode 100644 index ce84fa7416..0000000000 --- a/src/mlpack/bindings/matlab/emst/emst.m +++ /dev/null @@ -1,52 +0,0 @@ -function result = emst(dataPoints, varargin) -% result = emst(dataPoints, varargin) -% -% Compute the Euclidean minimum spanning tree of a set of input points using the -% dual-tree Boruvka algorithm. -% -% The output is saved in a three-column matrix, where each row indicates an -% edge. The first column corresponds to the lesser index of the edge; the -% second column corresponds to the greater index of the edge; and the third -% column corresponds to the distance between the two points. -% -% Required parameters: -% -% dataPoints - The matrix of data points. Columns are assumed to represent -% dimensions, with rows representing separate points. -% -% Optional parameters (i.e. emst(..., 'parameter', value, ...)): -% -% 'method' - The algorithm for computing the tree. 'naive' or 'boruvka', with -% 'boruvka' being the default dual-tree Boruvka algorithm. -% 'leafSize' - Leaf size in the kd-tree. One-element leaves give the -% empirically best performance, but at the cost of greater memory -% requirements. Defaults to 1. -% -% Examples: -% -% result = emst(dataPoints); -% result = emst(dataPoints, 'method', 'naive'); -% result = emst(dataPoints, 'method', 'naive', 'leafSize', 5); - -% A parser for the inputs. -p = inputParser; -p.addParamValue('method', 'boruvka', ... - @(x) strcmpi(x, 'naive') || strcmpi(x, 'boruvka')); -p.addParamValue('leafSize', 1, @isscalar); - -% Parse the varargin options. -p.parse(varargin{:}); -parsed = p.Results; - -% Interface with mlpack. Transpose to machine learning standards. MLPACK -% expects column-major matrices; the user has passed in a row-major matrix. -if strcmpi(parsed.method, 'boruvka') - result = emst_mex(dataPoints', 1, parsed.leafSize); - result = result'; - return; -else - result = emst_mex(dataPoints', 0, 1); - result = result'; - return; -end - diff --git a/src/mlpack/bindings/matlab/gmm/CMakeLists.txt b/src/mlpack/bindings/matlab/gmm/CMakeLists.txt deleted file mode 100644 index dacb527dff..0000000000 --- a/src/mlpack/bindings/matlab/gmm/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# Simple rules for building mex file. The _mex suffix is necessary to avoid -# target name conflicts, and the mex file must have a different name than the .m -# file. -add_library(gmm_mex SHARED - gmm.cpp -) -target_link_libraries(gmm_mex - mlpack - ${LIBXML2_LIBRARIES} -) - -# Installation rule. Install both the mex and the MATLAB file. -install(TARGETS gmm_mex - LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/" -) -install(FILES - gmm.m - DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/" -) diff --git a/src/mlpack/bindings/matlab/gmm/gmm.cpp b/src/mlpack/bindings/matlab/gmm/gmm.cpp deleted file mode 100644 index 63a366eca1..0000000000 --- a/src/mlpack/bindings/matlab/gmm/gmm.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/** - * @file gmm.cpp - * @author Patrick Mason - * - * MEX function for MATLAB GMM binding. - */ -#include "mex.h" - -#include -#include - -using namespace mlpack; -using namespace mlpack::gmm; -using namespace mlpack::util; - -void mexFunction(int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[]) -{ - // argument checks - if (nrhs != 3) - { - mexErrMsgTxt("Expecting three inputs."); - } - - if (nlhs != 1) - { - mexErrMsgTxt("Output required."); - } - - size_t seed = (size_t) mxGetScalar(prhs[2]); - // Check parameters and load data. - if (seed != 0) - math::RandomSeed(seed); - else - math::RandomSeed((size_t) std::time(NULL)); - - // loading the data - double * mexDataPoints = mxGetPr(prhs[0]); - size_t numPoints = mxGetN(prhs[0]); - size_t numDimensions = mxGetM(prhs[0]); - arma::mat dataPoints(numDimensions, numPoints); - for (int i = 0, n = numPoints * numDimensions; i < n; ++i) - { - dataPoints(i) = mexDataPoints[i]; - } - - int gaussians = (int) mxGetScalar(prhs[1]); - if (gaussians <= 0) - { - std::stringstream ss; - ss << "Invalid number of Gaussians (" << gaussians << "); must " - "be greater than or equal to 1." << std::endl; - mexErrMsgTxt(ss.str().c_str()); - } - - // Calculate mixture of Gaussians. - GMM<> gmm(size_t(gaussians), dataPoints.n_rows); - - ////// Computing the parameters of the model using the EM algorithm ////// - gmm.Estimate(dataPoints); - - // setting up the matlab structure to be returned - mwSize ndim = 1; - mwSize dims[1] = { - 1 - }; - const char * fieldNames[3] = { - "dimensionality" - , "weights" - , "gaussians" - }; - - plhs[0] = mxCreateStructArray(ndim, dims, 3, fieldNames); - - // dimensionality - mxArray * field_value; - field_value = mxCreateDoubleMatrix(1, 1, mxREAL); - *mxGetPr(field_value) = numDimensions; - mxSetFieldByNumber(plhs[0], 0, 0, field_value); - - // mixture weights - field_value = mxCreateDoubleMatrix(gmm.Weights().size(), 1, mxREAL); - double * values = mxGetPr(field_value); - for (int i=0; i - -#include "hmm.hpp" -#include "hmm_util.hpp" -#include - -/* -PROGRAM_INFO("Hidden Markov Model (HMM) Sequence Generator", "This " - "utility takes an already-trained HMM (--model_file) and generates a " - "random observation sequence and hidden state sequence based on its " - "parameters, saving them to the specified files (--output_file and " - "--state_file)"); - -PARAM_STRING_REQ("model_file", "File containing HMM (XML).", "m"); -PARAM_INT_REQ("length", "Length of sequence to generate.", "l"); - -PARAM_INT("start_state", "Starting state of sequence.", "t", 0); -PARAM_STRING("output_file", "File to save observation sequence to.", "o", - "output.csv"); -PARAM_STRING("state_file", "File to save hidden state sequence to (may be left " - "unspecified.", "S", ""); -PARAM_INT("seed", "Random seed. If 0, 'std::time(NULL)' is used.", "s", 0); -*/ - - -using namespace mlpack; -using namespace mlpack::hmm; -using namespace mlpack::distribution; -using namespace mlpack::utilities; -using namespace mlpack::gmm; -using namespace mlpack::math; -using namespace arma; -using namespace std; - -namespace { - // gets the transition matrix from the struct - void getTransition(mat & transition, const mxArray * mxarray) - { - mxArray * mxTransitions = mxGetField(mxarray, 0, "transition"); - if (NULL == mxTransitions) - { - mexErrMsgTxt("Model struct did not have transition matrix 'transition'."); - } - if (mxDOUBLE_CLASS != mxGetClassID(mxTransitions)) - { - mexErrMsgTxt("Transition matrix 'transition' must have type mxDOUBLE_CLASS."); - } - const size_t m = mxGetM(mxTransitions); - const size_t n = mxGetN(mxTransitions); - transition.resize(m,n); - - double * values = mxGetPr(mxTransitions); - for (int i = 0; i < m*n; ++i) - transition(i) = values[i]; - } - - // writes the matlab transition matrix to the model - template - void writeTransition(HMM & hmm, const mxArray * mxarray) - { - mxArray * mxTransitions = mxGetField(mxarray, 0, "transition"); - if (NULL == mxTransitions) - { - mexErrMsgTxt("Model struct did not have transition matrix 'transition'."); - } - if (mxDOUBLE_CLASS != mxGetClassID(mxTransitions)) - { - mexErrMsgTxt("Transition matrix 'transition' must have type mxDOUBLE_CLASS."); - } - - arma::mat transition(mxGetM(mxTransitions), mxGetN(mxTransitions)); - double * values = mxGetPr(mxTransitions); - for (int i = 0; i < mxGetM(mxTransitions) * mxGetN(mxTransitions); ++i) - transition(i) = values[i]; - - hmm.Transition() = transition; - } - - // argument check on the emission field - void checkEmission(const mat & transition, const mxArray * mxarray) - { - if (NULL == mxarray) - { - mexErrMsgTxt("Model struct did not have 'emission' struct."); - } - if ((int) mxGetN(mxarray) != (int) transition.n_rows) - { - stringstream ss; - ss << "'emissions' struct array must have dimensions 1 x " - << transition.n_rows << "."; - mexErrMsgTxt(ss.str().c_str()); - } - } - -} // closing anonymous namespace - -void mexFunction(int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[]) -{ - // argument checks - if (nrhs != 4) - { - mexErrMsgTxt("Expecting four arguments."); - } - - if (nlhs != 1) - { - mexErrMsgTxt("Output required."); - } - - // seed argument - size_t seed = (size_t) mxGetScalar(prhs[3]); - - // Set random seed. - if (seed != 0) - mlpack::math::RandomSeed(seed); - else - mlpack::math::RandomSeed((size_t) std::time(NULL)); - - // length of observations - const int length = (int) mxGetScalar(prhs[1]); - - // start state - const int startState = (int) mxGetScalar(prhs[2]); - - if (length <= 0) - { - stringstream ss; - ss << "Invalid sequence length (" << length << "); must be greater " - << "than or equal to 0!"; - mexErrMsgTxt(ss.str().c_str()); - } - - // getting the model type - if (mxIsStruct(prhs[0]) == 0) - { - mexErrMsgTxt("Model argument is not a struct."); - } - - mxArray * mxHmmType = mxGetField(prhs[0], 0, "hmm_type"); - if (mxHmmType == NULL) - { - mexErrMsgTxt("Model struct did not have 'hmm_type'."); - } - if (mxCHAR_CLASS != mxGetClassID(mxHmmType)) - { - mexErrMsgTxt("'hmm_type' must have type mxCHAR_CLASS."); - } - - // getting the model type string - int bufLength = mxGetNumberOfElements(mxHmmType) + 1; - char * buf; - buf = (char *) mxCalloc(bufLength, sizeof(char)); - mxGetString(mxHmmType, buf, bufLength); - string type(buf); - mxFree(buf); - - cout << type << endl; - - // to be filled by the generator - mat observations; - Col sequence; - - // to be removed! - SaveRestoreUtility sr; - - if (type == "discrete") - { - HMM hmm(1, DiscreteDistribution(1)); - - // writing transition matrix to the hmm - writeTransition(hmm, prhs[0]); - - // writing emission matrix to the hmm - mxArray * mxEmission = mxGetField(prhs[0], 0, "emission"); - //checkEmission(hmm, mxEmission); - - vector emission(hmm.Transition().n_rows); - for (int i=0; i= (int) hmm.Transition().n_rows) - { - stringstream ss; - ss << "Invalid start state (" << startState << "); must be " - << "between 0 and number of states (" << hmm.Transition().n_rows - << ")!"; - mexErrMsgTxt(ss.str().c_str()); - } - - hmm.Generate(size_t(length), observations, sequence, size_t(startState)); - } - else if (type == "gaussian") - { - /* - //HMM hmm(1, GaussianDistribution(1)); - - // get transition matrix - //mat transition; - //getTransition(transition, prhs[0]); - - //hmm.Transition() = transition; - //cout << transition << endl; - arma::mat transition("0.75 0.25; 0.25 0.75"); - - // get emission - //vector emission(transition.n_rows); - vector emission; - GaussianDistribution g1("5.0 5.0", "1.0 0.0; 0.0 1.0"); - GaussianDistribution g2("-5.0 -5.0", "1.0 0.0; 0.0 1.0"); - emission.push_back(g1); - emission.push_back(g2); - - - //HMM hmm(transition, emission); - //hmm.Emission() = emission; - HMM hmm(transition, emission); - */ - - // Our distribution will have three two-dimensional output Gaussians. - cout << "following the test" << endl; - HMM hmm(3, GaussianDistribution(2)); - hmm.Transition() = arma::mat("0.4 0.6 0.8; 0.2 0.2 0.1; 0.4 0.2 0.1"); - hmm.Emission()[0] = GaussianDistribution("0.0 0.0", "1.0 0.0; 0.0 1.0"); - hmm.Emission()[1] = GaussianDistribution("2.0 2.0", "1.0 0.5; 0.5 1.2"); - hmm.Emission()[2] = GaussianDistribution("-2.0 1.0", "2.0 0.1; 0.1 1.0"); - - // Now we will generate a long sequence. - std::vector observations2(1); - std::vector > states2(1); - - // testing - SaveHMM(hmm, sr); - sr.WriteFile("testMexGaussian.xml"); - - // Start in state 1 (no reason). - cout << "test generation" << endl; - hmm.Generate(10000, observations2[0], states2[0], 1); - cout << "test complete" << endl; - - if (startState < 0 || startState >= (int) hmm.Transition().n_rows) - { - stringstream ss; - ss << "Invalid start state (" << startState << "); must be " - << "between 0 and number of states (" << hmm.Transition().n_rows - << ")!"; - mexErrMsgTxt(ss.str().c_str()); - } - cout << "generating!" << endl; - hmm.Generate(size_t(length), observations, sequence, size_t(startState)); - cout << "done!" << endl; - } - else if (type == "gmm") - { - HMM > hmm(1, GMM<>(1, 1)); - - LoadHMM(hmm, sr); - - if (startState < 0 || startState >= (int) hmm.Transition().n_rows) - { - Log::Fatal << "Invalid start state (" << startState << "); must be " - << "between 0 and number of states (" << hmm.Transition().n_rows - << ")!" << endl; - } - - hmm.Generate(size_t(length), observations, sequence, size_t(startState)); - } - else - { - Log::Fatal << "Unknown HMM type '" << type << "'" << "'!" << endl; - } - - cout << "returning to matlab" << endl; - - // Setting values to be returned to matlab - mwSize ndim = 1; - mwSize dims[1] = {1}; - const char * fieldNames[2] = { - "observations" - , "states" - }; - - plhs[0] = mxCreateStructArray(ndim, dims, 2, fieldNames); - - mxArray * tmp; - double * values; - - cout << observations.n_rows << "," << observations.n_cols << endl; - cout << sequence.n_rows << "," << sequence.n_cols << endl; - cout << observations << endl; - cout << sequence << endl; - - // settings the observations - tmp = mxCreateDoubleMatrix(observations.n_rows, observations.n_cols, mxREAL); - values = mxGetPr(tmp); - for (int i=0; i emission(transition.n_rows); - for (int i=0; i