def test_eval_measures(): #mainly regression tests x = np.arange(20).reshape(4,5) y = np.ones((4,5)) assert_equal(iqr(x, y), 5*np.ones(5)) assert_equal(iqr(x, y, axis=1), 2*np.ones(4)) assert_equal(iqr(x, y, axis=None), 9) assert_equal(mse(x, y), np.array([ 73.5, 87.5, 103.5, 121.5, 141.5])) assert_equal(mse(x, y, axis=1), np.array([ 3., 38., 123., 258.])) assert_almost_equal(rmse(x, y), np.array([ 8.5732141 , 9.35414347, 10.17349497, 11.02270384, 11.89537725])) assert_almost_equal(rmse(x, y, axis=1), np.array([ 1.73205081, 6.164414, 11.09053651, 16.0623784 ])) assert_equal(maxabs(x, y), np.array([ 14., 15., 16., 17., 18.])) assert_equal(maxabs(x, y, axis=1), np.array([ 3., 8., 13., 18.])) assert_equal(meanabs(x, y), np.array([ 7. , 7.5, 8.5, 9.5, 10.5])) assert_equal(meanabs(x, y, axis=1), np.array([ 1.4, 6. , 11. , 16. ])) assert_equal(meanabs(x, y, axis=0), np.array([ 7. , 7.5, 8.5, 9.5, 10.5])) assert_equal(medianabs(x, y), np.array([ 6.5, 7.5, 8.5, 9.5, 10.5])) assert_equal(medianabs(x, y, axis=1), np.array([ 1., 6., 11., 16.])) assert_equal(bias(x, y), np.array([ 6.5, 7.5, 8.5, 9.5, 10.5])) assert_equal(bias(x, y, axis=1), np.array([ 1., 6., 11., 16.])) assert_equal(medianbias(x, y), np.array([ 6.5, 7.5, 8.5, 9.5, 10.5])) assert_equal(medianbias(x, y, axis=1), np.array([ 1., 6., 11., 16.])) assert_equal(vare(x, y), np.array([ 31.25, 31.25, 31.25, 31.25, 31.25])) assert_equal(vare(x, y, axis=1), np.array([ 2., 2., 2., 2.]))
def test_eval_measures(): # mainly regression tests x = np.arange(20).reshape(4, 5) y = np.ones((4, 5)) assert_equal(iqr(x, y), 5 * np.ones(5)) assert_equal(iqr(x, y, axis=1), 2 * np.ones(4)) assert_equal(iqr(x, y, axis=None), 9) assert_equal(mse(x, y), np.array([73.5, 87.5, 103.5, 121.5, 141.5])) assert_equal(mse(x, y, axis=1), np.array([3.0, 38.0, 123.0, 258.0])) assert_almost_equal( rmse(x, y), np.array( [8.5732141, 9.35414347, 10.17349497, 11.02270384, 11.89537725] ), ) assert_almost_equal( rmse(x, y, axis=1), np.array([1.73205081, 6.164414, 11.09053651, 16.0623784]), ) err = x - y loc = np.where(x != 0) err[loc] /= x[loc] err[np.where(x == 0)] = np.nan expected = np.sqrt(np.nanmean(err ** 2, 0) * 100) assert_almost_equal(rmspe(x, y), expected) err[np.where(np.isnan(err))] = 0.0 expected = np.sqrt(np.nanmean(err ** 2, 0) * 100) assert_almost_equal(rmspe(x, y, zeros=0), expected) assert_equal(maxabs(x, y), np.array([14.0, 15.0, 16.0, 17.0, 18.0])) assert_equal(maxabs(x, y, axis=1), np.array([3.0, 8.0, 13.0, 18.0])) assert_equal(meanabs(x, y), np.array([7.0, 7.5, 8.5, 9.5, 10.5])) assert_equal(meanabs(x, y, axis=1), np.array([1.4, 6.0, 11.0, 16.0])) assert_equal(meanabs(x, y, axis=0), np.array([7.0, 7.5, 8.5, 9.5, 10.5])) assert_equal(medianabs(x, y), np.array([6.5, 7.5, 8.5, 9.5, 10.5])) assert_equal(medianabs(x, y, axis=1), np.array([1.0, 6.0, 11.0, 16.0])) assert_equal(bias(x, y), np.array([6.5, 7.5, 8.5, 9.5, 10.5])) assert_equal(bias(x, y, axis=1), np.array([1.0, 6.0, 11.0, 16.0])) assert_equal(medianbias(x, y), np.array([6.5, 7.5, 8.5, 9.5, 10.5])) assert_equal(medianbias(x, y, axis=1), np.array([1.0, 6.0, 11.0, 16.0])) assert_equal(vare(x, y), np.array([31.25, 31.25, 31.25, 31.25, 31.25])) assert_equal(vare(x, y, axis=1), np.array([2.0, 2.0, 2.0, 2.0]))
def gen_results(d): #exp = d.query('Trial > 10 and Time > 5') exp = d.query('Time > 5') error = exp.groupby(('Day', 'Subject', 'Trial')).ae.mean().reset_index() error.columns = ['Day', 'Subject', 'Trial', 'AbsoluteError'] rms = exp.groupby( ('Day', 'Subject', 'Trial')).apply(lambda x: rmse(x.y, x.yg)).reset_index() rms.columns = ['Day', 'Subject', 'Trial', 'RMSE'] var = exp.groupby( ('Day', 'Subject', 'Trial')).apply(lambda x: vare(x.y, x.yg)).reset_index() var.columns = ['Day', 'Subject', 'Trial', 'VARE'] crossings = exp.groupby( ('Day', 'Subject', 'Trial')).apply(lambda x: len(cross(x.e))).reset_index() crossings.columns = ['Day', 'Subject', 'Trial', 'Crossings'] rt = find_response_times(exp, trials) response_time = rt.groupby( ('Day', 'Subject', 'Trial')).mean().ResponseTime.reset_index() td = exp.groupby(('Day', 'Subject', 'Trial')).apply( lambda x: recover_shift(x['Time'], x['y'], x['yg'])).reset_index() time_delay = td.groupby( ('Day', 'Subject', 'Trial')).mean()[0].reset_index().abs() time_delay.columns = ['Day', 'Subject', 'Trial', 'LagTime'] #entropy = generate_entropy_results(exp) #res = error.merge(rms).merge(var).merge(crossings).merge(response_time, how='outer').merge(time_delay).merge(entropy) res = error.merge(rms).merge(var).merge(crossings).merge( response_time, how='outer').merge(time_delay) res['Feedback'] = res.Subject % 2 == 1 res = res.merge(trials[['Trial']]) res = res.sort(['Day', 'Subject', 'Trial']) #res['SecondaryTask'] = res['Secondary_Task'] res = res[[ 'Day', 'Subject', 'Trial', 'AbsoluteError', 'RMSE', 'VARE', 'ResponseTime', 'LagTime', 'Crossings', 'Feedback' ]] res = res.reset_index(drop=True) res['ID'] = (res.Day - 1) * res.Trial.max() + res.Trial return res