Optimize KL Bug [initial pos=None, dry_run=True, transition]
Initial Position, dry_run, transition
The mean is set accordingly to the initial position.
If initial pos == None
it is first generated as something living on a empty domain. @pfrank do you know why? As far as I understand it is empty because later this will be populated by _normal_initialize
if initial_position is None:
mean = full(makeDomain({}), 0.)
else:
mean = initial_position
del(initial_position)
This mean is used to generate a single_value_sample_list
: Which is then also EMPTY.
sl = _single_value_sample_list(mean, comm=comm(initial_index))
Then the mean is set to the mean of the previous iteration or to the _transition(sl). The mean keys missing in the initial multifield get populated by standard gaussian distributed variables (0.1 std). (so all here)
t = transitions(iglobal)
mean = mean if t is None else t(sl)
mean = _normal_initialize(mean, lh.domain)
Later in the minimization the sample_list gets overwritten.
Now the Problem:
If dry_run==True
is used:
- Sampling is skipped
- Minimization is skipped
- overwriting Sample_list is skipped This means we keep the old empty sample_list.
So, as soon as we set
- the initial_pos!= None an empty sample list is created
- and
dry_run==True
(which means, that the list sample_list stays empty) - any transition which trys to do something with the sample is called(e.g. calling a key() of the dictionary/Multifield)
ADDITION: It also fails if the transition starts at the 0 global it and not initial pos is given
You get an error (missing key).
My suggestion is to use the func
tion _normal_initialize
right after setting the mean to an empty domain (or not doing this anyways)
so that the sample is not empty.
Something like this:
if initial_position is None:
mean = full(makeDomain({}), 0.)
mean = _normal_initialize(mean, likelihood_energy(iglobal=0).domain)
else:
mean = initial_position
del(initial_position)
sl = _single_value_sample_list(mean, comm=comm(initial_index))
On the other hand this can be easily fixed by the user by setting the initial_pos. But we should address this in the near future. (I can do it next week, but let me know what you think) @pfrank @gedenhof @jroth @mtr