[R] boundary check

Robin Hankin rksh1 at cam.ac.uk
Fri Sep 24 15:14:22 CEST 2010


Feng

thanks for this.  The problem you report is
reproducible; it originates from simplex()
of the boot packge.

It is ultimately due to
the fact that x_i is precisely *on* the convex hull,
which is evidently causing problems.  I'll
investigate it.

In the short term, you can break the degeneracy:

> isin.chull(X[1,]+1e-10,X)
[1] FALSE
>

but I don't know if that is acceptable to you.

best

rksh



On 24/09/10 13:17, Feng Li wrote:
> Thanks. I agree with you that the speed and memory issues might be
> (actually is) a big problem for big dimensions. It is interesting to
> know to solve this by using linear programming. Buy the way, it seems
> a potential bug in your function if you try this
>
>
>   
>> X <- matrix(rnorm(50), 10, 5)
>> x_i<-X[1,,drop=FALSE]
>> isin.chull(x_i,X)
>>     
> Error in A.out[, basic] <- iden(M) : subscript out of bounds
>
> Or I must be wrong somewhere.
>
>
> Feng
>
>
> On Sep 24, 12:39 pm, Robin Hankin <rk... at cam.ac.uk> wrote:
>   
>> Hello
>>
>> convex hulls in large numbers of dimensions are hard.
>>
>> For your problem, though, one can tell whether a given
>> point is inside or outside by using linear programming:
>>
>>     
>>> X <- matrix(rnorm(50), 10, 5)
>>> x_i <- matrix(rnorm(5), 1, 5)
>>> isin.chull
>>>       
>> function(candidate,p,plot=FALSE,give.answers=FALSE,
>>   ...){
>>   if(plot){
>>     plot(p,...)
>>     p(candidate[1],candidate[2], pch=16)
>>   }
>>   n <- nrow(p) # number of points
>>   d <- ncol(p) # number of dimensions
>>
>>   p <- t(sweep(p,2,candidate))
>>   jj <- simplex(a=rep(1,n),A3=rbind(p,1),b3=c(0*candidate,1))
>>   if(give.answers){
>>     return(jj)
>>   }  else {
>>     return((jj$solved >= 0) & all(jj$soln<1))
>>   }
>>
>> }
>>     
>>> isin.chull(x_i,X)
>>>       
>> [1] FALSE
>>
>> (we can discuss offline; I'll summarize)
>>
>> HTH
>>
>> rksh
>>
>> On 24/09/10 10:44, Feng Li wrote:
>>
>>
>>
>>     
>>> Dear R,
>>>       
>>     
>>> I have a covariates matrix with 10 observations,  e.g.
>>>       
>>     
>>>> X <- matrix(rnorm(50), 10, 5)
>>>> X
>>>>         
>>     
>>>              [,1]        [,2]        [,3]        [,4]       [,5]
>>>  [1,]  0.24857135  0.30880745 -1.44118657  1.10229027  1.0526010
>>>  [2,]  1.24316806  0.36275370 -0.40096866 -0.24387888 -1.5324384
>>>  [3,] -0.33504014  0.42996246  0.03902479 -0.84778875 -2.4754644
>>>  [4,]  0.06710229  1.01950917 -0.09325091 -0.03222811  0.4127816
>>>  [5,] -0.13619141  1.33143821 -0.79958805  2.08274102  0.6901768
>>>  [6,] -0.45060357  0.19348831 -1.23793647 -0.72440163  0.5057326
>>>  [7,] -1.20740516  0.20231086  1.15584485  0.81777770 -1.2719855
>>>  [8,] -1.81166284 -0.07913113 -0.91080581 -0.34774436  0.9552182
>>>  [9,]  0.19131383  0.14980569 -0.37458224 -0.09371273 -1.7667203
>>> [10,] -0.85159276 -0.66679528  1.63019340  0.56920196 -2.4049600
>>>       
>>     
>>> And I define a boundary of X:  The smallest "ball" that nests all the
>>> observations of X. I wish to check if a particular point x_i
>>>       
>>     
>>>> x_i <- matrix(rnorm(5), 1, 5)
>>>> x_i
>>>>         
>>     
>>>            [,1]      [,2]       [,3]      [,4]      [,5]
>>> [1,] -0.1525543 0.4606419 -0.1011011 -1.557225 -1.035694
>>>       
>>     
>>> is inside the boundary of X or not. I know it's easy to do it with 1-D or
>>> 2-D, but I don't knot how to manage it when the dimension is large.
>>>       
>>     
>>> Can someone give a hint? Thanks in advance!
>>>       
>>     
>>> Feng
>>>       
>> --
>> Robin K. S. Hankin
>> Uncertainty Analyst
>> University of Cambridge
>> 19 Silver Street
>> Cambridge CB3 9EP
>> 01223-764877
>>
>> ______________________________________________
>> R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>     


-- 
Robin K. S. Hankin
Uncertainty Analyst
University of Cambridge
19 Silver Street
Cambridge CB3 9EP
01223-764877



More information about the R-help mailing list