2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5// $Id: Normalizations.icc 667905 2015-05-18 19:07:55Z wsfreund $
6#ifndef RINGERSELECTORTOOLS_NORMALIZATIONS_ICC
7#define RINGERSELECTORTOOLS_NORMALIZATIONS_ICC
9#include "Normalizations.h"
12#include "AsgMessaging/MsgStream.h"
15 * @brief Namespace dedicated for Ringer utilities
21* @brief Namespace dedicated for Ringer pre-processing utilities
23namespace PreProcessing
27 * @brief Namespace dedicated for Ringer normalization utilities
32 * @brief Helper functions:
36// =============================================================================
38float getMax( std::vector<float> &inputSpace ) {
39 float max = std::numeric_limits<float>::min();
40 for ( std::vector<float>::const_iterator itr = inputSpace.begin();
41 itr != inputSpace.end();
43 if (std::abs(*itr) > max) {
50// =============================================================================
52float getNorm( std::vector<float> &inputSpace ){
54 for ( std::vector<float>::const_iterator itr = inputSpace.begin();
55 itr != inputSpace.end();
59 return std::abs(norm);
62// =============================================================================
64float getNorm( std::vector<float> &inputSpace, const unsigned int p ){
65 if ( p == 1) return getNorm(inputSpace);
67 for ( std::vector<float>::const_iterator itr = inputSpace.begin();
68 itr != inputSpace.end();
70 norm += std::pow(*itr,p);
72 return std::abs(std::pow(norm,1/p));
75// =============================================================================
77void applyNorm( std::vector<float> &inputSpace, const float norm ){
79 float invNorm = 1/norm;
80 for ( std::vector<float>::iterator itr = inputSpace.begin();
81 itr != inputSpace.end();
87// =============================================================================
89void applyInvNorm( std::vector<float> &inputSpace, const float invNorm ){
90 for ( std::vector<float>::iterator itr = inputSpace.begin();
91 itr != inputSpace.end();
97// =============================================================================
99void applyInvNorm( std::vector<float> &inputSpace,
100 const std::vector<float> &invNorm )
102 std::vector<float>::const_iterator itr2 = invNorm.begin();
103 for ( std::vector<float>::iterator itr = inputSpace.begin();
104 itr != inputSpace.end();
111// =============================================================================
113void applyDeslocation( std::vector<float> &inputSpace, const float deslocation )
115 for ( std::vector<float>::iterator itr = inputSpace.begin();
116 itr != inputSpace.end();
123// =============================================================================
125void applyDeslocation( std::vector<float> &inputSpace,
126 const std::vector<float>& deslocation )
128 std::vector<float>::const_iterator itr2 = deslocation.begin();
129 for ( std::vector<float>::iterator itr = inputSpace.begin();
130 itr != inputSpace.end();
137} // Private namespace
139/// Normalization interfaces:
141// =============================================================================
143void Norm1::execute(std::vector<float> &inputSpace) const {
145 ATH_MSG_DEBUG("Applying Norm1. Input space is: " << inputSpace);
147 float norm1 = getNorm(inputSpace,1);
149 ATH_MSG_DEBUG("Normalization factor is " << norm1 );
151 applyNorm(inputSpace,norm1);
153 ATH_MSG_DEBUG("Pattern space is: " << inputSpace);
157// =============================================================================
159void Norm2::execute(std::vector<float> &inputSpace) const {
161 ATH_MSG_DEBUG("Applying Norm2. Input space is: " << inputSpace);
163 float norm2 = getNorm(inputSpace,2);
165 ATH_MSG_DEBUG("Normalization factor is " << norm2 );
167 applyNorm(inputSpace,norm2);
169 ATH_MSG_DEBUG("Pattern space is: " << inputSpace);
173// =============================================================================
175void Sqrt::execute(std::vector<float> &inputSpace) const {
177 ATH_MSG_DEBUG("Applying Sqrt. Input space is: " << inputSpace);
179 float sqrtNorm = std::sqrt(std::fabs(getNorm(inputSpace,1)));
181 ATH_MSG_DEBUG("Normalization factor is " << sqrtNorm );
183 applyNorm(inputSpace,sqrtNorm);
185 ATH_MSG_DEBUG("Pattern space is: " << inputSpace);
189// =============================================================================
191void ConstantValue::execute(std::vector<float> &inputSpace) const {
193 ATH_MSG_DEBUG("Applying ConstantValue(Value: " << 1/m_constantInv
194 << "). Input space is: " << inputSpace);
196 applyInvNorm(inputSpace,m_constantInv);
198 ATH_MSG_DEBUG("Pattern space is: " << inputSpace);
202// =============================================================================
204void Spherization::execute(std::vector<float> &inputSpace) const {
206 ATH_MSG_DEBUG("Applying Spherization. Input space is: " << inputSpace);
208 if ( inputSpace.size() != m_dim ){
209 throw std::runtime_error(std::string( "Input size (") +
210 std::to_string(inputSpace.size()) + ") does not match "
211 " this pre-processing inputSpace dimension size(" +
212 std::to_string(m_dim) + ".");
214 applyDeslocation(inputSpace,m_deslocation);
215 applyInvNorm(inputSpace,m_normInv);
217 ATH_MSG_DEBUG("Pattern space is: " << inputSpace);
221// =============================================================================
223void MinMax::execute(std::vector<float> &inputSpace) const {
225 ATH_MSG_DEBUG("Applying MinMax. Input space is: " << inputSpace);
227 if ( inputSpace.size() != m_dim ){
228 throw std::runtime_error(std::string( "Input size (") +
229 std::to_string(inputSpace.size()) + ") does not match "
230 " this pre-processing inputSpace dimension size(" +
231 std::to_string(m_dim) + ".");
233 applyDeslocation(inputSpace,m_deslocation);
234 applyInvNorm(inputSpace,m_normInv);
236 ATH_MSG_DEBUG("Pattern space is: " << inputSpace);
242} // namespace Discrimination
245#endif // RINGERSELECTORTOOLS_NORMALIZATIONS_ICC
246// vim: filetype=cpp :