Add license to files.
This commit is contained in:
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Utility functions to add options to boost::program_options based on their
|
||||
* type.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_ADD_TO_PO_HPP
|
||||
#define MLPACK_BINDINGS_CLI_ADD_TO_PO_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Return the default value of a parameter, depending on its type.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_DEFAULT_PARAM_HPP
|
||||
#define MLPACK_BINDINGS_CLI_DEFAULT_PARAM_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Return the default value of a parameter, depending on its type.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_DEFAULT_PARAM_IMPL_HPP
|
||||
#define MLPACK_BINDINGS_CLI_DEFAULT_PARAM_IMPL_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* If any memory has been allocated by the parameter, delete it.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_DELETE_ALLOCATED_MEMORY_HPP
|
||||
#define MLPACK_BINDINGS_CLI_DELETE_ALLOCATED_MEMORY_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
* @author Matthew Amidon
|
||||
*
|
||||
* Terminate the program; handle --verbose option; print output parameters.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_END_PROGRAM_HPP
|
||||
#define MLPACK_BINDINGS_CLI_END_PROGRAM_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* If the parameter has a type that may need to be deleted, return the address
|
||||
* of that object. Otherwise return NULL.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_GET_ALLOCATED_MEMORY_HPP
|
||||
#define MLPACK_BINDINGS_CLI_GET_ALLOCATED_MEMORY_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Use template metaprogramming to get the right type of parameter.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_GET_PARAM_HPP
|
||||
#define MLPACK_BINDINGS_CLI_GET_PARAM_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Print the parameter to stdout, using template metaprogramming to enforce
|
||||
* different behavior for different parameter types.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_HPP
|
||||
#define MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Implementation of parameter printing functions.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_IMPL_HPP
|
||||
#define MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_IMPL_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Return the parameter name that the user would specify on the command line,
|
||||
* with different behavior for different parameter types.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_NAME_HPP
|
||||
#define MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_NAME_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Return the parameter name that the user would specify on the command line,
|
||||
* with different behavior for different parameter types.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_NAME_IMPL_HPP
|
||||
#define MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_NAME_IMPL_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Given a parameter value, print what the user might actually specify on the
|
||||
* command line. Basically this adds ".csv" to types where data must be loaded.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_VALUE_HPP
|
||||
#define MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_VALUE_HPP
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
* Return the parameter value that the user would specify on the command line
|
||||
* depending on the type of the option. Basically this adds ".csv" to types
|
||||
* that need to be loaded.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_VALUE_IMPL_HPP
|
||||
#define MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_VALUE_IMPL_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Use template metaprogramming to get the right type of parameter, but without
|
||||
* any processing.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_GET_RAW_PARAM_HPP
|
||||
#define MLPACK_BINDINGS_CLI_GET_RAW_PARAM_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Map a parameter name to what it seen by boost::program_options using template
|
||||
* metaprogramming.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_MAP_PARAMETER_NAME_HPP
|
||||
#define MLPACK_BINDINGS_CLI_MAP_PARAMETER_NAME_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Output a parameter of different types using template metaprogramming.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_OUTPUT_PARAM_HPP
|
||||
#define MLPACK_BINDINGS_CLI_OUTPUT_PARAM_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Implementations of functions to output parameters of different types.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_CORE_UTIL_OUTPUT_PARAM_IMPL_HPP
|
||||
#define MLPACK_CORE_UTIL_OUTPUT_PARAM_IMPL_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Template metaprogramming structures to find the type (as seen by
|
||||
* boost::program_options) of a particular option type.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_PARAMETER_TYPE_HPP
|
||||
#define MLPACK_BINDINGS_CLI_PARAMETER_TYPE_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
* @author Matthew Amidon
|
||||
*
|
||||
* Parse the command line options.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_PARSE_COMMAND_LINE_HPP
|
||||
#define MLPACK_BINDINGS_CLI_PARSE_COMMAND_LINE_HPP
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
* This will generate a string representing what a user should type to invoke a
|
||||
* given option. For the command-line bindings, this will generate strings like
|
||||
* '--param_name=x' or '--param_name'.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_PRINT_DOC_FUNCTIONS_HPP
|
||||
#define MLPACK_BINDINGS_CLI_PRINT_DOC_FUNCTIONS_HPP
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
* This will generate a string representing what a user should type to invoke a
|
||||
* given option. For the command-line bindings, this will generate strings like
|
||||
* '--param_name=x' or '--param_name'.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_PRINT_DOC_FUNCTIONS_IMPL_HPP
|
||||
#define MLPACK_BINDINGS_CLI_PRINT_DOC_FUNCTIONS_IMPL_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Print help for a given function.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#include "print_help.hpp"
|
||||
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Print help for a command-line program.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_PRINT_HELP_HPP
|
||||
#define MLPACK_BINDINGS_CLI_PRINT_HELP_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Use template metaprogramming to get the right type of parameter.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_SET_PARAM_HPP
|
||||
#define MLPACK_BINDINGS_CLI_SET_PARAM_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Given a util::ParamData object, return a string containing the type of the input
|
||||
* parameter as given on the command-line.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_STRING_TYPE_PARAM_HPP
|
||||
#define MLPACK_BINDINGS_CLI_STRING_TYPE_PARAM_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Implementations of StringTypeParam().
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_STRING_TYPE_PARAM_IMPL_HPP
|
||||
#define MLPACK_BINDINGS_CLI_STRING_TYPE_PARAM_IMPL_HPP
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
# Build rules for the MATLAB bindings for MLPACK. These may not work well on
|
||||
# non-Linux systems.
|
||||
|
||||
# We need the mex compiler for this to work.
|
||||
find_package(MatlabMex REQUIRED)
|
||||
|
||||
# If the mex compiler is wrapping an "unsupported" version, warn the user that
|
||||
# they may have issues with the produced bindings for a multitude of reasons.
|
||||
# We can only reasonably check this on a UNIX-like system.
|
||||
if(UNIX)
|
||||
# The file test.cpp does not exist, but mex will still print a warning if it's
|
||||
# using a weird version.
|
||||
execute_process(COMMAND "${MATLAB_MEX}" test.cpp
|
||||
RESULT_VARIABLE MEX_RESULT_TRASH
|
||||
OUTPUT_VARIABLE MEX_OUTPUT
|
||||
ERROR_VARIABLE MEX_ERROR_TRASH)
|
||||
|
||||
string(REGEX MATCH "Warning: You are using" MEX_WARNING "${MEX_OUTPUT}")
|
||||
|
||||
if(MEX_WARNING)
|
||||
# We have to find the old compiler version and the new compiler version; if
|
||||
# the MATLAB version is newer, then we don't need to worry. If this step
|
||||
# fails somehow, we will just issue the warning anyway (just in case).
|
||||
string(REGEX REPLACE
|
||||
".*using [a-zA-Z]* version \"([0-9.]*)[^\"]*\".*"
|
||||
"\\1" OTHER_COMPILER_VERSION "${MEX_OUTPUT}")
|
||||
string(REGEX REPLACE
|
||||
".*currently supported with MEX is \"([0-9.]*)[^\"]*\".*"
|
||||
"\\1" MEX_COMPILER_VERSION "${MEX_OUTPUT}")
|
||||
|
||||
# If MEX_COMPILER_VERSION is greater than OTHER_COMPILER_VERSION, we don't
|
||||
# need to issue a warning.
|
||||
set(NEED_TO_WARN 1)
|
||||
if(MEX_COMPILER_VERSION AND OTHER_COMPILER_VERSION)
|
||||
# We seem to have read two valid version strings. So we can compare
|
||||
# them, and maybe we don't need to issue the warning.
|
||||
if(NOT ("${MEX_COMPILER_VERSION}" VERSION_LESS
|
||||
"${OTHER_COMPILER_VERSION}"))
|
||||
# The mex compiler is newer than our version. So no warning is
|
||||
# needed.
|
||||
set(NEED_TO_WARN 0)
|
||||
endif(NOT ("${MEX_COMPILER_VERSION}" VERSION_LESS
|
||||
"${OTHER_COMPILER_VERSION}"))
|
||||
endif()
|
||||
|
||||
if(NEED_TO_WARN EQUAL 1)
|
||||
message(WARNING "The MATLAB runtime glibc is different than the system "
|
||||
" glibc. This can (and probably will) cause the MLPACK bindings "
|
||||
"generated by this build script to fail with odd GLIBCXX_a_b_c "
|
||||
"version complaints when they are run. Assuming that the system "
|
||||
"glibc is newer than the MATLAB-provided version, the MATLAB version "
|
||||
"can probably be deleted (always save a copy in case this is wrong!)."
|
||||
"\nFor more information on this confusing issue, see\n"
|
||||
"http://dovgalecs.com/blog/matlab-glibcxx_3-4-11-not-found/\nand for "
|
||||
"an overly-detailed dissertation/rant on why it is not possible to "
|
||||
"work around this issue in any way, see\n"
|
||||
"http://www.mlpack.org/trac/ticket/253 for more information.")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Ignore the fact that we are setting CMAKE_SHARED_LIBRARY_CXX_FLAGS on CMake
|
||||
# 2.8.9 and newer. Because we are requiring at least CMake 2.8.5, we only have
|
||||
# to check the patch version.
|
||||
if(${CMAKE_PATCH_VERSION} GREATER 8)
|
||||
cmake_policy(SET CMP0018 OLD)
|
||||
endif()
|
||||
|
||||
# Use the mex compiler to compile.
|
||||
set(CMAKE_CXX_COMPILER "${MATLAB_MEX}")
|
||||
|
||||
# Set flags for the mex compiler, because a lot of the default CMake flags
|
||||
# aren't accepted by mex. The user who wants to customize these things should
|
||||
# probably modify their mexopts.sh so that mex uses those flags by default.
|
||||
# There is no easy way to tell mex to compile with profiling symbols, so that is
|
||||
# not done even if PROFILE is set.
|
||||
if(DEBUG)
|
||||
set(CMAKE_CXX_FLAGS "-g")
|
||||
set(CMAKE_C_FLAGS "-g")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "-O")
|
||||
set(CMAKE_C_FLAGS "-O")
|
||||
endif()
|
||||
|
||||
# Don't give -fPIC; mex will do that for us.
|
||||
set(CMAKE_SHARED_LIBRARY_C_FLAGS "")
|
||||
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "")
|
||||
|
||||
# Don't make 'lib<method>.mexglx'.
|
||||
set(CMAKE_SHARED_LIBRARY_PREFIX "")
|
||||
set(CMAKE_SHARED_MODULE_PREFIX "")
|
||||
|
||||
# Set custom commands for mex compilation, because the flags are (in general)
|
||||
# odd and different.
|
||||
set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> -outdir <OBJECT_DIR> <FLAGS> -c <SOURCE>")
|
||||
set(CMAKE_CXX_CREATE_SHARED_MODULE "<CMAKE_CXX_COMPILER> -cxx <LINK_FLAGS> -output <TARGET> <OBJECTS> <LINK_LIBRARIES>")
|
||||
set(CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_MODULE}")
|
||||
|
||||
# mex is weird because it doesn't respect the -o option, but in general it
|
||||
# appears to turn <source>.cpp into <source>.o, so CMake needs to know to
|
||||
# replace the extension.
|
||||
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
|
||||
|
||||
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
|
||||
set(CMAKE_SHARED_LIBRARY_SUFFIX ".mexa64")
|
||||
set(CMAKE_SHARED_MODULE_SUFFIX ".mexa64")
|
||||
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86" OR ${CMAKE_SYSTEM_PROCESSOR}
|
||||
STREQUAL "i686")
|
||||
set(CMAKE_SHARED_LIBRARY_SUFFIX ".mexglx")
|
||||
set(CMAKE_SHARED_MODULE_SUFFIX ".mexglx")
|
||||
endif()
|
||||
|
||||
# Place MATLAB bindings in matlab/.
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/matlab/)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/) # So we can include <mlpack/...>.
|
||||
|
||||
# Set MATLAB toolbox install directory.
|
||||
set(MATLAB_TOOLBOX_DIR "${MATLAB_ROOT}/toolbox")
|
||||
|
||||
# CHANGE HERE FOR NEW BINDINGS!!!!
|
||||
add_subdirectory(allkfn)
|
||||
add_subdirectory(allknn)
|
||||
add_subdirectory(emst)
|
||||
add_subdirectory(kmeans)
|
||||
add_subdirectory(range_search)
|
||||
add_subdirectory(gmm)
|
||||
add_subdirectory(pca)
|
||||
add_subdirectory(kernel_pca)
|
||||
add_subdirectory(lars)
|
||||
add_subdirectory(nca)
|
||||
add_subdirectory(nmf)
|
||||
|
||||
# Create a target whose sole purpose is to modify the pathdef.m MATLAB file so
|
||||
# that the MLPACK toolbox is added to the MATLAB default path.
|
||||
add_custom_target(matlab ALL
|
||||
# Modify pathdef.m.
|
||||
COMMAND ${CMAKE_COMMAND} -D MATLAB_ROOT="${MATLAB_ROOT}" -D
|
||||
PATHDEF_OUTPUT_FILE="${CMAKE_BINARY_DIR}/matlab/pathdef.m" -P
|
||||
${CMAKE_SOURCE_DIR}/CMake/ModifyMatlabPathdef.cmake
|
||||
# Due to the dependencies, 'make matlab' makes all the bindings.
|
||||
DEPENDS
|
||||
allknn_mex
|
||||
allkfn_mex
|
||||
emst_mex
|
||||
gmm_mex
|
||||
kmeans_mex
|
||||
range_search_mex
|
||||
)
|
||||
|
||||
install(FILES "${CMAKE_BINARY_DIR}/matlab/pathdef.m"
|
||||
DESTINATION "${MATLAB_ROOT}/toolbox/local/"
|
||||
)
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# Simple rules for building mex file. The _mex suffix is necessary to avoid
|
||||
# target name conflicts, and the mex file must have a different name than the .m
|
||||
# file.
|
||||
add_library(allkfn_mex SHARED
|
||||
allkfn.cpp
|
||||
)
|
||||
target_link_libraries(allkfn_mex
|
||||
mlpack
|
||||
${LIBXML2_LIBRARIES}
|
||||
)
|
||||
|
||||
# Installation rule. Install both the mex and the MATLAB file.
|
||||
install(TARGETS allkfn_mex
|
||||
LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
install(FILES
|
||||
allkfn.m
|
||||
DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
@@ -1,194 +0,0 @@
|
||||
/**
|
||||
* @file allkfn.cpp
|
||||
* @author Patrick Mason
|
||||
*
|
||||
* MEX function for MATLAB All-kFN binding.
|
||||
*/
|
||||
#include "mex.h"
|
||||
|
||||
#include <mlpack/core.hpp>
|
||||
#include <mlpack/methods/neighbor_search/neighbor_search.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::neighbor;
|
||||
using namespace mlpack::tree;
|
||||
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
// Check the inputs.
|
||||
if (nrhs != 6)
|
||||
{
|
||||
mexErrMsgTxt("Expecting seven arguments.");
|
||||
}
|
||||
|
||||
if (nlhs != 2)
|
||||
{
|
||||
mexErrMsgTxt("Two outputs required.");
|
||||
}
|
||||
|
||||
size_t numPoints = mxGetN(prhs[0]);
|
||||
size_t numDimensions = mxGetM(prhs[0]);
|
||||
|
||||
// Create the reference matrix.
|
||||
arma::mat referenceData(numDimensions, numPoints);
|
||||
// setting the values.
|
||||
double * mexDataPoints = mxGetPr(prhs[0]);
|
||||
for (int i = 0, n = numPoints * numDimensions; i < n; ++i)
|
||||
{
|
||||
referenceData(i) = mexDataPoints[i];
|
||||
}
|
||||
|
||||
// getting the leafsize
|
||||
int lsInt = (int) mxGetScalar(prhs[3]);
|
||||
|
||||
// getting k
|
||||
size_t k = (int) mxGetScalar(prhs[1]);
|
||||
|
||||
// naive algorithm?
|
||||
bool naive = (mxGetScalar(prhs[4]) == 1.0);
|
||||
|
||||
// single mode?
|
||||
bool singleMode = (mxGetScalar(prhs[5]) == 1.0);
|
||||
|
||||
// the query matrix
|
||||
double * mexQueryPoints = mxGetPr(prhs[2]);
|
||||
arma::mat queryData;
|
||||
bool hasQueryData = ((mxGetM(prhs[2]) != 0) && (mxGetN(prhs[2]) != 0));
|
||||
|
||||
// Sanity check on k value: must be greater than 0, must be less than the
|
||||
// number of reference points.
|
||||
if (k > referenceData.n_cols)
|
||||
{
|
||||
stringstream os;
|
||||
os << "Invalid k: " << k << "; must be greater than 0 and less ";
|
||||
os << "than or equal to the number of reference points (";
|
||||
os << referenceData.n_cols << ")." << endl;
|
||||
mexErrMsgTxt(os.str().c_str());
|
||||
}
|
||||
|
||||
// Sanity check on leaf size.
|
||||
if (lsInt < 0)
|
||||
{
|
||||
stringstream os;
|
||||
os << "Invalid leaf size: " << lsInt << ". Must be greater ";
|
||||
os << "than or equal to 0." << endl;
|
||||
mexErrMsgTxt(os.str().c_str());
|
||||
}
|
||||
size_t leafSize = lsInt;
|
||||
|
||||
// Naive mode overrides single mode.
|
||||
if (singleMode && naive)
|
||||
{
|
||||
mexWarnMsgTxt("single_mode ignored because naive is present.");
|
||||
}
|
||||
|
||||
if (naive)
|
||||
leafSize = referenceData.n_cols;
|
||||
|
||||
arma::Mat<size_t> neighbors;
|
||||
arma::mat distances;
|
||||
|
||||
AllkFN* allkfn = NULL;
|
||||
|
||||
std::vector<size_t> oldFromNewRefs;
|
||||
|
||||
// Build trees by hand, so we can save memory: if we pass a tree to
|
||||
// NeighborSearch, it does not copy the matrix.
|
||||
BinarySpaceTree<bound::HRectBound<2>, QueryStat<FurthestNeighborSort> >
|
||||
refTree(referenceData, oldFromNewRefs, leafSize);
|
||||
BinarySpaceTree<bound::HRectBound<2>, QueryStat<FurthestNeighborSort> >*
|
||||
queryTree = NULL; // Empty for now.
|
||||
|
||||
std::vector<size_t> oldFromNewQueries;
|
||||
|
||||
if (hasQueryData)
|
||||
{
|
||||
// setting the values.
|
||||
mexDataPoints = mxGetPr(prhs[2]);
|
||||
numPoints = mxGetN(prhs[2]);
|
||||
numDimensions = mxGetM(prhs[2]);
|
||||
queryData = arma::mat(numDimensions, numPoints);
|
||||
for (int i = 0, n = numPoints * numDimensions; i < n; ++i)
|
||||
{
|
||||
queryData(i) = mexDataPoints[i];
|
||||
}
|
||||
|
||||
if (naive && leafSize < queryData.n_cols)
|
||||
leafSize = queryData.n_cols;
|
||||
|
||||
// Build trees by hand, so we can save memory: if we pass a tree to
|
||||
// NeighborSearch, it does not copy the matrix.
|
||||
queryTree = new BinarySpaceTree<bound::HRectBound<2>,
|
||||
QueryStat<FurthestNeighborSort> >(queryData, oldFromNewQueries,
|
||||
leafSize);
|
||||
|
||||
allkfn = new AllkFN(&refTree, queryTree, referenceData, queryData,
|
||||
singleMode);
|
||||
}
|
||||
else
|
||||
{
|
||||
allkfn = new AllkFN(&refTree, referenceData, singleMode);
|
||||
}
|
||||
|
||||
allkfn->Search(k, neighbors, distances);
|
||||
|
||||
// We have to map back to the original indices from before the tree
|
||||
// construction.
|
||||
arma::mat distancesOut(distances.n_rows, distances.n_cols);
|
||||
arma::Mat<size_t> neighborsOut(neighbors.n_rows, neighbors.n_cols);
|
||||
|
||||
// Do the actual remapping.
|
||||
if (hasQueryData)
|
||||
{
|
||||
for (size_t i = 0; i < distances.n_cols; ++i)
|
||||
{
|
||||
// Map distances (copy a column).
|
||||
distancesOut.col(oldFromNewQueries[i]) = distances.col(i);
|
||||
|
||||
// Map indices of neighbors.
|
||||
for (size_t j = 0; j < distances.n_rows; ++j)
|
||||
{
|
||||
neighborsOut(j, oldFromNewQueries[i]) = oldFromNewRefs[neighbors(j, i)];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < distances.n_cols; ++i)
|
||||
{
|
||||
// Map distances (copy a column).
|
||||
distancesOut.col(oldFromNewRefs[i]) = distances.col(i);
|
||||
|
||||
// Map indices of neighbors.
|
||||
for (size_t j = 0; j < distances.n_rows; ++j)
|
||||
{
|
||||
neighborsOut(j, oldFromNewRefs[i]) = oldFromNewRefs[neighbors(j, i)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up.
|
||||
if (queryTree)
|
||||
delete queryTree;
|
||||
|
||||
// constructing matrix to return to matlab
|
||||
plhs[0] = mxCreateDoubleMatrix(distances.n_rows, distances.n_cols, mxREAL);
|
||||
plhs[1] = mxCreateDoubleMatrix(neighbors.n_rows, neighbors.n_cols, mxREAL);
|
||||
|
||||
// setting the values
|
||||
double * out = mxGetPr(plhs[0]);
|
||||
for (int i = 0, n = distances.n_rows * distances.n_cols; i < n; ++i)
|
||||
{
|
||||
out[i] = distances(i);
|
||||
}
|
||||
out = mxGetPr(plhs[1]);
|
||||
for (int i = 0, n = neighbors.n_rows * neighbors.n_cols; i < n; ++i)
|
||||
{
|
||||
out[i] = neighbors(i);
|
||||
}
|
||||
|
||||
// More clean up.
|
||||
delete allkfn;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
function [distances, neighbors] = allkfn(dataPoints, k, varargin)
|
||||
% [distances, neighbors] = allkfn(dataPoints, k, varargin)
|
||||
%
|
||||
% Calculate the all k-furthest-neighbors of a set of points. You may specify a
|
||||
% separate set of reference points and query points, or just a reference set
|
||||
% which will be used as both the reference and query set.
|
||||
%
|
||||
% The output matrices are organized such that row i and column j in the
|
||||
% neighbors matrix corresponds to the index of the point in the reference set
|
||||
% which is the i'th furthest neighbor from the point in the query set with index
|
||||
% j. Row i and column j in the distances output matrix corresponds to the
|
||||
% distance between those two points.
|
||||
%
|
||||
% Parameters:
|
||||
%
|
||||
% dataPoints - The reference set of data points. Columns are assumed to
|
||||
% represent dimensions, with rows representing separate points.
|
||||
% k - The number of furthest neighbors to find.
|
||||
%
|
||||
% Optional parameters (i.e. allkfn(..., 'parameter', value, ...)):
|
||||
%
|
||||
% 'queryPoints' - An optional set of query points, if the reference and query
|
||||
% sets are different. Columns are assumed to represent
|
||||
% dimensions, with rows representing separate points.
|
||||
% 'leafSize' - Leaf size in the kd-tree. Defaults to 20.
|
||||
% 'method' - Algorithm to use. 'naive' uses naive O(n^2) computation;
|
||||
% 'single' uses single-tree traversal; 'dual' uses the standard
|
||||
% dual-tree traversal. Defaults to 'dual'.
|
||||
%
|
||||
% Examples:
|
||||
%
|
||||
% [distances, neighbors] = allkfn(dataPoints, 5);
|
||||
% [distances, neighbors] = allkfn(dataPoints, 5, 'method', 'single');
|
||||
% [distances, neighbors] = allkfn(dataPoints, 5, 'queryPoints', queryPoints);
|
||||
|
||||
% A parser for the inputs.
|
||||
p = inputParser;
|
||||
p.addParamValue('queryPoints', zeros(0), @ismatrix);
|
||||
p.addParamValue('leafSize', 20, @isscalar);
|
||||
p.addParamValue('naive', false, @(x) (x == true) || (x == false));
|
||||
p.addParamValue('singleMode', false, @(x) (x == true) || (x == false));
|
||||
|
||||
% parsing the varargin options
|
||||
varargin{:}
|
||||
p.parse(varargin{:});
|
||||
parsed = p.Results;
|
||||
parsed
|
||||
|
||||
% interfacing with mlpack
|
||||
[distances neighbors] = mex_allkfn(dataPoints', k, parsed.queryPoints', ...
|
||||
parsed.leafSize, parsed.naive, parsed.singleMode);
|
||||
|
||||
% transposing results
|
||||
distances = distances';
|
||||
neighbors = neighbors' + 1; % matlab indices began at 1, not zero
|
||||
|
||||
return;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# Simple rules for building mex file. The _mex suffix is necessary to avoid
|
||||
# target name conflicts, and the mex file must have a different name than the .m
|
||||
# file.
|
||||
add_library(allknn_mex SHARED
|
||||
allknn.cpp
|
||||
)
|
||||
target_link_libraries(allknn_mex
|
||||
mlpack
|
||||
${LIBXML2_LIBRARIES}
|
||||
)
|
||||
|
||||
# Installation rule. Install both the mex and the MATLAB file.
|
||||
install(TARGETS allknn_mex
|
||||
LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
install(FILES
|
||||
allknn.m
|
||||
DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
@@ -1,279 +0,0 @@
|
||||
/**
|
||||
* @file allknn.cpp
|
||||
* @author Patrick Mason
|
||||
*
|
||||
* MEX function for MATLAB All-kNN binding.
|
||||
*/
|
||||
#include "mex.h"
|
||||
|
||||
#include <mlpack/core.hpp>
|
||||
#include <mlpack/core/tree/cover_tree.hpp>
|
||||
#include <mlpack/methods/neighbor_search/neighbor_search.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::neighbor;
|
||||
using namespace mlpack::tree;
|
||||
|
||||
// the gateway, required by all mex functions
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
// checking inputs
|
||||
if (nrhs != 7)
|
||||
{
|
||||
mexErrMsgTxt("Expecting seven arguments.");
|
||||
}
|
||||
|
||||
if (nlhs != 2)
|
||||
{
|
||||
mexErrMsgTxt("Two outputs required.");
|
||||
}
|
||||
|
||||
// getting the dimensions of the reference matrix
|
||||
size_t numPoints = mxGetN(prhs[0]);
|
||||
size_t numDimensions = mxGetM(prhs[0]);
|
||||
|
||||
// feeding the referenceData matrix
|
||||
arma::mat referenceData(numDimensions, numPoints);
|
||||
// setting the values.
|
||||
double * mexDataPoints = mxGetPr(prhs[0]);
|
||||
for (int i = 0, n = numPoints * numDimensions; i < n; ++i)
|
||||
{
|
||||
referenceData(i) = mexDataPoints[i];
|
||||
}
|
||||
|
||||
// getting the leafsize
|
||||
int lsInt = (int) mxGetScalar(prhs[3]);
|
||||
|
||||
// getting k
|
||||
size_t k = (int) mxGetScalar(prhs[1]);
|
||||
|
||||
// naive algorithm?
|
||||
bool naive = (mxGetScalar(prhs[4]) == 1.0);
|
||||
|
||||
// single mode?
|
||||
bool singleMode = (mxGetScalar(prhs[5]) == 1.0);
|
||||
|
||||
// the query matrix
|
||||
double * mexQueryPoints = mxGetPr(prhs[2]);
|
||||
arma::mat queryData;
|
||||
bool hasQueryData = ((mxGetM(prhs[2]) != 0) && (mxGetN(prhs[2]) != 0));
|
||||
|
||||
// cover-tree?
|
||||
bool usesCoverTree = (mxGetScalar(prhs[6]) == 1.0);
|
||||
|
||||
// Sanity check on k value: must be greater than 0, must be less than the
|
||||
// number of reference points.
|
||||
if (k > referenceData.n_cols)
|
||||
{
|
||||
stringstream os;
|
||||
os << "Invalid k: " << k << "; must be greater than 0 and less ";
|
||||
os << "than or equal to the number of reference points (";
|
||||
os << referenceData.n_cols << ")." << endl;
|
||||
mexErrMsgTxt(os.str().c_str());
|
||||
}
|
||||
|
||||
// Sanity check on leaf size.
|
||||
if (lsInt < 0)
|
||||
{
|
||||
stringstream os;
|
||||
os << "Invalid leaf size: " << lsInt << ". Must be greater "
|
||||
"than or equal to 0." << endl;
|
||||
mexErrMsgTxt(os.str().c_str());
|
||||
}
|
||||
size_t leafSize = lsInt;
|
||||
|
||||
// Naive mode overrides single mode.
|
||||
if (singleMode && naive)
|
||||
{
|
||||
mexWarnMsgTxt("single_mode ignored because naive is present.");
|
||||
}
|
||||
|
||||
if (naive)
|
||||
leafSize = referenceData.n_cols;
|
||||
|
||||
arma::Mat<size_t> neighbors;
|
||||
arma::mat distances;
|
||||
|
||||
//if (!CLI::HasParam("cover_tree"))
|
||||
if (usesCoverTree)
|
||||
{
|
||||
// Because we may construct it differently, we need a pointer.
|
||||
AllkNN* allknn = NULL;
|
||||
|
||||
// Mappings for when we build the tree.
|
||||
std::vector<size_t> oldFromNewRefs;
|
||||
|
||||
// Build trees by hand, so we can save memory: if we pass a tree to
|
||||
// NeighborSearch, it does not copy the matrix.
|
||||
|
||||
BinarySpaceTree<bound::HRectBound<2>, QueryStat<NearestNeighborSort> >
|
||||
refTree(referenceData, oldFromNewRefs, leafSize);
|
||||
BinarySpaceTree<bound::HRectBound<2>, QueryStat<NearestNeighborSort> >*
|
||||
queryTree = NULL; // Empty for now.
|
||||
|
||||
std::vector<size_t> oldFromNewQueries;
|
||||
|
||||
if (hasQueryData)
|
||||
{
|
||||
// setting the values.
|
||||
mexDataPoints = mxGetPr(prhs[2]);
|
||||
numPoints = mxGetN(prhs[2]);
|
||||
numDimensions = mxGetM(prhs[2]);
|
||||
queryData = arma::mat(numDimensions, numPoints);
|
||||
for (int i = 0, n = numPoints * numDimensions; i < n; ++i)
|
||||
{
|
||||
queryData(i) = mexDataPoints[i];
|
||||
}
|
||||
|
||||
if (naive && leafSize < queryData.n_cols)
|
||||
leafSize = queryData.n_cols;
|
||||
|
||||
// Build trees by hand, so we can save memory: if we pass a tree to
|
||||
// NeighborSearch, it does not copy the matrix.
|
||||
if (!singleMode)
|
||||
{
|
||||
queryTree = new BinarySpaceTree<bound::HRectBound<2>,
|
||||
QueryStat<NearestNeighborSort> >(queryData, oldFromNewQueries,
|
||||
leafSize);
|
||||
}
|
||||
|
||||
allknn = new AllkNN(&refTree, queryTree, referenceData, queryData,
|
||||
singleMode);
|
||||
}
|
||||
else
|
||||
{
|
||||
allknn = new AllkNN(&refTree, referenceData, singleMode);
|
||||
}
|
||||
|
||||
arma::mat distancesOut;
|
||||
arma::Mat<size_t> neighborsOut;
|
||||
|
||||
allknn->Search(k, neighborsOut, distancesOut);
|
||||
|
||||
// We have to map back to the original indices from before the tree
|
||||
// construction.
|
||||
neighbors.set_size(neighborsOut.n_rows, neighborsOut.n_cols);
|
||||
distances.set_size(distancesOut.n_rows, distancesOut.n_cols);
|
||||
|
||||
// Do the actual remapping.
|
||||
if ((hasQueryData) && !singleMode)
|
||||
{
|
||||
for (size_t i = 0; i < distancesOut.n_cols; ++i)
|
||||
{
|
||||
// Map distances (copy a column) and square root.
|
||||
distances.col(oldFromNewQueries[i]) = sqrt(distancesOut.col(i));
|
||||
|
||||
// Map indices of neighbors.
|
||||
for (size_t j = 0; j < distancesOut.n_rows; ++j)
|
||||
{
|
||||
neighbors(j, oldFromNewQueries[i]) =
|
||||
oldFromNewRefs[neighborsOut(j, i)];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((hasQueryData) && singleMode)
|
||||
{
|
||||
// No remapping of queries is necessary. So distances are the same.
|
||||
distances = sqrt(distancesOut);
|
||||
|
||||
// The neighbor indices must be mapped.
|
||||
for (size_t j = 0; j < neighborsOut.n_elem; ++j)
|
||||
{
|
||||
neighbors[j] = oldFromNewRefs[neighborsOut[j]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < distancesOut.n_cols; ++i)
|
||||
{
|
||||
// Map distances (copy a column).
|
||||
distances.col(oldFromNewRefs[i]) = sqrt(distancesOut.col(i));
|
||||
|
||||
// Map indices of neighbors.
|
||||
for (size_t j = 0; j < distancesOut.n_rows; ++j)
|
||||
{
|
||||
neighbors(j, oldFromNewRefs[i]) = oldFromNewRefs[neighborsOut(j, i)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up.
|
||||
if (queryTree)
|
||||
delete queryTree;
|
||||
|
||||
delete allknn;
|
||||
}
|
||||
else // Cover trees.
|
||||
{
|
||||
// Build our reference tree.
|
||||
CoverTree<metric::LMetric<2, true>, tree::FirstPointIsRoot,
|
||||
QueryStat<NearestNeighborSort> > referenceTree(referenceData, 1.3);
|
||||
CoverTree<metric::LMetric<2, true>, tree::FirstPointIsRoot,
|
||||
QueryStat<NearestNeighborSort> >* queryTree = NULL;
|
||||
|
||||
NeighborSearch<NearestNeighborSort, metric::LMetric<2, true>,
|
||||
CoverTree<metric::LMetric<2, true>, tree::FirstPointIsRoot,
|
||||
QueryStat<NearestNeighborSort> > >* allknn = NULL;
|
||||
|
||||
// See if we have query data.
|
||||
if (hasQueryData)
|
||||
{
|
||||
// setting the values.
|
||||
mexDataPoints = mxGetPr(prhs[2]);
|
||||
numPoints = mxGetN(prhs[2]);
|
||||
numDimensions = mxGetM(prhs[2]);
|
||||
queryData = arma::mat(numDimensions, numPoints);
|
||||
for (int i = 0, n = numPoints * numDimensions; i < n; ++i)
|
||||
{
|
||||
queryData(i) = mexDataPoints[i];
|
||||
}
|
||||
|
||||
// Build query tree.
|
||||
if (!singleMode)
|
||||
{
|
||||
queryTree = new CoverTree<metric::LMetric<2, true>,
|
||||
tree::FirstPointIsRoot, QueryStat<NearestNeighborSort> >(queryData,
|
||||
1.3);
|
||||
}
|
||||
|
||||
allknn = new NeighborSearch<NearestNeighborSort, metric::LMetric<2, true>,
|
||||
CoverTree<metric::LMetric<2, true>, tree::FirstPointIsRoot,
|
||||
QueryStat<NearestNeighborSort> > >(&referenceTree, queryTree,
|
||||
referenceData, queryData, singleMode);
|
||||
}
|
||||
else
|
||||
{
|
||||
allknn = new NeighborSearch<NearestNeighborSort, metric::LMetric<2, true>,
|
||||
CoverTree<metric::LMetric<2, true>, tree::FirstPointIsRoot,
|
||||
QueryStat<NearestNeighborSort> > >(&referenceTree, referenceData,
|
||||
singleMode);
|
||||
}
|
||||
|
||||
allknn->Search(k, neighbors, distances);
|
||||
|
||||
delete allknn;
|
||||
|
||||
if (queryTree)
|
||||
delete queryTree;
|
||||
}
|
||||
|
||||
// writing back to matlab
|
||||
// constructing matrix to return to matlab
|
||||
plhs[0] = mxCreateDoubleMatrix(distances.n_rows, distances.n_cols, mxREAL);
|
||||
plhs[1] = mxCreateDoubleMatrix(neighbors.n_rows, neighbors.n_cols, mxREAL);
|
||||
|
||||
// setting the values
|
||||
double * out = mxGetPr(plhs[0]);
|
||||
for (int i = 0, n = distances.n_rows * distances.n_cols; i < n; ++i)
|
||||
{
|
||||
out[i] = distances(i);
|
||||
}
|
||||
out = mxGetPr(plhs[1]);
|
||||
for (int i = 0, n = neighbors.n_rows * neighbors.n_cols; i < n; ++i)
|
||||
{
|
||||
out[i] = neighbors(i);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
function [distances neighbors] = allknn(dataPoints, k, varargin)
|
||||
%All K-Nearest-Neighbors
|
||||
%
|
||||
% This program will calculate the all k-nearest-neighbors of a set of points
|
||||
% using kd-trees or cover trees (cover tree support is experimental and may not
|
||||
% be optimally fast). You may specify a separate set of reference points and
|
||||
% query points, or just a reference set which will be used as both the reference
|
||||
% and query set.
|
||||
%
|
||||
% For example, the following will calculate the 5 nearest neighbors of eachpoint
|
||||
% in 'input.csv' and store the distances in 'distances.csv' and the neighbors in
|
||||
% the file 'neighbors.csv':
|
||||
|
||||
% $ allknn --k=5 --reference_file=input.csv --distances_file=distances.csv
|
||||
% --neighbors_file=neighbors.csv
|
||||
|
||||
% The output files are organized such that row i and column j in the neighbors
|
||||
% output file corresponds to the index of the point in the reference set which
|
||||
% is the i'th nearest neighbor from the point in the query set with index j.
|
||||
% Row i and column j in the distances output file corresponds to the distance
|
||||
% between those two points.
|
||||
%
|
||||
% Parameters:
|
||||
% dataPoints - the matrix of data points. Columns are assumed to represent dimensions,
|
||||
% with rows representing seperate points.
|
||||
% method - the algorithm for computing the tree. 'naive' or 'boruvka', with
|
||||
% 'boruvka' being the default algorithm.
|
||||
% leafSize - Leaf size in the kd-tree. One-element leaves give the
|
||||
% empirically best performance, but at the cost of greater memory
|
||||
% requirements. One is default.
|
||||
%
|
||||
% Examples:
|
||||
% result = emst(dataPoints);
|
||||
% or
|
||||
% esult = emst(dataPoints,'method','naive');
|
||||
|
||||
% a parser for the inputs
|
||||
p = inputParser;
|
||||
p.addParamValue('queryPoints', zeros(0), @ismatrix);
|
||||
p.addParamValue('leafSize', 20, @isscalar);
|
||||
p.addParamValue('naive', false, @(x) (x == true) || (x == false));
|
||||
p.addParamValue('singleMode', false, @(x) (x == true) || (x == false));
|
||||
p.addParamValue('coverTree', false, @(x) (x == true) || (x == false));
|
||||
|
||||
% parsing the varargin options
|
||||
varargin{:}
|
||||
p.parse(varargin{:});
|
||||
parsed = p.Results;
|
||||
parsed
|
||||
|
||||
% interfacing with mlpack
|
||||
[distances neighbors] = mex_allknn(dataPoints', k, parsed.queryPoints', ...
|
||||
parsed.leafSize, parsed.naive, parsed.singleMode, parsed.coverTree);
|
||||
|
||||
% transposing results
|
||||
distances = distances';
|
||||
neighbors = neighbors' + 1; % matlab indices began at 1, not zero
|
||||
|
||||
return;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# Simple rules for building mex file. The _mex suffix is necessary to avoid
|
||||
# target name conflicts, and the mex file must have a different name than the .m
|
||||
# file.
|
||||
add_library(emst_mex SHARED
|
||||
emst.cpp
|
||||
)
|
||||
target_link_libraries(emst_mex
|
||||
mlpack
|
||||
${LIBXML2_LIBRARIES}
|
||||
)
|
||||
|
||||
# Installation rule. Install both the mex and the MATLAB file.
|
||||
install(TARGETS emst_mex
|
||||
LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
install(FILES
|
||||
emst.m
|
||||
DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
@@ -1,72 +0,0 @@
|
||||
/**
|
||||
* @file emst.cpp
|
||||
* @author Patrick Mason
|
||||
*
|
||||
* MEX function for MATLAB EMST binding.
|
||||
*/
|
||||
#include "mex.h"
|
||||
|
||||
#include <mlpack/core.hpp>
|
||||
#include <mlpack/methods/emst/dtb.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::emst;
|
||||
using namespace mlpack::tree;
|
||||
|
||||
// The gateway, required by all mex functions.
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
// Argument checks.
|
||||
if (nrhs != 3)
|
||||
{
|
||||
mexErrMsgTxt("Expecting an datapoints matrix, isBoruvka, and leafSize.");
|
||||
}
|
||||
|
||||
if (nlhs != 1)
|
||||
{
|
||||
mexErrMsgTxt("Output required.");
|
||||
}
|
||||
|
||||
const size_t numPoints = mxGetN(prhs[0]);
|
||||
const size_t numDimensions = mxGetM(prhs[0]);
|
||||
|
||||
// Converting from mxArray to armadillo matrix.
|
||||
arma::mat dataPoints(numDimensions, numPoints);
|
||||
|
||||
// Set the values.
|
||||
double* mexDataPoints = mxGetPr(prhs[0]);
|
||||
for (int i = 0, n = numPoints * numDimensions; i < n; ++i)
|
||||
{
|
||||
dataPoints(i) = mexDataPoints[i];
|
||||
}
|
||||
|
||||
const bool isBoruvka = (mxGetScalar(prhs[1]) == 1.0);
|
||||
|
||||
// Run the computation.
|
||||
arma::mat result;
|
||||
if (isBoruvka)
|
||||
{
|
||||
// Get the number of leaves.
|
||||
const size_t leafSize = (size_t) mxGetScalar(prhs[2]);
|
||||
|
||||
DualTreeBoruvka<> dtb(dataPoints, false, leafSize);
|
||||
dtb.ComputeMST(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
DualTreeBoruvka<> naive(dataPoints, true);
|
||||
naive.ComputeMST(result);
|
||||
}
|
||||
|
||||
// Construct matrix to return to MATLAB.
|
||||
plhs[0] = mxCreateDoubleMatrix(3, numPoints - 1, mxREAL);
|
||||
|
||||
double* out = mxGetPr(plhs[0]);
|
||||
for (int i = 0, n = (numPoints - 1) * 3; i < n; ++i)
|
||||
{
|
||||
out[i] = result(i);
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
function result = emst(dataPoints, varargin)
|
||||
% result = emst(dataPoints, varargin)
|
||||
%
|
||||
% Compute the Euclidean minimum spanning tree of a set of input points using the
|
||||
% dual-tree Boruvka algorithm.
|
||||
%
|
||||
% The output is saved in a three-column matrix, where each row indicates an
|
||||
% edge. The first column corresponds to the lesser index of the edge; the
|
||||
% second column corresponds to the greater index of the edge; and the third
|
||||
% column corresponds to the distance between the two points.
|
||||
%
|
||||
% Required parameters:
|
||||
%
|
||||
% dataPoints - The matrix of data points. Columns are assumed to represent
|
||||
% dimensions, with rows representing separate points.
|
||||
%
|
||||
% Optional parameters (i.e. emst(..., 'parameter', value, ...)):
|
||||
%
|
||||
% 'method' - The algorithm for computing the tree. 'naive' or 'boruvka', with
|
||||
% 'boruvka' being the default dual-tree Boruvka algorithm.
|
||||
% 'leafSize' - Leaf size in the kd-tree. One-element leaves give the
|
||||
% empirically best performance, but at the cost of greater memory
|
||||
% requirements. Defaults to 1.
|
||||
%
|
||||
% Examples:
|
||||
%
|
||||
% result = emst(dataPoints);
|
||||
% result = emst(dataPoints, 'method', 'naive');
|
||||
% result = emst(dataPoints, 'method', 'naive', 'leafSize', 5);
|
||||
|
||||
% A parser for the inputs.
|
||||
p = inputParser;
|
||||
p.addParamValue('method', 'boruvka', ...
|
||||
@(x) strcmpi(x, 'naive') || strcmpi(x, 'boruvka'));
|
||||
p.addParamValue('leafSize', 1, @isscalar);
|
||||
|
||||
% Parse the varargin options.
|
||||
p.parse(varargin{:});
|
||||
parsed = p.Results;
|
||||
|
||||
% Interface with mlpack. Transpose to machine learning standards. MLPACK
|
||||
% expects column-major matrices; the user has passed in a row-major matrix.
|
||||
if strcmpi(parsed.method, 'boruvka')
|
||||
result = emst_mex(dataPoints', 1, parsed.leafSize);
|
||||
result = result';
|
||||
return;
|
||||
else
|
||||
result = emst_mex(dataPoints', 0, 1);
|
||||
result = result';
|
||||
return;
|
||||
end
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# Simple rules for building mex file. The _mex suffix is necessary to avoid
|
||||
# target name conflicts, and the mex file must have a different name than the .m
|
||||
# file.
|
||||
add_library(gmm_mex SHARED
|
||||
gmm.cpp
|
||||
)
|
||||
target_link_libraries(gmm_mex
|
||||
mlpack
|
||||
${LIBXML2_LIBRARIES}
|
||||
)
|
||||
|
||||
# Installation rule. Install both the mex and the MATLAB file.
|
||||
install(TARGETS gmm_mex
|
||||
LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
install(FILES
|
||||
gmm.m
|
||||
DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
@@ -1,129 +0,0 @@
|
||||
/**
|
||||
* @file gmm.cpp
|
||||
* @author Patrick Mason
|
||||
*
|
||||
* MEX function for MATLAB GMM binding.
|
||||
*/
|
||||
#include "mex.h"
|
||||
|
||||
#include <mlpack/core.hpp>
|
||||
#include <mlpack/methods/gmm/gmm.hpp>
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::gmm;
|
||||
using namespace mlpack::util;
|
||||
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
// argument checks
|
||||
if (nrhs != 3)
|
||||
{
|
||||
mexErrMsgTxt("Expecting three inputs.");
|
||||
}
|
||||
|
||||
if (nlhs != 1)
|
||||
{
|
||||
mexErrMsgTxt("Output required.");
|
||||
}
|
||||
|
||||
size_t seed = (size_t) mxGetScalar(prhs[2]);
|
||||
// Check parameters and load data.
|
||||
if (seed != 0)
|
||||
math::RandomSeed(seed);
|
||||
else
|
||||
math::RandomSeed((size_t) std::time(NULL));
|
||||
|
||||
// loading the data
|
||||
double * mexDataPoints = mxGetPr(prhs[0]);
|
||||
size_t numPoints = mxGetN(prhs[0]);
|
||||
size_t numDimensions = mxGetM(prhs[0]);
|
||||
arma::mat dataPoints(numDimensions, numPoints);
|
||||
for (int i = 0, n = numPoints * numDimensions; i < n; ++i)
|
||||
{
|
||||
dataPoints(i) = mexDataPoints[i];
|
||||
}
|
||||
|
||||
int gaussians = (int) mxGetScalar(prhs[1]);
|
||||
if (gaussians <= 0)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Invalid number of Gaussians (" << gaussians << "); must "
|
||||
"be greater than or equal to 1." << std::endl;
|
||||
mexErrMsgTxt(ss.str().c_str());
|
||||
}
|
||||
|
||||
// Calculate mixture of Gaussians.
|
||||
GMM<> gmm(size_t(gaussians), dataPoints.n_rows);
|
||||
|
||||
////// Computing the parameters of the model using the EM algorithm //////
|
||||
gmm.Estimate(dataPoints);
|
||||
|
||||
// setting up the matlab structure to be returned
|
||||
mwSize ndim = 1;
|
||||
mwSize dims[1] = {
|
||||
1
|
||||
};
|
||||
const char * fieldNames[3] = {
|
||||
"dimensionality"
|
||||
, "weights"
|
||||
, "gaussians"
|
||||
};
|
||||
|
||||
plhs[0] = mxCreateStructArray(ndim, dims, 3, fieldNames);
|
||||
|
||||
// dimensionality
|
||||
mxArray * field_value;
|
||||
field_value = mxCreateDoubleMatrix(1, 1, mxREAL);
|
||||
*mxGetPr(field_value) = numDimensions;
|
||||
mxSetFieldByNumber(plhs[0], 0, 0, field_value);
|
||||
|
||||
// mixture weights
|
||||
field_value = mxCreateDoubleMatrix(gmm.Weights().size(), 1, mxREAL);
|
||||
double * values = mxGetPr(field_value);
|
||||
for (int i=0; i<gmm.Weights().size(); ++i)
|
||||
{
|
||||
values[i] = gmm.Weights()[i];
|
||||
}
|
||||
mxSetFieldByNumber(plhs[0], 0, 1, field_value);
|
||||
|
||||
// gaussian mean/variances
|
||||
const char * gaussianNames[2] = {
|
||||
"mean"
|
||||
, "covariance"
|
||||
};
|
||||
ndim = 1;
|
||||
dims[0] = gmm.Gaussians();
|
||||
|
||||
field_value = mxCreateStructArray(ndim, dims, 2, gaussianNames);
|
||||
for (int i=0; i<gmm.Gaussians(); ++i)
|
||||
{
|
||||
mxArray * tmp;
|
||||
double * values;
|
||||
|
||||
// setting the mean
|
||||
arma::mat mean = gmm.Means()[i];
|
||||
tmp = mxCreateDoubleMatrix(numDimensions, 1, mxREAL);
|
||||
values = mxGetPr(tmp);
|
||||
for (int j = 0; j < numDimensions; ++j)
|
||||
{
|
||||
values[j] = mean(j);
|
||||
}
|
||||
// note: SetField does not copy the data structure.
|
||||
// mxDuplicateArray does the necessary copying.
|
||||
mxSetFieldByNumber(field_value, i, 0, mxDuplicateArray(tmp));
|
||||
mxDestroyArray(tmp);
|
||||
|
||||
// setting the covariance matrix
|
||||
arma::mat covariance = gmm.Covariances()[i];
|
||||
tmp = mxCreateDoubleMatrix(numDimensions, numDimensions, mxREAL);
|
||||
values = mxGetPr(tmp);
|
||||
for (int j = 0; j < numDimensions * numDimensions; ++j)
|
||||
{
|
||||
values[j] = covariance(j);
|
||||
}
|
||||
mxSetFieldByNumber(field_value, i, 1, mxDuplicateArray(tmp));
|
||||
mxDestroyArray(tmp);
|
||||
}
|
||||
mxSetFieldByNumber(plhs[0], 0, 2, field_value);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
function result = gmm(dataPoints, varargin)
|
||||
%Gaussian Mixture Model (GMM) Training
|
||||
%
|
||||
% This program takes a parametric estimate of a Gaussian mixture model (GMM)
|
||||
% using the EM algorithm to find the maximum likelihood estimate. The model is
|
||||
% saved to an XML file, which contains information about each Gaussian.
|
||||
%
|
||||
%Parameters:
|
||||
% dataPoints- (required) Matrix containing the data on which the model will be fit
|
||||
% seed - (optional) Random seed. If 0, 'std::time(NULL)' is used.
|
||||
% Default value is 0.
|
||||
% gaussians - (optional) Number of gaussians in the GMM. Default value is 1.
|
||||
|
||||
% a parser for the inputs
|
||||
p = inputParser;
|
||||
p.addParamValue('gaussians', 1, @isscalar);
|
||||
p.addParamValue('seed', 0, @isscalar);
|
||||
|
||||
% parsing the varargin options
|
||||
p.parse(varargin{:});
|
||||
parsed = p.Results;
|
||||
|
||||
% interfacing with mlpack
|
||||
result = mex_gmm(dataPoints', parsed.gaussians, parsed.seed);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,373 +0,0 @@
|
||||
#include "mex.h"
|
||||
|
||||
#include <mlpack/core.hpp>
|
||||
|
||||
#include "hmm.hpp"
|
||||
#include "hmm_util.hpp"
|
||||
#include <mlpack/methods/gmm/gmm.hpp>
|
||||
|
||||
/*
|
||||
PROGRAM_INFO("Hidden Markov Model (HMM) Sequence Generator", "This "
|
||||
"utility takes an already-trained HMM (--model_file) and generates a "
|
||||
"random observation sequence and hidden state sequence based on its "
|
||||
"parameters, saving them to the specified files (--output_file and "
|
||||
"--state_file)");
|
||||
|
||||
PARAM_STRING_REQ("model_file", "File containing HMM (XML).", "m");
|
||||
PARAM_INT_REQ("length", "Length of sequence to generate.", "l");
|
||||
|
||||
PARAM_INT("start_state", "Starting state of sequence.", "t", 0);
|
||||
PARAM_STRING("output_file", "File to save observation sequence to.", "o",
|
||||
"output.csv");
|
||||
PARAM_STRING("state_file", "File to save hidden state sequence to (may be left "
|
||||
"unspecified.", "S", "");
|
||||
PARAM_INT("seed", "Random seed. If 0, 'std::time(NULL)' is used.", "s", 0);
|
||||
*/
|
||||
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::hmm;
|
||||
using namespace mlpack::distribution;
|
||||
using namespace mlpack::utilities;
|
||||
using namespace mlpack::gmm;
|
||||
using namespace mlpack::math;
|
||||
using namespace arma;
|
||||
using namespace std;
|
||||
|
||||
namespace {
|
||||
// gets the transition matrix from the struct
|
||||
void getTransition(mat & transition, const mxArray * mxarray)
|
||||
{
|
||||
mxArray * mxTransitions = mxGetField(mxarray, 0, "transition");
|
||||
if (NULL == mxTransitions)
|
||||
{
|
||||
mexErrMsgTxt("Model struct did not have transition matrix 'transition'.");
|
||||
}
|
||||
if (mxDOUBLE_CLASS != mxGetClassID(mxTransitions))
|
||||
{
|
||||
mexErrMsgTxt("Transition matrix 'transition' must have type mxDOUBLE_CLASS.");
|
||||
}
|
||||
const size_t m = mxGetM(mxTransitions);
|
||||
const size_t n = mxGetN(mxTransitions);
|
||||
transition.resize(m,n);
|
||||
|
||||
double * values = mxGetPr(mxTransitions);
|
||||
for (int i = 0; i < m*n; ++i)
|
||||
transition(i) = values[i];
|
||||
}
|
||||
|
||||
// writes the matlab transition matrix to the model
|
||||
template <class T>
|
||||
void writeTransition(HMM<T> & hmm, const mxArray * mxarray)
|
||||
{
|
||||
mxArray * mxTransitions = mxGetField(mxarray, 0, "transition");
|
||||
if (NULL == mxTransitions)
|
||||
{
|
||||
mexErrMsgTxt("Model struct did not have transition matrix 'transition'.");
|
||||
}
|
||||
if (mxDOUBLE_CLASS != mxGetClassID(mxTransitions))
|
||||
{
|
||||
mexErrMsgTxt("Transition matrix 'transition' must have type mxDOUBLE_CLASS.");
|
||||
}
|
||||
|
||||
arma::mat transition(mxGetM(mxTransitions), mxGetN(mxTransitions));
|
||||
double * values = mxGetPr(mxTransitions);
|
||||
for (int i = 0; i < mxGetM(mxTransitions) * mxGetN(mxTransitions); ++i)
|
||||
transition(i) = values[i];
|
||||
|
||||
hmm.Transition() = transition;
|
||||
}
|
||||
|
||||
// argument check on the emission field
|
||||
void checkEmission(const mat & transition, const mxArray * mxarray)
|
||||
{
|
||||
if (NULL == mxarray)
|
||||
{
|
||||
mexErrMsgTxt("Model struct did not have 'emission' struct.");
|
||||
}
|
||||
if ((int) mxGetN(mxarray) != (int) transition.n_rows)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "'emissions' struct array must have dimensions 1 x "
|
||||
<< transition.n_rows << ".";
|
||||
mexErrMsgTxt(ss.str().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
} // closing anonymous namespace
|
||||
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
// argument checks
|
||||
if (nrhs != 4)
|
||||
{
|
||||
mexErrMsgTxt("Expecting four arguments.");
|
||||
}
|
||||
|
||||
if (nlhs != 1)
|
||||
{
|
||||
mexErrMsgTxt("Output required.");
|
||||
}
|
||||
|
||||
// seed argument
|
||||
size_t seed = (size_t) mxGetScalar(prhs[3]);
|
||||
|
||||
// Set random seed.
|
||||
if (seed != 0)
|
||||
mlpack::math::RandomSeed(seed);
|
||||
else
|
||||
mlpack::math::RandomSeed((size_t) std::time(NULL));
|
||||
|
||||
// length of observations
|
||||
const int length = (int) mxGetScalar(prhs[1]);
|
||||
|
||||
// start state
|
||||
const int startState = (int) mxGetScalar(prhs[2]);
|
||||
|
||||
if (length <= 0)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "Invalid sequence length (" << length << "); must be greater "
|
||||
<< "than or equal to 0!";
|
||||
mexErrMsgTxt(ss.str().c_str());
|
||||
}
|
||||
|
||||
// getting the model type
|
||||
if (mxIsStruct(prhs[0]) == 0)
|
||||
{
|
||||
mexErrMsgTxt("Model argument is not a struct.");
|
||||
}
|
||||
|
||||
mxArray * mxHmmType = mxGetField(prhs[0], 0, "hmm_type");
|
||||
if (mxHmmType == NULL)
|
||||
{
|
||||
mexErrMsgTxt("Model struct did not have 'hmm_type'.");
|
||||
}
|
||||
if (mxCHAR_CLASS != mxGetClassID(mxHmmType))
|
||||
{
|
||||
mexErrMsgTxt("'hmm_type' must have type mxCHAR_CLASS.");
|
||||
}
|
||||
|
||||
// getting the model type string
|
||||
int bufLength = mxGetNumberOfElements(mxHmmType) + 1;
|
||||
char * buf;
|
||||
buf = (char *) mxCalloc(bufLength, sizeof(char));
|
||||
mxGetString(mxHmmType, buf, bufLength);
|
||||
string type(buf);
|
||||
mxFree(buf);
|
||||
|
||||
cout << type << endl;
|
||||
|
||||
// to be filled by the generator
|
||||
mat observations;
|
||||
Col<size_t> sequence;
|
||||
|
||||
// to be removed!
|
||||
SaveRestoreUtility sr;
|
||||
|
||||
if (type == "discrete")
|
||||
{
|
||||
HMM<DiscreteDistribution> hmm(1, DiscreteDistribution(1));
|
||||
|
||||
// writing transition matrix to the hmm
|
||||
writeTransition(hmm, prhs[0]);
|
||||
|
||||
// writing emission matrix to the hmm
|
||||
mxArray * mxEmission = mxGetField(prhs[0], 0, "emission");
|
||||
//checkEmission(hmm, mxEmission);
|
||||
|
||||
vector<DiscreteDistribution> emission(hmm.Transition().n_rows);
|
||||
for (int i=0; i<hmm.Transition().n_rows; ++i)
|
||||
{
|
||||
mxArray * mxProbabilities = mxGetField(mxEmission, i, "probabilities");
|
||||
if (NULL == mxProbabilities)
|
||||
{
|
||||
mexErrMsgTxt("'probabilities' field could not be found in 'emission' struct.");
|
||||
}
|
||||
|
||||
arma::vec probabilities(mxGetN(mxProbabilities));
|
||||
double * values = mxGetPr(mxProbabilities);
|
||||
for (int j=0; j<mxGetN(mxProbabilities); ++j)
|
||||
probabilities(j) = values[j];
|
||||
|
||||
emission[i] = DiscreteDistribution(probabilities);
|
||||
}
|
||||
|
||||
hmm.Emission() = emission;
|
||||
|
||||
// At this point, the HMM model should be fully formed.
|
||||
if (startState < 0 || startState >= (int) hmm.Transition().n_rows)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "Invalid start state (" << startState << "); must be "
|
||||
<< "between 0 and number of states (" << hmm.Transition().n_rows
|
||||
<< ")!";
|
||||
mexErrMsgTxt(ss.str().c_str());
|
||||
}
|
||||
|
||||
hmm.Generate(size_t(length), observations, sequence, size_t(startState));
|
||||
}
|
||||
else if (type == "gaussian")
|
||||
{
|
||||
/*
|
||||
//HMM<GaussianDistribution> hmm(1, GaussianDistribution(1));
|
||||
|
||||
// get transition matrix
|
||||
//mat transition;
|
||||
//getTransition(transition, prhs[0]);
|
||||
|
||||
//hmm.Transition() = transition;
|
||||
//cout << transition << endl;
|
||||
arma::mat transition("0.75 0.25; 0.25 0.75");
|
||||
|
||||
// get emission
|
||||
//vector<GaussianDistribution> emission(transition.n_rows);
|
||||
vector<GaussianDistribution> emission;
|
||||
GaussianDistribution g1("5.0 5.0", "1.0 0.0; 0.0 1.0");
|
||||
GaussianDistribution g2("-5.0 -5.0", "1.0 0.0; 0.0 1.0");
|
||||
emission.push_back(g1);
|
||||
emission.push_back(g2);
|
||||
|
||||
|
||||
//HMM<GaussianDistribution> hmm(transition, emission);
|
||||
//hmm.Emission() = emission;
|
||||
HMM<GaussianDistribution> hmm(transition, emission);
|
||||
*/
|
||||
|
||||
// Our distribution will have three two-dimensional output Gaussians.
|
||||
cout << "following the test" << endl;
|
||||
HMM<GaussianDistribution> hmm(3, GaussianDistribution(2));
|
||||
hmm.Transition() = arma::mat("0.4 0.6 0.8; 0.2 0.2 0.1; 0.4 0.2 0.1");
|
||||
hmm.Emission()[0] = GaussianDistribution("0.0 0.0", "1.0 0.0; 0.0 1.0");
|
||||
hmm.Emission()[1] = GaussianDistribution("2.0 2.0", "1.0 0.5; 0.5 1.2");
|
||||
hmm.Emission()[2] = GaussianDistribution("-2.0 1.0", "2.0 0.1; 0.1 1.0");
|
||||
|
||||
// Now we will generate a long sequence.
|
||||
std::vector<arma::mat> observations2(1);
|
||||
std::vector<arma::Col<size_t> > states2(1);
|
||||
|
||||
// testing
|
||||
SaveHMM(hmm, sr);
|
||||
sr.WriteFile("testMexGaussian.xml");
|
||||
|
||||
// Start in state 1 (no reason).
|
||||
cout << "test generation" << endl;
|
||||
hmm.Generate(10000, observations2[0], states2[0], 1);
|
||||
cout << "test complete" << endl;
|
||||
|
||||
if (startState < 0 || startState >= (int) hmm.Transition().n_rows)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "Invalid start state (" << startState << "); must be "
|
||||
<< "between 0 and number of states (" << hmm.Transition().n_rows
|
||||
<< ")!";
|
||||
mexErrMsgTxt(ss.str().c_str());
|
||||
}
|
||||
cout << "generating!" << endl;
|
||||
hmm.Generate(size_t(length), observations, sequence, size_t(startState));
|
||||
cout << "done!" << endl;
|
||||
}
|
||||
else if (type == "gmm")
|
||||
{
|
||||
HMM<GMM<> > hmm(1, GMM<>(1, 1));
|
||||
|
||||
LoadHMM(hmm, sr);
|
||||
|
||||
if (startState < 0 || startState >= (int) hmm.Transition().n_rows)
|
||||
{
|
||||
Log::Fatal << "Invalid start state (" << startState << "); must be "
|
||||
<< "between 0 and number of states (" << hmm.Transition().n_rows
|
||||
<< ")!" << endl;
|
||||
}
|
||||
|
||||
hmm.Generate(size_t(length), observations, sequence, size_t(startState));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::Fatal << "Unknown HMM type '" << type << "'" << "'!" << endl;
|
||||
}
|
||||
|
||||
cout << "returning to matlab" << endl;
|
||||
|
||||
// Setting values to be returned to matlab
|
||||
mwSize ndim = 1;
|
||||
mwSize dims[1] = {1};
|
||||
const char * fieldNames[2] = {
|
||||
"observations"
|
||||
, "states"
|
||||
};
|
||||
|
||||
plhs[0] = mxCreateStructArray(ndim, dims, 2, fieldNames);
|
||||
|
||||
mxArray * tmp;
|
||||
double * values;
|
||||
|
||||
cout << observations.n_rows << "," << observations.n_cols << endl;
|
||||
cout << sequence.n_rows << "," << sequence.n_cols << endl;
|
||||
cout << observations << endl;
|
||||
cout << sequence << endl;
|
||||
|
||||
// settings the observations
|
||||
tmp = mxCreateDoubleMatrix(observations.n_rows, observations.n_cols, mxREAL);
|
||||
values = mxGetPr(tmp);
|
||||
for (int i=0; i<observations.n_rows * observations.n_cols; ++i)
|
||||
values[i] = observations(i);
|
||||
|
||||
// note: SetField does not copy the data structure.
|
||||
// mxDuplicateArray does the necessary copying.
|
||||
mxSetFieldByNumber(plhs[0], 0, 0, mxDuplicateArray(tmp));
|
||||
mxDestroyArray(tmp);
|
||||
|
||||
// settings the observations
|
||||
tmp = mxCreateDoubleMatrix(sequence.n_rows, sequence.n_cols, mxREAL);
|
||||
values = mxGetPr(tmp);
|
||||
for (int i=0; i<length; ++i)
|
||||
values[i] = sequence(i);
|
||||
|
||||
// note: SetField does not copy the data structure.
|
||||
// mxDuplicateArray does the necessary copying.
|
||||
mxSetFieldByNumber(plhs[0], 0, 1, mxDuplicateArray(tmp));
|
||||
mxDestroyArray(tmp);
|
||||
}
|
||||
|
||||
/*
|
||||
mxArray * mxEmission = mxGetField(prhs[0], 0, "emission");
|
||||
checkEmission(transition, mxEmission);
|
||||
|
||||
vector<GaussianDistribution> emission(transition.n_rows);
|
||||
for (int i=0; i<transition.n_rows; ++i)
|
||||
{
|
||||
// mean
|
||||
mxArray * mxMean = mxGetField(mxEmission, i, "mean");
|
||||
if (NULL == mxMean)
|
||||
{
|
||||
mexErrMsgTxt("'mean' field could not be found in 'emission' struct.");
|
||||
}
|
||||
|
||||
arma::vec mean(mxGetN(mxMean));
|
||||
double * values = mxGetPr(mxMean);
|
||||
for (int j=0; j<mxGetN(mxMean); ++j)
|
||||
mean(j) = values[j];
|
||||
|
||||
cout << mean << endl;
|
||||
|
||||
// covariance
|
||||
mxArray * mxCovariance = mxGetField(mxEmission, i, "covariance");
|
||||
if (NULL == mxCovariance)
|
||||
{
|
||||
mexErrMsgTxt("'covariance' field could not be found in 'emission' struct.");
|
||||
}
|
||||
|
||||
const size_t m = (size_t) mxGetM(mxCovariance);
|
||||
const size_t n = (size_t) mxGetN(mxCovariance);
|
||||
mat covariance(m, n);
|
||||
values = mxGetPr(mxCovariance);
|
||||
for (int j=0; j < m * n; ++j)
|
||||
covariance(j) = values[j];
|
||||
|
||||
cout << covariance << endl;
|
||||
|
||||
emission[i] = GaussianDistribution(mean, covariance);
|
||||
}
|
||||
*/
|
||||
@@ -1,28 +0,0 @@
|
||||
function sequence = hmm_generate(model, sequence_length, varargin)
|
||||
%Hidden Markov Model (HMM) Sequence Generator
|
||||
%
|
||||
% This utility takes an already-trained HMM (model) and generates a
|
||||
% random observation sequence and hidden state sequence based on its parameters,
|
||||
% saving them to the specified files (--output_file and --state_file)
|
||||
%
|
||||
%Parameters:
|
||||
% model - (required) HMM model struct.
|
||||
% sequence_length - (required) Length of the sequence to produce.
|
||||
% start_state - (optional) Starting state of sequence. Default value 0.
|
||||
% seed - (optional) Random seed. If 0, 'std::time(NULL)' is used.
|
||||
% Default value 0.
|
||||
|
||||
% a parser for the inputs
|
||||
p = inputParser;
|
||||
p.addParamValue('start_state', 0, @isscalar);
|
||||
p.addParamValue('seed', 0, @isscalar);
|
||||
|
||||
% parsing the varargin options
|
||||
p.parse(varargin{:});
|
||||
parsed = p.Results;
|
||||
|
||||
% interfacing with mlpack.
|
||||
sequence = mex_hmm_generate(model, sequence_length, ...
|
||||
parsed.start_state, parsed.seed);
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# Simple rules for building mex file. The _mex suffix is necessary to avoid
|
||||
# target name conflicts, and the mex file must have a different name than the .m
|
||||
# file.
|
||||
add_library(kernel_pca_mex SHARED
|
||||
kernel_pca.cpp
|
||||
)
|
||||
target_link_libraries(kernel_pca_mex
|
||||
mlpack
|
||||
${LIBXML2_LIBRARIES}
|
||||
)
|
||||
|
||||
# Installation rule. Install both the mex and the MATLAB file.
|
||||
install(TARGETS kernel_pca_mex
|
||||
LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
install(FILES
|
||||
kernel_pca.m
|
||||
DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
@@ -1,136 +0,0 @@
|
||||
#include "mex.h"
|
||||
|
||||
#include <mlpack/core.hpp>
|
||||
#include <mlpack/core/kernels/linear_kernel.hpp>
|
||||
#include <mlpack/core/kernels/gaussian_kernel.hpp>
|
||||
#include <mlpack/core/kernels/hyperbolic_tangent_kernel.hpp>
|
||||
#include <mlpack/core/kernels/laplacian_kernel.hpp>
|
||||
#include <mlpack/core/kernels/polynomial_kernel.hpp>
|
||||
#include <mlpack/core/kernels/cosine_distance.hpp>
|
||||
|
||||
#include <mlpack/methods/kernel_pca/kernel_pca.hpp>
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::kpca;
|
||||
using namespace mlpack::kernel;
|
||||
using namespace std;
|
||||
using namespace arma;
|
||||
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
// argument checks
|
||||
if (nrhs != 8)
|
||||
{
|
||||
mexErrMsgTxt("Expecting eight arguments.");
|
||||
}
|
||||
|
||||
if (nlhs != 1)
|
||||
{
|
||||
mexErrMsgTxt("Output required.");
|
||||
}
|
||||
|
||||
// Load input dataset.
|
||||
if (mxDOUBLE_CLASS != mxGetClassID(prhs[0]))
|
||||
mexErrMsgTxt("Input dataset must have type mxDOUBLE_CLASS.");
|
||||
|
||||
mat dataset(mxGetM(prhs[0]), mxGetN(prhs[0]));
|
||||
double * values = mxGetPr(prhs[0]);
|
||||
for (int i=0, num=mxGetNumberOfElements(prhs[0]); i<num; ++i)
|
||||
dataset(i) = values[i];
|
||||
|
||||
// Get the new dimensionality, if it is necessary.
|
||||
size_t newDim = dataset.n_rows;
|
||||
const int argNewDim = (int) mxGetScalar(prhs[2]);
|
||||
if (argNewDim != 0)
|
||||
{
|
||||
newDim = argNewDim;
|
||||
|
||||
if (newDim > dataset.n_rows)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "New dimensionality (" << newDim
|
||||
<< ") cannot be greater than existing dimensionality ("
|
||||
<< dataset.n_rows << ")!";
|
||||
mexErrMsgTxt(ss.str().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// Get the kernel type and make sure it is valid.
|
||||
if (mxCHAR_CLASS != mxGetClassID(prhs[1]))
|
||||
{
|
||||
mexErrMsgTxt("Kernel input must have type mxCHAR_CLASS.");
|
||||
}
|
||||
int bufLength = mxGetNumberOfElements(prhs[1]) + 1;
|
||||
char * buf;
|
||||
buf = (char *) mxCalloc(bufLength, sizeof(char));
|
||||
mxGetString(prhs[1], buf, bufLength);
|
||||
string kernelType(buf);
|
||||
mxFree(buf);
|
||||
|
||||
// scale parameter
|
||||
const bool scaleData = (mxGetScalar(prhs[3]) == 1.0);
|
||||
|
||||
if (kernelType == "linear")
|
||||
{
|
||||
KernelPCA<LinearKernel> kpca(LinearKernel(), scaleData);
|
||||
kpca.Apply(dataset, newDim);
|
||||
}
|
||||
else if (kernelType == "gaussian")
|
||||
{
|
||||
const double bandwidth = mxGetScalar(prhs[3]);
|
||||
|
||||
GaussianKernel kernel(bandwidth);
|
||||
KernelPCA<GaussianKernel> kpca(kernel, scaleData);
|
||||
kpca.Apply(dataset, newDim);
|
||||
}
|
||||
else if (kernelType == "polynomial")
|
||||
{
|
||||
const double degree = mxGetScalar(prhs[4]);
|
||||
const double offset = mxGetScalar(prhs[5]);
|
||||
|
||||
PolynomialKernel kernel(offset, degree);
|
||||
KernelPCA<PolynomialKernel> kpca(kernel, scaleData);
|
||||
kpca.Apply(dataset, newDim);
|
||||
}
|
||||
else if (kernelType == "hyptan")
|
||||
{
|
||||
const double scale = mxGetScalar(prhs[6]);
|
||||
const double offset = mxGetScalar(prhs[5]);
|
||||
|
||||
HyperbolicTangentKernel kernel(scale, offset);
|
||||
KernelPCA<HyperbolicTangentKernel> kpca(kernel, scaleData);
|
||||
kpca.Apply(dataset, newDim);
|
||||
}
|
||||
else if (kernelType == "laplacian")
|
||||
{
|
||||
const double bandwidth = mxGetScalar(prhs[7]);
|
||||
|
||||
LaplacianKernel kernel(bandwidth);
|
||||
KernelPCA<LaplacianKernel> kpca(kernel, scaleData);
|
||||
kpca.Apply(dataset, newDim);
|
||||
}
|
||||
else if (kernelType == "cosine")
|
||||
{
|
||||
KernelPCA<CosineDistance> kpca(CosineDistance(), scaleData);
|
||||
kpca.Apply(dataset, newDim);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid kernel type.
|
||||
stringstream ss;
|
||||
ss << "Invalid kernel type ('" << kernelType << "'); valid choices "
|
||||
<< "are 'linear', 'gaussian', 'polynomial', 'hyptan', 'laplacian', and "
|
||||
<< "'cosine'.";
|
||||
mexErrMsgTxt(ss.str().c_str());
|
||||
}
|
||||
|
||||
// Now returning results to matlab
|
||||
plhs[0] = mxCreateDoubleMatrix(dataset.n_rows, dataset.n_cols, mxREAL);
|
||||
values = mxGetPr(plhs[0]);
|
||||
for (int i = 0; i < dataset.n_rows * dataset.n_cols; ++i)
|
||||
{
|
||||
values[i] = dataset(i);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
function result = kernel_pca(dataPoints, kernel, varargin)
|
||||
%Kernel Principal Components Analysis
|
||||
%
|
||||
% This program performs Kernel Principal Components Analysis (KPCA) on the
|
||||
% specified dataset with the specified kernel. This will transform the data
|
||||
% onto the kernel principal components, and optionally reduce the dimensionality
|
||||
% by ignoring the kernel principal components with the smallest eigenvalues.
|
||||
%
|
||||
% For the case where a linear kernel is used, this reduces to regular PCA.
|
||||
%
|
||||
% The kernels that are supported are listed below:
|
||||
%
|
||||
% * 'linear': the standard linear dot product (same as normal PCA):
|
||||
% K(x, y) = x^T y
|
||||
%
|
||||
% * 'gaussian': a Gaussian kernel; requires bandwidth:
|
||||
% K(x, y) = exp(-(|| x - y || ^ 2) / (2 * (bandwidth ^ 2)))
|
||||
%
|
||||
% * 'polynomial': polynomial kernel; requires offset and degree:
|
||||
% K(x, y) = (x^T y + offset) ^ degree
|
||||
%
|
||||
% * 'hyptan': hyperbolic tangent kernel; requires scale and offset:
|
||||
% K(x, y) = tanh(scale * (x^T y) + offset)
|
||||
%
|
||||
% * 'laplacian': Laplacian kernel; requires bandwidth:
|
||||
% K(x, y) = exp(-(|| x - y ||) / bandwidth)
|
||||
%
|
||||
% * 'cosine': cosine distance:
|
||||
% K(x, y) = 1 - (x^T y) / (|| x || * || y ||)
|
||||
%
|
||||
% The parameters for each of the kernels should be specified with the options
|
||||
% bandwidth, kernel_scale, offset, or degree (or a combination of those
|
||||
% options).
|
||||
%
|
||||
%Parameters
|
||||
% dataPoints - (required) Input dataset to perform KPCA on.
|
||||
% kernel - (required) The kernel to use.
|
||||
% new_dimensionality - (optional) If not 0, reduce the dimensionality of the
|
||||
% dataset by ignoring the dimensions with the smallest
|
||||
% eighenvalues.
|
||||
% bandwidth - (optional) Bandwidt, for gaussian or laplacian kernels.
|
||||
% Default value is 1.
|
||||
% degree - (optional) Degree of polynomial, for 'polynomial' kernel.
|
||||
% Default value 1.
|
||||
% kernel_scale - (optional) Scale, for 'hyptan' kernel. Default value 1.
|
||||
% offset - (optional) Offset, for 'hyptan' and 'polynomial' kernels.
|
||||
% Default value is 1.
|
||||
% scale - (optional) If true, the data will be scaled before performing
|
||||
% KPCA such that the variance of each feature is 1.
|
||||
|
||||
% a parser for the inputs
|
||||
p = inputParser;
|
||||
p.addParamValue('new_dimensionality', @isscalar);
|
||||
p.addParamValue('offset', @isscalar);
|
||||
p.addParamValue('kernel_scale', @isscalar);
|
||||
p.addParamValue('bandwidth', @isscalar);
|
||||
p.addParamValue('degree', @isscalar);
|
||||
p.addParamValue('scale', false, @(x) (x == true) || (x == false));
|
||||
|
||||
% parsing the varargin options
|
||||
p.parse(varargin{:});
|
||||
parsed = p.Results;
|
||||
|
||||
% interfacing with mlpack. transposing to machine learning standards.
|
||||
result = mex_kernel_pca(dataPoints', kernel, ...
|
||||
parsed.new_dimensionality, parsed.scale, ...
|
||||
parsed.degree, parsed.offset, ...
|
||||
parsed.kernel_scale, parsed.bandwidth);
|
||||
|
||||
result = result';
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# Simple rules for building mex file. The _mex suffix is necessary to avoid
|
||||
# target name conflicts, and the mex file must have a different name than the .m
|
||||
# file.
|
||||
add_library(kmeans_mex SHARED
|
||||
kmeans.cpp
|
||||
)
|
||||
target_link_libraries(kmeans_mex
|
||||
mlpack
|
||||
${LIBXML2_LIBRARIES}
|
||||
)
|
||||
|
||||
# Installation rule. Install both the mex and the MATLAB file.
|
||||
install(TARGETS kmeans_mex
|
||||
LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
install(FILES
|
||||
kmeans.m
|
||||
DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
@@ -1,175 +0,0 @@
|
||||
/**
|
||||
* @file kmeans.cpp
|
||||
* @author Patrick Mason
|
||||
*
|
||||
* MEX function for MATLAB k-means binding.
|
||||
*/
|
||||
#include "mex.h"
|
||||
|
||||
#include <mlpack/core.hpp>
|
||||
#include <mlpack/methods/kmeans/kmeans.hpp>
|
||||
#include <mlpack/methods/kmeans/allow_empty_clusters.hpp>
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::kmeans;
|
||||
using namespace std;
|
||||
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
// argument checks
|
||||
if (nrhs != 7)
|
||||
{
|
||||
mexErrMsgTxt("Expecting seven arguments.");
|
||||
}
|
||||
|
||||
if (nlhs != 1)
|
||||
{
|
||||
mexErrMsgTxt("Output required.");
|
||||
}
|
||||
|
||||
size_t seed = (size_t) mxGetScalar(prhs[6]);
|
||||
|
||||
// Initialize random seed.
|
||||
//if (CLI::GetParam<int>("seed") != 0)
|
||||
//math::RandomSeed((size_t) CLI::GetParam<int>("seed"));
|
||||
if (seed != 0)
|
||||
math::RandomSeed(seed);
|
||||
else
|
||||
math::RandomSeed((size_t) std::time(NULL));
|
||||
|
||||
// Now do validation of options.
|
||||
//string inputFile = CLI::GetParam<string>("inputFile");
|
||||
//int clusters = CLI::GetParam<int>("clusters");
|
||||
int clusters = (int) mxGetScalar(prhs[1]);
|
||||
if (clusters < 1)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "Invalid number of clusters requested (" << clusters << ")! "
|
||||
<< "Must be greater than or equal to 1.";
|
||||
mexErrMsgTxt(ss.str().c_str());
|
||||
}
|
||||
|
||||
//int maxIterations = CLI::GetParam<int>("max_iterations");
|
||||
int maxIterations = (int) mxGetScalar(prhs[2]);
|
||||
if (maxIterations < 0)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "Invalid value for maximum iterations (" << maxIterations <<
|
||||
")! Must be greater than or equal to 0.";
|
||||
mexErrMsgTxt(ss.str().c_str());
|
||||
}
|
||||
|
||||
//double overclustering = CLI::GetParam<double>("overclustering");
|
||||
double overclustering = mxGetScalar(prhs[3]);
|
||||
if (overclustering < 1)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "Invalid value for overclustering (" << overclustering <<
|
||||
")! Must be greater than or equal to 1.";
|
||||
mexErrMsgTxt(ss.str().c_str());
|
||||
}
|
||||
|
||||
const bool allow_empty_clusters = (mxGetScalar(prhs[4]) == 1.0);
|
||||
const bool fast_kmeans = (mxGetScalar(prhs[5]) == 1.0);
|
||||
|
||||
/*
|
||||
// Make sure we have an output file if we're not doing the work in-place.
|
||||
if (!CLI::HasParam("in_place") && !CLI::HasParam("outputFile"))
|
||||
{
|
||||
Log::Fatal << "--outputFile not specified (and --in_place not set)."
|
||||
<< std::endl;
|
||||
}
|
||||
*/
|
||||
|
||||
// Load our dataset.
|
||||
const size_t numPoints = mxGetN(prhs[0]);
|
||||
const size_t numDimensions = mxGetM(prhs[0]);
|
||||
arma::mat dataset(numDimensions, numPoints);
|
||||
|
||||
// setting the values.
|
||||
double * mexDataPoints = mxGetPr(prhs[0]);
|
||||
for (int i = 0, n = numPoints * numDimensions; i < n; ++i)
|
||||
{
|
||||
dataset(i) = mexDataPoints[i];
|
||||
}
|
||||
|
||||
// Now create the KMeans object. Because we could be using different types,
|
||||
// it gets a little weird...
|
||||
arma::Col<size_t> assignments;
|
||||
|
||||
//if (CLI::HasParam("allow_empty_clusters"))
|
||||
if (allow_empty_clusters)
|
||||
{
|
||||
KMeans<metric::SquaredEuclideanDistance, RandomPartition,
|
||||
AllowEmptyClusters> k(maxIterations, overclustering);
|
||||
|
||||
//if (CLI::HasParam("fast_kmeans"))
|
||||
if (fast_kmeans)
|
||||
k.FastCluster(dataset, clusters, assignments);
|
||||
else
|
||||
k.Cluster(dataset, clusters, assignments);
|
||||
}
|
||||
else
|
||||
{
|
||||
KMeans<> k(maxIterations, overclustering);
|
||||
|
||||
//if (CLI::HasParam("fast_kmeans"))
|
||||
if (fast_kmeans)
|
||||
k.FastCluster(dataset, clusters, assignments);
|
||||
else
|
||||
k.Cluster(dataset, clusters, assignments);
|
||||
}
|
||||
|
||||
/*
|
||||
// Now figure out what to do with our results.
|
||||
if (CLI::HasParam("in_place"))
|
||||
{
|
||||
// Add the column of assignments to the dataset; but we have to convert them
|
||||
// to type double first.
|
||||
arma::vec converted(assignments.n_elem);
|
||||
for (size_t i = 0; i < assignments.n_elem; i++)
|
||||
converted(i) = (double) assignments(i);
|
||||
|
||||
dataset.insert_rows(dataset.n_rows, trans(converted));
|
||||
|
||||
// Save the dataset.
|
||||
data::Save(inputFile.c_str(), dataset);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CLI::HasParam("labels_only"))
|
||||
{
|
||||
// Save only the labels.
|
||||
string outputFile = CLI::GetParam<string>("outputFile");
|
||||
arma::Mat<size_t> output = trans(assignments);
|
||||
data::Save(outputFile.c_str(), output);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Convert the assignments to doubles.
|
||||
arma::vec converted(assignments.n_elem);
|
||||
for (size_t i = 0; i < assignments.n_elem; i++)
|
||||
converted(i) = (double) assignments(i);
|
||||
|
||||
dataset.insert_rows(dataset.n_rows, trans(converted));
|
||||
|
||||
// Now save, in the different file.
|
||||
string outputFile = CLI::GetParam<string>("outputFile");
|
||||
data::Save(outputFile.c_str(), dataset);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// constructing matrix to return to matlab
|
||||
plhs[0] = mxCreateDoubleMatrix(assignments.n_elem, 1, mxREAL);
|
||||
|
||||
// setting the values
|
||||
double * out = mxGetPr(plhs[0]);
|
||||
for (int i = 0, n = assignments.n_elem; i < n; ++i)
|
||||
{
|
||||
out[i] = assignments(i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
function assignments = emst(dataPoints, clusters, varargin)
|
||||
%K-Means Clustering
|
||||
%
|
||||
% This program performs K-Means clustering on the given dataset, storing the
|
||||
% learned cluster assignments either as a column of labels in the file
|
||||
% containing the input dataset or in a separate file. Empty clusters are not
|
||||
% allowed by default; when a cluster becomes empty, the point furthest from the
|
||||
% centroid of the cluster with maximum variance is taken to fill that cluster.
|
||||
|
||||
% a parser for the inputs
|
||||
p = inputParser;
|
||||
p.addParamValue('allow_empty_clusters', false, @(x) (x == true) || (x == false));
|
||||
p.addParamValue('fast_kmeans', false, @(x) (x == true) || (x == false));
|
||||
p.addParamValue('max_iterations', 1000, @isscalar);
|
||||
p.addParamValue('overclustering', 1, @isscalar);
|
||||
p.addParamValue('seed', 0, @isscalar);
|
||||
|
||||
% parsing the varargin options
|
||||
p.parse(varargin{:});
|
||||
parsed = p.Results;
|
||||
|
||||
% interfacing with mlpack. transposing to machine learning standards.
|
||||
assignments = mex_kmeans(dataPoints', clusters, parsed.max_iterations, ...
|
||||
parsed.overclustering, parsed.allow_empty_clusters, ...
|
||||
parsed.fast_kmeans, parsed.seed);
|
||||
|
||||
assignments = assignments + 1; % changing to matlab indexing
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# Simple rules for building mex file. The _mex suffix is necessary to avoid
|
||||
# target name conflicts, and the mex file must have a different name than the .m
|
||||
# file.
|
||||
add_library(lars_mex SHARED
|
||||
lars.cpp
|
||||
)
|
||||
target_link_libraries(lars_mex
|
||||
mlpack
|
||||
${LIBXML2_LIBRARIES}
|
||||
)
|
||||
|
||||
# Installation rule. Install both the mex and the MATLAB file.
|
||||
install(TARGETS lars_mex
|
||||
LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
install(FILES
|
||||
lars.m
|
||||
DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
@@ -1,58 +0,0 @@
|
||||
#include "mex.h"
|
||||
|
||||
#include <mlpack/core.hpp>
|
||||
|
||||
#include <mlpack/methods/lars/lars.hpp>
|
||||
|
||||
using namespace arma;
|
||||
using namespace std;
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::regression;
|
||||
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
// argument checks
|
||||
if (nrhs != 4)
|
||||
{
|
||||
mexErrMsgTxt("Expecting four inputs.");
|
||||
}
|
||||
|
||||
if (nlhs != 1)
|
||||
{
|
||||
mexErrMsgTxt("Output required.");
|
||||
}
|
||||
|
||||
double lambda1 = mxGetScalar(prhs[2]);
|
||||
double lambda2 = mxGetScalar(prhs[3]);
|
||||
bool useCholesky = (mxGetScalar(prhs[3]) == 1.0);
|
||||
|
||||
// loading covariates
|
||||
mat matX(mxGetM(prhs[0]), mxGetN(prhs[0]));
|
||||
double * values = mxGetPr(prhs[0]);
|
||||
for (int i=0, num=mxGetNumberOfElements(prhs[0]); i<num; ++i)
|
||||
matX(i) = values[i];
|
||||
|
||||
// loading responses
|
||||
mat matY(mxGetM(prhs[1]), mxGetN(prhs[1]));
|
||||
values = mxGetPr(prhs[1]);
|
||||
for (int i=0, num=mxGetNumberOfElements(prhs[1]); i<num; ++i)
|
||||
matY(i) = values[i];
|
||||
|
||||
if (matY.n_cols > 1)
|
||||
mexErrMsgTxt("Only one column or row allowed in responses file!");
|
||||
|
||||
if (matY.n_elem != matX.n_rows)
|
||||
mexErrMsgTxt("Number of responses must be equal to number of rows of X!");
|
||||
|
||||
// Do LARS.
|
||||
LARS lars(useCholesky, lambda1, lambda2);
|
||||
vec beta;
|
||||
lars.Regress(matX, matY.unsafe_col(0), beta, false /* do not transpose */);
|
||||
|
||||
// return to matlab
|
||||
plhs[0] = mxCreateDoubleMatrix(beta.n_elem, 1, mxREAL);
|
||||
values = mxGetPr(plhs[0]);
|
||||
for (int i = 0; i < beta.n_elem; ++i)
|
||||
values[i] = beta(i);
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
function beta = lars(X, Y, varargin)
|
||||
%LARS
|
||||
%
|
||||
% An implementation of LARS: Least Angle Regression (Stagewise/laSso). This is
|
||||
% a stage-wise homotopy-based algorithm for L1-regularized linear regression
|
||||
% (LASSO) and L1+L2-regularized linear regression (Elastic Net).
|
||||
%
|
||||
% Let X be a matrix where each row is a point and each column is a dimension,
|
||||
% and let y be a vector of targets.
|
||||
%
|
||||
% The Elastic Net problem is to solve
|
||||
%
|
||||
% min_beta 0.5 || X * beta - y ||_2^2 + lambda_1 ||beta||_1 +
|
||||
% 0.5 lambda_2 ||beta||_2^2
|
||||
%
|
||||
% If lambda_1 > 0 and lambda_2 = 0, the problem is the LASSO.
|
||||
% If lambda_1 > 0 and lambda_2 > 0, the problem is the Elastic Net.
|
||||
% If lambda_1 = 0 and lambda_2 > 0, the problem is Ridge Regression.
|
||||
% If lambda_1 = 0 and lambda_2 = 0, the problem is unregularized linear
|
||||
% regression.
|
||||
%
|
||||
% For efficiency reasons, it is not recommended to use this algorithm with
|
||||
% lambda_1 = 0.
|
||||
%
|
||||
%Parameters
|
||||
% X - (required) Matrix containing covariates.
|
||||
% Y - (required) Matrix containing y.
|
||||
% lambda1 - (optional) Default value 0. l1-penalty regularization.
|
||||
% lambda2 - (optional) Default value 0. l2-penalty regularization.
|
||||
% useCholesky - (optional) Use Cholesky decomposition during computation
|
||||
% rather than explicitly computing the full Gram
|
||||
% matrix.
|
||||
|
||||
% a parser for the inputs
|
||||
p = inputParser;
|
||||
p.addParamValue('lambda1', @isscalar);
|
||||
p.addParamValue('lambda2', @isscalar);
|
||||
p.addParamValue('useCholesky', false, @(x) (x == true) || (x == false));
|
||||
|
||||
% parsing the varargin options
|
||||
p.parse(varargin{:});
|
||||
parsed = p.Results;
|
||||
|
||||
% interfacing with mlpack. Does not require transposing.
|
||||
beta = mex_lars(X, Y, ...
|
||||
parsed.lambda1, parsed.lambda2, parsed.useCholesky);
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# Simple rules for building mex file. The _mex suffix is necessary to avoid
|
||||
# target name conflicts, and the mex file must have a different name than the .m
|
||||
# file.
|
||||
add_library(nca_mex SHARED
|
||||
nca.cpp
|
||||
)
|
||||
target_link_libraries(nca_mex
|
||||
mlpack
|
||||
${LIBXML2_LIBRARIES}
|
||||
)
|
||||
|
||||
# Installation rule. Install both the mex and the MATLAB file.
|
||||
install(TARGETS nca_mex
|
||||
LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
install(FILES
|
||||
nca.m
|
||||
DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
@@ -1,55 +0,0 @@
|
||||
#include "mex.h"
|
||||
|
||||
#include <mlpack/core.hpp>
|
||||
#include <mlpack/core/metrics/lmetric.hpp>
|
||||
|
||||
#include <mlpack/methods/nca/nca.hpp>
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::nca;
|
||||
using namespace mlpack::metric;
|
||||
using namespace std;
|
||||
using namespace arma;
|
||||
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
// argument checks
|
||||
if (nrhs != 2)
|
||||
{
|
||||
mexErrMsgTxt("Expecting two inputs.");
|
||||
}
|
||||
|
||||
if (nlhs != 1)
|
||||
{
|
||||
mexErrMsgTxt("Output required.");
|
||||
}
|
||||
|
||||
// Load data.
|
||||
mat data(mxGetM(prhs[0]), mxGetN(prhs[0]));
|
||||
double * values = mxGetPr(prhs[0]);
|
||||
for (int i=0, num=mxGetNumberOfElements(prhs[0]); i<num; ++i)
|
||||
data(i) = values[i];
|
||||
|
||||
// load labels
|
||||
umat labels(mxGetNumberOfElements(prhs[1]), 1);
|
||||
values = mxGetPr(prhs[1]);
|
||||
for (int i=0, num=mxGetNumberOfElements(prhs[1]); i<num; ++i)
|
||||
labels(i) = (int) values[i];
|
||||
|
||||
// dimension checks
|
||||
if (labels.n_elem != data.n_cols)
|
||||
mexErrMsgTxt("Labels vector and data have unmatching dimensions.");
|
||||
|
||||
// Now create the NCA object and run the optimization.
|
||||
NCA<LMetric<2> > nca(data, labels.unsafe_col(0));
|
||||
|
||||
mat distance;
|
||||
nca.LearnDistance(distance);
|
||||
|
||||
// return to matlab
|
||||
plhs[0] = mxCreateDoubleMatrix(distance.n_rows, distance.n_cols, mxREAL);
|
||||
values = mxGetPr(plhs[0]);
|
||||
for (int i = 0; i < distance.n_elem; ++i)
|
||||
values[i] = distance(i);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
function result = nca(dataPoints, labels)
|
||||
%Neighborhood Components Analysis (NCA)
|
||||
%
|
||||
% This program implements Neighborhood Components Analysis, both a linear
|
||||
% dimensionality reduction technique and a distance learning technique. The
|
||||
% method seeks to improve k-nearest-neighbor classification on a dataset by
|
||||
% scaling the dimensions. The method is nonparametric, and does not require a
|
||||
% value of k. It works by using stochastic ("soft") neighbor assignments and
|
||||
% using optimization techniques over the gradient of the accuracy of the
|
||||
% neighbor assignments.
|
||||
%
|
||||
% To work, this algorithm needs labeled data. It can be given as the last row
|
||||
% of the input dataset (--input_file), or alternatively in a separate file
|
||||
% (--labels_file).
|
||||
%
|
||||
%Parameters:
|
||||
% dataPoints - Input dataset to run NCA on.
|
||||
% labels - Labels for input dataset.
|
||||
|
||||
% interfacing with mlpack. transposing to machine learning standards.
|
||||
result = mex_nca(dataPoints', labels);
|
||||
result = result';
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# Simple rules for building mex file. The _mex suffix is necessary to avoid
|
||||
# target name conflicts, and the mex file must have a different name than the .m
|
||||
# file.
|
||||
add_library(nmf_mex SHARED
|
||||
nmf.cpp
|
||||
)
|
||||
target_link_libraries(nmf_mex
|
||||
mlpack
|
||||
${LIBXML2_LIBRARIES}
|
||||
)
|
||||
|
||||
# Installation rule. Install both the mex and the MATLAB file.
|
||||
install(TARGETS nmf_mex
|
||||
LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
install(FILES
|
||||
nmf.m
|
||||
DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
@@ -1,106 +0,0 @@
|
||||
#include "mex.h"
|
||||
|
||||
#include <mlpack/core.hpp>
|
||||
|
||||
#include <mlpack/methods/nmf/nmf.hpp>
|
||||
|
||||
#include <mlpack/methods/nmf/random_init.hpp>
|
||||
#include <mlpack/methods/nmf/mult_dist_update_rules.hpp>
|
||||
#include <mlpack/methods/nmf/mult_div_update_rules.hpp>
|
||||
#include <mlpack/methods/nmf/als_update_rules.hpp>
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::nmf;
|
||||
using namespace std;
|
||||
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
// argument checks
|
||||
if (nrhs != 6)
|
||||
{
|
||||
mexErrMsgTxt("Expecting six inputs.");
|
||||
}
|
||||
|
||||
if (nlhs != 2)
|
||||
{
|
||||
mexErrMsgTxt("Two outputs required.");
|
||||
}
|
||||
|
||||
const size_t seed = (size_t) mxGetScalar(prhs[5]);
|
||||
|
||||
// Initialize random seed.
|
||||
if (seed != 0)
|
||||
math::RandomSeed(seed);
|
||||
else
|
||||
math::RandomSeed((size_t) std::time(NULL));
|
||||
|
||||
// Gather parameters.
|
||||
const size_t r = (size_t) mxGetScalar(prhs[1]);
|
||||
const size_t maxIterations = (size_t) mxGetScalar(prhs[2]);
|
||||
const double minResidue = mxGetScalar(prhs[3]);
|
||||
|
||||
// update rule
|
||||
int bufLength = mxGetNumberOfElements(prhs[4]) + 1;
|
||||
char * buf = (char *) mxCalloc(bufLength, sizeof(char));
|
||||
mxGetString(prhs[4], buf, bufLength);
|
||||
string updateRules(buf);
|
||||
mxFree(buf);
|
||||
|
||||
// Validate rank.
|
||||
if (r < 1)
|
||||
{
|
||||
mexErrMsgTxt("The rank of the factorization cannot be less than 1.");
|
||||
}
|
||||
|
||||
if ((updateRules != "multdist") &&
|
||||
(updateRules != "multdiv") &&
|
||||
(updateRules != "als"))
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "Invalid update rules ('" << updateRules << "'); must be '"
|
||||
<< "multdist', 'multdiv', or 'als'.";
|
||||
mexErrMsgTxt(ss.str().c_str());
|
||||
}
|
||||
|
||||
// Load input dataset.
|
||||
arma::mat V(mxGetM(prhs[0]), mxGetN(prhs[0]));
|
||||
double * values = mxGetPr(prhs[0]);
|
||||
for (int i=0, num=mxGetNumberOfElements(prhs[0]); i<num; ++i)
|
||||
V(i) = values[i];
|
||||
|
||||
arma::mat W;
|
||||
arma::mat H;
|
||||
|
||||
// Perform NMF with the specified update rules.
|
||||
if (updateRules == "multdist")
|
||||
{
|
||||
NMF<> nmf(maxIterations, minResidue);
|
||||
nmf.Apply(V, r, W, H);
|
||||
}
|
||||
else if (updateRules == "multdiv")
|
||||
{
|
||||
NMF<RandomInitialization,
|
||||
WMultiplicativeDivergenceRule,
|
||||
HMultiplicativeDivergenceRule> nmf(maxIterations, minResidue);
|
||||
nmf.Apply(V, r, W, H);
|
||||
}
|
||||
else if (updateRules == "als")
|
||||
{
|
||||
NMF<RandomInitialization,
|
||||
WAlternatingLeastSquaresRule,
|
||||
HAlternatingLeastSquaresRule> nmf(maxIterations, minResidue);
|
||||
nmf.Apply(V, r, W, H);
|
||||
}
|
||||
|
||||
// return to matlab
|
||||
plhs[0] = mxCreateDoubleMatrix(W.n_rows, W.n_cols, mxREAL);
|
||||
values = mxGetPr(plhs[0]);
|
||||
for (int i = 0; i < W.n_elem; ++i)
|
||||
values[i] = W(i);
|
||||
|
||||
plhs[1] = mxCreateDoubleMatrix(H.n_rows, H.n_cols, mxREAL);
|
||||
values = mxGetPr(plhs[0]);
|
||||
for (int i = 0; i < H.n_elem; ++i)
|
||||
values[i] = H(i);
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
function [W H] = nmf(dataPoints, rank, varargin)
|
||||
%Non-negative Matrix Factorization
|
||||
%
|
||||
% This program performs non-negative matrix factorization on the given dataset,
|
||||
% storing the resulting decomposed matrices in the specified files. For an
|
||||
% input dataset V, NMF decomposes V into two matrices W and H such that
|
||||
%
|
||||
% V = W * H
|
||||
%
|
||||
% where all elements in W and H are non-negative. If V is of size (n x m), then
|
||||
% W will be of size (n x r) and H will be of size (r x m), where r is the rank
|
||||
% of the factorization (specified by --rank).
|
||||
%
|
||||
% Optionally, the desired update rules for each NMF iteration can be chosen from
|
||||
% the following list:
|
||||
%
|
||||
% - multdist: multiplicative distance-based update rules (Lee and Seung 1999)
|
||||
% - multdiv: multiplicative divergence-based update rules (Lee and Seung 1999)
|
||||
% - als: alternating least squares update rules (Paatero and Tapper 1994)
|
||||
%
|
||||
% The maximum number of iterations is specified with 'max_iterations', and the
|
||||
% minimum residue required for algorithm termination is specified with
|
||||
% 'min_residue'.
|
||||
%
|
||||
%Parameters:
|
||||
% dataPoints - (required) Input dataset to perform NMF on.
|
||||
% rank - (required) Rank of the factorization.
|
||||
% max_iterations - (optional) Number of iterations before NMF terminates.
|
||||
% (Default value 10000.)
|
||||
% min_residue - (optional) The minimum root mean square residue allowed for
|
||||
% each iteration, below which the program
|
||||
% terminates. Default value 1e-05.
|
||||
% seed - (optional) Random seed.If 0, 'std::time(NULL)' is used.
|
||||
% Default 0.
|
||||
% update rules - (optional) Update rules for each iteration; ( multdist |
|
||||
% multdiv | als ). Default value 'multdist'.
|
||||
|
||||
% a parser for the inputs
|
||||
p = inputParser;
|
||||
p.addParamValue('max_iterations', 10000, @isscalar);
|
||||
p.addParamValue('min_residue', 1e-05, @isscalar);
|
||||
p.addParamValue('update_rules', 'multdist', @ischar);
|
||||
p.addParamValue('seed', 0, @isscalar);
|
||||
|
||||
% parsing the varargin options
|
||||
p.parse(varargin{:});
|
||||
parsed = p.Results;
|
||||
|
||||
% interfacing with mlpack. transposing for machine learning standards.
|
||||
[W H] = mex_nmf(dataPoints', rank, ...
|
||||
parsed.max_iterations, parsed.min_residue, ...
|
||||
parsed.update_rules, parsed.seed);
|
||||
W = W';
|
||||
H = H';
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# Simple rules for building mex file. The _mex suffix is necessary to avoid
|
||||
# target name conflicts, and the mex file must have a different name than the .m
|
||||
# file.
|
||||
add_library(pca_mex SHARED
|
||||
pca.cpp
|
||||
)
|
||||
target_link_libraries(pca_mex
|
||||
mlpack
|
||||
${LIBXML2_LIBRARIES}
|
||||
)
|
||||
|
||||
# Installation rule. Install both the mex and the MATLAB file.
|
||||
install(TARGETS pca_mex
|
||||
LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
install(FILES
|
||||
pca.m
|
||||
DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
@@ -1,62 +0,0 @@
|
||||
#include "mex.h"
|
||||
|
||||
#include <mlpack/core.hpp>
|
||||
|
||||
#include <mlpack/methods/pca/pca.hpp>
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::pca;
|
||||
using namespace std;
|
||||
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
// argument checks
|
||||
if (nrhs != 3)
|
||||
{
|
||||
mexErrMsgTxt("Expecting three inputs.");
|
||||
}
|
||||
|
||||
if (nlhs != 1)
|
||||
{
|
||||
mexErrMsgTxt("Output required.");
|
||||
}
|
||||
|
||||
// loading the data
|
||||
double * mexDataPoints = mxGetPr(prhs[0]);
|
||||
size_t numPoints = mxGetN(prhs[0]);
|
||||
size_t numDimensions = mxGetM(prhs[0]);
|
||||
arma::mat dataset(numDimensions, numPoints);
|
||||
for (int i = 0, n = numPoints * numDimensions; i < n; ++i)
|
||||
dataset(i) = mexDataPoints[i];
|
||||
|
||||
// Find out what dimension we want.
|
||||
size_t newDimension = dataset.n_rows; // No reduction, by default.
|
||||
|
||||
if (mxGetScalar(prhs[1]) != 0.0)
|
||||
{
|
||||
// Validate the parameter.
|
||||
newDimension = (size_t) mxGetScalar(prhs[1]);
|
||||
if (newDimension > dataset.n_rows)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "New dimensionality (" << newDimension
|
||||
<< ") cannot be greater than existing dimensionality ("
|
||||
<< dataset.n_rows << ")!";
|
||||
mexErrMsgTxt(ss.str().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// Get the options for running PCA.
|
||||
const bool scale = (mxGetScalar(prhs[2]) == 1.0);
|
||||
|
||||
// Perform PCA.
|
||||
PCA p(scale);
|
||||
p.Apply(dataset, newDimension);
|
||||
|
||||
// Now returning results to matlab
|
||||
plhs[0] = mxCreateDoubleMatrix(dataset.n_rows, dataset.n_cols, mxREAL);
|
||||
double * values = mxGetPr(plhs[0]);
|
||||
for (int i = 0; i < dataset.n_rows * dataset.n_cols; ++i)
|
||||
values[i] = dataset(i);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
function result = pca(dataPoints, varargin)
|
||||
%Principal Components Analysis
|
||||
%
|
||||
% This program performs principal components analysis on the given dataset. It
|
||||
% will transform the data onto its principal components, optionally performing
|
||||
% dimensionality reduction by ignoring the principal components with the
|
||||
% smallest eigenvalues.
|
||||
%
|
||||
%Parameters:
|
||||
% dataPoints - (required) Matrix to perform PCA on.
|
||||
% newDimensionality - (optional) Desired dimensionality of output dataset. If 0,
|
||||
% no dimensionality reduction is performed.
|
||||
% Default value 0.
|
||||
% scale - (optional) If set, the data will be scaled before running
|
||||
% PCA, such that the variance of each feature is
|
||||
% 1. Default value is false.
|
||||
|
||||
% a parser for the inputs
|
||||
p = inputParser;
|
||||
p.addParamValue('newDimensionality', 0, @isscalar);
|
||||
p.addParamValue('scale', false, @(x) (x == true) || (x == false));
|
||||
|
||||
% parsing the varargin options
|
||||
p.parse(varargin{:});
|
||||
parsed = p.Results;
|
||||
|
||||
% interfacing with mlpack
|
||||
result = mex_pca(dataPoints', parsed.newDimensionality, parsed.scale);
|
||||
result = result';
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# Simple rules for building mex file. The _mex suffix is necessary to avoid
|
||||
# target name conflicts, and the mex file must have a different name than the .m
|
||||
# file.
|
||||
add_library(range_search_mex SHARED
|
||||
range_search.cpp
|
||||
)
|
||||
target_link_libraries(range_search_mex
|
||||
mlpack
|
||||
${LIBXML2_LIBRARIES}
|
||||
)
|
||||
|
||||
# Installation rule. Install both the mex and the MATLAB file.
|
||||
install(TARGETS range_search_mex
|
||||
LIBRARY DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
install(FILES
|
||||
range_search.m
|
||||
DESTINATION "${MATLAB_TOOLBOX_DIR}/mlpack/"
|
||||
)
|
||||
@@ -1,325 +0,0 @@
|
||||
/**
|
||||
* @file range_search.cpp
|
||||
* @author Patrick Mason
|
||||
*
|
||||
* MEX function for MATLAB range search binding.
|
||||
*/
|
||||
#include "mex.h"
|
||||
|
||||
#include <mlpack/core.hpp>
|
||||
#include <mlpack/core/metrics/lmetric.hpp>
|
||||
#include <mlpack/methods/range_search/range_search.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::range;
|
||||
using namespace mlpack::tree;
|
||||
|
||||
typedef RangeSearch<metric::SquaredEuclideanDistance,
|
||||
BinarySpaceTree<bound::HRectBound<2>, EmptyStatistic> > RSType;
|
||||
|
||||
// the gateway, required by all mex functions
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
// Give CLI the command line parameters the user passed in.
|
||||
//CLI::ParseCommandLine(argc, argv);
|
||||
|
||||
// Get all the parameters.
|
||||
//string referenceFile = CLI::GetParam<string>("reference_file");
|
||||
//string distancesFile = CLI::GetParam<string>("distances_file");
|
||||
//string neighborsFile = CLI::GetParam<string>("neighbors_file");
|
||||
|
||||
//int lsInt = CLI::GetParam<int>("leaf_size");
|
||||
//double max = CLI::GetParam<double>("max");
|
||||
//double min = CLI::GetParam<double>("min");
|
||||
//bool naive = CLI::HasParam("naive");
|
||||
//bool singleMode = CLI::HasParam("single_mode");
|
||||
|
||||
// argument checks
|
||||
if (nrhs != 7)
|
||||
{
|
||||
mexErrMsgTxt("Expecting an datapoints matrix, isBoruvka, and leafSize.");
|
||||
}
|
||||
|
||||
if (nlhs != 1)
|
||||
{
|
||||
mexErrMsgTxt("Output required.");
|
||||
}
|
||||
|
||||
double max = mxGetScalar(prhs[1]);
|
||||
double min = mxGetScalar(prhs[2]);
|
||||
int lsInt = (int) mxGetScalar(prhs[4]);
|
||||
bool naive = (mxGetScalar(prhs[5]) == 1.0);
|
||||
bool singleMode = (mxGetScalar(prhs[6]) == 1.0);
|
||||
|
||||
// checking for query data
|
||||
bool hasQueryData = ((mxGetM(prhs[3]) != 0) && (mxGetN(prhs[3]) != 0));
|
||||
arma::mat queryData;
|
||||
|
||||
// setting the dataset values.
|
||||
double * mexDataPoints = mxGetPr(prhs[0]);
|
||||
size_t numPoints = mxGetN(prhs[0]);
|
||||
size_t numDimensions = mxGetM(prhs[0]);
|
||||
arma::mat referenceData(numDimensions, numPoints);
|
||||
for (int i = 0, n = numPoints * numDimensions; i < n; ++i)
|
||||
{
|
||||
referenceData(i) = mexDataPoints[i];
|
||||
}
|
||||
|
||||
//if (!data::Load(referenceFile.c_str(), referenceData))
|
||||
// Log::Fatal << "Reference file " << referenceFile << "not found." << endl;
|
||||
|
||||
//Log::Info << "Loaded reference data from '" << referenceFile << "'." << endl;
|
||||
|
||||
// Sanity check on range value: max must be greater than min.
|
||||
if (max <= min)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "Invalid range: maximum (" << max << ") must be greater than "
|
||||
<< "minimum (" << min << ").";
|
||||
mexErrMsgTxt(ss.str().c_str());
|
||||
}
|
||||
|
||||
// Sanity check on leaf size.
|
||||
if (lsInt < 0)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "Invalid leaf size: " << lsInt << ". Must be greater "
|
||||
"than or equal to 0.";
|
||||
mexErrMsgTxt(ss.str().c_str());
|
||||
}
|
||||
|
||||
size_t leafSize = lsInt;
|
||||
|
||||
// Naive mode overrides single mode.
|
||||
if (singleMode && naive)
|
||||
{
|
||||
mexWarnMsgTxt("single_mode ignored because naive is present.");
|
||||
}
|
||||
|
||||
if (naive)
|
||||
leafSize = referenceData.n_cols;
|
||||
|
||||
vector<vector<size_t> > neighbors;
|
||||
vector<vector<double> > distances;
|
||||
|
||||
// Because we may construct it differently, we need a pointer.
|
||||
RSType* rangeSearch = NULL;
|
||||
|
||||
// Mappings for when we build the tree.
|
||||
vector<size_t> oldFromNewRefs;
|
||||
|
||||
// Build trees by hand, so we can save memory: if we pass a tree to
|
||||
// NeighborSearch, it does not copy the matrix.
|
||||
//Log::Info << "Building reference tree..." << endl;
|
||||
//Timer::Start("tree_building");
|
||||
|
||||
BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>
|
||||
refTree(referenceData, oldFromNewRefs, leafSize);
|
||||
BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>*
|
||||
queryTree = NULL; // Empty for now.
|
||||
|
||||
//Timer::Stop("tree_building");
|
||||
|
||||
std::vector<size_t> oldFromNewQueries;
|
||||
|
||||
//if (CLI::GetParam<string>("query_file") != "")
|
||||
if (hasQueryData)
|
||||
{
|
||||
//string queryFile = CLI::GetParam<string>("query_file");
|
||||
//if (!data::Load(queryFile.c_str(), queryData))
|
||||
// Log::Fatal << "Query file " << queryFile << " not found" << endl;
|
||||
|
||||
// setting the values.
|
||||
mexDataPoints = mxGetPr(prhs[3]);
|
||||
numPoints = mxGetN(prhs[3]);
|
||||
numDimensions = mxGetM(prhs[3]);
|
||||
queryData = arma::mat(numDimensions, numPoints);
|
||||
for (int i = 0, n = numPoints * numDimensions; i < n; ++i)
|
||||
{
|
||||
queryData(i) = mexDataPoints[i];
|
||||
}
|
||||
|
||||
if (naive && leafSize < queryData.n_cols)
|
||||
leafSize = queryData.n_cols;
|
||||
|
||||
//Log::Info << "Loaded query data from '" << queryFile << "'." << endl;
|
||||
|
||||
//Log::Info << "Building query tree..." << endl;
|
||||
|
||||
// Build trees by hand, so we can save memory: if we pass a tree to
|
||||
// NeighborSearch, it does not copy the matrix.
|
||||
//Timer::Start("tree_building");
|
||||
|
||||
queryTree = new BinarySpaceTree<bound::HRectBound<2>,
|
||||
tree::EmptyStatistic >(queryData, oldFromNewQueries,
|
||||
leafSize);
|
||||
|
||||
//Timer::Stop("tree_building");
|
||||
|
||||
rangeSearch = new RSType(&refTree, queryTree, referenceData, queryData,
|
||||
singleMode);
|
||||
|
||||
//Log::Info << "Tree built." << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
rangeSearch = new RSType(&refTree, referenceData, singleMode);
|
||||
|
||||
//Log::Info << "Trees built." << endl;
|
||||
}
|
||||
|
||||
//Log::Info << "Computing neighbors within range [" << min << ", " << max
|
||||
// << "]." << endl;
|
||||
|
||||
math::Range r = math::Range(min, max);
|
||||
rangeSearch->Search(r, neighbors, distances);
|
||||
|
||||
//Log::Info << "Neighbors computed." << endl;
|
||||
|
||||
// We have to map back to the original indices from before the tree
|
||||
// construction.
|
||||
//Log::Info << "Re-mapping indices..." << endl;
|
||||
|
||||
vector<vector<double> > distancesOut;
|
||||
distancesOut.resize(distances.size());
|
||||
vector<vector<size_t> > neighborsOut;
|
||||
neighborsOut.resize(neighbors.size());
|
||||
|
||||
// Do the actual remapping.
|
||||
//if (CLI::GetParam<string>("query_file") != "")
|
||||
if (hasQueryData)
|
||||
{
|
||||
for (size_t i = 0; i < distances.size(); ++i)
|
||||
{
|
||||
// Map distances (copy a column).
|
||||
distancesOut[oldFromNewQueries[i]] = distances[i];
|
||||
|
||||
// Map indices of neighbors.
|
||||
neighborsOut[oldFromNewQueries[i]].resize(neighbors[i].size());
|
||||
for (size_t j = 0; j < distances[i].size(); ++j)
|
||||
{
|
||||
neighborsOut[oldFromNewQueries[i]][j] = oldFromNewRefs[neighbors[i][j]];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < distances.size(); ++i)
|
||||
{
|
||||
// Map distances (copy a column).
|
||||
distancesOut[oldFromNewRefs[i]] = distances[i];
|
||||
|
||||
// Map indices of neighbors.
|
||||
neighborsOut[oldFromNewRefs[i]].resize(neighbors[i].size());
|
||||
for (size_t j = 0; j < distances[i].size(); ++j)
|
||||
{
|
||||
neighborsOut[oldFromNewRefs[i]][j] = oldFromNewRefs[neighbors[i][j]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setting values to be returned to matlab
|
||||
mwSize ndim = 1;
|
||||
mwSize dims[1] = {distancesOut.size()};
|
||||
const char * fieldNames[2] = {
|
||||
"neighbors"
|
||||
, "distances"
|
||||
};
|
||||
|
||||
plhs[0] = mxCreateStructArray(ndim, dims, 2, fieldNames);
|
||||
|
||||
// setting the structure elements
|
||||
for (int i=0; i<distancesOut.size(); ++i)
|
||||
{
|
||||
mxArray * tmp;
|
||||
double * values;
|
||||
|
||||
// settings the neighbors
|
||||
const size_t numElements = distancesOut[i].size();
|
||||
tmp = mxCreateDoubleMatrix(1, numElements, mxREAL);
|
||||
values = mxGetPr(tmp);
|
||||
for (int j=0; j<numElements; ++j)
|
||||
{
|
||||
// converting to matlab's index offset
|
||||
values[j] = neighborsOut[i][j] + 1;
|
||||
}
|
||||
// note: SetField does not copy the data structure.
|
||||
// mxDuplicateArray does the necessary copying.
|
||||
mxSetFieldByNumber(plhs[0], i, 0, mxDuplicateArray(tmp));
|
||||
mxDestroyArray(tmp);
|
||||
|
||||
// setting the distances
|
||||
tmp = mxCreateDoubleMatrix(1, numElements, mxREAL);
|
||||
values = mxGetPr(tmp);
|
||||
for (int j=0; j<numElements; ++j)
|
||||
{
|
||||
values[j] = distancesOut[i][j];
|
||||
}
|
||||
mxSetFieldByNumber(plhs[0], i, 1, mxDuplicateArray(tmp));
|
||||
mxDestroyArray(tmp);
|
||||
}
|
||||
|
||||
// Clean up.
|
||||
if (queryTree)
|
||||
delete queryTree;
|
||||
delete rangeSearch;
|
||||
|
||||
/*
|
||||
// Save output. We have to do this by hand.
|
||||
fstream distancesStr(distancesFile.c_str(), fstream::out);
|
||||
if (!distancesStr.is_open())
|
||||
{
|
||||
Log::Warn << "Cannot open file '" << distancesFile << "' to save output "
|
||||
<< "distances to!" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Loop over each point.
|
||||
for (size_t i = 0; i < distancesOut.size(); ++i)
|
||||
{
|
||||
// Store the distances of each point. We may have 0 points to store, so
|
||||
// we must account for that possibility.
|
||||
for (size_t j = 0; j + 1 < distancesOut[i].size(); ++j)
|
||||
{
|
||||
distancesStr << distancesOut[i][j] << ", ";
|
||||
}
|
||||
|
||||
if (distancesOut[i].size() > 0)
|
||||
distancesStr << distancesOut[i][distancesOut[i].size() - 1];
|
||||
|
||||
distancesStr << endl;
|
||||
}
|
||||
|
||||
distancesStr.close();
|
||||
}
|
||||
|
||||
fstream neighborsStr(neighborsFile.c_str(), fstream::out);
|
||||
if (!neighborsStr.is_open())
|
||||
{
|
||||
Log::Warn << "Cannot open file '" << neighborsFile << "' to save output "
|
||||
<< "neighbor indices to!" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Loop over each point.
|
||||
for (size_t i = 0; i < neighborsOut.size(); ++i)
|
||||
{
|
||||
// Store the neighbors of each point. We may have 0 points to store, so
|
||||
// we must account for that possibility.
|
||||
for (size_t j = 0; j + 1 < neighborsOut[i].size(); ++j)
|
||||
{
|
||||
neighborsStr << neighborsOut[i][j] << ", ";
|
||||
}
|
||||
|
||||
if (neighborsOut[i].size() > 0)
|
||||
neighborsStr << neighborsOut[i][neighborsOut[i].size() - 1];
|
||||
|
||||
neighborsStr << endl;
|
||||
}
|
||||
|
||||
neighborsStr.close();
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
function result = range_search(dataPoints, maxDistance, varargin)
|
||||
%Range Search
|
||||
%
|
||||
% This function implements range search with a Euclidean distance metric. For a
|
||||
% given query point, a given range, and a given set of reference points, the
|
||||
% program will return all of the reference points with distance to the query
|
||||
% point in the given range. This is performed for an entire set of query
|
||||
% points. You may specify a separate set of reference and query points, or only
|
||||
% a reference set -- which is then used as both the reference and query set.
|
||||
% The given range is taken to be inclusive (that is, points with a distance
|
||||
% exactly equal to the minimum and maximum of the range are included in the
|
||||
% results).
|
||||
%
|
||||
% For example, the following will calculate the points within the range [2, 5]
|
||||
% of each point in 'input.csv' and store the distances in 'distances.csv' and
|
||||
% the neighbors in 'neighbors.csv':
|
||||
%
|
||||
%Parameters:
|
||||
% dataPoints - (required) Matrix containing the reference dataset.
|
||||
% maxDistance - (required) The upper bound of the range.
|
||||
% minDistance - (optional) The lower bound. The default value is zero.
|
||||
% queryPoints - (optional) Range search query points.
|
||||
% leafSize - (optional) Leaf size for tree building. Default value 20.
|
||||
% naive - (optional) If true, O(n^2) naive mode is used for computation.
|
||||
% singleMode - (optional) If true, single-tree search is used (as opposed to
|
||||
% dual-tree search.
|
||||
|
||||
% a parser for the inputs
|
||||
p = inputParser;
|
||||
p.addParamValue('minDistance', 0, @isscalar);
|
||||
p.addParamValue('queryPoints', zeros(0), @ismatrix);
|
||||
p.addParamValue('leafSize', 20, @isscalar);
|
||||
p.addParamValue('naive', false, @(x) (x == true) || (x == false));
|
||||
p.addParamValue('singleMode', false, @(x) (x == true) || (x == false));
|
||||
|
||||
% parsing the varargin options
|
||||
p.parse(varargin{:});
|
||||
parsed = p.Results;
|
||||
|
||||
% interfacing with mlpack
|
||||
result = mex_range_search(dataPoints', maxDistance, ...
|
||||
parsed.minDistance, parsed.queryPoints', parsed.leafSize, ...
|
||||
parsed.naive, parsed.singleMode);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copy all built artifacts from build/lib.*/* to mlpack/.
|
||||
#
|
||||
# mlpack is free software; you may redistribute it and/or modify it under the
|
||||
# terms of the 3-clause BSD license. You should have received a copy of the
|
||||
# 3-clause BSD license along with mlpack. If not, see
|
||||
# http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
import sys
|
||||
import sysconfig
|
||||
import shutil
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
* Return "mat", "col", or "row" depending on the type of the given Armadillo
|
||||
* object. This is so that the correct overload of arma_numpy.numpy_to_<type>()
|
||||
* can be called.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_GET_ARMA_TYPE_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_GET_ARMA_TYPE_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Template metaprogramming to return the string representation of the Cython
|
||||
* type for a given Cython binding parameter.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_GET_CYTHON_TYPE_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_GET_CYTHON_TYPE_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Given a C++ type, return the Python numpy dtype associated with that type.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_GET_NUMPY_TYPE_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_GET_NUMPY_TYPE_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Given a matrix type, return the letter we should append to get the right
|
||||
* arma_numpy method call.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_GET_NUMPY_TYPE_CHAR_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_GET_NUMPY_TYPE_CHAR_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Get a parameter for a Python binding.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_GET_PARAM_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_GET_PARAM_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Get a printable version of parameters.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_GET_PRINTABLE_PARAM_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_GET_PRINTABLE_PARAM_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Template metaprogramming to return the string representation of the Python
|
||||
* type for a given Python binding parameter.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_GET_PYTHON_TYPE_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_GET_PYTHON_TYPE_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* For a serializable model, print the class import.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_IMPORT_DECL_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_IMPORT_DECL_HPP
|
||||
|
||||
@@ -2,4 +2,9 @@
|
||||
"""
|
||||
This is an autogenerated file that allows convenient imports of mlpack
|
||||
functionality.
|
||||
|
||||
mlpack is free software; you may redistribute it and/or modify it under the
|
||||
terms of the 3-clause BSD license. You should have received a copy of the
|
||||
3-clause BSD license along with mlpack. If not, see
|
||||
http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
"""
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Simple utilities for boost::serialization.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_MLPACK_SERIALIZATION_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_MLPACK_SERIALIZATION_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Print the class definition for generating a .pyx binding.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_PRINT_CLASS_DEFN_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_PRINT_CLASS_DEFN_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Print the definition of a Python parameter.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_PRINT_DEFN_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_PRINT_DEFN_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Print documentation (as part of a docstring) for a Python binding parameter.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_PRINT_DOC_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_PRINT_DOC_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* This file contains functions useful for printing documentation strings
|
||||
* related to Python bindings.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_PRINT_DOC_FUNCTIONS_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_PRINT_DOC_FUNCTIONS_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* This file contains functions useful for printing documentation strings
|
||||
* related to Python bindings.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_PRINT_DOC_FUNCTIONS_IMPL_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_PRINT_DOC_FUNCTIONS_IMPL_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Print input processing for a Python binding option.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_PRINT_INPUT_PROCESSING_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_PRINT_INPUT_PROCESSING_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Print the output processing in a Python binding .pyx file for a given
|
||||
* parameter.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_PRINT_OUTPUT_PROCESSING_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_PRINT_OUTPUT_PROCESSING_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
# so that we can add it to the Python path from CMake.
|
||||
#
|
||||
# The argument to this should be the installation prefix.
|
||||
#
|
||||
# mlpack is free software; you may redistribute it and/or modify it under the
|
||||
# terms of the 3-clause BSD license. You should have received a copy of the
|
||||
# 3-clause BSD license along with mlpack. If not, see
|
||||
# http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
import sys
|
||||
|
||||
print(sys.argv[1] + \
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Implementation of function to generate a .pyx file given a list of parameters
|
||||
* for the function.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#include "print_pyx.hpp"
|
||||
#include <mlpack/core/util/cli.hpp>
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Given a list of ParamData structures, emit a .pyx file defining the Cython
|
||||
* binding.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_GENERATE_PYX_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_GENERATE_PYX_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* The Python option type.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_PY_OPTION_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_PY_OPTION_HPP
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#!/usr/bin/python
|
||||
"""
|
||||
A file to generate a setup.py.
|
||||
|
||||
mlpack is free software; you may redistribute it and/or modify it under the
|
||||
terms of the 3-clause BSD license. You should have received a copy of the
|
||||
3-clause BSD license along with mlpack. If not, see
|
||||
http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Given a C++ typename that may have template parameters, return stripped and
|
||||
* printable versions to be used in Python bindings.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_PYTHON_STRIP_TYPE_HPP
|
||||
#define MLPACK_BINDINGS_PYTHON_STRIP_TYPE_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
test_dataset_info.py
|
||||
|
||||
Test that to_matrix() and to_matrix_with_info() return the correct types.
|
||||
|
||||
mlpack is free software; you may redistribute it and/or modify it under the
|
||||
terms of the 3-clause BSD license. You should have received a copy of the
|
||||
3-clause BSD license along with mlpack. If not, see
|
||||
http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
"""
|
||||
import unittest
|
||||
import pandas as pd
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
test_python_binding.py
|
||||
|
||||
Test that passing types to Python bindings works successfully.
|
||||
|
||||
mlpack is free software; you may redistribute it and/or modify it under the
|
||||
terms of the 3-clause BSD license. You should have received a copy of the
|
||||
3-clause BSD license along with mlpack. If not, see
|
||||
http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
"""
|
||||
import unittest
|
||||
import pandas as pd
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* A binding test for Python.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#include <mlpack/prereqs.hpp>
|
||||
#include <mlpack/core/util/cli.hpp>
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Delete any pointers held by the CLI object.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#include "clean_memory.hpp"
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Delete any unique pointers that are held by the CLI object. This is similar
|
||||
* to the code in end_program.hpp.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_TESTS_CLEAN_MEMORY_HPP
|
||||
#define MLPACK_BINDINGS_TESTS_CLEAN_MEMORY_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* If any memory has been allocated by the parameter, delete it.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_DELETE_ALLOCATED_MEMORY_HPP
|
||||
#define MLPACK_BINDINGS_CLI_DELETE_ALLOCATED_MEMORY_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* If the parameter has a type that may need to be deleted, return the address
|
||||
* of that object. Otherwise return NULL.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_GET_ALLOCATED_MEMORY_HPP
|
||||
#define MLPACK_BINDINGS_CLI_GET_ALLOCATED_MEMORY_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Use template metaprogramming to get the right type of parameter.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_TESTS_GET_PARAM_HPP
|
||||
#define MLPACK_BINDINGS_TESTS_GET_PARAM_HPP
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Print the parameter to stdout, using template metaprogramming to enforce
|
||||
* different behavior for different parameter types.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_TESTS_GET_PRINTABLE_PARAM_HPP
|
||||
#define MLPACK_BINDINGS_TESTS_GET_PRINTABLE_PARAM_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Implementation of parameter printing functions.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_TESTS_GET_PRINTABLE_PARAM_IMPL_HPP
|
||||
#define MLPACK_BINDINGS_TESTS_GET_PRINTABLE_PARAM_IMPL_HPP
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Implementation of IgnoreCheck() for Python bindings.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_TEST_IGNORE_CHECK_HPP
|
||||
#define MLPACK_BINDINGS_TEST_IGNORE_CHECK_HPP
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
* This is an adapted version of Conrad Sanderson's implementation of
|
||||
* arma::diskio::convert_naninf() from Armadillo. It is here so as to avoid
|
||||
* using Armadillo internal functionality.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_CORE_DATA_HAS_NANINF_HPP
|
||||
#define MLPACK_CORE_DATA_HAS_NANINF_HPP
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
/**
|
||||
* @file load_csv.cpp
|
||||
* @author Tham Ngap Wei
|
||||
*
|
||||
* A CSV reader that uses boost::spirit.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#include "load_csv.hpp"
|
||||
|
||||
using namespace boost::spirit;
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
*
|
||||
* Make an alias of a matrix. For sparse matrices, unfortunately no alias can
|
||||
* be made and a copy must be incurred.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_CORE_MATH_MAKE_ALIAS_HPP
|
||||
#define MLPACK_CORE_MATH_MAKE_ALIAS_HPP
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user