Skip to content

Instantly share code, notes, and snippets.

@AntonGitName
Last active April 18, 2017 08:34
Show Gist options
  • Save AntonGitName/4a2002ebc3366a6daf3d68cc2b1a2630 to your computer and use it in GitHub Desktop.
Save AntonGitName/4a2002ebc3366a6daf3d68cc2b1a2630 to your computer and use it in GitHub Desktop.
Au testing course
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 0 2 0
0 0 2 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
0 1 2 0
0 1 2 1
0 2 0 0
0 2 0 1
0 2 1 0
0 2 1 1
0 2 2 0
0 2 2 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 0 2 0
1 0 2 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
1 1 2 0
1 1 2 1
1 2 0 0
1 2 0 1
1 2 1 0
1 2 1 1
1 2 2 0
1 2 2 1
2 0 0 0
2 0 0 1
2 0 1 0
2 0 1 1
2 0 2 0
2 0 2 1
2 1 0 0
2 1 0 1
2 1 1 0
2 1 1 1
2 1 2 0
2 1 2 1
2 2 0 0
2 2 0 1
2 2 1 0
2 2 1 1
2 2 2 0
2 2 2 1
3 0 0 0
3 0 0 1
3 0 1 0
3 0 1 1
3 0 2 0
3 0 2 1
3 1 0 0
3 1 0 1
3 1 1 0
3 1 1 1
3 1 2 0
3 1 2 1
3 2 0 0
3 2 0 1
3 2 1 0
3 2 1 1
3 2 2 0
3 2 2 1
4 0 0 0
4 0 0 1
4 0 1 0
4 0 1 1
4 0 2 0
4 0 2 1
4 1 0 0
4 1 0 1
4 1 1 0
4 1 1 1
4 1 2 0
4 1 2 1
4 2 0 0
4 2 0 1
4 2 1 0
4 2 1 1
4 2 2 0
4 2 2 1
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Let's try to generate an array by ourself first.\n",
"\n",
"We need a mixed-level orthogonal array with strength 3. \n",
"I have found a list of common series here: \n",
"http://www.pietereendebak.nl/oapackage/series.html\n",
"\n",
"In our case the most suitable variant is this one:\n",
"http://www.pietereendebak.nl/oapackage/series/series-90.5-3-3-2-t3.html.\n",
"But in fact, it is just a table of all possible variants for given series (it is kinda obvious if first you notice that 90 = 5 x 3 x 3 x 2). \n",
"That means that some rows can be removed while preserving the strength of 3 for an array.\n",
"\n",
"Let's do this."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import itertools\n",
"\n",
"# generate all possible combinations [5 x 3 x 3 x 2]\n",
"c = np.array(list(itertools.product(range(5), range(3), range(3), range(2))))\n",
"# create indexes for all triplets\n",
"indexes = [[0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3]]\n",
"\n",
"def check_strength(a):\n",
" for idxs in indexes:\n",
" view = a[:, idxs].tolist()\n",
" # check that every possible triplet is presented in our orthgonal array\n",
" for row in c[:, idxs]:\n",
" if row.tolist() not in view:\n",
" return False\n",
" return True"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# load precalculated series\n",
"initial_array = np.loadtxt(\"series-90.5-3-3-2-t3.txt\").astype(int)\n",
"rows = initial_array\n",
"# It is not minimal possible array with strength 3. For instance, it \n",
"# is easily seen that row (0 0 0 0) can be removed as we have rows\n",
"# (0 0 0 1), (0 0 1 0), (0 1 0 0) and (1 0 0 0).\n",
"\n",
"# try to reduce number of rows\n",
"while True:\n",
" n = len(rows)\n",
" can_stop = True\n",
" # choose a row that we are going to remove\n",
" for i in range(n):\n",
" indxs = list(range(n))\n",
" indxs = indxs[:i] + indxs[i+1:]\n",
" # check if resulting array still has a strength of value 3\n",
" if check_strength(rows[indxs,:]):\n",
" # remove row and continue\n",
" rows = rows[indxs,:]\n",
" can_stop = False\n",
" break\n",
" # no rows to remove, finish iterations\n",
" if can_stop:\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Resulting array (size = 45):\n",
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 2 0\n",
"0 1 0 1\n",
"0 1 1 1\n",
"0 1 2 0\n",
"0 2 0 0\n",
"0 2 1 0\n",
"0 2 2 1\n",
"1 0 0 1\n",
"1 0 1 1\n",
"1 0 2 0\n",
"1 1 0 1\n",
"1 1 1 1\n",
"1 1 2 0\n",
"1 2 0 0\n",
"1 2 1 0\n",
"1 2 2 1\n",
"2 0 0 1\n",
"2 0 1 1\n",
"2 0 2 0\n",
"2 1 0 1\n",
"2 1 1 1\n",
"2 1 2 0\n",
"2 2 0 0\n",
"2 2 1 0\n",
"2 2 2 1\n",
"3 0 0 1\n",
"3 0 1 1\n",
"3 0 2 0\n",
"3 1 0 1\n",
"3 1 1 1\n",
"3 1 2 0\n",
"3 2 0 0\n",
"3 2 1 0\n",
"3 2 2 1\n",
"4 0 0 0\n",
"4 0 1 0\n",
"4 0 2 1\n",
"4 1 0 0\n",
"4 1 1 0\n",
"4 1 2 1\n",
"4 2 0 1\n",
"4 2 1 1\n",
"4 2 2 0\n",
"Removed rows (count = 45):\n",
"0 0 0 0\n",
"0 0 1 0\n",
"0 0 2 1\n",
"0 1 0 0\n",
"0 1 1 0\n",
"0 1 2 1\n",
"0 2 0 1\n",
"0 2 1 1\n",
"0 2 2 0\n",
"1 0 0 0\n",
"1 0 1 0\n",
"1 0 2 1\n",
"1 1 0 0\n",
"1 1 1 0\n",
"1 1 2 1\n",
"1 2 0 1\n",
"1 2 1 1\n",
"1 2 2 0\n",
"2 0 0 0\n",
"2 0 1 0\n",
"2 0 2 1\n",
"2 1 0 0\n",
"2 1 1 0\n",
"2 1 2 1\n",
"2 2 0 1\n",
"2 2 1 1\n",
"2 2 2 0\n",
"3 0 0 0\n",
"3 0 1 0\n",
"3 0 2 1\n",
"3 1 0 0\n",
"3 1 1 0\n",
"3 1 2 1\n",
"3 2 0 1\n",
"3 2 1 1\n",
"3 2 2 0\n",
"4 0 0 1\n",
"4 0 1 1\n",
"4 0 2 0\n",
"4 1 0 1\n",
"4 1 1 1\n",
"4 1 2 0\n",
"4 2 0 0\n",
"4 2 1 0\n",
"4 2 2 1\n"
]
}
],
"source": [
"print(\"Resulting array (size = {}):\".format(len(rows)))\n",
"print('\\n'.join(' '.join(str(x) for x in row) for row in rows))\n",
"print(\"Removed rows (count = {}):\".format(len(initial_array) - len(rows)))\n",
"print('\\n'.join(' '.join(str(x) for x in row) for row in initial_array if row.tolist() not in rows.tolist()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Let's try to use oapackage to generate an array.\n",
"\n",
"Unfortunately, it fails to generate an array for OA(45; 3; 5<sup>1</sup>3<sup>2</sup>2<sup>1</sup>). But it does generate an array for OA(90; 3; 5<sup>1</sup>3<sup>2</sup>2<sup>1</sup>) with all rows duplicated..."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import oapackage\n",
"import oapackage.oahelper as oahelper\n",
"import oalib"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def generate_and_print(N): \n",
" adata = oalib.arraydata_t([5, 3, 3, 2], N, 3, 4)\n",
" al = oalib.array_link(adata.N, adata.strength, 1)\n",
" al.create_root(adata)\n",
" extended = oalib.extend_array(al, adata)\n",
" if extended:\n",
" extended[0].showarray()\n",
" else:\n",
" print(\"fail\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"45\n",
"fail\n",
"90\n",
"array: \n",
" 0 0 0 0\n",
" 0 0 0 0\n",
" 0 0 1 0\n",
" 0 0 1 1\n",
" 0 0 2 1\n",
" 0 0 2 1\n",
" 0 1 0 0\n",
" 0 1 0 1\n",
" 0 1 1 0\n",
" 0 1 1 1\n",
" 0 1 2 0\n",
" 0 1 2 1\n",
" 0 2 0 1\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n",
"generate_and_print(45)\n",
"print(\"90\")\n",
"generate_and_print(90)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment