Commits

Ruben Martinez-Cantin committed 39b1f57

Solving bug in Python cmake config in MacOS. Improved docs.

Comments (0)

Files changed (7)

cmake/PythonMagic.cmake

 
 include(FindPythonInterp)
 ## check python
-find_package(PythonLibs 2 EXACT) # using PYTHON_INCLUDE_PATH instead of PYTHON_INCLUDE_DIR
+find_package(PythonLibs 2) # using PYTHON_INCLUDE_PATH instead of PYTHON_INCLUDE_DIR
 if( NOT PYTHON_EXECUTABLE )
   # look specifically for 2.7
   find_program(PYTHON_EXECUTABLE NAMES python2.7 python27 python PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.7\\InstallPath])

doxygen/install.dox

 
 
 \subsection compile Compile the library:
-In order to compile the source code in a *nix system, run this from a terminal.
+In order to compile the source code in a *nix system, run this from a
+terminal.
 \verbatim
 >> cmake . 
 >> make
 >> sudo make install
 \endverbatim
 
-\b Important: If you use \b ccmake instead of \b cmake you will access a graphical
-interface to select features such as the include the Python and Matlab
-interfaces, debug/release mode or if you want to use shared libraries
-or not. \b Shared libraries are required to run the Python interface.
+\b Important: If you use \b ccmake instead of \b cmake you will access
+a graphical interface to select features such as the include the
+Python and Matlab interfaces, debug/release mode or if you want to use
+shared libraries or not. \b Shared libraries are required to run the
+Python interface.
 
 \subsubsection instpath Install the library in a different path
 
 and 2.7. The interface relies on Numpy arrays. If we want to select
 the option to compile the Python interface we can just run:
 \verbatim
+>> cmake -DBUILD_PYTHON=ON . 
+\endverbatim
+or 
+\verbatim
 >> ccmake . 
->> make
->> sudo make install
 \endverbatim
+and select the corresponding option.
 
-\b Important: Python requires bayesopt to be a \b shared library.
+\b Important: Python requires bayesopt to be a \b shared library. The
+option is automatically adjusted by CMake.
 
 \subsection instmatlab MATLAB/Octave interface:
 

examples/bo_display.cpp

  
   //plot
   subplot(2,1,1);
-  title("press r to run and stop");
+  title("Press r to run and stop, s to run a step and q to quit.");
   plot(x,y); set(3);
   plot(lx,ly);set("k");set("*");
   plot(x,su);set("g"); set(2);

include/gaussian_process_ign.hpp

-/** \file gaussian_process_ign.hpp 
-    \brief Gaussian process with normal-inverse-gamma hyperprior 
-           on mean and signal variance parameters. */
-/*
------------------------------------------------------------------------------
-   Copyright (C) 2011 Ruben Martinez-Cantin <rmcantin@unizar.es>
- 
-   This program is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation, either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------------------
-*/
-
-#ifndef  _GAUSSIAN_PROCESS_IGN_HPP_
-#define  _GAUSSIAN_PROCESS_IGN_HPP_
-
-#include "gauss_distribution.hpp"
-#include "hierarchical_gaussian_process.hpp"
-
-namespace bayesopt
-{
-   
-  /** \addtogroup  NonParametricProcesses */
-  /**@{*/
-
-  /**
-   * \brief Gaussian process with normal-inverse-gamma hyperprior 
-   *        on mean and signal variance parameters.
-   */
-  class GaussianProcessIGN: public HierarchicalGaussianProcess
-  {
-  public:
-    GaussianProcessIGN(size_t dim, bopt_params params);
-
-    virtual ~GaussianProcessIGN();
-
-    /** 
-     * \brief Function that returns the prediction of the GP for a query point
-     * in the hypercube [0,1].
-     * 
-     * @param query in the hypercube [0,1] to evaluate the Gaussian process
-     * @return pointer to the probability distribution.
-     */	
-    ProbabilityDistribution* prediction(const vectord &query);
-
-  private:
-
-    /** 
-     * \brief Computes the negative log likelihood of the data for all
-     * the parameters.
-     * @return value negative log likelihood
-     */
-    //    double negativeTotalLogLikelihood()
-    //{ //TODO: Implement
-    //  assert(false); };
-
-    /** 
-     * \brief Computes the negative log likelihood and its gradient of
-     * the data.
-     * @return value negative log likelihood
-     */
-    double negativeLogLikelihood();
-
-    /** 
-     * \brief Precompute some values of the prediction that do not depends on
-     * the query
-     * @return error code
-     */
-    int precomputePrediction();
-
-  private:
-    const double mAlpha, mBeta;         //!< GP prior parameters (Inv-Gamma)
-    const double mDelta2;               //!< GP prior parameters (Normal)
-
-    double mMu, mSig;                   //!< GP posterior parameters
-
-    //! Precomputed GP prediction operations
-    vectord mUInvR;
-    vectord mInvRy;
-    double mUInvRUDelta;
-    vectord mAlphaV;
-    GaussianDistribution* d_;
-  };
-  /**@}*/
-
-} //namespace bayesopt
-
-#endif

