int quantize(Real x, char *type, FeatureMedoid **fms, int mn){
  int m, nn;
  double *mean = NULL, *sigma = NULL;
  distance_metric dm = NULL;
  for (m = 0; m < mn; m ++)
    if (strcmp(type, fms[m]->name) == 0)
      break;
  if (m == mn)
    panic("quantize: type = %s unrecognized value type!", type);
  nn = fms[m]->nn;
  mean = fms[m]->mean;
  sigma = fms[m]->sigma;
  dm = (fms[m]->dm_id == 0)? fake_mahalanobis: my_angle_separation;
  return nearest_1d(x, mean, sigma, nn, dm);
}
Exemple #2
0
/** Builds an interpolation matrix to go from height points to ice/exchange grid.
@param ret Put the regrid matrix here.
@param elevIh Must be the result of this->elevI_hash() */
void IceRegridder_L0::GvEp(spsparse::SparseTriplets<SparseMatrix> &ret) const
{
    IceExch dest = interp_grid;
    std::unordered_map<long,double> const elevIh(elevI_hash());


    if (gcm->hpdefs.size() == 0) (*icebin_error)(-1,
        "IceRegridder_L0::GvEp(): hpdefs is zero-length!");

    // ---------------------------------------
    // Handle Z_INTERP or ELEV_CLASS_INTERP

    // Interpolate in the vertical
    for (auto cell = exgrid->cells.begin(); cell != exgrid->cells.end(); ++cell) {
        long const iA = cell->i;        // GCM Atmosphere grid
        long const iI = cell->j;        // Ice Grid
        long const iX = cell->index;    // X=Exchange Grid
        long const iG = (dest == IceExch::ICE ? iI : iX);   // G=Interpolation Grid
        auto ii = elevIh.find(iI);
        if (ii != elevIh.end()) {
            double const elev = ii->second;

            // This cell not masked: look up elevation point as usual
            double elevation = std::max(elev, 0.0);

            // Interpolate in height points
            switch(interp_style.index()) {
                case InterpStyle::Z_INTERP : {
                    int ihps[2];
                    double whps[2];
                    linterp_1d(gcm->hpdefs, elevation, ihps, whps);
                    ret.add({iG, gcm->indexingHP.tuple_to_index<2>({iA, ihps[0]})},
                        cell->native_area * whps[0]);
                    ret.add({iG, gcm->indexingHP.tuple_to_index<2>({iA, ihps[1]})},
                        cell->native_area * whps[1]);
                } break;
                case InterpStyle::ELEV_CLASS_INTERP : {
                    int ihps0 = nearest_1d(gcm->hpdefs, elevation);
                    ret.add({iG, gcm->indexingHP.tuple_to_index<2>({iA, ihps0})},
                        cell->native_area);
                } break;
            }
        }
    }
}