From fd04e78ad9217e087cc83b4fff7fb4732ef31638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana?= Date: Fri, 29 Sep 2023 18:50:25 +0200 Subject: [PATCH] Restore sample.cc --- sample/sample.cc | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) diff --git a/sample/sample.cc b/sample/sample.cc index 89c491c..9d7175f 100644 --- a/sample/sample.cc +++ b/sample/sample.cc @@ -58,52 +58,6 @@ pair>, vector> extract_indices(vector indices, vect int main(int argc, char** argv) { - torch::Tensor weights_ = torch::full({ 10 }, 1.0 / 10, torch::kFloat64); - torch::Tensor y_ = torch::tensor({ 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }, torch::kInt32); - torch::Tensor ypred = torch::tensor({ 1, 1, 1, 0, 0, 1, 1, 1, 1, 0 }, torch::kInt32); - cout << "Initial weights_: " << endl; - for (int i = 0; i < 10; i++) { - cout << weights_.index({ i }).item() << ", "; - } - cout << "end." << endl; - cout << "y_: " << endl; - for (int i = 0; i < 10; i++) { - cout << y_.index({ i }).item() << ", "; - } - cout << "end." << endl; - cout << "ypred: " << endl; - for (int i = 0; i < 10; i++) { - cout << ypred.index({ i }).item() << ", "; - } - cout << "end." << endl; - auto mask_wrong = ypred != y_; - auto mask_right = ypred == y_; - auto masked_weights = weights_ * mask_wrong.to(weights_.dtype()); - double epsilon_t = masked_weights.sum().item(); - cout << "epsilon_t: " << epsilon_t << endl; - double wt = (1 - epsilon_t) / epsilon_t; - cout << "wt: " << wt << endl; - double alpha_t = epsilon_t == 0 ? 1 : 0.5 * log(wt); - cout << "alpha_t: " << alpha_t << endl; - // Step 3.2: Update weights for next classifier - // Step 3.2.1: Update weights of wrong samples - cout << "exp(alpha_t): " << exp(alpha_t) << endl; - cout << "exp(-alpha_t): " << exp(-alpha_t) << endl; - weights_ += mask_wrong.to(weights_.dtype()) * exp(alpha_t) * weights_; - // Step 3.2.2: Update weights of right samples - weights_ += mask_right.to(weights_.dtype()) * exp(-alpha_t) * weights_; - // Step 3.3: Normalise the weights - double totalWeights = torch::sum(weights_).item(); - cout << "totalWeights: " << totalWeights << endl; - cout << "Before normalization: " << endl; - for (int i = 0; i < 10; i++) { - cout << weights_.index({ i }).item() << endl; - } - weights_ = weights_ / totalWeights; - cout << "After normalization: " << endl; - for (int i = 0; i < 10; i++) { - cout << weights_.index({ i }).item() << endl; - } map datasets = { {"diabetes", true}, {"ecoli", true},