LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
lsst::gauss2d::detail Namespace Reference

Classes

class  GradientsExtra
 
struct  Terms
 
class  TermsGradient
 
struct  TermsMoments
 
class  TermsPixel
 Storage for terms common to Gaussians for a single pixel. More...
 
struct  ValuesGauss
 

Typedefs

typedef std::vector< double > vecd
 
typedef std::unique_ptr< vecdvecdptr
 
typedef std::array< double, N_PARAMS_GAUSS2DWeights
 
typedef std::vector< TermsPixelTermsPixelVec
 
typedef std::vector< TermsGradientTermsGradientVec
 
using type_name_prober = void
 

Functions

TermsMoments gaussian_pixel_x_xx (const double cen_x, const double x_min, const double bin_x, const unsigned int dim_x, const double xx_weight, const double xy_weight)
 
Terms terms_from_covar (double weight, const Ellipse &ell)
 
template<class Data >
void gaussian_pixel (Data &image, const double weight, const double cen_x, const double cen_y, const double xx_weight, const double yy_weight, const double xy_weight)
 
void gaussian_pixel_get_jacobian (ValuesGauss &out, const double m, const double m_unweight, const double xmc_norm, const double ymc_weighted, const double xmc, const double ymc, const double norms_yy, const double xmc_t_xy_factor, const double sig_x_inv, const double sig_y_inv, const double xy_norm, const double xx_norm, const double yy_weighted, const double rho_div_one_m_rhosq, const double norms_xy_div_rho, const double dsig_x_conv_src=1, const double dsig_y_conv_src=1, const double drho_c_dsig_x_src=0, const double drho_c_dsig_y_src=0, const double drho_c_drho_s=1)
 
void gaussian_pixel_get_jacobian_from_terms (ValuesGauss &out, const size_t dim1, const TermsPixel &terms_pixel, const TermsGradient &terms_grad, double m, double m_unweighted, double xy_norm)
 
template<typename t >
void gaussian_pixel_add_values (t &cen_x, t &cen_y, t &L, t &sig_x, t &sig_y, t &rho, const ValuesGauss &values, const t weight_cen_x=1, const t weight_cen_y=1, const t weight_L=1, const t weight_sig_x=1, const t weight_sig_y=1, const t weight_rho=1)
 
template<typename t , class Data , class Indices , bool do_extra>
void gaussians_pixel_add_like_grad (Image< t, Data > *output, const Image< idx_type, Indices > &grad_param_map, const Image< t, Data > &grad_param_factor, const size_t N_GAUSS, const std::vector< Weights > &gaussweights, double &chi_pix, double &loglike, const double model, double data, double sigma_inv, unsigned int dim1, unsigned int dim2, const TermsPixelVec &terms_pixel, const TermsGradientVec &terms_grad, ValuesGauss &gradients, const std::shared_ptr< const Image< idx_type, Indices > > extra_param_map, const std::shared_ptr< const Image< t, Data > > extra_param_factor)
 
template<typename T , class Data , class Indices , GradientType gradient_type, bool do_extra>
gaussian_pixel_add_all (size_t g, size_t j, size_t i, double weight, double sigma_inv, const TermsPixelVec &terms_pixel_vec, ImageArray< T, Data > &output_jac_ref, const Image< idx_type, Indices > &grad_param_map, const Image< T, Data > &grad_param_factor, std::vector< Weights > &gradweights, const TermsGradientVec &terms_grad_vec, ValuesGauss &gradients, GradientsExtra< T, Data, Indices > *grad_extra)
 
template<typename Indices >
const std::shared_ptr< const Indices > _param_map_default (size_t n_gaussians, size_t n_params=N_PARAMS_GAUSS2D, size_t increment=1)
 
template<typename Data >
const std::shared_ptr< const Data > _param_factor_default (size_t n_gaussians, size_t n_params=N_PARAMS_GAUSS2D, double value=1.)
 
template<typename T >
constexpr std::string_view wrapped_type_name ()
 
constexpr std::size_t wrapped_type_name_prefix_length ()
 
constexpr std::size_t wrapped_type_name_suffix_length ()
 

Variables

constexpr std::string_view NAMESPACE_SEPARATOR = "::"
 

Typedef Documentation

◆ TermsGradientVec

Definition at line 327 of file evaluate.h.

◆ TermsPixelVec

Definition at line 229 of file evaluate.h.

◆ type_name_prober

Definition at line 47 of file type_name.h.

◆ vecd

Definition at line 65 of file evaluate.h.

◆ vecdptr

Definition at line 66 of file evaluate.h.