include/student_t_process.hpp

-/** \file student_t_process.hpp
-    \brief Student's t process with Jeffreys hyperprior 
-           on mean and signal variance parameters. */
-/*
--------------------------------------------------------------------------
-   This file is part of BayesOpt, an efficient C++ library for 
-   Bayesian optimization.
-
-   Copyright (C) 2011-2013 Ruben Martinez-Cantin <rmcantin@unizar.es>
- 
-   BayesOpt is free software: you can redistribute it and/or modify it 
-   under the terms of the GNU General Public License as published by
-   the Free Software Foundation, either version 3 of the License, or
-   (at your option) any later version.
-
-   BayesOpt is distributed in the hope that it will be useful, but 
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with BayesOpt.  If not, see <http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------
-*/
-
-
-#ifndef  _STUDENT_T_PROCESS_HPP_
-#define  _STUDENT_T_PROCESS_HPP_
-
-#include "student_t_distribution.hpp"
-#include "hierarchical_gaussian_process.hpp"
- 
-namespace bayesopt
-{
-  
-  /** \addtogroup  NonParametricProcesses */
-  /**@{*/
-
-  /**
-   * \brief Student's t process with Jeffreys hyperprior 
-   *        on mean and signal variance parameters.
-   */
-  class StudentTProcess: public HierarchicalGaussianProcess
-  {
-  public:
-    StudentTProcess(size_t dim, bopt_params params);
-    virtual ~StudentTProcess();
-
-    /** 
-     * \brief Function that returns the prediction of the GP for a query point
-     * in the hypercube [0,1].
-     * 
-     * @param query in the hypercube [0,1] to evaluate the Gaussian process
-     * @return pointer to the probability distribution.
-     */	
-    ProbabilityDistribution* prediction(const vectord &query);
-
-
-  private:
-
-    /** 
-     * \brief Computes the negative log likelihood and its gradient of the data.
-     * 
-     *
-     * @return value negative log likelihood
-     */
-    double negativeLogLikelihood();
-
-    /** 
-     * \brief Precompute some values of the prediction that do not depends on
-     * the query
-     * @return error code
-     */
-    int precomputePrediction();
-
-  private:
-    double mMu, mSig;                   //!< GP posterior parameters
-
-    //! Precomputed GP prediction operations
-    vectord mUInvR;     
-    vectord mInvRy;         
-    double mUInvRUDelta;
-    StudentTDistribution* d_;
-  };
-
-  /**@}*/
-
-} //namespace bayesopt
-
-
-#endif

src/gaussian_process_ign.cpp

-/*
--------------------------------------------------------------------------
-   This file is part of BayesOpt, an efficient C++ library for 
-   Bayesian optimization.
-
-   Copyright (C) 2011-2013 Ruben Martinez-Cantin <rmcantin@unizar.es>
- 
-   BayesOpt is free software: you can redistribute it and/or modify it 
-   under the terms of the GNU General Public License as published by
-   the Free Software Foundation, either version 3 of the License, or
-   (at your option) any later version.
-
-   BayesOpt is distributed in the hope that it will be useful, but 
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with BayesOpt.  If not, see <http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------
-*/
-
-#include "gaussian_process_ign.hpp"
-#include "cholesky.hpp"
-#include "trace_ublas.hpp"
-#include "gauss_distribution.hpp"
-
-namespace bayesopt
-{
-
-  using boost::numeric::ublas::inplace_solve;
-  using boost::numeric::ublas::lower_tag;
-  using boost::numeric::ublas::lower;
-  using utils::cholesky_solve;
-  using utils::cholesky_decompose;
-
-  GaussianProcessIGN::GaussianProcessIGN(size_t dim, bopt_params params):
-    GaussianProcess(dim,params), mAlpha(params.alpha), 
-    mBeta (params.beta), mDelta2(parameters.mean.s_mu[0])
-  {
-    d_ = new GaussianDistribution();
-  }  // Constructor
-
-
-
-  GaussianProcessIGN::~GaussianProcessIGN()
-  {
-    delete d_;
-  } // Default destructor
-
-
-
-
-  double GaussianProcessIGN::negativeLogLikelihood()
-  {
-    matrixd K = computeCorrMatrix();
-    size_t n = K.size1();
-    matrixd L(n,n);
-    cholesky_decompose(K,L);
-
-    vectord alphU(mMeanV);
-    inplace_solve(L,alphU,lower_tag());
-    double eta = inner_prod(alphU,alphU) + 1/mDelta2;
-  
-    vectord alphY(mGPY);
-    inplace_solve(L,alphY,lower_tag());
-    double mu     = inner_prod(alphU,alphY) / eta;
-    double YInvRY = inner_prod(alphY,alphY);
-    
-    double sigma = (mBeta + YInvRY - mu*mu*eta) / (mAlpha + (n+1) + 2);
-  
-    vectord yumu = mGPY - mMeanV*mu;
-    alphY = yumu;
-    inplace_solve(L,alphY,lower_tag());
-
-    double lik1 = inner_prod(alphY,alphY) / (2*sigma); 
-    double lik2 = utils::log_trace(L) + 0.5*n*log(sigma) + n*0.91893853320467; //log(2*pi)/2
-  
-    //TODO: This must be wrong.
-    size_t index = 0;
-    vectord th = mKernel->getHyperParameters();
-
-    return lik1 + lik2 + mBeta/2 * th(index) -
-      (mAlpha+1) * log(th(index));
-  }
-
-
-  ProbabilityDistribution* GaussianProcessIGN::prediction( const vectord &query )
-  {
-    double kn;
-    double uInvRr, rInvRr, rInvRy;
-    double meanf = mMean->getMean(query);
-
-    vectord colR = computeCrossCorrelation(query);
-    kn = (*mKernel)(query, query);
-
-#if USE_CHOL
-    vectord invRr(colR);
-    inplace_solve(mL,invRr,lower_tag());
-    rInvRr = inner_prod(invRr,invRr);
-    uInvRr = inner_prod(mUInvR, invRr);  
-    rInvRy = inner_prod(invRr, mInvRy );
-#else
-    vectord rInvR = prod(colR,mInvR);
-	
-    rInvRr = inner_prod(rInvR,colR);
-    uInvRr = inner_prod(mUInvR,colR);
-    rInvRy = inner_prod(colR,mInvRy);
-#endif
-  
-    double yPred = meanf*mMu + rInvRy;
-    double sPred = sqrt( mSig * (kn - rInvRr + (meanf - uInvRr) * (meanf - uInvRr) 
-				 / mUInvRUDelta ) );
-
-    d_->setMeanAndStd(yPred,sPred);
-    return d_;
-  }
-
-  int GaussianProcessIGN::precomputePrediction()
-  {
-    size_t nSamples = mGPXX.size();
-
-    mUInvR.resize(nSamples,false);
-    mInvRy.resize(nSamples,false);
-
-#if USE_CHOL
-    mAlphaV.resize(nSamples,false);
-    mAlphaV = mGPY;
-    cholesky_solve(mL,mAlphaV,lower());
-
-    //  vectord alphaMean(mMeanV);
-    mUInvR = mMeanV;
-    inplace_solve(mL,mUInvR,lower_tag());
-    mUInvRUDelta = inner_prod(mUInvR,mUInvR) + 1/mDelta2;
-
-    mMu = inner_prod(mMeanV,mAlphaV) / mUInvRUDelta;
-    double YInvRY = inner_prod(mGPY,mAlphaV);
-
-    mInvRy = mGPY - mMeanV*mMu;
-    inplace_solve(mL,mInvRy,lower_tag());
-#else
-    // mInvR.resize(nSamples,nSamples);
-    // mInvR.assign(boost::numeric::ublas::identity_matrix<double>(nSamples));
-    // cholesky_solve(mL,mInvR,lower());
-    mUInvR = prod(mMeanV,mInvR);
-    mUInvRUDelta = inner_prod(mUInvR,mMeanV) + 1/mDelta2;
-  
-    vectord YInvR(nSamples);
-    double YInvRY;
-  
-    mMu =  inner_prod(mUInvR,mGPY) / mUInvRUDelta;
-  
-    noalias(YInvR) = prod(mGPY,mInvR);
-    YInvRY = inner_prod(YInvR,mGPY);
-    vectord ymu = mGPY - mMeanV*mMu;
-    mInvRy = prod(mInvR,ymu);
-#endif  
-
-    mSig = (mBeta + YInvRY - mMu*mMu*mUInvRUDelta) / (mAlpha + (nSamples+1) + 2);
-  
-    return 1;
-  }
-
-} //namespace bayesopt

src/student_t_process.cpp

