VTK-m  2.0
NDimsEntropy.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 
11 #ifndef vtk_m_worklet_NDimsEntropy_h
12 #define vtk_m_worklet_NDimsEntropy_h
13 
14 #include <vtkm/Math.h>
15 #include <vtkm/cont/Algorithm.h>
16 #include <vtkm/cont/ArrayHandle.h>
22 
23 #include <vtkm/cont/Field.h>
24 
25 namespace vtkm
26 {
27 namespace worklet
28 {
29 
31 {
32 public:
33  void SetNumOfDataPoints(vtkm::Id _numDataPoints)
34  {
35  NumDataPoints = _numDataPoints;
36  NdHistogram.SetNumOfDataPoints(_numDataPoints);
37  }
38 
39  // Add a field and the bin for this field
40  // Return: rangeOfRange is min max value of this array
41  // binDelta is delta of a bin
42  template <typename HandleType>
43  void AddField(const HandleType& fieldArray, vtkm::Id numberOfBins)
44  {
45  vtkm::Range range;
46  vtkm::Float64 delta;
47 
48  NdHistogram.AddField(fieldArray, numberOfBins, range, delta);
49  }
50 
51  // Execute the entropy computation filter given
52  // fields and number of bins of each fields
53  // Returns:
54  // Entropy (log2) of the field of the data
56  {
57  std::vector<vtkm::cont::ArrayHandle<vtkm::Id>> binIds;
59  NdHistogram.Run(binIds, freqs);
60 
62  vtkm::Id initFreqSumValue = 0;
63  vtkm::Id freqSum = vtkm::cont::Algorithm::Reduce(freqs, initFreqSumValue, vtkm::Sum());
64 
66  vtkm::cont::ArrayHandle<vtkm::Float64> informationContent;
68  static_cast<vtkm::Float64>(freqSum));
70  setBinInformationContentDispatcher(binWorklet);
71  setBinInformationContentDispatcher.Invoke(freqs, informationContent);
72 
74  vtkm::Float64 initEntropyValue = 0;
75  vtkm::Float64 entropy =
76  vtkm::cont::Algorithm::Reduce(informationContent, initEntropyValue, vtkm::Sum());
77 
78  return entropy;
79  }
80 
81 private:
84 };
85 }
86 } // namespace vtkm::worklet
87 
88 #endif // vtk_m_worklet_NDimsEntropy_h
vtkm::cont::ArrayHandle< vtkm::Id >
ArrayHandle.h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::NDimsEntropy::NdHistogram
vtkm::worklet::NDimsHistogram NdHistogram
Definition: NDimsEntropy.h:82
WorkletMapField.h
vtkm::worklet::NDimsEntropy::SetNumOfDataPoints
void SetNumOfDataPoints(vtkm::Id _numDataPoints)
Definition: NDimsEntropy.h:33
ComputeNDEntropy.h
vtkm::worklet::NDimsHistogram::SetNumOfDataPoints
void SetNumOfDataPoints(vtkm::Id _numDataPoints)
Definition: NDimsHistogram.h:35
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
DispatcherMapField.h
vtkm::worklet::histogram::SetBinInformationContent
Definition: ComputeNDEntropy.h:23
vtkm::worklet::NDimsEntropy::AddField
void AddField(const HandleType &fieldArray, vtkm::Id numberOfBins)
Definition: NDimsEntropy.h:43
vtkm::Sum
Binary Predicate that takes two arguments argument x, and y and returns sum (addition) of the two val...
Definition: BinaryOperators.h:33
vtkm::worklet::DispatcherMapField
Dispatcher for worklets that inherit from WorkletMapField.
Definition: DispatcherMapField.h:25
Math.h
Algorithm.h
vtkm::worklet::NDimsEntropy::NumDataPoints
vtkm::Id NumDataPoints
Definition: NDimsEntropy.h:83
vtkm::worklet::NDimsHistogram::Run
void Run(std::vector< vtkm::cont::ArrayHandle< vtkm::Id >> &binId, vtkm::cont::ArrayHandle< vtkm::Id > &freqs)
Definition: NDimsHistogram.h:99
vtkm::worklet::NDimsEntropy::Run
vtkm::Float64 Run()
Definition: NDimsEntropy.h:55
vtkm::worklet::NDimsHistogram
Definition: NDimsHistogram.h:32
vtkm::cont::Algorithm::Reduce
static VTKM_CONT U Reduce(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, U initialValue)
Definition: Algorithm.h:656
vtkm::worklet::NDimsHistogram::AddField
void AddField(const HandleType &fieldArray, vtkm::Id numberOfBins, vtkm::Range &rangeOfValues, vtkm::Float64 &binDelta)
Definition: NDimsHistogram.h:48
ArrayHandleCounting.h
Field.h
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::worklet::NDimsEntropy
Definition: NDimsEntropy.h:30
NDimsHistogram.h
vtkm::Range
Represent a continuous scalar range of values.
Definition: Range.h:31