本文整理汇总了C++中eigen::MatrixXd::ldlt方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixXd::ldlt方法的具体用法?C++ MatrixXd::ldlt怎么用?C++ MatrixXd::ldlt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::MatrixXd
的用法示例。
在下文中一共展示了MatrixXd::ldlt方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
Eigen::VectorXd operator()(const F& obj, Eigen::VectorXd x) const {
Eigen::VectorXd g, d;
Eigen::MatrixXd G;
LineSearch lineSearch;
obj(x, g);
obj(x, G);
DEBUG_PRINT(x);
DEBUG_PRINT(g);
DEBUG_PRINT(G);
DEBUG_PRINT(G.ldlt().solve(g));
while(g.norm() > 10e-10) {
#if DEBUG
std::cout << std::string(20, '-') << std::endl;
#endif
d = G.ldlt().solve(-g);
DEBUG_PRINT(G.ldlt().solve(-g).transpose());
DEBUG_PRINT(G.ldlt().vectorD());
Real a = 1.;
a = lineSearch(obj, x, d, a);
DEBUG_PRINT(a);
DEBUG_PRINT(obj(x));
x = x + a * d;
obj(x, g);
obj(x, G);
DEBUG_PRINT(x.transpose());
DEBUG_PRINT(g.transpose());
// DEBUG_PRINT(G);
}
return x;
}
示例2: ICPEnergyMinimization
void Registration::ICPEnergyMinimization(const Point3DSet* pRef, const Point3DSet* pOrigin, const MagicMath::HomoMatrix4* pTransInit,
std::vector<int>& sampleIndex, std::vector<int>& correspondIndex, MagicMath::HomoMatrix4* pTransDelta)
{
//DebugLog << "Registration::ICPEnergyMinimization" << std::endl;
int pcNum = sampleIndex.size();
Eigen::MatrixXd matA(pcNum, 6);
Eigen::VectorXd vecB(pcNum, 1);
for (int i = 0; i < pcNum; i++)
{
MagicMath::Vector3 norRef = pRef->GetPoint(correspondIndex.at(i))->GetNormal();
MagicMath::Vector3 posRef = pRef->GetPoint(correspondIndex.at(i))->GetPosition();
MagicMath::Vector3 posPC = pTransInit->TransformPoint( pOrigin->GetPoint(sampleIndex.at(i))->GetPosition() );
vecB(i) = (posRef - posPC) * norRef;
MagicMath::Vector3 coffTemp = posPC.CrossProduct(norRef);
matA(i, 0) = coffTemp[0];
matA(i, 1) = coffTemp[1];
matA(i, 2) = coffTemp[2];
matA(i, 3) = norRef[0];
matA(i, 4) = norRef[1];
matA(i, 5) = norRef[2];
}
Eigen::MatrixXd matAT = matA.transpose();
Eigen::MatrixXd matCoefA = matAT * matA;
Eigen::MatrixXd vecCoefB = matAT * vecB;
Eigen::VectorXd res = matCoefA.ldlt().solve(vecCoefB);
pTransDelta->Unit();
pTransDelta->SetValue(0, 1, -res(2));
pTransDelta->SetValue(0, 2, res(1));
pTransDelta->SetValue(0, 3, res(3));
pTransDelta->SetValue(1, 0, res(2));
pTransDelta->SetValue(1, 2, -res(0));
pTransDelta->SetValue(1, 3, res(4));
pTransDelta->SetValue(2, 0, -res(1));
pTransDelta->SetValue(2, 1, res(0));
pTransDelta->SetValue(2, 3, res(5));
//print result
/*DebugLog << "MatA: " << std::endl;
DebugLog << 1 << " " << -res(2) << " " << res(1) << " " << res(3) << std::endl;
DebugLog << res(2) << " " << 1 << " " << -res(0) << " " << res(4) << std::endl;
DebugLog << -res(1) << " " << res(0) << " " << 1 << " " << res(5) << std::endl;*/
}
示例3: LearnSpectralParameters
void TensorJTree::LearnSpectralParameters()
{
for (int i = 0; i < node_list->size(); ++i)
{
node_list->at(i)->MarkMultModes();
FindObservationPartitions(i);
}
for (int i = 0; i < node_list->size(); ++i)
{
node_list->at(i)->MarkObservableRepresentation();
}
for (int i = 0; i < node_list->size(); ++i)
{
cout << i;
cout << "\n";
node_list->at(i)->ComputeObservableRepresentation();
}
for (int i = 0; i < node_list->size(); ++i)
{
node_list->at(i)->FinalizeObservableRepresentation();
}
for (int i = 0; i < node_list->size(); ++i)
{
cout << i;
cout << "\n";
vector<double> big_forward_vec;
// big_forward_vec.reserve(10000);
Matrix big_back_matrix;
// big_back_matrix.Reserve(10000);
bool invModesExist = node_list->at(i)->InvModesExists();
if (invModesExist)
{
vector<Tensor*>& forward_list = node_list->at(i)->GetForwardList();
vector<Tensor*>& extra_list = node_list->at(i)->GetExtraList();
Tensor& X = node_list->at(i)->GetTransformTensor().GetTensor();
vector<int> result_dims = X.Dims();
assert(forward_list.size() == extra_list.size());
vector<int> inv_group_modes = node_list->at(i)->GetInvModeGroup();
vector<int> inv_modes = node_list->at(i)->GetInvModes();
for (int j = 0; j < forward_list.size(); ++j)
{
Tensor& forward_tensor = *(forward_list[j]);
Tensor& back_tensor = *(extra_list[j]);
if (j == 0)
{
Tensor::CreateLinearSystem(big_forward_vec, big_back_matrix, X, back_tensor, forward_tensor, inv_group_modes, inv_modes);
}
else
{
vector<double> forward_vec;
Matrix back_matrix;
Tensor::CreateLinearSystem(forward_vec, back_matrix, X, back_tensor, forward_tensor, inv_group_modes, inv_modes);
VectorPlus::Concat(big_forward_vec, forward_vec);
big_back_matrix.MatrixConcat(back_matrix);
}
}
Eigen::MatrixXd A(big_back_matrix.Dim(0), big_back_matrix.Dim(1));
for (int j = 0; j < big_back_matrix.Dim(0); ++j)
{
for (int k = 0; k < big_back_matrix.Dim(1); ++k)
{
A(j,k) = big_back_matrix.At(j,k);
}
}
Eigen::VectorXd b(big_forward_vec.size());
for (int j = 0; j < big_forward_vec.size(); ++j)
{
b(j) = big_forward_vec.at(j);
}
//cout << "yee";
Eigen::MatrixXd newA = A.transpose() * A;
Eigen::MatrixXd newb = A.transpose() * b;
Eigen::VectorXd res = newA.ldlt().solve(newb);
//cout << "yeeldlt solved";
//Eigen::VectorXd res = A.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(b);
//cout << "yeesvdsolved";
// solve the linear system here
Tensor result_tensor(result_dims);
for (int j = 0; j < res.size(); ++j)
{
result_tensor.Set(j, res(j));
}
Tensor& curr_result = node_list->at(i)->GetTransformTensor().GetTensor();
// assert(Tensor::Diff(result_tensor, curr_result) < .0001);
//.........这里部分代码省略.........
示例4: LearnTemplateSpectralParameters
//.........这里部分代码省略.........
if (invModesExist)
{
for (int j = 0; j < i_cliques.size(); ++j)
{
cout << j;
cout << "\n";
if (node_list->at(i_cliques[0])->is_invalid())
{
assert(0);
continue;
}
int index = i_cliques[j];
vector<Tensor*>& forward_list = node_list->at(index)->GetForwardList();
vector<Tensor*>& extra_list = node_list->at(index)->GetExtraList();
Tensor& X = node_list->at(index)->GetTransformTensor().GetTensor();
if (j == 0)
{
result_dims = X.Dims();
}
assert(forward_list.size() == extra_list.size());
vector<int> inv_group_modes = node_list->at(index)->GetInvModeGroup();
vector<int> inv_modes = node_list->at(index)->GetInvModes();
for (int k = 0; k < forward_list.size(); ++k)
{
Tensor& forward_tensor = *(forward_list[k]);
Tensor& back_tensor = *(extra_list[k]);
if (j == 0 && k == 0)
{
Tensor::CreateLinearSystem(big_forward_vec, big_back_matrix, X, back_tensor, forward_tensor, inv_group_modes, inv_modes);
}
else
{
vector<double> forward_vec;
Matrix back_matrix;
cout << "yeebeforesystem";
Tensor::CreateLinearSystem(forward_vec, back_matrix, X, back_tensor, forward_tensor, inv_group_modes, inv_modes);
cout << "yeeaftersystem";
VectorPlus::Concat(big_forward_vec, forward_vec);
big_back_matrix.MatrixConcat(back_matrix);
cout << "yeeafterconcat";
}
}
node_list->at(index)->DeleteForwardList();
node_list->at(index)->DeleteExtraList();
}
cout << big_back_matrix.Dim(0);
cout << "\n";
cout << big_back_matrix.Dim(1);
cout << "\n";
Eigen::MatrixXd A(big_back_matrix.Dim(0), big_back_matrix.Dim(1));
cout << "allocatedbigone";
for (int j = 0; j < big_back_matrix.Dim(0); ++j)
{
for (int k = 0; k < big_back_matrix.Dim(1); ++k)
{
(A)(j,k) = big_back_matrix.At(j,k);
}
}
Eigen::VectorXd b(big_forward_vec.size());
for (int j = 0; j < big_forward_vec.size(); ++j)
{
b(j) = big_forward_vec.at(j);
}
cout << "before solve";
cout << "\n";
Eigen::MatrixXd newA = A.transpose() * (A);
Eigen::MatrixXd newb = A.transpose() * b;
Eigen::VectorXd res = newA.ldlt().solve(newb);
cout << "after solve";
cout << "\n";
// solve the linear system here
Tensor result_tensor(result_dims);
for (int j = 0; j < res.size(); ++j)
{
result_tensor.Set(j, res(j));
}
Tensor& curr_result = node_list->at(i_cliques[0])->GetTransformTensor().GetTensor();
// assert(Tensor::Diff(result_tensor, curr_result) < .0001);
for (int j = 0; j < i_cliques.size(); ++j)
{
node_list->at(i_cliques[j])->SetTransformTensor(result_tensor);
}
}
}
}