Skip to content

Commit a81bf18

Browse files
committed
Decompose with equal sample sized bins
1 parent 49e3b67 commit a81bf18

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/simdec/decomposition.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,18 @@ def statistic_(inputs):
163163
bins.append(inputs)
164164
return statistic_method(inputs)
165165

166+
# make bins with equal number of samples for a given dimension
167+
# sort and then split in n-state
168+
sorted_inputs = np.sort(inputs, axis=0)
169+
bin_edges = []
170+
for i, states_ in enumerate(states):
171+
splits = np.array_split(sorted_inputs[:, i], states_)
172+
bin_edges_ = [splits_[0] for splits_ in splits]
173+
bin_edges_.append(splits[-1][-1]) # last point to close the edges
174+
bin_edges.append(bin_edges_)
175+
166176
res = stats.binned_statistic_dd(
167-
inputs, values=output, statistic=statistic_, bins=states
177+
inputs, values=output, statistic=statistic_, bins=bin_edges
168178
)
169179

170180
bins = pd.DataFrame(bins[1:]).T

0 commit comments

Comments
 (0)