Jpp  18.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
JACOUSTICS::JKatoomba< JGandalf > Struct Template Reference

Template specialisation of fit function of acoustic model based on JGandalf minimiser. More...

#include <JKatoomba.hh>

Inheritance diagram for JACOUSTICS::JKatoomba< JGandalf >:
JACOUSTICS::JKatoomba<>

Public Types

typedef double result_type
 

Public Member Functions

 JKatoomba (const JGeometry &geometry, const JSoundVelocity &velocity, const int option)
 Constructor. More...
 
template<class T >
result_type operator() (T __begin, T __end)
 Fit. More...
 

Public Attributes

double lambda
 
JModel value
 
int numberOfIterations
 
JMATH::JMatrixNS V
 

Static Public Attributes

static int debug = 0
 debug level More...
 
static int MAXIMUM_ITERATIONS = 1000
 maximal number of iterations More...
 
static double EPSILON = 1.0e-3
 maximal distance to minimum More...
 
static double LAMBDA_MIN = 0.01
 minimal value control parameter More...
 
static double LAMBDA_MAX = 100.0
 maximal value control parameter More...
 
static double LAMBDA_UP = 9.0
 multiplication factor control parameter More...
 
static double LAMBDA_DOWN = 11.0
 multiplication factor control parameter More...
 
static double PIVOT = 1.0e-3
 minimal value diagonal element of matrix More...
 

Private Member Functions

template<class T >
void evaluate (T __begin, T __end)
 Evaluation of fit. More...
 

Private Attributes

std::vector< double > Y
 
result_type successor
 
JModel previous
 
std::vector< double > h
 

Detailed Description

template<>
struct JACOUSTICS::JKatoomba< JGandalf >

Template specialisation of fit function of acoustic model based on JGandalf minimiser.

Definition at line 639 of file JKatoomba.hh.

Member Typedef Documentation

Definition at line 642 of file JKatoomba.hh.

Constructor & Destructor Documentation

JACOUSTICS::JKatoomba< JGandalf >::JKatoomba ( const JGeometry geometry,
const JSoundVelocity velocity,
const int  option 
)
inline

Constructor.

Parameters
geometrydetector geometry
velocitysound velocity
optionoption

Definition at line 652 of file JKatoomba.hh.

654  :
655  JKatoomba<>(geometry, velocity, option)
656  {};

Member Function Documentation

template<class T >
result_type JACOUSTICS::JKatoomba< JGandalf >::operator() ( T  __begin,
T  __end 
)
inline

Fit.

Parameters
__beginbegin of hits
__endend of hits
Returns
chi2 and gradient

Definition at line 667 of file JKatoomba.hh.

668  {
669  using namespace std;
670  using namespace JPP;
671 
672  value.setOption(this->option);
673 
674  const int N = value.getN();
675 
676  V.resize(N);
677  Y.resize(N);
678  h.resize(N);
679 
680  lambda = LAMBDA_MIN;
681 
682  result_type precessor = numeric_limits<double>::max();
683 
685 
686  DEBUG("step: " << numberOfIterations << endl);
687 
688  evaluate(__begin, __end);
689 
690  DEBUG("lambda: " << FIXED(12,5) << lambda << endl);
691  DEBUG("chi2: " << FIXED(12,5) << successor << endl);
692 
693  if (successor < precessor) {
694 
695  if (numberOfIterations != 0) {
696 
697  if (fabs(precessor - successor) < EPSILON*fabs(precessor)) {
698  return successor;
699  }
700 
701  if (lambda > LAMBDA_MIN) {
702  lambda /= LAMBDA_DOWN;
703  }
704  }
705 
706  precessor = successor;
707  previous = value;
708 
709  } else {
710 
711  value = previous;
712  lambda *= LAMBDA_UP;
713 
714  if (lambda > LAMBDA_MAX) {
715  return precessor; // no improvement found
716  }
717 
718  evaluate(__begin, __end);
719  }
720 
721 
722  // force definite positiveness
723 
724  for (int i = 0; i != N; ++i) {
725 
726  if (V(i,i) < PIVOT) {
727  V(i,i) = PIVOT;
728  }
729 
730  h[i] = 1.0 / sqrt(V(i,i));
731  }
732 
733 
734  // normalisation
735 
736  for (int i = 0; i != N; ++i) {
737  for (int j = 0; j != i; ++j) {
738  V(j,i) *= h[i] * h[j];
739  V(i,j) = V(j,i);
740  }
741  }
742 
743  for (int i = 0; i != N; ++i) {
744  V(i,i) = 1.0 + lambda;
745  }
746 
747 
748  try {
749  V.invert();
750  }
751  catch (const JException& error) {
752  ERROR("JKatoomb<JGandalf>: " << error.what() << endl);
753  return precessor;
754  }
755 
756 
757  for (int i = 0; i != N; ++i) {
758 
759  DEBUG("u[" << noshowpos << setw(3) << i << "] = " << showpos << FIXED(20,5) << value[i]);
760 
761  double y = 0.0;
762 
763  for (int j = 0; j != N; ++j) {
764  y += V(i,j) * Y[j] * h[i] * h[j];
765  }
766 
767  value[i] -= y;
768 
769  DEBUG(' ' << FIXED(20,10) << y << noshowpos << endl);
770  }
771  }
772 
773  return precessor;
774  }
size_t getN() const
Get number of fit parameters.
General exception.
Definition: JException.hh:23
void setOption(const int option)
Set fit option.
static double LAMBDA_UP
multiplication factor control parameter
Definition: JKatoomba.hh:781
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:421
static double EPSILON
maximal distance to minimum
Definition: JKatoomba.hh:778
static double LAMBDA_MIN
minimal value control parameter
Definition: JKatoomba.hh:779
void evaluate(T __begin, T __end)
Evaluation of fit.
Definition: JKatoomba.hh:798
#define ERROR(A)
Definition: JMessage.hh:66
static double LAMBDA_MAX
maximal value control parameter
Definition: JKatoomba.hh:780
static int MAXIMUM_ITERATIONS
maximal number of iterations
Definition: JKatoomba.hh:777
std::vector< double > h
Definition: JKatoomba.hh:901
void invert()
Invert matrix according LDU decomposition.
Definition: JMatrixNS.hh:80
virtual const char * what() const override
Get error message.
Definition: JException.hh:48
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:36
static double LAMBDA_DOWN
multiplication factor control parameter
Definition: JKatoomba.hh:782
static double PIVOT
minimal value diagonal element of matrix
Definition: JKatoomba.hh:783
int j
Definition: JPolint.hh:703
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std::vector< double > Y
Definition: JKatoomba.hh:898
template<class T >
void JACOUSTICS::JKatoomba< JGandalf >::evaluate ( T  __begin,
T  __end 
)
inlineprivate

