diff options
| author | Patrick Simianer <p@simianer.de> | 2011-11-21 12:21:08 +0100 | 
|---|---|---|
| committer | Patrick Simianer <p@simianer.de> | 2011-11-21 12:21:08 +0100 | 
| commit | 574e2336348e5d3960b3232209d01845b40e6ea8 (patch) | |
| tree | 958921d46db445acf3506a8f5620429682a4362a /dtrain/test/log_reg_dyer | |
| parent | 868d01c156914faaf85335c86374cc8f47a61b96 (diff) | |
added pro stuff,clean up
Diffstat (limited to 'dtrain/test/log_reg_dyer')
| -rw-r--r-- | dtrain/test/log_reg_dyer/bin_class.cc | 4 | ||||
| -rw-r--r-- | dtrain/test/log_reg_dyer/bin_class.h | 22 | ||||
| -rw-r--r-- | dtrain/test/log_reg_dyer/log_reg.cc | 39 | ||||
| -rw-r--r-- | dtrain/test/log_reg_dyer/log_reg.h | 14 | 
4 files changed, 0 insertions, 79 deletions
| diff --git a/dtrain/test/log_reg_dyer/bin_class.cc b/dtrain/test/log_reg_dyer/bin_class.cc deleted file mode 100644 index 19bcde25..00000000 --- a/dtrain/test/log_reg_dyer/bin_class.cc +++ /dev/null @@ -1,4 +0,0 @@ -#include "bin_class.h" - -Objective::~Objective() {} - diff --git a/dtrain/test/log_reg_dyer/bin_class.h b/dtrain/test/log_reg_dyer/bin_class.h deleted file mode 100644 index 3466109a..00000000 --- a/dtrain/test/log_reg_dyer/bin_class.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _BIN_CLASS_H_ -#define _BIN_CLASS_H_ - -#include <vector> -#include "sparse_vector.h" - -struct TrainingInstance { -  // TODO add other info? loss for MIRA-type updates? -  SparseVector<double> x_feature_map; -  bool y; -}; - -struct Objective { -  virtual ~Objective(); - -  // returns f(x) and f'(x) -  virtual double ObjectiveAndGradient(const SparseVector<double>& x, -                  const std::vector<TrainingInstance>& training_instances, -                  SparseVector<double>* g) const = 0; -}; - -#endif diff --git a/dtrain/test/log_reg_dyer/log_reg.cc b/dtrain/test/log_reg_dyer/log_reg.cc deleted file mode 100644 index ec2331fe..00000000 --- a/dtrain/test/log_reg_dyer/log_reg.cc +++ /dev/null @@ -1,39 +0,0 @@ -#include "log_reg.h" - -#include <vector> -#include <cmath> - -#include "sparse_vector.h" - -using namespace std; - -double LogisticRegression::ObjectiveAndGradient(const SparseVector<double>& x, -                              const vector<TrainingInstance>& training_instances, -                              SparseVector<double>* g) const { -  double cll = 0; -  for (int i = 0; i < training_instances.size(); ++i) { -    const double dotprod = training_instances[i].x_feature_map.dot(x); // TODO no bias, if bias, add x[0] -    double lp_false = dotprod; -    double lp_true = -dotprod; -    if (0 < lp_true) { -      lp_true += log1p(exp(-lp_true)); -      lp_false = log1p(exp(lp_false)); -    } else { -      lp_true = log1p(exp(lp_true)); -      lp_false += log1p(exp(-lp_false)); -    } -    lp_true *= -1; -    lp_false *= -1; -    if (training_instances[i].y) {  // true label -      cll -= lp_true; -      (*g) -= training_instances[i].x_feature_map * exp(lp_false); -      // (*g)[0] -= exp(lp_false); // bias -    } else {                  // false label -      cll -= lp_false; -      (*g) += training_instances[i].x_feature_map * exp(lp_true); -      // g += corpus[i].second * exp(lp_true); -    } -  } -  return cll; -} - diff --git a/dtrain/test/log_reg_dyer/log_reg.h b/dtrain/test/log_reg_dyer/log_reg.h deleted file mode 100644 index ecc560b8..00000000 --- a/dtrain/test/log_reg_dyer/log_reg.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _LOG_REG_H_ -#define _LOG_REG_H_ - -#include <vector> -#include "sparse_vector.h" -#include "bin_class.h" - -struct LogisticRegression : public Objective { -  double ObjectiveAndGradient(const SparseVector<double>& x, -                              const std::vector<TrainingInstance>& training_instances, -                              SparseVector<double>* g) const; -}; - -#endif | 
