! \brief This class used to convert feature values into bin, * and store some meta information for bin*/
| 63 | /*! \brief This class used to convert feature values into bin, |
| 64 | * and store some meta information for bin*/ |
| 65 | class BinMapper { |
| 66 | public: |
| 67 | BinMapper(); |
| 68 | BinMapper(const BinMapper& other); |
| 69 | explicit BinMapper(const void* memory); |
| 70 | ~BinMapper(); |
| 71 | |
| 72 | bool CheckAlign(const BinMapper& other) const { |
| 73 | if (num_bin_ != other.num_bin_) { |
| 74 | return false; |
| 75 | } |
| 76 | if (missing_type_ != other.missing_type_) { |
| 77 | return false; |
| 78 | } |
| 79 | if (bin_type_ == BinType::NumericalBin) { |
| 80 | for (int i = 0; i < num_bin_; ++i) { |
| 81 | if (bin_upper_bound_[i] != other.bin_upper_bound_[i]) { |
| 82 | return false; |
| 83 | } |
| 84 | } |
| 85 | } else { |
| 86 | for (int i = 0; i < num_bin_; i++) { |
| 87 | if (bin_2_categorical_[i] != other.bin_2_categorical_[i]) { |
| 88 | return false; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | /*! \brief Get number of bins */ |
| 96 | inline int num_bin() const { return num_bin_; } |
| 97 | /*! \brief Missing Type */ |
| 98 | inline MissingType missing_type() const { return missing_type_; } |
| 99 | /*! \brief True if bin is trivial (contains only one bin) */ |
| 100 | inline bool is_trivial() const { return is_trivial_; } |
| 101 | /*! \brief Sparsity of this bin ( num_zero_bins / num_data ) */ |
| 102 | inline double sparse_rate() const { return sparse_rate_; } |
| 103 | /*! |
| 104 | * \brief Save binary data to file |
| 105 | * \param file File want to write |
| 106 | */ |
| 107 | void SaveBinaryToFile(const VirtualFileWriter* writer) const; |
| 108 | /*! |
| 109 | * \brief Mapping bin into feature value |
| 110 | * \param bin |
| 111 | * \return Feature value of this bin |
| 112 | */ |
| 113 | inline double BinToValue(uint32_t bin) const { |
| 114 | if (bin_type_ == BinType::NumericalBin) { |
| 115 | return bin_upper_bound_[bin]; |
| 116 | } else { |
| 117 | return bin_2_categorical_[bin]; |
| 118 | } |
| 119 | } |
| 120 | /*! |
| 121 | * \brief Get sizes in byte of this object |
| 122 | */ |
nothing calls this directly
no outgoing calls
no test coverage detected