{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Enumerate orthogonal arrays" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Orthogonal Array package can completely enumerate all orthogonal arrays of a specified class. In this notebook, we enumerate specific classes of three-level orthogonal arrays and mixel-level orthogonal arrays." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, we specify the class of three-level orthogonal arrays to enumerate. For example, we consider three-level orthogonal arrays of strength 2 with 27 runs and 8 factors." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "arrayclass: N 27, k 8, strength 2, s {3,3,3,3,3,3,3,3}, order 0\n" ] } ], "source": [ "import oapackage\n", "\n", "run_size = 27\n", "strength = 2\n", "number_of_factors = 8\n", "factor_levels = 3\n", "arrayclass = oapackage.arraydata_t(factor_levels, run_size, strength, number_of_factors)\n", "print(arrayclass)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Second, we create the root array as the starting point of our enumeration." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "00\n", "00\n", "00\n", "01\n", "01\n", "01\n", "02\n", "02\n", "02\n", "10\n", "10\n", "10\n", "11\n", "11\n", "11\n", "12\n", "12\n", "12\n", "20\n", "20\n", "20\n", "21\n", "21\n", "21\n", "22\n", "22\n", "22\n" ] } ], "source": [ "ll2 = [arrayclass.create_root()]\n", "ll2[0].showarraycompact()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Third, extend the root array. It is also possible to extend a list of arrays." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "extended to 9 arrays with 3 columns\n", "extended to 711 arrays with 4 columns\n" ] } ], "source": [ "list3columns = oapackage.extend_arraylist(ll2, arrayclass)\n", "print(\"extended to %d arrays with 3 columns\" % len(list3columns))\n", "list4columns = oapackage.extend_arraylist(list3columns, arrayclass)\n", "print(\"extended to %d arrays with 4 columns\" % len(list4columns))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is also possible to extend selected arrays from a list." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "extended first 2 arrays to 189 arrays with 5 columns\n" ] } ], "source": [ "ll = oapackage.extend_arraylist(list4columns[0:8], arrayclass)\n", "print(\"extended first 2 arrays to %d arrays with 5 columns\" % len(ll))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By adding one column at a time we can enumerate all three-level orthogonal arrays of strength 2 with 27 runs and 8 factors. The total computation time for this would be a couple of hours." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Mixed-level orthogonal arrays" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The package can also enumerate mixed-level orthogonal arrays. For instance, consider enumerating all 16-run strength-2 orthogonal arrays with one four-level factor and nine two-level factors." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "arrayclass: N 16, k 10, strength 2, s {4,2,2,2,2,2,2,2,2,2}, order 0\n" ] } ], "source": [ "run_size = 16\n", "strength = 2\n", "number_of_factors = 10\n", "factor_levels = [4, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n", "arrayclass = oapackage.arraydata_t(factor_levels, run_size, strength, number_of_factors)\n", "print(arrayclass)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create the root array as the starting point of our enumeration." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "00\n", "00\n", "01\n", "01\n", "10\n", "10\n", "11\n", "11\n", "20\n", "20\n", "21\n", "21\n", "30\n", "30\n", "31\n", "31\n" ] } ], "source": [ "al = arrayclass.create_root()\n", "al.showarraycompact()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For these arrays, we can extend a single array or lists of arrays." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "extended to 3 arrays with 3 columns\n", "extended to 10 arrays with 4 columns\n" ] } ], "source": [ "array_list = [arrayclass.create_root()]\n", "array_list_3columns = oapackage.extend_arraylist(array_list, arrayclass)\n", "array_list_4columns = oapackage.extend_arraylist(array_list_3columns, arrayclass)\n", "print(\"extended to %d arrays with 3 columns\" % len(array_list_3columns))\n", "print(\"extended to %d arrays with 4 columns\" % len(array_list_4columns))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, enumerate all 16-run strength-2 orthogonal arrays with one four-level factor and nine two-level factors." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "extended to 28 arrays with 5 columns\n", "extended to 65 arrays with 6 columns\n", "extended to 110 arrays with 7 columns\n", "extended to 123 arrays with 8 columns\n", "extended to 110 arrays with 9 columns\n", "extended to 72 arrays with 10 columns\n" ] } ], "source": [ "arrays = array_list_4columns\n", "for extension_column in range(5, number_of_factors + 1):\n", " extensions = oapackage.extend_arraylist(arrays, arrayclass)\n", " print(\"extended to %d arrays with %d columns\" % (len(extensions), extension_column))\n", " arrays = extensions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Notes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* The numbers of isomorphism classes for various types of classes can be found at the webpage series of orthogonal arrays.\n", "* For larger number of arrays the command line tools are more convenient and more memory efficient." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.8" } }, "nbformat": 4, "nbformat_minor": 4 }