Latin Hypercube Sampling with a condition

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Latin Hypercube Sampling with a condition

dviana
Hello all,

I am trying to do a Latin Hypercube Sampling (LHS) to a 5-parameter
design matrix. I start as follows:

library(lhs)

p1<-randomLHS(1000, 5)

If I check the distribution of each parameter (column), they are
perfectly uniformly distributed (as expected).For example,

hist(p1[,1])

Now the hard (maybe strange) question. I want the combination of the
first three parameters to sum up to 1 (which obviously do not)

s<-p1[,1]+p1[,2]+p1[,3]

s==1

It occurred to me to divide each of these parameters with the sum
(vector "s" above). However the uniform distribution is lost (example
for parameter 1 - first column):

par1.transf<-p1[,1]/s

hist(par1.transf)


So, is there a way to maintain the random LHS (with uniformly
distributed parameters) so that the refered condition is fulfilled?

Any suggestions would be much welcome.

Thanks,

Duarte

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Latin Hypercube Sampling with a condition

carnellr
Duarte Viana <viana.sptd <at> gmail.com> writes:

>
> Hello all,
>
> I am trying to do a Latin Hypercube Sampling (LHS) to a 5-parameter
> design matrix. I start as follows:
>
> library(lhs)
>
> p1<-randomLHS(1000, 5)
>
> If I check the distribution of each parameter (column), they are
> perfectly uniformly distributed (as expected).For example,
>
> hist(p1[,1])
>
> Now the hard (maybe strange) question. I want the combination of the
> first three parameters to sum up to 1 (which obviously do not)
>
> s<-p1[,1]+p1[,2]+p1[,3]
>
> s==1
>
> It occurred to me to divide each of these parameters with the sum
> (vector "s" above). However the uniform distribution is lost (example
> for parameter 1 - first column):
>
> par1.transf<-p1[,1]/s
>
> hist(par1.transf)
>
> So, is there a way to maintain the random LHS (with uniformly
> distributed parameters) so that the refered condition is fulfilled?
>
> Any suggestions would be much welcome.
>
> Thanks,
>
> Duarte
>
>

Duarte,

In my experience with Latin hypercube samples, most people draw the sample on
a uniform hypercube and then transform the uniform cube to have new
distributions on the margins.  The transformed distributions are not
necessarily uniform.  It is possible to draw a Latin hypercube with correlated
margins and I hope to add that to my package in the future.  I have also done
transforms such that the transformed marginal distributions are correlated (as
you have in your example).  I have not seen a correlated set of uniform
marginal distributions such that the margins sum to one, however.  I'll make a
quick example argument that explains the difficulty...

In two dimensions, you could draw this which is uniform and correlated.
x <- seq(0.05, 0.95, length=10)
y <- 1-x
all.equal(x+y, rep(1, length(x)))
hist(x)
hist(y)

But in three dimensions, it is hard to maintain uniformity because large
samples on the first uniform margin overweight the small samples on the other
margins.
x <- seq(0.05, 0.95, length=10)
y <- runif(length(x), 0, 1-x)
z <- 1-x-y
hist(x)
hist(y)
hist(z)

If you could explain why you want to maintain the uniformity on the margins, I
might be able to suggest something different.

Rob

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Latin Hypercube Sampling with a condition

Ravi Varadhan
I am not sure, but this thread from a couple of months ago might be relevant (and useful):

https://stat.ethz.ch/pipermail/r-help/2011-March/273423.html

Ravi.

________________________________________
From: [hidden email] [[hidden email]] on behalf of Rob Carnell [[hidden email]]
Sent: Thursday, June 02, 2011 8:30 AM
To: [hidden email]
Subject: Re: [R] Latin Hypercube Sampling with a condition

Duarte Viana <viana.sptd <at> gmail.com> writes:

