{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example code for delete-one-factor projections" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Any orthogonal array can be reduced to delete-one-factor projection form using `reduceDOPform`. The method is described in the article [A canonical form for non-regular arrays based on\n", "generalized wordlength pattern values of\n", "delete-one-factor projections](http://pietereendebak.nl/files/Eendebak2014-delete-one-factor.pdf) by Eendebak, P. T.\n", "In this notebook, we reduce an example array to its delete-one-factor projection form." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load required libraries and select an example orthogonal array with 16 runs and 7 factors." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "array:\n", " 0 0 0 0 0 0 0\n", " 0 0 0 0 0 0 1\n", " 0 0 0 1 1 1 0\n", " 0 0 0 1 1 1 1\n", " 0 1 1 0 0 1 0\n", " 0 1 1 0 0 1 1\n", " 0 1 1 1 1 0 0\n", " 0 1 1 1 1 0 1\n", " 1 0 1 0 1 0 0\n", " 1 0 1 0 1 1 1\n", " 1 0 1 1 0 0 0\n", " 1 0 1 1 0 1 1\n", " 1 1 0 0 1 0 1\n", " 1 1 0 0 1 1 0\n", " 1 1 0 1 0 0 1\n", " 1 1 0 1 0 1 0\n" ] } ], "source": [ "import oapackage\n", "\n", "al = oapackage.exampleArray(4)\n", "al = oapackage.reduceDOPform(al)\n", "al.showarray()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A key property of the delete-of-factor projection form is that the generalized word length patterns (GWLPs) of the projections are ordered. For details on the GWLP, see [Statistical properties of orthogonal arrays](https://oapackage.readthedocs.io/en/latest/properties.html#statistical-properties-of-orthogonal-arrays)." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "GWLP (1.0, 0.0, 0.0, 3.5, 2.5, 0.5, 0.5, 0.0)\n", "Delete column 0: GWLP (1.0, 0.0, 0.0, 1.5, 1.0, 0.5, 0.0)\n", "Delete column 1: GWLP (1.0, 0.0, 0.0, 1.75, 0.75, 0.25, 0.25)\n", "Delete column 2: GWLP (1.0, 0.0, 0.0, 1.75, 0.75, 0.25, 0.25)\n", "Delete column 3: GWLP (1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0)\n", "Delete column 4: GWLP (1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0)\n", "Delete column 5: GWLP (1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0)\n", "Delete column 6: GWLP (1.0, 0.0, 0.0, 3.0, 2.0, 0.0, 0.0)\n" ] } ], "source": [ "print(f\"GWLP {al.GWLP()}\")\n", "for ii in range(0, al.n_columns):\n", " bl = al.deleteColumn(ii)\n", " print(\"Delete column %d: GWLP %s\" % (ii, str(bl.GWLP())))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The symmetry group of the projection GWLPs can be calculated. This symmetry group determines how fast an array can be reduced to normal form." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "symmetry group: 7 elements, 4 subgroups: 1 2 3 1 \n" ] } ], "source": [ "dof_values = oapackage.projectionDOFvalues(al)\n", "sg = oapackage.symmetry_group(dof_values, False)\n", "sg.show(1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is also possible to reduce mixed-level arrays to their delete-of-factor projection forms. We now show an example involving an orthogonal array with 24 runs, one four-level factor, one three-level factor and three two-level factors." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "array:\n", " 0 0 0 0 0\n", " 0 0 0 0 0\n", " 0 1 0 0 0\n", " 0 1 1 1 1\n", " 0 2 1 1 1\n", " 0 2 1 1 1\n", " 1 0 0 1 1\n", " 1 0 0 1 1\n", " 1 1 0 0 1\n", " 1 1 1 1 0\n", " 1 2 1 0 0\n", " 1 2 1 0 0\n", " 2 0 1 0 1\n", " 2 0 1 0 1\n", " 2 1 0 1 0\n", " 2 1 1 0 1\n", " 2 2 0 1 0\n", " 2 2 0 1 0\n", " 3 0 1 1 0\n", " 3 0 1 1 0\n", " 3 1 0 1 1\n", " 3 1 1 0 0\n", " 3 2 0 0 1\n", " 3 2 0 0 1\n", "delete-one-factor GWLP values [(1.0, 0.0, 0.0, 0.0, 0.6666666666666666), (1.0, 0.0, 0.0, 2.111111111111111, 0.0), (1.0, 0.0, 0.0, 1.8888888888888888, 0.4444444444444444), (1.0, 0.0, 0.0, 2.3333333333333335, 0.0), (1.0, 0.0, 0.0, 1.8888888888888888, 0.4444444444444444)]\n" ] } ], "source": [ "al = oapackage.exampleArray(5)\n", "al.showarray()\n", "dopgwlp = oapackage.projectionGWLPs(al)\n", "print(f\"delete-one-factor GWLP values {[x.raw_values() for x in dopgwlp]}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The delete-of-factor values for mixel-level arrays consists of the factor level of the deleted column and the GWLP of the projection." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "column 0: factor level 4\n", " delete-of-factor value: [-4.0, 1.0, 0.0, 0.0, 0.0, 0.6666666666666666]\n", "column 1: factor level 3\n", " delete-of-factor value: [-3.0, 1.0, 0.0, 0.0, 2.111111111111111, 0.0]\n", "column 2: factor level 2\n", " delete-of-factor value: [-2.0, 1.0, 0.0, 0.0, 1.8888888888888888, 0.4444444444444444]\n", "column 3: factor level 2\n", " delete-of-factor value: [-2.0, 1.0, 0.0, 0.0, 2.3333333333333335, 0.0]\n", "column 4: factor level 2\n", " delete-of-factor value: [-2.0, 1.0, 0.0, 0.0, 1.8888888888888888, 0.4444444444444444]\n" ] } ], "source": [ "oapackage.projectionGWLPs\n", "dopgwp = oapackage.projectionGWLPs(al)\n", "arrayclass = oapackage.arraylink2arraydata(al)\n", "dofvalues = oapackage.projectionDOFvalues(al)\n", "factor_levels = arrayclass.factor_levels()\n", "\n", "for column, dof_value in enumerate(dofvalues):\n", " print(\"column %d: factor level %s\" % (column, factor_levels[column]))\n", " print(f\" delete-of-factor value: {list(dof_value.raw_values())}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Show the reduced array." ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "array:\n", " 0 0 0 0 0\n", " 0 0 0 0 0\n", " 0 1 0 0 0\n", " 0 1 1 1 1\n", " 0 2 1 1 1\n", " 0 2 1 1 1\n", " 1 0 0 1 1\n", " 1 0 0 1 1\n", " 1 1 0 0 1\n", " 1 1 1 1 0\n", " 1 2 1 0 0\n", " 1 2 1 0 0\n", " 2 0 1 0 1\n", " 2 0 1 0 1\n", " 2 1 0 1 0\n", " 2 1 1 0 1\n", " 2 2 0 1 0\n", " 2 2 0 1 0\n", " 3 0 1 1 0\n", " 3 0 1 1 0\n", " 3 1 0 1 1\n", " 3 1 1 0 0\n", " 3 2 0 0 1\n", " 3 2 0 0 1\n" ] } ], "source": [ "reduced_array = al.reduceDOP()\n", "al.showarray()" ] } ], "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 }