無限大の半径を持つ空間を単位正単体に縮める

  • 予定パッケージ名
    • SphereAndSimplex
  • 関数名
    • Sphere2Simplex
  • タイトル
Sphere2Simplex
  • 説明
無限大の半径を持つ空間を単位正単体に縮める
  • 使用例
Sphere2Simplex(c(1,2,3))
  • ソース
# n+1個の値のうち、一番小さい値とそのベクトルIDを出す
minind<-function(x){
	which(x==min(x))[1]
}
minindval<-function(x){
	list(ind=minind(x),v=min(x))
}

Sphere2Simplex<-function(x){
	if(!is.matrix(x)){
		x<-matrix(x,nr=1)
	}
	n<-length(x[1,])
	# n単体のn+1 個の頂点座標
	cv<-CategoryVector(n+1)
	# n+1個の頂点ベクトルへの射影の長さ
	X<-x%*%t(cv)
	# ベクトルxがどの頂点ベクトルに対してその射影を最短とするかを調べる
	# その頂点ベクトル以外の頂点が作る「n-1次元面」をxベクトルは通過する
	MinIndVal<-matrix(unlist(apply(X,1,minindval)),ncol=2,byrow=TRUE)
	# xのノルム
	r<-sqrt(apply(x^2,1,sum))
	# 無限遠を1/nに縮めるときにノルムrの点はどのくらいのノルムに縮めるか
	tmpr<-TangentDist(r,1)
	# 最長の縮み位置に対するtmprの比率
	tmpRatio<-tmpr/(1/(n))
	# 1乗から2乗の間の何乗にするか
	tmpk<-1+tmpRatio
	# 最終的に何倍に縮めるか
	ratio<-(tmpr^2/apply(abs(x)^tmpk,1,sum))^(1/tmpk)
	x*ratio
}
  • Rdファイル
\name{Sphere2Simplex}
\alias{Sphere2Simplex}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
Sphere2Simplex
}
\description{
Spherical space is transformed to a unit simplex
無限球座標を単位正単体に縮める
}
\usage{
Sphere2Simplex(c(1,2,3))
}
%- maybe also 'usage' for other objects documented here.
\details{
%%  ~~ If necessary, more details than the description above ~~
}
\value{
transformed coordinate
}
\references{
%% ~put references to the literature/web site here ~
}
\author{
%%  ~~who you are~~
}
\note{
%%  ~~further notes~~
}

%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
CategoryVector,TangentDist
}
\examples{

xs<-matrix(0,100,3)
xs[1,]<-c(0,0,1)
for(i in 2:100){
	xs[i,]<-xs[i-1,]*1.1
}
xsc<-Sphere2Simplex(xs)

plot(xsc[,1])
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ ~kwd1 }
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line