Commit febcb511 by ichuang

make psychometrics curve fitting more robust

parent 26f14aaf
...@@ -246,13 +246,16 @@ def generate_plots_for_problem(problem): ...@@ -246,13 +246,16 @@ def generate_plots_for_problem(problem):
yset['ydat'] = ydat yset['ydat'] = ydat
if len(ydat) > 3: # try to fit to logistic function if enough data points if len(ydat) > 3: # try to fit to logistic function if enough data points
cfp = curve_fit(func_2pl, xdat, ydat, [1.0, max_attempts / 2.0]) try:
yset['fitparam'] = cfp cfp = curve_fit(func_2pl, xdat, ydat, [1.0, max_attempts / 2.0])
yset['fitpts'] = func_2pl(np.array(xdat), *cfp[0]) yset['fitparam'] = cfp
yset['fiterr'] = [yd - yf for (yd, yf) in zip(ydat, yset['fitpts'])] yset['fitpts'] = func_2pl(np.array(xdat), *cfp[0])
fitx = np.linspace(xdat[0], xdat[-1], 100) yset['fiterr'] = [yd - yf for (yd, yf) in zip(ydat, yset['fitpts'])]
yset['fitx'] = fitx fitx = np.linspace(xdat[0], xdat[-1], 100)
yset['fity'] = func_2pl(np.array(fitx), *cfp[0]) yset['fitx'] = fitx
yset['fity'] = func_2pl(np.array(fitx), *cfp[0])
except Exception as err:
log.debug('Error in psychoanalyze curve fitting: %s' % err)
dataset['grade_%d' % grade] = yset dataset['grade_%d' % grade] = yset
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment