├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── DESCRIPTION ├── NAMESPACE ├── R ├── RcppMLPACK.package.skeleton.R ├── flags.R ├── fun.R └── inline.R ├── README.md ├── cleanup ├── configure ├── configure.ac ├── inst ├── include │ ├── RcppMLPACK.h │ └── mlpack │ │ ├── core.hpp │ │ ├── core │ │ ├── arma_extend │ │ │ ├── SpMat_extra_bones.hpp │ │ │ ├── SpMat_extra_meat.hpp │ │ │ ├── arma_extend.hpp │ │ │ ├── fn_ccov.hpp │ │ │ ├── fn_inplace_reshape.hpp │ │ │ ├── glue_ccov_meat.hpp │ │ │ ├── glue_ccov_proto.hpp │ │ │ ├── hdf5_misc.hpp │ │ │ ├── op_ccov_meat.hpp │ │ │ ├── op_ccov_proto.hpp │ │ │ ├── promote_type.hpp │ │ │ ├── restrictors.hpp │ │ │ ├── traits.hpp │ │ │ └── typedef.hpp │ │ ├── data │ │ │ ├── load.hpp │ │ │ ├── load_impl.hpp │ │ │ ├── normalize_labels.hpp │ │ │ ├── normalize_labels_impl.hpp │ │ │ ├── save.hpp │ │ │ └── save_impl.hpp │ │ ├── dists │ │ │ ├── discrete_distribution.hpp │ │ │ ├── gaussian_distribution.hpp │ │ │ └── laplace_distribution.hpp │ │ ├── kernels │ │ │ ├── cosine_distance.hpp │ │ │ ├── cosine_distance_impl.hpp │ │ │ ├── epanechnikov_kernel.hpp │ │ │ ├── epanechnikov_kernel_impl.hpp │ │ │ ├── example_kernel.hpp │ │ │ ├── gaussian_kernel.hpp │ │ │ ├── hyperbolic_tangent_kernel.hpp │ │ │ ├── kernel_traits.hpp │ │ │ ├── laplacian_kernel.hpp │ │ │ ├── linear_kernel.hpp │ │ │ ├── polynomial_kernel.hpp │ │ │ ├── pspectrum_string_kernel.hpp │ │ │ ├── pspectrum_string_kernel_impl.hpp │ │ │ ├── spherical_kernel.hpp │ │ │ └── triangular_kernel.hpp │ │ ├── math │ │ │ ├── clamp.hpp │ │ │ ├── lin_alg.hpp │ │ │ ├── random.hpp │ │ │ ├── range.hpp │ │ │ ├── range_impl.hpp │ │ │ └── round.hpp │ │ ├── metrics │ │ │ ├── ip_metric.hpp │ │ │ ├── ip_metric_impl.hpp │ │ │ ├── lmetric.hpp │ │ │ ├── lmetric_impl.hpp │ │ │ ├── mahalanobis_distance.hpp │ │ │ └── mahalanobis_distance_impl.hpp │ │ ├── optimizers │ │ │ ├── aug_lagrangian │ │ │ │ ├── aug_lagrangian.hpp │ │ │ │ ├── aug_lagrangian_function.hpp │ │ │ │ ├── aug_lagrangian_function_impl.hpp │ │ │ │ ├── aug_lagrangian_impl.hpp │ │ │ │ └── aug_lagrangian_test_functions.hpp │ │ │ ├── lbfgs │ │ │ │ ├── lbfgs.hpp │ │ │ │ ├── lbfgs_impl.hpp │ │ │ │ └── test_functions.hpp │ │ │ ├── lrsdp │ │ │ │ ├── lrsdp.hpp │ │ │ │ └── lrsdp_function.hpp │ │ │ ├── sa │ │ │ │ ├── exponential_schedule.hpp │ │ │ │ ├── sa.hpp │ │ │ │ └── sa_impl.hpp │ │ │ └── sgd │ │ │ │ ├── sgd.hpp │ │ │ │ ├── sgd_impl.hpp │ │ │ │ └── test_function.hpp │ │ ├── tree │ │ │ ├── ballbound.hpp │ │ │ ├── ballbound_impl.hpp │ │ │ ├── binary_space_tree.hpp │ │ │ ├── binary_space_tree │ │ │ │ ├── binary_space_tree.hpp │ │ │ │ ├── binary_space_tree_impl.hpp │ │ │ │ ├── dual_tree_traverser.hpp │ │ │ │ ├── dual_tree_traverser_impl.hpp │ │ │ │ ├── mean_split.hpp │ │ │ │ ├── mean_split_impl.hpp │ │ │ │ ├── single_tree_traverser.hpp │ │ │ │ ├── single_tree_traverser_impl.hpp │ │ │ │ └── traits.hpp │ │ │ ├── bounds.hpp │ │ │ ├── cosine_tree │ │ │ │ └── cosine_tree.hpp │ │ │ ├── cover_tree.hpp │ │ │ ├── cover_tree │ │ │ │ ├── cover_tree.hpp │ │ │ │ ├── cover_tree_impl.hpp │ │ │ │ ├── dual_tree_traverser.hpp │ │ │ │ ├── dual_tree_traverser_impl.hpp │ │ │ │ ├── first_point_is_root.hpp │ │ │ │ ├── single_tree_traverser.hpp │ │ │ │ ├── single_tree_traverser_impl.hpp │ │ │ │ └── traits.hpp │ │ │ ├── example_tree.hpp │ │ │ ├── hrectbound.hpp │ │ │ ├── hrectbound_impl.hpp │ │ │ ├── mrkd_statistic.hpp │ │ │ ├── mrkd_statistic_impl.hpp │ │ │ ├── rectangle_tree.hpp │ │ │ ├── statistic.hpp │ │ │ ├── traversal_info.hpp │ │ │ └── tree_traits.hpp │ │ └── util │ │ │ ├── arma_traits.hpp │ │ │ ├── nulloutstream.hpp │ │ │ ├── option.hpp │ │ │ ├── option_impl.hpp │ │ │ ├── prefixedoutstream.hpp │ │ │ ├── prefixedoutstream_impl.hpp │ │ │ ├── sfinae_utility.hpp │ │ │ ├── string_util.hpp │ │ │ ├── timers.hpp │ │ │ └── version.hpp │ │ ├── methods │ │ ├── amf │ │ │ ├── amf.hpp │ │ │ ├── amf_impl.hpp │ │ │ ├── init_rules │ │ │ │ ├── random_acol_init.hpp │ │ │ │ └── random_init.hpp │ │ │ ├── termination_policies │ │ │ │ ├── complete_incremental.hpp │ │ │ │ ├── complete_incremental_termination.hpp │ │ │ │ ├── incomplete_incremental.hpp │ │ │ │ ├── simple_residue_termination.hpp │ │ │ │ ├── simple_tolerance_termination.hpp │ │ │ │ └── validation_RMSE_termination.hpp │ │ │ └── update_rules │ │ │ │ ├── nmf_als.hpp │ │ │ │ ├── nmf_mult_dist.hpp │ │ │ │ ├── nmf_mult_div.hpp │ │ │ │ ├── svd_batch_learning.hpp │ │ │ │ ├── svd_complete_incremental_learning.hpp │ │ │ │ └── svd_incomplete_incremental_learning.hpp │ │ ├── cf │ │ │ ├── cf.hpp │ │ │ └── cf_impl.hpp │ │ ├── decision_stump │ │ │ ├── decision_stump.hpp │ │ │ └── decision_stump_impl.hpp │ │ ├── det │ │ │ ├── dt_utils.hpp │ │ │ └── dtree.hpp │ │ ├── emst │ │ │ ├── dtb.hpp │ │ │ ├── dtb_impl.hpp │ │ │ ├── dtb_rules.hpp │ │ │ ├── dtb_rules_impl.hpp │ │ │ ├── dtb_stat.hpp │ │ │ ├── edge_pair.hpp │ │ │ └── union_find.hpp │ │ ├── fastmks │ │ │ ├── fastmks.hpp │ │ │ ├── fastmks_impl.hpp │ │ │ ├── fastmks_rules.hpp │ │ │ ├── fastmks_rules_impl.hpp │ │ │ └── fastmks_stat.hpp │ │ ├── gmm │ │ │ ├── diagonal_constraint.hpp │ │ │ ├── eigenvalue_ratio_constraint.hpp │ │ │ ├── em_fit.hpp │ │ │ ├── em_fit_impl.hpp │ │ │ ├── gmm.hpp │ │ │ ├── gmm_impl.hpp │ │ │ ├── no_constraint.hpp │ │ │ ├── phi.hpp │ │ │ └── positive_definite_constraint.hpp │ │ ├── hmm │ │ │ ├── hmm.hpp │ │ │ ├── hmm_impl.hpp │ │ │ ├── hmm_util.hpp │ │ │ └── hmm_util_impl.hpp │ │ ├── kernel_pca │ │ │ ├── kernel_pca.hpp │ │ │ ├── kernel_pca_impl.hpp │ │ │ └── kernel_rules │ │ │ │ ├── naive_method.hpp │ │ │ │ └── nystroem_method.hpp │ │ ├── kmeans │ │ │ ├── allow_empty_clusters.hpp │ │ │ ├── kmeans.hpp │ │ │ ├── kmeans_impl.hpp │ │ │ ├── max_variance_new_cluster.hpp │ │ │ ├── max_variance_new_cluster_impl.hpp │ │ │ ├── random_partition.hpp │ │ │ ├── refined_start.hpp │ │ │ └── refined_start_impl.hpp │ │ ├── lars │ │ │ └── lars.hpp │ │ ├── linear_regression │ │ │ └── linear_regression.hpp │ │ ├── local_coordinate_coding │ │ │ ├── lcc.hpp │ │ │ └── lcc_impl.hpp │ │ ├── logistic_regression │ │ │ ├── logistic_regression.hpp │ │ │ ├── logistic_regression_function.hpp │ │ │ └── logistic_regression_impl.hpp │ │ ├── lsh │ │ │ ├── lsh_search.hpp │ │ │ └── lsh_search_impl.hpp │ │ ├── mvu │ │ │ └── mvu.hpp │ │ ├── naive_bayes │ │ │ ├── naive_bayes_classifier.hpp │ │ │ └── naive_bayes_classifier_impl.hpp │ │ ├── nca │ │ │ ├── nca.hpp │ │ │ ├── nca_impl.hpp │ │ │ ├── nca_softmax_error_function.hpp │ │ │ └── nca_softmax_error_function_impl.hpp │ │ ├── neighbor_search │ │ │ ├── neighbor_search.hpp │ │ │ ├── neighbor_search_impl.hpp │ │ │ ├── neighbor_search_rules.hpp │ │ │ ├── neighbor_search_rules_impl.hpp │ │ │ ├── neighbor_search_stat.hpp │ │ │ ├── ns_traversal_info.hpp │ │ │ ├── sort_policies │ │ │ │ ├── furthest_neighbor_sort.hpp │ │ │ │ ├── furthest_neighbor_sort_impl.hpp │ │ │ │ ├── nearest_neighbor_sort.hpp │ │ │ │ └── nearest_neighbor_sort_impl.hpp │ │ │ ├── typedef.hpp │ │ │ └── unmap.hpp │ │ ├── nystroem_method │ │ │ ├── kmeans_selection.hpp │ │ │ ├── nystroem_method.hpp │ │ │ ├── nystroem_method_impl.hpp │ │ │ ├── ordered_selection.hpp │ │ │ └── random_selection.hpp │ │ ├── pca │ │ │ └── pca.hpp │ │ ├── perceptron │ │ │ ├── initialization_methods │ │ │ │ ├── random_init.hpp │ │ │ │ └── zero_init.hpp │ │ │ ├── learning_policies │ │ │ │ └── simple_weight_update.hpp │ │ │ ├── perceptron.hpp │ │ │ └── perceptron_impl.hpp │ │ ├── quic_svd │ │ │ ├── quic_svd.hpp │ │ │ └── quic_svd_impl.hpp │ │ ├── radical │ │ │ └── radical.hpp │ │ ├── range_search │ │ │ ├── range_search.hpp │ │ │ ├── range_search_impl.hpp │ │ │ ├── range_search_rules.hpp │ │ │ ├── range_search_rules_impl.hpp │ │ │ └── range_search_stat.hpp │ │ ├── rann │ │ │ ├── ra_query_stat.hpp │ │ │ ├── ra_search.hpp │ │ │ ├── ra_search_impl.hpp │ │ │ ├── ra_search_rules.hpp │ │ │ ├── ra_search_rules_impl.hpp │ │ │ └── ra_typedef.hpp │ │ ├── regularized_svd │ │ │ ├── regularized_svd.hpp │ │ │ ├── regularized_svd_function.hpp │ │ │ └── regularized_svd_impl.hpp │ │ ├── sparse_autoencoder │ │ │ ├── sparse_autoencoder.hpp │ │ │ ├── sparse_autoencoder_function.hpp │ │ │ └── sparse_autoencoder_impl.hpp │ │ └── sparse_coding │ │ │ ├── data_dependent_random_initializer.hpp │ │ │ ├── nothing_initializer.hpp │ │ │ ├── random_initializer.hpp │ │ │ ├── sparse_coding.hpp │ │ │ └── sparse_coding_impl.hpp │ │ └── prereqs.hpp └── skeleton │ ├── Makevars │ ├── Makevars.win │ └── kmeans.cpp ├── man ├── RcppMLPACK-package.Rd ├── RcppMLPACK.package.skeleton.Rd └── mlKmeans.Rd ├── src ├── Makevars ├── Makevars.win ├── RcppExports.cpp ├── RcppMLPACK.h ├── init.c ├── kmeans.cpp └── mlpack │ ├── core.hpp │ ├── core │ ├── arma_extend │ │ ├── SpMat_extra_bones.hpp │ │ ├── SpMat_extra_meat.hpp │ │ ├── arma_extend.hpp │ │ ├── fn_ccov.hpp │ │ ├── fn_inplace_reshape.hpp │ │ ├── glue_ccov_meat.hpp │ │ ├── glue_ccov_proto.hpp │ │ ├── hdf5_misc.hpp │ │ ├── op_ccov_meat.hpp │ │ ├── op_ccov_proto.hpp │ │ ├── promote_type.hpp │ │ ├── restrictors.hpp │ │ ├── traits.hpp │ │ └── typedef.hpp │ ├── data │ │ ├── load.hpp │ │ ├── load_impl.hpp │ │ ├── normalize_labels.hpp │ │ ├── normalize_labels_impl.hpp │ │ ├── save.hpp │ │ └── save_impl.hpp │ ├── dists │ │ ├── discrete_distribution.cpp │ │ ├── discrete_distribution.hpp │ │ ├── gaussian_distribution.cpp │ │ ├── gaussian_distribution.hpp │ │ ├── laplace_distribution.cpp │ │ └── laplace_distribution.hpp │ ├── kernels │ │ ├── cosine_distance.hpp │ │ ├── cosine_distance_impl.hpp │ │ ├── epanechnikov_kernel.cpp │ │ ├── epanechnikov_kernel.hpp │ │ ├── epanechnikov_kernel_impl.hpp │ │ ├── example_kernel.hpp │ │ ├── gaussian_kernel.hpp │ │ ├── hyperbolic_tangent_kernel.hpp │ │ ├── kernel_traits.hpp │ │ ├── laplacian_kernel.hpp │ │ ├── linear_kernel.hpp │ │ ├── polynomial_kernel.hpp │ │ ├── pspectrum_string_kernel.cpp │ │ ├── pspectrum_string_kernel.hpp │ │ ├── pspectrum_string_kernel_impl.hpp │ │ ├── spherical_kernel.hpp │ │ └── triangular_kernel.hpp │ ├── math │ │ ├── clamp.hpp │ │ ├── lin_alg.cpp │ │ ├── lin_alg.hpp │ │ ├── random.cpp │ │ ├── random.hpp │ │ ├── range.hpp │ │ ├── range_impl.hpp │ │ └── round.hpp │ ├── metrics │ │ ├── ip_metric.hpp │ │ ├── ip_metric_impl.hpp │ │ ├── lmetric.hpp │ │ ├── lmetric_impl.hpp │ │ ├── mahalanobis_distance.hpp │ │ └── mahalanobis_distance_impl.hpp │ ├── optimizers │ │ ├── aug_lagrangian │ │ │ ├── aug_lagrangian.hpp │ │ │ ├── aug_lagrangian_function.hpp │ │ │ ├── aug_lagrangian_function_impl.hpp │ │ │ ├── aug_lagrangian_impl.hpp │ │ │ ├── aug_lagrangian_test_functions.cpp │ │ │ └── aug_lagrangian_test_functions.hpp │ │ ├── lbfgs │ │ │ ├── lbfgs.hpp │ │ │ ├── lbfgs_impl.hpp │ │ │ ├── test_functions.cpp │ │ │ └── test_functions.hpp │ │ ├── lrsdp │ │ │ ├── lrsdp.cpp │ │ │ ├── lrsdp.hpp │ │ │ ├── lrsdp_function.cpp │ │ │ └── lrsdp_function.hpp │ │ ├── sa │ │ │ ├── exponential_schedule.hpp │ │ │ ├── sa.hpp │ │ │ └── sa_impl.hpp │ │ └── sgd │ │ │ ├── sgd.hpp │ │ │ ├── sgd_impl.hpp │ │ │ ├── test_function.cpp │ │ │ └── test_function.hpp │ ├── tree │ │ ├── ballbound.hpp │ │ ├── ballbound_impl.hpp │ │ ├── binary_space_tree.hpp │ │ ├── binary_space_tree │ │ │ ├── binary_space_tree.hpp │ │ │ ├── binary_space_tree_impl.hpp │ │ │ ├── dual_tree_traverser.hpp │ │ │ ├── dual_tree_traverser_impl.hpp │ │ │ ├── mean_split.hpp │ │ │ ├── mean_split_impl.hpp │ │ │ ├── single_tree_traverser.hpp │ │ │ ├── single_tree_traverser_impl.hpp │ │ │ └── traits.hpp │ │ ├── bounds.hpp │ │ ├── cosine_tree │ │ │ ├── cosine_tree.cpp │ │ │ └── cosine_tree.hpp │ │ ├── cover_tree.hpp │ │ ├── cover_tree │ │ │ ├── cover_tree.hpp │ │ │ ├── cover_tree_impl.hpp │ │ │ ├── dual_tree_traverser.hpp │ │ │ ├── dual_tree_traverser_impl.hpp │ │ │ ├── first_point_is_root.hpp │ │ │ ├── single_tree_traverser.hpp │ │ │ ├── single_tree_traverser_impl.hpp │ │ │ └── traits.hpp │ │ ├── example_tree.hpp │ │ ├── hrectbound.hpp │ │ ├── hrectbound_impl.hpp │ │ ├── mrkd_statistic.cpp │ │ ├── mrkd_statistic.hpp │ │ ├── mrkd_statistic_impl.hpp │ │ ├── rectangle_tree.hpp │ │ ├── statistic.hpp │ │ ├── traversal_info.hpp │ │ └── tree_traits.hpp │ └── util │ │ ├── arma_traits.hpp │ │ ├── nulloutstream.hpp │ │ ├── option.cpp │ │ ├── option.hpp │ │ ├── option_impl.hpp │ │ ├── prefixedoutstream.cpp │ │ ├── prefixedoutstream.hpp │ │ ├── prefixedoutstream_impl.hpp │ │ ├── sfinae_utility.hpp │ │ ├── string_util.cpp │ │ ├── string_util.hpp │ │ ├── timers.cpp │ │ ├── timers.hpp │ │ ├── version.cpp │ │ └── version.hpp │ ├── methods │ ├── amf │ │ ├── amf.hpp │ │ ├── amf_impl.hpp │ │ ├── init_rules │ │ │ ├── random_acol_init.hpp │ │ │ └── random_init.hpp │ │ ├── termination_policies │ │ │ ├── complete_incremental_termination.hpp │ │ │ ├── incomplete_incremental_termination.hpp │ │ │ ├── simple_residue_termination.hpp │ │ │ ├── simple_tolerance_termination.hpp │ │ │ └── validation_RMSE_termination.hpp │ │ └── update_rules │ │ │ ├── nmf_als.hpp │ │ │ ├── nmf_mult_dist.hpp │ │ │ ├── nmf_mult_div.hpp │ │ │ ├── svd_batch_learning.hpp │ │ │ ├── svd_complete_incremental_learning.hpp │ │ │ └── svd_incomplete_incremental_learning.hpp │ ├── cf │ │ ├── cf.hpp │ │ └── cf_impl.hpp │ ├── decision_stump │ │ ├── decision_stump.hpp │ │ └── decision_stump_impl.hpp │ ├── det │ │ ├── dt_utils.cpp │ │ ├── dt_utils.hpp │ │ ├── dtree.cpp │ │ └── dtree.hpp │ ├── emst │ │ ├── dtb.hpp │ │ ├── dtb_impl.hpp │ │ ├── dtb_rules.hpp │ │ ├── dtb_rules_impl.hpp │ │ ├── dtb_stat.hpp │ │ ├── edge_pair.hpp │ │ └── union_find.hpp │ ├── fastmks │ │ ├── fastmks.hpp │ │ ├── fastmks_impl.hpp │ │ ├── fastmks_rules.hpp │ │ ├── fastmks_rules_impl.hpp │ │ └── fastmks_stat.hpp │ ├── gmm │ │ ├── diagonal_constraint.hpp │ │ ├── eigenvalue_ratio_constraint.hpp │ │ ├── em_fit.hpp │ │ ├── em_fit_impl.hpp │ │ ├── gmm.hpp │ │ ├── gmm_impl.hpp │ │ ├── no_constraint.hpp │ │ ├── phi.hpp │ │ └── positive_definite_constraint.hpp │ ├── hmm │ │ ├── hmm.hpp │ │ ├── hmm_impl.hpp │ │ ├── hmm_util.hpp │ │ └── hmm_util_impl.hpp │ ├── kernel_pca │ │ ├── kernel_pca.hpp │ │ ├── kernel_pca_impl.hpp │ │ └── kernel_rules │ │ │ ├── naive_method.hpp │ │ │ └── nystroem_method.hpp │ ├── kmeans │ │ ├── allow_empty_clusters.hpp │ │ ├── kmeans.hpp │ │ ├── kmeans_impl.hpp │ │ ├── max_variance_new_cluster.hpp │ │ ├── max_variance_new_cluster_impl.hpp │ │ ├── random_partition.hpp │ │ ├── refined_start.hpp │ │ └── refined_start_impl.hpp │ ├── lars │ │ ├── lars.cpp │ │ └── lars.hpp │ ├── linear_regression │ │ ├── linear_regression.cpp │ │ └── linear_regression.hpp │ ├── local_coordinate_coding │ │ ├── lcc.hpp │ │ └── lcc_impl.hpp │ ├── logistic_regression │ │ ├── logistic_regression.hpp │ │ ├── logistic_regression_function.cpp │ │ ├── logistic_regression_function.hpp │ │ └── logistic_regression_impl.hpp │ ├── lsh │ │ ├── lsh_search.hpp │ │ └── lsh_search_impl.hpp │ ├── mvu │ │ ├── mvu.cpp │ │ └── mvu.hpp │ ├── naive_bayes │ │ ├── naive_bayes_classifier.hpp │ │ └── naive_bayes_classifier_impl.hpp │ ├── nca │ │ ├── nca.hpp │ │ ├── nca_impl.hpp │ │ ├── nca_softmax_error_function.hpp │ │ └── nca_softmax_error_function_impl.hpp │ ├── neighbor_search │ │ ├── neighbor_search.hpp │ │ ├── neighbor_search_impl.hpp │ │ ├── neighbor_search_rules.hpp │ │ ├── neighbor_search_rules_impl.hpp │ │ ├── neighbor_search_stat.hpp │ │ ├── ns_traversal_info.hpp │ │ ├── sort_policies │ │ │ ├── furthest_neighbor_sort.cpp │ │ │ ├── furthest_neighbor_sort.hpp │ │ │ ├── furthest_neighbor_sort_impl.hpp │ │ │ ├── nearest_neighbor_sort.cpp │ │ │ ├── nearest_neighbor_sort.hpp │ │ │ └── nearest_neighbor_sort_impl.hpp │ │ ├── typedef.hpp │ │ ├── unmap.cpp │ │ └── unmap.hpp │ ├── nystroem_method │ │ ├── kmeans_selection.hpp │ │ ├── nystroem_method.hpp │ │ ├── nystroem_method_impl.hpp │ │ ├── ordered_selection.hpp │ │ └── random_selection.hpp │ ├── pca │ │ ├── pca.cpp │ │ └── pca.hpp │ ├── perceptron │ │ ├── initialization_methods │ │ │ ├── random_init.hpp │ │ │ └── zero_init.hpp │ │ ├── learning_policies │ │ │ └── simple_weight_update.hpp │ │ ├── perceptron.hpp │ │ └── perceptron_impl.hpp │ ├── quic_svd │ │ ├── quic_svd.hpp │ │ └── quic_svd_impl.hpp │ ├── radical │ │ ├── radical.cpp │ │ └── radical.hpp │ ├── range_search │ │ ├── range_search.hpp │ │ ├── range_search_impl.hpp │ │ ├── range_search_rules.hpp │ │ ├── range_search_rules_impl.hpp │ │ └── range_search_stat.hpp │ ├── rann │ │ ├── ra_query_stat.hpp │ │ ├── ra_search.hpp │ │ ├── ra_search_impl.hpp │ │ ├── ra_search_rules.hpp │ │ ├── ra_search_rules_impl.hpp │ │ └── ra_typedef.hpp │ ├── regularized_svd │ │ ├── regularized_svd.hpp │ │ ├── regularized_svd_function.cpp │ │ ├── regularized_svd_function.hpp │ │ └── regularized_svd_impl.hpp │ ├── sparse_autoencoder │ │ ├── sparse_autoencoder.hpp │ │ ├── sparse_autoencoder_function.cpp │ │ ├── sparse_autoencoder_function.hpp │ │ └── sparse_autoencoder_impl.hpp │ └── sparse_coding │ │ ├── data_dependent_random_initializer.hpp │ │ ├── nothing_initializer.hpp │ │ ├── random_initializer.hpp │ │ ├── sparse_coding.hpp │ │ └── sparse_coding_impl.hpp │ └── prereqs.hpp └── vignettes ├── RcppMLPACK-intro.Rnw └── ref.bib /.Rbuildignore: -------------------------------------------------------------------------------- 1 | .travis.yml 2 | .git 3 | ^.*\.Rproj$ 4 | ^\.Rproj\.user$ 5 | ^.*\.tar\.gz$ -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # editor backup files 2 | *~ 3 | \#*\# 4 | 5 | # compiled code 6 | *.o 7 | *.so 8 | *.dll 9 | *.a 10 | 11 | # SVN stuff 12 | .svn 13 | 14 | # RUnit generated stuff 15 | inst/unitTests/report* 16 | 17 | #autoconf 18 | config.log 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Run Travis CI for R using https://eddelbuettel.github.io/r-travis/ 2 | 3 | language: c 4 | 5 | sudo: required 6 | 7 | dist: trusty 8 | 9 | before_install: 10 | - curl -OLs https://eddelbuettel.github.io/r-travis/run.sh && chmod 0755 run.sh 11 | - ./run.sh bootstrap 12 | 13 | install: 14 | - ./run.sh install_aptget r-cran-rcpp r-cran-rcpparmadillo r-cran-bh r-cran-runit 15 | 16 | script: 17 | - ./run.sh run_tests 18 | 19 | after_failure: 20 | - ./run.sh dump_logs 21 | 22 | notifications: 23 | email: 24 | on_success: change 25 | on_failure: change 26 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: RcppMLPACK 2 | Type: Package 3 | Title: 'Rcpp' Integration for the 'MLPACK' Library 4 | Version: 1.0.10-7 5 | Date: 2020-04-17 6 | Author: Qiang Kou, Ryan Curtin 7 | Maintainer: Qiang Kou 8 | Description: 'MLPACK' is an intuitive, fast, scalable C++ machine learning 9 | library, meant to be a machine learning analog to 'LAPACK'. It 10 | aims to implement a wide array of machine learning methods 11 | and function as a Swiss army knife for machine learning 12 | researchers: 'MLPACK' is available from ; 13 | sources are included in the package. 14 | SystemRequirements: A C++11 compiler. Versions 4.8.*, 4.9.* or later of GCC will be fine. 15 | License: LGPL (>= 2) 16 | Depends: R (>= 3.3.0) 17 | Imports: Rcpp (>= 0.12.8) 18 | LinkingTo: Rcpp, RcppArmadillo, BH 19 | URL: https://github.com/thirdwing/RcppMLPACK1, 20 | http://www.mlpack.org/ 21 | BugReports: https://github.com/thirdwing/RcppMLPACK1/issues 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | useDynLib(RcppMLPACK, .registration=TRUE) 2 | export(RcppMLPACK.package.skeleton, mlKmeans) 3 | importFrom(Rcpp, evalCpp) 4 | importFrom(utils, packageDescription, package.skeleton) 5 | -------------------------------------------------------------------------------- /R/flags.R: -------------------------------------------------------------------------------- 1 | RcppMLPACK.system.file <- function(...){ 2 | tools::file_path_as_absolute( base::system.file( ..., package = "RcppMLPACK" ) ) 3 | } 4 | 5 | staticLinking <- function() { 6 | ! grepl( "^linux", R.version$os ) 7 | } 8 | 9 | RcppMLPACKLdPath <- function() { 10 | if (nzchar(.Platform$r_arch)) { ## eg amd64, ia64, mips 11 | path <- RcppMLPACK.system.file("lib",.Platform$r_arch) 12 | } else { 13 | path <- RcppMLPACK.system.file("lib") 14 | } 15 | path 16 | } 17 | 18 | RcppMLPACKLdFlags <- function(static=staticLinking()) { 19 | RcppMLPACKdir <- RcppMLPACKLdPath() 20 | if (static) { # static is default on Windows and OS X 21 | flags <- paste('"',RcppMLPACKdir, '/libRcppMLPACK.a"', sep="") 22 | } else { # else for dynamic linking 23 | flags <- paste("-L", RcppMLPACKdir, " -lRcppMLPACK", sep="") # baseline setting 24 | if ((.Platform$OS.type == "unix") && # on Linux, we can use rpath to encode path 25 | (length(grep("^linux",R.version$os)))) { 26 | flags <- paste(flags, " -Wl,-rpath,", RcppMLPACKdir, sep="") 27 | } 28 | } 29 | invisible(flags) 30 | } 31 | 32 | CxxFlags <- function() { 33 | path <- RcppMLPACK.system.file("include") 34 | paste("-I", path, sep="") 35 | } 36 | 37 | LdFlags <- function(static=staticLinking()) { 38 | cat(RcppMLPACKLdFlags(static=static)) 39 | } 40 | -------------------------------------------------------------------------------- /R/fun.R: -------------------------------------------------------------------------------- 1 | mlKmeans <- function(X, y) { 2 | 3 | X <- as.matrix(X) 4 | y <- as.numeric(y) 5 | 6 | .Call( "RcppMLPACK_kmeans", X, y, PACKAGE = "RcppMLPACK" ) 7 | 8 | } 9 | -------------------------------------------------------------------------------- /R/inline.R: -------------------------------------------------------------------------------- 1 | inlineCxxPlugin <- function(...) { 2 | plugin <- Rcpp::Rcpp.plugin.maker( 3 | include.before = "#include ", 4 | libs = sprintf("%s $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)", RcppMLPACKLdFlags()), 5 | LinkingTo = c("RcppArmadillo", "Rcpp", "BH", "RcppMLPACK"), 6 | package = "RcppMLPACK" 7 | ) 8 | settings <- plugin() 9 | settings 10 | } 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | RcppMLPACK 2 | ========== 3 | 4 | [![Build Status](https://travis-ci.org/thirdwing/RcppMLPACK1.svg?branch=master)](https://travis-ci.org/thirdwing/RcppMLPACK1) 5 | 6 | [MLPACK](http://www.mlpack.org/) is a C++ machine learning library with emphasis on scalability, speed, and ease-of-use. Its aim is to make machine learning possible for novice users by means of a simple, consistent API, while simultaneously exploiting C++ language features to provide maximum performance and maximum flexibility for expert users. MLPACK outperforms competing machine learning libraries by large margins; see the [BigLearning workshop paper](http://www.mlpack.org/papers/mlpack2011.pdf) for details. 7 | 8 | The algorithms implemented in MLPACK: 9 | 10 | * Fast Hierarchical Clustering (Euclidean Minimum Spanning Trees) 11 | * Gaussian Mixture Models (trained via EM) 12 | * Hidden Markov Models (training, prediction, and classification) 13 | * Kernel Principal Components Analysis 14 | * K-Means clustering 15 | * LARS/Lasso Regression 16 | * Least-squares Linear Regression 17 | * Maximum Variance Unfolding (using LRSDP) 18 | * Naive Bayes Classifier 19 | * Neighborhood Components Analysis (using LRSDP) 20 | * RADICAL (Robust, Accurate, Direct ICA aLgorithm) 21 | * Tree-based k-nearest-neighbors search and classifier 22 | * Tree-based range search 23 | 24 | The RcppMLPACK package includes the source code from the MLPACK library. Thus users do not need to install MLPACK itself in order to use RcppMLPACK. 25 | 26 | This MLPACK integration heavily relies on [Rcpp](http://www.rcpp.org) and RcppArmadillo packages. 27 | 28 | The version number of MLPACK is used as the version number of this package. 29 | 30 | Testing and bug reports are deeply welcome. 31 | 32 | You can find examples in the [wiki page](https://github.com/thirdwing/RcppMLPACK1/wiki). You can always find me by email (qkou@umail.iu.edu) if you have any questions. 33 | -------------------------------------------------------------------------------- /cleanup: -------------------------------------------------------------------------------- 1 | find . -name \*~ -exec rm {} \; 2 | find . -name \*.o -exec rm {} \; 3 | find . -name \*.so -exec rm {} \; 4 | find . -name "#*#" -exec rm {} \; 5 | 6 | rm -rf ./inst/lib 7 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | ## RcppMLPACK configure.ac 2 | ## 3 | ## RcppMLPACK compiler check modified from RcppArmadillo to check for gcc > 4.6 4 | ## 5 | ## Copyright (C) 2016 Dirk Eddelbuettel, James Balamuta 6 | ## 7 | ## Licensed under GPL-2 or later 8 | 9 | ## require at least autoconf 2.61 10 | AC_PREREQ(2.61) 11 | 12 | ## Process this file with autoconf to produce a configure script. 13 | AC_INIT(RcppMLPACK, m4_esyscmd_s([awk -e '/^Version:/ {print $2}' DESCRIPTION])) 14 | 15 | ## Set R_HOME, respecting an environment variable if one is set 16 | : ${R_HOME=$(R RHOME)} 17 | if test -z "${R_HOME}"; then 18 | AC_MSG_ERROR([Could not determine R_HOME.]) 19 | fi 20 | ## Use R to set CXX and CXXFLAGS 21 | CXX=$(${R_HOME}/bin/R CMD config CXX) 22 | CXXFLAGS=$("${R_HOME}/bin/R" CMD config CXXFLAGS) 23 | 24 | ## We are using C++ 25 | AC_LANG(C++) 26 | AC_REQUIRE_CPP 27 | 28 | ## Check the C++ compiler using the CXX value set 29 | AC_PROG_CXX 30 | 31 | ## If it is g++, we have GXX set so let's examine it 32 | if test "${GXX}" = yes; then 33 | AC_MSG_CHECKING([whether g++ version is sufficient]) 34 | gxx_version=$(${CXX} -v 2>&1 | awk '/^.*g.. version/ {print $3}') 35 | case ${gxx_version} in 36 | 1.*|2.*|3.*|4.0.*|4.1.*|4.2.*|4.3.*|4.4.*|4.5.*|4.6.*) 37 | AC_MSG_RESULT([no]) 38 | AC_MSG_WARN([Only g++ version 4.7 or greater can be used with RcppMLPACK.]) 39 | AC_MSG_ERROR([Please use a different compiler.]) 40 | ;; 41 | 4.7.*|4.8.*|4.9.*|5.*|6.*) ## Removes gcc 4.6.* from this line 42 | gxx_newer_than_45="-fpermissive" 43 | AC_MSG_RESULT([(${gxx_version}) yes]) 44 | ;; 45 | esac 46 | fi -------------------------------------------------------------------------------- /inst/include/mlpack/core/arma_extend/SpMat_extra_bones.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SpMat_extra_bones.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Add a batch constructor for SpMat, if the version is older than 3.810.0. 6 | */ 7 | #if ARMA_VERSION_MAJOR == 3 && ARMA_VERSION_MINOR < 810 8 | template inline SpMat( 9 | const Base& locations, 10 | const Base& values, 11 | const bool sort_locations = true); 12 | 13 | template inline SpMat( 14 | const Base& locations, 15 | const Base& values, 16 | const uword n_rows, 17 | const uword n_cols, 18 | const bool sort_locations = true); 19 | #endif 20 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/arma_extend/arma_extend.hpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * @file arma_extend.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Include Armadillo extensions which currently are not part of the main 6 | * Armadillo codebase. 7 | * 8 | * This will allow the use of the ccov() function (which performs the same 9 | * function as cov(trans(X)) but without the cost of computing trans(X)). This 10 | * also gives sparse matrix support, if it is necessary. 11 | */ 12 | #ifndef __MLPACK_CORE_ARMA_EXTEND_ARMA_EXTEND_HPP 13 | #define __MLPACK_CORE_ARMA_EXTEND_ARMA_EXTEND_HPP 14 | 15 | // Add batch constructor for sparse matrix (if version <= 3.810.0). 16 | #define ARMA_EXTRA_SPMAT_PROTO mlpack/core/arma_extend/SpMat_extra_bones.hpp 17 | #define ARMA_EXTRA_SPMAT_MEAT mlpack/core/arma_extend/SpMat_extra_meat.hpp 18 | 19 | #include 20 | #define NDEBUG 1 21 | 22 | namespace arma { 23 | // u64/s64 24 | #include "typedef.hpp" 25 | #include "traits.hpp" 26 | #include "promote_type.hpp" 27 | #include "restrictors.hpp" 28 | #include "hdf5_misc.hpp" 29 | 30 | // ccov() 31 | #include "op_ccov_proto.hpp" 32 | #include "op_ccov_meat.hpp" 33 | #include "glue_ccov_proto.hpp" 34 | #include "glue_ccov_meat.hpp" 35 | #include "fn_ccov.hpp" 36 | 37 | // inplace_reshape() 38 | #include "fn_inplace_reshape.hpp" 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/arma_extend/fn_ccov.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 NICTA and the authors listed below 2 | // http://nicta.com.au 3 | // 4 | // Authors: 5 | // - Conrad Sanderson (conradsand at ieee dot org) 6 | // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) 7 | // - Ryan Curtin (ryan at igglybob dot com) 8 | // 9 | // This file is part of the Armadillo C++ library. 10 | // It is provided without any warranty of fitness 11 | // for any purpose. You can redistribute this file 12 | // and/or modify it under the terms of the GNU 13 | // Lesser General Public License (LGPL) as published 14 | // by the Free Software Foundation, either version 3 15 | // of the License or (at your option) any later version. 16 | // (see http://www.opensource.org/licenses for more info) 17 | 18 | 19 | //! \addtogroup fn_ccov 20 | //! @{ 21 | 22 | 23 | 24 | template 25 | inline 26 | const Op 27 | ccov(const Base& X, const uword norm_type = 0) 28 | { 29 | arma_extra_debug_sigprint(); 30 | 31 | arma_debug_check( (norm_type > 1), "ccov(): norm_type must be 0 or 1"); 32 | 33 | return Op(X.get_ref(), norm_type, 0); 34 | } 35 | 36 | 37 | 38 | template 39 | inline 40 | const Glue 41 | cov(const Base& A, const Base& B, const uword norm_type = 0) 42 | { 43 | arma_extra_debug_sigprint(); 44 | 45 | arma_debug_check( (norm_type > 1), "ccov(): norm_type must be 0 or 1"); 46 | 47 | return Glue(A.get_ref(), B.get_ref(), norm_type); 48 | } 49 | 50 | 51 | 52 | //! @} 53 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/arma_extend/fn_inplace_reshape.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 NICTA and the authors listed below 2 | // http://nicta.com.au 3 | // 4 | // Authors: 5 | // - Ryan Curtin (ryan at igglybob dot com) 6 | // 7 | // This file is part of the Armadillo C++ library. 8 | // It is provided without any warranty of fitness 9 | // for any purpose. You can redistribute this file 10 | // and/or modify it under the terms of the GNU 11 | // Lesser General Public License (LGPL) as published 12 | // by the Free Software Foundation, either version 3 13 | // of the License or (at your option) any later version. 14 | // (see http://www.opensource.org/licenses for more info) 15 | 16 | 17 | //! \addtogroup fn_inplace_reshape 18 | //! @{ 19 | 20 | 21 | 22 | /** 23 | * This does not handle column vectors or row vectors entirely correctly. You 24 | * should be able to do multiplication or other basic operations with the 25 | * resulting matrix, but it may have other problems. So if you are using this 26 | * on vectors (arma::Col<> or arma::Row<>), be careful, and be warned that 27 | * bizarre behavior may occur. 28 | */ 29 | template 30 | inline 31 | Mat& 32 | inplace_reshape(Mat& X, 33 | const uword new_n_rows, 34 | const uword new_n_cols) 35 | { 36 | arma_extra_debug_sigprint(); 37 | 38 | arma_debug_check((new_n_rows * new_n_cols) != X.n_elem, 39 | "inplace_reshape(): cannot add or remove elements"); 40 | 41 | access::rw(X.n_rows) = new_n_rows; 42 | access::rw(X.n_cols) = new_n_cols; 43 | 44 | return X; 45 | } 46 | 47 | 48 | 49 | //! @} 50 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/arma_extend/glue_ccov_proto.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 NICTA and the authors listed below 2 | // http://nicta.com.au 3 | // 4 | // Authors: 5 | // - Conrad Sanderson (conradsand at ieee dot org) 6 | // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) 7 | // - Ryan Curtin (ryan at igglybob dot com) 8 | // 9 | // This file is part of the Armadillo C++ library. 10 | // It is provided without any warranty of fitness 11 | // for any purpose. You can redistribute this file 12 | // and/or modify it under the terms of the GNU 13 | // Lesser General Public License (LGPL) as published 14 | // by the Free Software Foundation, either version 3 15 | // of the License or (at your option) any later version. 16 | // (see http://www.opensource.org/licenses for more info) 17 | 18 | 19 | 20 | //! \addtogroup glue_ccov 21 | //! @{ 22 | 23 | class glue_ccov 24 | { 25 | public: 26 | 27 | template inline static void direct_ccov(Mat& out, const Mat& A, const Mat& B, const uword norm_type); 28 | template inline static void direct_ccov(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat< std::complex >& B, const uword norm_type); 29 | 30 | template inline static void apply(Mat& out, const Glue& X); 31 | }; 32 | 33 | //! @} 34 | 35 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/arma_extend/hdf5_misc.hpp: -------------------------------------------------------------------------------- 1 | // To hack in u64/s64 support to Armadillo when it is not compiled with 2 | // ARMA_64BIT_WORD. 3 | namespace hdf5_misc { 4 | 5 | #if defined(ARMA_USE_HDF5) 6 | #if !(defined(ARMA_64BIT_WORD) || defined(ARMA_USE_U64S64)) 7 | #if defined(ULLONG_MAX) 8 | template<> 9 | inline 10 | hid_t 11 | get_hdf5_type< long long >() 12 | { 13 | return H5Tcopy(H5T_NATIVE_LLONG); 14 | } 15 | 16 | template<> 17 | inline 18 | hid_t 19 | get_hdf5_type< unsigned long long >() 20 | { 21 | return H5Tcopy(H5T_NATIVE_ULLONG); 22 | } 23 | #endif 24 | #endif 25 | #endif 26 | 27 | } // namespace hdf5_misc 28 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/arma_extend/op_ccov_proto.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 NICTA and the authors listed below 2 | // http://nicta.com.au 3 | // 4 | // Authors: 5 | // - Conrad Sanderson (conradsand at ieee dot org) 6 | // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) 7 | // 8 | // This file is part of the Armadillo C++ library. 9 | // It is provided without any warranty of fitness 10 | // for any purpose. You can redistribute this file 11 | // and/or modify it under the terms of the GNU 12 | // Lesser General Public License (LGPL) as published 13 | // by the Free Software Foundation, either version 3 14 | // of the License or (at your option) any later version. 15 | // (see http://www.opensource.org/licenses for more info) 16 | 17 | 18 | 19 | //! \addtogroup op_cov 20 | //! @{ 21 | 22 | 23 | 24 | class op_ccov 25 | { 26 | public: 27 | 28 | template inline static void direct_ccov(Mat& out, const Mat& X, const uword norm_type); 29 | template inline static void direct_ccov(Mat< std::complex >& out, const Mat< std::complex >& X, const uword norm_type); 30 | 31 | template inline static void apply(Mat& out, const Op& in); 32 | }; 33 | 34 | 35 | 36 | //! @} 37 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/arma_extend/restrictors.hpp: -------------------------------------------------------------------------------- 1 | // Modifications to allow u64/s64 in Armadillo when ARMA_64BIT_WORD is not 2 | // defined. Only required on Armadillo < 3.6.2. 3 | #if (ARMA_VERSION_MAJOR < 3) || \ 4 | ((ARMA_VERSION_MAJOR == 3) && (ARMA_VERSION_MINOR < 6)) || \ 5 | ((ARMA_VERSION_MAJOR == 3) && (ARMA_VERSION_MINOR == 6) && \ 6 | (ARMA_VERSION_PATCH < 2)) 7 | #ifndef ARMA_64BIT_WORD 8 | 9 | template<> struct arma_scalar_only { typedef u64 result; }; 10 | template<> struct arma_scalar_only { typedef s64 result; }; 11 | 12 | template<> struct arma_integral_only { typedef u64 result; }; 13 | template<> struct arma_integral_only { typedef s64 result; }; 14 | 15 | template<> struct arma_unsigned_integral_only { typedef u64 result; }; 16 | 17 | template<> struct arma_signed_integral_only { typedef s64 result; }; 18 | 19 | template<> struct arma_signed_only { typedef s64 result; }; 20 | 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/arma_extend/traits.hpp: -------------------------------------------------------------------------------- 1 | // Extra traits to support u64 and s64 (or, specifically, unsigned long and 2 | // long) until that is applied to the Armadillo sources. 3 | 4 | // This isn't necessary if Armadillo was compiled with 64-bit support, or if 5 | // ARMA_USE_U64S64 is enabled, or if Armadillo >= 3.6.2 is used (by default 6 | // Armadillo 3.6.2 allows long types). 7 | #if (ARMA_VERSION_MAJOR < 3) || \ 8 | ((ARMA_VERSION_MAJOR == 3) && (ARMA_VERSION_MINOR < 6)) || \ 9 | ((ARMA_VERSION_MAJOR == 3) && (ARMA_VERSION_MINOR == 6) && \ 10 | (ARMA_VERSION_PATCH < 2)) 11 | #if !(defined(ARMA_64BIT_WORD) || defined(ARMA_USE_U64S64)) 12 | template 13 | struct is_u64 14 | { static const bool value = false; }; 15 | 16 | template<> 17 | struct is_u64 18 | { static const bool value = true; }; 19 | 20 | 21 | template 22 | struct is_s64 23 | { static const bool value = false; }; 24 | 25 | template<> 26 | struct is_s64 27 | { static const bool value = true; }; 28 | 29 | template<> 30 | struct is_supported_elem_type 31 | { 32 | static const bool value = true; 33 | }; 34 | 35 | template<> 36 | struct is_supported_elem_type 37 | { 38 | static const bool value = true; 39 | }; 40 | 41 | 42 | template<> 43 | struct is_signed 44 | { 45 | static const bool value = false; 46 | }; 47 | 48 | #endif 49 | #endif 50 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/arma_extend/typedef.hpp: -------------------------------------------------------------------------------- 1 | // Extensions to typedef u64 and s64 until that support is added into 2 | // Armadillo. We only need to typedef s64 on Armadillo > 1.2.0. This is not 3 | // necessary for Armadillo > 3.6.1. 4 | #if (ARMA_VERSION_MAJOR < 3) || \ 5 | ((ARMA_VERSION_MAJOR == 3) && (ARMA_VERSION_MINOR < 6)) || \ 6 | ((ARMA_VERSION_MAJOR == 3) && (ARMA_VERSION_MINOR == 6) && \ 7 | (ARMA_VERSION_PATCH < 2)) 8 | #ifndef ARMA_64BIT_WORD 9 | // We must typedef both u64 and s64. 10 | #if ULONG_MAX >= 0xffffffffffffffff 11 | typedef unsigned long u64; 12 | typedef long s64; 13 | #elif ULLONG_MAX >= 0xffffffffffffffff 14 | typedef unsigned long long u64; 15 | typedef long long s64; 16 | #else 17 | #error "don't know how to typedef 'u64' on this system" 18 | #endif 19 | 20 | namespace junk 21 | { 22 | struct arma_64_elem_size_test 23 | { 24 | arma_static_check( (sizeof(u64) != 8), ERROR___TYPE_U64_HAS_UNSUPPORTED_SIZE ); 25 | arma_static_check( (sizeof(s64) != 8), ERROR___TYPE_S64_HAS_UNSUPPORTED_SIZE ); 26 | }; 27 | } 28 | 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/kernels/cosine_distance.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file cosine_distance.hpp 3 | * @author Ryan Curtin 4 | * 5 | * This implements the cosine distance (or cosine similarity) between two 6 | * vectors, which is a measure of the angle between the two vectors. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_CORE_KERNELS_COSINE_DISTANCE_HPP 24 | #define __MLPACK_CORE_KERNELS_COSINE_DISTANCE_HPP 25 | 26 | #include 27 | 28 | namespace mlpack { 29 | namespace kernel { 30 | 31 | /** 32 | * The cosine distance (or cosine similarity). It is defined by 33 | * 34 | * @f[ 35 | * d(a, b) = \frac{a^T b}{|| a || || b ||} 36 | * @f] 37 | * 38 | * and this class assumes the standard L2 inner product. 39 | */ 40 | class CosineDistance 41 | { 42 | public: 43 | /** 44 | * Computes the cosine distance between two points. 45 | * 46 | * @param a First vector. 47 | * @param b Second vector. 48 | * @return d(a, b). 49 | */ 50 | template 51 | static double Evaluate(const VecType& a, const VecType& b); 52 | 53 | /** 54 | * Returns a string representation of this object. 55 | */ 56 | std::string ToString() const 57 | { 58 | std::ostringstream convert; 59 | convert << "CosineDistance [" << this << "]" << std::endl; 60 | return convert.str(); 61 | } 62 | }; 63 | 64 | //! Kernel traits for the cosine distance. 65 | template<> 66 | class KernelTraits 67 | { 68 | public: 69 | //! The cosine kernel is normalized: K(x, x) = 1 for all x. 70 | static const bool IsNormalized = true; 71 | }; 72 | 73 | }; // namespace kernel 74 | }; // namespace mlpack 75 | 76 | // Include implementation. 77 | #include "cosine_distance_impl.hpp" 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/kernels/cosine_distance_impl.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file cosine_distance_impl.hpp 3 | * @author Ryan Curtin 4 | * 5 | * This implements the cosine distance. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_CORE_KERNELS_COSINE_DISTANCE_IMPL_HPP 23 | #define __MLPACK_CORE_KERNELS_COSINE_DISTANCE_IMPL_HPP 24 | 25 | #include "cosine_distance.hpp" 26 | 27 | namespace mlpack { 28 | namespace kernel { 29 | 30 | template 31 | double CosineDistance::Evaluate(const VecType& a, const VecType& b) 32 | { 33 | // Since we are using the L2 inner product, this is easy. But we have to make 34 | // sure we aren't dividing by zero (if we are, then the cosine similarity is 35 | // 0: we reason this value because the cosine distance is just a normalized 36 | // dot product; take away the normalization, and if ||a|| or ||b|| is equal to 37 | // 0, then a^T b is zero too). 38 | const double denominator = norm(a, 2) * norm(b, 2); 39 | if (denominator == 0.0) 40 | return 0; 41 | else 42 | return dot(a, b) / denominator; 43 | } 44 | 45 | }; // namespace kernel 46 | }; // namespace mlpack 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/kernels/kernel_traits.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file kernel_traits.hpp 3 | * @author Ryan Curtin 4 | * 5 | * This provides the KernelTraits class, a template class to get information 6 | * about various kernels. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_CORE_KERNELS_KERNEL_TRAITS_HPP 24 | #define __MLPACK_CORE_KERNELS_KERNEL_TRAITS_HPP 25 | 26 | namespace mlpack { 27 | namespace kernel { 28 | 29 | /** 30 | * This is a template class that can provide information about various kernels. 31 | * By default, this class will provide the weakest possible assumptions on 32 | * kernels, and each kernel should override values as necessary. If a kernel 33 | * doesn't need to override a value, then there's no need to write a 34 | * KernelTraits specialization for that class. 35 | */ 36 | template 37 | class KernelTraits 38 | { 39 | public: 40 | /** 41 | * If true, then the kernel is normalized: K(x, x) = K(y, y) = 1 for all x. 42 | */ 43 | static const bool IsNormalized = false; 44 | }; 45 | 46 | }; // namespace kernel 47 | }; // namespace mlpack 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/kernels/linear_kernel.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file linear_kernel.hpp 3 | * @author Wei Guan 4 | * @author James Cline 5 | * @author Ryan Curtin 6 | * 7 | * Implementation of the linear kernel (just the standard dot product). 8 | * 9 | * This file is part of MLPACK 1.0.10. 10 | * 11 | * MLPACK is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free 13 | * Software Foundation, either version 3 of the License, or (at your option) any 14 | * later version. 15 | * 16 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 17 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 18 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 19 | * details (LICENSE.txt). 20 | * 21 | * You should have received a copy of the GNU General Public License along with 22 | * MLPACK. If not, see . 23 | */ 24 | #ifndef __MLPACK_CORE_KERNELS_LINEAR_KERNEL_HPP 25 | #define __MLPACK_CORE_KERNELS_LINEAR_KERNEL_HPP 26 | 27 | #include 28 | 29 | namespace mlpack { 30 | namespace kernel { 31 | 32 | /** 33 | * The simple linear kernel (dot product). For any two vectors @f$ x @f$ and 34 | * @f$ y @f$, 35 | * 36 | * @f[ 37 | * K(x, y) = x^T y 38 | * @f] 39 | * 40 | * This kernel has no parameters and therefore the evaluation can be static. 41 | */ 42 | class LinearKernel 43 | { 44 | public: 45 | /** 46 | * This constructor does nothing; the linear kernel has no parameters to 47 | * store. 48 | */ 49 | LinearKernel() { } 50 | 51 | /** 52 | * Simple evaluation of the dot product. This evaluation uses Armadillo's 53 | * dot() function. 54 | * 55 | * @tparam VecType Type of vector (should be arma::vec or arma::spvec). 56 | * @param a First vector. 57 | * @param b Second vector. 58 | * @return K(a, b). 59 | */ 60 | template 61 | static double Evaluate(const VecType& a, const VecType& b) 62 | { 63 | return arma::dot(a, b); 64 | } 65 | 66 | //! Return a string representation of the kernel. 67 | std::string ToString() const 68 | { 69 | std::ostringstream convert; 70 | convert << "LinearKernel [" << this << "]" << std::endl; 71 | return convert.str(); 72 | } 73 | }; 74 | 75 | }; // namespace kernel 76 | }; // namespace mlpack 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/math/clamp.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file clamp.hpp 3 | * 4 | * Miscellaneous math clamping routines. 5 | * 6 | * This file is part of MLPACK 1.0.10. 7 | * 8 | * MLPACK is free software: you can redistribute it and/or modify it under the 9 | * terms of the GNU Lesser General Public License as published by the Free 10 | * Software Foundation, either version 3 of the License, or (at your option) any 11 | * later version. 12 | * 13 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 15 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 16 | * details (LICENSE.txt). 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * MLPACK. If not, see . 20 | */ 21 | #ifndef __MLPACK_CORE_MATH_CLAMP_HPP 22 | #define __MLPACK_CORE_MATH_CLAMP_HPP 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace mlpack { 29 | namespace math /** Miscellaneous math routines. */ { 30 | 31 | /** 32 | * Forces a number to be non-negative, turning negative numbers into zero. 33 | * Avoids branching costs (this is a measurable improvement). 34 | * 35 | * @param d Double to clamp. 36 | * @return 0 if d < 0, d otherwise. 37 | */ 38 | inline double ClampNonNegative(const double d) 39 | { 40 | return (d + fabs(d)) / 2; 41 | } 42 | 43 | /** 44 | * Forces a number to be non-positive, turning positive numbers into zero. 45 | * Avoids branching costs (this is a measurable improvement). 46 | * 47 | * @param d Double to clamp. 48 | * @param 0 if d > 0, d otherwise. 49 | */ 50 | inline double ClampNonPositive(const double d) 51 | { 52 | return (d - fabs(d)) / 2; 53 | } 54 | 55 | /** 56 | * Clamp a number between a particular range. 57 | * 58 | * @param value The number to clamp. 59 | * @param rangeMin The first of the range. 60 | * @param rangeMax The last of the range. 61 | * @return max(rangeMin, min(rangeMax, d)). 62 | */ 63 | inline double ClampRange(double value, 64 | const double rangeMin, 65 | const double rangeMax) 66 | { 67 | value -= rangeMax; 68 | value = ClampNonPositive(value) + rangeMax; 69 | value -= rangeMin; 70 | value = ClampNonNegative(value) + rangeMin; 71 | return value; 72 | } 73 | 74 | }; // namespace math 75 | }; // namespace mlpack 76 | 77 | #endif // __MLPACK_CORE_MATH_CLAMP_HPP 78 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/math/round.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file round.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Implementation of round() for use on Visual Studio, where C99 isn't 6 | * implemented. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_CORE_MATH_ROUND_HPP 24 | #define __MLPACK_CORE_MATH_ROUND_HPP 25 | 26 | // _MSC_VER should only be defined for Visual Studio, which doesn't implement 27 | // C99. 28 | #ifdef _MSC_VER 29 | 30 | // This function ends up going into the global namespace, so it can be used in 31 | // place of C99's round(). 32 | 33 | //! Round a number to the nearest integer. 34 | inline double round(double a) 35 | { 36 | return floor(a + 0.5); 37 | } 38 | 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/metrics/ip_metric.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ip_metric.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Inner product induced metric. If given a kernel function, this gives the 6 | * complementary metric. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_METHODS_FASTMKS_IP_METRIC_HPP 24 | #define __MLPACK_METHODS_FASTMKS_IP_METRIC_HPP 25 | 26 | namespace mlpack { 27 | namespace metric { 28 | 29 | template 30 | class IPMetric 31 | { 32 | public: 33 | //! Create the IPMetric without an instantiated kernel. 34 | IPMetric(); 35 | 36 | //! Create the IPMetric with an instantiated kernel. 37 | IPMetric(KernelType& kernel); 38 | 39 | //! Destroy the IPMetric object. 40 | ~IPMetric(); 41 | 42 | /** 43 | * Evaluate the metric. 44 | */ 45 | template 46 | double Evaluate(const Vec1Type& a, const Vec2Type& b); 47 | 48 | //! Get the kernel. 49 | const KernelType& Kernel() const { return kernel; } 50 | //! Modify the kernel. 51 | KernelType& Kernel() { return kernel; } 52 | /** 53 | * Returns a string representation of this object. 54 | */ 55 | std::string ToString() const; 56 | private: 57 | //! The locally stored kernel, if it is necessary. 58 | KernelType* localKernel; 59 | //! The reference to the kernel that is being used. 60 | KernelType& kernel; 61 | }; 62 | 63 | }; // namespace metric 64 | }; // namespace mlpack 65 | 66 | // Include implementation. 67 | #include "ip_metric_impl.hpp" 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/optimizers/sgd/test_function.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file test_function.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Very simple test function for SGD. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_CORE_OPTIMIZERS_SGD_TEST_FUNCTION_HPP 23 | #define __MLPACK_CORE_OPTIMIZERS_SGD_TEST_FUNCTION_HPP 24 | 25 | #include 26 | 27 | namespace mlpack { 28 | namespace optimization { 29 | namespace test { 30 | 31 | //! Very, very simple test function which is the composite of three other 32 | //! functions. It turns out that although this function is very simple, 33 | //! optimizing it fully can take a very long time. It seems to take in excess 34 | //! of 10 million iterations with a step size of 0.0005. 35 | class SGDTestFunction 36 | { 37 | public: 38 | //! Nothing to do for the constructor. 39 | SGDTestFunction() { } 40 | 41 | //! Return 3 (the number of functions). 42 | size_t NumFunctions() const { return 3; } 43 | 44 | //! Get the starting point. 45 | arma::mat GetInitialPoint() const { return arma::mat("6; -45.6; 6.2"); } 46 | 47 | //! Evaluate a function. 48 | double Evaluate(const arma::mat& coordinates, const size_t i) const; 49 | 50 | //! Evaluate the gradient of a function. 51 | void Gradient(const arma::mat& coordinates, 52 | const size_t i, 53 | arma::mat& gradient) const; 54 | }; 55 | 56 | }; // namespace test 57 | }; // namespace optimization 58 | }; // namespace mlpack 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/tree/binary_space_tree.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file binary_space_tree.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Include all the necessary files to use the BinarySpaceTree class. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_CORE_TREE_BINARY_SPACE_TREE_HPP 23 | #define __MLPACK_CORE_TREE_BINARY_SPACE_TREE_HPP 24 | 25 | #include "bounds.hpp" 26 | #include "binary_space_tree/binary_space_tree.hpp" 27 | #include "binary_space_tree/single_tree_traverser.hpp" 28 | #include "binary_space_tree/single_tree_traverser_impl.hpp" 29 | #include "binary_space_tree/dual_tree_traverser.hpp" 30 | #include "binary_space_tree/dual_tree_traverser_impl.hpp" 31 | #include "binary_space_tree/traits.hpp" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/tree/binary_space_tree/traits.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file traits.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Specialization of the TreeTraits class for the BinarySpaceTree type of tree. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_CORE_TREE_BINARY_SPACE_TREE_TRAITS_HPP 23 | #define __MLPACK_CORE_TREE_BINARY_SPACE_TREE_TRAITS_HPP 24 | 25 | #include 26 | 27 | namespace mlpack { 28 | namespace tree { 29 | 30 | /** 31 | * This is a specialization of the TreeType class to the BinarySpaceTree tree 32 | * type. It defines characteristics of the binary space tree, and is used to 33 | * help write tree-independent (but still optimized) tree-based algorithms. See 34 | * mlpack/core/tree/tree_traits.hpp for more information. 35 | */ 36 | template 39 | class TreeTraits > 40 | { 41 | public: 42 | /** 43 | * Each binary space tree node has two children which represent 44 | * non-overlapping subsets of the space which the node represents. Therefore, 45 | * children are not overlapping. 46 | */ 47 | static const bool HasOverlappingChildren = false; 48 | 49 | /** 50 | * There is no guarantee that the first point in a node is its centroid. 51 | */ 52 | static const bool FirstPointIsCentroid = false; 53 | 54 | /** 55 | * Points are not contained at multiple levels of the binary space tree. 56 | */ 57 | static const bool HasSelfChildren = false; 58 | 59 | /** 60 | * Points are rearranged during building of the tree. 61 | */ 62 | static const bool RearrangesDataset = true; 63 | }; 64 | 65 | }; // namespace tree 66 | }; // namespace mlpack 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/tree/bounds.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file bounds.hpp 3 | * 4 | * Bounds that are useful for binary space partitioning trees. 5 | * 6 | * This file is part of MLPACK 1.0.10. 7 | * 8 | * MLPACK is free software: you can redistribute it and/or modify it under the 9 | * terms of the GNU Lesser General Public License as published by the Free 10 | * Software Foundation, either version 3 of the License, or (at your option) any 11 | * later version. 12 | * 13 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 15 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 16 | * details (LICENSE.txt). 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * MLPACK. If not, see . 20 | */ 21 | 22 | #ifndef __MLPACK_CORE_TREE_BOUNDS_HPP 23 | #define __MLPACK_CORE_TREE_BOUNDS_HPP 24 | 25 | #include 26 | #include 27 | 28 | #include "hrectbound.hpp" 29 | #include "ballbound.hpp" 30 | 31 | #endif // __MLPACK_CORE_TREE_BOUNDS_HPP 32 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/tree/cover_tree.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file cover_tree.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Includes all the necessary files to use the CoverTree class. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_CORE_TREE_COVER_TREE_HPP 23 | #define __MLPACK_CORE_TREE_COVER_TREE_HPP 24 | 25 | #include "bounds.hpp" 26 | #include "cover_tree/cover_tree.hpp" 27 | #include "cover_tree/single_tree_traverser.hpp" 28 | #include "cover_tree/single_tree_traverser_impl.hpp" 29 | #include "cover_tree/dual_tree_traverser.hpp" 30 | #include "cover_tree/dual_tree_traverser_impl.hpp" 31 | #include "cover_tree/traits.hpp" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/tree/cover_tree/first_point_is_root.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file first_point_is_root.hpp 3 | * @author Ryan Curtin 4 | * 5 | * A very simple policy for the cover tree; the first point in the dataset is 6 | * chosen as the root of the cover tree. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_CORE_TREE_FIRST_POINT_IS_ROOT_HPP 24 | #define __MLPACK_CORE_TREE_FIRST_POINT_IS_ROOT_HPP 25 | 26 | #include 27 | 28 | namespace mlpack { 29 | namespace tree { 30 | 31 | /** 32 | * This class is meant to be used as a choice for the policy class 33 | * RootPointPolicy of the CoverTree class. This policy determines which point 34 | * is used for the root node of the cover tree. This particular implementation 35 | * simply chooses the first point in the dataset as the root. A more complex 36 | * implementation might choose, for instance, the point with least maximum 37 | * distance to other points (the closest to the "middle"). 38 | */ 39 | class FirstPointIsRoot 40 | { 41 | public: 42 | /** 43 | * Return the point to be used as the root point of the cover tree. This just 44 | * returns 0. 45 | */ 46 | static size_t ChooseRoot(const arma::mat& /* dataset */) { return 0; } 47 | }; 48 | 49 | }; // namespace tree 50 | }; // namespace mlpack 51 | 52 | #endif // __MLPACK_CORE_TREE_FIRST_POINT_IS_ROOT_HPP 53 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/tree/cover_tree/traits.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file traits.hpp 3 | * @author Ryan Curtin 4 | * 5 | * This file contains the specialization of the TreeTraits class for the 6 | * CoverTree type of tree. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_CORE_TREE_COVER_TREE_TRAITS_HPP 24 | #define __MLPACK_CORE_TREE_COVER_TREE_TRAITS_HPP 25 | 26 | #include 27 | 28 | namespace mlpack { 29 | namespace tree { 30 | 31 | /** 32 | * The specialization of the TreeTraits class for the CoverTree tree type. It 33 | * defines characteristics of the cover tree, and is used to help write 34 | * tree-independent (but still optimized) tree-based algorithms. See 35 | * mlpack/core/tree/tree_traits.hpp for more information. 36 | */ 37 | template 40 | class TreeTraits > 41 | { 42 | public: 43 | /** 44 | * The cover tree (or, this implementation of it) does not require that 45 | * children represent non-overlapping subsets of the parent node. 46 | */ 47 | static const bool HasOverlappingChildren = true; 48 | 49 | /** 50 | * Each cover tree node contains only one point, and that point is its 51 | * centroid. 52 | */ 53 | static const bool FirstPointIsCentroid = true; 54 | 55 | /** 56 | * Cover trees do have self-children. 57 | */ 58 | static const bool HasSelfChildren = true; 59 | 60 | /** 61 | * Points are not rearranged when the tree is built. 62 | */ 63 | static const bool RearrangesDataset = false; 64 | }; 65 | 66 | }; // namespace tree 67 | }; // namespace mlpack 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/tree/rectangle_tree.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file rectangle_tree.hpp 3 | * @author Andrew Wells 4 | * 5 | * Include all the necessary filse to use the Rectangle Type Trees (RTree, RStarTree, XTree, 6 | * and HilbertRTree.) 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_CORE_TREE_RECTANGLE_TREE_HPP 24 | #define __MLPACK_CORE_TREE_RECTANGLE_TREE_HPP 25 | 26 | /* we include bounds.hpp since it gives us the necessary files. 27 | * However, we will not use the "ballbounds" option. 28 | */ 29 | #include "bounds.hpp" 30 | #include "rectangle_tree/rectangle_tree.hpp" 31 | #include "rectangle_tree/single_tree_traverser.hpp" 32 | #include "rectangle_tree/single_tree_traverser_impl.hpp" 33 | #include "rectangle_tree/dual_tree_traverser.hpp" 34 | #include "rectangle_tree/dual_tree_traverser_impl.hpp" 35 | #include "rectangle_tree/r_tree_split.hpp" 36 | #include "rectangle_tree/r_star_tree_split.hpp" 37 | #include "rectangle_tree/r_tree_descent_heuristic.hpp" 38 | #include "rectangle_tree/r_star_tree_descent_heuristic.hpp" 39 | #include "rectangle_tree/traits.hpp" 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/tree/statistic.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file statistic.hpp 3 | * 4 | * Definition of the policy type for the statistic class. 5 | * 6 | * You should define your own statistic that looks like EmptyStatistic. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | 24 | #ifndef __MLPACK_CORE_TREE_STATISTIC_HPP 25 | #define __MLPACK_CORE_TREE_STATISTIC_HPP 26 | 27 | namespace mlpack { 28 | namespace tree { 29 | 30 | /** 31 | * Empty statistic if you are not interested in storing statistics in your 32 | * tree. Use this as a template for your own. 33 | */ 34 | class EmptyStatistic 35 | { 36 | public: 37 | EmptyStatistic() { } 38 | ~EmptyStatistic() { } 39 | 40 | /** 41 | * This constructor is called when a node is finished being created. The 42 | * node is finished, and its children are finished, but it is not 43 | * necessarily true that the statistics of other nodes are initialized yet. 44 | * 45 | * @param node Node which this corresponds to. 46 | */ 47 | template 48 | EmptyStatistic(TreeType& /* node */) { } 49 | 50 | public: 51 | /** 52 | * Returns a string representation of this object. 53 | */ 54 | std::string ToString() const 55 | { 56 | std::stringstream convert; 57 | convert << "EmptyStatistic [" << this << "]" << std::endl; 58 | return convert.str(); 59 | } 60 | }; 61 | 62 | }; // namespace tree 63 | }; // namespace mlpack 64 | 65 | #endif // __MLPACK_CORE_TREE_STATISTIC_HPP 66 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/util/option_impl.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file option_impl.hpp 3 | * @author Matthew Amidon 4 | * 5 | * Implementation of template functions for the Option class. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_CORE_UTIL_OPTION_IMPL_HPP 23 | #define __MLPACK_CORE_UTIL_OPTION_IMPL_HPP 24 | 25 | // Just in case it has not been included. 26 | #include "option.hpp" 27 | 28 | namespace mlpack { 29 | namespace util { 30 | 31 | /** 32 | * Registers a parameter with CLI. 33 | */ 34 | template 35 | Option::Option(bool ignoreTemplate, 36 | N defaultValue, 37 | const std::string& identifier, 38 | const std::string& description, 39 | const std::string& alias, 40 | bool required) 41 | { 42 | if (ignoreTemplate) 43 | { 44 | CLI::Add(identifier, description, alias, required); 45 | } 46 | else 47 | { 48 | CLI::Add(identifier, description, alias, required); 49 | CLI::GetParam(identifier) = defaultValue; 50 | } 51 | } 52 | 53 | 54 | /** 55 | * Registers a flag parameter with CLI. 56 | */ 57 | template 58 | Option::Option(const std::string& identifier, 59 | const std::string& description, 60 | const std::string& alias) 61 | { 62 | CLI::AddFlag(identifier, description, alias); 63 | } 64 | 65 | }; // namespace util 66 | }; // namespace mlpack 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/util/string_util.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file string_util.hpp 3 | * @author Trironk Kiatkungwanglai 4 | * @author Ryan Birmingham 5 | * 6 | * Declares methods that are useful for writing formatting output. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_CORE_STRING_UTIL_HPP 24 | #define __MLPACK_CORE_STRING_UTIL_HPP 25 | 26 | #include 27 | 28 | namespace mlpack { 29 | namespace util { 30 | 31 | //! A utility function that replaces all all newlines with a number of spaces 32 | //! depending on the indentation level. 33 | std::string Indent(std::string input, const size_t howManyTabs = 1); 34 | 35 | }; // namespace util 36 | }; // namespace mlpack 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /inst/include/mlpack/core/util/version.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file version.hpp 3 | * @author Ryan Curtin 4 | * 5 | * The current version of mlpack, available as macros and as a string. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_CORE_UTIL_VERSION_HPP 23 | #define __MLPACK_CORE_UTIL_VERSION_HPP 24 | 25 | #include 26 | 27 | // The version of mlpack. If this is svn trunk, this will be a version with 28 | // higher number than the most recent release. 29 | #define __MLPACK_VERSION_MAJOR 1 30 | #define __MLPACK_VERSION_MINOR 0 31 | #define __MLPACK_VERSION_PATCH 9 32 | 33 | // The name of the version (for use by --version). 34 | namespace mlpack { 35 | namespace util { 36 | 37 | /** 38 | * This will return either "mlpack x.y.z" or "mlpack trunk-rXXXXX" depending on 39 | * whether or not this is a stable version of mlpack or an svn revision. 40 | */ 41 | std::string GetVersion(); 42 | 43 | }; // namespace util 44 | }; // namespace mlpack 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/amf/init_rules/random_init.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file random_init.hpp 3 | * @author Mohan Rajendran 4 | * 5 | * Intialization rule for Non-Negative Matrix Factorization (NMF). This simple 6 | * initialization is performed by assigning a random matrix to W and H. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_METHODS_LMF_RANDOM_INIT_HPP 24 | #define __MLPACK_METHODS_LMF_RANDOM_INIT_HPP 25 | 26 | #include 27 | 28 | namespace mlpack { 29 | namespace amf { 30 | 31 | class RandomInitialization 32 | { 33 | public: 34 | // Empty constructor required for the InitializeRule template 35 | RandomInitialization() { } 36 | 37 | template 38 | inline static void Initialize(const MatType& V, 39 | const size_t r, 40 | arma::mat& W, 41 | arma::mat& H) 42 | { 43 | // Simple implementation (left in the header file due to its simplicity). 44 | size_t n = V.n_rows; 45 | size_t m = V.n_cols; 46 | 47 | // Intialize to random values. 48 | W.randu(n, r); 49 | H.randu(r, m); 50 | } 51 | }; 52 | 53 | }; // namespace amf 54 | }; // namespace mlpack 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/amf/termination_policies/complete_incremental.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file complete_incremental_termination_hpp 3 | * @author Sumedh Ghaisas 4 | * 5 | * Complete incremental learning termination policy. 6 | * 7 | * This file is part of MLPACK 1.0.9. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED 23 | #define COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED 24 | 25 | namespace mlpack 26 | { 27 | namespace amf 28 | { 29 | 30 | template 31 | class CompleteIncrementalTermination 32 | { 33 | public: 34 | CompleteIncrementalTermination(TerminationPolicy t_policy = TerminationPolicy()) 35 | : t_policy(t_policy) {} 36 | 37 | template 38 | void Initialize(const MatType& V) 39 | { 40 | t_policy.Initialize(V); 41 | 42 | incrementalIndex = accu(V != 0); 43 | iteration = 0; 44 | } 45 | 46 | void Initialize(const arma::sp_mat& V) 47 | { 48 | t_policy.Initialize(V); 49 | 50 | incrementalIndex = V.n_nonzero; 51 | iteration = 0; 52 | } 53 | 54 | bool IsConverged(arma::mat& W, arma::mat& H) 55 | { 56 | iteration++; 57 | if(iteration % incrementalIndex == 0) 58 | return t_policy.IsConverged(W, H); 59 | else return false; 60 | } 61 | 62 | const double& Index() 63 | { 64 | return t_policy.Index(); 65 | } 66 | const size_t& Iteration() 67 | { 68 | return iteration; 69 | } 70 | 71 | const size_t& MaxIterations() 72 | { 73 | return t_policy.MaxIterations(); 74 | } 75 | 76 | private: 77 | TerminationPolicy t_policy; 78 | 79 | size_t incrementalIndex; 80 | size_t iteration; 81 | }; 82 | 83 | } // namespace amf 84 | } // namespace mlpack 85 | 86 | 87 | #endif // COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED 88 | 89 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/amf/termination_policies/complete_incremental_termination.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file complete_incremental_termination_hpp 3 | * @author Sumedh Ghaisas 4 | * 5 | * Complete incremental learning termination policy. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED 23 | #define COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED 24 | 25 | namespace mlpack 26 | { 27 | namespace amf 28 | { 29 | 30 | template 31 | class CompleteIncrementalTermination 32 | { 33 | public: 34 | CompleteIncrementalTermination(TerminationPolicy t_policy = TerminationPolicy()) 35 | : t_policy(t_policy) {} 36 | 37 | template 38 | void Initialize(const MatType& V) 39 | { 40 | t_policy.Initialize(V); 41 | 42 | incrementalIndex = accu(V != 0); 43 | iteration = 0; 44 | } 45 | 46 | void Initialize(const arma::sp_mat& V) 47 | { 48 | t_policy.Initialize(V); 49 | 50 | incrementalIndex = V.n_nonzero; 51 | iteration = 0; 52 | } 53 | 54 | bool IsConverged(arma::mat& W, arma::mat& H) 55 | { 56 | iteration++; 57 | if(iteration % incrementalIndex == 0) 58 | return t_policy.IsConverged(W, H); 59 | else return false; 60 | } 61 | 62 | const double& Index() 63 | { 64 | return t_policy.Index(); 65 | } 66 | const size_t& Iteration() 67 | { 68 | return iteration; 69 | } 70 | 71 | const size_t& MaxIterations() 72 | { 73 | return t_policy.MaxIterations(); 74 | } 75 | 76 | private: 77 | TerminationPolicy t_policy; 78 | 79 | size_t incrementalIndex; 80 | size_t iteration; 81 | }; 82 | 83 | } // namespace amf 84 | } // namespace mlpack 85 | 86 | 87 | #endif // COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED 88 | 89 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/amf/termination_policies/incomplete_incremental.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file incomplete_incremental_termination.hpp 3 | * @author Sumedh Ghaisas 4 | * 5 | * This file is part of MLPACK 1.0.9. 6 | * 7 | * MLPACK is free software: you can redistribute it and/or modify it under the 8 | * terms of the GNU Lesser General Public License as published by the Free 9 | * Software Foundation, either version 3 of the License, or (at your option) any 10 | * later version. 11 | * 12 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 13 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 14 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 15 | * details (LICENSE.txt). 16 | * 17 | * You should have received a copy of the GNU General Public License along with 18 | * MLPACK. If not, see . 19 | */ 20 | #ifndef _INCOMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED 21 | #define _INCOMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED 22 | 23 | #include 24 | 25 | namespace mlpack { 26 | namespace amf { 27 | 28 | template 29 | class IncompleteIncrementalTermination 30 | { 31 | public: 32 | IncompleteIncrementalTermination(TerminationPolicy t_policy = TerminationPolicy()) 33 | : t_policy(t_policy) {} 34 | 35 | template 36 | void Initialize(const MatType& V) 37 | { 38 | t_policy.Initialize(V); 39 | 40 | incrementalIndex = V.n_rows; 41 | iteration = 0; 42 | } 43 | 44 | bool IsConverged(arma::mat& W, arma::mat& H) 45 | { 46 | iteration++; 47 | if(iteration % incrementalIndex == 0) 48 | return t_policy.IsConverged(W, H); 49 | else return false; 50 | } 51 | 52 | const double& Index() 53 | { 54 | return t_policy.Index(); 55 | } 56 | const size_t& Iteration() 57 | { 58 | return iteration; 59 | } 60 | const size_t& MaxIterations() 61 | { 62 | return t_policy.MaxIterations(); 63 | } 64 | 65 | private: 66 | TerminationPolicy t_policy; 67 | 68 | size_t incrementalIndex; 69 | size_t iteration; 70 | }; 71 | 72 | }; // namespace amf 73 | }; // namespace mlpack 74 | 75 | #endif 76 | 77 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/gmm/diagonal_constraint.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file diagonal_constraint.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Constrain a covariance matrix to be diagonal. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_METHODS_GMM_DIAGONAL_CONSTRAINT_HPP 23 | #define __MLPACK_METHODS_GMM_DIAGONAL_CONSTRAINT_HPP 24 | 25 | #include 26 | 27 | namespace mlpack { 28 | namespace gmm { 29 | 30 | /** 31 | * Force a covariance matrix to be diagonal. 32 | */ 33 | class DiagonalConstraint 34 | { 35 | public: 36 | //! Force a covariance matrix to be diagonal. 37 | static void ApplyConstraint(arma::mat& covariance) 38 | { 39 | // Save the diagonal only. 40 | arma::vec diagonal = covariance.diag(); 41 | covariance = arma::diagmat(diagonal); 42 | } 43 | }; 44 | 45 | }; // namespace gmm 46 | }; // namespace mlpack 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/gmm/no_constraint.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file no_constraint.hpp 3 | * @author Ryan Curtin 4 | * 5 | * No constraint on the covariance matrix. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_METHODS_GMM_NO_CONSTRAINT_HPP 23 | #define __MLPACK_METHODS_GMM_NO_CONSTRAINT_HPP 24 | 25 | #include 26 | 27 | namespace mlpack { 28 | namespace gmm { 29 | 30 | /** 31 | * This class enforces no constraint on the covariance matrix. It's faster this 32 | * way, although depending on your situation you may end up with a 33 | * non-invertible covariance matrix. 34 | */ 35 | class NoConstraint 36 | { 37 | public: 38 | //! Do nothing, and do not modify the covariance matrix. 39 | static void ApplyConstraint(const arma::mat& /* covariance */) { } 40 | }; 41 | 42 | }; // namespace gmm 43 | }; // namespace mlpack 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/gmm/positive_definite_constraint.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file positive_definite_constraint.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Restricts a covariance matrix to being positive definite. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_METHODS_GMM_POSITIVE_DEFINITE_CONSTRAINT_HPP 23 | #define __MLPACK_METHODS_GMM_POSITIVE_DEFINITE_CONSTRAINT_HPP 24 | 25 | #include 26 | 27 | namespace mlpack { 28 | namespace gmm { 29 | 30 | /** 31 | * Given a covariance matrix, force the matrix to be positive definite. 32 | */ 33 | class PositiveDefiniteConstraint 34 | { 35 | public: 36 | /** 37 | * Apply the positive definiteness constraint to the given covariance matrix. 38 | * 39 | * @param covariance Covariance matrix. 40 | */ 41 | static void ApplyConstraint(arma::mat& covariance) 42 | { 43 | // TODO: make this more efficient. 44 | if (arma::det(covariance) <= 1e-50) 45 | { 46 | Rcpp::Rcout << "Covariance matrix is not positive definite. Adding " 47 | << "perturbation." << std::endl; 48 | 49 | double perturbation = 1e-30; 50 | while (arma::det(covariance) <= 1e-50) 51 | { 52 | covariance.diag() += perturbation; 53 | perturbation *= 10; 54 | } 55 | } 56 | } 57 | }; 58 | 59 | }; // namespace gmm 60 | }; // namespace mlpack 61 | 62 | #endif 63 | 64 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/hmm/hmm_util.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file hmm_util.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Save/load utilities for HMMs. This should be eventually merged into the HMM 6 | * class itself. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_METHODS_HMM_HMM_UTIL_HPP 24 | #define __MLPACK_METHODS_HMM_HMM_UTIL_HPP 25 | 26 | #include "hmm.hpp" 27 | 28 | namespace mlpack { 29 | namespace hmm { 30 | 31 | /** 32 | * Save an HMM to file. This only works for GMMs, DiscreteDistributions, and 33 | * GaussianDistributions. 34 | * 35 | * @tparam Distribution Distribution type of HMM. 36 | * @param sr SaveRestoreUtility to use. 37 | */ 38 | template 39 | void SaveHMM(const HMM& hmm, util::SaveRestoreUtility& sr); 40 | 41 | /** 42 | * Load an HMM from file. This only works for GMMs, DiscreteDistributions, and 43 | * GaussianDistributions. 44 | * 45 | * @tparam Distribution Distribution type of HMM. 46 | * @param sr SaveRestoreUtility to use. 47 | */ 48 | template 49 | void LoadHMM(HMM& hmm, util::SaveRestoreUtility& sr); 50 | 51 | }; // namespace hmm 52 | }; // namespace mlpack 53 | 54 | // Include implementation. 55 | #include "hmm_util_impl.hpp" 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/kmeans/allow_empty_clusters.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file allow_empty_clusters.hpp 3 | * @author Ryan Curtin 4 | * 5 | * This very simple policy is used when K-Means is allowed to return empty 6 | * clusters. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_METHODS_KMEANS_ALLOW_EMPTY_CLUSTERS_HPP 24 | #define __MLPACK_METHODS_KMEANS_ALLOW_EMPTY_CLUSTERS_HPP 25 | 26 | #include 27 | 28 | namespace mlpack { 29 | namespace kmeans { 30 | 31 | /** 32 | * Policy which allows K-Means to create empty clusters without any error being 33 | * reported. 34 | */ 35 | class AllowEmptyClusters 36 | { 37 | public: 38 | //! Default constructor required by EmptyClusterPolicy policy. 39 | AllowEmptyClusters() { } 40 | 41 | /** 42 | * This function does nothing. It is called by K-Means when K-Means detects 43 | * an empty cluster. 44 | * 45 | * @tparam MatType Type of data (arma::mat or arma::spmat). 46 | * @param data Dataset on which clustering is being performed. 47 | * @param emptyCluster Index of cluster which is empty. 48 | * @param centroids Centroids of each cluster (one per column). 49 | * @param clusterCounts Number of points in each cluster. 50 | * @param assignments Cluster assignments of each point. 51 | * 52 | * @return Number of points changed (0). 53 | */ 54 | template 55 | static size_t EmptyCluster(const MatType& /* data */, 56 | const size_t /* emptyCluster */, 57 | const MatType& /* centroids */, 58 | arma::Col& /* clusterCounts */, 59 | arma::Col& /* assignments */) 60 | { 61 | // Empty clusters are okay! Do nothing. 62 | return 0; 63 | } 64 | }; 65 | 66 | }; // namespace kmeans 67 | }; // namespace mlpack 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/mvu/mvu.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file mvu.hpp 3 | * @author Ryan Curtin 4 | * 5 | * An implementation of Maximum Variance Unfolding. This file defines an MVU 6 | * class as well as a class representing the objective function (a semidefinite 7 | * program) which MVU seeks to minimize. Minimization is performed by the 8 | * Augmented Lagrangian optimizer (which in turn uses the L-BFGS optimizer). 9 | * 10 | * Note: this implementation of MVU does not work. See #189. 11 | * 12 | * This file is part of MLPACK 1.0.10. 13 | * 14 | * MLPACK is free software: you can redistribute it and/or modify it under the 15 | * terms of the GNU Lesser General Public License as published by the Free 16 | * Software Foundation, either version 3 of the License, or (at your option) any 17 | * later version. 18 | * 19 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 20 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 21 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 22 | * details (LICENSE.txt). 23 | * 24 | * You should have received a copy of the GNU General Public License along with 25 | * MLPACK. If not, see . 26 | */ 27 | #ifndef __MLPACK_METHODS_MVU_MVU_HPP 28 | #define __MLPACK_METHODS_MVU_MVU_HPP 29 | 30 | #include 31 | 32 | namespace mlpack { 33 | namespace mvu { 34 | 35 | /** 36 | * The MVU class is meant to provide a good abstraction for users. The dataset 37 | * needs to be provided, as well as several parameters. 38 | * 39 | * - dataset 40 | * - new dimensionality 41 | */ 42 | class MVU 43 | { 44 | public: 45 | MVU(const arma::mat& dataIn); 46 | 47 | void Unfold(const size_t newDim, 48 | const size_t numNeighbors, 49 | arma::mat& outputCoordinates); 50 | 51 | private: 52 | const arma::mat& data; 53 | }; 54 | 55 | }; // namespace mvu 56 | }; // namespace mlpack 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/neighbor_search/typedef.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file typedef.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Simple typedefs describing template instantiations of the NeighborSearch 6 | * class which are commonly used. This is meant to be included by 7 | * neighbor_search.h but is a separate file for simplicity. 8 | * 9 | * This file is part of MLPACK 1.0.10. 10 | * 11 | * MLPACK is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free 13 | * Software Foundation, either version 3 of the License, or (at your option) any 14 | * later version. 15 | * 16 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 17 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 18 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 19 | * details (LICENSE.txt). 20 | * 21 | * You should have received a copy of the GNU General Public License along with 22 | * MLPACK. If not, see . 23 | */ 24 | #ifndef __MLPACK_NEIGHBOR_SEARCH_TYPEDEF_H 25 | #define __MLPACK_NEIGHBOR_SEARCH_TYPEDEF_H 26 | 27 | // In case someone included this directly. 28 | #include "neighbor_search.hpp" 29 | 30 | #include 31 | 32 | #include "sort_policies/nearest_neighbor_sort.hpp" 33 | #include "sort_policies/furthest_neighbor_sort.hpp" 34 | 35 | namespace mlpack { 36 | namespace neighbor { 37 | 38 | /** 39 | * The AllkNN class is the all-k-nearest-neighbors method. It returns L2 40 | * distances (Euclidean distances) for each of the k nearest neighbors. 41 | */ 42 | typedef NeighborSearch AllkNN; 43 | 44 | /** 45 | * The AllkFN class is the all-k-furthest-neighbors method. It returns L2 46 | * distances (Euclidean distances) for each of the k furthest neighbors. 47 | */ 48 | typedef NeighborSearch AllkFN; 49 | 50 | }; // namespace neighbor 51 | }; // namespace mlpack 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/nystroem_method/kmeans_selection.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file kmeans_selection.hpp 3 | * @author Marcus Edel 4 | * 5 | * Use the centroids of the K-Means clustering method for use in the Nystroem 6 | * method of kernel matrix approximation. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_METHODS_NYSTROEM_METHOD_KMEANS_SELECTION_HPP 24 | #define __MLPACK_METHODS_NYSTROEM_METHOD_KMEANS_SELECTION_HPP 25 | 26 | #include 27 | #include 28 | 29 | namespace mlpack { 30 | namespace kernel { 31 | 32 | template > 33 | class KMeansSelection 34 | { 35 | public: 36 | /** 37 | * Use the K-Means clustering method to select the specified number of points 38 | * in the dataset. You are responsible for deleting the returned matrix! 39 | * 40 | * @param data Dataset to sample from. 41 | * @param m Number of points to select. 42 | * @return Matrix pointer in which centroids are stored. 43 | */ 44 | const static arma::mat* Select(const arma::mat& data, 45 | const size_t m, 46 | const size_t maxIterations = 5) 47 | { 48 | arma::Col assignments; 49 | arma::mat* centroids = new arma::mat; 50 | 51 | // Perform the K-Means clustering method. 52 | ClusteringType kmeans(maxIterations); 53 | kmeans.Cluster(data, m, assignments, *centroids); 54 | 55 | return centroids; 56 | } 57 | }; 58 | 59 | }; // namespace kernel 60 | }; // namespace mlpack 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/nystroem_method/ordered_selection.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ordered_selection.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Select the first points of the dataset for use in the Nystroem method of 6 | * kernel matrix approximation. This is mostly for testing, but might have 7 | * other uses. 8 | * 9 | * This file is part of MLPACK 1.0.10. 10 | * 11 | * MLPACK is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free 13 | * Software Foundation, either version 3 of the License, or (at your option) any 14 | * later version. 15 | * 16 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 17 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 18 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 19 | * details (LICENSE.txt). 20 | * 21 | * You should have received a copy of the GNU General Public License along with 22 | * MLPACK. If not, see . 23 | */ 24 | #ifndef __MLPACK_METHODS_NYSTROEM_METHOD_ORDERED_SELECTION_HPP 25 | #define __MLPACK_METHODS_NYSTROEM_METHOD_ORDERED_SELECTION_HPP 26 | 27 | #include 28 | 29 | namespace mlpack { 30 | namespace kernel { 31 | 32 | class OrderedSelection 33 | { 34 | public: 35 | /** 36 | * Select the specified number of points in the dataset. 37 | * 38 | * @param data Dataset to sample from. 39 | * @param m Number of points to select. 40 | * @return Indices of selected points from the dataset. 41 | */ 42 | const static arma::Col Select(const arma::mat& /* unused */, 43 | const size_t m) 44 | { 45 | // This generates [0 1 2 3 ... (m - 1)]. 46 | return arma::linspace >(0, m - 1, m); 47 | } 48 | }; 49 | 50 | }; // namespace kernel 51 | }; // namespace mlpack 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/nystroem_method/random_selection.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file random_selection.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Randomly select some points (with replacement) to use for the Nystroem 6 | * method. Replacement is suboptimal, but for rank << number of points, this is 7 | * unlikely. 8 | * 9 | * This file is part of MLPACK 1.0.10. 10 | * 11 | * MLPACK is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free 13 | * Software Foundation, either version 3 of the License, or (at your option) any 14 | * later version. 15 | * 16 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 17 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 18 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 19 | * details (LICENSE.txt). 20 | * 21 | * You should have received a copy of the GNU General Public License along with 22 | * MLPACK. If not, see . 23 | */ 24 | #ifndef __MLPACK_METHODS_NYSTROEM_METHOD_RANDOM_SELECTION_HPP 25 | #define __MLPACK_METHODS_NYSTROEM_METHOD_RANDOM_SELECTION_HPP 26 | 27 | #include 28 | 29 | namespace mlpack { 30 | namespace kernel { 31 | 32 | class RandomSelection 33 | { 34 | public: 35 | /** 36 | * Randomly select the specified number of points in the dataset. 37 | * 38 | * @param data Dataset to sample from. 39 | * @param m Number of points to select. 40 | * @return Indices of selected points from the dataset. 41 | */ 42 | const static arma::Col Select(const arma::mat& data, const size_t m) 43 | { 44 | arma::Col selectedPoints(m); 45 | for (size_t i = 0; i < m; ++i) 46 | selectedPoints(i) = math::RandInt(0, data.n_cols); 47 | 48 | return selectedPoints; 49 | } 50 | }; 51 | 52 | }; // namespace kernel 53 | }; // namespace mlpack 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/perceptron/initialization_methods/random_init.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file random_init.hpp 3 | * @author Udit Saxena 4 | * 5 | * Random initialization for perceptron weights. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef _MLPACK_METHOS_PERCEPTRON_INITIALIZATION_METHODS_RANDOM_INIT_HPP 23 | #define _MLPACK_METHOS_PERCEPTRON_INITIALIZATION_METHODS_RANDOM_INIT_HPP 24 | 25 | #include 26 | 27 | namespace mlpack { 28 | namespace perceptron { 29 | 30 | /** 31 | * This class is used to initialize weights for the weightVectors matrix in a 32 | * random manner. 33 | */ 34 | class RandomInitialization 35 | { 36 | public: 37 | RandomInitialization() { } 38 | 39 | inline static void Initialize(arma::mat& W, 40 | const size_t row, 41 | const size_t col) 42 | { 43 | W = arma::randu(row, col); 44 | } 45 | }; // class RandomInitialization 46 | 47 | }; // namespace perceptron 48 | }; // namespace mlpack 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/perceptron/initialization_methods/zero_init.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file zero_init.hpp 3 | * @author Udit Saxena 4 | * 5 | * Implementation of ZeroInitialization policy for perceptrons. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef _MLPACK_METHOS_PERCEPTRON_INITIALIZATION_METHODS_ZERO_INIT_HPP 23 | #define _MLPACK_METHOS_PERCEPTRON_INITIALIZATION_METHODS_ZERO_INIT_HPP 24 | 25 | #include 26 | 27 | namespace mlpack { 28 | namespace perceptron { 29 | 30 | /** 31 | * This class is used to initialize the matrix weightVectors to zero. 32 | */ 33 | class ZeroInitialization 34 | { 35 | public: 36 | ZeroInitialization() { } 37 | 38 | inline static void Initialize(arma::mat& W, 39 | const size_t row, 40 | const size_t col) 41 | { 42 | arma::mat tempWeights(row, col); 43 | tempWeights.fill(0.0); 44 | 45 | W = tempWeights; 46 | } 47 | }; // class ZeroInitialization 48 | 49 | }; // namespace perceptron 50 | }; // namespace mlpack 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/regularized_svd/regularized_svd_impl.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file regularized_svd_impl.hpp 3 | * @author Siddharth Agrawal 4 | * 5 | * An implementation of Regularized SVD. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | 23 | #ifndef __MLPACK_METHODS_REGULARIZED_SVD_REGULARIZED_SVD_IMPL_HPP 24 | #define __MLPACK_METHODS_REGULARIZED_SVD_REGULARIZED_SVD_IMPL_HPP 25 | 26 | namespace mlpack { 27 | namespace svd { 28 | 29 | template class OptimizerType> 30 | RegularizedSVD::RegularizedSVD(const arma::mat& data, 31 | arma::mat& u, 32 | arma::mat& v, 33 | const size_t rank, 34 | const size_t iterations, 35 | const double alpha, 36 | const double lambda) : 37 | data(data), 38 | rank(rank), 39 | iterations(iterations), 40 | alpha(alpha), 41 | lambda(lambda), 42 | rSVDFunc(data, rank, lambda), 43 | optimizer(rSVDFunc, alpha, iterations * data.n_cols) 44 | { 45 | arma::mat parameters = rSVDFunc.GetInitialPoint(); 46 | 47 | // Train the model. 48 | Timer::Start("regularized_svd_optimization"); 49 | const double out = optimizer.Optimize(parameters); 50 | Timer::Stop("regularized_svd_optimization"); 51 | 52 | const size_t numUsers = max(data.row(0)) + 1; 53 | const size_t numItems = max(data.row(1)) + 1; 54 | 55 | u = parameters.submat(0, 0, rank - 1, numUsers - 1); 56 | v = parameters.submat(0, numUsers, rank - 1, numUsers + numItems - 1); 57 | } 58 | 59 | }; // namespace svd 60 | }; // namespace mlpack 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/sparse_coding/nothing_initializer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file nothing_initializer.hpp 3 | * @author Ryan Curtin 4 | * 5 | * An initializer for SparseCoding which does precisely nothing. It is useful 6 | * for when you have an already defined dictionary and you plan on setting it 7 | * with SparseCoding::Dictionary(). 8 | * 9 | * This file is part of MLPACK 1.0.10. 10 | * 11 | * MLPACK is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free 13 | * Software Foundation, either version 3 of the License, or (at your option) any 14 | * later version. 15 | * 16 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 17 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 18 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 19 | * details (LICENSE.txt). 20 | * 21 | * You should have received a copy of the GNU General Public License along with 22 | * MLPACK. If not, see . 23 | */ 24 | #ifndef __MLPACK_METHODS_SPARSE_CODING_NOTHING_INITIALIZER_HPP 25 | #define __MLPACK_METHODS_SPARSE_CODING_NOTHING_INITIALIZER_HPP 26 | 27 | #include 28 | 29 | namespace mlpack { 30 | namespace sparse_coding { 31 | 32 | /** 33 | * A DictionaryInitializer for SparseCoding which does not initialize anything; 34 | * it is useful for when the dictionary is already known and will be set with 35 | * SparseCoding::Dictionary(). 36 | */ 37 | class NothingInitializer 38 | { 39 | public: 40 | /** 41 | * This function does not initialize the dictionary. This will cause problems 42 | * for SparseCoding if the dictionary is not set manually before running the 43 | * method. 44 | */ 45 | static void Initialize(const arma::mat& /* data */, 46 | const size_t /* atoms */, 47 | arma::mat& /* dictionary */) 48 | { 49 | // Do nothing! 50 | } 51 | }; 52 | 53 | }; // namespace sparse_coding 54 | }; // namespace mlpack 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /inst/include/mlpack/methods/sparse_coding/random_initializer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file random_initializer.hpp 3 | * @author Nishant Mehta 4 | * 5 | * A very simple random dictionary initializer for SparseCoding; it is probably 6 | * not a very good choice. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_METHODS_SPARSE_CODING_RANDOM_INITIALIZER_HPP 24 | #define __MLPACK_METHODS_SPARSE_CODING_RANDOM_INITIALIZER_HPP 25 | 26 | #include 27 | 28 | namespace mlpack { 29 | namespace sparse_coding { 30 | 31 | /** 32 | * A DictionaryInitializer for use with the SparseCoding class. This provides a 33 | * random, normally distributed dictionary, such that each atom has a norm of 1. 34 | */ 35 | class RandomInitializer 36 | { 37 | public: 38 | /** 39 | * Initialize the dictionary randomly from a normal distribution, such that 40 | * each atom has a norm of 1. This is simple enough to be included with the 41 | * definition. 42 | * 43 | * @param data Dataset to use for initialization. 44 | * @param atoms Number of atoms (columns) in the dictionary. 45 | * @param dictionary Dictionary to initialize. 46 | */ 47 | static void Initialize(const arma::mat& data, 48 | const size_t atoms, 49 | arma::mat& dictionary) 50 | { 51 | // Create random dictionary. 52 | dictionary.randn(data.n_rows, atoms); 53 | 54 | // Normalize each atom. 55 | for (size_t j = 0; j < atoms; ++j) 56 | dictionary.col(j) /= norm(dictionary.col(j), 2); 57 | } 58 | }; 59 | 60 | }; // namespace sparse_coding 61 | }; // namespace mlpack 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /inst/include/mlpack/prereqs.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file prereqs.hpp 3 | * 4 | * The core includes that mlpack expects; standard C++ includes and Armadillo. 5 | * 6 | * This file is part of MLPACK 1.0.10. 7 | * 8 | * MLPACK is free software: you can redistribute it and/or modify it under the 9 | * terms of the GNU Lesser General Public License as published by the Free 10 | * Software Foundation, either version 3 of the License, or (at your option) any 11 | * later version. 12 | * 13 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 15 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 16 | * details (LICENSE.txt). 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * MLPACK. If not, see . 20 | */ 21 | #ifndef __MLPACK_PREREQS_HPP 22 | #define __MLPACK_PREREQS_HPP 23 | 24 | // First, check if Armadillo was included before, warning if so. 25 | #ifdef ARMA_INCLUDES 26 | #pragma message "Armadillo was included before mlpack; this can sometimes cause\ 27 | problems. It should only be necessary to include and not\ 28 | ." 29 | #endif 30 | 31 | // Next, standard includes. 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | // Defining _USE_MATH_DEFINES should set M_PI. 42 | #define _USE_MATH_DEFINES 43 | #include 44 | 45 | // For tgamma(). 46 | #include 47 | 48 | // But if it's not defined, we'll do it. 49 | #ifndef M_PI 50 | #define M_PI 3.141592653589793238462643383279 51 | #endif 52 | 53 | // Give ourselves a nice way to force functions to be inline if we need. 54 | #define force_inline 55 | #if defined(__GNUG__) && !defined(DEBUG) 56 | #undef force_inline 57 | #define force_inline __attribute__((always_inline)) 58 | #elif defined(_MSC_VER) && !defined(DEBUG) 59 | #undef force_inline 60 | #define force_inline __forceinline 61 | #endif 62 | 63 | // Now include Armadillo through the special mlpack extensions. 64 | #include 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /inst/skeleton/Makevars: -------------------------------------------------------------------------------- 1 | PKG_LIBS= `$(R_HOME)/bin/Rscript -e "RcppMLPACK:::LdFlags()"` $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) 2 | -------------------------------------------------------------------------------- /inst/skeleton/Makevars.win: -------------------------------------------------------------------------------- 1 | PKG_LIBS= PKG_LIBS = $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "RcppMLPACK:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) 2 | -------------------------------------------------------------------------------- /inst/skeleton/kmeans.cpp: -------------------------------------------------------------------------------- 1 | #include "RcppMLPACK.h" 2 | 3 | using namespace mlpack::kmeans; 4 | using namespace Rcpp; 5 | 6 | // [[Rcpp::export]] 7 | List mlkmeans(const arma::mat& data, const int& clusters) { 8 | 9 | arma::Col assignments; 10 | 11 | // Initialize with the default arguments. 12 | KMeans<> k; 13 | 14 | k.Cluster(data, clusters, assignments); 15 | 16 | return List::create(_["clusters"] = clusters, 17 | _["result"] = assignments); 18 | } 19 | -------------------------------------------------------------------------------- /man/RcppMLPACK-package.Rd: -------------------------------------------------------------------------------- 1 | \name{RcppMLPACK-package} 2 | \alias{RcppMLPACK-package} 3 | \alias{RcppMLPACK} 4 | \docType{package} 5 | \title{ 6 | Rcpp Integration for MLPACK Library 7 | } 8 | \description{ 9 | The package eases the integration of MLPACK types with R. 10 | MLPACK is an intuitive, fast, scalable C++ machine learning 11 | library, meant to be a machine learning analog to LAPACK. 12 | } 13 | \author{ 14 | For RcppMLPACK: Qiang Kou 15 | 16 | For MLPACK: Ryan Curtin 17 | 18 | Maintainer: Qiang Kou 19 | } 20 | \references{ 21 | MLPACK project: \url{http://www.mlpack.org/} 22 | } 23 | \keyword{ package } 24 | \keyword{ programming } 25 | \keyword{ interface } 26 | 27 | 28 | -------------------------------------------------------------------------------- /man/mlKmeans.Rd: -------------------------------------------------------------------------------- 1 | \name{mlKmeans} 2 | \alias{mlKmeans} 3 | \title{kmeans from MLPACK} 4 | \description{ 5 | kmeans example for using MLPACK with R. 6 | } 7 | \usage{ 8 | mlKmeans(X, y) 9 | } 10 | \arguments{ 11 | \item{X}{data matrix.} 12 | \item{y}{number of clusters.} 13 | } 14 | \details{ 15 | This is a kmeans example using RcppMLPACK. It uses the Kmeans method in MLPACK and integrates with R. 16 | } 17 | \value{ 18 | \code{mlKmeans} returns a list with cluster assignment: 19 | } 20 | \references{MLPACK project: \url{http://www.mlpack.org/}} 21 | \author{ 22 | For RcppMLPACK: Qiang Kou 23 | 24 | For MLPACK: Ryan Curtin 25 | } 26 | \examples{ 27 | data(trees, package="datasets") 28 | mlKmeans(t(trees),3) 29 | } 30 | -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | CXX_STD = CXX11 2 | 3 | MLPACKOBJECTS=\ 4 | ./mlpack/methods/pca/pca.o \ 5 | ./mlpack/methods/det/dtree.o \ 6 | ./mlpack/methods/det/dt_utils.o \ 7 | ./mlpack/methods/linear_regression/linear_regression.o \ 8 | ./mlpack/methods/radical/radical.o \ 9 | ./mlpack/methods/neighbor_search/unmap.o \ 10 | ./mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.o \ 11 | ./mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.o \ 12 | ./mlpack/methods/lars/lars.o \ 13 | ./mlpack/methods/logistic_regression/logistic_regression_function.o \ 14 | ./mlpack/methods/regularized_svd/regularized_svd_function.o \ 15 | ./mlpack/methods/sparse_autoencoder/sparse_autoencoder_function.o \ 16 | ./mlpack/core/math/lin_alg.o \ 17 | ./mlpack/core/math/random.o \ 18 | ./mlpack/core/kernels/pspectrum_string_kernel.o \ 19 | ./mlpack/core/optimizers/lbfgs/test_functions.o \ 20 | ./mlpack/core/optimizers/aug_lagrangian/aug_lagrangian_test_functions.o \ 21 | ./mlpack/core/optimizers/sgd/test_function.o \ 22 | ./mlpack/core/dists/gaussian_distribution.o \ 23 | ./mlpack/core/dists/discrete_distribution.o \ 24 | ./mlpack/core/dists/laplace_distribution.o \ 25 | ./mlpack/core/tree/mrkd_statistic.o \ 26 | ./mlpack/core/tree/cosine_tree/cosine_tree.o \ 27 | ./mlpack/core/util/string_util.o 28 | 29 | PKGOBJECTS = RcppExports.o kmeans.o 30 | OBJECTS= $(MLPACKOBJECTS) $(PKGOBJECTS) 31 | 32 | PKG_CPPFLAGS=-DBOOST_MATH_PROMOTE_DOUBLE_POLICY=false -I. 33 | PKG_LIBS= $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) 34 | 35 | USERDIR = ../inst/lib$(R_ARCH) 36 | STATICLIB = libRcppMLPACK.a 37 | USERLIB = $(USERDIR)/$(STATICLIB) 38 | 39 | RM = rm -f 40 | 41 | .PHONY: all clean 42 | 43 | all: userlib $(SHLIB) 44 | 45 | clean: 46 | ${RM} $(OBJECTS) $(SHLIB) 47 | 48 | $(USERLIB): $(OBJECTS) 49 | 50 | userlib: $(STATICLIB) 51 | -mkdir -p $(USERDIR) 52 | -mv $(STATICLIB) $(USERLIB) 53 | 54 | $(STATICLIB): $(OBJECTS) 55 | -------------------------------------------------------------------------------- /src/RcppExports.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace Rcpp; 5 | 6 | // kmeans 7 | List kmeans(SEXP data, const int& clusters); 8 | RcppExport SEXP RcppMLPACK_kmeans(SEXP dataSEXP, SEXP clustersSEXP) { 9 | BEGIN_RCPP 10 | Rcpp::RObject rcpp_result_gen; 11 | Rcpp::RNGScope rcpp_rngScope_gen; 12 | Rcpp::traits::input_parameter< SEXP >::type data(dataSEXP); 13 | Rcpp::traits::input_parameter< const int& >::type clusters(clustersSEXP); 14 | rcpp_result_gen = Rcpp::wrap(kmeans(data, clusters)); 15 | return rcpp_result_gen; 16 | END_RCPP 17 | } 18 | -------------------------------------------------------------------------------- /src/init.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include // for NULL 4 | #include 5 | 6 | /* FIXME: 7 | Check these declarations against the C/Fortran source code. 8 | */ 9 | 10 | /* .Call calls */ 11 | extern SEXP RcppMLPACK_kmeans(SEXP, SEXP); 12 | 13 | static const R_CallMethodDef CallEntries[] = { 14 | {"RcppMLPACK_kmeans", (DL_FUNC) &RcppMLPACK_kmeans, 2}, 15 | {NULL, NULL, 0} 16 | }; 17 | 18 | void R_init_RcppMLPACK(DllInfo *dll) 19 | { 20 | R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); 21 | R_useDynamicSymbols(dll, FALSE); 22 | } 23 | -------------------------------------------------------------------------------- /src/kmeans.cpp: -------------------------------------------------------------------------------- 1 | #include "RcppMLPACK.h" 2 | 3 | using namespace mlpack::kmeans; 4 | using namespace Rcpp; 5 | 6 | // [[Rcpp::export]] 7 | List kmeans(SEXP data, const int& clusters) { 8 | 9 | NumericMatrix Xr(data); 10 | arma::mat X(Xr.begin(), Xr.nrow(), Xr.ncol(), false); 11 | arma::Col assignments; 12 | 13 | // Initialize with the default arguments. 14 | KMeans<> k; 15 | 16 | k.Cluster(X, clusters, assignments); 17 | 18 | return List::create(_["clusters"] = clusters, 19 | _["result"] = assignments); 20 | } 21 | -------------------------------------------------------------------------------- /src/mlpack/core/arma_extend/SpMat_extra_bones.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SpMat_extra_bones.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Add a batch constructor for SpMat, if the version is older than 3.810.0. 6 | */ 7 | #if ARMA_VERSION_MAJOR == 3 && ARMA_VERSION_MINOR < 810 8 | template inline SpMat( 9 | const Base& locations, 10 | const Base& values, 11 | const bool sort_locations = true); 12 | 13 | template inline SpMat( 14 | const Base& locations, 15 | const Base& values, 16 | const uword n_rows, 17 | const uword n_cols, 18 | const bool sort_locations = true); 19 | #endif 20 | -------------------------------------------------------------------------------- /src/mlpack/core/arma_extend/arma_extend.hpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * @file arma_extend.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Include Armadillo extensions which currently are not part of the main 6 | * Armadillo codebase. 7 | * 8 | * This will allow the use of the ccov() function (which performs the same 9 | * function as cov(trans(X)) but without the cost of computing trans(X)). This 10 | * also gives sparse matrix support, if it is necessary. 11 | */ 12 | #ifndef __MLPACK_CORE_ARMA_EXTEND_ARMA_EXTEND_HPP 13 | #define __MLPACK_CORE_ARMA_EXTEND_ARMA_EXTEND_HPP 14 | 15 | // Add batch constructor for sparse matrix (if version <= 3.810.0). 16 | #define ARMA_EXTRA_SPMAT_PROTO mlpack/core/arma_extend/SpMat_extra_bones.hpp 17 | #define ARMA_EXTRA_SPMAT_MEAT mlpack/core/arma_extend/SpMat_extra_meat.hpp 18 | 19 | #include 20 | #define NDEBUG 1 21 | 22 | namespace arma { 23 | // u64/s64 24 | #include "typedef.hpp" 25 | #include "traits.hpp" 26 | #include "promote_type.hpp" 27 | #include "restrictors.hpp" 28 | #include "hdf5_misc.hpp" 29 | 30 | // ccov() 31 | #include "op_ccov_proto.hpp" 32 | #include "op_ccov_meat.hpp" 33 | #include "glue_ccov_proto.hpp" 34 | #include "glue_ccov_meat.hpp" 35 | #include "fn_ccov.hpp" 36 | 37 | // inplace_reshape() 38 | #include "fn_inplace_reshape.hpp" 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/mlpack/core/arma_extend/fn_ccov.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 NICTA and the authors listed below 2 | // http://nicta.com.au 3 | // 4 | // Authors: 5 | // - Conrad Sanderson (conradsand at ieee dot org) 6 | // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) 7 | // - Ryan Curtin (ryan at igglybob dot com) 8 | // 9 | // This file is part of the Armadillo C++ library. 10 | // It is provided without any warranty of fitness 11 | // for any purpose. You can redistribute this file 12 | // and/or modify it under the terms of the GNU 13 | // Lesser General Public License (LGPL) as published 14 | // by the Free Software Foundation, either version 3 15 | // of the License or (at your option) any later version. 16 | // (see http://www.opensource.org/licenses for more info) 17 | 18 | 19 | //! \addtogroup fn_ccov 20 | //! @{ 21 | 22 | 23 | 24 | template 25 | inline 26 | const Op 27 | ccov(const Base& X, const uword norm_type = 0) 28 | { 29 | arma_extra_debug_sigprint(); 30 | 31 | arma_debug_check( (norm_type > 1), "ccov(): norm_type must be 0 or 1"); 32 | 33 | return Op(X.get_ref(), norm_type, 0); 34 | } 35 | 36 | 37 | 38 | template 39 | inline 40 | const Glue 41 | cov(const Base& A, const Base& B, const uword norm_type = 0) 42 | { 43 | arma_extra_debug_sigprint(); 44 | 45 | arma_debug_check( (norm_type > 1), "ccov(): norm_type must be 0 or 1"); 46 | 47 | return Glue(A.get_ref(), B.get_ref(), norm_type); 48 | } 49 | 50 | 51 | 52 | //! @} 53 | -------------------------------------------------------------------------------- /src/mlpack/core/arma_extend/fn_inplace_reshape.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 NICTA and the authors listed below 2 | // http://nicta.com.au 3 | // 4 | // Authors: 5 | // - Ryan Curtin (ryan at igglybob dot com) 6 | // 7 | // This file is part of the Armadillo C++ library. 8 | // It is provided without any warranty of fitness 9 | // for any purpose. You can redistribute this file 10 | // and/or modify it under the terms of the GNU 11 | // Lesser General Public License (LGPL) as published 12 | // by the Free Software Foundation, either version 3 13 | // of the License or (at your option) any later version. 14 | // (see http://www.opensource.org/licenses for more info) 15 | 16 | 17 | //! \addtogroup fn_inplace_reshape 18 | //! @{ 19 | 20 | 21 | 22 | /** 23 | * This does not handle column vectors or row vectors entirely correctly. You 24 | * should be able to do multiplication or other basic operations with the 25 | * resulting matrix, but it may have other problems. So if you are using this 26 | * on vectors (arma::Col<> or arma::Row<>), be careful, and be warned that 27 | * bizarre behavior may occur. 28 | */ 29 | template 30 | inline 31 | Mat& 32 | inplace_reshape(Mat& X, 33 | const uword new_n_rows, 34 | const uword new_n_cols) 35 | { 36 | arma_extra_debug_sigprint(); 37 | 38 | arma_debug_check((new_n_rows * new_n_cols) != X.n_elem, 39 | "inplace_reshape(): cannot add or remove elements"); 40 | 41 | access::rw(X.n_rows) = new_n_rows; 42 | access::rw(X.n_cols) = new_n_cols; 43 | 44 | return X; 45 | } 46 | 47 | 48 | 49 | //! @} 50 | -------------------------------------------------------------------------------- /src/mlpack/core/arma_extend/glue_ccov_proto.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 NICTA and the authors listed below 2 | // http://nicta.com.au 3 | // 4 | // Authors: 5 | // - Conrad Sanderson (conradsand at ieee dot org) 6 | // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) 7 | // - Ryan Curtin (ryan at igglybob dot com) 8 | // 9 | // This file is part of the Armadillo C++ library. 10 | // It is provided without any warranty of fitness 11 | // for any purpose. You can redistribute this file 12 | // and/or modify it under the terms of the GNU 13 | // Lesser General Public License (LGPL) as published 14 | // by the Free Software Foundation, either version 3 15 | // of the License or (at your option) any later version. 16 | // (see http://www.opensource.org/licenses for more info) 17 | 18 | 19 | 20 | //! \addtogroup glue_ccov 21 | //! @{ 22 | 23 | class glue_ccov 24 | { 25 | public: 26 | 27 | template inline static void direct_ccov(Mat& out, const Mat& A, const Mat& B, const uword norm_type); 28 | template inline static void direct_ccov(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat< std::complex >& B, const uword norm_type); 29 | 30 | template inline static void apply(Mat& out, const Glue& X); 31 | }; 32 | 33 | //! @} 34 | 35 | -------------------------------------------------------------------------------- /src/mlpack/core/arma_extend/hdf5_misc.hpp: -------------------------------------------------------------------------------- 1 | // To hack in u64/s64 support to Armadillo when it is not compiled with 2 | // ARMA_64BIT_WORD. 3 | namespace hdf5_misc { 4 | 5 | #if defined(ARMA_USE_HDF5) 6 | #if !(defined(ARMA_64BIT_WORD) || defined(ARMA_USE_U64S64)) 7 | #if defined(ULLONG_MAX) 8 | template<> 9 | inline 10 | hid_t 11 | get_hdf5_type< long long >() 12 | { 13 | return H5Tcopy(H5T_NATIVE_LLONG); 14 | } 15 | 16 | template<> 17 | inline 18 | hid_t 19 | get_hdf5_type< unsigned long long >() 20 | { 21 | return H5Tcopy(H5T_NATIVE_ULLONG); 22 | } 23 | #endif 24 | #endif 25 | #endif 26 | 27 | } // namespace hdf5_misc 28 | -------------------------------------------------------------------------------- /src/mlpack/core/arma_extend/op_ccov_proto.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 NICTA and the authors listed below 2 | // http://nicta.com.au 3 | // 4 | // Authors: 5 | // - Conrad Sanderson (conradsand at ieee dot org) 6 | // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) 7 | // 8 | // This file is part of the Armadillo C++ library. 9 | // It is provided without any warranty of fitness 10 | // for any purpose. You can redistribute this file 11 | // and/or modify it under the terms of the GNU 12 | // Lesser General Public License (LGPL) as published 13 | // by the Free Software Foundation, either version 3 14 | // of the License or (at your option) any later version. 15 | // (see http://www.opensource.org/licenses for more info) 16 | 17 | 18 | 19 | //! \addtogroup op_cov 20 | //! @{ 21 | 22 | 23 | 24 | class op_ccov 25 | { 26 | public: 27 | 28 | template inline static void direct_ccov(Mat& out, const Mat& X, const uword norm_type); 29 | template inline static void direct_ccov(Mat< std::complex >& out, const Mat< std::complex >& X, const uword norm_type); 30 | 31 | template inline static void apply(Mat& out, const Op& in); 32 | }; 33 | 34 | 35 | 36 | //! @} 37 | -------------------------------------------------------------------------------- /src/mlpack/core/arma_extend/restrictors.hpp: -------------------------------------------------------------------------------- 1 | // Modifications to allow u64/s64 in Armadillo when ARMA_64BIT_WORD is not 2 | // defined. Only required on Armadillo < 3.6.2. 3 | #if (ARMA_VERSION_MAJOR < 3) || \ 4 | ((ARMA_VERSION_MAJOR == 3) && (ARMA_VERSION_MINOR < 6)) || \ 5 | ((ARMA_VERSION_MAJOR == 3) && (ARMA_VERSION_MINOR == 6) && \ 6 | (ARMA_VERSION_PATCH < 2)) 7 | #ifndef ARMA_64BIT_WORD 8 | 9 | template<> struct arma_scalar_only { typedef u64 result; }; 10 | template<> struct arma_scalar_only { typedef s64 result; }; 11 | 12 | template<> struct arma_integral_only { typedef u64 result; }; 13 | template<> struct arma_integral_only { typedef s64 result; }; 14 | 15 | template<> struct arma_unsigned_integral_only { typedef u64 result; }; 16 | 17 | template<> struct arma_signed_integral_only { typedef s64 result; }; 18 | 19 | template<> struct arma_signed_only { typedef s64 result; }; 20 | 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /src/mlpack/core/arma_extend/traits.hpp: -------------------------------------------------------------------------------- 1 | // Extra traits to support u64 and s64 (or, specifically, unsigned long and 2 | // long) until that is applied to the Armadillo sources. 3 | 4 | // This isn't necessary if Armadillo was compiled with 64-bit support, or if 5 | // ARMA_USE_U64S64 is enabled, or if Armadillo >= 3.6.2 is used (by default 6 | // Armadillo 3.6.2 allows long types). 7 | #if (ARMA_VERSION_MAJOR < 3) || \ 8 | ((ARMA_VERSION_MAJOR == 3) && (ARMA_VERSION_MINOR < 6)) || \ 9 | ((ARMA_VERSION_MAJOR == 3) && (ARMA_VERSION_MINOR == 6) && \ 10 | (ARMA_VERSION_PATCH < 2)) 11 | #if !(defined(ARMA_64BIT_WORD) || defined(ARMA_USE_U64S64)) 12 | template 13 | struct is_u64 14 | { static const bool value = false; }; 15 | 16 | template<> 17 | struct is_u64 18 | { static const bool value = true; }; 19 | 20 | 21 | template 22 | struct is_s64 23 | { static const bool value = false; }; 24 | 25 | template<> 26 | struct is_s64 27 | { static const bool value = true; }; 28 | 29 | template<> 30 | struct is_supported_elem_type 31 | { 32 | static const bool value = true; 33 | }; 34 | 35 | template<> 36 | struct is_supported_elem_type 37 | { 38 | static const bool value = true; 39 | }; 40 | 41 | 42 | template<> 43 | struct is_signed 44 | { 45 | static const bool value = false; 46 | }; 47 | 48 | #endif 49 | #endif 50 | -------------------------------------------------------------------------------- /src/mlpack/core/arma_extend/typedef.hpp: -------------------------------------------------------------------------------- 1 | // Extensions to typedef u64 and s64 until that support is added into 2 | // Armadillo. We only need to typedef s64 on Armadillo > 1.2.0. This is not 3 | // necessary for Armadillo > 3.6.1. 4 | #if (ARMA_VERSION_MAJOR < 3) || \ 5 | ((ARMA_VERSION_MAJOR == 3) && (ARMA_VERSION_MINOR < 6)) || \ 6 | ((ARMA_VERSION_MAJOR == 3) && (ARMA_VERSION_MINOR == 6) && \ 7 | (ARMA_VERSION_PATCH < 2)) 8 | #ifndef ARMA_64BIT_WORD 9 | // We must typedef both u64 and s64. 10 | #if ULONG_MAX >= 0xffffffffffffffff 11 | typedef unsigned long u64; 12 | typedef long s64; 13 | #elif ULLONG_MAX >= 0xffffffffffffffff 14 | typedef unsigned long long u64; 15 | typedef long long s64; 16 | #else 17 | #error "don't know how to typedef 'u64' on this system" 18 | #endif 19 | 20 | namespace junk 21 | { 22 | struct arma_64_elem_size_test 23 | { 24 | arma_static_check( (sizeof(u64) != 8), ERROR___TYPE_U64_HAS_UNSUPPORTED_SIZE ); 25 | arma_static_check( (sizeof(s64) != 8), ERROR___TYPE_S64_HAS_UNSUPPORTED_SIZE ); 26 | }; 27 | } 28 | 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /src/mlpack/core/kernels/cosine_distance.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file cosine_distance.hpp 3 | * @author Ryan Curtin 4 | * 5 | * This implements the cosine distance (or cosine similarity) between two 6 | * vectors, which is a measure of the angle between the two vectors. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_CORE_KERNELS_COSINE_DISTANCE_HPP 24 | #define __MLPACK_CORE_KERNELS_COSINE_DISTANCE_HPP 25 | 26 | #include 27 | 28 | namespace mlpack { 29 | namespace kernel { 30 | 31 | /** 32 | * The cosine distance (or cosine similarity). It is defined by 33 | * 34 | * @f[ 35 | * d(a, b) = \frac{a^T b}{|| a || || b ||} 36 | * @f] 37 | * 38 | * and this class assumes the standard L2 inner product. 39 | */ 40 | class CosineDistance 41 | { 42 | public: 43 | /** 44 | * Computes the cosine distance between two points. 45 | * 46 | * @param a First vector. 47 | * @param b Second vector. 48 | * @return d(a, b). 49 | */ 50 | template 51 | static double Evaluate(const VecType& a, const VecType& b); 52 | 53 | /** 54 | * Returns a string representation of this object. 55 | */ 56 | std::string ToString() const 57 | { 58 | std::ostringstream convert; 59 | convert << "CosineDistance [" << this << "]" << std::endl; 60 | return convert.str(); 61 | } 62 | }; 63 | 64 | //! Kernel traits for the cosine distance. 65 | template<> 66 | class KernelTraits 67 | { 68 | public: 69 | //! The cosine kernel is normalized: K(x, x) = 1 for all x. 70 | static const bool IsNormalized = true; 71 | }; 72 | 73 | }; // namespace kernel 74 | }; // namespace mlpack 75 | 76 | // Include implementation. 77 | #include "cosine_distance_impl.hpp" 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/mlpack/core/kernels/cosine_distance_impl.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file cosine_distance_impl.hpp 3 | * @author Ryan Curtin 4 | * 5 | * This implements the cosine distance. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_CORE_KERNELS_COSINE_DISTANCE_IMPL_HPP 23 | #define __MLPACK_CORE_KERNELS_COSINE_DISTANCE_IMPL_HPP 24 | 25 | #include "cosine_distance.hpp" 26 | 27 | namespace mlpack { 28 | namespace kernel { 29 | 30 | template 31 | double CosineDistance::Evaluate(const VecType& a, const VecType& b) 32 | { 33 | // Since we are using the L2 inner product, this is easy. But we have to make 34 | // sure we aren't dividing by zero (if we are, then the cosine similarity is 35 | // 0: we reason this value because the cosine distance is just a normalized 36 | // dot product; take away the normalization, and if ||a|| or ||b|| is equal to 37 | // 0, then a^T b is zero too). 38 | const double denominator = norm(a, 2) * norm(b, 2); 39 | if (denominator == 0.0) 40 | return 0; 41 | else 42 | return dot(a, b) / denominator; 43 | } 44 | 45 | }; // namespace kernel 46 | }; // namespace mlpack 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/mlpack/core/kernels/epanechnikov_kernel.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file epanechnikov_kernel.cpp 3 | * @author Neil Slagle 4 | * 5 | * Implementation of non-template Epanechnikov kernels. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #include "epanechnikov_kernel.hpp" 23 | 24 | #include 25 | 26 | using namespace mlpack; 27 | using namespace mlpack::kernel; 28 | 29 | /** 30 | * Compute the normalizer of this Epanechnikov kernel for the given dimension. 31 | * 32 | * @param dimension Dimension to calculate the normalizer for. 33 | */ 34 | double EpanechnikovKernel::Normalizer(const size_t dimension) 35 | { 36 | return 2.0 * pow(bandwidth, (double) dimension) * 37 | std::pow(M_PI, dimension / 2.0) / 38 | (boost::math::tgamma(dimension / 2.0 + 1.0) * (dimension + 2.0)); 39 | } 40 | 41 | /** 42 | * Evaluate the kernel not for two points but for a numerical value. 43 | */ 44 | double EpanechnikovKernel::Evaluate(const double distance) const 45 | { 46 | return std::max(0.0, 1 - std::pow(distance, 2.0) * inverseBandwidthSquared); 47 | } 48 | 49 | // Return string of object. 50 | std::string EpanechnikovKernel::ToString() const 51 | { 52 | std::ostringstream convert; 53 | convert << "EpanechnikovKernel [" << this << "]" << std::endl; 54 | convert << " Bandwidth: " << bandwidth << std::endl; 55 | convert << " Inverse squared bandwidth: "; 56 | convert << inverseBandwidthSquared << std::endl; 57 | return convert.str(); 58 | } 59 | -------------------------------------------------------------------------------- /src/mlpack/core/kernels/kernel_traits.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file kernel_traits.hpp 3 | * @author Ryan Curtin 4 | * 5 | * This provides the KernelTraits class, a template class to get information 6 | * about various kernels. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_CORE_KERNELS_KERNEL_TRAITS_HPP 24 | #define __MLPACK_CORE_KERNELS_KERNEL_TRAITS_HPP 25 | 26 | namespace mlpack { 27 | namespace kernel { 28 | 29 | /** 30 | * This is a template class that can provide information about various kernels. 31 | * By default, this class will provide the weakest possible assumptions on 32 | * kernels, and each kernel should override values as necessary. If a kernel 33 | * doesn't need to override a value, then there's no need to write a 34 | * KernelTraits specialization for that class. 35 | */ 36 | template 37 | class KernelTraits 38 | { 39 | public: 40 | /** 41 | * If true, then the kernel is normalized: K(x, x) = K(y, y) = 1 for all x. 42 | */ 43 | static const bool IsNormalized = false; 44 | }; 45 | 46 | }; // namespace kernel 47 | }; // namespace mlpack 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/mlpack/core/kernels/linear_kernel.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file linear_kernel.hpp 3 | * @author Wei Guan 4 | * @author James Cline 5 | * @author Ryan Curtin 6 | * 7 | * Implementation of the linear kernel (just the standard dot product). 8 | * 9 | * This file is part of MLPACK 1.0.10. 10 | * 11 | * MLPACK is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free 13 | * Software Foundation, either version 3 of the License, or (at your option) any 14 | * later version. 15 | * 16 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 17 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 18 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 19 | * details (LICENSE.txt). 20 | * 21 | * You should have received a copy of the GNU General Public License along with 22 | * MLPACK. If not, see . 23 | */ 24 | #ifndef __MLPACK_CORE_KERNELS_LINEAR_KERNEL_HPP 25 | #define __MLPACK_CORE_KERNELS_LINEAR_KERNEL_HPP 26 | 27 | #include 28 | 29 | namespace mlpack { 30 | namespace kernel { 31 | 32 | /** 33 | * The simple linear kernel (dot product). For any two vectors @f$ x @f$ and 34 | * @f$ y @f$, 35 | * 36 | * @f[ 37 | * K(x, y) = x^T y 38 | * @f] 39 | * 40 | * This kernel has no parameters and therefore the evaluation can be static. 41 | */ 42 | class LinearKernel 43 | { 44 | public: 45 | /** 46 | * This constructor does nothing; the linear kernel has no parameters to 47 | * store. 48 | */ 49 | LinearKernel() { } 50 | 51 | /** 52 | * Simple evaluation of the dot product. This evaluation uses Armadillo's 53 | * dot() function. 54 | * 55 | * @tparam VecType Type of vector (should be arma::vec or arma::spvec). 56 | * @param a First vector. 57 | * @param b Second vector. 58 | * @return K(a, b). 59 | */ 60 | template 61 | static double Evaluate(const VecType& a, const VecType& b) 62 | { 63 | return arma::dot(a, b); 64 | } 65 | 66 | //! Return a string representation of the kernel. 67 | std::string ToString() const 68 | { 69 | std::ostringstream convert; 70 | convert << "LinearKernel [" << this << "]" << std::endl; 71 | return convert.str(); 72 | } 73 | }; 74 | 75 | }; // namespace kernel 76 | }; // namespace mlpack 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /src/mlpack/core/math/clamp.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file clamp.hpp 3 | * 4 | * Miscellaneous math clamping routines. 5 | * 6 | * This file is part of MLPACK 1.0.10. 7 | * 8 | * MLPACK is free software: you can redistribute it and/or modify it under the 9 | * terms of the GNU Lesser General Public License as published by the Free 10 | * Software Foundation, either version 3 of the License, or (at your option) any 11 | * later version. 12 | * 13 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 15 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 16 | * details (LICENSE.txt). 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * MLPACK. If not, see . 20 | */ 21 | #ifndef __MLPACK_CORE_MATH_CLAMP_HPP 22 | #define __MLPACK_CORE_MATH_CLAMP_HPP 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace mlpack { 29 | namespace math /** Miscellaneous math routines. */ { 30 | 31 | /** 32 | * Forces a number to be non-negative, turning negative numbers into zero. 33 | * Avoids branching costs (this is a measurable improvement). 34 | * 35 | * @param d Double to clamp. 36 | * @return 0 if d < 0, d otherwise. 37 | */ 38 | inline double ClampNonNegative(const double d) 39 | { 40 | return (d + fabs(d)) / 2; 41 | } 42 | 43 | /** 44 | * Forces a number to be non-positive, turning positive numbers into zero. 45 | * Avoids branching costs (this is a measurable improvement). 46 | * 47 | * @param d Double to clamp. 48 | * @param 0 if d > 0, d otherwise. 49 | */ 50 | inline double ClampNonPositive(const double d) 51 | { 52 | return (d - fabs(d)) / 2; 53 | } 54 | 55 | /** 56 | * Clamp a number between a particular range. 57 | * 58 | * @param value The number to clamp. 59 | * @param rangeMin The first of the range. 60 | * @param rangeMax The last of the range. 61 | * @return max(rangeMin, min(rangeMax, d)). 62 | */ 63 | inline double ClampRange(double value, 64 | const double rangeMin, 65 | const double rangeMax) 66 | { 67 | value -= rangeMax; 68 | value = ClampNonPositive(value) + rangeMax; 69 | value -= rangeMin; 70 | value = ClampNonNegative(value) + rangeMin; 71 | return value; 72 | } 73 | 74 | }; // namespace math 75 | }; // namespace mlpack 76 | 77 | #endif // __MLPACK_CORE_MATH_CLAMP_HPP 78 | -------------------------------------------------------------------------------- /src/mlpack/core/math/random.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file random.cpp 3 | * 4 | * Declarations of global Boost random number generators. 5 | * 6 | * This file is part of MLPACK 1.0.10. 7 | * 8 | * MLPACK is free software: you can redistribute it and/or modify it under the 9 | * terms of the GNU Lesser General Public License as published by the Free 10 | * Software Foundation, either version 3 of the License, or (at your option) any 11 | * later version. 12 | * 13 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 15 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 16 | * details (LICENSE.txt). 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * MLPACK. If not, see . 20 | */ 21 | #include 22 | #include 23 | 24 | namespace mlpack { 25 | namespace math { 26 | 27 | #if BOOST_VERSION >= 104700 28 | // Global random object. 29 | boost::random::mt19937 randGen; 30 | // Global uniform distribution. 31 | boost::random::uniform_01<> randUniformDist; 32 | // Global normal distribution. 33 | boost::random::normal_distribution<> randNormalDist; 34 | #else 35 | // Global random object. 36 | boost::mt19937 randGen; 37 | 38 | #if BOOST_VERSION >= 103900 39 | // Global uniform distribution. 40 | boost::uniform_01<> randUniformDist; 41 | #else 42 | // Pre-1.39 Boost.Random did not give default template parameter values. 43 | boost::uniform_01 randUniformDist(randGen); 44 | #endif 45 | 46 | // Global normal distribution. 47 | boost::normal_distribution<> randNormalDist; 48 | #endif 49 | 50 | }; // namespace math 51 | }; // namespace mlpack 52 | -------------------------------------------------------------------------------- /src/mlpack/core/math/round.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file round.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Implementation of round() for use on Visual Studio, where C99 isn't 6 | * implemented. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_CORE_MATH_ROUND_HPP 24 | #define __MLPACK_CORE_MATH_ROUND_HPP 25 | 26 | // _MSC_VER should only be defined for Visual Studio, which doesn't implement 27 | // C99. 28 | #ifdef _MSC_VER 29 | 30 | // This function ends up going into the global namespace, so it can be used in 31 | // place of C99's round(). 32 | 33 | //! Round a number to the nearest integer. 34 | inline double round(double a) 35 | { 36 | return floor(a + 0.5); 37 | } 38 | 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/mlpack/core/metrics/ip_metric.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ip_metric.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Inner product induced metric. If given a kernel function, this gives the 6 | * complementary metric. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_METHODS_FASTMKS_IP_METRIC_HPP 24 | #define __MLPACK_METHODS_FASTMKS_IP_METRIC_HPP 25 | 26 | namespace mlpack { 27 | namespace metric { 28 | 29 | template 30 | class IPMetric 31 | { 32 | public: 33 | //! Create the IPMetric without an instantiated kernel. 34 | IPMetric(); 35 | 36 | //! Create the IPMetric with an instantiated kernel. 37 | IPMetric(KernelType& kernel); 38 | 39 | //! Destroy the IPMetric object. 40 | ~IPMetric(); 41 | 42 | /** 43 | * Evaluate the metric. 44 | */ 45 | template 46 | double Evaluate(const Vec1Type& a, const Vec2Type& b); 47 | 48 | //! Get the kernel. 49 | const KernelType& Kernel() const { return kernel; } 50 | //! Modify the kernel. 51 | KernelType& Kernel() { return kernel; } 52 | /** 53 | * Returns a string representation of this object. 54 | */ 55 | std::string ToString() const; 56 | private: 57 | //! The locally stored kernel, if it is necessary. 58 | KernelType* localKernel; 59 | //! The reference to the kernel that is being used. 60 | KernelType& kernel; 61 | }; 62 | 63 | }; // namespace metric 64 | }; // namespace mlpack 65 | 66 | // Include implementation. 67 | #include "ip_metric_impl.hpp" 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/mlpack/core/optimizers/lrsdp/lrsdp.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lrsdp.cpp 3 | * @author Ryan Curtin 4 | * 5 | * An implementation of Monteiro and Burer's formulation of low-rank 6 | * semidefinite programs (LR-SDP). 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #include "lrsdp.hpp" 24 | 25 | using namespace mlpack; 26 | using namespace mlpack::optimization; 27 | using namespace std; 28 | 29 | LRSDP::LRSDP(const size_t numConstraints, 30 | const arma::mat& initialPoint) : 31 | function(numConstraints, initialPoint), 32 | augLag(function) 33 | { } 34 | 35 | double LRSDP::Optimize(arma::mat& coordinates) 36 | { 37 | augLag.Sigma() = 20; 38 | augLag.Optimize(coordinates, 1000); 39 | 40 | return augLag.Function().Evaluate(coordinates); 41 | } 42 | 43 | // Convert the object to a string. 44 | std::string LRSDP::ToString() const 45 | { 46 | std::ostringstream convert; 47 | convert << "LRSDP [" << this << "]" << std::endl; 48 | convert << " Optimizer: " << util::Indent(augLag.ToString(), 1) << std::endl; 49 | return convert.str(); 50 | } 51 | -------------------------------------------------------------------------------- /src/mlpack/core/optimizers/sgd/test_function.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file test_function.cpp 3 | * @author Ryan Curtin 4 | * 5 | * Implementation of very simple test function for stochastic gradient descent 6 | * (SGD). 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #include "test_function.hpp" 24 | 25 | using namespace mlpack; 26 | using namespace mlpack::optimization; 27 | using namespace mlpack::optimization::test; 28 | 29 | double SGDTestFunction::Evaluate(const arma::mat& coordinates, const size_t i) 30 | const 31 | { 32 | switch (i) 33 | { 34 | case 0: 35 | return -std::exp(-std::abs(coordinates[0])); 36 | 37 | case 1: 38 | return std::pow(coordinates[1], 2); 39 | 40 | case 2: 41 | return std::pow(coordinates[2], 4) + 3 * std::pow(coordinates[2], 2); 42 | 43 | default: 44 | return 0; 45 | } 46 | } 47 | 48 | void SGDTestFunction::Gradient(const arma::mat& coordinates, 49 | const size_t i, 50 | arma::mat& gradient) const 51 | { 52 | gradient.zeros(3); 53 | switch (i) 54 | { 55 | case 0: 56 | if (coordinates[0] >= 0) 57 | gradient[0] = std::exp(-coordinates[0]); 58 | else 59 | gradient[0] = -std::exp(coordinates[1]); 60 | break; 61 | 62 | case 1: 63 | gradient[1] = 2 * coordinates[1]; 64 | break; 65 | 66 | case 2: 67 | gradient[2] = 4 * std::pow(coordinates[2], 3) + 6 * coordinates[2]; 68 | break; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/mlpack/core/optimizers/sgd/test_function.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file test_function.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Very simple test function for SGD. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_CORE_OPTIMIZERS_SGD_TEST_FUNCTION_HPP 23 | #define __MLPACK_CORE_OPTIMIZERS_SGD_TEST_FUNCTION_HPP 24 | 25 | #include 26 | 27 | namespace mlpack { 28 | namespace optimization { 29 | namespace test { 30 | 31 | //! Very, very simple test function which is the composite of three other 32 | //! functions. It turns out that although this function is very simple, 33 | //! optimizing it fully can take a very long time. It seems to take in excess 34 | //! of 10 million iterations with a step size of 0.0005. 35 | class SGDTestFunction 36 | { 37 | public: 38 | //! Nothing to do for the constructor. 39 | SGDTestFunction() { } 40 | 41 | //! Return 3 (the number of functions). 42 | size_t NumFunctions() const { return 3; } 43 | 44 | //! Get the starting point. 45 | arma::mat GetInitialPoint() const { return arma::mat("6; -45.6; 6.2"); } 46 | 47 | //! Evaluate a function. 48 | double Evaluate(const arma::mat& coordinates, const size_t i) const; 49 | 50 | //! Evaluate the gradient of a function. 51 | void Gradient(const arma::mat& coordinates, 52 | const size_t i, 53 | arma::mat& gradient) const; 54 | }; 55 | 56 | }; // namespace test 57 | }; // namespace optimization 58 | }; // namespace mlpack 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/mlpack/core/tree/binary_space_tree.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file binary_space_tree.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Include all the necessary files to use the BinarySpaceTree class. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_CORE_TREE_BINARY_SPACE_TREE_HPP 23 | #define __MLPACK_CORE_TREE_BINARY_SPACE_TREE_HPP 24 | 25 | #include "bounds.hpp" 26 | #include "binary_space_tree/binary_space_tree.hpp" 27 | #include "binary_space_tree/single_tree_traverser.hpp" 28 | #include "binary_space_tree/single_tree_traverser_impl.hpp" 29 | #include "binary_space_tree/dual_tree_traverser.hpp" 30 | #include "binary_space_tree/dual_tree_traverser_impl.hpp" 31 | #include "binary_space_tree/traits.hpp" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/mlpack/core/tree/binary_space_tree/traits.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file traits.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Specialization of the TreeTraits class for the BinarySpaceTree type of tree. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_CORE_TREE_BINARY_SPACE_TREE_TRAITS_HPP 23 | #define __MLPACK_CORE_TREE_BINARY_SPACE_TREE_TRAITS_HPP 24 | 25 | #include 26 | 27 | namespace mlpack { 28 | namespace tree { 29 | 30 | /** 31 | * This is a specialization of the TreeType class to the BinarySpaceTree tree 32 | * type. It defines characteristics of the binary space tree, and is used to 33 | * help write tree-independent (but still optimized) tree-based algorithms. See 34 | * mlpack/core/tree/tree_traits.hpp for more information. 35 | */ 36 | template 39 | class TreeTraits > 40 | { 41 | public: 42 | /** 43 | * Each binary space tree node has two children which represent 44 | * non-overlapping subsets of the space which the node represents. Therefore, 45 | * children are not overlapping. 46 | */ 47 | static const bool HasOverlappingChildren = false; 48 | 49 | /** 50 | * There is no guarantee that the first point in a node is its centroid. 51 | */ 52 | static const bool FirstPointIsCentroid = false; 53 | 54 | /** 55 | * Points are not contained at multiple levels of the binary space tree. 56 | */ 57 | static const bool HasSelfChildren = false; 58 | 59 | /** 60 | * Points are rearranged during building of the tree. 61 | */ 62 | static const bool RearrangesDataset = true; 63 | }; 64 | 65 | }; // namespace tree 66 | }; // namespace mlpack 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/mlpack/core/tree/bounds.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file bounds.hpp 3 | * 4 | * Bounds that are useful for binary space partitioning trees. 5 | * 6 | * This file is part of MLPACK 1.0.10. 7 | * 8 | * MLPACK is free software: you can redistribute it and/or modify it under the 9 | * terms of the GNU Lesser General Public License as published by the Free 10 | * Software Foundation, either version 3 of the License, or (at your option) any 11 | * later version. 12 | * 13 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 15 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 16 | * details (LICENSE.txt). 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * MLPACK. If not, see . 20 | */ 21 | 22 | #ifndef __MLPACK_CORE_TREE_BOUNDS_HPP 23 | #define __MLPACK_CORE_TREE_BOUNDS_HPP 24 | 25 | #include 26 | #include 27 | 28 | #include "hrectbound.hpp" 29 | #include "ballbound.hpp" 30 | 31 | #endif // __MLPACK_CORE_TREE_BOUNDS_HPP 32 | -------------------------------------------------------------------------------- /src/mlpack/core/tree/cover_tree.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file cover_tree.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Includes all the necessary files to use the CoverTree class. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_CORE_TREE_COVER_TREE_HPP 23 | #define __MLPACK_CORE_TREE_COVER_TREE_HPP 24 | 25 | #include "bounds.hpp" 26 | #include "cover_tree/cover_tree.hpp" 27 | #include "cover_tree/single_tree_traverser.hpp" 28 | #include "cover_tree/single_tree_traverser_impl.hpp" 29 | #include "cover_tree/dual_tree_traverser.hpp" 30 | #include "cover_tree/dual_tree_traverser_impl.hpp" 31 | #include "cover_tree/traits.hpp" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/mlpack/core/tree/cover_tree/first_point_is_root.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file first_point_is_root.hpp 3 | * @author Ryan Curtin 4 | * 5 | * A very simple policy for the cover tree; the first point in the dataset is 6 | * chosen as the root of the cover tree. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_CORE_TREE_FIRST_POINT_IS_ROOT_HPP 24 | #define __MLPACK_CORE_TREE_FIRST_POINT_IS_ROOT_HPP 25 | 26 | #include 27 | 28 | namespace mlpack { 29 | namespace tree { 30 | 31 | /** 32 | * This class is meant to be used as a choice for the policy class 33 | * RootPointPolicy of the CoverTree class. This policy determines which point 34 | * is used for the root node of the cover tree. This particular implementation 35 | * simply chooses the first point in the dataset as the root. A more complex 36 | * implementation might choose, for instance, the point with least maximum 37 | * distance to other points (the closest to the "middle"). 38 | */ 39 | class FirstPointIsRoot 40 | { 41 | public: 42 | /** 43 | * Return the point to be used as the root point of the cover tree. This just 44 | * returns 0. 45 | */ 46 | static size_t ChooseRoot(const arma::mat& /* dataset */) { return 0; } 47 | }; 48 | 49 | }; // namespace tree 50 | }; // namespace mlpack 51 | 52 | #endif // __MLPACK_CORE_TREE_FIRST_POINT_IS_ROOT_HPP 53 | -------------------------------------------------------------------------------- /src/mlpack/core/tree/cover_tree/single_tree_traverser.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file single_tree_traverser.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Defines the SingleTreeTraverser for the cover tree. This implements a 6 | * single-tree breadth-first recursion with a pruning rule and a base case (two 7 | * point) rule. 8 | * 9 | * This file is part of MLPACK 1.0.10. 10 | * 11 | * MLPACK is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free 13 | * Software Foundation, either version 3 of the License, or (at your option) any 14 | * later version. 15 | * 16 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 17 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 18 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 19 | * details (LICENSE.txt). 20 | * 21 | * You should have received a copy of the GNU General Public License along with 22 | * MLPACK. If not, see . 23 | */ 24 | #ifndef __MLPACK_CORE_TREE_COVER_TREE_SINGLE_TREE_TRAVERSER_HPP 25 | #define __MLPACK_CORE_TREE_COVER_TREE_SINGLE_TREE_TRAVERSER_HPP 26 | 27 | #include 28 | 29 | #include "cover_tree.hpp" 30 | 31 | namespace mlpack { 32 | namespace tree { 33 | 34 | template 35 | template 36 | class CoverTree::SingleTreeTraverser 37 | { 38 | public: 39 | /** 40 | * Initialize the single tree traverser with the given rule. 41 | */ 42 | SingleTreeTraverser(RuleType& rule); 43 | 44 | /** 45 | * Traverse the tree with the given point. 46 | * 47 | * @param queryIndex The index of the point in the query set which is used as 48 | * the query point. 49 | * @param referenceNode The tree node to be traversed. 50 | */ 51 | void Traverse(const size_t queryIndex, CoverTree& referenceNode); 52 | 53 | //! Get the number of prunes so far. 54 | size_t NumPrunes() const { return numPrunes; } 55 | //! Set the number of prunes (good for a reset to 0). 56 | size_t& NumPrunes() { return numPrunes; } 57 | 58 | private: 59 | //! Reference to the rules with which the tree will be traversed. 60 | RuleType& rule; 61 | 62 | //! The number of nodes which have been pruned during traversal. 63 | size_t numPrunes; 64 | }; 65 | 66 | }; // namespace tree 67 | }; // namespace mlpack 68 | 69 | // Include implementation. 70 | #include "single_tree_traverser_impl.hpp" 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/mlpack/core/tree/cover_tree/traits.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file traits.hpp 3 | * @author Ryan Curtin 4 | * 5 | * This file contains the specialization of the TreeTraits class for the 6 | * CoverTree type of tree. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_CORE_TREE_COVER_TREE_TRAITS_HPP 24 | #define __MLPACK_CORE_TREE_COVER_TREE_TRAITS_HPP 25 | 26 | #include 27 | 28 | namespace mlpack { 29 | namespace tree { 30 | 31 | /** 32 | * The specialization of the TreeTraits class for the CoverTree tree type. It 33 | * defines characteristics of the cover tree, and is used to help write 34 | * tree-independent (but still optimized) tree-based algorithms. See 35 | * mlpack/core/tree/tree_traits.hpp for more information. 36 | */ 37 | template 40 | class TreeTraits > 41 | { 42 | public: 43 | /** 44 | * The cover tree (or, this implementation of it) does not require that 45 | * children represent non-overlapping subsets of the parent node. 46 | */ 47 | static const bool HasOverlappingChildren = true; 48 | 49 | /** 50 | * Each cover tree node contains only one point, and that point is its 51 | * centroid. 52 | */ 53 | static const bool FirstPointIsCentroid = true; 54 | 55 | /** 56 | * Cover trees do have self-children. 57 | */ 58 | static const bool HasSelfChildren = true; 59 | 60 | /** 61 | * Points are not rearranged when the tree is built. 62 | */ 63 | static const bool RearrangesDataset = false; 64 | }; 65 | 66 | }; // namespace tree 67 | }; // namespace mlpack 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/mlpack/core/tree/mrkd_statistic.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file mrkd_statistic.cpp 3 | * @author James Cline 4 | * 5 | * Definition of the statistic for multi-resolution kd-trees. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #include "mrkd_statistic.hpp" 23 | 24 | using namespace mlpack; 25 | using namespace mlpack::tree; 26 | 27 | MRKDStatistic::MRKDStatistic() : 28 | dataset(NULL), 29 | begin(0), 30 | count(0), 31 | leftStat(NULL), 32 | rightStat(NULL), 33 | parentStat(NULL) 34 | { } 35 | 36 | /** 37 | * Returns a string representation of this object. 38 | */ 39 | std::string MRKDStatistic::ToString() const 40 | { 41 | std::ostringstream convert; 42 | 43 | convert << "MRKDStatistic [" << this << std::endl; 44 | convert << "begin: " << begin << std::endl; 45 | convert << "count: " << count << std::endl; 46 | convert << "sumOfSquaredNorms: " << sumOfSquaredNorms << std::endl; 47 | if (leftStat != NULL) 48 | { 49 | convert << "leftStat:" << std::endl; 50 | convert << mlpack::util::Indent(leftStat->ToString()); 51 | } 52 | if (rightStat != NULL) 53 | { 54 | convert << "rightStat:" << std::endl; 55 | convert << mlpack::util::Indent(rightStat->ToString()); 56 | } 57 | return convert.str(); 58 | } 59 | -------------------------------------------------------------------------------- /src/mlpack/core/tree/rectangle_tree.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file rectangle_tree.hpp 3 | * @author Andrew Wells 4 | * 5 | * Include all the necessary filse to use the Rectangle Type Trees (RTree, RStarTree, XTree, 6 | * and HilbertRTree.) 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_CORE_TREE_RECTANGLE_TREE_HPP 24 | #define __MLPACK_CORE_TREE_RECTANGLE_TREE_HPP 25 | 26 | /* we include bounds.hpp since it gives us the necessary files. 27 | * However, we will not use the "ballbounds" option. 28 | */ 29 | #include "bounds.hpp" 30 | #include "rectangle_tree/rectangle_tree.hpp" 31 | #include "rectangle_tree/single_tree_traverser.hpp" 32 | #include "rectangle_tree/single_tree_traverser_impl.hpp" 33 | #include "rectangle_tree/dual_tree_traverser.hpp" 34 | #include "rectangle_tree/dual_tree_traverser_impl.hpp" 35 | #include "rectangle_tree/r_tree_split.hpp" 36 | #include "rectangle_tree/r_star_tree_split.hpp" 37 | #include "rectangle_tree/r_tree_descent_heuristic.hpp" 38 | #include "rectangle_tree/r_star_tree_descent_heuristic.hpp" 39 | #include "rectangle_tree/traits.hpp" 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/mlpack/core/tree/statistic.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file statistic.hpp 3 | * 4 | * Definition of the policy type for the statistic class. 5 | * 6 | * You should define your own statistic that looks like EmptyStatistic. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | 24 | #ifndef __MLPACK_CORE_TREE_STATISTIC_HPP 25 | #define __MLPACK_CORE_TREE_STATISTIC_HPP 26 | 27 | namespace mlpack { 28 | namespace tree { 29 | 30 | /** 31 | * Empty statistic if you are not interested in storing statistics in your 32 | * tree. Use this as a template for your own. 33 | */ 34 | class EmptyStatistic 35 | { 36 | public: 37 | EmptyStatistic() { } 38 | ~EmptyStatistic() { } 39 | 40 | /** 41 | * This constructor is called when a node is finished being created. The 42 | * node is finished, and its children are finished, but it is not 43 | * necessarily true that the statistics of other nodes are initialized yet. 44 | * 45 | * @param node Node which this corresponds to. 46 | */ 47 | template 48 | EmptyStatistic(TreeType& /* node */) { } 49 | 50 | public: 51 | /** 52 | * Returns a string representation of this object. 53 | */ 54 | std::string ToString() const 55 | { 56 | std::stringstream convert; 57 | convert << "EmptyStatistic [" << this << "]" << std::endl; 58 | return convert.str(); 59 | } 60 | }; 61 | 62 | }; // namespace tree 63 | }; // namespace mlpack 64 | 65 | #endif // __MLPACK_CORE_TREE_STATISTIC_HPP 66 | -------------------------------------------------------------------------------- /src/mlpack/core/util/option.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file option.cpp 3 | * @author Ryan Curtin 4 | * 5 | * Implementation of the ProgramDoc class. The class registers itself with CLI 6 | * when constructed. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #include "cli.hpp" 24 | #include "option.hpp" 25 | 26 | #include 27 | 28 | using namespace mlpack; 29 | using namespace mlpack::util; 30 | using namespace std; 31 | 32 | /** 33 | * Construct a ProgramDoc object. When constructed, it will register itself 34 | * with CLI. A fatal error will be thrown if more than one is constructed. 35 | * 36 | * @param programName Short string representing the name of the program. 37 | * @param documentation Long string containing documentation on how to use the 38 | * program and what it is. No newline characters are necessary; this is 39 | * taken care of by CLI later. 40 | * @param defaultModule Name of the default module. 41 | */ 42 | ProgramDoc::ProgramDoc(const std::string& programName, 43 | const std::string& documentation) : 44 | programName(programName), 45 | documentation(documentation) 46 | { 47 | // Register this with CLI. 48 | CLI::RegisterProgramDoc(this); 49 | } 50 | -------------------------------------------------------------------------------- /src/mlpack/core/util/option_impl.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file option_impl.hpp 3 | * @author Matthew Amidon 4 | * 5 | * Implementation of template functions for the Option class. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_CORE_UTIL_OPTION_IMPL_HPP 23 | #define __MLPACK_CORE_UTIL_OPTION_IMPL_HPP 24 | 25 | // Just in case it has not been included. 26 | #include "option.hpp" 27 | 28 | namespace mlpack { 29 | namespace util { 30 | 31 | /** 32 | * Registers a parameter with CLI. 33 | */ 34 | template 35 | Option::Option(bool ignoreTemplate, 36 | N defaultValue, 37 | const std::string& identifier, 38 | const std::string& description, 39 | const std::string& alias, 40 | bool required) 41 | { 42 | if (ignoreTemplate) 43 | { 44 | CLI::Add(identifier, description, alias, required); 45 | } 46 | else 47 | { 48 | CLI::Add(identifier, description, alias, required); 49 | CLI::GetParam(identifier) = defaultValue; 50 | } 51 | } 52 | 53 | 54 | /** 55 | * Registers a flag parameter with CLI. 56 | */ 57 | template 58 | Option::Option(const std::string& identifier, 59 | const std::string& description, 60 | const std::string& alias) 61 | { 62 | CLI::AddFlag(identifier, description, alias); 63 | } 64 | 65 | }; // namespace util 66 | }; // namespace mlpack 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/mlpack/core/util/string_util.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file string_util.cpp 3 | * @author Trironk Kiatkungwanglai 4 | * @author Ryan Birmingham 5 | * 6 | * Defines methods useful for formatting output. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #include "string_util.hpp" 24 | 25 | using namespace mlpack; 26 | using namespace mlpack::util; 27 | using namespace std; 28 | 29 | //! A utility function that replaces all all newlines with a number of spaces 30 | //! depending on the indentation level. 31 | string mlpack::util::Indent(string input, const size_t howManyTabs) 32 | { 33 | // For each declared... 34 | string standardTab = " "; 35 | string bigTab = ""; 36 | for (size_t ind = 0; ind < howManyTabs; ind++) 37 | { 38 | // Increase amount tabbed on later lines. 39 | bigTab += standardTab; 40 | 41 | // Add indentation to first line. 42 | input.insert(0, 1, ' '); 43 | input.insert(0, 1, ' '); 44 | } 45 | 46 | // Create the character sequence to replace all newline characters. 47 | std::string tabbedNewline("\n" + bigTab); 48 | 49 | // Replace all newline characters with the precomputed character sequence. 50 | size_t startPos = 0; 51 | while ((startPos = input.find("\n", startPos)) != string::npos) 52 | { 53 | // Don't replace the last newline. 54 | if (startPos == input.length() - 1) 55 | break; 56 | 57 | input.replace(startPos, 1, tabbedNewline); 58 | startPos += tabbedNewline.length(); 59 | } 60 | 61 | return input; 62 | } 63 | -------------------------------------------------------------------------------- /src/mlpack/core/util/string_util.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file string_util.hpp 3 | * @author Trironk Kiatkungwanglai 4 | * @author Ryan Birmingham 5 | * 6 | * Declares methods that are useful for writing formatting output. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_CORE_STRING_UTIL_HPP 24 | #define __MLPACK_CORE_STRING_UTIL_HPP 25 | 26 | #include 27 | 28 | namespace mlpack { 29 | namespace util { 30 | 31 | //! A utility function that replaces all all newlines with a number of spaces 32 | //! depending on the indentation level. 33 | std::string Indent(std::string input, const size_t howManyTabs = 1); 34 | 35 | }; // namespace util 36 | }; // namespace mlpack 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/mlpack/core/util/version.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file version.cpp 3 | * @author Ryan Curtin 4 | * 5 | * The implementation of GetVersion(). 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #include "version.hpp" 23 | 24 | #include 25 | 26 | // If we are not an svn revision, just use the macros to assemble the version 27 | // name. 28 | std::string mlpack::util::GetVersion() 29 | { 30 | #ifndef __MLPACK_SUBVERSION 31 | std::stringstream o; 32 | o << "mlpack " << __MLPACK_VERSION_MAJOR << "." << __MLPACK_VERSION_MINOR 33 | << "." << __MLPACK_VERSION_PATCH; 34 | return o.str(); 35 | #else 36 | #include "svnversion.hpp" 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /src/mlpack/core/util/version.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file version.hpp 3 | * @author Ryan Curtin 4 | * 5 | * The current version of mlpack, available as macros and as a string. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_CORE_UTIL_VERSION_HPP 23 | #define __MLPACK_CORE_UTIL_VERSION_HPP 24 | 25 | #include 26 | 27 | // The version of mlpack. If this is svn trunk, this will be a version with 28 | // higher number than the most recent release. 29 | #define __MLPACK_VERSION_MAJOR 1 30 | #define __MLPACK_VERSION_MINOR 0 31 | #define __MLPACK_VERSION_PATCH 9 32 | 33 | // The name of the version (for use by --version). 34 | namespace mlpack { 35 | namespace util { 36 | 37 | /** 38 | * This will return either "mlpack x.y.z" or "mlpack trunk-rXXXXX" depending on 39 | * whether or not this is a stable version of mlpack or an svn revision. 40 | */ 41 | std::string GetVersion(); 42 | 43 | }; // namespace util 44 | }; // namespace mlpack 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/mlpack/methods/amf/init_rules/random_init.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file random_init.hpp 3 | * @author Mohan Rajendran 4 | * 5 | * Intialization rule for Non-Negative Matrix Factorization (NMF). This simple 6 | * initialization is performed by assigning a random matrix to W and H. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_METHODS_LMF_RANDOM_INIT_HPP 24 | #define __MLPACK_METHODS_LMF_RANDOM_INIT_HPP 25 | 26 | #include 27 | 28 | namespace mlpack { 29 | namespace amf { 30 | 31 | class RandomInitialization 32 | { 33 | public: 34 | // Empty constructor required for the InitializeRule template 35 | RandomInitialization() { } 36 | 37 | template 38 | inline static void Initialize(const MatType& V, 39 | const size_t r, 40 | arma::mat& W, 41 | arma::mat& H) 42 | { 43 | // Simple implementation (left in the header file due to its simplicity). 44 | size_t n = V.n_rows; 45 | size_t m = V.n_cols; 46 | 47 | // Intialize to random values. 48 | W.randu(n, r); 49 | H.randu(r, m); 50 | } 51 | }; 52 | 53 | }; // namespace amf 54 | }; // namespace mlpack 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/mlpack/methods/amf/termination_policies/complete_incremental_termination.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file complete_incremental_termination_hpp 3 | * @author Sumedh Ghaisas 4 | * 5 | * Complete incremental learning termination policy. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED 23 | #define COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED 24 | 25 | namespace mlpack 26 | { 27 | namespace amf 28 | { 29 | 30 | template 31 | class CompleteIncrementalTermination 32 | { 33 | public: 34 | CompleteIncrementalTermination(TerminationPolicy t_policy = TerminationPolicy()) 35 | : t_policy(t_policy) {} 36 | 37 | template 38 | void Initialize(const MatType& V) 39 | { 40 | t_policy.Initialize(V); 41 | 42 | incrementalIndex = accu(V != 0); 43 | iteration = 0; 44 | } 45 | 46 | void Initialize(const arma::sp_mat& V) 47 | { 48 | t_policy.Initialize(V); 49 | 50 | incrementalIndex = V.n_nonzero; 51 | iteration = 0; 52 | } 53 | 54 | bool IsConverged(arma::mat& W, arma::mat& H) 55 | { 56 | iteration++; 57 | if(iteration % incrementalIndex == 0) 58 | return t_policy.IsConverged(W, H); 59 | else return false; 60 | } 61 | 62 | const double& Index() 63 | { 64 | return t_policy.Index(); 65 | } 66 | const size_t& Iteration() 67 | { 68 | return iteration; 69 | } 70 | 71 | const size_t& MaxIterations() 72 | { 73 | return t_policy.MaxIterations(); 74 | } 75 | 76 | private: 77 | TerminationPolicy t_policy; 78 | 79 | size_t incrementalIndex; 80 | size_t iteration; 81 | }; 82 | 83 | } // namespace amf 84 | } // namespace mlpack 85 | 86 | 87 | #endif // COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED 88 | 89 | -------------------------------------------------------------------------------- /src/mlpack/methods/amf/termination_policies/incomplete_incremental_termination.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file incomplete_incremental_termination.hpp 3 | * @author Sumedh Ghaisas 4 | * 5 | * This file is part of MLPACK 1.0.10. 6 | * 7 | * MLPACK is free software: you can redistribute it and/or modify it under the 8 | * terms of the GNU Lesser General Public License as published by the Free 9 | * Software Foundation, either version 3 of the License, or (at your option) any 10 | * later version. 11 | * 12 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 13 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 14 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 15 | * details (LICENSE.txt). 16 | * 17 | * You should have received a copy of the GNU General Public License along with 18 | * MLPACK. If not, see . 19 | */ 20 | #ifndef _INCOMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED 21 | #define _INCOMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED 22 | 23 | #include 24 | 25 | namespace mlpack { 26 | namespace amf { 27 | 28 | template 29 | class IncompleteIncrementalTermination 30 | { 31 | public: 32 | IncompleteIncrementalTermination(TerminationPolicy t_policy = TerminationPolicy()) 33 | : t_policy(t_policy) {} 34 | 35 | template 36 | void Initialize(const MatType& V) 37 | { 38 | t_policy.Initialize(V); 39 | 40 | incrementalIndex = V.n_rows; 41 | iteration = 0; 42 | } 43 | 44 | bool IsConverged(arma::mat& W, arma::mat& H) 45 | { 46 | iteration++; 47 | if(iteration % incrementalIndex == 0) 48 | return t_policy.IsConverged(W, H); 49 | else return false; 50 | } 51 | 52 | const double& Index() 53 | { 54 | return t_policy.Index(); 55 | } 56 | const size_t& Iteration() 57 | { 58 | return iteration; 59 | } 60 | const size_t& MaxIterations() 61 | { 62 | return t_policy.MaxIterations(); 63 | } 64 | 65 | private: 66 | TerminationPolicy t_policy; 67 | 68 | size_t incrementalIndex; 69 | size_t iteration; 70 | }; 71 | 72 | }; // namespace amf 73 | }; // namespace mlpack 74 | 75 | #endif 76 | 77 | -------------------------------------------------------------------------------- /src/mlpack/methods/gmm/diagonal_constraint.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file diagonal_constraint.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Constrain a covariance matrix to be diagonal. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_METHODS_GMM_DIAGONAL_CONSTRAINT_HPP 23 | #define __MLPACK_METHODS_GMM_DIAGONAL_CONSTRAINT_HPP 24 | 25 | #include 26 | 27 | namespace mlpack { 28 | namespace gmm { 29 | 30 | /** 31 | * Force a covariance matrix to be diagonal. 32 | */ 33 | class DiagonalConstraint 34 | { 35 | public: 36 | //! Force a covariance matrix to be diagonal. 37 | static void ApplyConstraint(arma::mat& covariance) 38 | { 39 | // Save the diagonal only. 40 | arma::vec diagonal = covariance.diag(); 41 | covariance = arma::diagmat(diagonal); 42 | } 43 | }; 44 | 45 | }; // namespace gmm 46 | }; // namespace mlpack 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/mlpack/methods/gmm/no_constraint.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file no_constraint.hpp 3 | * @author Ryan Curtin 4 | * 5 | * No constraint on the covariance matrix. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_METHODS_GMM_NO_CONSTRAINT_HPP 23 | #define __MLPACK_METHODS_GMM_NO_CONSTRAINT_HPP 24 | 25 | #include 26 | 27 | namespace mlpack { 28 | namespace gmm { 29 | 30 | /** 31 | * This class enforces no constraint on the covariance matrix. It's faster this 32 | * way, although depending on your situation you may end up with a 33 | * non-invertible covariance matrix. 34 | */ 35 | class NoConstraint 36 | { 37 | public: 38 | //! Do nothing, and do not modify the covariance matrix. 39 | static void ApplyConstraint(const arma::mat& /* covariance */) { } 40 | }; 41 | 42 | }; // namespace gmm 43 | }; // namespace mlpack 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/mlpack/methods/gmm/positive_definite_constraint.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file positive_definite_constraint.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Restricts a covariance matrix to being positive definite. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef __MLPACK_METHODS_GMM_POSITIVE_DEFINITE_CONSTRAINT_HPP 23 | #define __MLPACK_METHODS_GMM_POSITIVE_DEFINITE_CONSTRAINT_HPP 24 | 25 | #include 26 | 27 | namespace mlpack { 28 | namespace gmm { 29 | 30 | /** 31 | * Given a covariance matrix, force the matrix to be positive definite. 32 | */ 33 | class PositiveDefiniteConstraint 34 | { 35 | public: 36 | /** 37 | * Apply the positive definiteness constraint to the given covariance matrix. 38 | * 39 | * @param covariance Covariance matrix. 40 | */ 41 | static void ApplyConstraint(arma::mat& covariance) 42 | { 43 | // TODO: make this more efficient. 44 | if (arma::det(covariance) <= 1e-50) 45 | { 46 | Rcpp::Rcout << "Covariance matrix is not positive definite. Adding " 47 | << "perturbation." << std::endl; 48 | 49 | double perturbation = 1e-30; 50 | while (arma::det(covariance) <= 1e-50) 51 | { 52 | covariance.diag() += perturbation; 53 | perturbation *= 10; 54 | } 55 | } 56 | } 57 | }; 58 | 59 | }; // namespace gmm 60 | }; // namespace mlpack 61 | 62 | #endif 63 | 64 | -------------------------------------------------------------------------------- /src/mlpack/methods/hmm/hmm_util.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file hmm_util.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Save/load utilities for HMMs. This should be eventually merged into the HMM 6 | * class itself. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_METHODS_HMM_HMM_UTIL_HPP 24 | #define __MLPACK_METHODS_HMM_HMM_UTIL_HPP 25 | 26 | #include "hmm.hpp" 27 | 28 | namespace mlpack { 29 | namespace hmm { 30 | 31 | /** 32 | * Save an HMM to file. This only works for GMMs, DiscreteDistributions, and 33 | * GaussianDistributions. 34 | * 35 | * @tparam Distribution Distribution type of HMM. 36 | * @param sr SaveRestoreUtility to use. 37 | */ 38 | template 39 | void SaveHMM(const HMM& hmm, util::SaveRestoreUtility& sr); 40 | 41 | /** 42 | * Load an HMM from file. This only works for GMMs, DiscreteDistributions, and 43 | * GaussianDistributions. 44 | * 45 | * @tparam Distribution Distribution type of HMM. 46 | * @param sr SaveRestoreUtility to use. 47 | */ 48 | template 49 | void LoadHMM(HMM& hmm, util::SaveRestoreUtility& sr); 50 | 51 | }; // namespace hmm 52 | }; // namespace mlpack 53 | 54 | // Include implementation. 55 | #include "hmm_util_impl.hpp" 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/mlpack/methods/kmeans/allow_empty_clusters.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file allow_empty_clusters.hpp 3 | * @author Ryan Curtin 4 | * 5 | * This very simple policy is used when K-Means is allowed to return empty 6 | * clusters. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_METHODS_KMEANS_ALLOW_EMPTY_CLUSTERS_HPP 24 | #define __MLPACK_METHODS_KMEANS_ALLOW_EMPTY_CLUSTERS_HPP 25 | 26 | #include 27 | 28 | namespace mlpack { 29 | namespace kmeans { 30 | 31 | /** 32 | * Policy which allows K-Means to create empty clusters without any error being 33 | * reported. 34 | */ 35 | class AllowEmptyClusters 36 | { 37 | public: 38 | //! Default constructor required by EmptyClusterPolicy policy. 39 | AllowEmptyClusters() { } 40 | 41 | /** 42 | * This function does nothing. It is called by K-Means when K-Means detects 43 | * an empty cluster. 44 | * 45 | * @tparam MatType Type of data (arma::mat or arma::spmat). 46 | * @param data Dataset on which clustering is being performed. 47 | * @param emptyCluster Index of cluster which is empty. 48 | * @param centroids Centroids of each cluster (one per column). 49 | * @param clusterCounts Number of points in each cluster. 50 | * @param assignments Cluster assignments of each point. 51 | * 52 | * @return Number of points changed (0). 53 | */ 54 | template 55 | static size_t EmptyCluster(const MatType& /* data */, 56 | const size_t /* emptyCluster */, 57 | const MatType& /* centroids */, 58 | arma::Col& /* clusterCounts */, 59 | arma::Col& /* assignments */) 60 | { 61 | // Empty clusters are okay! Do nothing. 62 | return 0; 63 | } 64 | }; 65 | 66 | }; // namespace kmeans 67 | }; // namespace mlpack 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/mlpack/methods/mvu/mvu.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file mvu.hpp 3 | * @author Ryan Curtin 4 | * 5 | * An implementation of Maximum Variance Unfolding. This file defines an MVU 6 | * class as well as a class representing the objective function (a semidefinite 7 | * program) which MVU seeks to minimize. Minimization is performed by the 8 | * Augmented Lagrangian optimizer (which in turn uses the L-BFGS optimizer). 9 | * 10 | * Note: this implementation of MVU does not work. See #189. 11 | * 12 | * This file is part of MLPACK 1.0.10. 13 | * 14 | * MLPACK is free software: you can redistribute it and/or modify it under the 15 | * terms of the GNU Lesser General Public License as published by the Free 16 | * Software Foundation, either version 3 of the License, or (at your option) any 17 | * later version. 18 | * 19 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 20 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 21 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 22 | * details (LICENSE.txt). 23 | * 24 | * You should have received a copy of the GNU General Public License along with 25 | * MLPACK. If not, see . 26 | */ 27 | #ifndef __MLPACK_METHODS_MVU_MVU_HPP 28 | #define __MLPACK_METHODS_MVU_MVU_HPP 29 | 30 | #include 31 | 32 | namespace mlpack { 33 | namespace mvu { 34 | 35 | /** 36 | * The MVU class is meant to provide a good abstraction for users. The dataset 37 | * needs to be provided, as well as several parameters. 38 | * 39 | * - dataset 40 | * - new dimensionality 41 | */ 42 | class MVU 43 | { 44 | public: 45 | MVU(const arma::mat& dataIn); 46 | 47 | void Unfold(const size_t newDim, 48 | const size_t numNeighbors, 49 | arma::mat& outputCoordinates); 50 | 51 | private: 52 | const arma::mat& data; 53 | }; 54 | 55 | }; // namespace mvu 56 | }; // namespace mlpack 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * @file nearest_neighbor_sort.cpp 3 | * @author Ryan Curtin 4 | * 5 | * Implementation of the simple FurthestNeighborSort policy class. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #include "furthest_neighbor_sort.hpp" 23 | 24 | using namespace mlpack::neighbor; 25 | 26 | size_t FurthestNeighborSort::SortDistance(const arma::vec& list, 27 | const arma::Col& indices, 28 | double newDistance) 29 | { 30 | // The first element in the list is the nearest neighbor. We only want to 31 | // insert if the new distance is greater than the last element in the list. 32 | if (newDistance < list[list.n_elem - 1]) 33 | return (size_t() - 1); // Do not insert. 34 | 35 | // Search from the beginning. This may not be the best way. 36 | for (size_t i = 0; i < list.n_elem; i++) 37 | if (newDistance >= list[i] || indices[i] == (size_t() - 1)) 38 | return i; 39 | 40 | // Control should never reach here. 41 | return (size_t() - 1); 42 | } 43 | -------------------------------------------------------------------------------- /src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file nearest_neighbor_sort.cpp 3 | * @author Ryan Curtin 4 | * 5 | * Implementation of the simple NearestNeighborSort policy class. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #include "nearest_neighbor_sort.hpp" 23 | 24 | using namespace mlpack::neighbor; 25 | 26 | size_t NearestNeighborSort::SortDistance(const arma::vec& list, 27 | const arma::Col& indices, 28 | double newDistance) 29 | { 30 | // The first element in the list is the nearest neighbor. We only want to 31 | // insert if the new distance is less than the last element in the list. 32 | if (newDistance > list[list.n_elem - 1]) 33 | return (size_t() - 1); // Do not insert. 34 | 35 | // Search from the beginning. This may not be the best way. 36 | for (size_t i = 0; i < list.n_elem; i++) 37 | if (newDistance <= list[i] || indices[i] == (size_t() - 1)) 38 | return i; 39 | 40 | // Control should never reach here. 41 | return (size_t() - 1); 42 | } 43 | -------------------------------------------------------------------------------- /src/mlpack/methods/neighbor_search/typedef.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file typedef.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Simple typedefs describing template instantiations of the NeighborSearch 6 | * class which are commonly used. This is meant to be included by 7 | * neighbor_search.h but is a separate file for simplicity. 8 | * 9 | * This file is part of MLPACK 1.0.10. 10 | * 11 | * MLPACK is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free 13 | * Software Foundation, either version 3 of the License, or (at your option) any 14 | * later version. 15 | * 16 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 17 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 18 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 19 | * details (LICENSE.txt). 20 | * 21 | * You should have received a copy of the GNU General Public License along with 22 | * MLPACK. If not, see . 23 | */ 24 | #ifndef __MLPACK_NEIGHBOR_SEARCH_TYPEDEF_H 25 | #define __MLPACK_NEIGHBOR_SEARCH_TYPEDEF_H 26 | 27 | // In case someone included this directly. 28 | #include "neighbor_search.hpp" 29 | 30 | #include 31 | 32 | #include "sort_policies/nearest_neighbor_sort.hpp" 33 | #include "sort_policies/furthest_neighbor_sort.hpp" 34 | 35 | namespace mlpack { 36 | namespace neighbor { 37 | 38 | /** 39 | * The AllkNN class is the all-k-nearest-neighbors method. It returns L2 40 | * distances (Euclidean distances) for each of the k nearest neighbors. 41 | */ 42 | typedef NeighborSearch AllkNN; 43 | 44 | /** 45 | * The AllkFN class is the all-k-furthest-neighbors method. It returns L2 46 | * distances (Euclidean distances) for each of the k furthest neighbors. 47 | */ 48 | typedef NeighborSearch AllkFN; 49 | 50 | }; // namespace neighbor 51 | }; // namespace mlpack 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/mlpack/methods/nystroem_method/kmeans_selection.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file kmeans_selection.hpp 3 | * @author Marcus Edel 4 | * 5 | * Use the centroids of the K-Means clustering method for use in the Nystroem 6 | * method of kernel matrix approximation. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_METHODS_NYSTROEM_METHOD_KMEANS_SELECTION_HPP 24 | #define __MLPACK_METHODS_NYSTROEM_METHOD_KMEANS_SELECTION_HPP 25 | 26 | #include 27 | #include 28 | 29 | namespace mlpack { 30 | namespace kernel { 31 | 32 | template > 33 | class KMeansSelection 34 | { 35 | public: 36 | /** 37 | * Use the K-Means clustering method to select the specified number of points 38 | * in the dataset. You are responsible for deleting the returned matrix! 39 | * 40 | * @param data Dataset to sample from. 41 | * @param m Number of points to select. 42 | * @return Matrix pointer in which centroids are stored. 43 | */ 44 | const static arma::mat* Select(const arma::mat& data, 45 | const size_t m, 46 | const size_t maxIterations = 5) 47 | { 48 | arma::Col assignments; 49 | arma::mat* centroids = new arma::mat; 50 | 51 | // Perform the K-Means clustering method. 52 | ClusteringType kmeans(maxIterations); 53 | kmeans.Cluster(data, m, assignments, *centroids); 54 | 55 | return centroids; 56 | } 57 | }; 58 | 59 | }; // namespace kernel 60 | }; // namespace mlpack 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/mlpack/methods/nystroem_method/ordered_selection.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ordered_selection.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Select the first points of the dataset for use in the Nystroem method of 6 | * kernel matrix approximation. This is mostly for testing, but might have 7 | * other uses. 8 | * 9 | * This file is part of MLPACK 1.0.10. 10 | * 11 | * MLPACK is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free 13 | * Software Foundation, either version 3 of the License, or (at your option) any 14 | * later version. 15 | * 16 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 17 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 18 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 19 | * details (LICENSE.txt). 20 | * 21 | * You should have received a copy of the GNU General Public License along with 22 | * MLPACK. If not, see . 23 | */ 24 | #ifndef __MLPACK_METHODS_NYSTROEM_METHOD_ORDERED_SELECTION_HPP 25 | #define __MLPACK_METHODS_NYSTROEM_METHOD_ORDERED_SELECTION_HPP 26 | 27 | #include 28 | 29 | namespace mlpack { 30 | namespace kernel { 31 | 32 | class OrderedSelection 33 | { 34 | public: 35 | /** 36 | * Select the specified number of points in the dataset. 37 | * 38 | * @param data Dataset to sample from. 39 | * @param m Number of points to select. 40 | * @return Indices of selected points from the dataset. 41 | */ 42 | const static arma::Col Select(const arma::mat& /* unused */, 43 | const size_t m) 44 | { 45 | // This generates [0 1 2 3 ... (m - 1)]. 46 | return arma::linspace >(0, m - 1, m); 47 | } 48 | }; 49 | 50 | }; // namespace kernel 51 | }; // namespace mlpack 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/mlpack/methods/nystroem_method/random_selection.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file random_selection.hpp 3 | * @author Ryan Curtin 4 | * 5 | * Randomly select some points (with replacement) to use for the Nystroem 6 | * method. Replacement is suboptimal, but for rank << number of points, this is 7 | * unlikely. 8 | * 9 | * This file is part of MLPACK 1.0.10. 10 | * 11 | * MLPACK is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free 13 | * Software Foundation, either version 3 of the License, or (at your option) any 14 | * later version. 15 | * 16 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 17 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 18 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 19 | * details (LICENSE.txt). 20 | * 21 | * You should have received a copy of the GNU General Public License along with 22 | * MLPACK. If not, see . 23 | */ 24 | #ifndef __MLPACK_METHODS_NYSTROEM_METHOD_RANDOM_SELECTION_HPP 25 | #define __MLPACK_METHODS_NYSTROEM_METHOD_RANDOM_SELECTION_HPP 26 | 27 | #include 28 | 29 | namespace mlpack { 30 | namespace kernel { 31 | 32 | class RandomSelection 33 | { 34 | public: 35 | /** 36 | * Randomly select the specified number of points in the dataset. 37 | * 38 | * @param data Dataset to sample from. 39 | * @param m Number of points to select. 40 | * @return Indices of selected points from the dataset. 41 | */ 42 | const static arma::Col Select(const arma::mat& data, const size_t m) 43 | { 44 | arma::Col selectedPoints(m); 45 | for (size_t i = 0; i < m; ++i) 46 | selectedPoints(i) = math::RandInt(0, data.n_cols); 47 | 48 | return selectedPoints; 49 | } 50 | }; 51 | 52 | }; // namespace kernel 53 | }; // namespace mlpack 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/mlpack/methods/perceptron/initialization_methods/random_init.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file random_init.hpp 3 | * @author Udit Saxena 4 | * 5 | * Random initialization for perceptron weights. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef _MLPACK_METHOS_PERCEPTRON_INITIALIZATION_METHODS_RANDOM_INIT_HPP 23 | #define _MLPACK_METHOS_PERCEPTRON_INITIALIZATION_METHODS_RANDOM_INIT_HPP 24 | 25 | #include 26 | 27 | namespace mlpack { 28 | namespace perceptron { 29 | 30 | /** 31 | * This class is used to initialize weights for the weightVectors matrix in a 32 | * random manner. 33 | */ 34 | class RandomInitialization 35 | { 36 | public: 37 | RandomInitialization() { } 38 | 39 | inline static void Initialize(arma::mat& W, 40 | const size_t row, 41 | const size_t col) 42 | { 43 | W = arma::randu(row, col); 44 | } 45 | }; // class RandomInitialization 46 | 47 | }; // namespace perceptron 48 | }; // namespace mlpack 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/mlpack/methods/perceptron/initialization_methods/zero_init.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file zero_init.hpp 3 | * @author Udit Saxena 4 | * 5 | * Implementation of ZeroInitialization policy for perceptrons. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | #ifndef _MLPACK_METHOS_PERCEPTRON_INITIALIZATION_METHODS_ZERO_INIT_HPP 23 | #define _MLPACK_METHOS_PERCEPTRON_INITIALIZATION_METHODS_ZERO_INIT_HPP 24 | 25 | #include 26 | 27 | namespace mlpack { 28 | namespace perceptron { 29 | 30 | /** 31 | * This class is used to initialize the matrix weightVectors to zero. 32 | */ 33 | class ZeroInitialization 34 | { 35 | public: 36 | ZeroInitialization() { } 37 | 38 | inline static void Initialize(arma::mat& W, 39 | const size_t row, 40 | const size_t col) 41 | { 42 | arma::mat tempWeights(row, col); 43 | tempWeights.fill(0.0); 44 | 45 | W = tempWeights; 46 | } 47 | }; // class ZeroInitialization 48 | 49 | }; // namespace perceptron 50 | }; // namespace mlpack 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/mlpack/methods/regularized_svd/regularized_svd_impl.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file regularized_svd_impl.hpp 3 | * @author Siddharth Agrawal 4 | * 5 | * An implementation of Regularized SVD. 6 | * 7 | * This file is part of MLPACK 1.0.10. 8 | * 9 | * MLPACK is free software: you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details (LICENSE.txt). 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * MLPACK. If not, see . 21 | */ 22 | 23 | #ifndef __MLPACK_METHODS_REGULARIZED_SVD_REGULARIZED_SVD_IMPL_HPP 24 | #define __MLPACK_METHODS_REGULARIZED_SVD_REGULARIZED_SVD_IMPL_HPP 25 | 26 | namespace mlpack { 27 | namespace svd { 28 | 29 | template class OptimizerType> 30 | RegularizedSVD::RegularizedSVD(const arma::mat& data, 31 | arma::mat& u, 32 | arma::mat& v, 33 | const size_t rank, 34 | const size_t iterations, 35 | const double alpha, 36 | const double lambda) : 37 | data(data), 38 | rank(rank), 39 | iterations(iterations), 40 | alpha(alpha), 41 | lambda(lambda), 42 | rSVDFunc(data, rank, lambda), 43 | optimizer(rSVDFunc, alpha, iterations * data.n_cols) 44 | { 45 | arma::mat parameters = rSVDFunc.GetInitialPoint(); 46 | 47 | // Train the model. 48 | Timer::Start("regularized_svd_optimization"); 49 | const double out = optimizer.Optimize(parameters); 50 | Timer::Stop("regularized_svd_optimization"); 51 | 52 | const size_t numUsers = max(data.row(0)) + 1; 53 | const size_t numItems = max(data.row(1)) + 1; 54 | 55 | u = parameters.submat(0, 0, rank - 1, numUsers - 1); 56 | v = parameters.submat(0, numUsers, rank - 1, numUsers + numItems - 1); 57 | } 58 | 59 | }; // namespace svd 60 | }; // namespace mlpack 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/mlpack/methods/sparse_coding/nothing_initializer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file nothing_initializer.hpp 3 | * @author Ryan Curtin 4 | * 5 | * An initializer for SparseCoding which does precisely nothing. It is useful 6 | * for when you have an already defined dictionary and you plan on setting it 7 | * with SparseCoding::Dictionary(). 8 | * 9 | * This file is part of MLPACK 1.0.10. 10 | * 11 | * MLPACK is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free 13 | * Software Foundation, either version 3 of the License, or (at your option) any 14 | * later version. 15 | * 16 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 17 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 18 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 19 | * details (LICENSE.txt). 20 | * 21 | * You should have received a copy of the GNU General Public License along with 22 | * MLPACK. If not, see . 23 | */ 24 | #ifndef __MLPACK_METHODS_SPARSE_CODING_NOTHING_INITIALIZER_HPP 25 | #define __MLPACK_METHODS_SPARSE_CODING_NOTHING_INITIALIZER_HPP 26 | 27 | #include 28 | 29 | namespace mlpack { 30 | namespace sparse_coding { 31 | 32 | /** 33 | * A DictionaryInitializer for SparseCoding which does not initialize anything; 34 | * it is useful for when the dictionary is already known and will be set with 35 | * SparseCoding::Dictionary(). 36 | */ 37 | class NothingInitializer 38 | { 39 | public: 40 | /** 41 | * This function does not initialize the dictionary. This will cause problems 42 | * for SparseCoding if the dictionary is not set manually before running the 43 | * method. 44 | */ 45 | static void Initialize(const arma::mat& /* data */, 46 | const size_t /* atoms */, 47 | arma::mat& /* dictionary */) 48 | { 49 | // Do nothing! 50 | } 51 | }; 52 | 53 | }; // namespace sparse_coding 54 | }; // namespace mlpack 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/mlpack/methods/sparse_coding/random_initializer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file random_initializer.hpp 3 | * @author Nishant Mehta 4 | * 5 | * A very simple random dictionary initializer for SparseCoding; it is probably 6 | * not a very good choice. 7 | * 8 | * This file is part of MLPACK 1.0.10. 9 | * 10 | * MLPACK is free software: you can redistribute it and/or modify it under the 11 | * terms of the GNU Lesser General Public License as published by the Free 12 | * Software Foundation, either version 3 of the License, or (at your option) any 13 | * later version. 14 | * 15 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 18 | * details (LICENSE.txt). 19 | * 20 | * You should have received a copy of the GNU General Public License along with 21 | * MLPACK. If not, see . 22 | */ 23 | #ifndef __MLPACK_METHODS_SPARSE_CODING_RANDOM_INITIALIZER_HPP 24 | #define __MLPACK_METHODS_SPARSE_CODING_RANDOM_INITIALIZER_HPP 25 | 26 | #include 27 | 28 | namespace mlpack { 29 | namespace sparse_coding { 30 | 31 | /** 32 | * A DictionaryInitializer for use with the SparseCoding class. This provides a 33 | * random, normally distributed dictionary, such that each atom has a norm of 1. 34 | */ 35 | class RandomInitializer 36 | { 37 | public: 38 | /** 39 | * Initialize the dictionary randomly from a normal distribution, such that 40 | * each atom has a norm of 1. This is simple enough to be included with the 41 | * definition. 42 | * 43 | * @param data Dataset to use for initialization. 44 | * @param atoms Number of atoms (columns) in the dictionary. 45 | * @param dictionary Dictionary to initialize. 46 | */ 47 | static void Initialize(const arma::mat& data, 48 | const size_t atoms, 49 | arma::mat& dictionary) 50 | { 51 | // Create random dictionary. 52 | dictionary.randn(data.n_rows, atoms); 53 | 54 | // Normalize each atom. 55 | for (size_t j = 0; j < atoms; ++j) 56 | dictionary.col(j) /= norm(dictionary.col(j), 2); 57 | } 58 | }; 59 | 60 | }; // namespace sparse_coding 61 | }; // namespace mlpack 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/mlpack/prereqs.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file prereqs.hpp 3 | * 4 | * The core includes that mlpack expects; standard C++ includes and Armadillo. 5 | * 6 | * This file is part of MLPACK 1.0.10. 7 | * 8 | * MLPACK is free software: you can redistribute it and/or modify it under the 9 | * terms of the GNU Lesser General Public License as published by the Free 10 | * Software Foundation, either version 3 of the License, or (at your option) any 11 | * later version. 12 | * 13 | * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 15 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 16 | * details (LICENSE.txt). 17 | * 18 | * You should have received a copy of the GNU General Public License along with 19 | * MLPACK. If not, see . 20 | */ 21 | #ifndef __MLPACK_PREREQS_HPP 22 | #define __MLPACK_PREREQS_HPP 23 | 24 | // First, check if Armadillo was included before, warning if so. 25 | #ifdef ARMA_INCLUDES 26 | #pragma message "Armadillo was included before mlpack; this can sometimes cause\ 27 | problems. It should only be necessary to include and not\ 28 | ." 29 | #endif 30 | 31 | // Next, standard includes. 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | // Defining _USE_MATH_DEFINES should set M_PI. 42 | #define _USE_MATH_DEFINES 43 | #include 44 | 45 | // For tgamma(). 46 | #include 47 | 48 | // But if it's not defined, we'll do it. 49 | #ifndef M_PI 50 | #define M_PI 3.141592653589793238462643383279 51 | #endif 52 | 53 | // Give ourselves a nice way to force functions to be inline if we need. 54 | #define force_inline 55 | #if defined(__GNUG__) && !defined(DEBUG) 56 | #undef force_inline 57 | #define force_inline __attribute__((always_inline)) 58 | #elif defined(_MSC_VER) && !defined(DEBUG) 59 | #undef force_inline 60 | #define force_inline __forceinline 61 | #endif 62 | 63 | // Now include Armadillo through the special mlpack extensions. 64 | #include 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /vignettes/ref.bib: -------------------------------------------------------------------------------- 1 | @article{Eddelbuettel:Francois:2011:JSSOBK:v40i08, 2 | author = "Dirk Eddelbuettel and Romain Francois", 3 | title = "Rcpp: Seamless {R} and {C++} Integration", 4 | journal = "Journal of Statistical Software", 5 | volume = "40", 6 | number = "8", 7 | pages = "1--18", 8 | day = "13", 9 | month = "4", 10 | year = "2011", 11 | CODEN = "JSSOBK", 12 | ISSN = "1548-7660", 13 | bibdate = "2011-03-21", 14 | URL = "http://www.jstatsoft.org/v40/i08", 15 | accepted = "2011-03-21", 16 | acknowledgement = "", 17 | keywords = "", 18 | submitted = "2010-11-15", 19 | } 20 | 21 | @article{eddelbuettel2014rcpparmadillo, 22 | title={Rcpparmadillo: Accelerating {R} with high-performance {C++} linear algebra}, 23 | author={Eddelbuettel, Dirk and Sanderson, Conrad}, 24 | journal={Computational Statistics \& Data Analysis}, 25 | volume={71}, 26 | pages={1054--1063}, 27 | year={2014}, 28 | publisher={Elsevier} 29 | } 30 | 31 | @article{curtin2013mlpack, 32 | title={{MLPACK}: A scalable {C++} machine learning library}, 33 | author={Curtin, Ryan and Cline, James and Slagle, Neil and March, William and Ram, Parikshit and Mehta, Nishant and Gray, Alexander}, 34 | journal={The Journal of Machine Learning Research}, 35 | volume={14}, 36 | number={1}, 37 | pages={801--805}, 38 | year={2013}, 39 | publisher={JMLR. org} 40 | } 41 | 42 | @TECHREPORT{arma, 43 | author = {Conrad Sanderson}, 44 | title = {Armadillo: An Open Source {C++} Linear Algebra Library for Fast Prototyping 45 | and Computationally Intensive Experiments}, 46 | institution = {NICTA}, 47 | year = {2010}, 48 | owner = {Administrator}, 49 | timestamp = {2014.01.11}, 50 | url = {http://arma.sf.net/} 51 | } 52 | 53 | @MANUAL{inline, 54 | title = {{inline}: inline {C}, {C++}, {Fortran} function calls from {R}}, 55 | author = {Oleg Sklyar and Duncan Murdoch and Mike Smith and Dirk Eddelbuettel 56 | and Romain Fran\c{c}ois}, 57 | year = {2013}, 58 | note = {R package version 0.3.13}, 59 | owner = {Administrator}, 60 | timestamp = {2013.12.29}, 61 | url = {http://cran.r-project.org/web/package=inline} 62 | } 63 | 64 | @MANUAL{rbenchmark, 65 | title = {rbenchmark: Benchmarking routine for {R}}, 66 | author = {Wacek Kusnierczyk}, 67 | year = {2012}, 68 | note = {R package version 1.0}, 69 | url = {http://cran.r-project.org/packages=rbenchmark} 70 | } 71 | --------------------------------------------------------------------------------