├── .gitignore ├── SConstruct ├── buildenvironment ├── cygwin.py ├── darwin.py ├── msys.py └── posix.py ├── classifier ├── classifier.h ├── classifier.hpp └── lazylearner.hpp ├── clustering ├── clustering.h ├── nonsupervised │ ├── clustering.hpp │ ├── clustering.i │ ├── kmeans.hpp │ ├── kmeans.i │ ├── neuralgas.hpp │ ├── neuralgas.i │ ├── relational_neuralgas.hpp │ ├── relational_neuralgas.i │ ├── spectralclustering.hpp │ └── spectralclustering.i └── supervised │ ├── clustering.hpp │ ├── clustering.i │ ├── rlvq.hpp │ └── rlvq.i ├── dimensionreduce ├── dimensionreduce.h ├── nonsupervised │ ├── lle.hpp │ ├── mds.hpp │ ├── mds.i │ ├── pca.hpp │ ├── pca.i │ ├── reduce.hpp │ └── reduce.i └── supervised │ ├── lda.hpp │ ├── lda.i │ ├── reduce.hpp │ └── reduce.i ├── distances ├── distance.hpp ├── distance.i ├── distances.h ├── ncd.hpp ├── ncd.i └── norm │ ├── euclid.hpp │ └── euclid.i ├── documentation ├── .gitignore ├── build.py ├── documentation.doxyfile └── documentation.footer.htm ├── errorhandling ├── assert.h ├── exception.hpp └── exception.implementation.hpp ├── examples ├── classifier │ ├── build.py │ └── lazy.cpp ├── clustering │ ├── build.py │ ├── kmeans.cpp │ ├── neuralgas.cpp │ ├── patch_neuralgas.cpp │ ├── relational_neuralgas.cpp │ ├── rlvq.cpp │ └── spectral.cpp ├── distance │ ├── build.py │ └── ncd.cpp ├── geneticalgorithm │ ├── build.py │ └── knapsack.cpp ├── java │ ├── clustering │ │ ├── build.py │ │ ├── rng.java │ │ └── spectral.java │ ├── reducing │ │ ├── build.py │ │ ├── mds.java │ │ └── pca.java │ └── tools │ │ ├── build.py │ │ ├── eigen.java │ │ ├── random.java │ │ └── svd.java ├── other │ ├── build.py │ ├── matlab │ │ ├── plotfiles.m │ │ ├── plotnntp.m │ │ ├── plottwitter.m │ │ └── plotwiki.m │ ├── mds_file.cpp │ ├── mds_nntp.cpp │ ├── mds_twitter.cpp │ └── mds_wikipedia.cpp ├── reducing │ ├── build.py │ ├── lda.cpp │ ├── mds.cpp │ └── pca.cpp └── sources │ ├── build.py │ ├── cloud.cpp │ ├── newsgroup.cpp │ ├── twitter.cpp │ └── wikipedia.cpp ├── functionoptimization ├── functionoptimization.h └── gradientdescent.hpp ├── geneticalgorithm ├── crossover │ ├── crossover.h │ ├── crossover.hpp │ └── kcrossover.hpp ├── fitness │ ├── fitness.h │ └── fitness.hpp ├── geneticalgorithm.h ├── individual │ ├── binaryindividual.hpp │ ├── individual.h │ └── individual.hpp ├── population.hpp └── selection │ ├── bestof.hpp │ ├── roulettewheel.hpp │ ├── selection.h │ └── selection.hpp ├── library ├── .gitignore └── build.py ├── license.md ├── machinelearning.cpp ├── machinelearning.h ├── neighborhood ├── kapproximation.hpp ├── knn.hpp ├── neighborhood.h └── neighborhood.hpp ├── readme.md ├── styleguide ├── checkstyle.py └── rules.py ├── swig └── java │ ├── build.py │ ├── java.hpp │ └── java.i ├── textprocess ├── stopwordreduction.h ├── termfrequency.h └── textprocess.h └── tools ├── files ├── csv.hpp ├── files.h ├── hdf.hpp └── hdf.i ├── function.hpp ├── iostreams ├── iostreams.h └── urlencoder.h ├── language ├── bindings.h ├── build.py ├── de.po ├── iso639.h └── language.h ├── lapack.hpp ├── lapack.i ├── logger.hpp ├── logger.implementation.hpp ├── matrix.hpp ├── matrix.i ├── random.hpp ├── random.i ├── sources ├── cloud.hpp ├── nntp.h ├── sources.h ├── twitter.h └── wikipedia.h ├── tools.h ├── typeinfo.h ├── vector.hpp └── vector.i /.gitignore: -------------------------------------------------------------------------------- 1 | *.bak 2 | *.bz2 3 | *.bzip 4 | *.cbp 5 | *.class 6 | *.core 7 | *.dblite 8 | *.dll 9 | *.dylib 10 | *.git* 11 | *.gzip 12 | *.hdf* 13 | *.jpg 14 | *.layout 15 | *.log 16 | *.os 17 | *.png 18 | *.pyc 19 | *.so 20 | *.o 21 | *.a 22 | *.lib 23 | *.stackdump 24 | *.xcodeproj 25 | *.zip 26 | .sconf_temp 27 | build 28 | -------------------------------------------------------------------------------- /classifier/classifier.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** header file to connect all clustering algorithm for one include **/ 25 | 26 | #ifndef __MACHINELEARNING_CLASSIFIER_CLASSIFIER_H 27 | #define __MACHINELEARNING_CLASSIFIER_CLASSIFIER_H 28 | 29 | #include "classifier.hpp" 30 | 31 | #include "lazylearner.hpp" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /classifier/classifier.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | #ifndef __MACHINELEARNING_CLASSIFIER_CLASSIFIER_HPP 25 | #define __MACHINELEARNING_CLASSIFIER_CLASSIFIER_HPP 26 | 27 | 28 | #include 29 | #include 30 | 31 | #include "../errorhandling/exception.hpp" 32 | #include "../distances/distances.h" 33 | 34 | 35 | namespace machinelearning { 36 | 37 | /** namespace for all classifier algorithms **/ 38 | namespace classifier { 39 | 40 | namespace ublas = boost::numeric::ublas; 41 | 42 | 43 | 44 | /** abstract class for classificator 45 | * @note every data matrix must be row orientated. 46 | * data matrix NxM with n number of datapoints and M data dimension 47 | * @todo checking method names and parameters (it's not optimal for using) 48 | **/ 49 | template class classifier 50 | { 51 | BOOST_STATIC_ASSERT( !boost::is_integral::value ); 52 | 53 | 54 | public : 55 | 56 | /** method for training prototypes **/ 57 | virtual void setDatabase( const ublas::matrix&, const std::vector& ) = 0; 58 | 59 | /** method which returns prototypes **/ 60 | virtual ublas::matrix getDatabasePoints( void ) const = 0; 61 | 62 | /** return lables of prototypes **/ 63 | virtual std::vector getDatabaseLabel( void ) const = 0; 64 | 65 | /** disable and enable logging **/ 66 | virtual void setLogging( const bool& ) = 0; 67 | 68 | /** returns dimension of data points **/ 69 | virtual std::size_t getDatabaseSize( void ) const = 0; 70 | 71 | /** returns number of data points **/ 72 | virtual std::size_t getDatabaseCount( void ) const = 0; 73 | 74 | /** shows logging status **/ 75 | virtual bool getLogging( void ) const = 0; 76 | 77 | /** return the quantizationerror **/ 78 | virtual std::vector getLoggedQuantizationError( void ) const = 0; 79 | 80 | /** calculate label for unkown datapoints **/ 81 | virtual std::vector use( const ublas::matrix& ) const = 0; 82 | 83 | }; 84 | 85 | } 86 | } 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /clustering/clustering.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** header file to connect all clustering algorithm for one include **/ 25 | 26 | #ifndef __MACHINELEARNING_CLUSTERING_CLUSTERING_H 27 | #define __MACHINELEARNING_CLUSTERING_CLUSTERING_H 28 | 29 | namespace machinelearning { 30 | 31 | /** namespace for all clustering algorithms 32 | * @todo adding SOM http://www.cis.hut.fi/research/som-research/ 33 | **/ 34 | namespace clustering { } 35 | 36 | } 37 | 38 | 39 | #include "nonsupervised/clustering.hpp" 40 | #include "nonsupervised/neuralgas.hpp" 41 | #include "nonsupervised/relational_neuralgas.hpp" 42 | #include "nonsupervised/kmeans.hpp" 43 | #include "nonsupervised/spectralclustering.hpp" 44 | 45 | #include "supervised/clustering.hpp" 46 | #include "supervised/rlvq.hpp" 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /clustering/nonsupervised/kmeans.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for k-means **/ 25 | 26 | 27 | #ifdef SWIGJAVA 28 | %module "kmeansmodule" 29 | %include "../../swig/java/java.i" 30 | 31 | %typemap(javainterfaces) machinelearning::clustering::nonsupervised::kmeans "Clustering"; 32 | #endif 33 | 34 | 35 | %include "kmeans.hpp" 36 | %template(kMeans) machinelearning::clustering::nonsupervised::kmeans; 37 | -------------------------------------------------------------------------------- /clustering/nonsupervised/neuralgas.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for neural gas **/ 25 | 26 | 27 | #ifdef SWIGJAVA 28 | %module "neuralgasmodule" 29 | %include "../../swig/java/java.i" 30 | 31 | %typemap(javainterfaces) machinelearning::clustering::nonsupervised::neuralgas "Clustering, PatchClustering"; 32 | #endif 33 | 34 | 35 | %include "neuralgas.hpp" 36 | %template(NeuralGas) machinelearning::clustering::nonsupervised::neuralgas; 37 | -------------------------------------------------------------------------------- /clustering/nonsupervised/relational_neuralgas.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for relational neuralgas **/ 25 | 26 | 27 | #ifdef SWIGJAVA 28 | %module "rngmodule" 29 | %include "../../swig/java/java.i" 30 | 31 | %typemap(javainterfaces) machinelearning::clustering::nonsupervised::relational_neuralgas "Clustering"; 32 | #endif 33 | 34 | 35 | %include "relational_neuralgas.hpp" 36 | %template(RelationalNeuralGas) machinelearning::clustering::nonsupervised::relational_neuralgas; 37 | -------------------------------------------------------------------------------- /clustering/nonsupervised/spectralclustering.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for spectral clustering **/ 25 | 26 | 27 | #ifdef SWIGJAVA 28 | %module "spectralclusteringmodule" 29 | %include "../../swig/java/java.i" 30 | 31 | %typemap(javainterfaces) machinelearning::clustering::nonsupervised::spectralclustering "Clustering"; 32 | #endif 33 | 34 | 35 | %include "spectralclustering.hpp" 36 | %template(SpectralClustering) machinelearning::clustering::nonsupervised::spectralclustering; 37 | -------------------------------------------------------------------------------- /clustering/supervised/clustering.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | #ifndef __MACHINELEARNING_CLUSTERING_SUPERVISED_CLUSTERING_HPP 25 | #define __MACHINELEARNING_CLUSTERING_SUPERVISED_CLUSTERING_HPP 26 | 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "../../errorhandling/exception.hpp" 33 | #include "../../distances/distances.h" 34 | #include "../../tools/tools.h" 35 | 36 | namespace machinelearning { namespace clustering { 37 | 38 | /** namespace for all supervised cluster algorithms **/ 39 | namespace supervised { 40 | 41 | #ifndef SWIG 42 | namespace ublas = boost::numeric::ublas; 43 | #endif 44 | 45 | 46 | /** abstract class for all supervised clustering classes 47 | * @note every data / prototype matrix must be row orientated. 48 | * data matrix NxM with n number of datapoints and M data dimension 49 | * @note The template type of this class need not be a countable datatype like (eg. int, long) 50 | * @todo add method for setting prototypes 51 | * @todo add supervised neural gas (see bng_supervised/bng_supervised.m) 52 | **/ 53 | template class clustering 54 | { 55 | #ifndef SWIG 56 | BOOST_STATIC_ASSERT( !boost::is_integral::value ); 57 | #endif 58 | 59 | 60 | public : 61 | 62 | /** method for training prototypes **/ 63 | virtual void train( const ublas::matrix&, const std::vector&, const std::size_t& ) = 0; 64 | 65 | /** method which returns prototypes **/ 66 | virtual ublas::matrix getPrototypes( void ) const = 0; 67 | 68 | /** return lables of prototypes **/ 69 | virtual std::vector getPrototypesLabel( void ) const = 0; 70 | 71 | /** disable and enable logging **/ 72 | virtual void setLogging( const bool& ) = 0; 73 | 74 | /** shows logging status **/ 75 | virtual bool getLogging( void ) const = 0; 76 | 77 | /** return history of trained prototypes **/ 78 | virtual std::vector< ublas::matrix > getLoggedPrototypes( void ) const = 0; 79 | 80 | /** returns the dimension of prototypes **/ 81 | virtual std::size_t getPrototypeSize( void ) const = 0; 82 | 83 | /** number of prototypes / classes **/ 84 | virtual std::size_t getPrototypeCount( void ) const = 0; 85 | 86 | /** return the quantizationerror **/ 87 | virtual std::vector getLoggedQuantizationError( void ) const = 0; 88 | 89 | /** index position for prototype or label **/ 90 | virtual ublas::indirect_array<> use( const ublas::matrix& ) const = 0; 91 | 92 | }; 93 | 94 | } 95 | 96 | } 97 | } 98 | #endif 99 | -------------------------------------------------------------------------------- /clustering/supervised/rlvq.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for rlvq **/ 25 | 26 | 27 | #ifdef SWIGJAVA 28 | %module "rlvqmodule" 29 | %include "../../swig/java/java.i" 30 | 31 | %typemap(javainterfaces) machinelearning::clustering::supervised::rlvq "ClusteringString"; 32 | %typemap(javainterfaces) machinelearning::clustering::supervised::rlvq "ClusteringLong"; 33 | #endif 34 | 35 | 36 | %include "rlvq.hpp" 37 | %template(RLVQString) machinelearning::clustering::supervised::rlvq; 38 | %template(RLVQLong) machinelearning::clustering::supervised::rlvq; 39 | -------------------------------------------------------------------------------- /dimensionreduce/dimensionreduce.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** header file to connect all dimensional reducing algorithm for one include **/ 25 | 26 | #ifndef __MACHINELEARNING_DIMENSIONREDUCE_DIMENSIONREDUCE_H 27 | #define __MACHINELEARNING_DIMENSIONREDUCE_DIMENSIONREDUCE_H 28 | 29 | 30 | namespace machinelearning { 31 | 32 | /** namespace for all algorithms to reduce data dimension **/ 33 | namespace dimensionreduce { } 34 | 35 | } 36 | 37 | 38 | #include "supervised/reduce.hpp" 39 | #include "supervised/lda.hpp" 40 | 41 | #include "nonsupervised/reduce.hpp" 42 | #include "nonsupervised/pca.hpp" 43 | #include "nonsupervised/lle.hpp" 44 | #include "nonsupervised/mds.hpp" 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /dimensionreduce/nonsupervised/mds.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for MDS **/ 25 | 26 | 27 | #ifdef SWIGJAVA 28 | %module "mdsmodule" 29 | %include "../../swig/java/java.i" 30 | 31 | %typemap(javainterfaces) machinelearning::dimensionreduce::nonsupervised::mds "Reduce"; 32 | #endif 33 | 34 | 35 | %include "mds.hpp" 36 | %template(MDS) machinelearning::dimensionreduce::nonsupervised::mds; 37 | -------------------------------------------------------------------------------- /dimensionreduce/nonsupervised/pca.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for PCA **/ 25 | 26 | 27 | #ifdef SWIGJAVA 28 | %module "pcamodule" 29 | %include "../../swig/java/java.i" 30 | 31 | %typemap(javainterfaces) machinelearning::dimensionreduce::nonsupervised::pca "Reduce"; 32 | #endif 33 | 34 | 35 | %include "pca.hpp" 36 | %template(PCA) machinelearning::dimensionreduce::nonsupervised::pca; 37 | -------------------------------------------------------------------------------- /dimensionreduce/nonsupervised/reduce.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | #ifndef __MACHINELEARNING_DIMENSIONREDUCE_NONSUPERVISED_REDUCE_HPP 26 | #define __MACHINELEARNING_DIMENSIONREDUCE_NONSUPERVISED_REDUCE_HPP 27 | 28 | 29 | #include 30 | #include 31 | 32 | #ifdef MACHINELEARNING_MPI 33 | #include 34 | #endif 35 | 36 | #include "../../errorhandling/exception.hpp" 37 | #include "../../tools/tools.h" 38 | 39 | 40 | namespace machinelearning { namespace dimensionreduce { 41 | 42 | /** namespace for all non-supervised reducing algorithms **/ 43 | namespace nonsupervised { 44 | 45 | #ifndef SWIG 46 | namespace ublas = boost::numeric::ublas; 47 | #ifdef MACHINELEARNING_MPI 48 | namespace mpi = boost::mpi; 49 | #endif 50 | #endif 51 | 52 | 53 | /** abstract class for nonsupervised dimension reducing classes **/ 54 | template class reduce 55 | { 56 | #ifndef SWIG 57 | BOOST_STATIC_ASSERT( !boost::is_integral::value ); 58 | #endif 59 | 60 | 61 | public : 62 | 63 | /** maps data to target dimension **/ 64 | virtual ublas::matrix map( const ublas::matrix& ) = 0; 65 | 66 | /** returns the mapped dimension **/ 67 | virtual std::size_t getDimension( void ) const = 0; 68 | 69 | }; 70 | 71 | 72 | #ifdef MACHINELEARNING_MPI 73 | 74 | /** abstract class for nonsupervised dimension reducing classes with MPI support **/ 75 | template class reducempi 76 | { 77 | BOOST_STATIC_ASSERT( !boost::is_integral::value ); 78 | 79 | 80 | public : 81 | 82 | /** maps data to target dimension **/ 83 | virtual ublas::matrix map( const mpi::communicator&, const ublas::matrix& ) = 0; 84 | 85 | }; 86 | 87 | #endif 88 | } 89 | 90 | } } 91 | #endif 92 | -------------------------------------------------------------------------------- /dimensionreduce/nonsupervised/reduce.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for the supervived reduce class, that should be 25 | * an java interface, because we can use the multiple inheritance and 26 | * disable all body parts 27 | **/ 28 | 29 | 30 | #ifdef SWIGJAVA 31 | %module "nonsupervicedreduceemodule" 32 | %include "../../swig/java/java.i" 33 | 34 | %typemap(javaclassmodifiers) machinelearning::dimensionreduce::nonsupervised::reduce "public interface" 35 | %typemap(javabody) machinelearning::dimensionreduce::nonsupervised::reduce "" 36 | %typemap(javafinalize) machinelearning::dimensionreduce::nonsupervised::reduce "" 37 | %typemap(javadestruct) machinelearning::dimensionreduce::nonsupervised::reduce "" 38 | 39 | %typemap(javaout) ublas::matrix machinelearning::dimensionreduce::nonsupervised::reduce::map ";" 40 | %typemap(javaout) std::size_t machinelearning::dimensionreduce::nonsupervised::reduce::getDimension ";" 41 | #endif 42 | 43 | 44 | %nodefaultctor machinelearning::dimensionreduce::nonsupervised::reduce; 45 | %nodefaultdtor machinelearning::dimensionreduce::nonsupervised::reduce; 46 | 47 | 48 | %include "reduce.hpp" 49 | %template(Reduce) machinelearning::dimensionreduce::nonsupervised::reduce; 50 | -------------------------------------------------------------------------------- /dimensionreduce/supervised/lda.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for LDA **/ 25 | 26 | 27 | #ifdef SWIGJAVA 28 | %module "ldamodule" 29 | %include "../../swig/java/java.i" 30 | 31 | %typemap(javainterfaces) machinelearning::dimensionreduce::supervised::lda "ReduceString"; 32 | %typemap(javainterfaces) machinelearning::dimensionreduce::supervised::lda "ReduceLong"; 33 | #endif 34 | 35 | 36 | %include "lda.hpp" 37 | %template(LDAString) machinelearning::dimensionreduce::supervised::lda; 38 | %template(LDALong) machinelearning::dimensionreduce::supervised::lda; -------------------------------------------------------------------------------- /dimensionreduce/supervised/reduce.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | #ifndef __MACHINELEARNING_DIMENSIONREDUCE_SUPERVISED_REDUCE_HPP 26 | #define __MACHINELEARNING_DIMENSIONREDUCE_SUPERVISED_REDUCE_HPP 27 | 28 | 29 | #include 30 | #include 31 | 32 | #ifdef MACHINELEARNING_MPI 33 | #include 34 | #endif 35 | 36 | #include "../../errorhandling/exception.hpp" 37 | #include "../../tools/tools.h" 38 | 39 | 40 | namespace machinelearning { namespace dimensionreduce { 41 | 42 | /** namespace for all supervised reducing algorithms **/ 43 | namespace supervised { 44 | 45 | #ifndef SWIG 46 | namespace ublas = boost::numeric::ublas; 47 | #endif 48 | 49 | 50 | /** abstract class for supervised dimension reducing classes **/ 51 | template class reduce 52 | { 53 | #ifndef SWIG 54 | BOOST_STATIC_ASSERT( !boost::is_integral::value ); 55 | #endif 56 | 57 | 58 | public : 59 | 60 | /** maps data to target dimension **/ 61 | virtual ublas::matrix map( const ublas::matrix&, const std::vector& ) = 0; 62 | 63 | /** returns the mapped dimension **/ 64 | virtual std::size_t getDimension( void ) const = 0; 65 | 66 | }; 67 | 68 | } 69 | 70 | } } 71 | #endif 72 | -------------------------------------------------------------------------------- /dimensionreduce/supervised/reduce.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for the supervived reduce class, that should be 25 | * an java interface, because we can use the multiple inheritance and 26 | * disable all body parts 27 | **/ 28 | 29 | 30 | #ifdef SWIGJAVA 31 | %module "supervicedreduceemodule" 32 | %include "../../swig/java/java.i" 33 | 34 | %typemap(javaclassmodifiers) machinelearning::dimensionreduce::supervised::reduce "public interface" 35 | %typemap(javabody) machinelearning::dimensionreduce::supervised::reduce "" 36 | %typemap(javafinalize) machinelearning::dimensionreduce::supervised::reduce "" 37 | %typemap(javadestruct) machinelearning::dimensionreduce::supervised::reduce "" 38 | 39 | %typemap(javaout) ublas::matrix machinelearning::dimensionreduce::supervised::reduce::map ";" 40 | %typemap(javaout) std::size_t machinelearning::dimensionreduce::supervised::reduce::getDimension ";" 41 | 42 | 43 | %typemap(javaclassmodifiers) machinelearning::dimensionreduce::supervised::reduce "public interface" 44 | %typemap(javabody) machinelearning::dimensionreduce::supervised::reduce "" 45 | %typemap(javafinalize) machinelearning::dimensionreduce::supervised::reduce "" 46 | %typemap(javadestruct) machinelearning::dimensionreduce::supervised::reduce "" 47 | 48 | %typemap(javaout) ublas::matrix machinelearning::dimensionreduce::supervised::reduce::map ";" 49 | %typemap(javaout) std::size_t machinelearning::dimensionreduce::supervised::reduce::getDimension ";" 50 | #endif 51 | 52 | 53 | %nodefaultctor machinelearning::dimensionreduce::supervised::reduce; 54 | %nodefaultdtor machinelearning::dimensionreduce::supervised::reduce; 55 | 56 | %nodefaultctor machinelearning::dimensionreduce::supervised::reduce; 57 | %nodefaultdtor machinelearning::dimensionreduce::supervised::reduce; 58 | 59 | 60 | %include "reduce.hpp" 61 | %template(ReduceString) machinelearning::dimensionreduce::supervised::reduce; 62 | %template(ReduceLong) machinelearning::dimensionreduce::supervised::reduce; -------------------------------------------------------------------------------- /distances/distance.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for the distance class, that must create an abstract class 25 | * without any methods and properties, because the C++ class are pure virtual 26 | * and the methods are only called in the implementated JNI functions 27 | **/ 28 | 29 | 30 | #ifdef SWIGJAVA 31 | %module "distancemodule" 32 | %include "../swig/java/java.i" 33 | 34 | %typemap(javaclassmodifiers) machinelearning::distances::distance "public interface" 35 | %typemap(javabody) machinelearning::distances::distance "" 36 | %typemap(javafinalize) machinelearning::distances::distance "" 37 | %typemap(javadestruct) machinelearning::distances::distance "" 38 | 39 | %typemap(javaout) ublas::vector machinelearning::distances::distance::getNormalize ";" 40 | %typemap(javaout) ublas::matrix machinelearning::distances::distance::getNormalize ";" 41 | %typemap(javaout) double machinelearning::distances::distance::getLength ";" 42 | %typemap(javaout) ublas::vector machinelearning::distances::distance::getLength ";" 43 | %typemap(javaout) double machinelearning::distances::distance::getInvert ";" 44 | %typemap(javaout) ublas::vector machinelearning::distances::distance::getAbs ";" 45 | %typemap(javaout) double machinelearning::distances::distance::getDistance ";" 46 | %typemap(javaout) ublas::vector machinelearning::distances::distance::getDistance ";" 47 | #endif 48 | 49 | 50 | %nodefaultctor machinelearning::distances::distance; 51 | %nodefaultdtor machinelearning::distances::distance; 52 | 53 | 54 | %include "distance.hpp" 55 | %template(Distance) machinelearning::distances::distance; -------------------------------------------------------------------------------- /distances/distances.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | 26 | /** header file to connect all tools library for one includ **/ 27 | 28 | #ifndef __MACHINELEARNING_DISTANCES_DISTANCES_H 29 | #define __MACHINELEARNING_DISTANCES_DISTANCES_H 30 | 31 | 32 | namespace machinelearning { 33 | 34 | /** distance namespace for structures which calculates distances **/ 35 | namespace distances { 36 | 37 | /** namespace for norm structures **/ 38 | namespace norm { } 39 | 40 | } 41 | } 42 | 43 | 44 | #include "distance.hpp" 45 | #include "ncd.hpp" 46 | #include "norm/euclid.hpp" 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /distances/ncd.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for the NCD **/ 25 | 26 | 27 | #ifdef SWIGJAVA 28 | %module "ncdmodule" 29 | %include "../swig/java/java.i" 30 | #endif 31 | 32 | 33 | %include "ncd.hpp" 34 | %template(NCD) machinelearning::distances::ncd; 35 | -------------------------------------------------------------------------------- /distances/norm/euclid.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for the euclidian norm, set base classe manually **/ 25 | 26 | 27 | #ifdef SWIGJAVA 28 | %module "euclidmodule" 29 | %include "../../swig/java/java.i" 30 | 31 | %typemap(javainterfaces) machinelearning::distances::norm::euclid "machinelearning.distances.Distance"; 32 | #endif 33 | 34 | 35 | %include "euclid.hpp" 36 | %template(Euclid) machinelearning::distances::norm::euclid; 37 | -------------------------------------------------------------------------------- /documentation/.gitignore: -------------------------------------------------------------------------------- 1 | html 2 | -------------------------------------------------------------------------------- /documentation/build.py: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # LGPL License # 3 | # # 4 | # This file is part of the Machine Learning Framework. # 5 | # Copyright (c) 2010-2012, Philipp Kraus, # 6 | # This program is free software: you can redistribute it and/or modify # 7 | # it under the terms of the GNU Lesser General Public License as # 8 | # published by the Free Software Foundation, either version 3 of the # 9 | # License, or (at your option) any later version. # 10 | # # 11 | # This program is distributed in the hope that it will be useful, # 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | # GNU Lesser General Public License for more details. # 15 | # # 16 | # You should have received a copy of the GNU Lesser General Public License # 17 | # along with this program. If not, see . # 18 | ############################################################################ 19 | 20 | # -*- coding: utf-8 -*- 21 | 22 | 23 | # build script for the documentation 24 | 25 | import os 26 | Import("*") 27 | 28 | env.Clean( 29 | env.Alias( "documentation", 30 | env.Command("documentation", "documentation.doxyfile", "doxygen $SOURCE") 31 | ), 32 | os.path.join("#", "documentation", "html") 33 | ) -------------------------------------------------------------------------------- /documentation/documentation.footer.htm: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /errorhandling/assert.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** preprocessor command for framework asserts, which can be added to the logger 25 | * if the logger exists 26 | **/ 27 | 28 | #ifndef __MACHINELEARNING_ERRORHANDLING_ASSERT_H 29 | #define __MACHINELEARNING_ERRORHANDLING_ASSERT_H 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "../tools/logger.hpp" 36 | 37 | 38 | 39 | #ifdef MACHINELEARNING_NDEBUG 40 | 41 | #define MACHINELEARNING_ASSERT( p_expression, p_message ) 42 | 43 | #else 44 | 45 | #ifdef MACHINELEARNING_LOGGER 46 | 47 | #define MACHINELEARNING_ASSERT( p_expression, p_message ) \ 48 | { \ 49 | if (!p_expression) { \ 50 | if (machinelearning::tools::logger::exists()) { \ 51 | std::stringstream l_msg; \ 52 | l_msg << p_message << ", " << __FILE__ << ", line " << __LINE__; \ 53 | machinelearning::tools::logger::getInstance()->write( machinelearning::tools::logger::assert, l_msg.str() ); \ 54 | } \ 55 | std::cerr << "Machinlearning Assertion failed: " << p_message << ", " << __FILE__ << ", line " << __LINE__ << std::endl; \ 56 | exit(EXIT_FAILURE); \ 57 | } \ 58 | } 59 | 60 | #else 61 | 62 | #define MACHINELEARNING_ASSERT( p_expression, p_message ) \ 63 | { \ 64 | if (!p_expression) { \ 65 | std::cerr << "Machinlearning Assertion failed: " << p_message << ", " << __FILE__ << ", line " << __LINE__ << std::endl; \ 66 | exit(EXIT_FAILURE); \ 67 | } \ 68 | } 69 | 70 | #endif 71 | 72 | #endif 73 | 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /errorhandling/exception.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | #ifndef __MACHINELEARNING_ERRORHANDLING_EXCEPTION_HPP 25 | #define __MACHINELEARNING_ERRORHANDLING_EXCEPTION_HPP 26 | 27 | #include 28 | #include 29 | 30 | 31 | namespace machinelearning { 32 | 33 | /** namespace for all exceptions of the framework 34 | * @todo adding more exceptions for a better error handling 35 | **/ 36 | namespace exception { 37 | 38 | 39 | /** exception class for throwing on runtime errors **/ 40 | class runtime : public std::runtime_error 41 | { 42 | public : 43 | 44 | explicit runtime( const std::string& ); 45 | template explicit runtime( const std::string&, const T* ); 46 | template explicit runtime( const std::string&, const T& ); 47 | }; 48 | 49 | 50 | } 51 | } 52 | 53 | 54 | #include "exception.implementation.hpp" 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /errorhandling/exception.implementation.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | #ifndef __MACHINELEARNING_ERRORHANDLING_EXCEPTION_HPP 25 | #error never include this file directly 26 | #elif !defined __MACHINELEARNING_ERRORHANDLING_EXCEPTION_IMPLEMENTATION_HPP 27 | #define __MACHINELEARNING_ERRORHANDLING_EXCEPTION_IMPLEMENTATION_HPP 28 | 29 | #include 30 | #include 31 | 32 | #include "../tools/language/language.h" 33 | #include "../tools/typeinfo.h" 34 | #include "../tools/logger.hpp" 35 | 36 | 37 | 38 | namespace machinelearning { namespace exception { 39 | 40 | /** creates the exception with a message 41 | * @param p_msg error message 42 | **/ 43 | inline runtime::runtime( const std::string& p_msg ) : 44 | std::runtime_error( p_msg ) 45 | { 46 | #ifdef MACHINELEARNING_LOGGER 47 | if (tools::logger::exists()) 48 | tools::logger::getInstance()->write( tools::logger::exception, _("runtime exception is thrown: ") + p_msg); 49 | #endif 50 | } 51 | 52 | 53 | /** creates the exception with a message and a class name 54 | * @param p_msg error message 55 | * @param p_ptr pointer to an class object 56 | **/ 57 | template inline runtime::runtime( const std::string& p_msg, const T* p_ptr ) : 58 | std::runtime_error( p_msg + ( !tools::typeinfo::getClassName(p_ptr).empty() ? " ["+tools::typeinfo::getClassName(p_ptr)+"]" : "") ) 59 | { 60 | #ifdef MACHINELEARNING_LOGGER 61 | if (tools::logger::exists()) 62 | tools::logger::getInstance()->write( tools::logger::exception, _("runtime exception is thrown: ") + p_msg + ( !tools::typeinfo::getClassName(p_ptr).empty() ? " ["+tools::typeinfo::getClassName(p_ptr)+"]" : "")); 63 | #endif 64 | } 65 | 66 | 67 | /** creates the exception with a message and a class name 68 | * @param p_msg error message 69 | * @param p_obj reference to a classobject 70 | **/ 71 | template inline runtime::runtime( const std::string& p_msg, const T& p_obj ) : 72 | std::runtime_error( p_msg + ( !tools::typeinfo::getClassName(p_obj).empty() ? " ["+tools::typeinfo::getClassName(p_obj)+"]" : "") ) 73 | { 74 | #ifdef MACHINELEARNING_LOGGER 75 | if (tools::logger::exists()) 76 | tools::logger::getInstance()->write( tools::logger::exception, _("runtime exception is thrown: ") + p_msg + ( !tools::typeinfo::getClassName(p_obj).empty() ? " ["+tools::typeinfo::getClassName(p_obj)+"]" : "")); 77 | #endif 78 | } 79 | 80 | 81 | }} 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /examples/classifier/build.py: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # LGPL License # 3 | # # 4 | # This file is part of the Machine Learning Framework. # 5 | # Copyright (c) 2010-2012, Philipp Kraus, # 6 | # This program is free software: you can redistribute it and/or modify # 7 | # it under the terms of the GNU Lesser General Public License as # 8 | # published by the Free Software Foundation, either version 3 of the # 9 | # License, or (at your option) any later version. # 10 | # # 11 | # This program is distributed in the hope that it will be useful, # 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | # GNU Lesser General Public License for more details. # 15 | # # 16 | # You should have received a copy of the GNU Lesser General Public License # 17 | # along with this program. If not, see . # 18 | ############################################################################ 19 | 20 | # -*- coding: utf-8 -*- 21 | 22 | # build script for the classifier example 23 | 24 | import os 25 | Import("*") 26 | 27 | buildlist = [] 28 | 29 | if env["withfiles"] : 30 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "classifier", "lazy"), source=defaultcpp + ["lazy.cpp"] ) ) 31 | 32 | if env["uselocallibrary"] or env["copylibrary"] : 33 | Depends(buildlist, env.LibraryCopy( os.path.join("#build", env["buildtype"], "classifier"), [] )) 34 | 35 | env.Alias( "classifier", buildlist ) -------------------------------------------------------------------------------- /examples/clustering/build.py: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # LGPL License # 3 | # # 4 | # This file is part of the Machine Learning Framework. # 5 | # Copyright (c) 2010-2012, Philipp Kraus, # 6 | # This program is free software: you can redistribute it and/or modify # 7 | # it under the terms of the GNU Lesser General Public License as # 8 | # published by the Free Software Foundation, either version 3 of the # 9 | # License, or (at your option) any later version. # 10 | # # 11 | # This program is distributed in the hope that it will be useful, # 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | # GNU Lesser General Public License for more details. # 15 | # # 16 | # You should have received a copy of the GNU Lesser General Public License # 17 | # along with this program. If not, see . # 18 | ############################################################################ 19 | 20 | # -*- coding: utf-8 -*- 21 | 22 | # build script for the clustering example 23 | 24 | import os 25 | Import("*") 26 | 27 | buildlist = [] 28 | 29 | if env["withfiles"] : 30 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "clustering", "rlvq"), source=defaultcpp+["rlvq.cpp"] ) ) 31 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "clustering", "kmeans"), source=defaultcpp+["kmeans.cpp"] ) ) 32 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "clustering", "neuralgas"), source=defaultcpp+["neuralgas.cpp"] ) ) 33 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "clustering", "patch_neuralgas"), source=defaultcpp+["patch_neuralgas.cpp"] ) ) 34 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "clustering", "relational_neuralgas"), source=defaultcpp+["relational_neuralgas.cpp"] ) ) 35 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "clustering", "spectral"), source=defaultcpp+["spectral.cpp"] ) ) 36 | 37 | if env["uselocallibrary"] or env["copylibrary"] : 38 | Depends(buildlist, env.LibraryCopy( os.path.join("#build", env["buildtype"], "clustering"), [] )) 39 | 40 | env.Alias( "clustering", buildlist ) -------------------------------------------------------------------------------- /examples/distance/build.py: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # LGPL License # 3 | # # 4 | # This file is part of the Machine Learning Framework. # 5 | # Copyright (c) 2010-2012, Philipp Kraus, # 6 | # This program is free software: you can redistribute it and/or modify # 7 | # it under the terms of the GNU Lesser General Public License as # 8 | # published by the Free Software Foundation, either version 3 of the # 9 | # License, or (at your option) any later version. # 10 | # # 11 | # This program is distributed in the hope that it will be useful, # 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | # GNU Lesser General Public License for more details. # 15 | # # 16 | # You should have received a copy of the GNU Lesser General Public License # 17 | # along with this program. If not, see . # 18 | ############################################################################ 19 | 20 | # -*- coding: utf-8 -*- 21 | 22 | # build script for the distance example 23 | 24 | import os 25 | Import("*") 26 | 27 | buildlist = [] 28 | 29 | if env["withfiles"] : 30 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "distance", "ncd"), source=defaultcpp + ["ncd.cpp"] ) ) 31 | 32 | if env["uselocallibrary"] or env["copylibrary"] : 33 | Depends(buildlist, env.LibraryCopy( os.path.join("#build", env["buildtype"], "distance"), [] )) 34 | 35 | env.Alias( "distance", buildlist ) -------------------------------------------------------------------------------- /examples/distance/ncd.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | 32 | namespace po = boost::program_options; 33 | using namespace boost::numeric; 34 | using namespace machinelearning; 35 | 36 | 37 | /** main program 38 | * @param p_argc number of arguments 39 | * @param p_argv arguments 40 | **/ 41 | int main(int p_argc, char* p_argv[]) 42 | { 43 | #ifdef MACHINELEARNING_MULTILANGUAGE 44 | tools::language::bindings::bind(); 45 | #endif 46 | 47 | // default values 48 | std::string l_compress; 49 | std::string l_algorithm; 50 | std::string l_matrix; 51 | 52 | // create CML options with description 53 | po::options_description l_description("allowed options"); 54 | l_description.add_options() 55 | ("help", "produce help message") 56 | ("outfile", po::value(), "output HDF5 file") 57 | ("sources", po::value< std::vector >()->multitoken(), "list of text files or directories with text files (all files in the directory will be read and subdirectories will be ignored)") 58 | ("compress", po::value(&l_compress)->default_value("default"), "compression level (allowed values are: default [default], bestspeed or bestcompression)") 59 | ("algorithm", po::value(&l_algorithm)->default_value("gzip"), "compression algorithm (allowed values are: gzip [default], bzip)") 60 | ("matrix", po::value(&l_matrix)->default_value("symmetric"), "structure of the matrix (allowed values are: symmetric [default] or unsymmetric") 61 | ; 62 | 63 | po::variables_map l_map; 64 | po::positional_options_description l_input; 65 | po::store(po::command_line_parser(p_argc, p_argv).options(l_description).positional(l_input).run(), l_map); 66 | po::notify(l_map); 67 | 68 | if (l_map.count("help")) { 69 | std::cout << l_description << std::endl; 70 | return EXIT_SUCCESS; 71 | } 72 | 73 | if (!l_map.count("sources")) { 74 | std::cerr << "[--sources] must be set" << std::endl; 75 | return EXIT_FAILURE; 76 | } 77 | 78 | 79 | 80 | // create ncd object 81 | distances::ncd l_ncd( (l_algorithm == "gzip") ? distances::ncd::gzip : distances::ncd::bzip2 ); 82 | if (l_compress == "bestspeed") 83 | l_ncd.setCompressionLevel( distances::ncd::bestspeed ); 84 | if (l_compress == "bestcompression") 85 | l_ncd.setCompressionLevel( distances::ncd::bestcompression ); 86 | 87 | 88 | // create the distance matrix and use the each element of the vector as a filename 89 | ublas::matrix l_distancematrix; 90 | if (l_matrix == "unsymmetric") 91 | l_distancematrix = l_ncd.unsymmetric( l_map["sources"].as< std::vector >(), true); 92 | else 93 | l_distancematrix = l_ncd.symmetric( l_map["sources"].as< std::vector >(), true); 94 | 95 | 96 | if (!l_map.count("outfile")) 97 | std::cout << l_distancematrix << std::endl; 98 | else { 99 | // create hdf file and write data 100 | tools::files::hdf file(l_map["outfile"].as(), true); 101 | file.writeBlasMatrix( "/ncd", l_distancematrix, tools::files::hdf::NATIVE_DOUBLE ); 102 | std::cout << "structure of the output file" << std::endl; 103 | std::cout << "/ncd" << "\t\t" << "distance matrix" << std::endl; 104 | } 105 | 106 | return EXIT_SUCCESS; 107 | } 108 | -------------------------------------------------------------------------------- /examples/geneticalgorithm/build.py: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # LGPL License # 3 | # # 4 | # This file is part of the Machine Learning Framework. # 5 | # Copyright (c) 2010-2012, Philipp Kraus, # 6 | # This program is free software: you can redistribute it and/or modify # 7 | # it under the terms of the GNU Lesser General Public License as # 8 | # published by the Free Software Foundation, either version 3 of the # 9 | # License, or (at your option) any later version. # 10 | # # 11 | # This program is distributed in the hope that it will be useful, # 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | # GNU Lesser General Public License for more details. # 15 | # # 16 | # You should have received a copy of the GNU Lesser General Public License # 17 | # along with this program. If not, see . # 18 | ############################################################################ 19 | 20 | # -*- coding: utf-8 -*- 21 | 22 | 23 | # build script for the genetic algorithm example 24 | 25 | import os 26 | Import("*") 27 | 28 | buildlist = [] 29 | 30 | if env["withfiles"] : 31 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "geneticalgorithm", "knapsack"), source=defaultcpp + ["knapsack.cpp"] ) ) 32 | 33 | if env["uselocallibrary"] or env["copylibrary"] : 34 | Depends(buildlist, env.LibraryCopy( os.path.join("#build", env["buildtype"], "geneticalgorithm"), [] )) 35 | 36 | env.Alias( "ga", buildlist ) -------------------------------------------------------------------------------- /examples/java/clustering/build.py: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # LGPL License # 3 | # # 4 | # This file is part of the Machine Learning Framework. # 5 | # Copyright (c) 2010-2012, Philipp Kraus, # 6 | # This program is free software: you can redistribute it and/or modify # 7 | # it under the terms of the GNU Lesser General Public License as # 8 | # published by the Free Software Foundation, either version 3 of the # 9 | # License, or (at your option) any later version. # 10 | # # 11 | # This program is distributed in the hope that it will be useful, # 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | # GNU Lesser General Public License for more details. # 15 | # # 16 | # You should have received a copy of the GNU Lesser General Public License # 17 | # along with this program. If not, see . # 18 | ############################################################################ 19 | 20 | # -*- coding: utf-8 -*- 21 | 22 | 23 | # build script for the Java clustering 24 | 25 | import os 26 | Import("*") 27 | 28 | 29 | env.Alias( "javaclustering", 30 | env.Java( os.path.join("#build", env["buildtype"], "java", "clustering"), Dir("."), JAVACLASSPATH = [os.path.join("build", env["buildtype"], "machinelearning.jar")] ) 31 | ) -------------------------------------------------------------------------------- /examples/java/clustering/rng.java: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | import machinelearning.clustering.nonsupervised.*; 26 | import java.util.Random; 27 | 28 | 29 | /** java testprogram for using relational neural gas **/ 30 | public class rng { 31 | 32 | 33 | /** main method 34 | * @param p_args input arguments 35 | **/ 36 | public static void main(String[] p_args) 37 | { 38 | // generates random datapoints 39 | Random l_rand = new Random(); 40 | 41 | Double[][] l_data = new Double[8][8]; 42 | for(int i=0; i < l_data.length; i++) { 43 | for (int j=0; j < l_data[i].length; j++) { 44 | if (i==j) 45 | l_data[i][j] = new Double(0); 46 | else 47 | l_data[i][j] = l_rand.nextDouble(); 48 | System.out.print(l_data[i][j] + "\t"); 49 | } 50 | System.out.println(""); 51 | } 52 | 53 | // create RNG object and train data 54 | RelationalNeuralGas l_rng = new RelationalNeuralGas(4, l_data.length); 55 | l_rng.train(l_data, 10); 56 | 57 | // show RNG prototypes 58 | Double[][] l_proto = l_rng.getPrototypes(); 59 | System.out.println("\nprototypes:"); 60 | if (l_proto == null) 61 | System.out.println("no data is returned"); 62 | else 63 | for(int i=0; i < l_proto.length; i++) { 64 | for(int j=0; j < l_proto[i].length; ++j) 65 | System.out.print(l_proto[i][j] + "\t"); 66 | System.out.println(""); 67 | } 68 | 69 | 70 | // delete manually the RNG object (call destructor), should be 71 | // do the finalizer, but there is no guarantee. 72 | l_rng.delete(); 73 | 74 | 75 | // set objects to null for gc removing 76 | l_rng = null; 77 | l_data = null; 78 | l_proto = null; 79 | l_rand = null; 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /examples/java/clustering/spectral.java: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | import machinelearning.clustering.nonsupervised.*; 26 | import java.util.Random; 27 | 28 | 29 | /** java testprogram for using Spectral Clustering **/ 30 | public class spectral { 31 | 32 | 33 | /** main method 34 | * @param p_args input arguments 35 | **/ 36 | public static void main(String[] p_args) 37 | { 38 | 39 | // generates random datapoints 40 | Random l_rand = new Random(); 41 | 42 | Double[][] l_data = new Double[8][8]; 43 | for(int i=0; i < l_data.length; i++) { 44 | for (int j=0; j < l_data[i].length; j++) { 45 | if (i==j) 46 | l_data[i][j] = new Double(0); 47 | else 48 | l_data[i][j] = l_rand.nextDouble(); 49 | 50 | System.out.print(l_data[i][j] + "\t"); 51 | } 52 | System.out.println(""); 53 | } 54 | 55 | // create SpectralClustering object and train data 56 | SpectralClustering l_spectral = new SpectralClustering(3); 57 | l_spectral.train(l_data, 10); 58 | 59 | // show SpectralClustering prototypes 60 | Double[][] l_proto = l_spectral.getPrototypes(); 61 | System.out.println("\nprototypes:"); 62 | if (l_proto == null) 63 | System.out.println("no data is returned"); 64 | else 65 | for(int i=0; i < l_proto.length; i++) { 66 | for(int j=0; j < l_proto[i].length; ++j) 67 | System.out.print(l_proto[i][j] + "\t"); 68 | System.out.println(""); 69 | } 70 | 71 | 72 | // delete manually the SpectralClustering object (call destructor), should be 73 | // do the finalizer, but there is no guarantee. 74 | l_spectral.delete(); 75 | 76 | 77 | // set objects to null for gc removing 78 | l_spectral = null; 79 | l_data = null; 80 | l_proto = null; 81 | l_rand = null; 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /examples/java/reducing/build.py: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # LGPL License # 3 | # # 4 | # This file is part of the Machine Learning Framework. # 5 | # Copyright (c) 2010-2012, Philipp Kraus, # 6 | # This program is free software: you can redistribute it and/or modify # 7 | # it under the terms of the GNU Lesser General Public License as # 8 | # published by the Free Software Foundation, either version 3 of the # 9 | # License, or (at your option) any later version. # 10 | # # 11 | # This program is distributed in the hope that it will be useful, # 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | # GNU Lesser General Public License for more details. # 15 | # # 16 | # You should have received a copy of the GNU Lesser General Public License # 17 | # along with this program. If not, see . # 18 | ############################################################################ 19 | 20 | # -*- coding: utf-8 -*- 21 | 22 | 23 | # build script for the Java reducing 24 | 25 | import os 26 | Import("*") 27 | 28 | 29 | env.Alias( "javareduce", 30 | env.Java( os.path.join("#build", env["buildtype"], "java", "reducing"), Dir("."), JAVACLASSPATH = [os.path.join("build", env["buildtype"], "machinelearning.jar")] ) 31 | ) -------------------------------------------------------------------------------- /examples/java/reducing/mds.java: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | import machinelearning.dimensionreduce.nonsupervised.*; 26 | import java.util.Random; 27 | 28 | 29 | /** java testprogram for using MDS **/ 30 | public class mds { 31 | 32 | 33 | /** main method 34 | * @param p_args input arguments 35 | **/ 36 | public static void main(String[] p_args) 37 | { 38 | // generates random datapoints 39 | Random l_rand = new Random(); 40 | 41 | Double[][] l_data = new Double[8][8]; 42 | for(int i=0; i < l_data.length; i++) { 43 | for (int j=0; j < l_data[i].length; j++) { 44 | if (i==j) 45 | l_data[i][j] = new Double(0); 46 | else 47 | l_data[i][j] = l_rand.nextDouble(); 48 | System.out.print(l_data[i][j] + "\t"); 49 | } 50 | System.out.println(""); 51 | } 52 | 53 | // create MDS object 54 | MDS l_mds = new MDS(3, MDS.project.metric); 55 | 56 | 57 | // maps the random data points 58 | Double[][] l_result = l_mds.map(l_data); 59 | System.out.println("\nproject data:"); 60 | if (l_result == null) 61 | System.out.println("no data is returned"); 62 | else 63 | for(int i=0; i < l_result.length; i++) { 64 | for(int j=0; j < l_result[i].length; ++j) 65 | System.out.print(l_result[i][j] + "\t"); 66 | System.out.println(""); 67 | } 68 | 69 | 70 | // delete manually the PCA object (call destructor), should be 71 | // do the finalizer, but there is no guarantee. 72 | l_mds.delete(); 73 | 74 | // set objects to null for gc removing 75 | l_mds = null; 76 | l_result = null; 77 | l_data = null; 78 | l_rand = null; 79 | } 80 | 81 | } -------------------------------------------------------------------------------- /examples/java/reducing/pca.java: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | import machinelearning.dimensionreduce.nonsupervised.*; 26 | import java.util.Random; 27 | 28 | 29 | /** java testprogram for using PCA **/ 30 | public class pca { 31 | 32 | 33 | /** main method 34 | * @param p_args input arguments 35 | **/ 36 | public static void main(String[] p_args) 37 | { 38 | // generates random datapoints 39 | Random l_rand = new Random(); 40 | 41 | Double[][] l_data = new Double[15][8]; 42 | for(int i=0; i < l_data.length; i++) { 43 | for (int j=0; j < l_data[i].length; j++) { 44 | l_data[i][j] = l_rand.nextDouble() * 500; 45 | System.out.print(l_data[i][j] + "\t"); 46 | } 47 | System.out.println(""); 48 | } 49 | 50 | // create PCA object 51 | PCA l_pca = new PCA(3); 52 | 53 | 54 | // maps the random data points 55 | Double[][] l_result = l_pca.map(l_data); 56 | System.out.println("\nproject data:"); 57 | if (l_result == null) 58 | System.out.println("no data is returned"); 59 | else 60 | for(int i=0; i < l_result.length; i++) { 61 | for(int j=0; j < l_result[i].length; ++j) 62 | System.out.print(l_result[i][j] + "\t"); 63 | System.out.println(""); 64 | } 65 | 66 | // show PCA eigenvectors 67 | Double[][] l_eig = l_pca.getProject(); 68 | System.out.println("\neigenvectors:"); 69 | if (l_eig == null) 70 | System.out.println("no data is returned"); 71 | else 72 | for(int i=0; i < l_eig.length; i++) { 73 | for(int j=0; j < l_eig[i].length; ++j) 74 | System.out.print(l_eig[i][j] + "\t"); 75 | System.out.println(""); 76 | } 77 | 78 | 79 | // delete manually the PCA object (call destructor), should be 80 | // do the finalizer, but there is no guarantee. 81 | l_pca.delete(); 82 | 83 | 84 | // set objects to null for gc removing 85 | l_pca = null; 86 | l_result = null; 87 | l_data = null; 88 | l_eig = null; 89 | l_rand = null; 90 | } 91 | 92 | } -------------------------------------------------------------------------------- /examples/java/tools/build.py: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # LGPL License # 3 | # # 4 | # This file is part of the Machine Learning Framework. # 5 | # Copyright (c) 2010-2012, Philipp Kraus, # 6 | # This program is free software: you can redistribute it and/or modify # 7 | # it under the terms of the GNU Lesser General Public License as # 8 | # published by the Free Software Foundation, either version 3 of the # 9 | # License, or (at your option) any later version. # 10 | # # 11 | # This program is distributed in the hope that it will be useful, # 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | # GNU Lesser General Public License for more details. # 15 | # # 16 | # You should have received a copy of the GNU Lesser General Public License # 17 | # along with this program. If not, see . # 18 | ############################################################################ 19 | 20 | # -*- coding: utf-8 -*- 21 | 22 | 23 | # build script for the Java tools 24 | 25 | import os 26 | Import("*") 27 | 28 | 29 | env.Alias( "javatools", 30 | env.Java( os.path.join("#build", env["buildtype"], "java", "tools"), Dir("."), JAVACLASSPATH = [os.path.join("build", env["buildtype"], "machinelearning.jar")] ) 31 | ) -------------------------------------------------------------------------------- /examples/java/tools/eigen.java: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | import machinelearning.tools.*; 26 | import java.util.*; 27 | 28 | 29 | /** java testprogram for using eigenvalue algorithms **/ 30 | public class eigen { 31 | 32 | 33 | /** main method 34 | * @param p_args input arguments 35 | **/ 36 | public static void main(String[] p_args) 37 | { 38 | // generates random datapoints 39 | java.util.Random l_rand = new java.util.Random(); 40 | 41 | Double[][] l_data = new Double[6][6]; 42 | for(int i=0; i < l_data.length; i++) { 43 | for (int j=0; j < l_data[i].length; j++) { 44 | l_data[i][j] = l_rand.nextDouble() * 500; 45 | System.out.print(l_data[i][j] + "\t"); 46 | } 47 | System.out.println(""); 48 | } 49 | 50 | 51 | // create eigenvectors / -values 52 | ArrayList l_eigenvals = new ArrayList(); 53 | ArrayList l_eigenvecs = new ArrayList(); 54 | 55 | Lapack.eigen(l_data, l_eigenvals, l_eigenvecs); 56 | 57 | 58 | 59 | System.out.println("\neigenvalues:"); 60 | for(int i=0; i < l_eigenvals.size(); i++) 61 | System.out.print(l_eigenvals.get(i) + "\t"); 62 | System.out.println(""); 63 | l_eigenvals = null; 64 | 65 | 66 | 67 | System.out.println("\neigenvectors:\n"); 68 | for(int j=0; j < l_eigenvecs.size(); j++) { 69 | System.out.print( (j+1) + " eigenvector:\t"); 70 | for(int i=0; i < l_eigenvecs.get(j).length; i++) 71 | System.out.print(l_eigenvecs.get(j)[i] + "\t"); 72 | System.out.println("\n"); 73 | } 74 | l_eigenvecs = null; 75 | 76 | 77 | // get the largest eigenvector with perron-frobenius 78 | Double[] l_perron = Lapack.perronFrobenius( l_data, 2*l_data.length ); 79 | 80 | System.out.println("\nlargest eigenvector with perron-frobenius-theorem:"); 81 | for(int i=0; i < l_perron.length; i++) 82 | System.out.print(l_perron[i] + "\t"); 83 | System.out.println(""); 84 | l_perron = null; 85 | 86 | l_data = null; 87 | l_rand = null; 88 | } 89 | 90 | } -------------------------------------------------------------------------------- /examples/java/tools/random.java: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | 26 | /** java testprogram for random algorithms **/ 27 | public class random { 28 | 29 | 30 | /** main method 31 | * @param p_args input arguments 32 | **/ 33 | public static void main(String[] p_args) 34 | { 35 | if (p_args.length < 2) { 36 | System.out.println("first parameter type of distribution (uniform, bernoulli, cauchy, gamma, poisson, exponential, normal, student, weibull, rayleigh, chisquared, pareto, triangular, beta)"); 37 | System.out.println("second value number of elements"); 38 | System.exit(0); 39 | } 40 | 41 | int l_num = Integer.parseInt(p_args[1]); 42 | if (l_num < 1) { 43 | System.out.println("number of elements must be greater than zero"); 44 | System.exit(-1); 45 | } 46 | 47 | 48 | // create random object 49 | machinelearning.tools.Random l_random = new machinelearning.tools.Random(); 50 | 51 | for(int i=0; i < l_num; i++) { 52 | 53 | if (p_args[0].toLowerCase().equals("uniform")) 54 | System.out.println( l_random.get(machinelearning.tools.Random.distribution.uniform) ); 55 | 56 | if (p_args[0].toLowerCase().equals("bernoulli")) 57 | System.out.println( l_random.get(machinelearning.tools.Random.distribution.bernoulli) ); 58 | 59 | if (p_args[0].toLowerCase().equals("cauchy")) 60 | System.out.println( l_random.get(machinelearning.tools.Random.distribution.cauchy) ); 61 | 62 | if (p_args[0].toLowerCase().equals("gamma")) 63 | System.out.println( l_random.get(machinelearning.tools.Random.distribution.gamma) ); 64 | 65 | if (p_args[0].toLowerCase().equals("poisson")) 66 | System.out.println( l_random.get(machinelearning.tools.Random.distribution.poisson) ); 67 | 68 | if (p_args[0].toLowerCase().equals("exponential")) 69 | System.out.println( l_random.get(machinelearning.tools.Random.distribution.exponential) ); 70 | 71 | if (p_args[0].toLowerCase().equals("normal")) 72 | System.out.println( l_random.get(machinelearning.tools.Random.distribution.normal) ); 73 | 74 | if (p_args[0].toLowerCase().equals("student")) 75 | System.out.println( l_random.get(machinelearning.tools.Random.distribution.student) ); 76 | 77 | if (p_args[0].toLowerCase().equals("weibull")) 78 | System.out.println( l_random.get(machinelearning.tools.Random.distribution.weibull) ); 79 | 80 | if (p_args[0].toLowerCase().equals("rayleigh")) 81 | System.out.println( l_random.get(machinelearning.tools.Random.distribution.rayleigh) ); 82 | 83 | if (p_args[0].toLowerCase().equals("chisquared")) 84 | System.out.println( l_random.get(machinelearning.tools.Random.distribution.chisquared) ); 85 | 86 | if (p_args[0].toLowerCase().equals("pareto")) 87 | System.out.println( l_random.get(machinelearning.tools.Random.distribution.pareto) ); 88 | 89 | if (p_args[0].toLowerCase().equals("triangular")) 90 | System.out.println( l_random.get(machinelearning.tools.Random.distribution.triangular) ); 91 | 92 | if (p_args[0].toLowerCase().equals("beta")) 93 | System.out.println( l_random.get(machinelearning.tools.Random.distribution.beta) ); 94 | } 95 | 96 | 97 | l_random.delete(); 98 | l_random = null; 99 | } 100 | 101 | } -------------------------------------------------------------------------------- /examples/java/tools/svd.java: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | import machinelearning.tools.*; 26 | import java.util.*; 27 | 28 | 29 | /** java testprogram for using svd algorithms **/ 30 | public class svd { 31 | 32 | 33 | /** main method 34 | * @param p_args input arguments 35 | **/ 36 | public static void main(String[] p_args) 37 | { 38 | // generates random datapoints 39 | java.util.Random l_rand = new java.util.Random(); 40 | 41 | Double[][] l_data = new Double[4][8]; 42 | for(int i=0; i < l_data.length; i++) { 43 | for (int j=0; j < l_data[i].length; j++) { 44 | l_data[i][j] = l_rand.nextDouble() * 500; 45 | System.out.print(l_data[i][j] + "\t"); 46 | } 47 | System.out.println(""); 48 | } 49 | 50 | 51 | // create SVD 52 | ArrayList l_svdvals = new ArrayList(); 53 | ArrayList l_svdvecs1 = new ArrayList(); 54 | ArrayList l_svdvecs2 = new ArrayList(); 55 | 56 | Lapack.svd(l_data, l_svdvals, l_svdvecs1, l_svdvecs2); 57 | 58 | 59 | 60 | System.out.println("\nsvd values:"); 61 | for(int i=0; i < l_svdvals.size(); i++) 62 | System.out.print(l_svdvals.get(i) + "\t"); 63 | System.out.println(""); 64 | l_svdvals = null; 65 | 66 | 67 | 68 | System.out.println("\nsvd vectors 1:\n"); 69 | for(int j=0; j < l_svdvecs1.size(); j++) { 70 | System.out.print( (j+1) + " svd vector:\t"); 71 | for(int i=0; i < l_svdvecs1.get(j).length; i++) 72 | System.out.print(l_svdvecs1.get(j)[i] + "\t"); 73 | System.out.println("\n"); 74 | } 75 | l_svdvecs1 = null; 76 | 77 | 78 | 79 | System.out.println("\nsvd vectors 2:\n"); 80 | for(int j=0; j < l_svdvecs2.size(); j++) { 81 | System.out.print( (j+1) + " svd vector:\t"); 82 | for(int i=0; i < l_svdvecs2.get(j).length; i++) 83 | System.out.print(l_svdvecs2.get(j)[i] + "\t"); 84 | System.out.println("\n"); 85 | } 86 | l_svdvecs2 = null; 87 | 88 | 89 | l_data = null; 90 | l_rand = null; 91 | } 92 | 93 | } -------------------------------------------------------------------------------- /examples/other/build.py: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # LGPL License # 3 | # # 4 | # This file is part of the Machine Learning Framework. # 5 | # Copyright (c) 2010-2012, Philipp Kraus, # 6 | # This program is free software: you can redistribute it and/or modify # 7 | # it under the terms of the GNU Lesser General Public License as # 8 | # published by the Free Software Foundation, either version 3 of the # 9 | # License, or (at your option) any later version. # 10 | # # 11 | # This program is distributed in the hope that it will be useful, # 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | # GNU Lesser General Public License for more details. # 15 | # # 16 | # You should have received a copy of the GNU Lesser General Public License # 17 | # along with this program. If not, see . # 18 | ############################################################################ 19 | 20 | # -*- coding: utf-8 -*- 21 | 22 | # build script for the other example 23 | 24 | import os 25 | Import("*") 26 | 27 | buildlist = [] 28 | 29 | if env["withfiles"] : 30 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "other", "mds_file"), source=defaultcpp+["mds_file.cpp"] ) ) 31 | 32 | if env["withsources"] : 33 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "other", "mds_nntp"), source=defaultcpp+["mds_nntp.cpp"] ) ) 34 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "other", "mds_wikipedia"), source=defaultcpp+["mds_wikipedia.cpp"] ) ) 35 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "other", "mds_twitter"), source=defaultcpp+["mds_twitter.cpp"] ) ) 36 | 37 | if env["uselocallibrary"] or env["copylibrary"] : 38 | Depends(buildlist, env.LibraryCopy( os.path.join("#build", env["buildtype"], "other"), [] )) 39 | 40 | env.Alias( "other", buildlist ) -------------------------------------------------------------------------------- /examples/other/matlab/plotfiles.m: -------------------------------------------------------------------------------- 1 | % ############################################################################ 2 | % # LGPL License # 3 | % # # 4 | % # This file is part of the Machine Learning Framework. # 5 | % # Copyright (c) 2010-2012, Philipp Kraus, # 6 | % # This program is free software: you can redistribute it and/or modify # 7 | % # it under the terms of the GNU Lesser General Public License as # 8 | % # published by the Free Software Foundation, either version 3 of the # 9 | % # License, or (at your option) any later version. # 10 | % # # 11 | % # This program is distributed in the hope that it will be useful, # 12 | % # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | % # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | % # GNU Lesser General Public License for more details. # 15 | % # # 16 | % # You should have received a copy of the GNU Lesser General Public License # 17 | % # along with this program. If not, see . # 18 | % ############################################################################ 19 | 20 | 21 | % plots a HDF file that is created by the "mds_file" example 22 | % @pcfile HDF file 23 | function plotfiles( pcfile ) 24 | lmarkersize = 5; 25 | 26 | % get data 27 | data = hdf5read( pcfile, '/project'); 28 | if (size(data,2) ~= 2) && (size(data,2) ~= 3) 29 | error('plot only with 2D or 3D'); 30 | end 31 | label = hdf5read( pcfile, '/files'); 32 | datatxt=cell(1,size(data,1)); 33 | for i=1:numel(datatxt) 34 | datatxt{i} = char(label(i).data); 35 | end 36 | 37 | % create plot 38 | figure; 39 | grid on; 40 | hold on; 41 | set(datacursormode(gcf), 'DisplayStyle','datatip', 'SnapToDataVertex','off','Enable','on', 'UpdateFcn',{@showlabel,datatxt}); 42 | 43 | if size(data,2) == 2 44 | plot(data(:,1), data(:,2), '.', 'MarkerSize', lmarkersize); 45 | elseif size(data,2) == 3 46 | plot3(data(:,1), data(:,2), data(:,3), '.', 'MarkerSize', lmarkersize); 47 | end 48 | 49 | set(gca,'fontsize',1); 50 | 51 | if size(data,2) == 3 52 | view([-45 45]); 53 | end 54 | 55 | 56 | 57 | 58 | % label function for create "mouse over effect" 59 | % @param varargin input data 60 | % @return label text 61 | function txt = showlabel(varargin) 62 | label = varargin{3}; 63 | txt = label{get(varargin{2}, 'DataIndex')}; 64 | -------------------------------------------------------------------------------- /examples/other/matlab/plotnntp.m: -------------------------------------------------------------------------------- 1 | % ############################################################################ 2 | % # LGPL License # 3 | % # # 4 | % # This file is part of the Machine Learning Framework. # 5 | % # Copyright (c) 2010-2012, Philipp Kraus, # 6 | % # This program is free software: you can redistribute it and/or modify # 7 | % # it under the terms of the GNU Lesser General Public License as # 8 | % # published by the Free Software Foundation, either version 3 of the # 9 | % # License, or (at your option) any later version. # 10 | % # # 11 | % # This program is distributed in the hope that it will be useful, # 12 | % # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | % # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | % # GNU Lesser General Public License for more details. # 15 | % # # 16 | % # You should have received a copy of the GNU Lesser General Public License # 17 | % # along with this program. If not, see . # 18 | % ############################################################################ 19 | 20 | 21 | % plots a HDF file that is created by the "mds_nntp" example 22 | % @param pcfile HDF file 23 | function plotnntp( pcfile ) 24 | lmarkersize=5; 25 | 26 | % create colors 27 | textlabel = hdf5read( pcfile, '/uniquegroup'); 28 | label = cell(size(textlabel,1),1); 29 | labelcolor = cell(size(textlabel,1),1); 30 | 31 | col = jet(size(textlabel,1)); 32 | %col = hsv(size(textlabel,1)); 33 | for i=1:size(labelcolor,1) 34 | label{i} = char(textlabel(i).data); 35 | labelcolor{i} = col(i, :); 36 | end 37 | 38 | % we create for each label group a data matrix 39 | data = hdf5read( pcfile, '/project'); 40 | if (size(data,2) ~= 2) && (size(data,2) ~= 3) 41 | error('plot only with 2D or 3D'); 42 | end 43 | 44 | datalabel = hdf5read( pcfile, '/group'); 45 | 46 | datacell = cell(size(label,1),1); 47 | maxcount = zeros(size(label,1),1); 48 | 49 | for i=1:size(textlabel,1) 50 | datacell{i} = zeros( size(data,1), size(data,2) ); 51 | end 52 | 53 | for i=1:size(data,1) 54 | pos = strmatch(char(datalabel(i).data), label, 'exact'); 55 | point = datacell{pos}; 56 | 57 | point(maxcount(pos)+1,:) = data(i,:); 58 | 59 | datacell{pos} = point; 60 | maxcount(pos) = maxcount(pos) + 1; 61 | end 62 | 63 | % remove non-existing datasets 64 | emptycell = maxcount == 0; 65 | for i=1:numel(emptycell) 66 | if emptycell(i) 67 | datacell(i) = []; 68 | labelcolor(i) = []; 69 | label(i) = []; 70 | maxcount(i) = []; 71 | end 72 | end 73 | 74 | % create plot 75 | figure; 76 | grid on; 77 | hold on; 78 | 79 | phandle = zeros(numel(datacell),1); 80 | for i=1:numel(datacell) 81 | 82 | point = datacell{i}; 83 | point = point(1:maxcount(i), :); 84 | 85 | if size(point,2) == 2 86 | phandle(i) = plot(point(:,1), point(:,2), '.', 'Color', labelcolor{i}, 'DisplayName', label{i}, MarkerSize', lmarkersize); 87 | elseif size(point,2) == 3 88 | phandle(i) = plot3(point(:,1), point(:,2), point(:,3), '.', 'Color', labelcolor{i}, 'DisplayName', label{i}, 'MarkerSize', lmarkersize); 89 | end 90 | end 91 | set(gca,'fontsize',8); 92 | legend(phandle); 93 | 94 | if size(datacell{1},2) == 3 95 | view([-45 45]); 96 | end -------------------------------------------------------------------------------- /examples/other/matlab/plottwitter.m: -------------------------------------------------------------------------------- 1 | % ############################################################################ 2 | % # LGPL License # 3 | % # # 4 | % # This file is part of the Machine Learning Framework. # 5 | % # Copyright (c) 2010-2012, Philipp Kraus, # 6 | % # This program is free software: you can redistribute it and/or modify # 7 | % # it under the terms of the GNU Lesser General Public License as # 8 | % # published by the Free Software Foundation, either version 3 of the # 9 | % # License, or (at your option) any later version. # 10 | % # # 11 | % # This program is distributed in the hope that it will be useful, # 12 | % # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | % # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | % # GNU Lesser General Public License for more details. # 15 | % # # 16 | % # You should have received a copy of the GNU Lesser General Public License # 17 | % # along with this program. If not, see . # 18 | % ############################################################################ 19 | 20 | 21 | % plots a HDF file that is created by the "mds_twitter" example 22 | % @param pcfile HDF file 23 | function plottwitter( pcfile, pnnodes ) 24 | lmarkersize=5; 25 | 26 | % get data (if only one file is used) 27 | if nargin < 2 || isempty(pnnodes) 28 | textlabel = hdf5read( pcfile, '/uniquegroup'); 29 | data = hdf5read( pcfile, '/project'); 30 | datalabel = hdf5read( pcfile, '/label'); 31 | else 32 | %if files of the cluster nodes are used 33 | loaddata = cell(pnnodes,1); 34 | loadlabel = cell(pnnodes,1); 35 | for i=1:pnnodes 36 | loaddata{i} = hdf5read( strcat('node', num2str(i-1), '_', pcfile), '/project'); 37 | loadlabel{i} = hdf5read( strcat('node', num2str(i-1), '_', pcfile), '/label'); 38 | end 39 | 40 | data = cell2mat(loaddata); 41 | datalabel = cell2mat(loadlabel); 42 | textlabel = hdf5read( strcat('node0_', pcfile), '/uniquegroup'); 43 | end 44 | 45 | 46 | 47 | 48 | % we create for each label group a data matrix 49 | if (size(data,2) ~= 2) && (size(data,2) ~= 3) 50 | error('plot only with 2D or 3D'); 51 | end 52 | 53 | label = cell(size(textlabel,1),1); 54 | labelcolor = cell(size(textlabel,1),1); 55 | 56 | col = jet(size(textlabel,1)); 57 | %col = hsv(size(textlabel,1)); 58 | for i=1:size(labelcolor,1) 59 | label{i} = char(textlabel(i).data); 60 | labelcolor{i} = col(i, :); 61 | end 62 | 63 | datacell = cell(size(label,1),1); 64 | maxcount = zeros(size(label,1),1); 65 | 66 | for i=1:size(textlabel,1) 67 | datacell{i} = zeros( size(data,1), size(data,2) ); 68 | end 69 | 70 | for i=1:size(data,1) 71 | pos = strmatch(char(datalabel(i).data), label, 'exact'); 72 | point = datacell{pos}; 73 | 74 | point(maxcount(pos)+1,:) = data(i,:); 75 | 76 | datacell{pos} = point; 77 | maxcount(pos) = maxcount(pos) + 1; 78 | end 79 | 80 | 81 | % remove non-existing datasets 82 | emptycell = maxcount == 0; 83 | for i=1:numel(emptycell) 84 | if emptycell(i) 85 | datacell(i) = []; 86 | labelcolor(i) = []; 87 | label(i) = []; 88 | maxcount(i) = []; 89 | end 90 | end 91 | 92 | % create plot 93 | figure; 94 | grid on; 95 | hold on; 96 | 97 | phandle = zeros(numel(datacell),1); 98 | for i=1:numel(datacell) 99 | 100 | point = datacell{i}; 101 | point = point(1:maxcount(i), :); 102 | 103 | if size(point,2) == 2 104 | phandle(i) = plot(point(:,1), point(:,2), '.', 'Color', labelcolor{i}, 'DisplayName', label{i}, 'MarkerSize', lmarkersize); 105 | elseif size(point,2) == 3 106 | phandle(i) = plot3(point(:,1), point(:,2), point(:,3), '.', 'Color', labelcolor{i}, 'DisplayName', label{i}, 'MarkerSize', lmarkersize); 107 | end 108 | end 109 | set(gca,'fontsize',8); 110 | 111 | legend(phandle); 112 | 113 | if size(datacell{1},2) == 3 114 | view([-45 45]); 115 | end 116 | -------------------------------------------------------------------------------- /examples/other/matlab/plotwiki.m: -------------------------------------------------------------------------------- 1 | % ############################################################################ 2 | % # LGPL License # 3 | % # # 4 | % # This file is part of the Machine Learning Framework. # 5 | % # Copyright (c) 2010-2012, Philipp Kraus, # 6 | % # This program is free software: you can redistribute it and/or modify # 7 | % # it under the terms of the GNU Lesser General Public License as # 8 | % # published by the Free Software Foundation, either version 3 of the # 9 | % # License, or (at your option) any later version. # 10 | % # # 11 | % # This program is distributed in the hope that it will be useful, # 12 | % # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | % # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | % # GNU Lesser General Public License for more details. # 15 | % # # 16 | % # You should have received a copy of the GNU Lesser General Public License # 17 | % # along with this program. If not, see . # 18 | % ############################################################################ 19 | 20 | 21 | % plots a HDF file that is created by the "mds_wikipedia" example 22 | % @param pcfile HDF file 23 | % @param pnnodes number of nodes 24 | function plotwiki( pcfile, pnnodes ) 25 | lmarkersize=5; 26 | 27 | % get data (if only one file is used) 28 | if nargin < 2 || isempty(pnnodes) 29 | data = hdf5read( pcfile, '/project'); 30 | label = hdf5read( pcfile, '/label'); 31 | else 32 | %if files of the cluster nodes are used 33 | loaddata = cell(pnnodes,1); 34 | loadlabel = cell(pnnodes,1); 35 | for i=1:pnnodes 36 | loaddata{i} = hdf5read( strcat('node', num2str(i-1), '_', pcfile), '/project'); 37 | loadlabel{i} = hdf5read( strcat('node', num2str(i-1), '_', pcfile), '/label'); 38 | end 39 | 40 | data = cell2mat(loaddata); 41 | label = cell2mat(loadlabel); 42 | end 43 | 44 | 45 | if (size(data,2) ~= 2) && (size(data,2) ~= 3) 46 | error('plot only with 2D or 3D'); 47 | end 48 | datatxt=cell(size(label,1), 1); 49 | for i=1:size(datatxt,1) 50 | datatxt{i} = char(label(i).data); 51 | end 52 | 53 | 54 | 55 | % create plot 56 | figure; 57 | grid on; 58 | hold on; 59 | set(datacursormode(gcf), 'DisplayStyle','datatip', 'SnapToDataVertex','off','Enable','on', 'UpdateFcn',{@showlabel,datatxt}); 60 | 61 | 62 | if size(data,2) == 2 63 | plot(data(:,1), data(:,2), '.', 'MarkerSize', lmarkersize); 64 | elseif size(data,2) == 3 65 | plot3(data(:,1), data(:,2), data(:,3), '.', 'MarkerSize', lmarkersize); 66 | end 67 | set(gca,'fontsize',1); 68 | 69 | if size(data,2) == 3 70 | view([-45 45]); 71 | end 72 | 73 | 74 | 75 | % label function for create "mouse over effect" 76 | % @param varargin input data 77 | % @return label text 78 | function txt = showlabel(varargin) 79 | label = varargin{3}; 80 | txt = label{get(varargin{2}, 'DataIndex')}; 81 | -------------------------------------------------------------------------------- /examples/reducing/build.py: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # LGPL License # 3 | # # 4 | # This file is part of the Machine Learning Framework. # 5 | # Copyright (c) 2010-2012, Philipp Kraus, # 6 | # This program is free software: you can redistribute it and/or modify # 7 | # it under the terms of the GNU Lesser General Public License as # 8 | # published by the Free Software Foundation, either version 3 of the # 9 | # License, or (at your option) any later version. # 10 | # # 11 | # This program is distributed in the hope that it will be useful, # 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | # GNU Lesser General Public License for more details. # 15 | # # 16 | # You should have received a copy of the GNU Lesser General Public License # 17 | # along with this program. If not, see . # 18 | ############################################################################ 19 | 20 | # -*- coding: utf-8 -*- 21 | 22 | # build script for the reducing example 23 | 24 | import os 25 | Import("*") 26 | 27 | buildlist = [] 28 | 29 | if env["withfiles"] : 30 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "reducing", "lda"), source=defaultcpp+["lda.cpp"] ) ) 31 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "reducing", "mds"), source=defaultcpp+["mds.cpp"] ) ) 32 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "reducing", "pca"), source=defaultcpp+["pca.cpp"] ) ) 33 | 34 | if env["uselocallibrary"] or env["copylibrary"] : 35 | Depends(buildlist, env.LibraryCopy( os.path.join("#build", env["buildtype"], "reducing"), [] )) 36 | 37 | env.Alias( "reducing", buildlist ) -------------------------------------------------------------------------------- /examples/reducing/pca.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | 32 | namespace po = boost::program_options; 33 | namespace ublas = boost::numeric::ublas; 34 | namespace dim = machinelearning::dimensionreduce::nonsupervised; 35 | namespace tools = machinelearning::tools; 36 | 37 | 38 | /** main program 39 | * @param p_argc number of arguments 40 | * @param p_argv arguments 41 | **/ 42 | int main(int p_argc, char* p_argv[]) 43 | { 44 | #ifdef MACHINELEARNING_MULTILANGUAGE 45 | tools::language::bindings::bind(); 46 | #endif 47 | 48 | // default values 49 | std::size_t l_dimension; 50 | std::string l_outpath; 51 | 52 | // create CML options with description 53 | po::options_description l_description("allowed options"); 54 | l_description.add_options() 55 | ("help", "produce help message") 56 | ("infile", po::value(), "input file") 57 | ("inpath", po::value(), "input path of the datapoint within the input file") 58 | ("outfile", po::value(), "output HDF5 file") 59 | ("outpath", po::value(&l_outpath)->default_value("/pca"), "output path within the HDF5 file [default: /pca]") 60 | ("dimension", po::value(&l_dimension)->default_value(3), "target dimension [default: 3]") 61 | ; 62 | 63 | po::variables_map l_map; 64 | po::positional_options_description l_input; 65 | po::store(po::command_line_parser(p_argc, p_argv).options(l_description).positional(l_input).run(), l_map); 66 | po::notify(l_map); 67 | 68 | if (l_map.count("help")) { 69 | std::cout << l_description << std::endl; 70 | return EXIT_SUCCESS; 71 | } 72 | 73 | if ( (!l_map.count("infile")) || (!l_map.count("inpath")) || (!l_map.count("outfile")) ) { 74 | std::cerr << "[--infile], [--inpath] and [--outfile] option must be set" << std::endl; 75 | return EXIT_FAILURE; 76 | } 77 | 78 | 79 | // read source hdf file 80 | tools::files::hdf source( l_map["infile"].as() ); 81 | 82 | // create pca object and map the data 83 | dim::pca l_pca( l_dimension ); 84 | const ublas::matrix l_project = l_pca.map( source.readBlasMatrix( l_map["inpath"].as(), tools::files::hdf::NATIVE_DOUBLE) ); 85 | 86 | 87 | // create file and write data to hdf 88 | tools::files::hdf target( l_map["outfile"].as(), true); 89 | target.writeBlasMatrix( l_outpath, l_project, tools::files::hdf::NATIVE_DOUBLE ); 90 | 91 | return EXIT_SUCCESS; 92 | } 93 | -------------------------------------------------------------------------------- /examples/sources/build.py: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # LGPL License # 3 | # # 4 | # This file is part of the Machine Learning Framework. # 5 | # Copyright (c) 2010-2012, Philipp Kraus, # 6 | # This program is free software: you can redistribute it and/or modify # 7 | # it under the terms of the GNU Lesser General Public License as # 8 | # published by the Free Software Foundation, either version 3 of the # 9 | # License, or (at your option) any later version. # 10 | # # 11 | # This program is distributed in the hope that it will be useful, # 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | # GNU Lesser General Public License for more details. # 15 | # # 16 | # You should have received a copy of the GNU Lesser General Public License # 17 | # along with this program. If not, see . # 18 | ############################################################################ 19 | 20 | # -*- coding: utf-8 -*- 21 | 22 | # build script for the source example 23 | 24 | import os 25 | Import("*") 26 | 27 | buildlist = [] 28 | 29 | if env["withsources"] : 30 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "sources", "twitter"), source=defaultcpp+["twitter.cpp"] ) ) 31 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "sources", "newsgroup"), source=defaultcpp+["newsgroup.cpp"] ) ) 32 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "sources", "wikipedia"), source=defaultcpp+["wikipedia.cpp"] ) ) 33 | 34 | if env["withfiles"] : 35 | buildlist.append( env.Program( target=os.path.join("#build", env["buildtype"], "sources", "cloud"), source=defaultcpp+["cloud.cpp"] ) ) 36 | 37 | if env["uselocallibrary"] or env["copylibrary"] : 38 | Depends(buildlist, env.LibraryCopy( os.path.join("#build", env["buildtype"], "sources"), [] )) 39 | 40 | env.Alias( "sources", buildlist ) -------------------------------------------------------------------------------- /examples/sources/newsgroup.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | 31 | using namespace machinelearning; 32 | namespace po = boost::program_options; 33 | 34 | 35 | /** main program 36 | * @param p_argc number of arguments 37 | * @param p_argv arguments 38 | **/ 39 | int main(int p_argc, char* p_argv[]) 40 | { 41 | #ifdef MACHINELEARNING_MULTILANGUAGE 42 | tools::language::bindings::bind(); 43 | #endif 44 | 45 | std::string l_content; 46 | bool l_cancel; 47 | 48 | // create CML options with description 49 | po::options_description l_description("allowed options"); 50 | l_description.add_options() 51 | ("help", "produce help message") 52 | ("server", po::value(), "IP / address of the NNTP server") 53 | ("groups", po::value< std::vector >()->multitoken(), "list of groups / not set = show group list") 54 | ("content", po::value(&l_content)->default_value("body"), "content of articles (values: full, body [default], header)") 55 | ("canceled", po::value(&l_cancel)->default_value(false), "show canceled articles (values: false / 0 [default], true)") 56 | ; 57 | 58 | po::variables_map l_map; 59 | po::positional_options_description l_input; 60 | po::store(po::command_line_parser(p_argc, p_argv).options(l_description).positional(l_input).run(), l_map); 61 | po::notify(l_map); 62 | 63 | if (l_map.count("help")) { 64 | std::cout << l_description << std::endl; 65 | return EXIT_SUCCESS; 66 | } 67 | 68 | if (!l_map.count("server")) { 69 | std::cerr << "[--server] option must be set" << std::endl; 70 | return EXIT_FAILURE; 71 | } 72 | 73 | 74 | 75 | 76 | // connect to server 77 | tools::sources::nntp news( l_map["server"].as() ); 78 | 79 | if (!l_map.count("groups")) { 80 | 81 | // read group list 82 | std::map l_groups = news.getGroupList(); 83 | for (std::map::iterator it = l_groups.begin(); it != l_groups.end(); ++it) 84 | std::cout << it->first << " (" << it->second << ")" << std::endl; 85 | 86 | } else { 87 | 88 | news.setContent( tools::sources::nntp::body ); 89 | if (l_content == "full") 90 | news.setContent( tools::sources::nntp::full ); 91 | if (l_content == "header") 92 | news.setContent( tools::sources::nntp::header ); 93 | 94 | 95 | const std::vector l_groups = l_map["groups"].as< std::vector >(); 96 | 97 | for(std::size_t i=0; i < l_groups.size(); ++i) { 98 | // sets the newsgroup for browsing 99 | news.setGroup( l_groups[i] ); 100 | 101 | // browse each article in the group 102 | for(tools::sources::nntp::iterator it=news.begin(); it != news.end(); ++it) { 103 | if ( (it->isArticleCanceled()) && l_cancel ) 104 | continue; 105 | 106 | std::cout << it->getArticle() << "\n===================================================================================" << std::endl; 107 | } 108 | } 109 | } 110 | 111 | return EXIT_SUCCESS; 112 | } 113 | -------------------------------------------------------------------------------- /examples/sources/wikipedia.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | 31 | using namespace machinelearning; 32 | namespace po = boost::program_options; 33 | 34 | 35 | /** output for one article 36 | * @param p_wiki wikipedia object 37 | **/ 38 | void output( tools::sources::wikipedia& p_wiki ) { 39 | // extract article data (if article exists read data else get acronyms) 40 | std::vector l_label; 41 | if (p_wiki.isArticle()) { 42 | std::cout << p_wiki.getArticleContent() << "\n-----------------------------------------------------------------------------------" << std::endl; 43 | l_label = p_wiki.getArticleLabel(); 44 | } else 45 | l_label = p_wiki.getArticleAcronym(); 46 | 47 | 48 | // show label data 49 | for(std::size_t i=0; i < l_label.size(); ++i) 50 | std::cout << l_label[i] << std::endl; 51 | } 52 | 53 | 54 | 55 | /** main program 56 | * @param p_argc number of arguments 57 | * @param p_argv arguments 58 | **/ 59 | int main(int p_argc, char* p_argv[]) 60 | { 61 | #ifdef MACHINELEARNING_MULTILANGUAGE 62 | tools::language::bindings::bind(); 63 | #endif 64 | 65 | std::string l_lang; 66 | 67 | // create CML options with description 68 | po::options_description l_description("allowed options"); 69 | l_description.add_options() 70 | ("help", "produce help message") 71 | ("search", po::value< std::vector >()->multitoken(), "returns the artice of the keyword / returns list of articles / if empty, you will get a random article") 72 | ("lang", po::value(&l_lang)->default_value("en"), "language code (iso 639-1 or -3) [default: en]") 73 | ; 74 | 75 | po::variables_map l_map; 76 | po::positional_options_description l_input; 77 | po::store(po::command_line_parser(p_argc, p_argv).options(l_description).positional(l_input).run(), l_map); 78 | po::notify(l_map); 79 | 80 | if (l_map.count("help")) { 81 | std::cout << l_description << std::endl; 82 | return EXIT_SUCCESS; 83 | } 84 | 85 | 86 | // create wikipedia object 87 | tools::sources::wikipedia wiki( tools::language::fromString(l_lang) ); 88 | 89 | if (!l_map.count("search")) { 90 | wiki.getRandomArticle(); 91 | output(wiki); 92 | } else { 93 | const std::vector l_search = l_map["search"].as< std::vector >(); 94 | 95 | for(std::size_t i=0; i < l_search.size(); ++i) { 96 | wiki.getArticle( l_search[i] ); 97 | output(wiki); 98 | std::cout << "\n===================================================================================" << std::endl; 99 | } 100 | } 101 | 102 | return EXIT_SUCCESS; 103 | } 104 | -------------------------------------------------------------------------------- /functionoptimization/functionoptimization.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | #ifndef __MACHINELEARNING_FUNCTIONOPTIMIZATION_FUNCTIONOPTIMIZATION_H 26 | #define __MACHINELEARNING_FUNCTIONOPTIMIZATION_FUNCTIONOPTIMIZATION_H 27 | 28 | namespace machinelearning { 29 | 30 | /** namespace with structurs for fitting functions **/ 31 | namespace functionaloptimization {} 32 | } 33 | 34 | #include "gradientdescent.hpp" 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /geneticalgorithm/crossover/crossover.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | #ifndef __MACHINELEARNING_GENETICALGORITHM_CROSSOVER_CROSSOVER_H 26 | #define __MACHINELEARNING_GENETICALGORITHM_CROSSOVER_CROSSOVER_H 27 | 28 | namespace machinelearning { namespace geneticalgorithm { 29 | 30 | /** namespace of the genetic algorithms for crossover structures **/ 31 | namespace crossover {} 32 | 33 | }} 34 | 35 | #include "crossover.hpp" 36 | #include "kcrossover.hpp" 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /geneticalgorithm/crossover/crossover.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | #ifndef __MACHINELEARNING_GENETICALGORITHM_CROSSOVER_CROSSOVER_HPP 26 | #define __MACHINELEARNING_GENETICALGORITHM_CROSSOVER_CROSSOVER_HPP 27 | 28 | #include 29 | 30 | #include "../individual/individual.hpp" 31 | 32 | 33 | namespace machinelearning { namespace geneticalgorithm { namespace crossover { 34 | 35 | /** abstract class of the crossover function **/ 36 | template class crossover 37 | { 38 | 39 | public : 40 | 41 | /** returns the number how many individuals are needed for the crossover (default should be two) 42 | * @return number of needed individuals 43 | **/ 44 | virtual std::size_t getNumberOfIndividuals( void ) const = 0; 45 | 46 | /** set the individuals with a smart-pointer 47 | * @param p_individual smart-pointer object to an individual 48 | **/ 49 | virtual void setIndividual( const boost::shared_ptr< individual::individual >& p_individual ) = 0; 50 | 51 | /** creates a new smart-pointer object with the new individual data 52 | * @return a new smart-pointer object of the individual that should be replaced 53 | **/ 54 | virtual boost::shared_ptr< individual::individual > combine( void ) = 0; 55 | 56 | /** method for cloning the object, for using on multithread 57 | * @param p_ptr smart-pointer object 58 | **/ 59 | virtual void clone( boost::shared_ptr< crossover >& p_ptr ) const = 0; 60 | 61 | /** method that is called at the end of each iteration 62 | * @param p_population population 63 | **/ 64 | virtual void onEachIteration( const std::vector< boost::shared_ptr< individual::individual > >& p_population ) = 0; 65 | }; 66 | 67 | }}} 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /geneticalgorithm/fitness/fitness.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | #ifndef __MACHINELEARNING_GENETICALGORITHM_FITNESS_FITNESS_H 26 | #define __MACHINELEARNING_GENETICALGORITHM_FITNESS_FITNESS_H 27 | 28 | namespace machinelearning { namespace geneticalgorithm { 29 | 30 | /** namespace of the genetic algorithms for fitness structures **/ 31 | namespace fitness {} 32 | 33 | }} 34 | 35 | #include "fitness.hpp" 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /geneticalgorithm/fitness/fitness.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | #ifndef __MACHINELEARNING_GENETICALGORITHM_FITNESS_FITNESS_HPP 26 | #define __MACHINELEARNING_GENETICALGORITHM_FITNESS_FITNESS_HPP 27 | 28 | #include 29 | #include 30 | 31 | #include "../individual/individual.hpp" 32 | 33 | 34 | namespace machinelearning { namespace geneticalgorithm { namespace fitness { 35 | 36 | /** abstract class of the fitness function **/ 37 | template class fitness 38 | { 39 | BOOST_STATIC_ASSERT( !boost::is_integral::value ); 40 | 41 | public : 42 | 43 | /** method for calculating the fitness value of an individual / return value should be [0, best value] 44 | * @param p_individual reference to an individual 45 | **/ 46 | virtual T getFitness( const individual::individual& p_individual ) = 0; 47 | 48 | /** bool method, that will be true if the optimal fitness values is reached. The 49 | * iteration process will bes stopped immediately, but the elite individual will 50 | * be added basis of the fitness value to the elite list 51 | * @return bool for stopping iteration process 52 | **/ 53 | virtual bool isOptimumReached( void ) const = 0; 54 | 55 | /** method for cloning the object, for using on multithread 56 | * @param p_ptr smart-pointer object 57 | **/ 58 | virtual void clone( boost::shared_ptr< fitness >& p_ptr ) const = 0; 59 | 60 | /** method that is called at the end of each iteration 61 | * @param p_population population 62 | **/ 63 | virtual void onEachIteration( const std::vector< boost::shared_ptr< individual::individual > >& p_population ) = 0; 64 | 65 | }; 66 | 67 | }}} 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /geneticalgorithm/geneticalgorithm.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** header file to connect all genetic algorithm for one include **/ 25 | 26 | #ifndef __MACHINELEARNING_GENETICALGORITHM_GENETICALGORITHM_H 27 | #define __MACHINELEARNING_GENETICALGORITHM_GENETICALGORITHM_H 28 | 29 | 30 | namespace machinelearning { 31 | 32 | /** namespace for genetic algorithms 33 | * @todo adding different individuals, crossover and fitness function for example use 34 | * @todo adding LUA ( http://en.wikipedia.org/wiki/Lua_(programming_language) ) support for 35 | **/ 36 | namespace geneticalgorithm {} 37 | 38 | } 39 | 40 | 41 | #include "population.hpp" 42 | 43 | #include "fitness/fitness.h" 44 | #include "selection/selection.h" 45 | #include "individual/individual.h" 46 | #include "crossover/crossover.h" 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /geneticalgorithm/individual/individual.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | #ifndef __MACHINELEARNING_GENETICALGORITHM_INDIVIDUAL_INDIVIDUAL_H 26 | #define __MACHINELEARNING_GENETICALGORITHM_INDIVIDUAL_INDIVIDUAL_H 27 | 28 | namespace machinelearning { namespace geneticalgorithm { 29 | 30 | /** namespace of the genetic algorithms for individual structures **/ 31 | namespace individual {} 32 | 33 | }} 34 | 35 | #include "individual.hpp" 36 | #include "binaryindividual.hpp" 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /geneticalgorithm/individual/individual.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | #ifndef __MACHINELEARNING_GENETICALGORITHM_INDIVIDUAL_INDIVIDUAL_HPP 26 | #define __MACHINELEARNING_GENETICALGORITHM_INDIVIDUAL_INDIVIDUAL_HPP 27 | 28 | #include 29 | 30 | 31 | 32 | namespace machinelearning { namespace geneticalgorithm { namespace individual { 33 | 34 | /** abstract class of an indivdual of the population **/ 35 | template class individual 36 | { 37 | 38 | public : 39 | 40 | /** method for cloning the object. The method should be create a new individual for the population 41 | * initialization on the heap and returns the smart-pointer to the heap object within the reference parameter. 42 | * @param p_individual reference in which the new individual smart-pointer object is written 43 | **/ 44 | virtual void clone( boost::shared_ptr< individual >& p_individual ) const = 0; 45 | 46 | /** returns a value of a data element at the position of the individual 47 | * @param p_index index position of the gen position 48 | **/ 49 | virtual T operator[]( const std::size_t& p_index ) const = 0; 50 | 51 | /** returns a reference of a data element at the position of the individual 52 | * @param p_index index position of the gen position 53 | **/ 54 | virtual T& operator[]( const std::size_t& p_index ) = 0; 55 | 56 | /** mutates the individual **/ 57 | virtual void mutate( void ) = 0; 58 | 59 | /** returns the number of positions / length 60 | * @return length / size of the gen sequence 61 | **/ 62 | virtual std::size_t size( void ) const = 0; 63 | 64 | }; 65 | 66 | }}} 67 | #endif 68 | 69 | -------------------------------------------------------------------------------- /geneticalgorithm/selection/bestof.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | #ifndef __MACHINELEARNING_GENETICALGORITHM_SELECTION_BESTOF_HPP 26 | #define __MACHINELEARNING_GENETICALGORITHM_SELECTION_BESTOF_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "selection.hpp" 33 | #include "../individual/individual.hpp" 34 | #include "../../tools/tools.h" 35 | 36 | 37 | 38 | namespace machinelearning { namespace geneticalgorithm { namespace selection { 39 | 40 | 41 | namespace ublas = boost::numeric::ublas; 42 | 43 | 44 | /** class of the bestof-selection. uses the n best elements of the population **/ 45 | template class bestof : public selection 46 | { 47 | BOOST_STATIC_ASSERT( !boost::is_integral::value ); 48 | 49 | public : 50 | 51 | bestof( const std::size_t& ); 52 | 53 | void clone( boost::shared_ptr< selection >& p_ptr ) const; 54 | void getElite( const std::size_t&, const std::size_t&, const std::vector< boost::shared_ptr< individual::individual > >&, const ublas::vector&, const ublas::vector&, const ublas::vector&,std::vector< boost::shared_ptr< individual::individual > >& ); 55 | 56 | void onEachIteration( const std::vector< boost::shared_ptr< individual::individual > >& ) {} 57 | 58 | 59 | private : 60 | 61 | /** number of elements **/ 62 | const std::size_t m_number; 63 | 64 | }; 65 | 66 | 67 | 68 | /** constructor 69 | * @param p_num number of elements that should be used 70 | **/ 71 | template inline bestof::bestof( const std::size_t& p_num ) : 72 | m_number( p_num ) 73 | { 74 | if (p_num == 0) 75 | throw exception::runtime(_("number must be greater than zero"), *this); 76 | } 77 | 78 | 79 | /** method for cloning the object, for using on multithread 80 | * @param p_ptr smart-pointer object 81 | **/ 82 | template inline void bestof::clone( boost::shared_ptr< selection >& p_ptr ) const 83 | { 84 | p_ptr = boost::shared_ptr< selection >( new bestof(m_number) ); 85 | } 86 | 87 | 88 | /** returns the first n elites 89 | * @param p_start start value of the elite values 90 | * @param p_end end value of the elite values ([start, end) elite elements must be created) 91 | * @param p_population const reference to the population 92 | * @param p_rankIndex rank index (first index has the position of the population element, that has the smalles fitness value) 93 | * @param p_elite vector with elite individual 94 | **/ 95 | template inline void bestof::getElite( const std::size_t& p_start, const std::size_t& p_end, const std::vector< boost::shared_ptr< individual::individual > >& p_population, const ublas::vector&, const ublas::vector& p_rankIndex, const ublas::vector&, std::vector< boost::shared_ptr< individual::individual > >& p_elite ) 96 | { 97 | const std::size_t l_end = std::min(p_end, m_number); 98 | 99 | std::size_t n = p_start; 100 | for(std::size_t i=p_start; i < p_end; ++i) { 101 | p_elite.push_back( p_population[p_rankIndex[p_rankIndex.size()-1-n]] ); 102 | n++; 103 | if (n >= l_end) 104 | n = p_start; 105 | } 106 | } 107 | 108 | 109 | }}} 110 | #endif 111 | 112 | -------------------------------------------------------------------------------- /geneticalgorithm/selection/selection.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | #ifndef __MACHINELEARNING_GENETICALGORITHM_SELECTION_SELECTION_H 26 | #define __MACHINELEARNING_GENETICALGORITHM_SELECTION_SELECTION_H 27 | 28 | namespace machinelearning { namespace geneticalgorithm { 29 | 30 | /** namespace of the genetic algorithms for selection structures **/ 31 | namespace selection {} 32 | 33 | }} 34 | 35 | #include "selection.hpp" 36 | #include "roulettewheel.hpp" 37 | #include "bestof.hpp" 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /geneticalgorithm/selection/selection.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | #ifndef __MACHINELEARNING_GENETICALGORITHM_SELECTION_SELECTION_HPP 26 | #define __MACHINELEARNING_GENETICALGORITHM_SELECTION_SELECTION_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "../individual/individual.hpp" 33 | 34 | 35 | 36 | namespace machinelearning { namespace geneticalgorithm { namespace selection { 37 | 38 | 39 | namespace ublas = boost::numeric::ublas; 40 | 41 | 42 | /** abstract class of the selection function **/ 43 | template class selection 44 | { 45 | BOOST_STATIC_ASSERT( !boost::is_integral::value ); 46 | 47 | public : 48 | 49 | /** returns a vector with smart-pointer to the individuals that are elite. The vector must be return the elite objects within the range [start,end) 50 | * @param p_start start value of the elite values 51 | * @param p_end end value of the elite values ([start, end) elite elements must be created) 52 | * @param p_population const reference to the population 53 | * @param p_fitness vector with fitnss values (index is equal to the index of the population) 54 | * @param p_rankIndex rank index (first index has the position of the population element, that has the smalles fitness value) 55 | * @param p_rank rank values (first element equal to polulation index has the rank value of the first individual) 56 | * @param p_elite vector with elite individual [must not be thread-safe] 57 | **/ 58 | virtual void 59 | getElite( 60 | const std::size_t& p_start, 61 | const std::size_t& p_end, 62 | const std::vector< boost::shared_ptr< individual::individual > >& p_population, 63 | const ublas::vector& p_fitness, 64 | const ublas::vector& p_rankIndex, 65 | const ublas::vector& p_rank, 66 | std::vector< boost::shared_ptr< individual::individual > >& p_elite 67 | ) = 0; 68 | 69 | /** method for cloning the object, for using on multithread 70 | * @param p_ptr smart-pointer object 71 | **/ 72 | virtual void clone( boost::shared_ptr< selection >& p_ptr ) const = 0; 73 | 74 | /** method that is called at the end of each iteration 75 | * @param p_population population 76 | **/ 77 | virtual void onEachIteration( const std::vector< boost::shared_ptr< individual::individual > >& p_population ) = 0; 78 | 79 | }; 80 | 81 | }}} 82 | #endif 83 | 84 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | *.tgz 2 | *.tar.* 3 | build_* 4 | ginac* 5 | cln* 6 | hdf5* 7 | atlas* 8 | ATLAS 9 | jsoncpp-src-* 10 | libxml2* 11 | boost* 12 | zlib* 13 | bzip2* 14 | -------------------------------------------------------------------------------- /machinelearning.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** implementation for initialization of static member 25 | * or different code structures that must run only once 26 | **/ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef MACHINELEARNING_MPI 33 | #include 34 | #endif 35 | 36 | #ifdef MACHINELEARNING_RANDOMDEVICE 37 | #include 38 | #endif 39 | 40 | 41 | #include "machinelearning.h" 42 | 43 | 44 | namespace machinelearning { 45 | 46 | /** initialization of the random device **/ 47 | #ifdef MACHINELEARNING_RANDOMDEVICE 48 | boost::random_device tools::random::m_random; 49 | #else 50 | 51 | #ifdef MACHINELEARNING_MPI 52 | boost::mpi::environment l_mpienv; 53 | boost::mpi::communicator l_mpi; 54 | boost::mt19937 tools::random::m_random( time(NULL) * (l_mpi.rank()+1) ); 55 | #else 56 | boost::mt19937 tools::random::m_random( time(NULL) ); 57 | #endif 58 | 59 | #endif 60 | 61 | 62 | /** initialization of the logger instance **/ 63 | #ifdef MACHINELEARNING_LOGGER 64 | tools::logger* tools::logger::m_instance = NULL; 65 | 66 | #ifdef MACHINELEARNING_MPI 67 | std::size_t tools::logger::m_mpitag = 999; 68 | std::string tools::logger::m_mpieot = "$EOT$"; 69 | #endif 70 | 71 | #endif 72 | 73 | } 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /neighborhood/neighborhood.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** header file to connect all neighborhood algorithms for one include **/ 25 | 26 | #ifndef __MACHINELEARNING_NEIGHBORHOOD_NEIGHBORHOOD_H 27 | #define __MACHINELEARNING_NEIGHBORHOOD_NEIGHBORHOOD_H 28 | 29 | #include "neighborhood.hpp" 30 | #include "knn.hpp" 31 | #include "kapproximation.hpp" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /neighborhood/neighborhood.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | 26 | #ifndef __MACHINELEARNING_NEIGHBORHOOD_NEIGHBORHOOD_HPP 27 | #define __MACHINELEARNING_NEIGHBORHOOD_NEIGHBORHOOD_HPP 28 | 29 | 30 | #include 31 | #include 32 | 33 | #include "../tools/tools.h" 34 | 35 | 36 | namespace machinelearning { 37 | 38 | 39 | /** neighborhood namespace for all structures to calculate neighbors 40 | **/ 41 | namespace neighborhood { 42 | 43 | 44 | namespace ublas = boost::numeric::ublas; 45 | 46 | 47 | 48 | /** abstract class for neighborhood classes 49 | * @todo recreate base class for neighborhood 50 | **/ 51 | template class neighborhood 52 | { 53 | BOOST_STATIC_ASSERT( !boost::is_integral::value ); 54 | 55 | 56 | public : 57 | 58 | /** function for calculating the neighborhoods **/ 59 | virtual ublas::matrix get( const ublas::matrix& ) const = 0; 60 | 61 | /** function for calculating the neighborhoods between different datapoints **/ 62 | virtual ublas::matrix get( const ublas::matrix&, const ublas::matrix& ) const = 0; 63 | 64 | /** calculates the distance between two vectors **/ 65 | virtual T calculateDistance( const ublas::vector&, const ublas::vector& ) const = 0; 66 | 67 | /** invert a value **/ 68 | virtual T invert( const T& ) const = 0; 69 | 70 | /** returns the number of neighbors **/ 71 | virtual std::size_t getNeighborCount( void ) const = 0; 72 | 73 | }; 74 | 75 | } 76 | } 77 | #endif 78 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | MachineLearning 2 | =============== 3 | 4 | C++ framework that implements machinelearning algorithms (clustering, dimension reducing, genetic algorithms) 5 | -------------------------------------------------------------------------------- /textprocess/textprocess.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | 26 | #ifndef __MACHINELEARNING_TEXTPROCESS_TEXTPROCESS_H 27 | #define __MACHINELEARNING_TEXTPROCESS_TEXTPROCESS_H 28 | 29 | namespace machinelearning { 30 | 31 | /** namespace for all textprocessing algorithm **/ 32 | namespace textprocess {} 33 | 34 | } 35 | 36 | 37 | 38 | #include "termfrequency.h" 39 | #include "stopwordreduction.h" 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /tools/files/files.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | #ifdef MACHINELEARNING_FILES 25 | 26 | #ifndef __MACHINELEARNING_TOOLS_FILES_FILES_H 27 | #define __MACHINELEARNING_TOOLS_FILES_FILES_H 28 | 29 | namespace machinelearning { 30 | namespace tools { 31 | 32 | /** namespace for file support **/ 33 | namespace files {} 34 | 35 | } 36 | } 37 | 38 | 39 | #include "csv.hpp" 40 | #include "hdf.hpp" 41 | 42 | #endif 43 | #endif 44 | -------------------------------------------------------------------------------- /tools/files/hdf.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for the HDF calls, 25 | * we use always double types, so for writing we 26 | * set the HDF datatype by a fixed value 27 | **/ 28 | 29 | #ifdef MACHINELEARNING_FILES_HDF 30 | 31 | #ifdef SWIGJAVA 32 | %module "hdfmodule" 33 | %include "../../swig/java/java.i" 34 | %rename(HDF) hdf; 35 | 36 | %exception %{ 37 | try { 38 | $action 39 | } 40 | catch (const std::exception& e) { SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, e.what() ); } 41 | catch( const H5::Exception& e) { SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, e.getCDetailMsg() ); } 42 | catch (...) { SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "exception in machinelearning framework"); } 43 | %} 44 | #endif 45 | 46 | 47 | 48 | 49 | %include "hdf.hpp" 50 | 51 | %template(readBlasMatrix) machinelearning::tools::files::hdf::readBlasMatrix; 52 | %template(readBlasVector) machinelearning::tools::files::hdf::readBlasVector; 53 | %template(readValue) machinelearning::tools::files::hdf::readValue; 54 | 55 | %extend machinelearning::tools::files::hdf { 56 | void writeValue( const std::string& p_path, const double& p_val ) { $self->writeValue(p_path, p_val, tools::files::hdf::NATIVE_DOUBLE); } 57 | void writeBlasVector( const std::string& p_path, const ublas::vector& p_vector ) { $self->writeBlasVector(p_path, p_vector, tools::files::hdf::NATIVE_DOUBLE); } 58 | void writeBlasMatrix( const std::string& p_path, const ublas::matrix& p_matrix ) { $self->writeBlasMatrix(p_path, p_matrix, tools::files::hdf::NATIVE_DOUBLE); } 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /tools/iostreams/iostreams.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | #ifndef __MACHINELEARNING_TOOLS_IOSTREAMS_IOSTREAMS_H 25 | #define __MACHINELEARNING_TOOLS_IOSTREAMS_IOSTREAMS_H 26 | 27 | namespace machinelearning { 28 | namespace tools { 29 | 30 | /** namespace with classes for iostreams (eg URL encoding / decoding) **/ 31 | namespace iostreams {} 32 | 33 | } 34 | } 35 | 36 | #include "urlencoder.h" 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /tools/iostreams/urlencoder.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | #ifndef __MACHINELEARNING_TOOLS_IOSTREAMS_URLENCODER_H 25 | #define __MACHINELEARNING_TOOLS_IOSTREAMS_URLENCODER_H 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | namespace machinelearning { namespace tools { namespace iostreams { 34 | 35 | /** filter class for creating a stream with "percent encoding" 36 | * @see http://en.wikipedia.org/wiki/Percent-encoding 37 | * @todo test with different encodings of the input stream and |values| > 255 38 | **/ 39 | class urlencoder : public boost::iostreams::output_filter 40 | { 41 | 42 | public : 43 | 44 | urlencoder( const unsigned int& ); 45 | template bool put(S&, int); 46 | 47 | private : 48 | 49 | /** maximal unsigned value for the input character **/ 50 | const unsigned int m_maxinputsize; 51 | /** number of prefill values **/ 52 | unsigned int m_prefill; 53 | 54 | std::string toHex( const unsigned int& ) const; 55 | unsigned int prefill( const unsigned int& ) const; 56 | 57 | }; 58 | 59 | 60 | 61 | 62 | /** constructor 63 | * @param p_max maximum value for hex encoding 64 | **/ 65 | inline urlencoder::urlencoder( const unsigned int& p_max ) : 66 | m_maxinputsize( p_max ), 67 | m_prefill( prefill(p_max) ) 68 | {} 69 | 70 | 71 | /** determine prefill number of hex codes 72 | * @param p_max maximal number 73 | * @return number of prefixes 74 | **/ 75 | inline unsigned int urlencoder::prefill( const unsigned int& p_max ) const 76 | { 77 | unsigned int l_prefill = 0; 78 | 79 | for(unsigned int l_max = p_max; l_max != 0; ++l_prefill) 80 | l_max >>= 4; 81 | 82 | return l_prefill; 83 | } 84 | 85 | 86 | /** create a hexdecimal value of a input char 87 | * @param p_char input value 88 | * @return string with char value 89 | **/ 90 | inline std::string urlencoder::toHex( const unsigned int& p_char ) const 91 | { 92 | std::stringstream l_stream; 93 | l_stream << std::setfill('0') << std::setw(m_prefill) << std::hex << p_char; 94 | return l_stream.str(); 95 | } 96 | 97 | 98 | /** create representation 99 | * @param p_dest destination stream 100 | * @param p_char input character 101 | * @return bool for writing 102 | **/ 103 | template inline bool urlencoder::put(S& p_dest, int p_char) 104 | { 105 | // unreserved characters 106 | if ((isalnum(p_char)) || (p_char == '_') || (p_char == '~') || (p_char == '.') || (p_char == '-')) 107 | return boost::iostreams::put(p_dest, p_char); 108 | 109 | // reserved characters 110 | bool l_res = boost::iostreams::put(p_dest, '%'); 111 | 112 | // for the correct hex encoding, we need a uint value, the char value are in the range 113 | // -maxvalue/2 till maxvalue/2 and we change it to 0 to maxvalue-1 114 | const std::string l_hex= toHex( static_cast(p_char < 0 ? m_maxinputsize + p_char + 1 : p_char) % m_maxinputsize ); 115 | 116 | // change char to hex number and add the values to the stream 117 | for(std::size_t i=0; (i < l_hex.size()) && l_res; ++i) 118 | l_res = l_res && boost::iostreams::put(p_dest, l_hex[i]); 119 | 120 | return l_res; 121 | } 122 | 123 | }}} 124 | #endif 125 | -------------------------------------------------------------------------------- /tools/language/bindings.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | #ifndef MACHINELEARNING_MULTILANGUAGE 25 | #define _(string) string 26 | #else 27 | 28 | #ifndef __MACHINELEARNING_TOOLS_LANGUAGE_BINDINGS_H 29 | #define __MACHINELEARNING_TOOLS_LANGUAGE_BINDINGS_H 30 | 31 | extern "C" { 32 | #include 33 | } 34 | #include 35 | 36 | #define _(string) gettext(string) 37 | 38 | 39 | namespace machinelearning { namespace tools { namespace language { 40 | 41 | 42 | /** class for create langugage bindings **/ 43 | class bindings 44 | { 45 | 46 | public : 47 | 48 | static std::string getLanguage( void ); 49 | static void bind( const std::string& = "machinelearning", const std::string& = "language", const std::string& = "" ); 50 | 51 | 52 | }; 53 | 54 | 55 | /** returns the environmental language 56 | * @return string with language 57 | **/ 58 | inline std::string bindings::getLanguage( void ) 59 | { 60 | return getenv("LANG"); 61 | } 62 | 63 | 64 | /** bind the textdomain for different language 65 | * @param p_name name of language file (default: machinelearning) 66 | * @param p_path path to language file (default: language directory, relative to the executable / eg: language files locate under p_path / p_lang / p_name.mo) 67 | * @param p_lang language (empty for system value) 68 | **/ 69 | inline void bindings::bind( const std::string& p_name, const std::string& p_path, const std::string& p_lang ) 70 | { 71 | setlocale(LC_ALL, p_lang.c_str()); 72 | bindtextdomain(p_name.c_str(), p_path.c_str()); 73 | textdomain(p_name.c_str()); 74 | } 75 | 76 | 77 | }}} 78 | #endif 79 | #endif 80 | -------------------------------------------------------------------------------- /tools/language/build.py: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # LGPL License # 3 | # # 4 | # This file is part of the Machine Learning Framework. # 5 | # Copyright (c) 2010-2012, Philipp Kraus, # 6 | # This program is free software: you can redistribute it and/or modify # 7 | # it under the terms of the GNU Lesser General Public License as # 8 | # published by the Free Software Foundation, either version 3 of the # 9 | # License, or (at your option) any later version. # 10 | # # 11 | # This program is distributed in the hope that it will be useful, # 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 14 | # GNU Lesser General Public License for more details. # 15 | # # 16 | # You should have received a copy of the GNU Lesser General Public License # 17 | # along with this program. If not, see . # 18 | ############################################################################ 19 | 20 | # -*- coding: utf-8 -*- 21 | 22 | 23 | # build script for the multilanguage of the framework 24 | 25 | import os 26 | Import("*") 27 | 28 | 29 | env.Tool("gettext") 30 | env.AppendUnique(MSGMERGEFLAGS = ["--no-wrap", "--update"]) 31 | env.AppendUnique(XGETTEXTFLAGS = ["--keyword=_", "--language=c++", "--no-wrap"]) 32 | 33 | po = env.Translate(["de"], GlobRekursiv(os.path.join("..", ".."), env["CPPSUFFIXES"], ["swig", "examples", "documentation", "library", "buildenvironment"]), POAUTOINIT = True) 34 | mo = env.MOFiles(po) 35 | 36 | env.Clean( 37 | env.Alias("language", [ 38 | env.InstallAs( os.path.join("#build", "language", "de_DE.UTF-8", "LC_MESSAGES", "machinelearning.mo"), "de.mo") 39 | ]), 40 | [ 41 | "messages.pot", 42 | Glob("*.po~") 43 | ] 44 | ) 45 | -------------------------------------------------------------------------------- /tools/lapack.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for the Lapack calls **/ 25 | 26 | 27 | #ifdef SWIGJAVA 28 | %module "lapackmodule" 29 | %include "../swig/java/java.i" 30 | %rename(Lapack) lapack; 31 | #endif 32 | 33 | 34 | %include "lapack.hpp" 35 | %template(eigen) machinelearning::tools::lapack::eigen; 36 | %template(svd) machinelearning::tools::lapack::svd; 37 | %template(perronFrobenius) machinelearning::tools::lapack::perronfrobenius; 38 | %template(unnormalizedGraphLaplacian) machinelearning::tools::lapack::unnormalizedGraphLaplacian; 39 | %template(normalizedGraphLaplacian) machinelearning::tools::lapack::normalizedGraphLaplacian; 40 | -------------------------------------------------------------------------------- /tools/matrix.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for the matrix calls **/ 25 | 26 | 27 | #ifdef SWIGJAVA 28 | %module "matrixmodule" 29 | %include "../swig/java/java.i" 30 | %rename(Matrix) matrix; 31 | 32 | %typemap(javabody) machinelearning::tools::matrix "" 33 | %typemap(javafinalize) machinelearning::tools::matrix "" 34 | %typemap(javadestruct) machinelearning::tools::matrix "" 35 | #endif 36 | 37 | 38 | %nodefaultctor machinelearning::tools::matrix; 39 | %nodefaultdtor machinelearning::tools::matrix; 40 | 41 | 42 | %include "matrix.hpp" 43 | %template(max) machinelearning::tools::matrix::max; 44 | %template(min) machinelearning::tools::matrix::min; 45 | %template(mean) machinelearning::tools::matrix::mean; 46 | %template(variance) machinelearning::tools::matrix::variance; 47 | %template(sum) machinelearning::tools::matrix::sum; 48 | %template(trace) machinelearning::tools::matrix::trace; 49 | %template(cov) machinelearning::tools::matrix::cov; -------------------------------------------------------------------------------- /tools/random.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for the Random calls **/ 25 | 26 | 27 | #ifdef SWIGJAVA 28 | %module "randommodule" 29 | %include "../swig/java/java.i" 30 | %rename(Random) random; 31 | #endif 32 | 33 | 34 | %include "random.hpp" 35 | %template(get) machinelearning::tools::random::get; 36 | -------------------------------------------------------------------------------- /tools/sources/sources.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | #ifdef MACHINELEARNING_SOURCES 25 | 26 | #ifndef __MACHINELEARNING_TOOLS_SOURCES_SOURCES_H 27 | #define __MACHINELEARNING_TOOLS_SOURCES_SOURCES_H 28 | 29 | namespace machinelearning { 30 | namespace tools { 31 | 32 | /** namespace with classes for generating example data 33 | * @todo adding support for OpenStreetMap http://wiki.openstreetmap.org/wiki/API / http://wiki.openstreetmap.org/wiki/Overpass_API 34 | * @todo adding support for Apache Cassandra http://en.wikipedia.org/wiki/Apache_Cassandra 35 | * @todo adding support for Hadoop http://hadoop.apache.org/ 36 | * @todo adding support for MangoDB http://www.mongodb.org/ 37 | * @todo adding support for MonetDB http://www.monetdb.org/ 38 | * @todo adding support for graph databases http://en.wikipedia.org/wiki/Graph_database 39 | * @todo adding support for mySQL / MS SQL / Postgres SQL / Oracle via eg http://www.sqlapi.com/ 40 | * @todo adding twitter streaming support https://dev.twitter.com/docs/streaming-api/methods 41 | * @todo adding support for reading HTML data with WGet / Curl 42 | * @todo adding support for http://en.wikipedia.org/wiki/CouchDB 43 | * @todo adding support for web-sockets http://www.whatwg.org/specs/web-socket-protocol/ 44 | * @todo adding support for differnt source of http://datacatalogs.org/ 45 | * @todo adding support for http://www.data.gov/ 46 | **/ 47 | namespace sources {} 48 | 49 | } 50 | } 51 | 52 | #include "nntp.h" 53 | #include "wikipedia.h" 54 | #include "cloud.hpp" 55 | #include "twitter.h" 56 | 57 | #endif 58 | #endif 59 | -------------------------------------------------------------------------------- /tools/tools.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | 26 | #ifndef __MACHINELEARNING_TOOLS_TOOLS_H 27 | #define __MACHINELEARNING_TOOLS_TOOLS_H 28 | 29 | namespace machinelearning { 30 | 31 | /** namespace for all tools, which are used within the toolbox **/ 32 | namespace tools {} 33 | 34 | } 35 | 36 | 37 | #include "typeinfo.h" 38 | #include "random.hpp" 39 | #include "function.hpp" 40 | #include "matrix.hpp" 41 | #include "vector.hpp" 42 | #include "lapack.hpp" 43 | #include "logger.hpp" 44 | #include "sources/sources.h" 45 | #include "files/files.h" 46 | #include "language/language.h" 47 | #include "iostreams/iostreams.h" 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /tools/typeinfo.h: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | 25 | 26 | #ifndef __MACHINELEARNING_TOOLS_TYPEINFO_H 27 | #define __MACHINELEARNING_TOOLS_TYPEINFO_H 28 | 29 | #include 30 | #include 31 | 32 | #ifdef __GNUC__ 33 | #include 34 | #endif 35 | 36 | namespace machinelearning { namespace tools { 37 | 38 | 39 | /** class that creates a typeinfo interface **/ 40 | class typeinfo 41 | { 42 | 43 | public : 44 | 45 | template static std::string getClassName( const T* ); 46 | template static std::string getClassName( const T& ); 47 | }; 48 | 49 | 50 | /** returns the class name of a pointer 51 | * @param p_ptr pointer 52 | * @return string with class name and namespaces 53 | **/ 54 | template inline std::string typeinfo::getClassName( const T* p_ptr ) 55 | { 56 | try { 57 | 58 | #ifdef __GNUC__ 59 | return std::string(abi::__cxa_demangle( typeid(*p_ptr).name(), NULL, 0, NULL )); 60 | #endif 61 | 62 | 63 | } catch (...) {} 64 | 65 | return std::string(); 66 | } 67 | 68 | 69 | /** returns the class name of a reference 70 | * @param p_obj reference 71 | * @return string with class name and namespaces 72 | **/ 73 | template inline std::string typeinfo::getClassName( const T& p_obj ) 74 | { 75 | try { 76 | 77 | #ifdef __GNUC__ 78 | return std::string(abi::__cxa_demangle( typeid(p_obj).name(), NULL, 0, NULL )); 79 | #endif 80 | 81 | 82 | } catch (...) {} 83 | 84 | return std::string(); 85 | } 86 | 87 | 88 | }} 89 | #endif 90 | -------------------------------------------------------------------------------- /tools/vector.i: -------------------------------------------------------------------------------- 1 | /** 2 | @cond 3 | ############################################################################ 4 | # LGPL License # 5 | # # 6 | # This file is part of the Machine Learning Framework. # 7 | # Copyright (c) 2010-2012, Philipp Kraus, # 8 | # This program is free software: you can redistribute it and/or modify # 9 | # it under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 3 of the # 11 | # License, or (at your option) any later version. # 12 | # # 13 | # This program is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 16 | # GNU Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public License # 19 | # along with this program. If not, see . # 20 | ############################################################################ 21 | @endcond 22 | **/ 23 | 24 | /** interface file for the vector calls **/ 25 | 26 | 27 | #ifdef SWIGJAVA 28 | %module "vectormodule" 29 | %include "../swig/java/java.i" 30 | %rename(Vector) vector; 31 | 32 | %typemap(javabody) machinelearning::tools::vector "" 33 | %typemap(javafinalize) machinelearning::tools::vector "" 34 | %typemap(javadestruct) machinelearning::tools::vector "" 35 | #endif 36 | 37 | 38 | %nodefaultctor machinelearning::tools::vector; 39 | %nodefaultdtor machinelearning::tools::vector; 40 | 41 | 42 | %include "vector.hpp" 43 | %template(min) machinelearning::tools::vector::min; 44 | %template(max) machinelearning::tools::vector::max; 45 | %template(mean) machinelearning::tools::vector::mean; 46 | %template(variance) machinelearning::tools::vector::variance; 47 | --------------------------------------------------------------------------------