8 std::shared_ptr<KernelBase> kernel2In) :
KernelBase(kernel1In->inputDim,
9 std::max(kernel1In->coDim, kernel2In->coDim),
10 kernel1In->numParams + kernel2In->numParams),
17 cachedParams.head(kernel1In->numParams) = kernel1In->GetParams();
18 cachedParams.tail(kernel2In->numParams) = kernel2In->GetParams();
24 Eigen::Ref<const Eigen::VectorXd>
const& x2,
25 Eigen::Ref<const Eigen::VectorXd>
const& params,
26 Eigen::Ref<Eigen::MatrixXd> block)
const
31 kernel1->FillBlock(x1, x2, params.head(
kernel1->numParams), temp1);
32 kernel2->FillBlock(x1, x2, params.tail(
kernel2->numParams), temp2);
36 block = Eigen::MatrixXd(temp1.array() * temp2.array());
40 block = temp1(0,0)*temp2;
44 block = temp2(0,0)*temp1;
48 std::cerr <<
"\nERROR: Something unexpected happened with the dimensions of the kernels in this product.\n";
57 bool isSeperable =
true;
58 for(
unsigned leftDim :
kernel1->dimInds)
60 for(
unsigned rightDim :
kernel2->dimInds)
75 std::vector<std::shared_ptr<KernelBase>> output, output2;
76 output =
kernel1->GetSeperableComponents();
77 output2 =
kernel2->GetSeperableComponents();
78 output.insert(output.end(), output2.begin(), output2.end());
84 return std::vector<std::shared_ptr<KernelBase>>(1, this->
Clone());
91 std::tuple<std::shared_ptr<muq::Modeling::LinearSDE>, std::shared_ptr<muq::Modeling::LinearOperator>, Eigen::MatrixXd>
ProductKernel::GetStateSpace(boost::property_tree::ptree sdeOptions)
const
93 auto periodicCast1 = std::dynamic_pointer_cast<PeriodicKernel>(
kernel1);
94 auto periodicCast2 = std::dynamic_pointer_cast<PeriodicKernel>(
kernel2);
96 if(periodicCast1 && (!periodicCast2)){
98 }
else if((!periodicCast1) && periodicCast2){
107 throw muq::NotImplementedError(
"ERROR in ProductKernel::GetStateSpace(). The GetStateSpace() function has not been implemented for these types: \"" + type1 +
"\" and \"" + type2 +
"\"");
114 std::tuple<std::shared_ptr<muq::Modeling::LinearSDE>, std::shared_ptr<muq::Modeling::LinearOperator>, Eigen::MatrixXd>
ProductKernel::GetProductStateSpace(std::shared_ptr<PeriodicKernel>
const& kernel1,
115 std::shared_ptr<KernelBase>
const& kernel2,
116 boost::property_tree::ptree sdeOptions)
const
119 auto periodicGP =
kernel1->GetStateSpace(sdeOptions);
120 auto periodicSDE = std::get<0>(periodicGP);
122 auto periodicF = std::dynamic_pointer_cast<muq::Modeling::BlockDiagonalOperator>(periodicSDE->GetF());
125 auto periodicL = std::dynamic_pointer_cast<muq::Modeling::BlockDiagonalOperator>(periodicSDE->GetL());
128 auto otherGP =
kernel2->GetStateSpace(sdeOptions);
129 auto otherSDE = std::get<0>(otherGP);
130 auto otherF = otherSDE->GetF();
131 auto otherL = otherSDE->GetL();
132 auto otherH = std::get<1>(otherGP);
135 std::vector<std::shared_ptr<muq::Modeling::LinearOperator>> newBlocks( periodicF->GetBlocks().size() );
136 for(
int i=0; i<newBlocks.size(); ++i)
139 auto newF = std::make_shared<muq::Modeling::BlockDiagonalOperator>(newBlocks);
142 for(
int i=0; i<newBlocks.size(); ++i)
143 newBlocks.at(i) = std::make_shared<muq::Modeling::KroneckerProductOperator>(otherL, periodicL->GetBlock(i) );
145 auto newL = std::make_shared<muq::Modeling::BlockDiagonalOperator>(newBlocks);
148 Eigen::MatrixXd Hblock(1,2);
151 for(
int i=0; i<newBlocks.size(); ++i)
152 newBlocks.at(i) = std::make_shared<muq::Modeling::KroneckerProductOperator>(otherH, muq::Modeling::LinearOperator::Create(Hblock) );
154 auto newH = std::make_shared<muq::Modeling::BlockRowOperator>(newBlocks);
157 Eigen::MatrixXd periodicP = std::get<2>(periodicGP);
158 Eigen::MatrixXd otherP = std::get<2>(otherGP);
160 Eigen::MatrixXd Pinf = Eigen::MatrixXd::Zero(periodicP.rows()*otherP.rows(), periodicP.cols()*otherP.cols());
161 for(
int i=0; i<newBlocks.size(); ++i)
162 Pinf.block(2*i*otherP.rows(), 2*i*otherP.rows(), 2*otherP.rows(), 2*otherP.cols()) =
muq::Modeling::KroneckerProduct(otherP, periodicP.block(2*i,2*i,2,2));
165 Eigen::MatrixXd
const& otherQ = otherSDE->GetQ();
166 Eigen::MatrixXd Q = Eigen::MatrixXd::Zero(otherQ.rows()*periodicP.rows(), otherQ.cols()*periodicP.cols());
167 for(
int i=0; i<newBlocks.size(); ++i)
168 Q.block(2*i*otherQ.rows(), 2*i*otherQ.rows(), 2*otherQ.rows(), 2*otherQ.cols()) =
muq::Modeling::KroneckerProduct(otherQ, periodicP.block(2*i,2*i,2,2));
171 auto newSDE = std::make_shared<muq::Modeling::LinearSDE>(newF, newL, Q, sdeOptions);
172 return std::make_tuple(newSDE, newH, Pinf);
178 return std::make_shared<ProductKernel>(k1,k2);
Base class for all covariance kernels.
const unsigned int numParams
Eigen::VectorXd cachedParams
std::tuple< std::shared_ptr< muq::Modeling::LinearSDE >, std::shared_ptr< muq::Modeling::LinearOperator >, Eigen::MatrixXd > GetProductStateSpace(std::shared_ptr< PeriodicKernel > const &kernel1, std::shared_ptr< KernelBase > const &kernel2, boost::property_tree::ptree sdeOptions) const
virtual std::vector< std::shared_ptr< KernelBase > > GetSeperableComponents() override
Overridden by ProductKernel.
virtual void FillBlock(Eigen::Ref< const Eigen::VectorXd > const &x1, Eigen::Ref< const Eigen::VectorXd > const &x2, Eigen::Ref< const Eigen::VectorXd > const ¶ms, Eigen::Ref< Eigen::MatrixXd > block) const override
virtual std::tuple< std::shared_ptr< muq::Modeling::LinearSDE >, std::shared_ptr< muq::Modeling::LinearOperator >, Eigen::MatrixXd > GetStateSpace(boost::property_tree::ptree sdeOptions=boost::property_tree::ptree()) const override
Returns a state space representation of the covariance kernel.
virtual std::shared_ptr< KernelBase > Clone() const override
std::shared_ptr< KernelBase > kernel2
std::shared_ptr< KernelBase > kernel1
ProductKernel(std::shared_ptr< KernelBase > kernel1In, std::shared_ptr< KernelBase > kernel2In)
Class for virtual base functions that are not implemented.
LinearTransformMean< MeanType > operator*(Eigen::MatrixXd const &A, MeanType const &K)
Eigen::MatrixXd KroneckerProduct(Eigen::Ref< const Eigen::MatrixXd > const &A, Eigen::Ref< const Eigen::MatrixXd > const &B)
std::shared_ptr< LinearOperator > KroneckerSum(std::shared_ptr< LinearOperator > A, std::shared_ptr< LinearOperator > B)
std::string GetTypeName(PointerType const &ptr)