Jpp  17.3.0-rc.1
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 JDetector &detector, 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 553 of file JKatoomba.hh.

Member Typedef Documentation

Definition at line 556 of file JKatoomba.hh.

Constructor & Destructor Documentation

JACOUSTICS::JKatoomba< JGandalf >::JKatoomba ( const JDetector detector,
const JSoundVelocity velocity,
const int  option 
)
inline

Constructor.

Parameters
detectordetector
velocitysound velocity
optionoption

Definition at line 566 of file JKatoomba.hh.

568  :
569  JKatoomba<>(detector, velocity, option)
570  {};
do set_variable DETECTOR_TXT $WORKDIR detector

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 581 of file JKatoomba.hh.

582  {
583  using namespace std;
584  using namespace JPP;
585 
586  value.setOption(this->option);
587 
588  const int N = value.getN();
589 
590  V.resize(N);
591  Y.resize(N);
592  h.resize(N);
593 
594  lambda = LAMBDA_MIN;
595 
596  result_type precessor = numeric_limits<double>::max();
597 
599 
600  DEBUG("step: " << numberOfIterations << endl);
601 
602  evaluate(__begin, __end);
603 
604  DEBUG("lambda: " << FIXED(12,5) << lambda << endl);
605  DEBUG("chi2: " << FIXED(12,5) << successor << endl);
606 
607  if (successor < precessor) {
608 
609  if (numberOfIterations != 0) {
610 
611  if (fabs(precessor - successor) < EPSILON*fabs(precessor)) {
612  return successor;
613  }
614 
615  if (lambda > LAMBDA_MIN) {
616  lambda /= LAMBDA_DOWN;
617  }
618  }
619 
620  precessor = successor;
621  previous = value;
622 
623  } else {
624 
625  value = previous;
626  lambda *= LAMBDA_UP;
627 
628  if (lambda > LAMBDA_MAX) {
629  return precessor; // no improvement found
630  }
631 
632  evaluate(__begin, __end);
633  }
634 
635 
636  // force definite positiveness
637 
638  for (int i = 0; i != N; ++i) {
639 
640  if (V(i,i) < PIVOT) {
641  V(i,i) = PIVOT;
642  }
643 
644  h[i] = 1.0 / sqrt(V(i,i));
645  }
646 
647 
648  // normalisation
649 
650  for (int i = 0; i != N; ++i) {
651  for (int j = 0; j != i; ++j) {
652  V(j,i) *= h[i] * h[j];
653  V(i,j) = V(j,i);
654  }
655  }
656 
657  for (int i = 0; i != N; ++i) {
658  V(i,i) = 1.0 + lambda;
659  }
660 
661 
662  try {
663  V.invert();
664  }
665  catch (const JException& error) {
666  ERROR("JKatoomb<JGandalf>: " << error.what() << endl);
667  return precessor;
668  }
669 
670 
671  for (int i = 0; i != N; ++i) {
672 
673  DEBUG("u[" << noshowpos << setw(3) << i << "] = " << showpos << FIXED(20,5) << value[i]);
674 
675  double y = 0.0;
676 
677  for (int j = 0; j != N; ++j) {
678  y += V(i,j) * Y[j] * h[i] * h[j];
679  }
680 
681  value[i] -= y;
682 
683  DEBUG(' ' << FIXED(20,10) << y << noshowpos << endl);
684  }
685  }
686 
687  return precessor;
688  }
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:695
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
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:692
static double LAMBDA_MIN
minimal value control parameter
Definition: JKatoomba.hh:693
void evaluate(T __begin, T __end)
Evaluation of fit.
Definition: JKatoomba.hh:712
#define ERROR(A)
Definition: JMessage.hh:66
static double LAMBDA_MAX
maximal value control parameter
Definition: JKatoomba.hh:694
static int MAXIMUM_ITERATIONS
maximal number of iterations
Definition: JKatoomba.hh:691
std::vector< double > h
Definition: JKatoomba.hh:815
void invert()
Invert matrix according LDU decomposition.
Definition: JMatrixNS.hh:80
virtual const char * what() const override
Get error message.
Definition: JException.hh:48
static double LAMBDA_DOWN
multiplication factor control parameter
Definition: JKatoomba.hh:696
static double PIVOT
minimal value diagonal element of matrix
Definition: JKatoomba.hh:697
int j
Definition: JPolint.hh:703
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std::vector< double > Y
Definition: JKatoomba.hh:812
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 712 of file JKatoomba.hh.

