const vector<double>& KernelEstimationInterpolator::interpolate(const vector<double>& point) const
{
  const DataFrame& df = *_df;

  _result.resize(_depColumns.size());
  for (size_t i = 0; i < _result.size(); i++)
  {
    _result[i] = 0.0;
  }

  vector<double> simplePoint(_indColumns.size());
  for (size_t i = 0; i < _indColumns.size(); i++)
  {
    simplePoint[i] = point[_indColumns[i]];
  }

  double n0 = Normal::normal(0, _sigma);

  KnnIteratorNd it(_getIndex(), simplePoint);
  double wSum = 0.0;
  while (it.next() && it.getDistance() < _sigma * 3.0)
  {
    size_t i = it.getId();
    const vector<double>& record = df.getDataVector(i);

    // figure out the distance between point and this data vector
    double d = 0;
    for (size_t j = 0; j < _indColumns.size(); j++)
    {
      double v = point[_indColumns[j]] - record[_indColumns[j]];
      d += v * v;
    }
    d = sqrt(d);
    if (d / _sigma < 3.0)
    {
      // calculate the weight of this sample.
      double w = Normal::normal(d, _sigma) / n0;
      wSum += w;

      assert(w <= 1.000001);

      // calculate the contribution to the predicted value.
      for (size_t j = 0; j < _result.size(); j++)
      {
        _result[j] += (record[_depColumns[j]] * w);
      }
    }
  }
  // do less rubber sheeting as we get far away from tie points.
  wSum = std::max(wSum, n0);

  for (size_t j = 0; j < _result.size(); j++)
  {
    _result[j] /= wSum;
  }

  return _result;
}
Esempio n. 2
0
fmi2Boolean _isTime(ModelInstance *comp) {
    if (_isEmpty(comp)) {
        return fmi2False;
    }
    if (comp->time == _getTime(comp) && comp->microstep == _getIndex(comp)){
        return fmi2True;
    } else {
        return fmi2False;
    }
}
bool _isTime(ModelInstance *comp) {
    if (_isEmpty()) {
        return false;
    }
    if (comp->time == _getTime() && i(microstep_) == _getIndex()){
        return true;
    } else {
        return false;
    }
}
static CMPIStatus
enumInstances(CMPIInstanceMI * mi,
              const CMPIContext *ctx, void *rslt,
              const CMPIObjectPath * ref,
              const char **properties,
              void (*retFnc) (void *, CMPIInstance *), int ignprov)
{
  CMPIStatus      st = { CMPI_RC_OK, NULL };
  CMPIStatus      sti = { CMPI_RC_OK, NULL };
  BlobIndex      *bi;
  CMPIString     *cn = CMGetClassName(ref, NULL);
  CMPIString     *ns = CMGetNameSpace(ref, NULL);
  const char     *nss = ns->ft->getCharPtr(ns, NULL);
  const char     *cns = cn->ft->getCharPtr(cn, NULL);
  const char     *bnss = repositoryNs(nss);
  int             len,
                  i,
                  ac = 0;
  CMPIInstance   *ci;
  CMPIArgs       *in,
                 *out;
  CMPIObjectPath *op;
  CMPIArray      *ar;
  CMPIData        rv;
  const char    **keyList;

  _SFCB_ENTER(TRACE_INTERNALPROVIDER, "enumInstances");
  _SFCB_TRACE(1, ("--- %s %s", nss, cns));

  in = CMNewArgs(Broker, NULL);
  out = CMNewArgs(Broker, NULL);
  if (ignprov)
    CMAddArg(in, "classignoreprov", cns, CMPI_chars);
  else
    CMAddArg(in, "class", cns, CMPI_chars);

  op = CMNewObjectPath(Broker, bnss, "$ClassProvider$", &sti);
  _SFCB_TRACE(1, ("--- getallchildren"));
  rv = CBInvokeMethod(Broker, ctx, op, "getallchildren", in, out, &sti);
  _SFCB_TRACE(1, ("--- getallchildren rc: %d", sti.rc));

  ar = CMGetArg(out, "children", NULL).value.array;
  if (ar)
    ac = CMGetArrayCount(ar, NULL);
  _SFCB_TRACE(1, ("--- getallchildren ar: %p count: %d", ar, ac));

  for (i = 0; cns; i++) {
    _SFCB_TRACE(1, ("--- looking for %s", cns));
    if ((bi = _getIndex(bnss, cns)) != NULL) {
      for (ci = ipGetFirst(bi, &len, NULL, 0); ci;
           ci = ipGetNext(bi, &len, NULL, 0)) {
        if (properties) {
          keyList = getKeyList(ci->ft->getObjectPath(ci, NULL));
          ci->ft->setPropertyFilter(ci, properties, keyList);
          if (keyList) {
            free(keyList);
          }
        }
        _SFCB_TRACE(1, ("--- returning instance %p", ci));
        retFnc(rslt, ci);
      }
    }
    freeBlobIndex(&bi, 1);
    if (i < ac)
      cns = (char *) CMGetArrayElementAt(ar, i, NULL).value.string->hdl;
    else
      cns = NULL;
  }

  _SFCB_RETURN(st);
}
CMPIStatus
InternalProviderEnumInstanceNames(CMPIInstanceMI * mi,
                                  const CMPIContext *ctx,
                                  const CMPIResult *rslt,
                                  const CMPIObjectPath * ref)
{
  CMPIStatus      st = { CMPI_RC_OK, NULL };
  CMPIStatus      sti = { CMPI_RC_OK, NULL };
  BlobIndex      *bi;
  CMPIString     *cn = CMGetClassName(ref, NULL);
  CMPIString     *ns = CMGetNameSpace(ref, NULL);
  CMPIObjectPath *cop;
  const char     *nss = ns->ft->getCharPtr(ns, NULL);
  const char     *cns = cn->ft->getCharPtr(cn, NULL);
  const char     *bnss = repositoryNs(nss);
  size_t          ekl;
  int             i,
                  ac = 0;
  char            copKey[8192] = "";
  char           *kp;
  CMPIArgs       *in,
                 *out;
  CMPIObjectPath *op;
  CMPIArray      *ar;
  CMPIData        rv;

  _SFCB_ENTER(TRACE_INTERNALPROVIDER, "InternalProviderEnumInstanceNames");
  _SFCB_TRACE(1, ("%s %s", nss, cns));

  in = CMNewArgs(Broker, NULL);
  out = CMNewArgs(Broker, NULL);
  CMAddArg(in, "class", cns, CMPI_chars);
  op = CMNewObjectPath(Broker, bnss, "$ClassProvider$", &sti);
  rv = CBInvokeMethod(Broker, ctx, op, "getallchildren", in, out, &sti);
  ar = CMGetArg(out, "children", NULL).value.array;
  if (ar)
    ac = CMGetArrayCount(ar, NULL);

  for (i = 0; cns; i++) {
    if ((bi = _getIndex(bnss, cns)) != NULL) {
      if (ipGetFirst(bi, NULL, &kp, &ekl)) {
        while (1) {
          strcpy(copKey, nss);
          strcat(copKey, ":");
          strcat(copKey, cns);
          strcat(copKey, ".");
          strncat(copKey, kp, ekl);

          cop = getObjectPath(copKey, NULL);
          if (cop)
            CMReturnObjectPath(rslt, cop);
          else {
            CMPIStatus      st = { CMPI_RC_ERR_FAILED, NULL };
            return st;
          }
          if (bi->next < bi->dSize && ipGetNext(bi, NULL, &kp, &ekl)) {
            continue;
          }
          break;
        }
      }
      freeBlobIndex(&bi, 1);
    }
    if (i < ac)
      cns = (char *) CMGetArrayElementAt(ar, i, NULL).value.string->hdl;
    else
      cns = NULL;
  }
  _SFCB_RETURN(st);
}
double KernelEstimationInterpolator::_estimateError(unsigned int index) const
{
  const DataFrame& df = *_df;

  vector<double> predicted(_depColumns.size(), 0.0);
  const vector<double>& uut = df.getDataVector(index);
  vector<double> simplePoint(_indColumns.size());
  for (size_t i = 0; i < _indColumns.size(); i++)
  {
    simplePoint[i] = uut[_indColumns[i]];
  }


  double n0 = Normal::normal(0, _sigma);

  KnnIteratorNd it(_getIndex(), simplePoint);
  double wSum = 0.0;
  while (it.next() && it.getDistance() < _sigma * 3.0)
  {
    size_t i = it.getId();
    if (i == index)
    {
      continue;
    }
    const vector<double>& record = df.getDataVector(i);

    // figure out the distance between point and this data vector
    double d = 0;
    for (size_t j = 0; j < _indColumns.size(); j++)
    {
      double v = uut[_indColumns[j]] - record[_indColumns[j]];
      d += v * v;
    }
    d = sqrt(d);
    if (d / _sigma < 3.0)
    {
      // calculate the weight of this sample.
      double w = Normal::normal(d, _sigma) / n0;
      wSum += w;

      assert(w <= 1.000001);

      // calculate the contribution to the predicted value.
      for (size_t j = 0; j < predicted.size(); j++)
      {
        predicted[j] += (record[_depColumns[j]] * w);
      }
    }
  }
  // do less rubber sheeting as we get far away from tie points.
  wSum = std::max(wSum, n0);

  double result = 0.0;
  for (size_t j = 0; j < predicted.size(); j++)
  {
    //cout << "uut[_depColumns[" << j << "]] " << uut[_depColumns[j]] << endl;
    //cout << "predicted[" << j << "] " << predicted[j] << endl;
    double diff = uut[_depColumns[j]] - (predicted[j] / wSum);
    result += diff * diff;
  }
  result = sqrt(result);

  //cout << "wSum: " << wSum << " result: " << result << endl;

  return result;
}
Esempio n. 7
0
const vector<double>& IdwInterpolator::_interpolate(const vector<double>& point, int ignoreId) const
{
  const DataFrame& df = *_df;

  _result.resize(_depColumns.size());
  for (size_t i = 0; i < _result.size(); i++)
  {
    _result[i] = 0.0;
  }

  vector<double> simplePoint(_indColumns.size());
  for (size_t i = 0; i < _indColumns.size(); i++)
  {
    simplePoint[i] = point[_indColumns[i]];
  }

  KnnIteratorNd it(_getIndex(), simplePoint);
  double wSum = 0.0;
  int samples = 0;
  int iterations = 0;
  while (it.next() && samples < 50 && iterations <= _maxAllowedPerLoopOptimizationIterations)
  {
    size_t i = it.getId();
    if ((int)i == ignoreId)
    {
      continue;
    }
    const vector<double>& record = df.getDataVector(i);

    // figure out the distance between point and this data vector
    double d = 0;
    for (size_t j = 0; j < _indColumns.size(); j++)
    {
      double v = point[_indColumns[j]] - record[_indColumns[j]];
      d += v * v;
    }
    d = sqrt(d);
    // if the distance is zero then the weight is infinite and we don't need to look any further.
    if (d == 0)
    {
      wSum = 1.0;

      // Set the contribution equal to this value.
      for (size_t j = 0; j < _result.size(); j++)
      {
        _result[j] += record[_depColumns[j]];
      }
      break;
    }

    // calculate the weight of this sample.
    double w = _calculateWeight(d);
    wSum += w;

    // calculate the contribution to the predicted value.
    for (size_t j = 0; j < _result.size(); j++)
    {
      _result[j] += (record[_depColumns[j]] * w);
    }

    iterations++;
  }
  if (iterations > _iterations)
  {
    _iterations = iterations;
  }

  for (size_t j = 0; j < _result.size(); j++)
  {
    _result[j] /= wSum;
  }

  return _result;
}
Esempio n. 8
0
int DoChar(int sx, int sy, int c){

    if(font==NULL){
	font=&Font_7x8;
    };

	/* how many bytes is it high? */
    char height=(font->u8Height-1)/8+1;
    char hoff=(8-(font->u8Height%8))%8;


	const uint8_t * data;
    int width,preblank=0,postblank=0;
    do { /* Get Character data */
        /* Get intex into character list */
        c=_getIndex(c);

        /* starting offset into character source data */
        int toff=0;

        if(font->u8Width==0){
            if(efont.type == FONT_EXTERNAL){
                _getFontData(SEEK_WIDTH,0);
                for(int y=0;y<c;y++)
                    toff+=_getFontData(GET_WIDTH,0);
                width=_getFontData(GET_WIDTH,0);

                _getFontData(SEEK_DATA,toff);
                UINT res;
                UINT readbytes;
                UINT size = width * height;
                if(size > MAXCHR) size = MAXCHR;
                res = f_read(&file, charBuf, size, &readbytes);
                if(res != FR_OK || readbytes<width*height)
                    return sx;
                data=charBuf;
            }else{
                for(int y=0;y<c;y++)
                    toff+=font->charInfo[y].widthBits;
                width=font->charInfo[c].widthBits;

                toff*=height;
                data=&font->au8FontTable[toff];
            };
            postblank=1;
        }else if(font->u8Width==1){ // NEW CODE
            if(efont.type == FONT_EXTERNAL){
                _getFontData(SEEK_WIDTH,0);
                for(int y=0;y<c;y++)
                    toff+=_getFontData(GET_WIDTH,0);
                width=_getFontData(GET_WIDTH,0);
                _getFontData(SEEK_DATA,toff);
                UINT res;
                UINT readbytes;
                uint8_t testbyte;
                testbyte = read_byte ();
                if(testbyte>>4 ==15){
                    preblank = read_byte ();
                    postblank = read_byte ();
                    width-=3;
                    width/=height;
                    UINT size = width * height;
                    if(size > MAXCHR) size = MAXCHR;
                    res = f_read(&file, charBuf, size, &readbytes);
                    if(res != FR_OK || readbytes<width*height)
                        return sx;
                    data=charBuf;
                }else{
                    _getFontData(SEEK_DATA,toff);
                    data=pk_decode(NULL,&width); // Hackety-hack
                };
            }else{
                // Find offset and length for our character
                for(int y=0;y<c;y++)
                    toff+=font->charInfo[y].widthBits;
                width=font->charInfo[c].widthBits;
                if(font->au8FontTable[toff]>>4 == 15){ // It's a raw character!
                    preblank = font->au8FontTable[toff+1];
                    postblank= font->au8FontTable[toff+2];
                    data=&font->au8FontTable[toff+3];
                    width=(width-3/height);
                }else{
                    data=pk_decode(&font->au8FontTable[toff],&width);
                }
            };
Esempio n. 9
0
void TabTerminal::_handleLeft(QKeyEvent *event) {
	QString plainTextUserPrompt = _htmlToPlainText(_userPrompt);
	if(_getIndex(textCursor()) > plainTextUserPrompt.length()) {
		QTextEdit::keyPressEvent(event);
	}
}