VTK-m  2.0
ComputeNDEntropy.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_ComputeNDEntropy_h
12 #define vtk_m_worklet_ComputeNDEntropy_h
13 
15 
16 namespace vtkm
17 {
18 namespace worklet
19 {
20 namespace histogram
21 {
22 // For each bin, calculate its information content (log2)
24 {
25 public:
26  using ControlSignature = void(FieldIn freq, FieldOut informationContent);
27  using ExecutionSignature = void(_1, _2);
28 
30 
31  VTKM_CONT
33  : FreqSum(_freqSum)
34  {
35  }
36 
37  template <typename FreqType>
38  VTKM_EXEC void operator()(const FreqType& freq, vtkm::Float64& informationContent) const
39  {
40  vtkm::Float64 p = ((vtkm::Float64)freq) / FreqSum;
41  if (p > 0)
42  informationContent = -1 * p * vtkm::Log2(p);
43  else
44  informationContent = 0;
45  }
46 };
47 }
48 }
49 } // namespace vtkm::worklet
50 
51 #endif // vtk_m_worklet_ComputeNDEntropy_h
vtkm::worklet::histogram::SetBinInformationContent::FreqSum
vtkm::Float64 FreqSum
Definition: ComputeNDEntropy.h:29
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::WorkletMapField::FieldOut
A control signature tag for output fields.
Definition: WorkletMapField.h:60
vtkm::worklet::histogram::SetBinInformationContent::operator()
VTKM_EXEC void operator()(const FreqType &freq, vtkm::Float64 &informationContent) const
Definition: ComputeNDEntropy.h:38
DispatcherMapField.h
vtkm::worklet::histogram::SetBinInformationContent
Definition: ComputeNDEntropy.h:23
vtkm::Log2
VTKM_EXEC_CONT vtkm::Float32 Log2(vtkm::Float32 x)
Computes the logarithm base 2 of x.
Definition: Math.h:1514
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::histogram::SetBinInformationContent::ExecutionSignature
void(_1, _2) ExecutionSignature
Definition: ComputeNDEntropy.h:27
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::worklet::histogram::SetBinInformationContent::SetBinInformationContent
VTKM_CONT SetBinInformationContent(vtkm::Float64 _freqSum)
Definition: ComputeNDEntropy.h:32
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::worklet::histogram::SetBinInformationContent::ControlSignature
void(FieldIn freq, FieldOut informationContent) ControlSignature
Definition: ComputeNDEntropy.h:26
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38