◆ Weights

Definition at line 179 of file evaluate.h.

Function Documentation

◆ _param_factor_default()

template<typename Data >
const std::shared_ptr< const Data > lsst::gauss2d::detail::_param_factor_default ( size_t n_gaussians,
size_t n_params = N_PARAMS_GAUSS2D,
double value = 1. )

Definition at line 644 of file evaluate.h.

646 {
647 auto param_factor = std::make_shared<Data>(n_gaussians, n_params);
648 for (size_t g = 0; g < n_gaussians; ++g) {
649 for (size_t p = 0; p < n_params; ++p) {
650 param_factor->set_value(g, p, value);
651 }
652 }
653 return std::const_pointer_cast<const Data>(param_factor);
654}

◆ _param_map_default()

template<typename Indices >
const std::shared_ptr< const Indices > lsst::gauss2d::detail::_param_map_default ( size_t n_gaussians,
size_t n_params = N_PARAMS_GAUSS2D,
size_t increment = 1 )

Definition at line 629 of file evaluate.h.

631 {
632 auto param_map = std::make_shared<Indices>(n_gaussians, n_params);
633 size_t index = 0;
634 for (size_t g = 0; g < n_gaussians; ++g) {
635 for (size_t p = 0; p < n_params; ++p) {
636 param_map->set_value(g, p, index);
637 index += increment;
638 }
639 }
640 return std::const_pointer_cast<const Indices>(param_map);
641}

◆ gaussian_pixel()

template<class Data >
void lsst::gauss2d::detail::gaussian_pixel ( Data & image,
const double weight,
const double cen_x,
const double cen_y,
const double xx_weight,
const double yy_weight,
const double xy_weight )
inline

Definition at line 407 of file evaluate.h.

408 {
409 const unsigned int dim_x = image.get_n_cols();
410 const unsigned int dim_y = image.get_n_rows();
411 const auto coordsys = image.get_coordsys();
412 const double x_min = coordsys.x_min;
413 const double y_min = coordsys.y_min;
414 const double bin_x = coordsys.get_dx1() / image.get_n_cols();
415 const double bin_y = coordsys.get_dy2() / image.get_n_rows();
416
417 const double weight_pix = weight * bin_x * bin_y;
418
419 const auto moment_terms_y = gaussian_pixel_x_xx(cen_y, y_min, bin_y, dim_y, yy_weight, xy_weight);
420 const vecd& y_weighted = *(moment_terms_y.x_norm);
421 const vecd& yy_weighted = *(moment_terms_y.xx);
422
423 double x = x_min - cen_x + bin_x / 2.;
424 // TODO: Consider a version with cached xy, although it doubles memory usage
425 for (unsigned int i = 0; i < dim_x; i++) {
426 const double xx_weighted = x * x * xx_weight;
427 for (unsigned int j = 0; j < dim_y; j++) {
428 image.set_value_unchecked(j, i,
429 weight_pix * exp(-(xx_weighted + yy_weighted[j] - x * y_weighted[j])));
430 }
431 x += bin_x;
432 }
433}
TermsMoments gaussian_pixel_x_xx(const double cen_x, const double x_min, const double bin_x, const unsigned int dim_x, const double xx_weight, const double xy_weight)
Definition evaluate.h:83
afw::table::Key< double > weight

◆ gaussian_pixel_add_all()

template<typename T , class Data , class Indices , GradientType gradient_type, bool do_extra>
T lsst::gauss2d::detail::gaussian_pixel_add_all ( size_t g,
size_t j,
size_t i,
double weight,
double sigma_inv,
const TermsPixelVec & terms_pixel_vec,
ImageArray< T, Data > & output_jac_ref,
const Image< idx_type, Indices > & grad_param_map,
const Image< T, Data > & grad_param_factor,
std::vector< Weights > & gradweights,
const TermsGradientVec & terms_grad_vec,
ValuesGauss & gradients,
GradientsExtra< T, Data, Indices > * grad_extra )
inline

Definition at line 592 of file evaluate.h.

