| 52 | ~CrossEntropy() {} |
| 53 | |
| 54 | void Init(const Metadata& metadata, data_size_t num_data) override { |
| 55 | num_data_ = num_data; |
| 56 | label_ = metadata.label(); |
| 57 | weights_ = metadata.weights(); |
| 58 | |
| 59 | CHECK_NOTNULL(label_); |
| 60 | Common::CheckElementsIntervalClosed<label_t>(label_, 0.0f, 1.0f, num_data_, GetName()); |
| 61 | Log::Info("[%s:%s]: (objective) labels passed interval [0, 1] check", GetName(), __func__); |
| 62 | |
| 63 | if (weights_ != nullptr) { |
| 64 | label_t minw; |
| 65 | double sumw; |
| 66 | Common::ObtainMinMaxSum(weights_, num_data_, &minw, static_cast<label_t*>(nullptr), &sumw); |
| 67 | if (minw < 0.0f) { |
| 68 | Log::Fatal("[%s]: at least one weight is negative", GetName()); |
| 69 | } |
| 70 | if (sumw == 0.0f) { |
| 71 | Log::Fatal("[%s]: sum of weights is zero", GetName()); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | void GetGradients(const double* score, score_t* gradients, score_t* hessians) const override { |
| 77 | if (weights_ == nullptr) { |
nothing calls this directly
no test coverage detected