Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
wire-cell-build
ress
test
test_ress_largem.cxx
Go to the documentation of this file.
1
#include "
WireCellRess/LassoModel.h
"
2
#include "
WireCellRess/ElasticNetModel.h
"
3
4
#include <Eigen/Dense>
5
using namespace
Eigen
;
6
7
#include <iostream>
8
using namespace
std
;
9
10
void
test_model
(
WireCell::LinearModel
&
m
, MatrixXd&
G
, VectorXd&
W
);
11
void
test_lasso
(
WireCell::LassoModel
&
m
, MatrixXd&
G
, VectorXd&
W
);
12
void
print_results
(
WireCell::LinearModel
&
m
, VectorXd&
C
);
13
14
int
main
(
int
argc
,
char
*
argv
[])
15
{
16
// std::srand((unsigned int) time(0));
17
18
const
int
N_CELL = 500;
19
const
int
N_NZERO = 50;
20
const
int
N_WIRE =
int
(N_CELL * 0.5);
21
22
VectorXd
C
= VectorXd::Zero(N_CELL);
23
for
(
int
i=0; i<N_NZERO; i++) {
24
int
index
=
int
( N_CELL/2 * (VectorXd::Random(1)(0)+1) );
25
// cout << index << endl;
26
C(index) = VectorXd::Random(1)(0)*50 + 150;
27
}
28
29
// initialize G matrix: N_WIRE rows and N_CELL columns. (geometry matrix)
30
MatrixXd
G
= MatrixXd::Random(N_WIRE, N_CELL);
31
32
33
// W vector is the measured charge on wires.
34
VectorXd
W
= G * C;
35
36
// cout << "geometry matrix:" << endl;
37
// cout << G << endl << endl;
38
39
// cout << "measured charge on each wire:" << endl;
40
// cout << W.transpose() << endl << endl;
41
42
// cout << "true charge of each cell:" << endl;
43
// cout << C.transpose() << endl << endl;
44
double
lambda = 1;
45
46
// WireCell::ElasticNetModel m(lambda, 0.95, 100000, 1e-4);
47
// test_model(m, G, W);
48
// print_results(m, C);
49
50
WireCell::LassoModel
m2
(lambda, 10000, 1
e
-3);
51
test_lasso
(m2, G, W);
52
print_results
(m2, C);
53
54
return
0;
55
}
56
57
void
test_model
(
WireCell::LinearModel
&
m
, MatrixXd&
G
, VectorXd&
W
)
58
{
59
m.
SetData
(G, W);
60
m.
Fit
();
61
62
}
63
64
void
test_lasso
(
WireCell::LassoModel
&
m
, MatrixXd&
G
, VectorXd&
W
)
65
{
66
m.
SetData
(G, W);
67
68
// one can set the weight of each cell's regularization.
69
// m.SetLambdaWeight(0, 10.);
70
// m.SetLambdaWeight(2, 10.);
71
// m.SetLambdaWeight(6, 10.);
72
m.
Fit
();
73
}
74
75
void
print_results
(
WireCell::LinearModel
&
m
, VectorXd&
C
)
76
{
77
VectorXd beta = m.
Getbeta
();
78
79
// cout << "fitted charge of each cell: " << m.name << endl;
80
// cout << beta.transpose() << endl << endl;
81
82
// cout << "predicted charge on each wire: Lasso" << endl;
83
// cout << m.Predict().transpose() << endl << endl;
84
85
cout <<
"average residual charge difference per wire: "
<< m.
name
<<
": "
86
<< m.
MeanResidual
() <<
endl
;
87
88
int
nbeta = beta.size();
89
90
int
n_zero_true = 0;
91
int
n_zero_beta = 0;
92
int
n_zero_correct = 0;
93
94
for
(
int
i=0; i<nbeta; i++) {
95
if
(fabs(C(i))<0.1) n_zero_true++;
96
if
(fabs(beta(i))<5) n_zero_beta++;
97
if
(fabs(C(i))<0.1 && (fabs(C(i) - beta(i)) < 10)) n_zero_correct++;
98
}
99
cout <<
"true zeros: "
<< n_zero_true <<
endl
;
100
cout <<
"fitted zeros: "
<< n_zero_beta <<
endl
;
101
cout <<
"correct fitted zeros: "
<< n_zero_correct <<
endl
;
102
103
cout <<
endl
;
104
}
genie::units::m
static const double m
Definition:
Units.h:79
print_results
void print_results(WireCell::LinearModel &m, VectorXd &C)
Definition:
test_ress_largem.cxx:75
test_model
void test_model(WireCell::LinearModel &m, MatrixXd &G, VectorXd &W)
Definition:
test_ress_largem.cxx:57
Eigen
std
STL namespace.
C
Definition:
pointersEqual_t.cc:10
test_nxjs.G
G
Definition:
test_nxjs.py:9
WireCell::LinearModel
Definition:
LinearModel.h:9
WireCell::LassoModel
Definition:
LassoModel.h:8
freeze_graph.argv
argv
Definition:
freeze_graph.py:218
main
int main(int argc, char *argv[])
Definition:
test_ress_largem.cxx:14
e
const double e
Definition:
gUpMuFluxGen.cxx:165
dump_to_simple_cpp.W
W
Definition:
dump_to_simple_cpp.py:43
WireCell::LinearModel::Getbeta
Eigen::VectorXd & Getbeta()
Definition:
LinearModel.h:16
WireCell::LinearModel::MeanResidual
double MeanResidual()
Definition:
LinearModel.cxx:23
keras_to_tensorflow.int
int
Definition:
keras_to_tensorflow.py:69
WireCell::LinearModel::name
std::string name
Definition:
LinearModel.h:27
WireCell::LinearModel::SetData
virtual void SetData(Eigen::MatrixXd X, Eigen::VectorXd y)
Definition:
LinearModel.h:18
test_lasso
void test_lasso(WireCell::LassoModel &m, MatrixXd &G, VectorXd &W)
Definition:
test_ress_largem.cxx:64
WireCell::LassoModel::Fit
void Fit()
Definition:
LassoModel.cxx:32
ElasticNetModel.h
genie::units::m2
static const double m2
Definition:
Units.h:80
ValidateOpDetReco.index
index
Definition:
ValidateOpDetReco.py:375
WireCell::LinearModel::Fit
virtual void Fit()
Definition:
LinearModel.h:23
LassoModel.h
test_gen_rays_pdsp.argc
argc
Definition:
test_gen_rays_pdsp.py:6
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
Generated by
1.8.11