forcedotcom / distributions

Low-level primitives for collapsed Gibbs sampling in python and C++
BSD 3-Clause "New" or "Revised" License
33 stars 25 forks source link

merge two groups? #51

Closed jglidden closed 10 years ago

jglidden commented 10 years ago

Does it make sense to add a plus_group method to group to combine suff stats? This is a common pattern in inference for HDP models and, I believe, split-merge kernels.

shared = model.Shared()
group1 = model.Group()
group1.init(shared)
group2 = model.Group()
group2.init(shared)
group3 = group1.plus_group(group2)
fritzo commented 10 years ago

Sure, we already have the in-place group.merge() operation https://github.com/forcedotcom/distributions/blob/master/doc/overview.rst and adding a copying .plus_group operation should be as simple as adding the wrapper to the GroupMixin classes in python & cpp.

fritzo commented 10 years ago

Probably the cleanest way to support this is to implement .copy() methods for each datatype (cheaper than dump;load) and implement in GroupMixin

def plus_group(self, shared, other):
    sum = self.copy()
    sum.merge(shared, other)
    return sum