File: tPoisson.cc

package info (click to toggle)
casacore 3.8.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,912 kB
  • sloc: cpp: 471,569; fortran: 16,372; ansic: 7,416; yacc: 4,714; lex: 2,346; sh: 1,865; python: 629; perl: 531; sed: 499; csh: 201; makefile: 32
file content (119 lines) | stat: -rw-r--r-- 4,633 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//# Copyright (C) 1995,1996,1997,1999,2001,2002,2005
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This program is free software; you can redistribute it and/or modify it
//# under the terms of the GNU General Public License as published by the Free
//# Software Foundation; either version 2 of the License, or (at your option)
//# any later version.
//#
//# This program is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
//# more details.
//#
//# You should have received a copy of the GNU General Public License along
//# with this program; if not, write to the Free Software Foundation, Inc.,
//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//#        Internet email: casa-feedback@nrao.edu.
//#        Postal address: AIPS++ Project Office
//#                        National Radio Astronomy Observatory
//#                        520 Edgemont Road
//#                        Charlottesville, VA 22903-2475 USA

#include <casacore/scimath/Functionals/PoissonFunction.h>

#include <casacore/scimath/Mathematics/AutoDiff.h>
#include <casacore/scimath/Mathematics/AutoDiffA.h>
#include <casacore/scimath/Mathematics/AutoDiffIO.h>
#include <casacore/scimath/Mathematics/AutoDiffMath.h>
#include <casacore/casa/BasicSL/Constants.h>
#include <casacore/casa/BasicMath/Math.h>
#include <casacore/casa/Arrays/Vector.h>
#include <casacore/casa/Arrays/ArrayLogical.h>
#include <casacore/casa/Arrays/ArrayMath.h>
#include <casacore/casa/Utilities/Assert.h>

#include <casacore/casa/iostream.h>

#include <casacore/casa/namespace.h>
int main() {
  PoissonFunction<Double> null;
  AlwaysAssertExit(null.lambda() == 1.0 && null.height() == 1.0);

  const float ERROR_TOL = .00001;
  AlwaysAssertExit(near(null(0.0), .367879, ERROR_TOL) && near(null(1.0), .367879, ERROR_TOL));
  // name()
  cout << "Name of function: " << null.name() << endl; 
  AlwaysAssertExit(null.name() == "poisson");

  PoissonFunction<Double> poisson1(4.0, 2.0);
  AlwaysAssertExit(poisson1.lambda() == 4.0 && poisson1.height()==2.0);
  const PoissonFunction<Double> &cpoisson1 = poisson1;
  AlwaysAssertExit(cpoisson1.lambda() == 4.0 && cpoisson1.height()==2.0 );
  poisson1.setLambda(2.0);
  poisson1.setHeight(3.0);
  AlwaysAssertExit(poisson1[PoissonFunction<Double>::LAMBDA] == 2.0 );
  AlwaysAssertExit(poisson1[PoissonFunction<Double>::HEIGHT] == 3.0 );
  poisson1[PoissonFunction<Double>::LAMBDA] = 3.0;
  poisson1[PoissonFunction<Double>::HEIGHT] = 2.0;
  // <<
  cout << "Function Parameters: " << poisson1 << endl;

  AlwaysAssertExit(near(poisson1(3.0),0.4480836, ERROR_TOL ));
  Vector<Double> xvec(1);
  xvec = 5.0;
  cout << "Value at 5:      " << poisson1(xvec(0)) << endl;

  ///
  // Copy constructor
  PoissonFunction<Double> pc(poisson1);
  cout << "Copy: " << pc << "; "
		  <<"f(5) = " << pc(xvec(0)) << endl;

  PoissonFunction<Double> pcb(pc);
  cout << "Copy back: " << pcb << endl <<"f(5) = " << pcb(xvec(0)) << endl;
  AlwaysAssertExit(near(poisson1(xvec(0)), .2016376, ERROR_TOL));
  AlwaysAssertExit(near(pc(xvec(0)), .2016376, ERROR_TOL));
  AlwaysAssertExit(near(pcb(xvec(0)), .2016376, ERROR_TOL));
  xvec = 7.0;
  AlwaysAssertExit(near(poisson1(xvec(0)), .043208063, ERROR_TOL));
  

  //Available parameters
  PoissonFunction<Double> poisson2(poisson1);
  PoissonFunction<Double> poisson3;
  poisson3 = poisson2;
  cout << "NParameters="<<poisson1.nparameters()<<endl;
  AlwaysAssertExit(poisson1.nparameters() == 2);
  Vector<Double> parms = poisson1.parameters().getParameters();
  AlwaysAssertExit(parms(0) == 3.0);
  AlwaysAssertExit(parms(1) == 2.0);
  AlwaysAssertExit(allEQ(parms, poisson2.parameters().getParameters()) &&
		   allEQ(parms, poisson3.parameters().getParameters()));

  poisson1[0] = 1.0;
  poisson1[1] = 4.0;
  AlwaysAssertExit(poisson1.lambda() == 1.0 );
  AlwaysAssertExit(poisson1.height() == 4.0 );
  
  parms[0] = 11.0;
  parms[1] = 2.0;
  poisson1.parameters().setParameters(parms);
  AlwaysAssertExit(allEQ(poisson1.parameters().getParameters(), parms));
  

  // clone();
  cout << "Original value f(1):     " << poisson1(1.0) << endl;
  AlwaysAssertExit(nearAbs(poisson1(1.0), 0.0003674374, 1e-5))
  Function<Double> *poisson4ptr = poisson1.clone();
  cout << "f.clone(1):              " << (*poisson4ptr)(1.0) << endl;
  AlwaysAssertExit(near(poisson1(1.0), (*poisson4ptr)(1.0)))

  delete poisson4ptr;


  cout << "OK" << endl;
  return 0;
}