亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? balltreedensityclass.cc

?? 核密度估計(kde)的工具箱,我是在做背景建模的時候遇到這方面問題找到的,希望對大家有點用處.
?? CC
?? 第 1 頁 / 共 2 頁
字號:
//////////////////////////////////////////////////////////////////////////////////////
// KD-tree code extended for use in kernel density estimation
//////////////////////////////////////////////////////////////////////////////////////
//
// Written by Alex Ihler and Mike Mandel
// Copyright (C) 2003 Alexander Ihler; distributable under GPL -- see README.txt
//
//////////////////////////////////////////////////////////////////////////////////////
#define MEX
//#define NEWVERSION
#include <math.h>
#include <assert.h>
#include "mex.h"
#include "BallTreeDensity.h"

double *pMin, *pMax;                // need to declare these here, for kernel 
double **pAdd, *pErr;
double *min, *max;                  //   derivative functions in kernel.h

#include "kernels.h"                // min&max kernel bounds for various kernels

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// EVALUATION
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

void pushDownLocal(const BallTree& atTree, const BallTree::index aRoot)
{
  BallTree::index close;
    if (!atTree.isLeaf(aRoot)) {
      close = atTree.left(aRoot); 
      if (close != BallTree::NO_CHILD) pAdd[0][close] += pAdd[0][aRoot];
      close = atTree.right(aRoot); 
      if (close != BallTree::NO_CHILD) pAdd[0][close] += pAdd[0][aRoot];
      pAdd[0][aRoot] = 0;
    }
}
void pushDownAll(const BallTree& locations)
{
  BallTree::index j;
  for (j=locations.root(); j<locations.leafFirst(locations.root())-1; j++) {
      pAdd[0][locations.left(j)] += pAdd[0][j];
      pAdd[0][locations.right(j)] += pAdd[0][j];
      pAdd[0][j] = 0;
    }
    for (j=locations.leafFirst(locations.root()); j<=locations.leafLast(locations.root()); j++) {
      pMin[j] += pAdd[0][j] - pErr[j];
      pMax[j] += pAdd[0][j] + pErr[j];
      pAdd[0][j] = 0; pErr[j] = 0; 
    }
}
void recurseMinMax(const BallTree& atTree, const BallTree::index aRoot)
{
  BallTree::index l,r; l = atTree.left(aRoot); r = atTree.right(aRoot);
  if (!atTree.isLeaf(l)) recurseMinMax(atTree,l);
  if (!atTree.isLeaf(r)) recurseMinMax(atTree,r);
  pMin[aRoot] = pMin[l]; pMax[aRoot] = pMax[l];
  if (pMin[aRoot] > pMin[r]) pMin[aRoot] = pMin[r];
  if (pMax[aRoot] < pMax[r]) pMax[aRoot] = pMax[r];
}
/////////////////////////////////////////////////////////////////////
// Recursively evaluate the density implied by the samples of the 
// subtree (rooted at dRoot) of densTree at the locations given by
// the subtree (rooted at aRoot) of *this, to within the error 
// percentage "maxErr"
/////////////////////////////////////////////////////////////////////

