pernak18 / g-point-reduction

Jupyter Notebook evolution of RRTMGP g-point reduction (AKA k-distribution optimization) that started with Menno's [k-distribution-opt](https://github.com/MennoVeerman/k-distribution-opt) repo
0 stars 0 forks source link

Reduction Refinement #16

Closed pernak18 closed 2 years ago

pernak18 commented 2 years ago
Currently, the merged K and P in an iteration are defined in terms of the existing (i.e. at the time of the iteration) values as:
Ki = wi * ki + wi+1 * ki+1
Pi = Pi + Pi+1
where the normalized (i.e. wi + wi+1 =1) weights are defined in terms of the existing weights as:
wi  = wi / (wi + wi+1) and wi+1  = wi+1 / (wi + wi+1)

We choose the g-points involved in the winning trial as before.

Define a modified merged K’ as
K’i = (wi+Dw) * ki + (wi+1-Dw) * ki+1
where Dw is set as a fraction x of the larger weight wi :
Dw = x * wi
Write Dw = n * x0 * wi.
(The Planck merger is unchanged from above.)

Call the winning trial K0, which has corresponding cost function CF0. (We now drop the subscript i denoting the trial.) If CF0 represents a non-trivial (to be defined) increase in the overall CF, we evaluate two variations on the winning trial K0 (corresponding cost function CF0) :  K-1 and K1, where Kn, Dw = n * x0 * wi.
Let’s choose x0 = 0.05 for our first attempts at this.

We end up with three pairs of points:  (n=-1,CF-1), (n=0,CF0), (n=1,CF1).
----------------
Label these (x1,y1),(x2,y2), (x3,y3).

The minimum of the parabola through those points is 
xmin = [x32 * (y2-y1) + x22 * (y1-y3) + x12 * (y3-y2)] / {2 * [x3*(y2-y1) + x2*(y1-y3) + x1*(y3-y2)]}

Compute nmin = xmin /0.05. 
(This may need some experimentation.) If nmin is outside of the range +-1, then the final winning trial will use the K that yields the lowest of the three CFs above. 
If n is in the range +-1, then run a variation with nmin= xmin /0.05. 
If the resulting change in CF (between the CF for xmin and the CF before this iteration) is negative or a trivial positive, then terminate and the final result of this trial will use nmin.
If the resulting CF is greater than the other three, then the final winning trial will use the K that yields the lowest of the three CFs above. 
Check some sort of convergence criterion (tbd).
Choose the three points with lowest three CFs out of the four candidate points.
Repeat  the steps below -------
pernak18 commented 2 years ago

From Karen in Slack:

I can get the code to modify the coefficients and calculate fluxes with those coefficients; the modified fluxes are in the right and seem to make at least qualitative sense. But I cannot get correct total cost or deltaCost for the modified fluxes. Instead I get exactly the same values as for the original g-points.

The problem I see comes after line 269 (flux_compute.py): on this line I use the combineBandsSglMethod to fill build a combinedDS variable that contains the modified fluxes. I pass in the name of the new flux file for the modified band as trialNC. I think this is working; butwhen I compute the cost function (with costFuncCompSgl, it seems the cost functions for each of the cot function variables are modified but not the total cost function or its delta. And try as I might I cannot find the line that prints out the individual cost function terms:

pernak18 commented 2 years ago

i believe this was addressed with ec11aef92a4020d32ca850699f13f17c5ea80685 by making a (deep) copy of the cost optimization object, rather than introducing the perturbations into the existing object