const GaussianVectorRV<V,M>& ScaledCovMatrixTKGroup<V,M>::rv(unsigned int stageId) const { queso_require_not_equal_to_msg(m_rvs.size(), 0, "m_rvs.size() = 0"); queso_require_msg(m_rvs[0], "m_rvs[0] == NULL"); queso_require_greater_msg(m_preComputingPositions.size(), stageId, "m_preComputingPositions.size() <= stageId"); queso_require_msg(m_preComputingPositions[stageId], "m_preComputingPositions[stageId] == NULL"); if ((m_env.subDisplayFile() ) && (m_env.displayVerbosity() >= 10)) { *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::rv1()" << ", stageId = " << stageId << ": about to call m_rvs[0]->updateLawExpVector()" << ", vector = " << *m_preComputingPositions[stageId] // FIX ME: might demand parallelism << std::endl; } GaussianVectorRV<V, M> * gaussian_rv = dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[0]); gaussian_rv->updateLawExpVector(*m_preComputingPositions[stageId]); return (*gaussian_rv); }
const InvLogitGaussianVectorRV<V,M>& TransformedScaledCovMatrixTKGroup<V,M>::rv(unsigned int stageId) const { queso_require_not_equal_to_msg(m_rvs.size(), 0, "m_rvs.size() = 0"); queso_require_msg(m_rvs[0], "m_rvs[0] == NULL"); queso_require_greater_msg(m_preComputingPositions.size(), stageId, "m_preComputingPositions.size() <= stageId"); queso_require_msg(m_preComputingPositions[stageId], "m_preComputingPositions[stageId] == NULL"); if ((m_env.subDisplayFile() ) && (m_env.displayVerbosity() >= 10)) { *m_env.subDisplayFile() << "In TransformedScaledCovMatrixTKGroup<V,M>::rv1()" << ", stageId = " << stageId << ": about to call m_rvs[0]->updateLawExpVector()" << ", vector = " << *m_preComputingPositions[stageId] // FIX ME: might demand parallelism << std::endl; } InvLogitGaussianVectorRV<V, M> * invlogit_gaussian = dynamic_cast<InvLogitGaussianVectorRV<V, M> * >(m_rvs[0]); V transformedPreComputingPositions(*m_preComputingPositions[stageId]); transformToGaussianSpace(*m_preComputingPositions[stageId], transformedPreComputingPositions); invlogit_gaussian->updateLawExpVector(transformedPreComputingPositions); return (*invlogit_gaussian); }
void GenericMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::covMatrix(const P_V& positionVector1, const P_V& positionVector2, Q_M& imageMatrix) const { if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) { *m_env.subDisplayFile() << "Entering GenericMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::covMatrix()" << std::endl; } unsigned int matrixOrder = m_imageSet.vectorSpace().dimLocal(); queso_require_equal_to_msg(imageMatrix.numRowsLocal(), matrixOrder, "imageMatrix has invalid number of rows"); queso_require_equal_to_msg(imageMatrix.numCols(), matrixOrder, "imageMatrix has invalid number of columns"); queso_require_msg(m_covRoutinePtr, "m_covRoutinePtr = NULL"); m_covRoutinePtr(positionVector1, positionVector2, m_routineDataPtr, imageMatrix); if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) { *m_env.subDisplayFile() << "Leaving GenericMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::covMatrix()" << std::endl; } return; }
double PoweredJointPdf<V,M>::actualValue( const V& domainVector, const V* domainDirection, V* gradVector, M* hessianMatrix, V* hessianEffect) const { if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) { *m_env.subDisplayFile() << "Entering PoweredJointPdf<V,M>::actualValue()" << ": domainVector = " << domainVector << std::endl; } queso_require_equal_to_msg(domainVector.sizeLocal(), this->m_domainSet.vectorSpace().dimLocal(), "invalid input"); double value = m_srcDensity.actualValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect); queso_require_msg(!(domainDirection || gradVector || hessianMatrix || hessianEffect), "incomplete code for domainDirection, gradVector, hessianMatrix and hessianEffect calculations"); double returnValue = pow(value,m_exponent); returnValue *= exp(m_logOfNormalizationFactor); // [PDF-08] ??? if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) { *m_env.subDisplayFile() << "Leaving PoweredJointPdf<V,M>::actualValue()" << ": domainVector = " << domainVector << ", returnValue = " << returnValue << std::endl; } return returnValue; }
double PoweredJointPdf<V,M>::lnValue( const V& domainVector, const V* domainDirection, V* gradVector, M* hessianMatrix, V* hessianEffect) const { if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) { *m_env.subDisplayFile() << "Entering PoweredJointPdf<V,M>::lnValue()" << ": domainVector = " << domainVector << std::endl; } double value = m_srcDensity.lnValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect); queso_require_msg(!(domainDirection || gradVector || hessianMatrix || hessianEffect), "incomplete code for domainDirection, gradVector, hessianMatrix and hessianEffect calculations"); double returnValue = m_exponent*value; returnValue += m_logOfNormalizationFactor; // [PDF-08] ??? if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) { *m_env.subDisplayFile() << "Leaving PoweredJointPdf<V,M>::lnValue()" << ": domainVector = " << domainVector << ", returnValue = " << returnValue << std::endl; } return returnValue; }
const D_V& ExperimentStorage<S_V,S_M,D_V,D_M>::yVec_transformed() const { queso_require_msg(m_yVec_transformed, "'m_yVec_transformed' is NULL"); return *m_yVec_transformed; }
const D_M& ExperimentStorage<S_V,S_M,D_V,D_M>::Wy() const { queso_require_msg(m_Wy, "'m_Wy' is NULL"); return *m_Wy; }
void GpmsaComputerModelOptions::scanOptionsValues() { queso_deprecated(); #ifndef DISABLE_BOOST_PROGRAM_OPTIONS queso_require_msg(m_optionsDesc, "m_optionsDesc variable is NULL"); defineMyOptions (*m_optionsDesc); m_env.scanInputFileForMyOptions(*m_optionsDesc); //std::cout << "scan 000\n" // << std::endl; getMyOptionValues (*m_optionsDesc); //std::cout << "scan 001\n" // << std::endl; #endif // DISABLE_BOOST_PROGRAM_OPTIONS if (m_env.subDisplayFile() != NULL) { *m_env.subDisplayFile() << "In GpmsaComputerModelOptions::scanOptionsValues()" << ": after reading values of options with prefix '" << m_prefix << "', state of object is:" << "\n" << *this << std::endl; } return; }
void GslVector::mpiAllQuantile(double probability, const MpiComm& opComm, GslVector& resultVec) const { // Filter out those nodes that should not participate if (opComm.MyPID() < 0) return; queso_require_msg(!((probability < 0.) || (1. < probability)), "invalid input"); unsigned int size = this->sizeLocal(); queso_require_equal_to_msg(size, resultVec.sizeLocal(), "different vector sizes"); for (unsigned int i = 0; i < size; ++i) { double auxDouble = (int) (*this)[i]; std::vector<double> vecOfDoubles(opComm.NumProc(),0.); opComm.Gather((void *) &auxDouble, 1, RawValue_MPI_DOUBLE, (void *) &vecOfDoubles[0], (int) 1, RawValue_MPI_DOUBLE, 0, "GslVector::mpiAllQuantile()", "failed MPI.Gather()"); std::sort(vecOfDoubles.begin(), vecOfDoubles.end()); double result = vecOfDoubles[(unsigned int)( probability*((double)(vecOfDoubles.size()-1)) )]; opComm.Bcast((void *) &result, (int) 1, RawValue_MPI_DOUBLE, 0, "GslVector::mpiAllQuantile()", "failed MPI.Bcast()"); resultVec[i] = result; } return; }
// I/O methods--------------------------------------- void EnvironmentOptions::scanOptionsValues() { queso_deprecated(); #ifndef DISABLE_BOOST_PROGRAM_OPTIONS queso_require_msg(m_optionsDesc, "m_optionsDesc variable is NULL"); #endif // DISABLE_BOOST_PROGRAM_OPTIONS #ifndef DISABLE_BOOST_PROGRAM_OPTIONS defineMyOptions (*m_optionsDesc); m_env.scanInputFileForMyOptions(*m_optionsDesc); getMyOptionValues (*m_optionsDesc); #endif // DISABLE_BOOST_PROGRAM_OPTIONS // 'm_subDisplayOutputFile' is still not available at this moment. Use 'std::cout' //if (m_env.subScreenFile() != NULL) { // *m_env.subScreenFile() if ((m_env.fullRank() == 0) && (m_env.displayVerbosity() >= 3)) { std::cout << "In EnvironmentOptions::scanOptionsValues()" << ": after reading values of options with prefix '" << m_prefix << "', state of object is:" << "\n" << *this << std::endl; } return; }
GslVector& GslVector::operator*=(double a) { int iRC; iRC = gsl_vector_scale(m_vec,a); queso_require_msg(!(iRC), "failed"); return *this; }
GslVector& GslVector::operator+=(const GslVector& rhs) { int iRC; iRC = gsl_vector_add(m_vec,rhs.m_vec); queso_require_msg(!(iRC), "failed"); return *this; }
const D_V& ExperimentStorage<S_V,S_M,D_V,D_M>::dataVec_transformed(unsigned int experimentId) const { queso_require_less_msg(experimentId, m_dataVecs_transformed.size(), "experimentId is too large"); queso_require_msg(m_dataVecs_transformed[experimentId], "vector is NULL"); return *(m_dataVecs_transformed[experimentId]); }
const S_V& ExperimentStorage<S_V,S_M,D_V,D_M>::scenarioVec_standard(unsigned int experimentId) const { queso_require_less_msg(experimentId, m_scenarioVecs_standard.size(), "experimentId is too large"); queso_require_msg(m_scenarioVecs_standard[experimentId], "vector is NULL"); return *(m_scenarioVecs_standard[experimentId]); }
double BayesianJointPdf<V,M>::actualValue( const V& domainVector, const V* domainDirection, V* gradVector, M* hessianMatrix, V* hessianEffect) const { if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) { *m_env.subDisplayFile() << "Entering BayesianJointPdf<V,M>::actualValue()" << ": domainVector = " << domainVector << std::endl; } queso_require_equal_to_msg(domainVector.sizeLocal(), this->m_domainSet.vectorSpace().dimLocal(), "invalid input"); V* gradVLike = NULL; if (gradVector) gradVLike = &m_tmpVector1; M* hessianMLike = NULL; if (hessianMatrix) hessianMLike = m_tmpMatrix; V* hessianELike = NULL; if (hessianEffect) hessianELike = &m_tmpVector2; double value1 = m_priorDensity.actualValue (domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect); double value2 = 1.; if (m_likelihoodExponent != 0.) { value2 = m_likelihoodFunction.actualValue(domainVector,domainDirection,gradVLike ,hessianMLike ,hessianELike ); } queso_require_msg(!(gradVector || hessianMatrix || hessianEffect), "incomplete code for gradVector, hessianMatrix and hessianEffect calculations"); double returnValue = value1; if (m_likelihoodExponent == 0.) { // Do nothing } else if (m_likelihoodExponent == 1.) { returnValue *= value2; } else { returnValue *= pow(value2,m_likelihoodExponent); } returnValue *= exp(m_logOfNormalizationFactor); // [PDF-02] ??? m_lastComputedLogPrior = log(value1); m_lastComputedLogLikelihood = m_likelihoodExponent*log(value2); if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) { *m_env.subDisplayFile() << "Leaving BayesianJointPdf<V,M>::actualValue()" << ": domainVector = " << domainVector << ", returnValue = " << returnValue << std::endl; } return returnValue; }
const V & GPMSAFactory<V, M>::experimentOutput( unsigned int experimentId) const { queso_require_less_msg(experimentId, (this->m_experimentOutputs).size(), "experimentId is too large"); queso_require_msg(this->m_experimentOutputs[experimentId], "vector is NULL"); return *(this->m_experimentOutputs[experimentId]); }
const V & GPMSAFactory<V, M>::simulationOutput( unsigned int simulationId) const { queso_require_less_msg(simulationId, m_simulationOutputs.size(), "simulationId is too large"); queso_require_msg(m_simulationOutputs[simulationId], "vector is NULL"); return *(this->m_simulationOutputs[simulationId]); }
void GslVector::copy(const GslVector& src) { this->Vector::base_copy(src); int iRC; iRC = gsl_vector_memcpy(this->m_vec, src.m_vec); queso_require_msg(!(iRC), "failed"); return; }
const BaseVectorSequence<Q_V,Q_M>& StatisticalForwardProblem<P_V,P_M,Q_V,Q_M>::getParamChain() const { // Make sure this runs after the forward propagation // only then we obtain the actual realizations of the parameters queso_require_msg(m_paramChain, "m_paramChain is NULL"); return *m_paramChain; }
void GslVector::mpiBcast(int srcRank, const MpiComm& bcastComm) { // Filter out those nodes that should not participate if (bcastComm.MyPID() < 0) return; // Check 'srcRank' queso_require_msg(!((srcRank < 0) || (srcRank >= bcastComm.NumProc())), "invalud srcRank"); // Check number of participant nodes double localNumNodes = 1.; double totalNumNodes = 0.; bcastComm.Allreduce((void *) &localNumNodes, (void *) &totalNumNodes, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, "GslVector::mpiBcast()", "failed MPI.Allreduce() for numNodes"); queso_require_equal_to_msg(((int) totalNumNodes), bcastComm.NumProc(), "inconsistent numNodes"); // Check that all participant nodes have the same vector size double localVectorSize = this->sizeLocal(); double sumOfVectorSizes = 0.; bcastComm.Allreduce((void *) &localVectorSize, (void *) &sumOfVectorSizes, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, "GslVector::mpiBcast()", "failed MPI.Allreduce() for vectorSize"); if ( ((unsigned int) sumOfVectorSizes) != ((unsigned int)(totalNumNodes*localVectorSize)) ) { std::cerr << "rank " << bcastComm.MyPID() << ": sumOfVectorSizes = " << sumOfVectorSizes << ", totalNumNodes = " << totalNumNodes << ", localVectorSize = " << localVectorSize << std::endl; } bcastComm.Barrier(); queso_require_equal_to_msg(((unsigned int) sumOfVectorSizes), ((unsigned int)(totalNumNodes*localVectorSize)), "inconsistent vectorSize"); // Ok, bcast data std::vector<double> dataBuffer((unsigned int) localVectorSize, 0.); if (bcastComm.MyPID() == srcRank) { for (unsigned int i = 0; i < dataBuffer.size(); ++i) { dataBuffer[i] = (*this)[i]; } } bcastComm.Bcast((void *) &dataBuffer[0], (int) localVectorSize, RawValue_MPI_DOUBLE, srcRank, "GslVector::mpiBcast()", "failed MPI.Bcast()"); if (bcastComm.MyPID() != srcRank) { for (unsigned int i = 0; i < dataBuffer.size(); ++i) { (*this)[i] = dataBuffer[i]; } } return; }
const GaussianVectorRV<V, M> & ScaledCovMatrixTKGroup<V, M>::rv(const V & position) const { queso_require_not_equal_to_msg(m_rvs.size(), 0, "m_rvs.size() = 0"); queso_require_msg(m_rvs[0], "m_rvs[0] == NULL"); //queso_require_greater_msg(m_preComputingPositions.size(), this->m_stageId, "m_preComputingPositions.size() <= stageId"); //queso_require_msg(m_preComputingPositions[this->m_stageId], "m_preComputingPositions[stageId] == NULL"); GaussianVectorRV<V, M> * gaussian_rv = dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[this->m_stageId]); gaussian_rv->updateLawExpVector(position); return (*gaussian_rv); }
// --------------------------------------------------- TeuchosVector::TeuchosVector(const BaseEnvironment& env, const Map& map, double value) : Vector(env,map) { m_vec.size(map.NumGlobalElements()); m_vec = value; queso_require_msg(m_vec != NULL, "null vector generated"); queso_require_equal_to_msg(m_vec.length(), map.NumMyElements(), "incompatible local vec size"); queso_require_equal_to_msg(m_vec.length(), map.NumGlobalElements(), "incompatible global vec size"); queso_require_equal_to_msg(m_vec.length(), m_map.NumMyElements(), "incompatible own vec size"); }
// --------------------------------------------------- TeuchosVector::TeuchosVector(const TeuchosVector& v) // mox : Vector(v.env(),v.map()) { m_vec.size(v.sizeLocal()); queso_require_msg(m_vec != NULL, "null vector generated"); queso_require_equal_to_msg(m_vec.length(), v.map().NumMyElements(), "incompatible local vec size"); queso_require_equal_to_msg(m_vec.length(), v.map().NumGlobalElements(), "incompatible global vec size"); this->copy(v); queso_require_equal_to_msg(m_vec.length(), m_map.NumMyElements(), "incompatible own vec size"); }
void ConstantVectorFunction<P_V,P_M,Q_V,Q_M>::compute( const P_V& domainVector, const P_V* domainDirection, Q_V& imageVector, DistArray<P_V*>* gradVectors, // Yes, 'P_V' DistArray<P_M*>* hessianMatrices, // Yes, 'P_M' DistArray<P_V*>* hessianEffects) const { queso_require_msg(m_constantImageVector, "m_constantImageVector is NULL"); imageVector = *m_constantImageVector; return; }
void ScaledCovMatrixTKGroup<V,M>::setRVsWithZeroMean() { queso_require_not_equal_to_msg(m_rvs.size(), 0, "m_rvs.size() = 0"); queso_require_equal_to_msg(m_rvs.size(), m_scales.size(), "m_rvs.size() != m_scales.size()"); for (unsigned int i = 0; i < m_scales.size(); ++i) { double factor = 1./m_scales[i]/m_scales[i]; queso_require_msg(!(m_rvs[i]), "m_rvs[i] != NULL"); m_rvs[i] = new GaussianVectorRV<V,M>(m_prefix.c_str(), *m_vectorSpace, m_vectorSpace->zeroVector(), factor*m_originalCovMatrix); } }
double GaussianJointPdf<V,M>::actualValue( const V& domainVector, const V* domainDirection, V* gradVector, M* hessianMatrix, V* hessianEffect) const { if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 55)) { *m_env.subDisplayFile() << "Entering GaussianJointPdf<V,M>::actualValue()" << ", meanVector = " << *m_lawExpVector << ", lawCovMatrix = " << *m_lawCovMatrix << ": domainVector = " << domainVector << std::endl; } queso_require_equal_to_msg(domainVector.sizeLocal(), this->m_domainSet.vectorSpace().dimLocal(), "invalid input"); queso_require_msg(!(hessianMatrix || hessianEffect), "incomplete code for gradVector, hessianMatrix and hessianEffect calculations"); double returnValue = 0.; if (this->m_domainSet.contains(domainVector) == false) { // What should the gradient be here? returnValue = 0.; } else { // Already normalised (so the gradient will have the normalisation constant // in it) returnValue = std::exp(this->lnValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect)); if (gradVector) { (*gradVector) *= returnValue; } } if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 55)) { *m_env.subDisplayFile() << "Leaving GaussianJointPdf<V,M>::actualValue()" << ", meanVector = " << *m_lawExpVector << ", lawCovMatrix = " << *m_lawCovMatrix << ": domainVector = " << domainVector << ", returnValue = " << returnValue << std::endl; } return returnValue; }
// --------------------------------------------------- TeuchosVector::TeuchosVector(const BaseEnvironment& env, double d1, double d2, const Map& map) : Vector(env,map) { m_vec.size(map.NumGlobalElements()); queso_require_msg(m_vec != NULL, "null vector generated"); queso_require_equal_to_msg(m_vec.length(), map.NumMyElements(), "incompatible local vec size"); queso_require_equal_to_msg(m_vec.length(), map.NumGlobalElements(), "incompatible global vec size"); for (int i = 0; i < m_vec.length(); ++i) { double alpha = (double) i / ((double) m_vec.length() - 1.); (*this)[i] = (1.-alpha)*d1 + alpha*d2; } queso_require_equal_to_msg(m_vec.length(), m_map.NumMyElements(), "incompatible own vec size"); }
// --------------------------------------------------- TeuchosVector::TeuchosVector(const TeuchosVector& v, double d1, double d2) : Vector(v.env(),v.map()) { m_vec.size(v.sizeLocal()); queso_require_msg(m_vec != NULL, "null vector generated"); queso_require_equal_to_msg(m_vec.length(), v.map().NumMyElements(), "incompatible local vec size"); queso_require_equal_to_msg(m_vec.length(), v.map().NumGlobalElements(), "incompatible global vec size"); for ( int i = 0; i < m_vec.length(); ++i) { double alpha = (double) i / ((double) m_vec.length() - 1.); (*this)[i] = (1.-alpha)*d1 + alpha*d2; } queso_require_equal_to_msg(m_vec.length(), m_map.NumMyElements(), "incompatible own vec size"); }
//--------------------------------------------------- unsigned int FiniteDistribution::sample() const { queso_deprecated(); unsigned int result = 0; double aux = m_env.rngObject()->uniformSample(); queso_require_msg(!((aux < 0) || (aux > 1.)), "invalid uniform"); if (aux == 0.) { result = 0; } else if (aux == 1.) { result = m_map.find(aux)->second; } else { result = m_map.upper_bound(aux)->second; //if (m_map.upper_bound(aux)->second == 0) { // result = 0; //} //else { // result = m_map.upper_bound(aux)->second-1; //} } #if 0 // WE insert 'i' in map, not 'j'. So, the tests below don't make sense if (result >= m_map.size()) { std::cerr << "In FiniteDistribution::sample()" << ": aux = " << aux << ", m_map.size() = " << m_map.size() << ", result = " << result << std::endl; } queso_require_less_msg(result, m_map.size(), "invalid result"); #endif return result; }
const V& MarkovChainPositionData<V>::vecValues() const { queso_require_msg(m_vecValues, "m_vecValues is NULL"); return *m_vecValues; }