Skip to content

Commit

Permalink
Adding CMakeLists.txt for examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
mblum committed Oct 9, 2012
1 parent 8f4939f commit c1b2e0d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
17 changes: 13 additions & 4 deletions CMakeLists.txt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
# Copyright 2011 University of Freiburg.

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

# if no option is given, standard is release
IF(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Release)
ENDIF(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)

set(CMAKE_CXX_FLAGS_RELEASE "-DCLSQUARE -Wall -O2")
set(CMAKE_CXX_FLAGS_DEBUG "-DCLSQUARE -Wall -g")

PROJECT(libgp CXX C)

OPTION(BUILD_TESTS "Build tests" ON)
OPTION(BUILD_EXAMPLES "Build examples" ON)

SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_MODULE_PATH})

Expand All @@ -21,10 +31,9 @@ INCLUDE("Sources.cmake")
ADD_LIBRARY(gp ${LIBGP_SRC} ${LIBGP_INTERFACES})

# ----- Add example targets -----
ADD_EXECUTABLE(gpdense examples/gp_example_dense.cc)
# ADD_EXECUTABLE(gpsparse examples/gp_example_sparse.cc)
TARGET_LINK_LIBRARIES(gpdense gp)
# TARGET_LINK_LIBRARIES(gpsparse gp)
IF(BUILD_EXAMPLES)
ADD_SUBDIRECTORY(examples)
ENDIF()

# ----- Testing -----
IF(BUILD_TESTS)
Expand Down
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ADD_EXECUTABLE(gpdense gp_example_dense.cc)
TARGET_LINK_LIBRARIES(gpdense gp)
5 changes: 2 additions & 3 deletions include/gp_sparse.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ namespace libgp {
{
public:

/** Create and instance of SparseGaussianProcess with given input dimensionality and covariance function. */
/** Create an instance of SparseGaussianProcess with given input dimensionality and covariance function. */
SparseGaussianProcess (size_t input_dim, std::string covf_def);

/** Create and instance of SparseGaussianProcess from file. */
/** Create an instance of SparseGaussianProcess from file. */
SparseGaussianProcess (const char * filename);

virtual ~SparseGaussianProcess ();

virtual void compute();

protected:
Eigen::SimplicialCholesky<Eigen::SparseMatrix<double>, Eigen::Lower> solver;

};
}
Expand Down
1 change: 0 additions & 1 deletion src/rprop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ void RProp::maximize(GaussianProcess * gp, size_t n, bool verbose)
grad_old = grad;
gp->covf().set_loghyper(params);
}
std::cout << params << std::endl;
}

}
6 changes: 4 additions & 2 deletions tests/CMakeLists.txt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ INCLUDE(ExternalProject)
ExternalProject_Add(googletest
SVN_REPOSITORY "http://googletest.googlecode.com/svn/tags/release-1.6.0"
INSTALL_COMMAND ""
UPDATE_COMMAND ""
PREFIX "gtest"
)

# ----- Testing -----
INCLUDE_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR}/googletest-prefix/src/googletest/include)
LINK_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR}/googletest-prefix/src/googletest-build)
INCLUDE_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR}/gtest/src/googletest/include)
LINK_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR}/gtest/src/googletest-build)

# ----- Add sources -----
INCLUDE("Sources.cmake")
Expand Down
17 changes: 9 additions & 8 deletions tests/rprop_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,31 @@

TEST(RPropTest, Test1)
{
int input_dim = 3, param_dim = 5;
libgp::GaussianProcess * gp = new libgp::GaussianProcess(input_dim, "CovSum ( CovSEard, CovNoise)");
int input_dim = 3, param_dim = 3;
libgp::GaussianProcess * gp = new libgp::GaussianProcess(input_dim, "CovSum ( CovSEiso, CovNoise)");
Eigen::VectorXd params(param_dim);
params << 1, 2, 3, 0, -2;
params << 0, 0, log(0.01);
gp->covf().set_loghyper(params);
int n = 400;
int n = 500;
Eigen::MatrixXd X(n, input_dim);
X.setRandom();
X = X*10;
Eigen::VectorXd y = gp->covf().draw_random_sample(X);
for(size_t i = 0; i < n; ++i) {
double x[input_dim];
for(int j = 0; j < input_dim; ++j) x[j] = X(i,j);
gp->add_pattern(x, y(i));
}

params << 0, 0, 0, 0, 0;

params << -1, -1, -1;
gp->covf().set_loghyper(params);

libgp::RProp rprop;
rprop.init();
rprop.maximize(gp);
rprop.maximize(gp, 50, 0);

std::cout << gp->covf().get_loghyper() << std::endl;
ASSERT_NEAR(0, gp->covf().get_loghyper()(0), 0.1);
ASSERT_NEAR(0, gp->covf().get_loghyper()(1), 0.1);

}

Expand Down

0 comments on commit c1b2e0d

Please sign in to comment.