Ress.cxx
Go to the documentation of this file.
1 #include "WireCellUtil/Ress.h"
2 
4 
5 using namespace WireCell;
6 
8  Ress::vector_t measured,
9  const Ress::Params& params,
10  Ress::vector_t initial,
11  Ress::vector_t weights)
12 {
13  // Provide a uniform interface to RESS solving models. RESS
14  // *almost* already provides this.
15 
16  if (params.model == Ress::lasso) {
18  params.max_iter, params.tolerance, params.non_negative);
19  if (initial.size()) {
20  model.Setbeta(initial);
21  }
22  if (weights.size()) {
23  model.SetLambdaWeight(weights);
24  }
25  model.SetData(matrix, measured);
26  model.Fit();
27  return model.Getbeta();
28  }
29 
30  if (params.model == Ress::elnet) {
32  params.max_iter, params.tolerance, params.non_negative);
33  if (initial.size()) {
34  model.Setbeta(initial);
35  }
36  if (weights.size()) {
37  model.SetLambdaWeight(weights);
38  }
39  model.SetData(matrix, measured);
40  model.Fit();
41  return model.Getbeta();
42  }
43 
44  return Ress::vector_t();
45 }
46 
47 double Ress::chi2_l1(vector_t measured, vector_t solved, double lambda)
48 {
49  return 2 * lambda * solved.lpNorm<1>() * measured.size();
50 }
51 
53 {
54  return response * source;
55 }
56 
57 double Ress::chi2(vector_t measured, vector_t predicted)
58 {
59  return ( measured- predicted ).squaredNorm();
60 }
61 
62 double Ress::mean_residual(vector_t measured, vector_t predicted)
63 {
64  return ( measured - predicted ).norm() / measured.size();
65 }
double chi2(vector_t measured, vector_t predicted)
Definition: Ress.cxx:57
virtual void Setbeta(Eigen::VectorXd beta)
Definition: LinearModel.h:21
vector_t predict(matrix_t response, vector_t source)
Definition: Ress.cxx:52
vector_t solve(matrix_t response, vector_t measured, const Params &params=Params(), vector_t source=Eigen::VectorXd(), vector_t weights=Eigen::VectorXd())
Definition: Ress.cxx:7
Eigen::VectorXd vector_t
Definition: Ress.h:12
double mean_residual(vector_t measured, vector_t predicted)
Definition: Ress.cxx:62
void SetLambdaWeight(Eigen::VectorXd w)
Eigen::MatrixXd matrix_t
Definition: Ress.h:13
double chi2_l1(vector_t measured, vector_t solved, double lambda=1.0)
Definition: Ress.cxx:47
Eigen::VectorXd & Getbeta()
Definition: LinearModel.h:16
virtual void SetData(Eigen::MatrixXd X, Eigen::VectorXd y)
Definition: LinearModel.h:18
Definition: Main.h:22
double tolerance
Definition: Ress.h:25