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

Method Derive

Filters/Statistics/vtkDescriptiveStatistics.cxx:402–548  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

400
401//------------------------------------------------------------------------------
402void vtkDescriptiveStatistics::Derive(vtkStatisticalModel* modelData)
403{
404 auto* primaryTab = modelData ? modelData->GetTable(vtkStatisticalModel::Learned, 0) : nullptr;
405 if (!primaryTab)
406 {
407 return;
408 }
409
410 int numDoubles = 5;
411 std::string doubleNames[] = { "Standard Deviation", "Variance", "Skewness", "Kurtosis", "Sum" };
412
413 // Create table for derived statistics
414 vtkIdType nRow = primaryTab->GetNumberOfRows();
415 vtkTable* derivedTab = vtkTable::New();
416 vtkDoubleArray* doubleCol;
417 for (int j = 0; j < numDoubles; ++j)
418 {
419 if (!derivedTab->GetColumnByName(doubleNames[j].c_str()))
420 {
421 doubleCol = vtkDoubleArray::New();
422 doubleCol->SetName(doubleNames[j].c_str());
423 doubleCol->SetNumberOfTuples(nRow);
424 derivedTab->AddColumn(doubleCol);
425 doubleCol->Delete();
426 }
427 }
428
429 // Storage for standard deviation, variance, skewness, kurtosis, sum
430 std::vector<double> derivedVals(numDoubles);
431
432 for (int i = 0; i < nRow; ++i)
433 {
434 double mom2 = primaryTab->GetValueByName(i, "M2").ToDouble();
435 double mom3 = primaryTab->GetValueByName(i, "M3").ToDouble();
436 double mom4 = primaryTab->GetValueByName(i, "M4").ToDouble();
437
438 vtkTypeInt64 numSamples = primaryTab->GetValueByName(i, "Cardinality").ToTypeInt64();
439
440 if (!numSamples)
441 {
442 derivedVals[0] = std::numeric_limits<double>::quiet_NaN();
443 derivedVals[1] = std::numeric_limits<double>::quiet_NaN();
444 derivedVals[2] = std::numeric_limits<double>::quiet_NaN();
445 derivedVals[3] = std::numeric_limits<double>::quiet_NaN();
446 derivedVals[4] = std::numeric_limits<double>::quiet_NaN();
447
448 for (int j = 0; j < numDoubles; ++j)
449 {
450 derivedTab->SetValueByName(i, doubleNames[j].c_str(), derivedVals[j]);
451 }
452
453 continue;
454 }
455
456 double mean = primaryTab->GetValueByName(i, "Mean").ToDouble();
457
458 if (mom2 * mom2 <= FLT_EPSILON * std::abs(mean))
459 {

Callers

nothing calls this directly

Calls 15

GetColumnByNameMethod · 0.80
GetValueByNameMethod · 0.80
ToTypeInt64Method · 0.80
SetValueByNameMethod · 0.80
SetNumberOfTablesMethod · 0.80
DeleteMethod · 0.65
NewFunction · 0.50
absFunction · 0.50
sqrtFunction · 0.50
GetTableMethod · 0.45
GetNumberOfRowsMethod · 0.45

Tested by

no test coverage detected