|
1 | 1 | Gradient-based rho |
2 | 2 | ================== |
| 3 | +You can find a detailed example using this code in ``examples.farmer.CI.farmer_rho_demo.py``. |
3 | 4 |
|
4 | | -``mpisppy.utils.gradient.py`` computes rho |
5 | | -using the gradient and writes them in a file. |
| 5 | +Grad-rho is also supported in ``generic_cylinders.py``. |
6 | 6 |
|
7 | | -.. Note:: |
8 | | - This only works for two-stage problems for now. |
| 7 | +There are options in ``cfg`` to control dynamic updates: |
9 | 8 |
|
10 | | -To compute gradient-based rho, you can call ``grad_cost_and_rho`` |
11 | | -after creating your config object. |
12 | | -You will need to add ``gradient_args`` when you set up the config object. |
13 | | -For example with farmer: |
14 | | - |
15 | | -.. code-block:: python |
16 | | -
|
17 | | - import mpisppy.utils.gradient as grad |
18 | | -
|
19 | | - def _parse_args(): |
20 | | - cfg = config.Config() |
21 | | - ... |
22 | | - cfg.gradient_args() |
23 | | -
|
24 | | - def main(): |
25 | | - ... #after the config object is created |
26 | | - grad.grad_cost_and_rho('farmer', cfg) |
27 | | -
|
28 | | -.. Note:: |
29 | | - This will write a rho file (resp. grad cost file) |
30 | | - only if you include ``--grad-rho-file`` (resp. ``--grad-cost-file``) |
31 | | - in your bash script. |
32 | | - |
33 | | -You can find a detailed example using this code in ``examples.farmer.farmer_rho_demo.py``. |
34 | | - |
35 | | - |
36 | | -compute_grad |
37 | | ------------- |
38 | | - |
39 | | -This function computes the gradient of the objective function for each scenario. |
40 | | -It will write the resulting gradient costs in a csv file |
41 | | -containing each scenario name, variable name and the corresponding value. |
42 | | - |
43 | | -To use it you should include the following in your bash script. |
44 | | - |
45 | | -.. code-block:: bash |
46 | | -
|
47 | | - --xhatpath #path of your xhat file (.npy) |
48 | | - --grad-cost-file #file where gradient costs will be written |
49 | | -
|
50 | | -
|
51 | | -find_grad_rho |
52 | | -------------- |
53 | | - |
54 | | -This function computes rhos for each scenario and variable |
55 | | -using the previously computed gradient costs. |
56 | | -The rho values depend on both the scenario and the variable: |
57 | | -``compute_rhos`` returns a dictionnary with the variable names |
58 | | -and a list of corresponding rho values for each scenario. |
59 | | - |
60 | | - |
61 | | -grad_cost_and_rho |
62 | | ------------------ |
63 | | - |
64 | | -This function computes a rho for each variable using the dictionnary |
65 | | -returned by ``find_grad_rho``. |
66 | | -To do so, it uses an order statistic which you should set with ``--order-stat``. |
67 | | -It needs to be a float between 0 and 1: 0 (resp. 1, 0.5) |
68 | | -corresponding to the min (resp. max, average). |
69 | | -It will write the resulting rhos in a csv file |
70 | | -containing each variable name and the corresponding value. |
71 | | - |
72 | | -To use it you should include the following in your bash script. |
73 | | - |
74 | | -.. code-block:: bash |
75 | | -
|
76 | | - --grad-rho-file #file where gradient rhos will be written |
77 | | - --order-stat #float between 0 and 1 |
| 9 | + * `--dynamic-rho-primal-crit` and `--dynamic-rho-dual-crit` are booleans that trigger dynamic rho |
| 10 | + * `--dynamic-rho-primal-thresh` and `--dynamic-rho-dual-thresh` control how sensitive the trigger is. |
| 11 | + They have default values, so do not need to be set. See |
| 12 | + ``dyn_rho_base.py`` to see how the update is done if you don't like the default values. |
| 13 | + * `--grad-rho-multiplier` is a cummulative multiplier when rho is set or updated. |
0 commit comments