# LaPSO

##### Particle Swarm Optimization for LHD

`LaPSO`

returns a maximin distance LHD constructed by particle swarm optimization algorithm (PSO)

##### Usage

`LaPSO(n, k, m, N, SameNumP, SameNumG, p0, p = 50, q = 1)`

##### Arguments

- n
A positive integer.

- k
A positive integer.

- m
A positive integer.

- N
A positive integer.

- SameNumP
A non-negative integer.

- SameNumG
A non-negative integer.

- p0
A probability.

- p
A positive integer.

- q
The default is set to be 1, and it could be either 1 or 2.

##### Details

`n`

stands for the number of rows (or run size).`k`

stands for the number of columns (or the number of factors).`m`

stands for the number of particles.`N`

stands for the number of iterations.`SameNumP`

stands for how many elements in current column of current particle LHD should be the same as corresponding Personal Best. SameNumP=0, 1, 2, ..., n, and 0 means to skip the "exchange".`SameNumG`

stands for how many elements in current column of current particle LHD should be the same as corresponding Global Best. SameNumP=0, 1, 2, ..., n, and 0 means to skip the "exchange".`SameNumP`

and`SameNumG`

cannot be 0 at the same time.`p0`

stands the probability of exchange two randomly selected elements in current column of current particle LHD.`p`

is the parameter in the phi_p formula, and`p`

is prefered to be large.If

`q`

is 1 (the default setting),`dij`

is the rectangular distance. If`q`

is 2,`dij`

is the Euclidean distance.

##### Value

If all inputs are logical, then the output will be a `n`

by `k`

LHD.

##### Note

Here are some general suggestions about the parameters:

`SameNumP`

is approximately`n`

/2 when`SameNumG`

is 0.`SameNumG`

is approximately`n`

/4 when`SameNumP`

is 0.`p0`

* (`k`

- 1) = 1 or 2 is often sufficient. So`p0`

= 1/(`k`

- 1) or 2/(`k`

- 1).

##### References

Chen, R.-B., Hsieh, D.-N., Hung, Y., and Wang, W. (2013) Optimizing Latin hypercube designs by particle swarm. *Stat. Comput.*, **23**, 663-676.

##### Examples

```
# NOT RUN {
#create a 8 by 3 maximin distance LHD, with # of particles and iterations = 10, when SameNumG is 0
tryLaPSO1=LaPSO(n=8,k=3,m=10,N=10,SameNumP=8/2,SameNumG=0,p0=1/(3-1),p=50,q=1)
tryLaPSO1
phi_p(tryLaPSO1,p=50) #calculate the phi_p of "tryLaPSO1".
#create a 8 by 3 maximin distance LHD, with # of particles and iterations = 10, when SameNumP is 0
tryLaPSO2=LaPSO(n=8,k=3,m=10,N=10,SameNumP=0,SameNumG=8/4,p0=1/(3-1),p=50,q=1)
tryLaPSO2
phi_p(tryLaPSO2,p=50) #calculate the phi_p of "tryLaPSO2".
# }
```

*Documentation reproduced from package LHD, version 0.1.0, License: MIT + file LICENSE*