Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiGP #274

Merged
merged 3 commits into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions docs/tutorials/gp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ We assume that our samples are in a vector called ``samples`` and that our obser
.. literalinclude:: ../../src/tutorials/gp.cpp
:language: c++
:linenos:
:lines: 79-88
:lines: 77-86

Basic usage
------------
Expand All @@ -23,14 +23,14 @@ We first create a basic GP with an Exponential kernel (``kernel::Exp<Params>``)
.. literalinclude:: ../../src/tutorials/gp.cpp
:language: c++
:linenos:
:lines: 61-74
:lines: 61-72

The type of the GP is defined by the following lines:

.. literalinclude:: ../../src/tutorials/gp.cpp
:language: c++
:linenos:
:lines: 89-93
:lines: 87-91

To use the GP, we need :

Expand All @@ -40,7 +40,7 @@ To use the GP, we need :
.. literalinclude:: ../../src/tutorials/gp.cpp
:language: c++
:linenos:
:lines: 94-99
:lines: 92-97

Here we assume that the noise is the same for all samples and that it is equal to 0.01.

Expand All @@ -57,7 +57,7 @@ To visualize the predictions of the GP, we can query it for many points and reco
.. literalinclude:: ../../src/tutorials/gp.cpp
:language: c++
:linenos:
:lines: 101-112
:lines: 99-110


Hyper-parameter optimization
Expand All @@ -71,7 +71,7 @@ A new GP type is defined as follows:
.. literalinclude:: ../../src/tutorials/gp.cpp
:language: c++
:linenos:
:lines: 114-118
:lines: 112-116

It uses the default values for the parameters of ``SquaredExpARD``:

Expand All @@ -85,7 +85,7 @@ After calling the ``compute()`` method, the hyper-parameters can be optimized by
.. literalinclude:: ../../src/tutorials/gp.cpp
:language: c++
:linenos:
:lines: 121-123
:lines: 119-121


We can have a look at the difference between the two GPs:
Expand Down Expand Up @@ -115,7 +115,7 @@ We can also save our optimized GP model:
.. literalinclude:: ../../src/tutorials/gp.cpp
:language: c++
:linenos:
:lines: 140-141
:lines: 138-139

This will create a directory called ``myGP`` with several files (the GP data, kernel hyperparameters etc.). If we want a binary format (i.e., more compact), we can replace the ``TextArchive`` by ``BinaryArchive``.

Expand All @@ -124,6 +124,6 @@ To the load a saved model, we can do the following:
.. literalinclude:: ../../src/tutorials/gp.cpp
:language: c++
:linenos:
:lines: 143-144
:lines: 141-142

Note that we need to have the same kernel and mean function (i.e., the same GP type) as the one used for saving.
3 changes: 0 additions & 3 deletions src/examples/mono_dim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ BO_PARAMS(std::cout,

struct opt_rprop : public defaults::opt_rprop {
};

struct opt_parallelrepeater : public defaults::opt_parallelrepeater {
};
};)

