1

sparclWitten と Tibshirani が論文に基づいて作成したパッケージを使用しています。

Witten DM and R Tibshirani (2010) クラスタリングにおける特徴選択のフレームワーク。アメリカ統計学会誌 105(490): 713-726

関数の下の例を調べますHierarchicalSparseCluster

# Generate 2-class data
set.seed(1)
x <- matrix(rnorm(100*50),ncol=50)
y <- c(rep(1,50),rep(2,50))
x[y==1,1:25] <- x[y==1,1:25]+2

# Do tuning parameter selection for sparse hierarchical clustering
perm.out <- HierarchicalSparseCluster.permute(x, wbounds=c(1.5,2:6),nperms=5)

# Perform sparse hierarchical clustering
sparsehc <- HierarchicalSparseCluster(dists=perm.out$dists, wbound=perm.out$bestw, method="complete")

ここで確認するdim(sparsehc$dists)と、4950 と 50 が返されます。シミュレーションの設定から、 と がわかりましn=100p=50。また、マニュアルによると、戻り値distsはdata matrixの(n*n)xpx非類似度マトリックスです。4950 ではなく 100*100=10000 であるべきであるため、明らかに行の次元は n*n ではありません。どうもありがとうございました!

4

1 に答える 1

3

ヘルプ ページの間違いのsparclようです: 非類似度行列の次元distn2xpで、ここでn2=n*(n-1)/2. n実際、距離のx行列は必要ありませんがn、主対角線上のこの行列の一部のみが必要です。

sparcl私が上で言ったことのサポートのソース:

distfun.R

distfun=function(x){
#if(!is.loaded("distfun")){
#  dyn.load("distfun.so")
#}
n<-nrow(x)
p <- ncol(x)
x[is.na(x)]=0
mode(x)="single"
n2=n*(n-1)/2
junk=.Fortran("distfun",
         x,
        as.integer(n),
       as.integer(p),
       as.integer(n2),
       d=single(n2*p), PACKAGE="sparcl"
)
return(junk$d)
}

ここで、 がどのようn2に計算され、Fortran 関数に渡されるかを確認できます。

distfun.f

C Output from Public domain Ratfor, version 1.0
      subroutine distfun(x,n,p,n2,d)
      implicit double precision (a-h,o-z)
      integer n,p,n2
      real x(n,p),d(n2,p)
      ii=0
      do23000 i=1,n-1
      do23002 ip=i+1,n
      ii=ii+1
      do23004 j=1,p
      d(ii,j)=abs(x(i,j)-x(ip,j))
23004 continue
23005 continue
23002 continue
23003 continue
23000 continue
23001 continue
      return
      end

ここでdistは、行列の各特徴に対してn2、オブジェクト間のペアごとの距離のシーケンスを保持するサイズの列が構築されています。たとえば、 の場合n=4p=2最終n2=4*3/2=6的な行列は次のようになります6x2

    |    1     |     2    |
---------------------------
  1 | d(1,2)_1 | d(1,2)_2 |
  2 | d(1,3)_1 | d(1,3)_2 |
  3 | d(1,4)_1 | d(1,4)_2 |
  4 | d(2,3)_1 | d(2,3)_2 |
  5 | d(2,4)_1 | d(2,4)_2 |
  6 | d(3,4)_1 | d(3,4)_2 |

ここで、d(2,4)_1は、1 番目のフィーチャの 2 番目と 4 番目のオブジェクト間の距離です。

于 2013-01-21T12:57:50.357 に答える