Skip to content

Commit e72fa93

Browse files
committed
Build for vanilla armadillo
Note, this may lead to reduced performance as I've had to remove calls to custom cholbacksub and solve_tri functions. Will look into whether Armadillo correctly implements these performance gains yet...
1 parent c4a9123 commit e72fa93

File tree

6 files changed

+75
-95
lines changed

6 files changed

+75
-95
lines changed

CMakeLists.txt

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,50 @@
1-
cmake_minimum_required(VERSION 2.4.6)
2-
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
1+
cmake_minimum_required(VERSION 2.8.3)
2+
project(gp)
3+
set(CMAKE_BUILD_TYPE Debug)
34

4-
# Set the build type. Options are:
5-
# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
6-
# Debug : w/ debug symbols, w/o optimization
7-
# Release : w/o debug symbols, w/ optimization
8-
# RelWithDebInfo : w/ debug symbols, w/ optimization
9-
# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
10-
#set(ROS_BUILD_TYPE RelWithDebInfo)
11-
set(ROS_BUILD_TYPE Debug)
12-
13-
rosbuild_init()
14-
15-
#set the default path for built executables to the "bin" directory
16-
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
17-
#set the default path for built libraries to the "lib" directory
18-
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
5+
find_package(ARMADILLO REQUIRED)
196

7+
include_directories(
8+
${ARMADILLO_INCLUDE_DIRS})
209

