PPCKO: Principal Predictive Components for Estimating an Autoregressive Operator
 
Loading...
Searching...
No Matches
removing_nan_imp.hpp
Go to the documentation of this file.
1// Copyright (c) 2024 Andrea Enrico Franzoni (andreaenrico.franzoni@gmail.com)
2//
3// This file is part of PPCKO
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of PPCKO and associated documentation files (the PPCKO software), to deal
7// PPCKO without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of PPCKO, and to permit persons to whom PPCKO is
10// furnished to do so, subject to the following conditions:
11//
12// PPCKO IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17// OUT OF OR IN CONNECTION WITH PPCKO OR THE USE OR OTHER DEALINGS IN
18// PPCKO.
19
20#include "removing_nan.hpp"
21
22
28
29
34template<typename T,REM_NAN MA_t>
35void
36removing_nan<T,MA_t>::row_removal(Eigen::Block<Eigen::Matrix<T,-1,-1>,1>& row, MAT<REM_NAN::MR>)
37{
38 //counting how many non-NaNs
39 const auto n_not_nan = std::count_if(row.begin(),row.end(),[](T el){return !std::isnan(el);});
40 std::vector<T> el_not_nan;
41 el_not_nan.reserve(n_not_nan);
42 //saving non-NaNs values
43 std::copy_if(row.begin(),row.end(),std::back_inserter(el_not_nan),[](T el){return !std::isnan(el);});
44 //evaluating their mean
45 const T mean = std::accumulate(el_not_nan.begin(),el_not_nan.end(),static_cast<T>(0),std::plus{})/static_cast<T>(n_not_nan);
46 el_not_nan.clear();
47 //replacing
48 std::replace_if(row.begin(),row.end(),[](T el){return std::isnan(el);},mean);
49}
50
51
56template<typename T,REM_NAN MA_t>
57void
58removing_nan<T,MA_t>::row_removal(Eigen::Block<Eigen::Matrix<T,-1,-1>,1>& row, MAT<REM_NAN::ZR>)
59{
60 std::replace_if(row.begin(),row.end(),[](T el){return std::isnan(el);},static_cast<T>(0));
61}
Contains the class to remove (dummy and not dummy) NaNs.
std::integral_constant< REM_NAN, MA_t > MAT
Definition removing_nan.hpp:53