struct fit_eval {
Expand Down
3 changes: 0 additions & 3 deletions src/examples/obs_multi_auto_mean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ struct Params {
struct stop_maxiterations {
BO_PARAM(int, iterations, 100);
};

struct opt_parallelrepeater : defaults::opt_parallelrepeater {
};
};

template <typename Params, typename Model>
Expand Down
1 change: 1 addition & 0 deletions src/limbo/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
///@defgroup model_opt_defaults

#include <limbo/model/gp.hpp>
#include <limbo/model/multi_gp.hpp>
#include <limbo/model/sparsified_gp.hpp>

#include <limbo/model/gp/kernel_lf_opt.hpp>
Expand Down
8 changes: 4 additions & 4 deletions src/limbo/model/gp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace limbo {
/// useful because the model might be created before knowing anything about the process
GP() : _dim_in(-1), _dim_out(-1), _inv_kernel_updated(false) {}

/// useful because the model might be created before having samples
/// useful because the model might be created before having samples
GP(int dim_in, int dim_out)
: _dim_in(dim_in), _dim_out(dim_out), _kernel_function(dim_in), _mean_function(dim_out), _inv_kernel_updated(false) {}

Expand Down Expand Up @@ -153,7 +153,7 @@ namespace limbo {

/**
\\rst
return :math:`\mu`, :math:`\sigma^2` (unormalized). If there is no sample, return the value according to the mean function. Using this method instead of separate calls to mu() and sigma() is more efficient because some computations are shared between mu() and sigma().
return :math:`\mu`, :math:`\sigma^2` (un-normalized). If there is no sample, return the value according to the mean function. Using this method instead of separate calls to mu() and sigma() is more efficient because some computations are shared between mu() and sigma().
\\endrst
*/
std::tuple<Eigen::VectorXd, double> query(const Eigen::VectorXd& v) const
Expand Down Expand Up @@ -193,14 +193,14 @@ namespace limbo {
/// return the number of dimensions of the input
int dim_in() const
{
assert(_dim_in != -1); // need to compute first !
assert(_dim_in != -1); // need to compute first!
return _dim_in;
}

/// return the number of dimensions of the output
int dim_out() const
{
assert(_dim_out != -1); // need to compute first !
assert(_dim_out != -1); // need to compute first!
return _dim_out;
}

Expand Down
3 changes: 1 addition & 2 deletions src/limbo/model/gp/hp_opt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@

#include <Eigen/Core>

#include <limbo/opt/parallel_repeater.hpp>
#include <limbo/opt/rprop.hpp>

namespace limbo {
namespace model {
namespace gp {
///@ingroup model_opt
///base class for optimization of the hyper-parameters of a GP
template <typename Params, typename Optimizer = opt::ParallelRepeater<Params, opt::Rprop<Params>>>
template <typename Params, typename Optimizer = opt::Rprop<Params>>
struct HPOpt {
public:
HPOpt() : _called(false) {}
Expand Down
9 changes: 4 additions & 5 deletions src/limbo/model/gp/kernel_lf_opt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@
#define LIMBO_MODEL_GP_KERNEL_LF_OPT_HPP

#include <limbo/model/gp/hp_opt.hpp>
#include <limbo/tools/random_generator.hpp>

namespace limbo {
namespace model {
namespace gp {
///@ingroup model_opt
///optimize the likelihood of the kernel only
template <typename Params, typename Optimizer = opt::ParallelRepeater<Params, opt::Rprop<Params>>>
template <typename Params, typename Optimizer = opt::Rprop<Params>>
struct KernelLFOpt : public HPOpt<Params, Optimizer> {
public:
template <typename GP>
Expand Down Expand Up @@ -96,8 +95,8 @@ namespace limbo {
const GP& _original_gp;
};
};
}
}
}
} // namespace gp
} // namespace model
} // namespace limbo

#endif
9 changes: 4 additions & 5 deletions src/limbo/model/gp/kernel_loo_opt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@
#define LIMBO_MODEL_GP_KERNEL_LOO_OPT_HPP

#include <limbo/model/gp/hp_opt.hpp>
#include <limbo/tools/random_generator.hpp>

namespace limbo {
namespace model {
namespace gp {
///@ingroup model_opt
///optimize the likelihood of the kernel only
template <typename Params, typename Optimizer = opt::ParallelRepeater<Params, opt::Rprop<Params>>>
template <typename Params, typename Optimizer = opt::Rprop<Params>>
struct KernelLooOpt : public HPOpt<Params, Optimizer> {
public:
template <typename GP>
Expand Down Expand Up @@ -96,8 +95,8 @@ namespace limbo {
const GP& _original_gp;
};
};
}
}
}
} // namespace gp
} // namespace model
} // namespace limbo

#endif
9 changes: 4 additions & 5 deletions src/limbo/model/gp/kernel_mean_lf_opt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@
#define LIMBO_MODEL_GP_KERNEL_MEAN_LF_OPT_HPP

#include <limbo/model/gp/hp_opt.hpp>
#include <limbo/tools/random_generator.hpp>

namespace limbo {
namespace model {
namespace gp {
///@ingroup model_opt
///optimize the likelihood of both the kernel and the mean (try to align the mean function)
template <typename Params, typename Optimizer = opt::ParallelRepeater<Params, opt::Rprop<Params>>>
template <typename Params, typename Optimizer = opt::Rprop<Params>>
struct KernelMeanLFOpt : public HPOpt<Params, Optimizer> {
public:
template <typename GP>
Expand Down Expand Up @@ -109,8 +108,8 @@ namespace limbo {
const GP& _original_gp;
};
};
}
}
}
} // namespace gp
} // namespace model
} // namespace limbo

#endif
9 changes: 4 additions & 5 deletions src/limbo/model/gp/mean_lf_opt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@
#define LIMBO_MODEL_GP_MEAN_LF_OPT_HPP

#include <limbo/model/gp/hp_opt.hpp>
#include <limbo/tools/random_generator.hpp>

namespace limbo {
namespace model {
namespace gp {
///@ingroup model_opt
///optimize the likelihood of the mean only (try to align the mean function)
template <typename Params, typename Optimizer = opt::ParallelRepeater<Params, opt::Rprop<Params>>>
template <typename Params, typename Optimizer = opt::Rprop<Params>>
struct MeanLFOpt : public HPOpt<Params, Optimizer> {
public:
template <typename GP>
Expand Down Expand Up @@ -99,8 +98,8 @@ namespace limbo {
GP _original_gp;
};
};
}
}
}
} // namespace gp
} // namespace model
} // namespace limbo

#endif
Loading