Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for cumsum flag for histogram #5138

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions python/fate/arch/histogram/_histogram_sbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class HistogramBuilder:
def __init__(
self, num_node, feature_bin_sizes, value_schemas, global_seed=None, seed=None, node_mapping=None, k=None
self, num_node, feature_bin_sizes, value_schemas, global_seed=None, seed=None, node_mapping=None, k=None, enable_cumsum=True
):
self._num_node = num_node
self._feature_bin_sizes = feature_bin_sizes
Expand All @@ -13,6 +13,7 @@ def __init__(
self._global_seed = global_seed
self._seed = seed
self._node_mapping = node_mapping
self._enable_cumsum = enable_cumsum
self._k = k

def __str__(self):
Expand All @@ -35,6 +36,7 @@ def statistic(self, data) -> "DistributedHistogram":
self._global_seed,
self._k,
self._node_mapping,
self._enable_cumsum,
)
table = data.mapReducePartitions(mapper, lambda x, y: x.iadd(y))
data = DistributedHistogram(
Expand All @@ -43,13 +45,14 @@ def statistic(self, data) -> "DistributedHistogram":
return data


def get_partition_hist_build_mapper(num_node, feature_bin_sizes, value_schemas, global_seed, k, node_mapping):
def get_partition_hist_build_mapper(num_node, feature_bin_sizes, value_schemas, global_seed, k, node_mapping, enable_cumsum):
def _partition_hist_build_mapper(part):
hist = Histogram.create(num_node, feature_bin_sizes, value_schemas)
for _, raw in part:
feature_ids, node_ids, targets = raw
hist.i_update(feature_ids, node_ids, targets, node_mapping)
hist.i_cumsum_bins()
if enable_cumsum:
hist.i_cumsum_bins()
if global_seed is not None:
hist.i_shuffle(global_seed)
splits = hist.to_splits(k)
Expand Down