You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/src/confidence_intervals.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,7 @@ This object has a ``run`` method that returns a gap estimator and a confidence i
57
57
Examples
58
58
--------
59
59
60
-
There are example scripts for sequential sampling in both ``farmer`` and ``aircond``.
60
+
There are example scripts for sequential sampling in both ``farmer/CI`` and ``aircond``.
61
61
62
62
Using stand-alone ``mmw_conf.py``
63
63
---------------------------------
@@ -79,7 +79,7 @@ to be able to pass problem-specific args down without knowing what they are.
79
79
80
80
Once a model satisfies the requirement for amalgamator, next a ``.npy`` file should be constructed from the given model. This can be accomplished, for example, by adding the line
81
81
``sputils.ef_ROOT_nonants_npy_serializer(instance, 'xhat.npy')`` after solving the ef ``instance``. When using ``Amalgamator`` to solve the program, this can be done by adding the line
82
-
``sputils.ef_ROOT_nonants_npy_serializer(ama_object.ef, "xhat.npy")`` to your existing program (see the example in ``farmer.py`` for an example of this).
82
+
``sputils.ef_ROOT_nonants_npy_serializer(ama_object.ef, "xhat.npy")`` to your existing program (see the example in ``examples/farmer/archive/farmer.py`` for an example of this).
83
83
84
84
Once this is accomplished, on the command line, run
85
85
``python -m mpisppy.confidence_intervals.mmw_conf my_model.py xhat.npy gurobi --num-scens n --alpha 0.95``. Note that ``xhat.npy`` is assumed to be in the same directory as ``my_model.py`` in this case. If the file is saved elsewhere then the corresponding path should be called on the command line.
@@ -47,7 +47,7 @@ constraints are the number of tons per acre that each crop will yield (2.5 for
47
47
wheat, 3 for corn, and 20 for sugar beets).
48
48
49
49
50
-
The following code creates an instance of the farmer's model:
50
+
The following code in ``examples/farmer/archive/farmer.py`` (with similar code in ``examples/farmer/farmer.py``) creates an instance of the farmer's model:
51
51
52
52
.. testcode::
53
53
@@ -109,7 +109,8 @@ yields for each crop. We can solve the model:
109
109
The optimal objective value is:
110
110
111
111
.. testoutput::
112
-
112
+
:options: +SKIP
113
+
113
114
-118600.0
114
115
115
116
In practice, the farmer does not know the number of tons that each crop will
We can extract the optimal solution itself using the ``get_root_solution``
231
-
method of the ``ExtensiveForm`` object:
232
-
233
-
.. testcode::
234
-
235
-
soln = ef.get_root_solution()
236
-
for (var_name, var_val) in soln.items():
237
-
print(var_name, var_val)
238
-
239
-
.. testoutput::
240
-
241
-
X[BEETS] 250.0
242
-
X[CORN] 80.0
243
-
X[WHEAT] 170.0
223
+
This command writes solution data for nonanticipative variables to two files with the base name farmersol and full scenario solutions to a directory named farmersol_soldir.
244
224
225
+
.. note::
226
+
Most command line options relevant to the EF start with --EF. Most other command line options will be silently ignored
227
+
if ``--EF`` is specified (one exception is ``--solution-base-name``).
228
+
245
229
246
230
Solving Using Progressive Hedging (PH)
247
231
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
248
232
249
-
We can also solve the model using the progressive hedging (PH) algorithm.
250
-
First, we must construct a PH object:
251
-
252
-
.. testcode::
253
-
254
-
from mpisppy.opt.ph import PH
255
-
256
-
options = {
257
-
"solver_name": "cplex_persistent",
258
-
"PHIterLimit": 5,
259
-
"defaultPHrho": 10,
260
-
"convthresh": 1e-7,
261
-
"verbose": False,
262
-
"display_progress": False,
263
-
"display_timing": False,
264
-
"iter0_solver_options": dict(),
265
-
"iterk_solver_options": dict(),
266
-
}
267
-
all_scenario_names = ["good", "average", "bad"]
268
-
ph = PH(
269
-
options,
270
-
all_scenario_names,
271
-
scenario_creator,
272
-
)
273
-
274
-
275
-
.. testoutput::
276
-
:hide:
277
-
278
-
...
279
-
280
-
Note that all of the options in the ``options`` dict must be specified in order
281
-
to construct the PH object. Once the PH object is constructed, we can execute
282
-
the algorithm with a call to the ``ph_main`` method:
283
-
284
-
.. testcode::
285
-
286
-
ph.ph_main()
287
-
288
-
.. testoutput::
289
-
:hide:
290
-
291
-
...
292
-
293
-
294
-
.. testoutput::
295
-
:options: +SKIP
296
-
297
-
298
-
[ 0.00] Start SPBase.__init__
299
-
[ 0.01] Start PHBase.__init__
300
-
[ 0.01] Creating solvers
301
-
[ 0.01] Entering solve loop in PHBase.Iter0
302
-
[ 2.80] Reached user-specified limit=5 on number of PH iterations
233
+
Here is a simple command that uses PH as the hub algorithm and
234
+
computes lower bounds using a Lagrangian spoke (``--lagrangian``) with
235
+
upper bounds computed by randomly trying scenario solutions to fix the nonanticipative variables (``--xhatshuffle``).
303
236
304
-
Note that precise timing results may differ. In this toy example, we only
305
-
execute 5 iterations of the algorithm. Although the algorithm does not converge
306
-
completely, we can see that the first-stage variables already exhibit
0 commit comments