Esempio n. 1
0
void
GPMSAFactory<V, M>::addSimulation(V & simulationScenario,
                                            V & simulationParameter,
                                            V & simulationOutput)
{
  queso_require_less_msg(this->m_numSimulationAdds, this->m_numSimulations, "too many simulation adds...");

  this->m_simulationScenarios[this->m_numSimulationAdds] = &simulationScenario;
  this->m_simulationParameters[this->m_numSimulationAdds] = &simulationParameter;
  this->m_simulationOutputs[this->m_numSimulationAdds] = &simulationOutput;
  this->m_numSimulationAdds++;

  if ((this->m_numSimulationAdds == this->m_numSimulations) &&
      (this->m_numExperimentAdds == this->m_numExperiments) &&
      (this->m_constructedGP == false)) {
    this->m_constructedGP = true;
    this->gpmsaEmulator = new GPMSAEmulator<V, M>(
        this->prior().imageSet(),
        this->m_scenarioSpace,
        this->m_parameterSpace,
        this->m_simulationOutputSpace,
        this->m_experimentOutputSpace,
        this->m_numSimulations,
        this->m_numExperiments,
        this->m_simulationScenarios,
        this->m_simulationParameters,
        this->m_simulationOutputs,
        this->m_experimentScenarios,
        this->m_experimentOutputs,
        *(this->m_experimentErrors),
        *(this->m_totalPrior));
  }
}
Esempio n. 2
0
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]);
}
Esempio n. 3
0
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]);
}
Esempio n. 4
0
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]);
}
Esempio n. 5
0
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]);
}
Esempio n. 6
0
/* extracts elements from vector (*this) starting at position initialPos and save in vec */
void TeuchosVector::cwExtract(unsigned int initialPos, TeuchosVector& vec) const
{
   queso_require_less_msg(initialPos, this->sizeLocal(), "invalid initialPos");

   queso_require_less_equal_msg((initialPos +vec.sizeLocal()), this->sizeLocal(), "invalid vec.sizeLocal()");

  for (unsigned int i = 0; i < vec.sizeLocal(); ++i) {
    vec[i] = (*this)[initialPos+i];
  }

  return;
}
Esempio n. 7
0
void
GslVector::cwSet(unsigned int initialPos, const GslVector& vec)
{
  queso_require_less_msg(initialPos, this->sizeLocal(), "invalid initialPos");

  queso_require_less_equal_msg((initialPos +vec.sizeLocal()), this->sizeLocal(), "invalid vec.sizeLocal()");

  for (unsigned int i = 0; i < vec.sizeLocal(); ++i) {
    (*this)[initialPos+i] = vec[i];
  }

  return;
}
Esempio n. 8
0
void
GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::commonConstructor(const GcmZInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>& z)
{
    unsigned int cMatTildeRank   = m_Cmat_tilde.rank(0.,1.e-8 ); // todo: should be an option
    unsigned int cMatTildeRank14 = m_Cmat_tilde.rank(0.,1.e-14);
    if (m_env.subDisplayFile()) {
      *m_env.subDisplayFile() << "In GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
                              << ": m_Cmat_tilde.numRowsLocal() = "  << m_Cmat_tilde.numRowsLocal()
                              << ", m_Cmat_tilde.numCols() = "       << m_Cmat_tilde.numCols()
                              << ", m_Cmat_tilde.rank(0.,1.e-8) = "  << cMatTildeRank
                              << ", m_Cmat_tilde.rank(0.,1.e-14) = " << cMatTildeRank14
                              << std::endl;
    }
    queso_require_equal_to_msg(cMatTildeRank, z.m_Cmat_rank, "'m_Cmat_tilde' should have full column rank");

    queso_require_less_msg(m_Lmat.numRowsGlobal(), m_Lmat.numCols(), "'m_Lmat' should be a 'horizontal' rectangular matrix");

    //******************************************************************************
    // Tilde situation: form 'm_Lmat_t'
    //******************************************************************************
    m_Lmat_t.fillWithTranspose(0,0,m_Lmat,true,true);
    unsigned int lMatRank   = m_Lmat_t.rank(0.,1.e-8 ); // todo: should be an option
    unsigned int lMatRank14 = m_Lmat_t.rank(0.,1.e-14);
    if (m_env.subDisplayFile()) {
      *m_env.subDisplayFile() << "In GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::commonConstructor()"
                              << ": m_Lmat.numRowsLocal() = "  << m_Lmat.numRowsLocal()
                              << ", m_Lmat.numCols() = "       << m_Lmat.numCols()
                              << ", m_Lmat.rank(0.,1.e-8) = "  << lMatRank
                              << ", m_Lmat.rank(0.,1.e-14) = " << lMatRank14
                              << std::endl;
    }

    queso_require_equal_to_msg(lMatRank, z.m_Cmat_rank, "'m_Lmat' should have full row rank");

    if (m_env.checkingLevel() >= 1) {
      // Check if C == C_tilde * L
      D_M tmpCmat(m_Cmat_tilde * m_Lmat);
      tmpCmat -= *z.m_Cmat;
      double cDiffNorm = tmpCmat.normFrob();
      if (m_env.subDisplayFile()) {
        *m_env.subDisplayFile() << "In GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::commonConstructor()"
                                << ": ||tmpC - C||_2 = " << cDiffNorm
                                << std::endl;
      }
    }

  return;
}
Esempio n. 9
0
//---------------------------------------------------
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;
}
Esempio n. 10
0
void
ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment(
  const S_V& scenarioVec_standard,
  const D_V& dataVec_transformed,
  const D_M& covMat_transformed_inv)
{
  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
    *m_env.subDisplayFile() << "Entering ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment()"
                            << ": m_addId = " << m_addId
                            << "\n  scenarioVec_standard = "   << scenarioVec_standard
                            << "\n  dataVec_transformed = "    << dataVec_transformed
                            << "\n  covMat_transformed_inv = " << covMat_transformed_inv
                            << std::endl;
  }

  queso_require_less_msg(m_addId, m_paper_n, "too many adds...");

  m_scenarioVecs_standard  [m_addId] = &scenarioVec_standard;
  m_dataVecs_transformed   [m_addId] = &dataVec_transformed;
  m_covMats_transformed_inv[m_addId] = &covMat_transformed_inv;
  m_paper_n_ys_transformed[m_addId] = dataVec_transformed.sizeLocal();
  m_paper_n_y += m_paper_n_ys_transformed[m_addId];
  m_addId++;

  if (m_addId == m_paper_n) {
    if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
      *m_env.subDisplayFile() << "KEY In ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment()"
                              << ": m_addId = " << m_addId
                              << ", m_paper_n_y = " << m_paper_n_y
                              << std::endl;
    }

    //***********************************************************************
    // Form 'yVec_transformed', 'Wy' matrix, and compute its inverse
    //***********************************************************************
    m_y_space = new VectorSpace<D_V,D_M>(m_env, "m_y_exp_storage", m_paper_n_y, NULL),
    m_yVec_transformed = new D_V(m_y_space->zeroVector());
    m_yVec_transformed->cwSetConcatenated(m_dataVecs_transformed);

    if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
      *m_env.subDisplayFile() << "In ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment()"
                              << ": populated yVec_transformed of size = " << m_yVec_transformed->sizeLocal()
                              << "\n *m_yVec_transformed = " << *m_yVec_transformed
                              << std::endl;
    }

    m_Wy = new D_M(m_y_space->zeroVector());
    if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
      *m_env.subDisplayFile() << "In ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment()"
                              << ": key-debug"
                              << ", m_Wy just created (not yet populated)"
                              << ", numRowsLocal = " << m_Wy->numRowsLocal()
                              << ", numCols = "      << m_Wy->numCols()
                              << std::endl;
    }

    m_Wy->fillWithBlocksDiagonally(0,0,m_covMats_transformed_inv,true,true);
    if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
      *m_env.subDisplayFile() << "In ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment()"
                              << ": key-debug"
                              << ", m_Wy just populated"
                              << std::endl;
    }

    if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
      *m_env.subDisplayFile() << "In ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment()"
                              << ": m_Wy->lnDeterminant() = " << m_Wy->lnDeterminant()
                              << std::endl;
    }
  }

  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
    *m_env.subDisplayFile() << "Leaving ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment()"
                            << ": m_addId = " << m_addId
                            << std::endl;
  }

  return;
}
Esempio n. 11
0
void
GslVector::subReadContents(
  const std::string&            fileName,
  const std::string&            fileType,
  const std::set<unsigned int>& allowedSubEnvIds)
{
  queso_require_greater_equal_msg(m_env.subRank(), 0, "unexpected subRank");

  queso_require_less_equal_msg(this->numOfProcsForStorage(), 1, "implemented just for sequential vectors for now");

  FilePtrSetStruct filePtrSet;
  if (m_env.openInputFile(fileName,
                          fileType, // "m or hdf"
                          allowedSubEnvIds,
                          filePtrSet)) {
    double subReadSize = this->sizeLocal();

    // In the logic below, the id of a line' begins with value 0 (zero)
    unsigned int idOfMyFirstLine = 1;
    unsigned int idOfMyLastLine = this->sizeLocal();
    unsigned int numParams = 1; // Yes, just '1'

    // Read number of chain positions in the file by taking care of the first line,
    // which resembles something like 'variable_name = zeros(n_positions,m_params);'
    std::string tmpString;

    // Read 'variable name' string
    *filePtrSet.ifsVar >> tmpString;
    //std::cout << "Just read '" << tmpString << "'" << std::endl;

    // Read '=' sign
    *filePtrSet.ifsVar >> tmpString;
    //std::cout << "Just read '" << tmpString << "'" << std::endl;
    queso_require_equal_to_msg(tmpString, "=", "string should be the '=' sign");

    // Read 'zeros(n_positions,n_params)' string
    *filePtrSet.ifsVar >> tmpString;
    //std::cout << "Just read '" << tmpString << "'" << std::endl;
    unsigned int posInTmpString = 6;

    // Isolate 'n_positions' in a string
    char nPositionsString[tmpString.size()-posInTmpString+1];
    unsigned int posInPositionsString = 0;
    do {
      queso_require_less_msg(posInTmpString, tmpString.size(), "symbol ',' not found in first line of file");
      nPositionsString[posInPositionsString++] = tmpString[posInTmpString++];
    } while (tmpString[posInTmpString] != ',');
    nPositionsString[posInPositionsString] = '\0';

    // Isolate 'n_params' in a string
    posInTmpString++; // Avoid reading ',' char
    char nParamsString[tmpString.size()-posInTmpString+1];
    unsigned int posInParamsString = 0;
    do {
      queso_require_less_msg(posInTmpString, tmpString.size(), "symbol ')' not found in first line of file");
      nParamsString[posInParamsString++] = tmpString[posInTmpString++];
    } while (tmpString[posInTmpString] != ')');
    nParamsString[posInParamsString] = '\0';

    // Convert 'n_positions' and 'n_params' strings to numbers
    unsigned int sizeOfVecInFile = (unsigned int) strtod(nPositionsString,NULL);
    unsigned int numParamsInFile = (unsigned int) strtod(nParamsString,   NULL);
    if (m_env.subDisplayFile()) {
      *m_env.subDisplayFile() << "In GslVector::subReadContents()"
                              << ": fullRank "            << m_env.fullRank()
                              << ", sizeOfVecInFile = "   << sizeOfVecInFile
                              << ", numParamsInFile = "   << numParamsInFile
                              << ", this->sizeLocal() = " << this->sizeLocal()
                              << std::endl;
    }

    // Check if [size of vec in file] >= [requested sub vec size]
    queso_require_greater_equal_msg(sizeOfVecInFile, subReadSize, "size of vec in file is not big enough");

    // Check if [num params in file] == [num params in current vec]
    queso_require_equal_to_msg(numParamsInFile, numParams, "number of parameters of vec in file is different than number of parameters in this vec object");

    // Code common to any core in a communicator
    unsigned int maxCharsPerLine = 64*numParams; // Up to about 60 characters to represent each parameter value

    unsigned int lineId = 0;
    while (lineId < idOfMyFirstLine) {
      filePtrSet.ifsVar->ignore(maxCharsPerLine,'\n');
      lineId++;
    };

    if (m_env.subDisplayFile()) {
      *m_env.subDisplayFile() << "In GslVector::subReadContents()"
                              << ": beginning to read input actual data"
                              << std::endl;
    }

    // Take care of initial part of the first data line,
    // which resembles something like 'variable_name = [value1 value2 ...'
    // Read 'variable name' string
    *filePtrSet.ifsVar >> tmpString;
    //std::cout << "Core 0 just read '" << tmpString << "'" << std::endl;

    // Read '=' sign
    *filePtrSet.ifsVar >> tmpString;
    //std::cout << "Core 0 just read '" << tmpString << "'" << std::endl;
    queso_require_equal_to_msg(tmpString, "=", "in core 0, string should be the '=' sign");

    // Take into account the ' [' portion
    std::streampos tmpPos = filePtrSet.ifsVar->tellg();
    filePtrSet.ifsVar->seekg(tmpPos+(std::streampos)2);

    if (m_env.subDisplayFile()) {
      *m_env.subDisplayFile() << "In GslVector::subReadContents()"
                              << ": beginning to read lines with numbers only"
                              << ", lineId = " << lineId
                              << ", idOfMyFirstLine = " << idOfMyFirstLine
                              << ", idOfMyLastLine = " << idOfMyLastLine
                              << std::endl;
    }

    while (lineId <= idOfMyLastLine) {
      *filePtrSet.ifsVar >> (*this)[lineId - idOfMyFirstLine];
      lineId++;
    };

    m_env.closeFile(filePtrSet,fileType);
  }