597 {
598 const TermsPixel& terms_pixel = terms_pixel_vec[g];
599 const double xy_norm = terms_pixel.xmc * (*terms_pixel.ymc_weighted)[j];
600 const double value_unweight
601 = terms_pixel.weight * exp(-(terms_pixel.xmc_sq_norm + (*terms_pixel.yy_weighted)[j] - xy_norm));
602 const double value = weight * value_unweight;
603 // Computes dmodel/dx for x in [cen_x, cen_y, flux, sigma_x, sigma_y, rho]
604 if constexpr (gradient_type == GradientType::loglike) {
605 Weights& output = gradweights[g];
606 output[0] = value;
607 output[1] = value_unweight;
608 output[2] = xy_norm;
609 } else if constexpr (gradient_type == GradientType::jacobian) {
610 gaussian_pixel_get_jacobian_from_terms(gradients, j, terms_pixel, terms_grad_vec[g],
611 sigma_inv * value, sigma_inv * value_unweight, xy_norm);
612 gaussian_pixel_add_values<T>(
613 output_jac_ref[grad_param_map.get_value_unchecked(g, 0)]._get_value_unchecked(j, i),
614 output_jac_ref[grad_param_map.get_value_unchecked(g, 1)]._get_value_unchecked(j, i),
615 output_jac_ref[grad_param_map.get_value_unchecked(g, 2)]._get_value_unchecked(j, i),
616 output_jac_ref[grad_param_map.get_value_unchecked(g, 3)]._get_value_unchecked(j, i),
617 output_jac_ref[grad_param_map.get_value_unchecked(g, 4)]._get_value_unchecked(j, i),
618 output_jac_ref[grad_param_map.get_value_unchecked(g, 5)]._get_value_unchecked(j, i),
619 gradients, grad_param_factor.get_value_unchecked(g, 0),
620 grad_param_factor.get_value_unchecked(g, 1), grad_param_factor.get_value_unchecked(g, 2),
621 grad_param_factor.get_value_unchecked(g, 3), grad_param_factor.get_value_unchecked(g, 4),
622 grad_param_factor.get_value_unchecked(g, 5));
623 if constexpr (do_extra) grad_extra->add(g, j, i, gradients);
624 }
625 return value;
626}
T get_value_unchecked(size_t row, size_t col) const
Definition image.h:173
void add(size_t g, size_t dim1, size_t dim2, const ValuesGauss &gradients)
Definition evaluate.h:364
Storage for terms common to Gaussians for a single pixel.
Definition evaluate.h:194

◆ gaussian_pixel_add_values()

template<typename t >
void lsst::gauss2d::detail::gaussian_pixel_add_values ( t & cen_x,
t & cen_y,
t & L,
t & sig_x,
t & sig_y,
t & rho,
const ValuesGauss & values,
const t weight_cen_x = 1,
const t weight_cen_y = 1,
const t weight_L = 1,
const t weight_sig_x = 1,
const t weight_sig_y = 1,
const t weight_rho = 1 )
inline

Definition at line 533 of file evaluate.h.

537 {
538 cen_x += weight_cen_x * values.cen_x;
539 cen_y += weight_cen_y * values.cen_y;
540 L += weight_L * values.L;
541 sig_x += weight_sig_x * values.sigma_x;
542 sig_y += weight_sig_y * values.sigma_y;
543 rho += weight_rho * values.rho;
544}

◆ gaussian_pixel_get_jacobian()

void lsst::gauss2d::detail::gaussian_pixel_get_jacobian ( ValuesGauss & out,
const double m,
const double m_unweight,
const double xmc_norm,
const double ymc_weighted,
const double xmc,
const double ymc,
const double norms_yy,
const double xmc_t_xy_factor,
const double sig_x_inv,
const double sig_y_inv,
const double xy_norm,
const double xx_norm,
const double yy_weighted,
const double rho_div_one_m_rhosq,
const double norms_xy_div_rho,
const double dsig_x_conv_src = 1,
const double dsig_y_conv_src = 1,
const double drho_c_dsig_x_src = 0,
const double drho_c_dsig_y_src = 0,
const double drho_c_drho_s = 1 )
inline

Definition at line 495 of file evaluate.h.

503 {
504 out.cen_x = m * (2 * xmc_norm - ymc_weighted);
505 out.cen_y = m * (2 * ymc * norms_yy - xmc_t_xy_factor);
506 out.L = m_unweight;
507 const double one_p_xy = 1. + xy_norm;
508 // df/dsigma_src = df/d_sigma_conv * dsigma_conv/dsigma_src
509 const double dfdrho_c = m
510 * (rho_div_one_m_rhosq * (1 - 2 * (xx_norm + yy_weighted - xy_norm))
511 + xmc * ymc * norms_xy_div_rho);
512 out.sigma_x = dfdrho_c * drho_c_dsig_x_src + dsig_x_conv_src * (m * sig_x_inv * (2 * xx_norm - one_p_xy));
513 out.sigma_y
514 = dfdrho_c * drho_c_dsig_y_src + dsig_y_conv_src * (m * sig_y_inv * (2 * yy_weighted - one_p_xy));
515 // drho_conv/drho_src = sigmaxy_src/sigmaxy_conv
516 out.rho = dfdrho_c * drho_c_drho_s;
517}
int m
Definition SpanSet.cc:48

◆ gaussian_pixel_get_jacobian_from_terms()

void lsst::gauss2d::detail::gaussian_pixel_get_jacobian_from_terms ( ValuesGauss & out,
const size_t dim1,
const TermsPixel & terms_pixel,
const TermsGradient & terms_grad,
double m,
double m_unweighted,
double xy_norm )
inline

Definition at line 519 of file evaluate.h.

522 {
524 out, m, m_unweighted * terms_pixel.weight_kernel, terms_pixel.xmc_weighted,
525 (*terms_pixel.ymc_weighted)[dim1], terms_pixel.xmc, (*terms_grad.ymc)[dim1], terms_grad.yy_weight,
526 terms_grad.xmc_t_xy_weight, terms_grad.sig_x_inv, terms_grad.sig_y_inv, xy_norm,
527 terms_pixel.xmc_sq_norm, (*terms_pixel.yy_weighted)[dim1], terms_grad.rho_factor,
528 terms_grad.rho_xy_factor, terms_grad.sig_x_src_div_conv, terms_grad.sig_y_src_div_conv,
529 terms_grad.drho_c_dsig_x_src, terms_grad.drho_c_dsig_y_src, terms_grad.drho_c_drho_s);
530}
void gaussian_pixel_get_jacobian(ValuesGauss &out, const double m, const double m_unweight, const double xmc_norm, const double ymc_weighted, const double xmc, const double ymc, const double norms_yy, const double xmc_t_xy_factor, const double sig_x_inv, const double sig_y_inv, const double xy_norm, const double xx_norm, const double yy_weighted, const double rho_div_one_m_rhosq, const double norms_xy_div_rho, const double dsig_x_conv_src=1, const double dsig_y_conv_src=1, const double drho_c_dsig_x_src=0, const double drho_c_dsig_y_src=0, const double drho_c_drho_s=1)
Definition evaluate.h:495

◆ gaussian_pixel_x_xx()

TermsMoments lsst::gauss2d::detail::gaussian_pixel_x_xx ( const double cen_x,
const double x_min,
const double bin_x,
const unsigned int dim_x,
const double xx_weight,
const double xy_weight )
inline

Definition at line 83 of file evaluate.h.

85 {
86 const double x_init = x_min - cen_x + bin_x / 2.;
87 vecdptr x = std::make_unique<vecd>(dim_x);
88 vecdptr xx = std::make_unique<vecd>(dim_x);
89 vecdptr x_norm = std::make_unique<vecd>(dim_x);
90 for (unsigned int i = 0; i < dim_x; i++) {
91 double dist = x_init + i * bin_x;
92 (*x)[i] = dist;
93 (*xx)[i] = dist * dist * xx_weight;
94 (*x_norm)[i] = dist * xy_weight;
95 }
96 return TermsMoments({std::move(x), std::move(x_norm), std::move(xx)});
97}
T move(T... args)

◆ gaussians_pixel_add_like_grad()

template<typename t , class Data , class Indices , bool do_extra>
void lsst::gauss2d::detail::gaussians_pixel_add_like_grad ( Image< t, Data > * output,
const Image< idx_type, Indices > & grad_param_map,
const Image< t, Data > & grad_param_factor,
const size_t N_GAUSS,
const std::vector< Weights > & gaussweights,
double & chi_pix,
double & loglike,
const double model,
double data,
double sigma_inv,
unsigned int dim1,
unsigned int dim2,
const TermsPixelVec & terms_pixel,
const TermsGradientVec & terms_grad,
ValuesGauss & gradients,
const std::shared_ptr< const Image< idx_type, Indices > > extra_param_map,
const std::shared_ptr< const Image< t, Data > > extra_param_factor )
inline

Definition at line 548 of file evaluate.h.