713  {
714  using namespace std;
715  using namespace JPP;
716 
717  successor = 0.0;
718 
719  V.reset();
720 
721  for (std::vector<double>::iterator i = Y.begin(); i != Y.end(); ++i) {
722  *i = 0.0;
723  }
724 
725  for (T hit = __begin; hit != __end; ++hit) {
726 
727  const JGEOMETRY::JString& string = detector[hit->getString()];
728  const JMODEL ::JString& parameters = value.string[hit->getString()];
729  const JPosition3D position = string.getPosition(parameters, hit->getFloor());
730 
731  const double D = hit->getDistance(position);
732  const double Vi = velocity.getInverseVelocity(D, hit->getZ(), position.getZ());
733  const double toa_s = value.emitter[hit->getEKey()].t1 + D * Vi;
734 
735  const double u = (toa_s - hit->getValue()) / hit->sigma;
736  const double W = sqrt(hit->getWeight());
737 
738  successor += (W*W) * estimator->getRho(u);
739 
740  H_t H(1.0, string.getGradient(parameters, hit->getPosition(), hit->getFloor()) * Vi);
741 
742  H *= W * estimator->getPsi(u) / hit->sigma;
743 
744  I_t i;
745 
746  i.t1 = value.getIndex(hit->getEKey(), &H_t::t1);
747  i.tx = value.getIndex(hit->getString(), &H_t::tx);
748  i.ty = value.getIndex(hit->getString(), &H_t::ty);
749  i.tx2 = value.getIndex(hit->getString(), &H_t::tx2);
750  i.ty2 = value.getIndex(hit->getString(), &H_t::ty2);
751  i.vs = value.getIndex(hit->getString(), &H_t::vs);
752 
753  V(i.t1, i.t1) += H.t1 * H.t1;
754 
755  Y[i.t1] += W * H.t1;
756 
757  if (hit->getFloor() != 0) {
758 
759  switch (this->option) {
760 
762  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;
763 
764  V(i.vs, i.t1) += H.vs * H.t1;
765  V(i.vs, i.tx) += H.vs * H.tx;
766  V(i.vs, i.ty) += H.vs * H.ty;
767  V(i.vs, i.tx2) += H.vs * H.tx2;
768  V(i.vs, i.ty2) += H.vs * H.ty2;
769 
770  V(i.vs, i.vs) += H.vs * H.vs;
771 
772  Y[i.vs] += W * H.vs;
773 
775  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;
776 
777  V(i.tx2, i.t1) += H.tx2 * H.t1;
778  V(i.tx2, i.tx) += H.tx2 * H.tx;
779  V(i.tx2, i.ty) += H.tx2 * H.ty;
780 
781  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;
782 
783  V(i.ty2, i.t1) += H.ty2 * H.t1;
784  V(i.ty2, i.tx) += H.ty2 * H.tx;
785  V(i.ty2, i.ty) += H.ty2 * H.ty;
786 
787  V(i.tx2, i.tx2) += H.tx2 * H.tx2; V(i.tx2, i.ty2) += H.tx2 * H.ty2;
788  V(i.ty2, i.tx2) += H.ty2 * H.tx2; V(i.ty2, i.ty2) += H.ty2 * H.ty2;
789 
790  Y[i.tx2] += W * H.tx2;
791  Y[i.ty2] += W * H.ty2;
792 
794  V(i.t1, i.tx) += H.t1 * H.tx; V(i.t1, i.ty) += H.t1 * H.ty;
795  V(i.tx, i.t1) += H.tx * H.t1; V(i.ty, i.t1) += H.ty * H.t1;
796 
797  V(i.tx, i.tx) += H.tx * H.tx; V(i.tx, i.ty) += H.tx * H.ty;
798  V(i.ty, i.tx) += H.ty * H.tx; V(i.ty, i.ty) += H.ty * H.ty;
799 
800  Y[i.tx] += W * H.tx;
801  Y[i.ty] += W * H.ty;
802  break;
803 
804  default:
805  break;
806  }
807  }
808  }
809  }
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
Detector file.
Definition: JHead.hh:226
std::vector< double > vs
do set_variable OUTPUT_DIRECTORY $WORKDIR T
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
JACOUSTICS::JModel::emitter_type emitter
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:812

Member Data Documentation

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

debug level

debug level.

Definition at line 690 of file JKatoomba.hh.

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

maximal number of iterations

maximal number of iterations.

Definition at line 691 of file JKatoomba.hh.

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

maximal distance to minimum

maximal distance to minimum.

Definition at line 692 of file JKatoomba.hh.

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

minimal value control parameter

Definition at line 693 of file JKatoomba.hh.

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

maximal value control parameter

Definition at line 694 of file JKatoomba.hh.

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

multiplication factor control parameter

Definition at line 695 of file JKatoomba.hh.

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

multiplication factor control parameter

Definition at line 696 of file JKatoomba.hh.

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

minimal value diagonal element of matrix

Definition at line 697 of file JKatoomba.hh.

double JACOUSTICS::JKatoomba< JGandalf >::lambda

Definition at line 699 of file JKatoomba.hh.

Definition at line 700 of file JKatoomba.hh.

int JACOUSTICS::JKatoomba< JGandalf >::numberOfIterations

Definition at line 701 of file JKatoomba.hh.

Definition at line 702 of file JKatoomba.hh.

Definition at line 812 of file JKatoomba.hh.

Definition at line 813 of file JKatoomba.hh.

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

Definition at line 814 of file JKatoomba.hh.

Definition at line 815 of file JKatoomba.hh.


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