Fix bug: column partitions were were incorrectly mapped to view partitions.
As with the previous bug fix -- I suspect that again, itertools.groupby
was used incorrectly. To avoid any mistakes, I am now referring to view
indices directly, via a named list of view indices.
@@ -947,17 +947,19 @@ class CGPM_Backend(BayesDB_Backend):
}
def _json_ready_model(self, state, name_map):
+ # We work off the same view-indeces everywhere.
+ view_indices = sorted(state.views.keys())
# state.Zv() is a column partition given as {colnum: viewnum, ...}
- column_groups = itertools.groupby(
- sorted(state.Zv().items()),
- key=operator.itemgetter(1))
column_partition = [
- [name_map[colno] for (colno, _) in block]
- for (_, block) in column_groups
+ [name_map[colno] for colno, current_view_index in state.Zv().items()
+ if current_view_index==view_index]
+ for view_index in view_indices
]
- column_crp_hypers = [view.alpha() for view in state.views.values()]
-
+ column_crp_hypers = [
+ state.views[view_index].alpha()
+ for view_index in view_indices
+ ]
# All row clusters for all views: e.g. [[[0,1], [2,3,4], [5]], [[0,2,3],[1,4,5]]]
# This triple comprehension is tricky so here is some explanation.
# view.Zr() is a row partition given as {rownum: clusternum, ...}.
@@ -969,12 +971,12 @@ class CGPM_Backend(BayesDB_Backend):
[
sorted([
rowid
- for (rowid, current_cluster_index) in view.Zr().items()
+ for (rowid, current_cluster_index) in state.views[view_index].Zr().items()
if current_cluster_index==cluster_index
])
- for cluster_index in sorted(set(view.Zr().values()))
+ for cluster_index in sorted(set(state.views[view_index].Zr().values()))
]
- for view in state.views.values()
+ for view_index in view_indices
]
# Each column has a little dict of hyperparameters