void BallTreeDensity::evaluate(BallTree::index dRoot,
              const BallTree& atTree, BallTree::index aRoot, 
              double maxErr) const
{
  unsigned int k, close, far;
  double Kmin,Kmax,add,total;

  // find the minimum and maximum effect of these two balls on each other
  Kmax = minDistKer(dRoot, atTree, aRoot);
  Kmin = maxDistKer(dRoot, atTree, aRoot);

  total = pMin[ aRoot ];		   	     // take pmin of data below this level
#ifdef NEWVERSION
  total += pAdd[0][aRoot] - pErr[aRoot]; // add lower bound from local expansion
#endif
  total += weight(dRoot)*Kmin;           // also add minimum for this block

  // if the weighted contribution of this multiply is below the
  //    threshold, no need to recurse; just treat as constant
  //// //if ( Kmax - Kmin <= maxErr) {                    // APPROXIMATE: ABSOLUTE
  if ( Kmax - Kmin <= maxErr * total) {                    // APPROXIMATE: PERCENT
    Kmin *= weight(dRoot); Kmax *= weight(dRoot);

    if (this == &atTree && aRoot==dRoot) {                 // LEAVE-ONE-OUT (and same subtree)
      for (k=atTree.leafFirst(aRoot); k<=atTree.leafLast(aRoot); k++){
        pMin[k] += Kmin * (1 - weight(k)/weight(dRoot));   // leave our weight out of it
        pMax[k] += Kmax * (1 - weight(k)/weight(dRoot));   // 
      }
      recurseMinMax(atTree,aRoot);
    } else {                                               //     NO L-O-O => just add away
#ifdef NEWVERSION
      pAdd[0][aRoot] += (Kmin + Kmax)/2; pErr[aRoot] = (Kmax-Kmin)/2;
#else
      // !!! Should *not* do this -- instead add to local expansion (constant term)
      for (k=atTree.leafFirst(aRoot); k<=atTree.leafLast(aRoot); k++) {
        pMin[k] += Kmin;
        pMax[k] += Kmax;
      }
#endif
      if (!atTree.isLeaf(aRoot)) { pMin[aRoot] += Kmin; pMax[aRoot] += Kmax; }
    }

  } else if (Npts(dRoot)*atTree.Npts(aRoot)<=DirectSize){  // DIRECT EVALUATION
    evalDirect(dRoot,atTree,aRoot);
  } else if (0) {                                          // FAST GAUSS APPROX
    // if FGTTerms > 0 : have computed Hermite expansions of densTree (sigma uniform)
    // if FGTError(dRoot->Nterms,minDistDtoA,sigma) < maxError * total
    //  (if maxError, sigma, Nterms known, compute R0 & check >= minDist)
    //   translate dRoot's hermite expansion to a local expansion around aRoot
    //   Need to iterate over aRoot's leaves & evaluate?  (N log N)
    //   Update pMin structure...
  } else {                                                 // RECURSE ON SUBTREES

#ifdef NEWVERSION
    // push any local expansion
    pushDownLocal(atTree,aRoot);
#endif

    // Find the subtree in closest to the other tree's left child and do 
    // that first so that the values are higher and there is a better
    // chance of being able to skip a recursion.
    close = atTree.closer( atTree.left(aRoot), atTree.right(aRoot), *this, left(dRoot)); 
    if (left(dRoot) != NO_CHILD && close != NO_CHILD)
      evaluate(left(dRoot), atTree, close, maxErr); 
    far   = (close == atTree.left(aRoot)) ? atTree.right(aRoot) : atTree.left(aRoot);
    if (left(dRoot) != NO_CHILD && far != NO_CHILD)
      evaluate(left(dRoot), atTree, far, maxErr); 

    // Now the same thing for the density's right child    
    close = atTree.closer( atTree.left(aRoot), atTree.right(aRoot), *this, right(dRoot)); 
    if (right(dRoot) != NO_CHILD && close != NO_CHILD) 
      evaluate(right(dRoot), atTree, close, maxErr); 
    far   = (close == atTree.left(aRoot)) ? atTree.right(aRoot) : atTree.left(aRoot);
    if (right(dRoot) != NO_CHILD && far != NO_CHILD) 
      evaluate(right(dRoot), atTree, far, maxErr); 

    // Propogate additions in children's minimum value to this node
    if (!atTree.isLeaf(aRoot)) {
      pMin[aRoot] = pMin[ atTree.left(aRoot) ]; 
      pMax[aRoot] = pMax[ atTree.left(aRoot) ];
      if (atTree.right(aRoot) != NO_CHILD) {
        if (pMin[aRoot] > pMin[ atTree.right(aRoot) ])
          pMin[aRoot] = pMin[ atTree.right(aRoot) ];
        if (pMax[aRoot] < pMax[ atTree.right(aRoot) ])
          pMax[aRoot] = pMax[ atTree.right(aRoot) ];
      }
    }

  }
}

///////////////////////////////////////////
// Maybe we just want to evaluate this stuff directly.
///////////////////////////////////////////
void BallTreeDensity::evalDirect(BallTree::index dRoot, const BallTree& atTree, BallTree::index aRoot) const
{
  BallTree::index i,j;
  bool firstFlag = true;
  double minVal=2e22, maxVal=0;

  for (j=atTree.leafFirst(aRoot); j<=atTree.leafLast(aRoot); j++) {
    for (i=leafFirst(dRoot); i<=leafLast(dRoot); i++) {
      if (this != &atTree || i!=j) {               // Check leave-one-out condition;
        double d = weight(i) * maxDistKer(i,atTree,j);  //  Do direct N^2 kernel evaluation
        //if (this == &atTree) d /= 1-weight(j);     // leave-one-out => renormalize weights
        pMin[j] += d;
        pMax[j] += d;
      }
    }
#ifdef NEWVERSION
  }
  recurseMinMax(atTree,aRoot);              // pass up min (& max) value for pruning
#else
  if (pMin[j] < minVal) minVal = pMin[j];   // determine min & max value in this block
  if (pMax[j] > maxVal) maxVal = pMax[j];   
  }
  pMin[aRoot] = minVal; pMax[aRoot] = maxVal;