Evaluation of fit.

Parameters
__beginbegin of data
__endend of data

Definition at line 798 of file JKatoomba.hh.

799  {
800  using namespace std;
801  using namespace JPP;
802 
803  successor = 0.0;
804 
805  V.reset();
806 
807  for (std::vector<double>::iterator i = Y.begin(); i != Y.end(); ++i) {
808  *i = 0.0;
809  }
810 
811  for (T hit = __begin; hit != __end; ++hit) {
812 
813  const JGEOMETRY::JString& string = geometry[hit->getString()];
814  const JMODEL ::JString& parameters = value.string[hit->getString()];
815  const JPosition3D position = string.getPosition(parameters, hit->getFloor());
816 
817  const double D = hit->getDistance(position);
818  const double Vi = velocity.getInverseVelocity(D, hit->getZ(), position.getZ());
819  const double toa_s = value.emission[hit->getEKey()].t1 + D * Vi;
820 
821  const double u = (toa_s - hit->getValue()) / hit->getSigma();
822  const double W = sqrt(hit->getWeight());
823 
824  successor += (W*W) * estimator->getRho(u);
825 
826  H_t H(1.0, string.getGradient(parameters, hit->getPosition(), hit->getFloor()) * Vi);
827 
828  H *= W * estimator->getPsi(u) / hit->getSigma();
829 
830  I_t i;
831 
832  i.t1 = value.getIndex(hit->getEKey(), &H_t::t1);
833  i.tx = value.getIndex(hit->getString(), &H_t::tx);
834  i.ty = value.getIndex(hit->getString(), &H_t::ty);
835  i.tx2 = value.getIndex(hit->getString(), &H_t::tx2);
836  i.ty2 = value.getIndex(hit->getString(), &H_t::ty2);
837  i.vs = value.getIndex(hit->getString(), &H_t::vs);
838 
839  V(i.t1, i.t1) += H.t1 * H.t1;
840 
841  Y[i.t1] += W * H.t1;
842 
843  if (hit->getFloor() != 0) {
844 
845  switch (this->option) {
846 
848  V(i.t1, i.vs) += H.t1 * H.vs; V(i.tx, i.vs) += H.tx * H.vs; V(i.ty, i.vs) += H.ty * H.vs; V(i.tx2, i.vs) += H.tx2 * H.vs; V(i.ty2, i.vs) += H.ty2 * H.vs;
849 
850  V(i.vs, i.t1) += H.vs * H.t1;
851  V(i.vs, i.tx) += H.vs * H.tx;
852  V(i.vs, i.ty) += H.vs * H.ty;
853  V(i.vs, i.tx2) += H.vs * H.tx2;
854  V(i.vs, i.ty2) += H.vs * H.ty2;
855 
856  V(i.vs, i.vs) += H.vs * H.vs;
857 
858  Y[i.vs] += W * H.vs;
859 
861  V(i.t1, i.tx2) += H.t1 * H.tx2; V(i.tx, i.tx2) += H.tx * H.tx2; V(i.ty, i.tx2) += H.ty * H.tx2;
862 
863  V(i.tx2, i.t1) += H.tx2 * H.t1;
864  V(i.tx2, i.tx) += H.tx2 * H.tx;
865  V(i.tx2, i.ty) += H.tx2 * H.ty;
866 
867  V(i.t1, i.ty2) += H.t1 * H.ty2; V(i.tx, i.ty2) += H.tx * H.ty2; V(i.ty, i.ty2) += H.ty * H.ty2;
868 
869  V(i.ty2, i.t1) += H.ty2 * H.t1;
870  V(i.ty2, i.tx) += H.ty2 * H.tx;
871  V(i.ty2, i.ty) += H.ty2 * H.ty;
872 
873  V(i.tx2, i.tx2) += H.tx2 * H.tx2; V(i.tx2, i.ty2) += H.tx2 * H.ty2;
874  V(i.ty2, i.tx2) += H.ty2 * H.tx2; V(i.ty2, i.ty2) += H.ty2 * H.ty2;
875 
876  Y[i.tx2] += W * H.tx2;
877  Y[i.ty2] += W * H.ty2;
878 
880  V(i.t1, i.tx) += H.t1 * H.tx; V(i.t1, i.ty) += H.t1 * H.ty;
881  V(i.tx, i.t1) += H.tx * H.t1; V(i.ty, i.t1) += H.ty * H.t1;
882 
883  V(i.tx, i.tx) += H.tx * H.tx; V(i.tx, i.ty) += H.tx * H.ty;
884  V(i.ty, i.tx) += H.ty * H.tx; V(i.ty, i.ty) += H.ty * H.ty;
885 
886  Y[i.tx] += W * H.tx;
887  Y[i.ty] += W * H.ty;
888  break;
889 
890  default:
891  break;
892  }
893  }
894  }
895  }
fit times of emission of emitters and tilt angles of strings with second order correction and stretch...
static const double H
Planck constant [eV s].
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
JMatrixND & reset()
Set matrix to the null matrix.
Definition: JMatrixND.hh:434
fit times of emission of emitters and tilt angles of strings
std::vector< double > vs
do set_variable OUTPUT_DIRECTORY $WORKDIR T
JACOUSTICS::JModel::emission_type emission
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
fit times of emission of emitters and tilt angles of strings with second order correction ...
size_t getIndex(int id, double JString::*p) const
Get index of fit parameter for given string.
JACOUSTICS::JModel::string_type string
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
double u[N+1]
Definition: JPolint.hh:776
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
double getZ() const
Get z position.
Definition: JVector3D.hh:115
std::vector< double > Y
Definition: JKatoomba.hh:898

