{ "cells": [ { "cell_type": "markdown", "id": "cell-0", "metadata": {}, "source": [ "# Example of a C-efficient RUM design with ChoiceDesign\n", "\n", "This notebook illustrates how to use **ChoiceDesign** to generate a C-efficient experimental design for a Random Utility Maximisation (RUM) model. The C-criterion minimises the **variance of Willingness-to-Pay (WTP)** estimates rather than the overall parameter variance.\n", "\n", "For each non-cost attribute $x$ with parameter $\\beta_x$, the WTP is defined as:\n", "\n", "$$\\text{WTP}_x = \\frac{\\beta_x}{\\beta_{\\text{cost}}}$$\n", "\n", "Using the delta method, the variance of $\\text{WTP}_x$ is $c_x^\\top I^{-1} c_x$, where the contrast vector is:\n", "\n", "$$c_x[j] = \\begin{cases} 1/\\beta_{\\text{cost}} & j = x \\\\ -\\beta_x/\\beta_{\\text{cost}}^2 & j = \\text{cost} \\\\ 0 & \\text{otherwise} \\end{cases}$$\n", "\n", "The **C-error** is the sum of these variances over all nominated WTPs. A lower C-error means more precise WTP estimates, which is the quantity of primary interest in many stated choice studies.\n", "\n", "## Step 1: Load modules, define design parameters and set attributes\n", "\n", "The following lines load:\n", "- `EffDesign`: the class of efficient designs,\n", "- `Attribute` and `Parameter`: the classes of attributes and parameters, respectively." ] }, { "cell_type": "code", "execution_count": 1, "id": "cell-1", "metadata": {}, "outputs": [], "source": [ "from choicedesign.design import EffDesign\n", "from choicedesign.expressions import Attribute, Parameter" ] }, { "cell_type": "markdown", "id": "cell-2", "metadata": {}, "source": [ "The following lines define 2 alternatives and 4 attributes ($A$ to $D$). **Attribute $B$ is treated as the cost attribute** — its parameter $\\beta_B$ is the denominator in all WTP ratios." ] }, { "cell_type": "code", "execution_count": 2, "id": "cell-3", "metadata": {}, "outputs": [], "source": [ "alt1_A = Attribute('alt1_A',[1,2,3])\n", "alt1_B = Attribute('alt1_B',[10,15,15.5])\n", "alt1_C = Attribute('alt1_C',[0,3,5])\n", "alt1_D = Attribute('alt1_D',[0,1,2])\n", "\n", "alt2_A = Attribute('alt2_A',[1,2,3])\n", "alt2_B = Attribute('alt2_B',[10,15,15.5])\n", "alt2_C = Attribute('alt2_C',[0,3,5])\n", "alt2_D = Attribute('alt2_D',[0,1,2])" ] }, { "cell_type": "markdown", "id": "cell-4", "metadata": {}, "source": [ "## Step 2: Construct efficient design object and generate initial design matrix" ] }, { "cell_type": "code", "execution_count": 3, "id": "cell-5", "metadata": {}, "outputs": [], "source": [ "design = EffDesign(\n", " X = [alt1_A,alt1_B,alt1_C,alt1_D,\n", " alt2_A,alt2_B,alt2_C,alt2_D],\n", " ncs=18)" ] }, { "cell_type": "code", "execution_count": 4, "id": "cell-6", "metadata": {}, "outputs": [ { "data": { "application/vnd.microsoft.datawrangler.viewer.v0+json": { "columns": [ { "name": "index", "rawType": "int64", "type": "integer" }, { "name": "alt1_A", "rawType": "float64", "type": "float" }, { "name": "alt1_B", "rawType": "float64", "type": "float" }, { "name": "alt1_C", "rawType": "float64", "type": "float" }, { "name": "alt1_D", "rawType": "float64", "type": "float" }, { "name": "alt2_A", "rawType": "float64", "type": "float" }, { "name": "alt2_B", "rawType": "float64", "type": "float" }, { "name": "alt2_C", "rawType": "float64", "type": "float" }, { "name": "alt2_D", "rawType": "float64", "type": "float" } ], "ref": "eec5f5cd-4024-4dd4-b38a-1309345d2f1b", "rows": [ [ "0", "1.0", "15.0", "3.0", "2.0", "2.0", "10.0", "3.0", "1.0" ], [ "1", "1.0", "15.5", "0.0", "1.0", "3.0", "15.5", "3.0", "1.0" ], [ "2", "1.0", "15.5", "5.0", "1.0", "2.0", "15.0", "0.0", "1.0" ], [ "3", "3.0", "10.0", "5.0", "0.0", "1.0", "15.5", "0.0", "0.0" ], [ "4", "2.0", "15.0", "3.0", "1.0", "1.0", "10.0", "3.0", "0.0" ], [ "5", "1.0", "10.0", "5.0", "0.0", "2.0", "15.0", "3.0", "2.0" ], [ "6", "1.0", "10.0", "3.0", "0.0", "2.0", "15.0", "5.0", "1.0" ], [ "7", "2.0", "15.0", "5.0", "2.0", "1.0", "15.0", "3.0", "2.0" ], [ "8", "2.0", "15.5", "3.0", "1.0", "3.0", "15.5", "0.0", "0.0" ], [ "9", "3.0", "15.0", "5.0", "1.0", "1.0", "15.5", "5.0", "0.0" ], [ "10", "3.0", "15.5", "0.0", "2.0", "2.0", "10.0", "5.0", "2.0" ], [ "11", "1.0", "10.0", "3.0", "2.0", "3.0", "15.5", "3.0", "2.0" ], [ "12", "2.0", "15.0", "0.0", "0.0", "2.0", "10.0", "5.0", "2.0" ], [ "13", "3.0", "10.0", "0.0", "2.0", "3.0", "15.0", "0.0", "1.0" ], [ "14", "2.0", "15.5", "0.0", "0.0", "3.0", "15.5", "5.0", "1.0" ], [ "15", "2.0", "10.0", "5.0", "0.0", "1.0", "15.0", "0.0", "0.0" ], [ "16", "3.0", "15.5", "0.0", "2.0", "1.0", "10.0", "5.0", "0.0" ], [ "17", "3.0", "15.0", "3.0", "1.0", "3.0", "10.0", "0.0", "2.0" ] ], "shape": { "columns": 8, "rows": 18 } }, "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
alt1_Aalt1_Balt1_Calt1_Dalt2_Aalt2_Balt2_Calt2_D
01.015.03.02.02.010.03.01.0
11.015.50.01.03.015.53.01.0
21.015.55.01.02.015.00.01.0
33.010.05.00.01.015.50.00.0
42.015.03.01.01.010.03.00.0
51.010.05.00.02.015.03.02.0
61.010.03.00.02.015.05.01.0
72.015.05.02.01.015.03.02.0
82.015.53.01.03.015.50.00.0
93.015.05.01.01.015.55.00.0
103.015.50.02.02.010.05.02.0
111.010.03.02.03.015.53.02.0
122.015.00.00.02.010.05.02.0
133.010.00.02.03.015.00.01.0
142.015.50.00.03.015.55.01.0
152.010.05.00.01.015.00.00.0
163.015.50.02.01.010.05.00.0
173.015.03.01.03.010.00.02.0
\n", "
" ], "text/plain": [ " alt1_A alt1_B alt1_C alt1_D alt2_A alt2_B alt2_C alt2_D\n", "0 1.0 15.0 3.0 2.0 2.0 10.0 3.0 1.0\n", "1 1.0 15.5 0.0 1.0 3.0 15.5 3.0 1.0\n", "2 1.0 15.5 5.0 1.0 2.0 15.0 0.0 1.0\n", "3 3.0 10.0 5.0 0.0 1.0 15.5 0.0 0.0\n", "4 2.0 15.0 3.0 1.0 1.0 10.0 3.0 0.0\n", "5 1.0 10.0 5.0 0.0 2.0 15.0 3.0 2.0\n", "6 1.0 10.0 3.0 0.0 2.0 15.0 5.0 1.0\n", "7 2.0 15.0 5.0 2.0 1.0 15.0 3.0 2.0\n", "8 2.0 15.5 3.0 1.0 3.0 15.5 0.0 0.0\n", "9 3.0 15.0 5.0 1.0 1.0 15.5 5.0 0.0\n", "10 3.0 15.5 0.0 2.0 2.0 10.0 5.0 2.0\n", "11 1.0 10.0 3.0 2.0 3.0 15.5 3.0 2.0\n", "12 2.0 15.0 0.0 0.0 2.0 10.0 5.0 2.0\n", "13 3.0 10.0 0.0 2.0 3.0 15.0 0.0 1.0\n", "14 2.0 15.5 0.0 0.0 3.0 15.5 5.0 1.0\n", "15 2.0 10.0 5.0 0.0 1.0 15.0 0.0 0.0\n", "16 3.0 15.5 0.0 2.0 1.0 10.0 5.0 0.0\n", "17 3.0 15.0 3.0 1.0 3.0 10.0 0.0 2.0" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "init_design = design.gen_initdesign()\n", "init_design" ] }, { "cell_type": "markdown", "id": "cell-7", "metadata": {}, "source": [ "## Step 3: Set the utility functions and identify the cost parameter\n", "\n", "Parameters are defined with the `Parameter` class. The C-criterion requires knowing which parameter is the cost (denominator). Here `beta_B` plays that role — it has a negative prior consistent with a monetary cost." ] }, { "cell_type": "code", "execution_count": 5, "id": "cell-8", "metadata": {}, "outputs": [], "source": [ "beta_A = Parameter('beta_A',-0.1)\n", "beta_B = Parameter('beta_B',-0.02) # cost parameter\n", "beta_C = Parameter('beta_C',0.1)\n", "beta_D = Parameter('beta_D',0.15)" ] }, { "cell_type": "code", "execution_count": 6, "id": "cell-9", "metadata": {}, "outputs": [], "source": [ "V1 = beta_A * alt1_A + beta_B * alt1_B + beta_C * alt1_C + beta_D * alt1_D\n", "V2 = beta_A * alt2_A + beta_B * alt2_B + beta_C * alt2_C + beta_D * alt2_D\n", "\n", "V = {1: V1, 2: V2}" ] }, { "cell_type": "markdown", "id": "cell-10", "metadata": {}, "source": [ "## Step 4: Optimise the design using the C-error criterion\n", "\n", "Set `criterion='c'` and supply:\n", "\n", "* `cost_param`: the `Parameter` object that acts as the WTP denominator (`beta_B` here)\n", "* `wtp_params`: list of `Parameter` objects whose WTP variances are minimised (all non-cost parameters)\n", "\n", "The C-error is the sum of $c_x^\\top I^{-1} c_x$ over all nominated WTPs, evaluated at the prior values." ] }, { "cell_type": "code", "execution_count": 7, "id": "cell-11", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Evaluating initial design\n", "Optimization complete 0:00:59 / C-error: 3190.561282\n", "Elapsed time: 0:01:00\n", "C-error of initial design: 5800.839106\n", "C-error of last stored design: 3190.561282\n", "Utility Balance ratio: 99.24 %\n", "Algorithm iterations: 181904\n", "\n" ] } ], "source": [ "optimal_design, init_perf, final_perf, final_iter, ubalance_ratio = design.optimise(\n", " init_design=init_design,\n", " V=V,\n", " model='mnl',\n", " criterion='c',\n", " cost_param=beta_B,\n", " wtp_params=[beta_A, beta_C, beta_D],\n", " time_lim=1,\n", " verbose=True\n", ")" ] }, { "cell_type": "markdown", "id": "cell-12", "metadata": {}, "source": [ "## Blocking the design\n", "\n", "The optimal design can be blocked using the method `gen_blocks()`. The following line creates 3 blocks:" ] }, { "cell_type": "code", "execution_count": 8, "id": "cell-13", "metadata": {}, "outputs": [ { "data": { "application/vnd.microsoft.datawrangler.viewer.v0+json": { "columns": [ { "name": "index", "rawType": "int64", "type": "integer" }, { "name": "CS", "rawType": "float64", "type": "float" }, { "name": "alt1_A", "rawType": "float64", "type": "float" }, { "name": "alt1_B", "rawType": "float64", "type": "float" }, { "name": "alt1_C", "rawType": "float64", "type": "float" }, { "name": "alt1_D", "rawType": "float64", "type": "float" }, { "name": "alt2_A", "rawType": "float64", "type": "float" }, { "name": "alt2_B", "rawType": "float64", "type": "float" }, { "name": "alt2_C", "rawType": "float64", "type": "float" }, { "name": "alt2_D", "rawType": "float64", "type": "float" }, { "name": "Block", "rawType": "int64", "type": "integer" } ], "ref": "7b20dbbe-2336-4cc5-a271-47296288f853", "rows": [ [ "0", "1.0", "1.0", "15.5", "0.0", "2.0", "3.0", "10.0", "3.0", "0.0", "3" ], [ "1", "2.0", "1.0", "10.0", "0.0", "1.0", "3.0", "15.5", "0.0", "2.0", "2" ], [ "2", "3.0", "1.0", "15.0", "0.0", "1.0", "3.0", "15.0", "5.0", "1.0", "1" ], [ "3", "4.0", "3.0", "10.0", "3.0", "0.0", "1.0", "15.5", "0.0", "2.0", "2" ], [ "4", "5.0", "3.0", "15.5", "5.0", "2.0", "1.0", "10.0", "5.0", "0.0", "2" ], [ "5", "6.0", "2.0", "15.0", "5.0", "0.0", "2.0", "15.0", "3.0", "2.0", "3" ], [ "6", "7.0", "3.0", "10.0", "5.0", "1.0", "1.0", "15.5", "3.0", "1.0", "1" ], [ "7", "8.0", "1.0", "15.0", "0.0", "0.0", "2.0", "15.0", "3.0", "1.0", "2" ], [ "8", "9.0", "2.0", "15.0", "3.0", "1.0", "2.0", "15.0", "0.0", "0.0", "2" ], [ "9", "10.0", "3.0", "15.0", "3.0", "2.0", "1.0", "15.0", "5.0", "0.0", "3" ], [ "10", "11.0", "3.0", "15.5", "5.0", "2.0", "1.0", "10.0", "3.0", "1.0", "1" ], [ "11", "12.0", "2.0", "10.0", "5.0", "0.0", "2.0", "15.5", "3.0", "2.0", "3" ], [ "12", "13.0", "2.0", "15.5", "5.0", "0.0", "2.0", "10.0", "0.0", "2.0", "1" ], [ "13", "14.0", "1.0", "10.0", "3.0", "1.0", "3.0", "15.5", "5.0", "1.0", "1" ], [ "14", "15.0", "2.0", "15.5", "0.0", "1.0", "3.0", "10.0", "0.0", "1.0", "3" ], [ "15", "16.0", "3.0", "10.0", "3.0", "2.0", "1.0", "15.5", "5.0", "0.0", "3" ], [ "16", "17.0", "2.0", "15.0", "0.0", "2.0", "2.0", "15.0", "5.0", "0.0", "1" ], [ "17", "18.0", "1.0", "15.5", "3.0", "0.0", "3.0", "10.0", "0.0", "2.0", "2" ] ], "shape": { "columns": 10, "rows": 18 } }, "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
CSalt1_Aalt1_Balt1_Calt1_Dalt2_Aalt2_Balt2_Calt2_DBlock
01.01.015.50.02.03.010.03.00.03
12.01.010.00.01.03.015.50.02.02
23.01.015.00.01.03.015.05.01.01
34.03.010.03.00.01.015.50.02.02
45.03.015.55.02.01.010.05.00.02
56.02.015.05.00.02.015.03.02.03
67.03.010.05.01.01.015.53.01.01
78.01.015.00.00.02.015.03.01.02
89.02.015.03.01.02.015.00.00.02
910.03.015.03.02.01.015.05.00.03
1011.03.015.55.02.01.010.03.01.01
1112.02.010.05.00.02.015.53.02.03
1213.02.015.55.00.02.010.00.02.01
1314.01.010.03.01.03.015.55.01.01
1415.02.015.50.01.03.010.00.01.03
1516.03.010.03.02.01.015.55.00.03
1617.02.015.00.02.02.015.05.00.01
1718.01.015.53.00.03.010.00.02.02
\n", "
" ], "text/plain": [ " CS alt1_A alt1_B alt1_C alt1_D alt2_A alt2_B alt2_C alt2_D \\\n", "0 1.0 1.0 15.5 0.0 2.0 3.0 10.0 3.0 0.0 \n", "1 2.0 1.0 10.0 0.0 1.0 3.0 15.5 0.0 2.0 \n", "2 3.0 1.0 15.0 0.0 1.0 3.0 15.0 5.0 1.0 \n", "3 4.0 3.0 10.0 3.0 0.0 1.0 15.5 0.0 2.0 \n", "4 5.0 3.0 15.5 5.0 2.0 1.0 10.0 5.0 0.0 \n", "5 6.0 2.0 15.0 5.0 0.0 2.0 15.0 3.0 2.0 \n", "6 7.0 3.0 10.0 5.0 1.0 1.0 15.5 3.0 1.0 \n", "7 8.0 1.0 15.0 0.0 0.0 2.0 15.0 3.0 1.0 \n", "8 9.0 2.0 15.0 3.0 1.0 2.0 15.0 0.0 0.0 \n", "9 10.0 3.0 15.0 3.0 2.0 1.0 15.0 5.0 0.0 \n", "10 11.0 3.0 15.5 5.0 2.0 1.0 10.0 3.0 1.0 \n", "11 12.0 2.0 10.0 5.0 0.0 2.0 15.5 3.0 2.0 \n", "12 13.0 2.0 15.5 5.0 0.0 2.0 10.0 0.0 2.0 \n", "13 14.0 1.0 10.0 3.0 1.0 3.0 15.5 5.0 1.0 \n", "14 15.0 2.0 15.5 0.0 1.0 3.0 10.0 0.0 1.0 \n", "15 16.0 3.0 10.0 3.0 2.0 1.0 15.5 5.0 0.0 \n", "16 17.0 2.0 15.0 0.0 2.0 2.0 15.0 5.0 0.0 \n", "17 18.0 1.0 15.5 3.0 0.0 3.0 10.0 0.0 2.0 \n", "\n", " Block \n", "0 3 \n", "1 2 \n", "2 1 \n", "3 2 \n", "4 2 \n", "5 3 \n", "6 1 \n", "7 2 \n", "8 2 \n", "9 3 \n", "10 1 \n", "11 3 \n", "12 1 \n", "13 1 \n", "14 3 \n", "15 3 \n", "16 1 \n", "17 2 " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "optimal_design_blocked, corr_history = design.gen_blocks(optimal_design, n_blocks=3)\n", "optimal_design_blocked" ] }, { "cell_type": "markdown", "id": "cell-14", "metadata": {}, "source": [ "## (optional) Evaluate the design\n", "\n", "Pass `criterion='c'` with the same `cost_param` and `wtp_params` to `evaluate()` to compute the C-error of a stored design:" ] }, { "cell_type": "code", "execution_count": 9, "id": "cell-15", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "C-error: 3190.561282446267\n", "Utility balance: 99.23852054210096\n" ] } ], "source": [ "perf, ubalance = design.evaluate(\n", " optimal_design,\n", " V,\n", " model='mnl',\n", " criterion='c',\n", " cost_param=beta_B,\n", " wtp_params=[beta_A, beta_C, beta_D]\n", ")\n", "\n", "print('C-error:', perf)\n", "print('Utility balance:', ubalance)" ] }, { "cell_type": "markdown", "id": "2963ec52", "metadata": {}, "source": [ "## Export the design\n", "\n", "Export the C-efficient design to Excel." ] }, { "cell_type": "code", "execution_count": null, "id": "96feabe1", "metadata": {}, "outputs": [], "source": [ "attr_names = {\n", " 'alt1_A': 'Attribute A', 'alt2_A': 'Attribute A',\n", " 'alt1_B': 'Attribute B', 'alt2_B': 'Attribute B',\n", " 'alt1_C': 'Attribute C', 'alt2_C': 'Attribute C',\n", " 'alt1_D': 'Attribute D', 'alt2_D': 'Attribute D',\n", "}\n", "design.export_design(optimal_design, attr_names, 'rum_c_efficient_design.xlsx')" ] }, { "cell_type": "markdown", "id": "c37a8f00", "metadata": {}, "source": [ "## Save the optimisation summary\n", "\n", "After calling `optimise()`, the method `export_output()` writes a plain-text summary of the optimisation run — design configuration, stopping criteria, criterion values, utility balance, elapsed time, and iteration count — to a file." ] }, { "cell_type": "code", "execution_count": null, "id": "813ae028", "metadata": {}, "outputs": [], "source": [ "design.export_output('rum_c_efficient_output.txt')" ] }, { "cell_type": "markdown", "id": "cell-16", "metadata": {}, "source": [ "## References\n", "\n", "[1] Quan, W., Rose, J. M., Collins, A. T., & Bliemer, M. C. (2011). A comparison of algorithms for generating efficient choice experiments.\n" ] } ], "metadata": { "kernelspec": { "display_name": "choicedesign-oSBhddzi-py3.13", "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.13.1" } }, "nbformat": 4, "nbformat_minor": 5 }