>
> Hello all,
>
> I am trying to do a Latin Hypercube Sampling (LHS) to a 5-parameter
> design matrix. I start as follows:
>
> library(lhs)
>
> p1<-randomLHS(1000, 5)
>
> If I check the distribution of each parameter (column), they are
> perfectly uniformly distributed (as expected).For example,
>
> hist(p1[,1])
>
> Now the hard (maybe strange) question. I want the combination of the
> first three parameters to sum up to 1 (which obviously do not)
>
> s<-p1[,1]+p1[,2]+p1[,3]
>
> s==1
>
> It occurred to me to divide each of these parameters with the sum
> (vector "s" above). However the uniform distribution is lost (example
> for parameter 1 - first column):
>
> par1.transf<-p1[,1]/s
>
> hist(par1.transf)
>
> So, is there a way to maintain the random LHS (with uniformly
> distributed parameters) so that the refered condition is fulfilled?
>
> Any suggestions would be much welcome.
>
> Thanks,
>
> Duarte
>
>

Duarte,

In my experience with Latin hypercube samples, most people draw the sample on
a uniform hypercube and then transform the uniform cube to have new
distributions on the margins.  The transformed distributions are not
necessarily uniform.  It is possible to draw a Latin hypercube with correlated
margins and I hope to add that to my package in the future.  I have also done
transforms such that the transformed marginal distributions are correlated (as
you have in your example).  I have not seen a correlated set of uniform
marginal distributions such that the margins sum to one, however.  I'll make a
quick example argument that explains the difficulty...

In two dimensions, you could draw this which is uniform and correlated.
x <- seq(0.05, 0.95, length=10)
y <- 1-x
all.equal(x+y, rep(1, length(x)))
hist(x)
hist(y)

But in three dimensions, it is hard to maintain uniformity because large
samples on the first uniform margin overweight the small samples on the other
margins.
x <- seq(0.05, 0.95, length=10)
y <- runif(length(x), 0, 1-x)
z <- 1-x-y
hist(x)
hist(y)
hist(z)

If you could explain why you want to maintain the uniformity on the margins, I
might be able to suggest something different.

Rob

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Latin Hypercube Sampling with a condition

dviana
In reply to this post by carnellr
Thanks Rob and Ravi for the replies.

Let me try to explain my problem. I am trying to make a kind of
sensitivity analysis where I have 5 parameters (the margins of the
Latin hypercube), 3 of them are proportions that should sum to one. My
idea is to obtain uniform combinations of the 3 proportion-parameters
with the other two parameters. The uniformity should be maintained in
order to guarantee that each parameter (out of 5) have its own range
of values equally represented (for model output analyses).

Theoretically the 3 proportion-parameters might be regarded as one in
which the configuration of the proportions that sum to one vary. I
think I can visualize it like a set of permutations, more or less like
in the example below:

0.1 - 0.1 - 0.8
0.1 - 0.2 - 0.7
0.1 - 0.3 - 0.6
.
.
.
0.1 - 0.1 - 0.8
0.2 - 0.1 - 0.7
0.3 - 0.1 - 0.6
.
.
.
0.8 - 0.1 - 0.1
0.7 - 0.2 - 0.1
0.6 - 0.3 - 0.1
.
.
.
and so on, until all possible combinations are represented (and doing
it with more values) and then combined with the other two parameters
as to form a Latin hypercube.

The solutions given in the thread sent by Ravi work fine for random
generation of the 3 proportion-parameters, but it is hard to make a
Latin hypercube out of that with two more parameters.


Cheers,

Duarte

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Latin Hypercube Sampling with a condition

carnellr
Duarte Viana <viana.sptd <at> gmail.com> writes:

>
> Thanks Rob and Ravi for the replies.
>
> Let me try to explain my problem. I am trying to make a kind of
> sensitivity analysis where I have 5 parameters (the margins of the
> Latin hypercube), 3 of them are proportions that should sum to one. My
> idea is to obtain uniform combinations of the 3 proportion-parameters
> with the other two parameters. The uniformity should be maintained in
> order to guarantee that each parameter (out of 5) have its own range
> of values equally represented (for model output analyses).
>
> Theoretically the 3 proportion-parameters might be regarded as one in
> which the configuration of the proportions that sum to one vary. I
> think I can visualize it like a set of permutations, more or less like
> in the example below:
>
> 0.1 - 0.1 - 0.8
> 0.1 - 0.2 - 0.7
> 0.1 - 0.3 - 0.6
> .
> .
> .
> 0.1 - 0.1 - 0.8
> 0.2 - 0.1 - 0.7
> 0.3 - 0.1 - 0.6
> .
> .
> .
> 0.8 - 0.1 - 0.1
> 0.7 - 0.2 - 0.1
> 0.6 - 0.3 - 0.1
> .
> .
> .
> and so on, until all possible combinations are represented (and doing
> it with more values) and then combined with the other two parameters
> as to form a Latin hypercube.
>
> The solutions given in the thread sent by Ravi work fine for random
> generation of the 3 proportion-parameters, but it is hard to make a
> Latin hypercube out of that with two more parameters.
>
> Cheers,
>
> Duarte
>
>

Duarte,

The commmon practice in your situation is draw the K parameters together as a
uniform Latin hypercube on 0-1 and then transform the margins of the hypercube
to the desired distributions.

Easy Example
Parameter 1: normal(1, 2)
Parameter 2: normal(3, 4)
Parameter 3: uniform(5, 10)

require(lhs)
N <- 1000
x <- randomLHS(N, 3)
y <- x
y[,1] <- qnorm(x[,1], 1, 2)
y[,2] <- qnorm(x[,2], 3, 4)
y[,3] <- qunif(x[,3], 5, 10)

par(mfrow=c(2,2))
apply(x, 2, hist)

par(mfrow=c(2,2))
apply(y, 2, hist)

The transformed distributions maintain their "Latin" properties, but are in
the form of new distributions.

In your case, you'd like the first three columns to be transformed into a
correlated set that sums to one.  Still follow the pattern...

x <- randomLHS(N, 5)
y <- x
y[,1] <- x[,1]/rowSums(x[,1:3])
y[,2] <- x[,2]/rowSums(x[,1:3])
y[,3] <- x[,3]/rowSums(x[,1:3])
y[,4] <- x[,4]
y[,5] <- x[,5]

par(mfrow=c(2,3))
apply(x, 2, hist)

par(mfrow=c(2,3))
apply(y, 2, hist)

all.equal(rowSums(y[,1:3]), rep(1, nrow(y)))

The uniform properties are gone as you can see here...

par(mfrow=c(1,1))
pairs(x)
paris(y, col="red")

But, the "Latin" properties of the first three margins are maintained as in
this smaller example...

N <- 10
x <- randomLHS(N, 5)
y <- x
y[,1] <- x[,1]/rowSums(x[,1:3])
y[,2] <- x[,2]/rowSums(x[,1:3])
y[,3] <- x[,3]/rowSums(x[,1:3])
y[,4] <- x[,4]
y[,5] <- x[,5]

pairs(x)
pairs(y, col="red")

You could also look into a dirichlet type transform as I posted here
http://tolstoy.newcastle.edu.au/R/e5/help/08/11/8420.html

Rob

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Latin Hypercube Sampling with a condition

dviana
Thanks again Rob for your help.

In terms of parameter comparison there won't be a problem. However, if
one wants to assume a particular distribution (and not the one given
by the imposed condition), for example an uniform distribution to
obtain all the possible combinations (all the multidimensional space
uniformly filled), then a limitation exists. Perhaps it is not
possible to fulfill the three criteria - sum to one, maintain the
uniform distribution and maintain the latin hypercube property. Well,
I will try to do it the way you proposed.

Cheers,

Duarte






On Thu, Jun 2, 2011 at 7:06 PM, Rob Carnell <[hidden email]> wrote:

> Duarte Viana <viana.sptd <at> gmail.com> writes:
>
>>
>> Thanks Rob and Ravi for the replies.
>>
>> Let me try to explain my problem. I am trying to make a kind of
>> sensitivity analysis where I have 5 parameters (the margins of the
>> Latin hypercube), 3 of them are proportions that should sum to one. My
>> idea is to obtain uniform combinations of the 3 proportion-parameters
>> with the other two parameters. The uniformity should be maintained in
>> order to guarantee that each parameter (out of 5) have its own range
>> of values equally represented (for model output analyses).
>>
>> Theoretically the 3 proportion-parameters might be regarded as one in
>> which the configuration of the proportions that sum to one vary. I
>> think I can visualize it like a set of permutations, more or less like
>> in the example below:
>>
>> 0.1 - 0.1 - 0.8
>> 0.1 - 0.2 - 0.7
>> 0.1 - 0.3 - 0.6
>> .
>> .
>> .
>> 0.1 - 0.1 - 0.8
>> 0.2 - 0.1 - 0.7
>> 0.3 - 0.1 - 0.6
>> .
>> .
>> .
>> 0.8 - 0.1 - 0.1
>> 0.7 - 0.2 - 0.1
>> 0.6 - 0.3 - 0.1
>> .
>> .
>> .
>> and so on, until all possible combinations are represented (and doing
>> it with more values) and then combined with the other two parameters
>> as to form a Latin hypercube.
>>
>> The solutions given in the thread sent by Ravi work fine for random
>> generation of the 3 proportion-parameters, but it is hard to make a
>> Latin hypercube out of that with two more parameters.
>>
>> Cheers,
>>
>> Duarte
>>
>>
>
> Duarte,
>
> The commmon practice in your situation is draw the K parameters together as a
> uniform Latin hypercube on 0-1 and then transform the margins of the hypercube
> to the desired distributions.
>
> Easy Example
> Parameter 1: normal(1, 2)
> Parameter 2: normal(3, 4)
> Parameter 3: uniform(5, 10)
>
> require(lhs)
> N <- 1000
> x <- randomLHS(N, 3)
> y <- x
> y[,1] <- qnorm(x[,1], 1, 2)
> y[,2] <- qnorm(x[,2], 3, 4)
> y[,3] <- qunif(x[,3], 5, 10)
>
> par(mfrow=c(2,2))
> apply(x, 2, hist)
>
> par(mfrow=c(2,2))
> apply(y, 2, hist)
>
> The transformed distributions maintain their "Latin" properties, but are in
> the form of new distributions.
>
> In your case, you'd like the first three columns to be transformed into a
> correlated set that sums to one.  Still follow the pattern...
>
> x <- randomLHS(N, 5)
> y <- x
> y[,1] <- x[,1]/rowSums(x[,1:3])
> y[,2] <- x[,2]/rowSums(x[,1:3])
> y[,3] <- x[,3]/rowSums(x[,1:3])
> y[,4] <- x[,4]
> y[,5] <- x[,5]
>
> par(mfrow=c(2,3))
> apply(x, 2, hist)
>
> par(mfrow=c(2,3))
> apply(y, 2, hist)
>
> all.equal(rowSums(y[,1:3]), rep(1, nrow(y)))
>
> The uniform properties are gone as you can see here...
>
> par(mfrow=c(1,1))
> pairs(x)
> paris(y, col="red")
>
> But, the "Latin" properties of the first three margins are maintained as in
> this smaller example...
>
> N <- 10
> x <- randomLHS(N, 5)
> y <- x
> y[,1] <- x[,1]/rowSums(x[,1:3])
> y[,2] <- x[,2]/rowSums(x[,1:3])
> y[,3] <- x[,3]/rowSums(x[,1:3])
> y[,4] <- x[,4]
> y[,5] <- x[,5]
>
> pairs(x)
> pairs(y, col="red")
>
> You could also look into a dirichlet type transform as I posted here
> http://tolstoy.newcastle.edu.au/R/e5/help/08/11/8420.html
>
> Rob
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.