555 {
556 double diff = data - model;
557 chi_pix = sigma_inv * diff;
558 double diffvar = sigma_inv * chi_pix;
559 loglike -= diff * diffvar / 2.;
560 for (size_t g = 0; g < N_GAUSS; ++g) {
561 const Weights& weights = gaussweights[g];
562 /*
563 * Derivation:
564 *
565 ll = sum(-(data-model)^2*varinv/2)
566 dll/dx = --2*dmodel/dx*(data-model)*varinv/2
567 dmodelsum/dx = d(.. + model[g])/dx = dmodel[g]/dx
568 dll/dx = dmodel[g]/dx*diffvar
569 */
570 gaussian_pixel_get_jacobian_from_terms(gradients, dim1, terms_pixel[g], terms_grad[g],
571 weights[0] * diffvar, weights[1] * diffvar, weights[2]);
572 gaussian_pixel_add_values<t>(
573 output->_get_value_unchecked(0, grad_param_map.get_value_unchecked(g, 0)),
574 output->_get_value_unchecked(0, grad_param_map.get_value_unchecked(g, 1)),
575 output->_get_value_unchecked(0, grad_param_map.get_value_unchecked(g, 2)),
576 output->_get_value_unchecked(0, grad_param_map.get_value_unchecked(g, 3)),
577 output->_get_value_unchecked(0, grad_param_map.get_value_unchecked(g, 4)),
578 output->_get_value_unchecked(0, grad_param_map.get_value_unchecked(g, 5)), gradients,
579 grad_param_factor.get_value_unchecked(g, 0), grad_param_factor.get_value_unchecked(g, 1),
580 grad_param_factor.get_value_unchecked(g, 2), grad_param_factor.get_value_unchecked(g, 3),
581 grad_param_factor.get_value_unchecked(g, 4), grad_param_factor.get_value_unchecked(g, 5));
582 if constexpr (do_extra) {
583 double value = gradients.L * extra_param_factor->get_value_unchecked(g, 0)
584 + gradients.sigma_x * extra_param_factor->get_value_unchecked(g, 1)
585 + gradients.sigma_y * extra_param_factor->get_value_unchecked(g, 2);
586 output->_get_value_unchecked(0, extra_param_map->get_value_unchecked(g, 1)) += value;
587 }
588 }
589}
char * data
Definition BaseRecord.cc:61
T & _get_value_unchecked(size_t row, size_t col)
Definition image.h:128
void gaussian_pixel_get_jacobian_from_terms(ValuesGauss &out, const size_t dim1, const TermsPixel &terms_pixel, const TermsGradient &terms_grad, double m, double m_unweighted, double xy_norm)
Definition evaluate.h:519

◆ terms_from_covar()

Terms lsst::gauss2d::detail::terms_from_covar ( double weight,
const Ellipse & ell )

Definition at line 30 of file evaluate.cc.

30 {
31 double sig_x = ell.get_sigma_x();
32 double sig_y = ell.get_sigma_y();
33 double rho = ell.get_rho();
34
35 const double norm_exp = 1. / (1 - rho * rho);
36 Terms rval = {.weight = weight / (2. * M_PI * sig_x * sig_y) * sqrt(norm_exp),
37 .xx = norm_exp / (2. * sig_x * sig_x),
38 .yy = norm_exp / (2. * sig_y * sig_y),
39 .xy = rho * norm_exp / (sig_x * sig_y)};
40 return rval;
41}
#define M_PI
Definition ListMatch.cc:31
double get_rho() const override
Get rho.
Definition ellipse.cc:319
double get_sigma_x() const override
Get sigma_x.
Definition ellipse.cc:320
double get_sigma_y() const override
Get sigma_y.
Definition ellipse.cc:321

◆ wrapped_type_name()

template<typename T >
constexpr std::string_view lsst::gauss2d::detail::wrapped_type_name ( )
constexpr

Definition at line 50 of file type_name.h.

50 {
51#ifdef __clang__
52 return __PRETTY_FUNCTION__;
53#elif defined(__GNUC__)
54 return __PRETTY_FUNCTION__;
55#elif defined(_MSC_VER)
56 return __FUNCSIG__;
57#else
58#error "Unsupported compiler"
59#endif
60}

◆ wrapped_type_name_prefix_length()

constexpr std::size_t lsst::gauss2d::detail::wrapped_type_name_prefix_length ( )
constexpr

Definition at line 62 of file type_name.h.

62 {
63 return wrapped_type_name<type_name_prober>().find(type_name<type_name_prober>());
64}

◆ wrapped_type_name_suffix_length()

constexpr std::size_t lsst::gauss2d::detail::wrapped_type_name_suffix_length ( )
constexpr

Definition at line 66 of file type_name.h.

66 {
67 return wrapped_type_name<type_name_prober>().length() - wrapped_type_name_prefix_length()
68 - type_name<type_name_prober>().length();
69}
constexpr std::size_t wrapped_type_name_prefix_length()
Definition type_name.h:62

Variable Documentation

◆ NAMESPACE_SEPARATOR

constexpr std::string_view lsst::gauss2d::detail::NAMESPACE_SEPARATOR = "::"
constexpr

Definition at line 71 of file type_name.h.