Member Data Documentation

int JACOUSTICS::JKatoomba< JGandalf >::debug = 0
static

debug level

debug level.

Definition at line 776 of file JKatoomba.hh.

int JACOUSTICS::JKatoomba< JGandalf >::MAXIMUM_ITERATIONS = 1000
static

maximal number of iterations

maximal number of iterations.

Definition at line 777 of file JKatoomba.hh.

double JACOUSTICS::JKatoomba< JGandalf >::EPSILON = 1.0e-3
static

maximal distance to minimum

maximal distance to minimum.

Definition at line 778 of file JKatoomba.hh.

double JACOUSTICS::JKatoomba< JGandalf >::LAMBDA_MIN = 0.01
static

minimal value control parameter

Definition at line 779 of file JKatoomba.hh.

double JACOUSTICS::JKatoomba< JGandalf >::LAMBDA_MAX = 100.0
static

maximal value control parameter

Definition at line 780 of file JKatoomba.hh.

double JACOUSTICS::JKatoomba< JGandalf >::LAMBDA_UP = 9.0
static

multiplication factor control parameter

Definition at line 781 of file JKatoomba.hh.

double JACOUSTICS::JKatoomba< JGandalf >::LAMBDA_DOWN = 11.0
static

multiplication factor control parameter

Definition at line 782 of file JKatoomba.hh.

double JACOUSTICS::JKatoomba< JGandalf >::PIVOT = 1.0e-3
static

minimal value diagonal element of matrix

Definition at line 783 of file JKatoomba.hh.

double JACOUSTICS::JKatoomba< JGandalf >::lambda

Definition at line 785 of file JKatoomba.hh.

Definition at line 786 of file JKatoomba.hh.

int JACOUSTICS::JKatoomba< JGandalf >::numberOfIterations

Definition at line 787 of file JKatoomba.hh.

Definition at line 788 of file JKatoomba.hh.

Definition at line 898 of file JKatoomba.hh.

Definition at line 899 of file JKatoomba.hh.

JModel JACOUSTICS::JKatoomba< JGandalf >::previous
private

Definition at line 900 of file JKatoomba.hh.

Definition at line 901 of file JKatoomba.hh.


The documentation for this struct was generated from the following file: