void TransformedScaledCovMatrixTKGroup<V, M>::transformToGaussianSpace( const V & physicalPoint, V & transformedPoint) const { V min_domain_bounds(this->m_boxSubset.minValues()); V max_domain_bounds(this->m_boxSubset.maxValues()); for (unsigned int i = 0; i < transformedPoint.sizeLocal(); i++) { double min_val = min_domain_bounds[i]; double max_val = max_domain_bounds[i]; if (boost::math::isfinite(min_val) && boost::math::isfinite(max_val)) { // Left- and right-hand sides are finite. Do full transform. transformedPoint[i] = std::log(physicalPoint[i] - min_val) - std::log(max_val - physicalPoint[i]); } else if (boost::math::isfinite(min_val) && !boost::math::isfinite(max_val)) { // Left-hand side finite, but right-hand side is not. // Do only left-hand transform. transformedPoint[i] = std::log(physicalPoint[i] - min_val); } else if (!boost::math::isfinite(min_val) && boost::math::isfinite(max_val)) { // Right-hand side is finite, but left-hand side is not. // Do only right-hand transform. transformedPoint[i] = -std::log(max_val - physicalPoint[i]); } else { // No transform. transformedPoint[i] = physicalPoint[i]; } } }
double InvLogitGaussianJointPdf<V,M>::lnValue( const V& domainVector, const V* domainDirection, V* gradVector, M* hessianMatrix, V* hessianEffect) const { double returnValue; double lnDeterminant = 0.0; V transformedDomainVector(domainVector); V min_domain_bounds(this->m_domainBoxSubset.minValues()); V max_domain_bounds(this->m_domainBoxSubset.maxValues()); double lnjacobian = 0.0; for (unsigned int i = 0; i < domainVector.sizeLocal(); i++) { double min_val = min_domain_bounds[i]; double max_val = max_domain_bounds[i]; if (queso_isfinite(min_val) && queso_isfinite(max_val)) { if (domainVector[i] == min_val || domainVector[i] == max_val) { // Exit early if we can return -INFINITY; } // Left- and right-hand sides are finite. Do full transform. transformedDomainVector[i] = std::log(domainVector[i] - min_val) - std::log(max_val - domainVector[i]); lnjacobian += std::log(max_val - min_val) - std::log(domainVector[i] - min_val) - std::log(max_val - domainVector[i]); } else if (queso_isfinite(min_val) && !queso_isfinite(max_val)) { if (domainVector[i] == min_val) { // Exit early if we can return -INFINITY; } // Left-hand side finite, but right-hand side is not. // Do only left-hand transform. transformedDomainVector[i] = std::log(domainVector[i] - min_val); lnjacobian += -std::log(domainVector[i] - min_val); } else if (!queso_isfinite(min_val) && queso_isfinite(max_val)) { if (domainVector[i] == max_val) { // Exit early if we can return -INFINITY; } // Right-hand side is finite, but left-hand side is not. // Do only right-hand transform. transformedDomainVector[i] = -std::log(max_val - domainVector[i]); lnjacobian += -std::log(max_val - domainVector[i]); } else { // No transform. transformedDomainVector[i] = domainVector[i]; } } V diffVec(transformedDomainVector - this->lawExpVector()); if (m_diagonalCovMatrix) { returnValue = ((diffVec * diffVec) / this->lawVarVector()).sumOfComponents(); if (m_normalizationStyle == 0) { unsigned int iMax = this->lawVarVector().sizeLocal(); for (unsigned int i = 0; i < iMax; ++i) { lnDeterminant += log(this->lawVarVector()[i]); } } } else { V tmpVec = this->m_lawCovMatrix->invertMultiply(diffVec); returnValue = (diffVec * tmpVec).sumOfComponents(); if (m_normalizationStyle == 0) { lnDeterminant = this->m_lawCovMatrix->lnDeterminant(); } } if (m_normalizationStyle == 0) { returnValue += ((double) this->lawVarVector().sizeLocal()) * log(2 * M_PI); returnValue += lnDeterminant; } returnValue *= -0.5; returnValue += m_logOfNormalizationFactor; returnValue += lnjacobian; return returnValue; }