Example #1
0
//--------------------------------------------------------
double NRLib::FindLargestElement(const NRLib::Vector & v)
//-------------------------------------------------------
{
  double max_value = -std::numeric_limits<double>::infinity();
  for (int i=0 ; i < v.length() ; i++) {
    if (v(i) > max_value) {
      max_value = v(i);
    }
  }
  return max_value;
}
Example #2
0
void
Kriging2D::fillKrigingVector(NRLib::Vector          & k,
                             const CovGrid2D        & cov,
                             const std::vector<int> & indexi,
                             const std::vector<int> & indexj,
                             int i, int j)
{
  for(int ii=0 ; ii < k.length() ; ii++) {
    int deltai = indexi[ii] - i;
    int deltaj = indexj[ii] - j;
    k(ii) = static_cast<double>(cov.getCov(deltai,deltaj));
  }
}
Example #3
0
void NRLib::WriteVectorToFile(const std::string   & filename,
                              const NRLib::Vector & vector,
                              LinalgFileFormat      format)
{
  std::ofstream file;

  if (format == MatrixAscii) {
    NRLib::OpenWrite(file, filename);
    file.precision(8);
    file.setf(std::ios_base::scientific, std::ios_base::floatfield);
    for (int i = 0; i < vector.length(); ++i) {
      file.width(18);
      file << vector(i);
    }
  }
  else if (format == MatrixBinary) {
    NRLib::OpenWrite(file, filename, std::ios::out | std::ios::binary);
    for (int i = 0; i < vector.length(); ++i) {
      NRLib::WriteBinaryDouble(file, vector(i));
    }
  }
}
Example #4
0
void
Kriging2D::subtractTrend(NRLib::Vector            & residual,
                         const std::vector<float> & data,
                         const Grid2D             & trend,
                         const std::vector<int>   & indexi,
                         const std::vector<int>   & indexj)
{
  int md = residual.length();
  for (int i = 0 ; i < md ; i++)
    residual(i) = data[i] - static_cast<float>(trend(indexi[i],indexj[i]));

  bool debug = false;
  if (debug) {
    LogKit::LogFormatted(LogKit::Low,"\nData vector after trend subtraction:\n");
    for (int i = 0 ; i < md ; i++) {
      LogKit::LogFormatted(LogKit::Low," i indexi[i] indexj[i] residual : %3d %3d %3d  %.5f\n",i,indexi[i],indexj[i],residual(i));
    }
  }
}