2110
#common commands for building c++ executables and libraries
22-
rosbuild_add_library(${PROJECT_NAME}
23-
src/GP.cc
11+
add_library(${PROJECT_NAME}
12+
src/GP.cc
2413
src/KernelFunction.cc
2514
src/MeanFunction.cc
2615
src/CGOptimizer.cc)
27-
target_link_libraries(${PROJECT_NAME}
28-
armadillo
16+
target_link_libraries(${PROJECT_NAME}
17+
${ARMADILLO_LIBRARIES}
2918
gsl)
3019
if(APPLE)
3120
set_target_properties(${PROJECT_NAME}
3221
PROPERTIES LINK_FLAGS "${LINK_FLAGS} -framework Accelerate -framework vecLib")
3322
endif()
3423

35-
rosbuild_add_library(SPGP
36-
src/SPGP.cc
37-
src/GP.cc
24+
add_library(SPGP
25+
src/SPGP.cc
26+
src/GP.cc
3827
src/KernelFunction.cc
3928
src/MeanFunction.cc
4029
src/CGOptimizer.cc)
4130
target_link_libraries(SPGP
42-
armadillo
31+
${ARMADILLO_LIBRARIES}
4332
gsl)
4433
if(APPLE)
4534
set_target_properties(SPGP
4635
PROPERTIES LINK_FLAGS "${LINK_FLAGS} -framework Accelerate -framework vecLib")
4736
endif()
4837

49-
rosbuild_add_executable(test src/test.cc)
50-
target_link_libraries(test armadillo ${PROJECT_NAME})
38+
add_executable(test_gp src/test.cc)
39+
target_link_libraries(test_gp ${ARMADILLO_LIBRARIES} ${PROJECT_NAME})
5140
if(APPLE)
52-
set_target_properties(test
41+
set_target_properties(test_gp
5342
PROPERTIES LINK_FLAGS "${LINK_FLAGS} -framework Accelerate")
5443
endif()
5544

56-
rosbuild_add_executable(test_spgp src/test_spgp.cc)
57-
target_link_libraries(test_spgp armadillo SPGP)
45+
add_executable(test_spgp src/test_spgp.cc)
46+
target_link_libraries(test_spgp ${ARMADILLO_LIBRARIES} SPGP)
5847
if(APPLE)
5948
set_target_properties(test_spgp
6049
PROPERTIES LINK_FLAGS "${LINK_FLAGS} -framework Accelerate")
61-
endif()
50+
endif()

Makefile

Lines changed: 0 additions & 1 deletion
This file was deleted.

manifest.xml

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/GP.cc

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ void GP::ComputeAlpha()
125125
timer.tic();
126126
#endif
127127
this->alpha.set_size(y.n_cols);
128-
cholbacksub(alpha, this->L, trans(this->y - this->meanvals));
128+
// cholbacksub(alpha, this->L, trans(this->y - this->meanvals));
129+
solve(alpha, trimatu(this->L), trans(this->y - this->meanvals));
129130
this->need_to_compute_alpha = false;
130131
#ifdef BENCHMARK
131132
printf("%f seconds to compute alpha\n", timer.toc());
@@ -138,7 +139,8 @@ void GP::ComputeW()
138139
if(this->need_to_compute_w) {
139140
ComputeChol();
140141
this->W.set_size(this->L.n_rows, this->L.n_cols);
141-
cholbacksub(W, this->L, eye<Mat<REAL> >(K.n_rows, K.n_cols));
142+
// cholbacksub(W, this->L, eye<Mat<REAL> >(K.n_rows, K.n_cols));
143+
solve(W, trimatu(this->L), eye<Mat<REAL> >(K.n_rows, K.n_cols));
142144
this->need_to_compute_w = false;
143145
}
144146
}
@@ -321,7 +323,8 @@ void GP::Predict(const Col<REAL> &Xs, REAL &mu, REAL &var)
321323

322324
// trans(L) is LOWER TRIANGULAR
323325
Col<REAL> v(kstar.n_elem);
324-
solve_tri(v, trans(L), kstar, false);
326+
// solve_tri(v, trans(L), kstar, false);
327+
solve(v, trimatu(trans(L)), kstar);
325328
REAL kxsxs = this->kernel->Eval(Xs, Xs);
326329
var = kxsxs - dot(v, v) + this->s2_n;
327330
}
@@ -375,12 +378,15 @@ void GP::PredictGradient(const Col<REAL> &Xs, Col<REAL> &grad, Col<REAL> &vargra
375378
Col<REAL> v(kstar.n_elem);
376379
Col<REAL> tmp(kstar.n_elem);
377380
Mat<REAL> dv(kstar.n_elem, grad.n_elem);
378-
solve_tri(v, trans(L), kstar, false);
381+
// solve_tri(v, trans(L), kstar, false);
382+
solve(v, trimatu(trans(L)), kstar);
379383

380384
//printf("About to solve for dv\n");
381-
solve_tri(tmp, trans(L), trans(dkstar.row(0)), false);
385+
// solve_tri(tmp, trans(L), trans(dkstar.row(0)), false);
386+
solve(tmp, trimatu(trans(L)), trans(dkstar.row(0)));
382387
dv.col(0) = tmp;
383-
solve_tri(tmp, trans(L), trans(dkstar.row(1)), false);
388+
// solve_tri(tmp, trans(L), trans(dkstar.row(1)), false);
389+
solve(tmp, trimatu(trans(L)), trans(dkstar.row(1)));
384390
dv.col(1) = tmp;
385391
//dv.print("dv: ");
386392

@@ -408,7 +414,7 @@ void GP::OptimizeNoiseParam(REAL &noise_param, int max_iterations)
408414

409415
Col<REAL> noise_params(1);
410416
noise_params(0) = noise_param;
411-
417+
412418
opt.Initialize(noise_params, &f_eval_noise, &df_eval_noise, &fdf_eval_noise, 0.5, 0.1);
413419
opt.Optimize(noise_params, max_iterations);
414420
}
@@ -432,7 +438,7 @@ void GP::OptimizeKernelParam(Col<REAL> &kernel_param, int max_iterations)
432438
double f_eval_mean(const gsl_vector *x, void *param)
433439
{
434440
GP *gp_obj = reinterpret_cast<GP*>(param);
435-
441+
436442
Col<REAL> mean_param(gp_obj->GetMeanFunction()->GetParamDim());
437443
for(unsigned int i=0; i < mean_param.n_elem; ++i) {
438444
mean_param(i) = gsl_vector_get(x, i);
@@ -441,14 +447,14 @@ double f_eval_mean(const gsl_vector *x, void *param)
441447
gp_obj->SetMeanFuncParams(mean_param);
442448

443449
double ret = -gp_obj->ComputeLikelihood();
444-
450+
445451
return ret;
446452
}
447453

448454
void df_eval_mean(const gsl_vector *x, void *param, gsl_vector *g)
449455
{
450456
GP *gp_obj = reinterpret_cast<GP*>(param);
451-
457+
452458
Col<REAL> mean_param(gp_obj->GetMeanFunction()->GetParamDim());
453459
for(unsigned int i=0; i < mean_param.n_elem; ++i) {
454460
mean_param(i) = gsl_vector_get(x, i);
@@ -472,26 +478,26 @@ void fdf_eval_mean(const gsl_vector *x, void *param, double *f, gsl_vector *g)
472478
double f_eval_kernel(const gsl_vector *x, void *param)
473479
{
474480
GP *gp_obj = reinterpret_cast<GP*>(param);
475-
481+
476482
Col<REAL> kernel_param(gp_obj->GetKernelFunction()->GetParamDim());
477483
for(unsigned int i=0; i < kernel_param.n_elem; ++i) {
478484
kernel_param(i) = gsl_vector_get(x, i);
479485
if(kernel_param(i) < 1e-6) {
480486
return 1e6;
481487
}
482488
}
483-
489+
484490
gp_obj->SetKernelFuncParams(kernel_param);
485491

486492
double ret = -gp_obj->ComputeLikelihood();
487-
493+
488494
return ret;
489495
}
490496

491497
void df_eval_kernel(const gsl_vector *x, void *param, gsl_vector *g)
492498
{
493499
GP *gp_obj = reinterpret_cast<GP*>(param);
494-
500+
495501
Col<REAL> kernel_param(gp_obj->GetKernelFunction()->GetParamDim());
496502
for(unsigned int i=0; i < kernel_param.n_elem; ++i) {
497503
kernel_param(i) = gsl_vector_get(x, i);
@@ -515,17 +521,17 @@ void fdf_eval_kernel(const gsl_vector *x, void *param, double *f, gsl_vector *g)
515521
double f_eval_noise(const gsl_vector *x, void *param)
516522
{
517523
GP *gp_obj = reinterpret_cast<GP*>(param);
518-
524+
519525
REAL noise_param;
520526
noise_param = gsl_vector_get(x, 0);
521527
if(noise_param < 1e-6) {
522528
return 1e6;
523529
}
524-
530+
525531
gp_obj->SetNoise(noise_param);
526532

527533
double ret = -gp_obj->ComputeLikelihood();
528-
534+
529535
return ret;
530536
}
531537

0 commit comments

Comments
 (0)