------------------------------------------------------------------------------
| 474 | |
| 475 | //------------------------------------------------------------------------------ |
| 476 | static 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 | } |
no test coverage detected