Double_t theUnknownFunction(Double_t x, Double_t y) {
return sin((1.7+x)*(x-0.3)-2.3*(y+0.7));
}
void mlpRegression() {
TNtuple* t=new TNtuple("tree","tree","x:y:f");
TRandom r;
for (Int_t i=0; i<1000; i++) {
Float_t x=r.Rndm();
Float_t y=r.Rndm();
t->Fill(x,y,theUnknownFunction(x,y));
}
TMultiLayerPerceptron* mlp=new TMultiLayerPerceptron("x,y:10:8:f",t,
"Entry$%2","(Entry$%2)==0");
mlp->Train(150,"graph update=10");
TMLPAnalyzer* mlpa=new TMLPAnalyzer(mlp);
mlpa->GatherInformations();
mlpa->CheckNetwork();
mlpa->DrawDInputs();
TCanvas* cIO=new TCanvas("TruthDeviation", "TruthDeviation");
cIO->Divide(2,2);
cIO->cd(1);
mlpa->DrawTruthDeviations();
cIO->cd(2);
mlpa->DrawTruthDeviationInsOut();
cIO->cd(3);
mlpa->GetIOTree()->Draw("Out.Out0-True.True0:True.True0>>hDelta","","goff");
TH2F* hDelta=(TH2F*)gDirectory->Get("hDelta");
hDelta->SetTitle("Difference between ANN output and truth vs. truth");
hDelta->Draw("BOX");
cIO->cd(4);
Double_t vx[225];
Double_t vy[225];
Double_t delta[225];
Double_t v[2];
for (Int_t ix=0; ix<15; ix++) {
v[0]=ix/5.-1.;
for (Int_t iy=0; iy<15; iy++) {
v[1]=iy/5.-1.;
Int_t idx=ix*15+iy;
vx[idx]=v[0];
vy[idx]=v[1];
delta[idx]=mlp->Evaluate(0, v)-theUnknownFunction(v[0],v[1]);
}
}
TGraph2D* g2Extrapolate=new TGraph2D("ANN extrapolation",
"ANN extrapolation, ANN output - truth",
225, vx, vy, delta);
g2Extrapolate->Draw("TRI2");
}
|
|