Create List of Sample Measurements#

Synopsis#

Create a lsit of sample measurements.

Results#

Output:

id = 0         measurement vector = [1, 2, 4]  frequency = 1
id = 1         measurement vector = [2, 4, 5]  frequency = 1
id = 2         measurement vector = [3, 8, 6]  frequency = 1
id = 0         measurement vector = [1, 2, 4]  frequency = 1
id = 1         measurement vector = [2, 4, 5]  frequency = 1
id = 2         measurement vector = [3, 8, 6]  frequency = 1
Size = 3
Total frequency = 3

Code#

C++#

#include "itkListSample.h"
#include "itkVector.h"

int
main()
{
  using MeasurementVectorType = itk::Vector<float, 3>;
  using SampleType = itk::Statistics::ListSample<MeasurementVectorType>;
  auto sample = SampleType::New();

  MeasurementVectorType mv;
  mv[0] = 1.0;
  mv[1] = 2.0;
  mv[2] = 4.0;

  sample->PushBack(mv);

  sample->Resize(3);

  mv[0] = 2.0;
  mv[1] = 4.0;
  mv[2] = 5.0;
  sample->SetMeasurementVector(1, mv);

  mv[0] = 3.0;
  mv[1] = 8.0;
  mv[2] = 6.0;
  sample->SetMeasurementVector(2, mv);

  for (unsigned long i = 0; i < sample->Size(); ++i)
  {
    std::cout << "id = " << i << "\t measurement vector = " << sample->GetMeasurementVector(i)
              << "\t frequency = " << sample->GetFrequency(i) << std::endl;
  }

  SampleType::Iterator iter = sample->Begin();

  while (iter != sample->End())
  {
    std::cout << "id = " << iter.GetInstanceIdentifier() << "\t measurement vector = " << iter.GetMeasurementVector()
              << "\t frequency = " << iter.GetFrequency() << std::endl;
    ++iter;
  }

  std::cout << "Size = " << sample->Size() << std::endl;
  std::cout << "Total frequency = " << sample->GetTotalFrequency() << std::endl;

  return EXIT_SUCCESS;
}

Classes demonstrated#

template<typename TMeasurementVector>
class ListSample : public itk::Statistics::Sample<TMeasurementVector>

This class is the native implementation of the a Sample with an STL container.

ListSample stores measurements in a list type structure (as opposed to a Histogram, etc.). ListSample allows duplicate measurements. ListSample is not sorted.

ListSample does not allow the user to specify the frequency of a measurement directly. The GetFrequency() methods returns 1 if the measurement exists in the list, 0 otherwise.

See

Sample, Histogram

ITK Sphinx Examples:

See itk::Statistics::ListSample for additional documentation.