#endif
}

/////////////////////////////////////////////////////////////////////
// Dual Tree evaluation: estimate the values at this ball tree's
// points given the other tree as the samples from a distribution.
/////////////////////////////////////////////////////////////////////
void BallTreeDensity::evaluate(const BallTree& locations, double* p, double maxErr) const
{
  BallTree::index j;
  
  assert(Ndim() == locations.Ndim());
  assert(p != NULL);

  pMin = new double[2*locations.Npts()];
  pMax = new double[2*locations.Npts()];
  for (j=0;j<2*locations.Npts();j++) pMin[j] = pMax[j] = 0;
#ifdef NEWVERSION
  pAdd = new double*[1]; pAdd[0] = new double[2*locations.Npts()];
  pErr = new double[2*locations.Npts()];
  for (j=0;j<2*locations.Npts();j++) pAdd[0][j] = pErr[j] = 0;
#endif
  
  evaluate(root(), locations, locations.root(), 2*maxErr);

  // Compute & account for the kernel f'ns normalization constant
  double norm = 1;
  switch(getType()) {
    case Gaussian:  norm = pow(2*PI, ((double)Ndim())/2 );
                    if (bwUniform()) 
                      for (unsigned int i=0;i<Ndim();i++) norm *= sqrt(bandwidthMax[i]);
                    break;
    case Laplacian: norm = pow(2, ((double)Ndim()) );
                    if (bwUniform()) 
                      for (unsigned int i=0;i<Ndim();i++) norm *= bandwidthMax[i];
                    break;
    case Epanetchnikov: norm = pow(4.0/3, ((double)Ndim()) );
                    if (bwUniform()) 
                      for (unsigned int i=0;i<Ndim();i++) norm *= bandwidthMax[i];
                    break;
  }

  BallTree::index lRoot = locations.root();
#ifdef NEWVERSION
  pushDownAll(locations);
#endif
  if (this == &locations) {                          // if we need to do leave-one-out
    for (j=locations.leafFirst(lRoot); j<=locations.leafLast(lRoot); j++)
      p[locations.getIndexOf(j)] = .5*(pMin[j]+pMax[j])/norm/(1-weight(j));
  } else {
    for (j=locations.leafFirst(lRoot); j<=locations.leafLast(lRoot); j++)
      p[locations.getIndexOf(j)] = .5*(pMin[j]+pMax[j])/norm;
  }

  delete[] pMin; delete[] pMax; 
#ifdef NEWVERSION
  delete[] pAdd[0]; delete[] pAdd;
#endif
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// GRADIENT CALCULATION
//
//    Recursively evaluate the derivative of log-likelihood for two trees
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
double *gradD, *gradA;

////////////////////////////////////////////////////////////////////////////////////
// DIRECT VERSION:
//   Just iterate over the N^2 indices; faster than recursion for small N.
////////////////////////////////////////////////////////////////////////////////////
void BallTreeDensity::llGradDirect(BallTree::index dRoot, const BallTree& atTree, BallTree::index aRoot, Gradient gradWRT) const
{
  BallTree::index i,j;
  unsigned int k;

  for (i=atTree.leafFirst(aRoot);i<=atTree.leafLast(aRoot);i++) {
    for (j=leafFirst(dRoot);j<=leafLast(dRoot);j++) {
      if (this != &atTree || i!=j) {               // Check leave-one-out condition;
        unsigned long Nj = Ndim() * getIndexOf(j);
        unsigned long Ni = atTree.Ndim() * atTree.getIndexOf(i);
        dKdX_p(j,atTree,i,true,gradWRT);            // use "true" to signal leaf evaluation
        if (gradD) for (k=0;k<Ndim();k++) {
          gradD[Nj+k] -= weight(j) * atTree.weight(i) * (max[k]+min[k])/2;
        }
        if (gradA) for (k=0;k<Ndim();k++) {
          gradA[Ni+k] += weight(j) * atTree.weight(i) * (max[k]+min[k])/2;
        }
  } } }
}

////////////////////////////////////////////////////////////////////////////////////
// RECURSIVE VERSION:
//   Try to find approximations to speed things up.
////////////////////////////////////////////////////////////////////////////////////
void BallTreeDensity::llGradRecurse(BallTree::index dRoot,const BallTree& atTree, BallTree::index aRoot, double tolGrad, Gradient gradWRT) const
{
  BallTree::index i,j,close,far;
  unsigned int k; 

  dKdX_p(dRoot,atTree,aRoot,false,gradWRT);      // "false" signals maybe not leaf nodes
  double norm = 0;
  for (k=0;k<Ndim();k++) norm += .25*(max[k]-min[k])*(max[k]-min[k]);

  if (norm <= tolGrad) {     // IF OUR APPROXIMATION IS GOOD ENOUGH, ...
    if (this == &atTree && aRoot==dRoot) {                 // LEAVE-ONE-OUT (and same subtree)
      if (gradD) for (j=leafFirst(dRoot);j<=leafLast(dRoot);j++) {
        unsigned long Nj = Ndim() * getIndexOf(j);
        for (k=0;k<Ndim();k++)
          gradD[Nj+k] -= (atTree.weight(aRoot)-atTree.weight(j)) * weight(j) * (max[k]+min[k])/2;
      }
      if (gradA) for (i=atTree.leafFirst(aRoot);i<=atTree.leafLast(aRoot);i++) {
        unsigned long Ni = atTree.Ndim() * atTree.getIndexOf(i);
        for (k=0;k<Ndim();k++)
          gradA[Ni+k] += atTree.weight(i) * (weight(dRoot)-weight(i)) * (max[k]+min[k])/2;
      }
    } else {                                              // NO LOO; just regular
      if (gradD) for (j=leafFirst(dRoot);j<=leafLast(dRoot);j++) {
        unsigned long Nj = Ndim() * getIndexOf(j);
        for (k=0;k<Ndim();k++)
          gradD[Nj+k] -= atTree.weight(aRoot) * weight(j) * (max[k]+min[k])/2;
      }
      if (gradA) for (i=atTree.leafFirst(aRoot);i<=atTree.leafLast(aRoot);i++) {
        unsigned long Ni = atTree.Ndim() * atTree.getIndexOf(i);
        for (k=0;k<Ndim();k++)
          gradA[Ni+k] += atTree.weight(i) * weight(dRoot) * (max[k]+min[k])/2;
      }
    } 
                          // OR, IF THERE ARE VERY FEW POINTS

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久精品国产亚洲一区二区三区| 国产日本欧洲亚洲| 日韩欧美国产小视频| 国产精品久久久久毛片软件| 久久9热精品视频| 欧美日韩成人综合在线一区二区| 欧美另类一区二区三区| 大桥未久av一区二区三区中文| 亚洲图片自拍偷拍| 久久亚洲影视婷婷| 欧美日韩国产系列| 97se亚洲国产综合自在线不卡| 麻豆91免费观看| 一区二区三区不卡视频| 久久色在线观看| 欧美色网一区二区| 91网址在线看| 国产成人av福利| 蜜桃av一区二区| 图片区日韩欧美亚洲| |精品福利一区二区三区| 亚洲精品一区二区三区精华液| 欧美性大战久久久久久久| 成人sese在线| 国产乱子轮精品视频| 日本大胆欧美人术艺术动态| 亚洲男帅同性gay1069| 国产日韩欧美在线一区| 精品久久久久久综合日本欧美| av午夜一区麻豆| 丰满白嫩尤物一区二区| 国产精品1区2区3区| 激情综合网最新| 美女视频黄免费的久久 | 国产女人aaa级久久久级| 欧美精品视频www在线观看| 97国产一区二区| 成人精品一区二区三区四区| 激情综合色播五月| 美女免费视频一区二区| 热久久一区二区| 青青草97国产精品免费观看 | 久久男人中文字幕资源站| 日韩午夜小视频| 欧美一区二区二区| 欧美一二三区在线| 欧美精品乱人伦久久久久久| 欧美日韩另类一区| 欧美午夜片在线观看| 欧美久久久久久久久中文字幕| 精品视频1区2区| 欧美精品aⅴ在线视频| 欧美亚日韩国产aⅴ精品中极品| 色拍拍在线精品视频8848| 99在线精品一区二区三区| 99精品久久99久久久久| 色综合久久久久| 欧美性极品少妇| 日韩一区二区三区三四区视频在线观看 | 日韩在线卡一卡二| 舔着乳尖日韩一区| 韩国欧美一区二区| 国产91在线|亚洲| 日本伦理一区二区| 51久久夜色精品国产麻豆| 国产欧美日韩精品a在线观看| 中文字幕欧美日韩一区| 亚洲另类在线视频| 日日噜噜夜夜狠狠视频欧美人| 蜜桃免费网站一区二区三区| 国产一区美女在线| 91视频免费播放| 欧美精品18+| 久久亚洲精华国产精华液| 国产精品久久久久久久第一福利| 亚洲精品乱码久久久久久久久 | 亚洲免费在线视频| 午夜影视日本亚洲欧洲精品| 另类欧美日韩国产在线| 岛国一区二区在线观看| 欧美亚洲国产bt| 日韩女优av电影| 综合色天天鬼久久鬼色| 日韩精品视频网| 国产成人免费视频精品含羞草妖精| 91尤物视频在线观看| 日韩美女一区二区三区四区| 亚洲欧洲国产专区| 日韩国产一区二| 99久久久免费精品国产一区二区| 69久久99精品久久久久婷婷| 国产午夜精品理论片a级大结局| 亚洲自拍偷拍网站| 国产成人综合在线观看| 欧美中文字幕一区二区三区亚洲| 精品va天堂亚洲国产| 夜夜爽夜夜爽精品视频| 国产麻豆日韩欧美久久| 欧美精品一级二级| 国产精品久久99| 精品午夜一区二区三区在线观看| 色综合久久99| 国产精品天美传媒沈樵| 男女性色大片免费观看一区二区| av男人天堂一区| 精品国产伦理网| 午夜久久久久久电影| 亚洲免费av观看| 欧美精品一区二区三区在线| 亚洲天堂免费在线观看视频| 极品少妇xxxx偷拍精品少妇| 欧美肥妇bbw| 有码一区二区三区| 波多野洁衣一区| 亚洲精品一区二区三区四区高清| 五月天亚洲精品| 欧美在线短视频| 中文字幕在线播放不卡一区| 国产一区福利在线| 欧美白人最猛性xxxxx69交| 亚洲第一综合色| 国产精品婷婷午夜在线观看| 国产一区在线精品| 欧美一级一区二区| 亚洲va韩国va欧美va精品 | 欧美日韩精品欧美日韩精品一| 国产精品久久综合| 国产经典欧美精品| 亚洲精品在线免费播放| 麻豆成人免费电影| 欧美一区二区精品在线| 日韩精品一级二级| 欧美美女网站色| 亚洲福利一区二区| 欧美高清视频不卡网| 亚洲va天堂va国产va久| 欧美日韩日日骚| 亚洲国产婷婷综合在线精品| 欧美在线三级电影| 亚洲国产视频一区二区| 欧美日韩亚洲综合| 丝袜脚交一区二区| 91麻豆精品国产| 美女任你摸久久| 精品成人一区二区三区四区| 久久激情综合网| 精品精品国产高清一毛片一天堂| 久久99久久99精品免视看婷婷 | 亚洲免费色视频| 日本道精品一区二区三区| 一区二区成人在线视频| 欧美吞精做爰啪啪高潮| 五月婷婷激情综合| 欧美成人艳星乳罩| 国产精品综合二区| 亚洲欧洲日韩av| 在线观看av一区二区| 水蜜桃久久夜色精品一区的特点| 欧美一区二区人人喊爽| 久久97超碰国产精品超碰| 日本一区二区免费在线| 99re成人在线| 亚洲成人第一页| 26uuu国产电影一区二区| 国产成人av一区二区三区在线观看| 国产人伦精品一区二区| 91极品美女在线| 亚洲风情在线资源站| 自拍偷在线精品自拍偷无码专区| 精品亚洲成av人在线观看| 免费在线观看一区二区三区| 亚洲电影视频在线| 亚洲国产精品精华液网站| 亚洲视频免费观看| 亚洲美女视频在线| 欧美亚洲综合一区| 亚洲国产精品嫩草影院| eeuss国产一区二区三区| 久久久久成人黄色影片| 色老汉av一区二区三区| 久久精品国产精品亚洲综合| 亚洲视频网在线直播| 欧美大片拔萝卜| 91香蕉视频污在线| 麻豆成人久久精品二区三区红| 国产精品视频一二| 欧美二区在线观看| 成人性色生活片| 日本欧美肥老太交大片| 国产精品久久久久久久久搜平片| 91麻豆精品国产91久久久久久 | 成人午夜精品在线| 五月天久久比比资源色| 中文字幕巨乱亚洲| 91精品国产91久久综合桃花| 波多野结衣欧美| 国产在线视频一区二区三区| 一区二区三区欧美视频| 久久久不卡网国产精品二区| 欧美亚洲高清一区二区三区不卡|