numbas / Numbas

A completely browser-based e-assessment/e-learning system, with an emphasis on mathematics
http://www.numbas.org.uk
Apache License 2.0
197 stars 118 forks source link

Add functions to bin data #1020

Closed christianp closed 10 months ago

christianp commented 11 months ago

Data binning is the process of grouping data into a fixed number of smaller bins.

There should be functions to do this with lists of numbers in JME. There are a few ways to do it, depending on how much information you can give in advance, and how much you infer from the data.

So we need to define a few versions of bin that take different arguments. I'm not sure exactly what their names should be.

Here are some example inputs and outputs:

For the function bin(values, bin_width):

values: [1,2,3,4] bin_width: 2 Returns: [ [1,2], [3,4] ]

values: [10,11,12,13] bin_width: 2 Returns: [ [10,11], [12,13] ]

values: [13,12,11,10] bin_width: 2 Returns: [ [10,11], [12,13] ]

values: [1, 8] bin_width: 3 Returns: [ [1], [], [8] ]

values: [0,2,2,3,6,10,11,13] bin_width: 3 Returns: [ [0,2,2], [3], [6], [10,11], [13] ]

values: [1.36, 1.45, 1.60, 1.23, 1.25, 1.66, 1.10] bin_width: 0.1 Returns: [ [1.1], [1.23, 1.25], [1.36], [1.45], [], [1.60, 1.66] ]


For the function bin(values, num_bins): bin_width = (max(values) - min(values))/num_bins

values: [1,2,3,4] num_bins: 2 Returns: [ [1,2], [3,4] ]

values: [10,11,12,13] num_bins: 2 Returns: [ [10,11], [12,13] ]

values: [10,11,12,13] num_bins: 3 Returns: [ [10], [11], [12,13] ]

values: [13,12,11,10] num_bins: 3 Returns: [ [10], [11], [12,13] ]

values: [1, 8] num_bins: 2 Returns: [ [1], [8] ]

values: [0,2,2,3,6,10,11,13] num_bins: 5 Returns: [ [0,2,2], [3], [6], [10], [11,13] ]

values: [1.36, 1.45, 1.60, 1.23, 1.25, 1.66, 1.10] num_bins: 4 Returns: [ [1.10, 1.23], [1.25, 1.36], [1.45], [1.60, 1.66] ]


For the function bin(values, start, end, num_bins): bin_width = (end - start)/num_bins

values: [1,2,3,4] start: 0 end: 5 num_bins: 2 Returns: [ [1,2], [3,4] ]

values: [10,11,12,13] start: 10 end: 15 num_bins: 2 Returns: [ [10,11], [12,13] ]

values: [10,11,12,13] start: 0 end: 15 num_bins: 3 Returns: [ [], [], [10, 11, 12,13] ]

values: [0,2,2,3,6,10,11,13] start: 0 end: 15 num_bins: 5 Returns: [ [0,2,2], [3], [6], [10,11], [13] ]

values: [1.36, 1.45, 1.60, 1.23, 1.25, 1.66, 1.10] start: 1 end: 2 num_bins: 10 Returns: [ [], [1.10], [1.23,1.25], [1.36], [1.45], [], [1.60, 1.66], [], [], [] ]

christianp commented 11 months ago

@JanOnBread here's an issue describing how I want the bin functions to work.

yashmonk123 commented 10 months ago

can I take this issue?

yashmonk123 commented 10 months ago

And also can you please specify where we need to add that function and in which language you want

christianp commented 10 months ago

@yashmonk123 thanks for offering to help, but @janonbread took this on. I forgot to assign this issue to her - sorry for the inconvenience!