Skip to content

Commit

Permalink
Merge pull request #217 from eendebakpt/dev
Browse files Browse the repository at this point in the history
Release 2.7.2
  • Loading branch information
eendebakpt authored Sep 13, 2022
2 parents 21b016a + 3cf4d8b commit dc61bda
Show file tree
Hide file tree
Showing 38 changed files with 603 additions and 1,008 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ exclude: 'doc/conf.py'

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.20.0
rev: v2.37.3
hooks:
- id: pyupgrade
# for now don't force to change from %-operator to {}
args: [--keep-percent-format, --py37-plus]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.3.0
hooks:
- id: check-ast
- id: check-builtin-literals
Expand All @@ -22,18 +22,18 @@ repos:
args: [--remove]

- repo: https://github.com/pre-commit/mirrors-autopep8
rev: 'v1.5.7'
rev: 'v1.7.0'
hooks:
- id: autopep8
args: [--max-line-length=120]

- repo: https://github.com/PyCQA/isort/
rev: 5.9.1
rev: 5.10.1
hooks:
- id: isort

- repo: https://github.com/nbQA-dev/nbQA
rev: 0.13.1
rev: 1.4.0
hooks:
- id: nbqa-black
additional_dependencies: [black==20.8b1]
Expand Down
17 changes: 9 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# C++ build
language: cpp
compiler:
- gcc
- clang
os:
- osx
- linux

jobs:
include:
- os: linux
compiler: gcc
- os: linux
compiler: clang
- os: osx
compiler: gcc

#before_install:
# - sudo apt-get install cmake
Expand Down Expand Up @@ -35,5 +38,3 @@ script:

- ./oaconference -N 12 -k 6 -v 0
- ./oapareto result-20.2-2-2.oa -f B -o dummy.oa


50 changes: 5 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

PROJECT(OApackage)

Expand All @@ -8,9 +8,7 @@ PROJECT(OApackage)
# ----------------------------------------------------------------------------

if(WIN32)
#message(STATUS "Set build type...")
set(CMAKE_CONFIGURATION_TYPES Release CACHE TYPE INTERNAL FORCE) # no Debug
#set(CMAKE_BUILD_TYPE Release STRING)
endif()

if (NOT WIN32)
Expand All @@ -27,8 +25,6 @@ if(ZLIB_FOUND)
endif()
message(STATUS "ZLIB_FOUND: ${ZLIB_FOUND}")
if(ZLIB_FOUND)
#message(STATUS "ZLIB_INCLUDE_DIRS: ${ZLIB_INCLUDE_DIRS}")
#message(STATUS "ZLIB_LIBRARIES: ${ZLIB_LIBRARIES}")
include_directories(${ZLIB_INCLUDE_DIRS})
endif()

Expand All @@ -38,12 +34,13 @@ if (NumPy_FOUND)
message(STATUS "NumPy was found")
endif()

# find_package(MPI) # Needed for legacy code and OpenMP functionality

# ----------------------------------------------------------------------------
# Code
# ----------------------------------------------------------------------------

set (CMAKE_CXX_STANDARD 11)

include_directories(.)
include_directories(src)
include_directories(nauty)
Expand Down Expand Up @@ -151,10 +148,6 @@ if("$ENV{OADEBUG}" STREQUAL "1")
set(COPTS "-g -O0 -DOADEBUG" ) # -std=c++0x -Weffc++")
endif()

if(WIN32)
else()
set(LINKOPTS "${LINKOPTS}") # or use -s option
endif()

if(WIN32)
set(COPTS "/MT /wd4018 /wd4996")
Expand All @@ -167,7 +160,7 @@ endif()

set(COPTS "${COPTS} -DFULLPACKAGE")

if(ZLIB_FOUND AND 1)
if(ZLIB_FOUND)
set(COPTS "${COPTS} -DUSEZLIB")
include_directories(ZLIB_INCLUDE_DIRS)
else()
Expand Down Expand Up @@ -208,7 +201,7 @@ set(progs oacat oajoin oapareto oasplit oaanalyse oainfo oaunittest oaconvert oa
set(progsextend )

list(APPEND progs oacheck oastreaming oaranktest oatest oaclustergather)
list(APPEND progs oa_depth_extend)
list(APPEND progs oa_depth_extend oa_select_maxj)

if (WIN32)
add_library(oalib STATIC ${srcsextend} ${headersextend} ${nautysrc} ${graphsrc})
Expand Down Expand Up @@ -240,39 +233,6 @@ endif()
TARGET_LINK_LIBRARIES(oaextendsingle oalib)
set(extendprogs oaextendsingle )

if (MPI_FOUND AND NOT WIN32 AND 1)
message(STATUS "Found MPI package: adding oaextendmpi")
if (VERBOSE)
message(STATUS "MPI executable: ${MPIEXEC}, libs ${MPI_LIBRARIES}")
endif()
#message(STATUS " libs ${MPI_LIBRARIES}; flags ${MPI_COMPILE_FLAGS}; libs ${MPI_LIBRARIES}")
include_directories( ${MPI_INCLUDE_PATH} )
include_directories( src/mpitools )

add_executable(oaextendmpi EXCLUDE_FROM_ALL "utils/oaextend.cpp" ${headersextend} ${srcsextend} "src/mpitools/mpitools.cpp")
target_link_libraries(oaextendmpi ${MPI_LIBRARIES})
if(MPI_COMPILE_FLAGS)
set_target_properties(oaextendmpi PROPERTIES COMPILE_FLAGS "${MPI_COMPILE_FLAGS}")
endif()
if(MPI_LINK_FLAGS)
if (WIN32)
set_target_properties(oaextendmpi PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS} /MT")
endif()
set_target_properties(oaextendmpi PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()

set_target_properties(oaextendmpi PROPERTIES COMPILE_DEFINITIONS "OAEXTEND_MULTICORE;NEWINTERFACE" )

if (WIN32)
if(ZLIB_FOUND)
TARGET_LINK_LIBRARIES(oaextendmpi ${ZLIB_LIBRARIES})
endif()
else()
TARGET_LINK_LIBRARIES(oaextendmpi m ${ZLIB_LIBRARIES})
endif()

endif(MPI_FOUND AND NOT WIN32 AND 1)

message(STATUS "Extend progs: ${extendprogs}")

message(STATUS "Progs: ${progs}")
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
* Pieter Eendebak
* Eric Schoen
* Alan Vazquez-Alcocer


* Alexandre Bohyn
10 changes: 5 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ environment:

matrix:

- PYTHON: "C:\\Python310-x64"
PYTHON_VERSION: "3.10.4"
PYTHON_ARCH: "64"

- PYTHON: "C:\\Python39-x64"
PYTHON_VERSION: "3.9.1"
PYTHON_ARCH: "64"
Expand All @@ -27,10 +31,6 @@ environment:
PYTHON_VERSION: "3.7.x"
PYTHON_ARCH: "64"

- PYTHON: "C:\\Python37"
PYTHON_VERSION: "3.7.x"
PYTHON_ARCH: "32"

matrix:
fast_finish: true

Expand Down Expand Up @@ -100,7 +100,7 @@ install:
- "%CMD_IN_ENV% pip install mock"
- "%CMD_IN_ENV% python -c \"import mock\""

- cinst -y swig --version 4.0.1
- cinst -y swig # --version 3.0.12

build: off

Expand Down
88 changes: 75 additions & 13 deletions docs/examples/example_mixed_level_gwlp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,43 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"References [xx]"
"This notebook contains example code to compute the type-specific generalized word-length pattern (GWLP) for mixed-level designs, more specifically for regular four-and-two-level designs.\n",
"\n",
"In four-and-two-level designs, the four-level factors are constructed us the grouping scheme of [Wu & Zhang (1989)](https://doi.org/10.1093/biomet/80.1.203) where the levels of a four-level factor $A$ are based on the levels of three two-level factors $a_1$, $a_2$ and $a_3$, called the pseudo-factors, where $I=a_1a_2a_3$:\n",
"$$\n",
"\\begin{array}{ccccc}\n",
" a_1 & a_2 & a_3 & & A \\\\\n",
" 1 & 1 & 0 & \\rightarrow & 0 \\\\\n",
" 1 & 0 & 1 & \\rightarrow & 1 \\\\\n",
" 0 & 1 & 1 & \\rightarrow & 2 \\\\\n",
" 0 & 0 & 0 & \\rightarrow & 3 \\\\\n",
" \\end{array}\n",
"$$\n",
"The two-level factors can either be main factors or be entirely aliased with a combination of the main factors. Such aliased factors are called added factors. If one of the main factors, used in an added factor, is also used as pseudo-factor in a four-level factor, then the added factor has type $I$. If it is used as pseudo-factor in two distinct four-level factor, it has type $II$, etc $\\ldots$."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"import oapackage"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a $4^{1}2^{7}$ four-and-two-level regular design in 32 runs with 1 four-level factor and 7 two-level factors."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -60,16 +90,22 @@
}
],
"source": [
"import numpy as np\n",
"\n",
"import oapackage\n",
"\n",
"array = oapackage.exampleArray(56, 1)\n",
"array = array.selectFirstColumns(7)\n",
"arrayclass = oapackage.arraylink2arraydata(array)\n",
"array.showarraycompact()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The GWLP for mixed-level designs is computed using the adapted forms of equations (7) and (8) in [Xu and Wu (2001)](https://www.doi.org/10.1214/aos/1009210552).\n",
"\n",
"## Distance distribution\n",
"First, the distance distribution is first computed for all combinations of $(i,j)$ with $i \\in \\{0,1\\}$ and $j=0,\\ldots,7$ and $i\\neq j$. In this example with a $4^12^{7}$ design, that is a $2 \\times 8$ matrix $B$, where $B_{i,j}$ is the number of rows that have $(1-i)$ different elements if their four-level parts and $(7-j)$ different elements in their two-level parts, divided by the number of runs."
]
},
{
"cell_type": "code",
"execution_count": 3,
Expand All @@ -79,15 +115,31 @@
"name": "stdout",
"output_type": "stream",
"text": [
"distance distribution for mixed-level design [[1 0 1 4 1 0 1]\n",
"distance distribution for mixed-level design\n",
"[[1 0 1 4 1 0 1]\n",
" [0 2 6 8 6 2 0]]\n"
]
}
],
"source": [
"Dm = oapackage.distance_distribution_mixed(array, 0)\n",
"D = np.array(Dm).astype(int)\n",
"print(f\"distance distribution for mixed-level design {D}\")"
"print(f\"distance distribution for mixed-level design\\n{D}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This is verified since the sum of the matrix is 32 which is equal to $\\binom{32}{2} 32^{-1}$.\n",
"\n",
"## McWilliams Transforms\n",
"\n",
"Now, the second step in the computation of the GWLP, is to use the McWilliams Transforms to obtain the GWLP from the distance distribution matrix. The McWilliams Transform will create another $2 \\times 8$ matrix $B^{\\prime}$, obtained using the following formula\n",
"$$\n",
"B_{j_{1}, j_{2}}^{\\prime}=N^{-1} \\sum_{i_{1}=0}^{m} \\sum_{i_{2}=0}^{n} B_{i_{1}, i_{2}} P_{j_{1}}\\left(i_{1} ; 1, 4\\right) P_{j_{2}}\\left(i_{2} ; 7, 2\\right)\n",
"$$\n",
"where $P_j(x,n,s)$ is the Krawtchouck polynomials for a total of $n$ factors with $s$ levels."
]
},
{
Expand All @@ -108,17 +160,24 @@
"source": [
"N = array.n_rows\n",
"factor_levels_for_groups = arrayclass.factor_levels_column_groups()\n",
"\n",
"Bprime = oapackage.macwilliams_transform_mixed(\n",
" Dm, N, factor_levels_for_groups=arrayclass.factor_levels_column_groups(), verbose=0\n",
")\n",
"Bprime = oapackage.macwilliams_transform_mixed(Dm, N, factor_levels_for_groups, verbose=0)\n",
"print(f\"MacWilliams transform:\")\n",
"print(np.array(Bprime))"
"print(np.array(Bprime).astype(int))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This matrix is equivalent to the type specific generalized word-length pattern, where the row index indicates the type of words (0 to 1) and the column index indicates the length of the words (0 to 7).\n",
"\n",
"The generalized word-length pattern ($A$) can be obtained by summing the rows of the $B^{\\prime}$ matrix anti-diagonally. That is:\n",
"$$A_j(D) = \\sum_{i^{\\prime}+j^{\\prime}=j} B^{\\prime}_{i^{\\prime},j^{\\prime}}$$"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -136,6 +195,9 @@
}
],
"metadata": {
"interpreter": {
"hash": "3a893c4079a4533c9db639b850e04910700d284bba4afe56b82dceecf522f906"
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
Expand Down
7 changes: 7 additions & 0 deletions oalib.i
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,13 @@ public:
}
}

%extend jstructconference_t {
public:
std::string __repr__() {
return $self->showstr();
}
}

#ifdef SWIGPYTHON
// Add module docstring
%pythoncode
Expand Down
9 changes: 9 additions & 0 deletions oapackage/oahelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,15 @@ def write_text_arrayfile(filename: str, designs: List[Any], comment: str = None)
afile.append_arrays(designs)
afile.closefile()

def arrayfile_generator(afile):
""" Return generator to read all files in the array file """
af = oapackage.arrayfile_t(afile)

na=af.narrays
for ii in range(na):
yield af.readnext()
af.closefile()


def runcommand(cmd: str, dryrun=0, idstr: Optional[None] = None, verbose: int = 1, logfile: Optional[str] = None, shell: bool = True):
""" Run specified command in external environment
Expand Down
Loading

0 comments on commit dc61bda

Please sign in to comment.