Skip to content

Commit

Permalink
Add SGPP::optimization module (result of my Master's thesis).
Browse files Browse the repository at this point in the history
  • Loading branch information
valentjn committed Feb 5, 2015
1 parent 7fa549b commit 2303372
Show file tree
Hide file tree
Showing 115 changed files with 12,130 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Doxyfile_template
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ PAPER_TYPE = a4wide
# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
# packages that should be included in the LaTeX output.

EXTRA_PACKAGES =
EXTRA_PACKAGES = amsmath amsfonts

# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
# the generated latex document. The header should contain everything until
Expand Down Expand Up @@ -1512,7 +1512,7 @@ INCLUDE_FILE_PATTERNS =
# undefined via #undef or recursively expanded use the := operator
# instead of the = operator.

PREDEFINED =
PREDEFINED = _OPENMP USEARMADILLO USEEIGEN USEUMFPACK USEGMMPP

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
# this tag can be used to specify a list of macro names that should be expanded.
Expand Down
4 changes: 3 additions & 1 deletion base/doc/doxygen/dotfiles/module_dependencies.dot
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ digraph G {
datadriven [URL="\ref sg::datadriven"];
finance [URL="\ref sg::finance"];
solver [URL="\ref sg::solver"];
parallel [URL="\ref sg::parallel"];
parallel [URL="\ref sg::parallel"];
optimization [URL="\ref sg::optimization"];
combigrid [URL=""];

pde -> base;
Expand All @@ -24,4 +25,5 @@ digraph G {
parallel -> finance;
parallel -> datadriven [constraint=false];
combigrid -> base;
optimization -> base;
}
1 change: 1 addition & 0 deletions base/doc/doxygen/installation.doxy
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ avoid "undefined symbol" errors: When using them, depending on the dependencies,
- SG_FINANCE financial module
- SG_PARALLEL classes for parallel computing
- SG_COMBIGRID combigrid classes
- SG_OPTIMIZATION optimization of objective functions

Then there are two switches for supported high-level back-ends:
- SG_PYTHON integration of SG++ in Python
Expand Down
81 changes: 81 additions & 0 deletions optimization/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright (C) 2008-today The SG++ Project
# This file is part of the SG++ project. For conditions of distribution and
# use, please see the copyright notice provided with SG++ or at
# sgpp.sparsegrids.org

import os
import fnmatch

Import("env")
Import("BUILD_DIR")
Import("PYSGPP_BUILD_PATH")
Import("moduleName")
Import("libraryTargetList")
Import("installTargetList")



libs = ["sgppbase"]
config = env.Configure()

if config.CheckHeader("suitesparse/umfpack.h", language="c++"):
libs.append("umfpack")
env.Append(CPPDEFINES=["USEUMFPACK"])
print "SGPP::optimization will be compiled with UMFPACK."
else:
env.Append(CPPDEFINES=["DONTUSEUMFPACK"])
print "SGPP::optimization will be compiled without UMFPACK (not found)."

if config.CheckHeader("eigen3/Eigen/Dense", language="c++"):
env.Append(CPPDEFINES=["USEEIGEN"])
print "SGPP::optimization will be compiled with Eigen."
else:
env.Append(CPPDEFINES=["DONTUSEEIGEN"])
print "SGPP::optimization will be compiled without Eigen (not found)."

if config.CheckHeader("armadillo", language="c++"):
libs.append("armadillo")
env.Append(CPPDEFINES=["USEARMADILLO"])
print "SGPP::optimization will be compiled with Armadillo."
else:
env.Append(CPPDEFINES=["DONTUSEARMADILLO"])
print "SGPP::optimization will be compiled without Armadillo (not found)."

if config.CheckHeader("gmm/gmm.h", language="c++"):
env.Append(CPPDEFINES=["USEGMMPP"])
print "SGPP::optimization will be compiled with Gmm++."
else:
env.Append(CPPDEFINES=["DONTUSEGMMPP"])
print "SGPP::optimization will be compiled without Gmm++ (not found)."



dependencies = ["base"]

srcs = []
for currentFolder, subdirNames, fileNames in os.walk("."):
if currentFolder.startswith("./src"):
for fileName in fnmatch.filter(fileNames, "*.cpp"):
srcs.append(os.path.join(currentFolder, fileName))

objs = []
for sourceFile in srcs:
objs.append(env.SharedObject(sourceFile))
# objs.append(sourceFile)

lib = env.SharedLibrary(target="sgpp%s" % moduleName,
source=objs,
LIBPATH=BUILD_DIR,
LIBS=libs)
env.Depends(lib, "#/" + BUILD_DIR.path + "/libsgppbase.so")
libInstall = env.Install(BUILD_DIR, lib)
# # static libraries get the suffix "static" which allos scons to correctly resolve the dependencies
# # of the shared libaries on the static libraries on windows
libStatic = env.StaticLibrary(target="sgpp%sstatic" % moduleName,
source=objs,
SHLIBPREFIX="lib")
libStaticInstall = env.Install(BUILD_DIR, libStatic)
env.Depends(libInstall, libStaticInstall)

libraryTargetList.append(lib)
installTargetList.append(libInstall)
177 changes: 177 additions & 0 deletions optimization/build/pysgpp/optimization.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
// Copyright (C) 2008-today The SG++ project
// This file is part of the SG++ project. For conditions of distribution and
// use, please see the copyright notice provided with SG++ or at
// sgpp.sparsegrids.org

// to disable OpenMP multi-threading within Python
void omp_set_num_threads(int num_threads);
%init %{
omp_set_num_threads(1);
%}

// global variables for the support of SLE solver libaries (set at compile-time)
const bool ARMADILLO_ENABLED;
const bool EIGEN_ENABLED;
const bool GMMPP_ENABLED;
const bool UMFPACK_ENABLED;

%{
#ifdef USEARMADILLO
const bool ARMADILLO_ENABLED = true;
#else
const bool ARMADILLO_ENABLED = false;
#endif

#ifdef USEEIGEN
const bool EIGEN_ENABLED = true;
#else
const bool EIGEN_ENABLED = false;
#endif

#ifdef USEGMMPP
const bool GMMPP_ENABLED = true;
#else
const bool GMMPP_ENABLED = false;
#endif

#ifdef USEUMFPACK
const bool UMFPACK_ENABLED = true;
#else
const bool UMFPACK_ENABLED = false;
#endif
%}

// necessary tools
%rename(OptRNG) SGPP::optimization::tools::RNG;
%rename(OptRNGInstance) SGPP::optimization::tools::rng;
%include "optimization/src/sgpp/optimization/tools/RNG.hpp"

// renames
%rename(OptObjective) SGPP::optimization::function::Objective;
%rename(OptObjectiveGradient) SGPP::optimization::function::ObjectiveGradient;
%rename(OptObjectiveHessian) SGPP::optimization::function::ObjectiveHessian;
%rename(OptInterpolant) SGPP::optimization::function::Interpolant;
%rename(OptInterpolantGradient) SGPP::optimization::function::InterpolantGradient;
%rename(OptInterpolantHessian) SGPP::optimization::function::InterpolantHessian;

%rename(OptTestFunction) SGPP::optimization::function::test::Test;
%rename(OptAckley) SGPP::optimization::function::test::Ackley;
%rename(OptBeale) SGPP::optimization::function::test::Beale;
%rename(OptBranin) SGPP::optimization::function::test::Branin;
%rename(OptEasom) SGPP::optimization::function::test::Easom;
%rename(OptEggholder) SGPP::optimization::function::test::Eggholder;
%rename(OptGoldsteinPrice) SGPP::optimization::function::test::GoldsteinPrice;
%rename(OptGriewank) SGPP::optimization::function::test::Griewank;
%rename(OptHartman3) SGPP::optimization::function::test::Hartman3;
%rename(OptHartman6) SGPP::optimization::function::test::Hartman6;
%rename(OptHimmelblau) SGPP::optimization::function::test::Himmelblau;
%rename(OptHoelderTable) SGPP::optimization::function::test::HoelderTable;
%rename(OptMichalewicz) SGPP::optimization::function::test::Michalewicz;
%rename(OptMladineo) SGPP::optimization::function::test::Mladineo;
%rename(OptRastrigin) SGPP::optimization::function::test::Rastrigin;
%rename(OptRosenbrock) SGPP::optimization::function::test::Rosenbrock;
%rename(OptSHCB) SGPP::optimization::function::test::SHCB;
%rename(OptSchwefel) SGPP::optimization::function::test::Schwefel;
%rename(OptSphere) SGPP::optimization::function::test::Sphere;

%rename(OptHashRefinementMultiple) SGPP::optimization::gridgen::HashRefinementMultiple;
%rename(OptIterativeGridGenerator) SGPP::optimization::gridgen::IterativeGridGenerator;
%rename(OptIterativeGridGeneratorLinearSurplus) SGPP::optimization::gridgen::IterativeGridGeneratorLinearSurplus;
%rename(OptIterativeGridGeneratorRitterNovak) SGPP::optimization::gridgen::IterativeGridGeneratorRitterNovak;

%rename(OptSLESystem) SGPP::optimization::sle::system::System;
%rename(OptFullSystem) SGPP::optimization::sle::system::Full;
%rename(OptHierarchisationSystem) SGPP::optimization::sle::system::Hierarchisation;
%rename(OptSLESolver) SGPP::optimization::sle::solver::Solver;
%rename(OptArmadillo) SGPP::optimization::sle::solver::Armadillo;
%rename(OptAutoSolver) SGPP::optimization::sle::solver::Auto;
%rename(OptBiCGStab) SGPP::optimization::sle::solver::BiCGStab;
%rename(OptEigen) SGPP::optimization::sle::solver::Eigen;
%rename(OptGaussianElimination) SGPP::optimization::sle::solver::GaussianElimination;
%rename(OptGmmpp) SGPP::optimization::sle::solver::Gmmpp;
%rename(OptUMFPACK) SGPP::optimization::sle::solver::UMFPACK;

%rename(OptOptimizer) SGPP::optimization::optimizer::Optimizer;
%rename(OptDifferentialEvolution) SGPP::optimization::optimizer::DifferentialEvolution;
%rename(OptGradientMethod) SGPP::optimization::optimizer::GradientMethod;
%rename(OptNelderMead) SGPP::optimization::optimizer::NelderMead;
%rename(OptNewton) SGPP::optimization::optimizer::Newton;
%rename(OptNLCG) SGPP::optimization::optimizer::NLCG;
%rename(OptNewton) SGPP::optimization::optimizer::Newton;
%rename(OptRandomSearch) SGPP::optimization::optimizer::RandomSearch;

%rename(OptMutexType) SGPP::optimization::tools::MutexType;
%rename(OptPrinter) SGPP::optimization::tools::Printer;
%rename(OptPrinterInstance) SGPP::optimization::tools::printer;

// classes with director interface
%feature("director") SGPP::optimization::function::test::Test;
%feature("director") SGPP::optimization::function::Objective;
%feature("director") SGPP::optimization::function::ObjectiveGradient;
%feature("director") SGPP::optimization::function::ObjectiveHessian;
%feature("director") SGPP::optimization::gridgen::IterativeGridGenerator;
%feature("director") SGPP::optimization::sle::system::System;
%feature("director") SGPP::optimization::sle::solver::Solver;
%feature("director") SGPP::optimization::optimizer::Optimizer;

// includes
%include "optimization/src/sgpp/optimization/function/Objective.hpp"
%include "optimization/src/sgpp/optimization/function/ObjectiveGradient.hpp"
%include "optimization/src/sgpp/optimization/function/ObjectiveHessian.hpp"
%include "optimization/src/sgpp/optimization/function/Interpolant.hpp"
%include "optimization/src/sgpp/optimization/function/InterpolantGradient.hpp"
%include "optimization/src/sgpp/optimization/function/InterpolantHessian.hpp"

%include "optimization/src/sgpp/optimization/function/test/Test.hpp"
%include "optimization/src/sgpp/optimization/function/test/Ackley.hpp"
%include "optimization/src/sgpp/optimization/function/test/Beale.hpp"
%include "optimization/src/sgpp/optimization/function/test/Branin.hpp"
%include "optimization/src/sgpp/optimization/function/test/Easom.hpp"
%include "optimization/src/sgpp/optimization/function/test/Eggholder.hpp"
%include "optimization/src/sgpp/optimization/function/test/GoldsteinPrice.hpp"
%include "optimization/src/sgpp/optimization/function/test/Griewank.hpp"
%include "optimization/src/sgpp/optimization/function/test/Hartman3.hpp"
%include "optimization/src/sgpp/optimization/function/test/Hartman6.hpp"
%include "optimization/src/sgpp/optimization/function/test/Himmelblau.hpp"
%include "optimization/src/sgpp/optimization/function/test/HoelderTable.hpp"
%include "optimization/src/sgpp/optimization/function/test/Michalewicz.hpp"
%include "optimization/src/sgpp/optimization/function/test/Mladineo.hpp"
%include "optimization/src/sgpp/optimization/function/test/Rastrigin.hpp"
%include "optimization/src/sgpp/optimization/function/test/Rosenbrock.hpp"
%include "optimization/src/sgpp/optimization/function/test/SHCB.hpp"
%include "optimization/src/sgpp/optimization/function/test/Schwefel.hpp"
%include "optimization/src/sgpp/optimization/function/test/Sphere.hpp"

%include "optimization/src/sgpp/optimization/gridgen/HashRefinementMultiple.hpp"
%include "optimization/src/sgpp/optimization/gridgen/IterativeGridGenerator.hpp"
%include "optimization/src/sgpp/optimization/gridgen/IterativeGridGeneratorLinearSurplus.hpp"
%include "optimization/src/sgpp/optimization/gridgen/IterativeGridGeneratorRitterNovak.hpp"

%include "optimization/src/sgpp/optimization/operation/OptimizationOpFactory.hpp"
%include "optimization/src/sgpp/optimization/operation/hash/OperationMultipleHierarchisation.hpp"

%include "optimization/src/sgpp/optimization/sle/system/System.hpp"
%include "optimization/src/sgpp/optimization/sle/system/Cloneable.hpp"
%include "optimization/src/sgpp/optimization/sle/system/Full.hpp"
%include "optimization/src/sgpp/optimization/sle/system/Hierarchisation.hpp"

%include "optimization/src/sgpp/optimization/sle/solver/Solver.hpp"
%include "optimization/src/sgpp/optimization/sle/solver/Armadillo.hpp"
%include "optimization/src/sgpp/optimization/sle/solver/Auto.hpp"
%include "optimization/src/sgpp/optimization/sle/solver/BiCGStab.hpp"
%include "optimization/src/sgpp/optimization/sle/solver/Eigen.hpp"
%include "optimization/src/sgpp/optimization/sle/solver/GaussianElimination.hpp"
%include "optimization/src/sgpp/optimization/sle/solver/Gmmpp.hpp"
%include "optimization/src/sgpp/optimization/sle/solver/UMFPACK.hpp"

%include "optimization/src/sgpp/optimization/optimizer/Optimizer.hpp"
%include "optimization/src/sgpp/optimization/optimizer/DifferentialEvolution.hpp"
%include "optimization/src/sgpp/optimization/optimizer/GradientMethod.hpp"
%include "optimization/src/sgpp/optimization/optimizer/NelderMead.hpp"
%include "optimization/src/sgpp/optimization/optimizer/Newton.hpp"
%include "optimization/src/sgpp/optimization/optimizer/NLCG.hpp"
%include "optimization/src/sgpp/optimization/optimizer/Newton.hpp"
%include "optimization/src/sgpp/optimization/optimizer/RandomSearch.hpp"

%include "optimization/src/sgpp/optimization/tools/MutexType.hpp"
%include "optimization/src/sgpp/optimization/tools/Printer.hpp"
37 changes: 37 additions & 0 deletions optimization/build/pysgpp/std_unique_ptr.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (C) 2008-today The SG++ project
// This file is part of the SG++ project. For conditions of distribution and
// use, please see the copyright notice provided with SG++ or at
// sgpp.sparsegrids.org

// source: http://stackoverflow.com/questions/27693812/how-to-handle-unique-ptrs-with-swig

namespace std {
%feature("novaluewrapper") unique_ptr;
template <typename Type>
struct unique_ptr {
typedef Type* pointer;

explicit unique_ptr(pointer Ptr);
unique_ptr(unique_ptr&& Right);
template<class Type2, Class Del2> unique_ptr(unique_ptr<Type2, Del2>&& Right);
unique_ptr(const unique_ptr& Right) = delete;

pointer operator->() const;
pointer release();
void reset(pointer __p=pointer());
void swap(unique_ptr &__u);
pointer get() const;
operator bool() const;

~unique_ptr();
};
}

%define wrap_unique_ptr(Name, Type)
%template(Name) std::unique_ptr<Type>;
%newobject std::unique_ptr<Type>::release;

%typemap(out) std::unique_ptr<Type> %{
$result = SWIG_NewPointerObj(new $1_ltype(std::move($1)), $&1_descriptor, SWIG_POINTER_OWN);
%}
%enddef
Loading

0 comments on commit 2303372

Please sign in to comment.