tisimst / pyDOE

Design of experiments for Python
BSD 3-Clause "New" or "Revised" License
263 stars 114 forks source link

Error in generator specification for fracfact() #26

Closed AlexandreBohyn closed 4 years ago

AlexandreBohyn commented 4 years ago

There is an issue with the fracfact() function when specifying the generator. The following code should give me a 2^(3-1) design in 4 runs gen = 'a b ab'; fracfact(gen) But instead it treats the the generator string as "a b a b" and gives me a 2^4 design in 16 runs. This comes from the following code in the fracfact() function: A = [item for item in re.split('\-?\s?\+?', gen) if item] The regex string should be '-?\s+?', this way the space isn't optional and it treats a string 'ab' as an interaction and not as two factor 'a' 'b' put together.

tisimst commented 4 years ago

Which version of Python are you using? I get this in 2.7:

>>> from pyDOE import fracfact
>>> gen = 'a b ab'
>>> fracfact(gen)
[[-1. -1.  1.]
 [ 1. -1. -1.]
 [-1.  1. -1.]
 [ 1.  1.  1.]]

>>> re.split('\-?\s?\+?', gen)
['a', 'b', 'ab']

Could this be an issue in 3.X only or did I miss something?

AlexandreBohyn commented 4 years ago

Hello,

Yes I'm using python 3.7.4 so that might be the source of the problem.

AlexandreBohyn commented 4 years ago

I'm getting this outpout from 3.X:

>>> import pyDOE
>>> gen = 'a b ab'
>>> pyDOE.fracfact(gen)
array([[-1., -1., -1., -1.],
       [ 1., -1., -1., -1.],
       [-1.,  1., -1., -1.],
       [ 1.,  1., -1., -1.],
       [-1., -1.,  1., -1.],
       [ 1., -1.,  1., -1.],
       [-1.,  1.,  1., -1.],
       [ 1.,  1.,  1., -1.],
       [-1., -1., -1.,  1.],
       [ 1., -1., -1.,  1.],
       [-1.,  1., -1.,  1.],
       [ 1.,  1., -1.,  1.],
       [-1., -1.,  1.,  1.],
       [ 1., -1.,  1.,  1.],
       [-1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.]])
>>> re.split('\-?\s?\+?', gen)
['', 'a', '', 'b', '', 'a', 'b', '']

but using the new regex I have:

>>> re.split('\-?\s+\+?', gen)
['a', 'b', 'ab']
AlexandreBohyn commented 4 years ago

It works fine in the pyDOE2 package, so I guess the problem has been solved later on.