Skip to content

Commit

Permalink
add aditional histogram data to json output
Browse files Browse the repository at this point in the history
  • Loading branch information
basvandenberg committed Nov 22, 2014
1 parent b23c8c3 commit 42e7388
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions spice/featmat.py
Expand Up @@ -660,10 +660,13 @@ def ttest(self, labeling_name, label0, label1, object_is=None):
return ts

def histogram_data(self, feat_id, labeling_name, class_ids=None,
num_bins=40, standardized=False):
num_bins=40, standardized=False, title=None):

# test num_bins > 0

if(title is None):
title = ''

# get labeling data
try:
labeling = self.labeling_dict[labeling_name]
Expand Down Expand Up @@ -711,17 +714,26 @@ def histogram_data(self, feat_id, labeling_name, class_ids=None,
bin_edges = list(numpy.arange(min_val, max_val, step))
bin_edges.append(max_val)

max_count = 0
hists = {}
for lab in hist_data.keys():

h, e = numpy.histogram(hist_data[lab], bin_edges)
hists[lab] = list(h)

max_count = max(max_count, max(h))

result = {}
result['feature-id'] = feat_id
result['title'] = title
result['x-label'] = feat_name
result['legend'] = class_ids
for lab in class_ids:
result[lab] = hists[lab]
result['min-value'] = min_val
result['max-value'] = max_val
result['max-count'] = max_count
result['bin-edges'] = bin_edges

return result

Expand All @@ -732,7 +744,7 @@ def histogram_json(self, feat_id, labeling_name, class_ids=None,
title = ''

hist_data = self.histogram_data(feat_id, labeling_name, class_ids,
standardized=standardized)
standardized=standardized, title=title)
return json.dumps(hist_data)

def save_histogram(self, feat_id, labeling_name, class_ids=None,
Expand Down

0 comments on commit 42e7388

Please sign in to comment.