-/*
------------------------------------------------------------------------------
-   Copyright (C) 2011 Ruben Martinez-Cantin <rmcantin@unizar.es>
- 
-   This program is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation, either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------------------
-*/
-
-#include "student_t_process.hpp"
-#include "cholesky.hpp"
-#include "trace_ublas.hpp"
-#include "student_t_distribution.hpp"
-
-namespace bayesopt
-{
-  
-  using boost::numeric::ublas::inplace_solve;
-  using boost::numeric::ublas::lower_tag;
-  using boost::numeric::ublas::lower;
-  using utils::cholesky_decompose;
-  
-  
-  StudentTProcess::StudentTProcess(size_t dim, bopt_params params):
-    HierarchicalGaussianProcess(dim, params)
-  {
-    d_ = new StudentTDistribution();
-    if (strcmp(parameters.mean.name,"mZero") == 0)
-      {
-	FILE_LOG(logWARNING) << "Zero mean incompatible with Student's t "
-			     << "process, using one-mean instead.";
-	parameters.mean.name = "mOne";
-      }
-    setMean(parameters.mean,dim);
-  }  // Constructor
-
-
-
-  StudentTProcess::~StudentTProcess()
-  {
-    delete d_;
-  } // Default destructor
-
-
-  double StudentTProcess::negativeLogLikelihood()
-  {
-    matrixd K = computeCorrMatrix();
-    size_t n = K.size1();
-    matrixd L(n,n);
-    cholesky_decompose(K,L);
-
-    vectord alphU(mMeanV);
-    inplace_solve(L,alphU,lower_tag());
-    double eta = inner_prod(alphU,alphU);
-  
-    vectord alphY(mGPY);
-    inplace_solve(L,alphY,lower_tag());
-    double mu     = inner_prod(alphU,alphY) / eta;
-    double YInvRY = inner_prod(alphY,alphY);
-    
-    double sigma = (YInvRY - mu*mu*eta) / (n-1);
-
-    // TODO: Revise equation.
-    // Obtained from SEQUENTIAL DESIGN OF COMPUTER EXPERIMENTS
-    // TO MINIMIZE INTEGRATED RESPONSE FUNCTIONS
-    // http://www3.stat.sinica.edu.tw/statistica/oldpdf/A10n46.pdf
-    double negloglik = utils::log_trace(L) + 0.5*( (n-1)*log(sigma) + log(eta) );
-
-    return negloglik;
-  }
-
-
-  ProbabilityDistribution* StudentTProcess::prediction(const vectord &query)
-  {
-    double yPred, sPred, rInvRu, rInvRr, rInvRy;
-    double meanf = mMean->getMean(query);
-  
-    vectord colR = computeCrossCorrelation(query);
-    double kn = (*mKernel)(query, query);
-  
-#if USE_CHOL
-    vectord invRr(colR);
-    inplace_solve(mL,invRr,lower_tag());
-    rInvRr = inner_prod(invRr,invRr);
-    rInvRu = inner_prod(invRr,mUInvR);  
-    rInvRy = inner_prod(invRr, mInvRy );
-#else
-    vectord rInvR(mGPXX.size());
-    noalias(rInvR) = prod(colR,mInvR);	
-    rInvRr = inner_prod(rInvR,colR);
-    rInvRu = inner_prod(rInvR,mMeanV);
-    rInvRy = inner_prod(colR,mInvRy);
-#endif
-
-    yPred = meanf*mMu + rInvRy;
-    sPred = sqrt( mSig * (kn - rInvRr + (meanf - rInvRu) * (meanf - rInvRu) 
-			  / mUInvRUDelta ) );
-
-    d_->setMeanAndStd(yPred,sPred);
-    return d_;
-  }
-
-
-  int StudentTProcess::precomputePrediction()
-  {
-    size_t nSamples = mGPXX.size();
-    double YInvRY;
-    d_->setDof(nSamples-1);
-
-    mInvRy.resize(nSamples,false);
-
-#if USE_CHOL
-    mUInvR = mMeanV;
-    inplace_solve(mL,mUInvR,lower_tag());
-    mUInvRUDelta = inner_prod(mUInvR,mUInvR);
-
-    mInvRy = mGPY;
-    inplace_solve(mL,mInvRy,lower_tag());
-    mMu =  inner_prod(mUInvR,mInvRy) / mUInvRUDelta;
-    YInvRY = inner_prod(mInvRy,mInvRy);
-
-    mInvRy = mGPY - mMeanV*mMu;
-    inplace_solve(mL,mInvRy,lower_tag()); 
-#else
-    mUInvR = prod(mMeanV,mInvR);
-    mUInvRUDelta = inner_prod(mUInvR,mMeanV);
-    mMu =  inner_prod(mUInvR,mGPY) / mUInvRUDelta;
-    noalias(mInvRy) = prod(mInvR,mGPY); 
-    YInvRY = inner_prod(mGPY,mInvRy);
-
-    vectord yumu = mGPY - mMeanV*mMu;
-    mInvRy = prod(mInvR,yumu);
-#endif
-  
-    mSig = (YInvRY - mMu*mMu*mUInvRUDelta) / (nSamples-1);
-
-    return 1;
-  }
-
-} //namespace bayesopt
-
-