13 #ifndef __LOW_RANK_GP_MODEL_BUILDER_H
14 #define __LOW_RANK_GP_MODEL_BUILDER_H
20 #include <boost/thread.hpp>
21 #include <boost/scoped_ptr.hpp>
22 #include <boost/thread/future.hpp>
24 #include "CommonTypes.h"
26 #include "DataManager.h"
28 #include "ModelInfo.h"
29 #include "ModelBuilder.h"
31 #include "Representer.h"
32 #include "StatisticalModel.h"
45 const MatrixType& _resMat) :
46 lowerInd(_lowerInd), upperInd(_upperInd), resultForPoints(_resMat) {
51 MatrixType resultForPoints;
73 lowerInd = that.lowerInd;
74 upperInd = that.upperInd;
75 resultForPoints = that.resultForPoints;
96 typedef Representer<T> RepresenterType;
97 typedef typename RepresenterType::PointType PointType;
103 typedef typename DomainType::DomainPointsListType DomainPointsListType;
140 unsigned numPointsForNystrom = 500)
const {
142 VectorType zeroVec = VectorType::Zero(
143 m_representer->GetDomain().GetNumberOfPoints()
144 * m_representer->GetDimensions());
146 typename RepresenterType::DatasetConstPointerType zeroMean =
147 m_representer->SampleVectorToSample(zeroVec);
150 numPointsForNystrom);
163 typename RepresenterType::DatasetConstPointerType mean,
165 unsigned numComponents,
166 unsigned numPointsForNystrom = 500)
const {
169 std::vector<PointType> domainPoints = m_representer->GetDomain().GetDomainPoints();
170 unsigned numDomainPoints = m_representer->GetDomain().GetNumberOfPoints();
174 boost::scoped_ptr<Nystrom<T> > nystrom(
Nystrom<T>::Create(m_representer, kernel, numComponents, numPointsForNystrom));
180 std::vector<boost::future<EigenfunctionComputationResult>* > futvec;
183 unsigned numChunks = boost::thread::hardware_concurrency() + 1;
185 for (
unsigned i = 0; i <= numChunks; i++) {
187 unsigned chunkSize =
static_cast< unsigned >( ceil( static_cast< float >( numDomainPoints ) / static_cast< float >( numChunks ) ) );
188 unsigned lowerInd = i * chunkSize;
190 std::min( static_cast< unsigned >(numDomainPoints),
191 (i + 1) * chunkSize);
193 if (lowerInd >= upperInd) {
197 boost::future<EigenfunctionComputationResult>* fut =
new boost::future<EigenfunctionComputationResult>(
199 this, nystrom.get(), &kernel, numComponents, domainPoints, lowerInd, upperInd)));
200 futvec.push_back(fut);
203 MatrixType pcaBasis = MatrixType::Zero(numDomainPoints * kernelDim, numComponents);
206 for (
unsigned i = 0; i < futvec.size(); i++) {
208 pcaBasis.block(res.lowerInd * kernelDim, 0,
209 (res.upperInd - res.lowerInd) * kernelDim, pcaBasis.cols()) =
215 VectorType pcaVariance = nystrom->getEigenvalues();
217 RowVectorType mu = m_representer->SampleToSampleVector(mean);
220 m_representer, mu, pcaBasis, pcaVariance, 0);
224 typename BuilderInfo::DataInfoList dataInfo;
227 typename BuilderInfo::ParameterInfoList bi;
228 bi.push_back(BuilderInfo::KeyValuePair(
"NoiseVariance", Utils::toString(0)));
229 bi.push_back(BuilderInfo::KeyValuePair(
"KernelInfo", kernel.
GetKernelInfo()));
232 BuilderInfo builderInfo(
"LowRankGPModelBuilder", dataInfo, bi);
234 ModelInfo::BuilderInfoList biList( 1, builderInfo );;
254 const MatrixValuedKernelType* kernel,
unsigned numEigenfunctions,
255 const std::vector<PointType> & domainPts,
256 unsigned lowerInd,
unsigned upperInd)
const {
258 unsigned kernelDim = kernel->GetDimension();
260 assert(upperInd <= domainPts.size());
263 MatrixType resMat = MatrixType::Zero((upperInd - lowerInd) * kernelDim,
268 for (
unsigned i = lowerInd; i < upperInd; i++) {
270 PointType pti = domainPts[i];
274 return EigenfunctionComputationResult(lowerInd, upperInd, resMat);
283 m_representer(representer) {
287 LowRankGPModelBuilder(
const LowRankGPModelBuilder& orig);
288 LowRankGPModelBuilder& operator=(
const LowRankGPModelBuilder& rhs);
296 #endif // __LOW_RANK_GP_MODEL_BUILDER_H
StatisticalModelType * BuildNewZeroMeanModel(const MatrixValuedKernelType &kernel, unsigned numComponents, unsigned numPointsForNystrom=500) const
Definition: LowRankGPModelBuilder.h:138
StatisticalModelType * BuildNewModel(typename RepresenterType::DatasetConstPointerType mean, const MatrixValuedKernelType &kernel, unsigned numComponents, unsigned numPointsForNystrom=500) const
Definition: LowRankGPModelBuilder.h:162
MatrixType computeEigenfunctionsAtPoint(const PointType &pt) const
Definition: Nystrom.h:46
Common base class for all the model builder classes.
Definition: ModelBuilder.h:54
virtual ~LowRankGPModelBuilder()
Definition: LowRankGPModelBuilder.h:126
virtual unsigned GetDimension() const
Definition: Kernels.h:82
A trivial representer, that does no representation at all, but works directly with vectorial data...
Definition: TrivialVectorialRepresenter.h:83
virtual std::string GetKernelInfo() const =0
static LowRankGPModelBuilder * Create(const RepresenterType *representer)
Definition: LowRankGPModelBuilder.h:110
void Delete()
Definition: LowRankGPModelBuilder.h:119
Holds information about the data and the parameters used by a specific modelbuilder.
Definition: ModelInfo.h:125
void SetModelInfo(const ModelInfo &modelInfo)
Definition: StatisticalModel.hxx:486
stores meta information about the model, such as e.g. the name (uri) of the datasets used to build th...
Definition: ModelInfo.h:61
Definition: LowRankGPModelBuilder.h:92
Definition: LowRankGPModelBuilder.h:41
A Point/Value pair that is used to specify a value at a given point.
Definition: StatisticalModel.h:100