MCPcopy Create free account
hub / github.com/Kitware/VTK / vtkPCAStatisticsNormalizeSpec

Function vtkPCAStatisticsNormalizeSpec

Filters/Statistics/vtkPCAStatistics.cxx:476–583  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

474
475//------------------------------------------------------------------------------
476static void vtkPCAStatisticsNormalizeSpec(vtkVariantArray* normData, Eigen::MatrixXd& cov,
477 vtkTable* normSpec, vtkTable* reqModel, bool triangle)
478{
479 vtkIdType i, j;
480 vtkIdType m = reqModel->GetNumberOfColumns() - 2;
481 std::map<std::string, vtkIdType> colNames;
482 // Get a list of columns of interest for this request
483 for (i = 0; i < m; ++i)
484 {
485 colNames[reqModel->GetColumn(i + 2)->GetName()] = i;
486 }
487 // Turn normSpec into a useful array.
488 std::map<std::pair<vtkIdType, vtkIdType>, double> factor;
489 vtkIdType n = normSpec->GetNumberOfRows();
490 for (vtkIdType r = 0; r < n; ++r)
491 {
492 std::map<std::string, vtkIdType>::iterator it;
493 if ((it = colNames.find(normSpec->GetValue(r, 0).ToString())) == colNames.end())
494 {
495 continue;
496 }
497 i = it->second;
498 if ((it = colNames.find(normSpec->GetValue(r, 1).ToString())) == colNames.end())
499 {
500 continue;
501 }
502 j = it->second;
503 if (j < i)
504 {
505 vtkIdType tmp = i;
506 i = j;
507 j = tmp;
508 }
509 factor[std::pair<vtkIdType, vtkIdType>(i, j)] = normSpec->GetValue(r, 2).ToDouble();
510 }
511 // Now normalize cov, recording any missing factors along the way.
512 std::ostringstream missing;
513 bool gotMissing = false;
514 std::map<std::pair<vtkIdType, vtkIdType>, double>::iterator fit;
515 if (triangle)
516 { // Normalization factors are provided for the upper triangular portion of the covariance matrix.
517 for (i = 0; i < m; ++i)
518 {
519 for (j = i; j < m; ++j)
520 {
521 double v;
522 fit = factor.find(std::pair<vtkIdType, vtkIdType>(i, j));
523 if (fit == factor.end())
524 {
525 v = 1.;
526 gotMissing = true;
527 missing << "(" << reqModel->GetColumn(i + 2)->GetName() << ","
528 << reqModel->GetColumn(j + 2)->GetName() << ") ";
529 }
530 else
531 {
532 v = fit->second;
533 }

Callers 1

DeriveMethod · 0.85

Calls 12

sqrtFunction · 0.50
GetNumberOfColumnsMethod · 0.45
GetNameMethod · 0.45
GetColumnMethod · 0.45
GetNumberOfRowsMethod · 0.45
findMethod · 0.45
ToStringMethod · 0.45
GetValueMethod · 0.45
endMethod · 0.45
ToDoubleMethod · 0.45
InsertNextValueMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected