34 #ifndef SHARK_MODELS_KERNELS_EVAL_SKIP_MISSING_FEATURES_H 35 #define SHARK_MODELS_KERNELS_EVAL_SKIP_MISSING_FEATURES_H 44 #include <boost/optional.hpp> 45 #include <boost/math/special_functions/fpclassify.hpp> 57 template <
typename InputType,
typename InputTypeT1,
typename InputTypeT2>
60 const InputTypeT1& inputA,
61 const InputTypeT2& inputB)
70 typedef typename InputType::value_type InputValueType;
71 std::vector<InputValueType> tempInputA;
72 std::vector<InputValueType> tempInputB;
73 tempInputA.reserve(inputA.size());
74 tempInputB.reserve(inputB.size());
75 for (std::size_t index = 0; index < inputA.size(); ++index)
78 if (!boost::math::isnan(inputA(index)) && !boost::math::isnan(inputB(index)))
80 tempInputA.push_back(inputA(index));
81 tempInputB.push_back(inputB(index));
85 SIZE_CHECK(tempInputA.size() == tempInputB.size());
89 std::copy(tempInputA.begin(),tempInputA.end(),validInputA.begin());
90 std::copy(tempInputB.begin(),tempInputB.end(),validInputB.begin());
93 return kernelFunction.
eval(validInputA, validInputB);
103 template <
typename InputType,
typename InputTypeT1,
typename InputTypeT2,
typename InputTypeT3>
106 const InputTypeT1& inputA,
107 const InputTypeT2& inputB,
108 InputTypeT3
const& missingness)
120 typedef typename InputType::value_type InputValueType;
121 std::vector<InputValueType> tempInputA;
122 std::vector<InputValueType> tempInputB;
123 tempInputA.resize(inputA.size());
124 tempInputB.resize(inputB.size());
125 for (std::size_t index = 0; index < inputA.size(); ++index)
127 if (!boost::math::isnan(inputA(index)) && !boost::math::isnan(inputB(index)) && !boost::math::isnan(missingness(index)))
129 tempInputA.push_back(inputA(index));
130 tempInputB.push_back(inputB(index));
134 SIZE_CHECK(tempInputA.size() == tempInputB.size());
136 InputType validInputA(tempInputA.size());
137 InputType validInputB(tempInputA.size());
138 for (std::size_t i = 0; i < tempInputA.size(); ++i)
140 validInputA(i) = tempInputA[i];
141 validInputB(i) = tempInputB[i];
145 return kernelFunction.
eval(validInputA, validInputB);
150 #endif // SHARK_MODELS_KERNELS_EVAL_SKIP_MISSING_FEATURES_H