def make_fcn(filename):
<EOL>with open(filename, '<STR_LIT:r>') as ifile:<EOL><INDENT>lines = ifile.readlines()<EOL><DEDENT>name = filename.split('<STR_LIT:.>')[<NUM_LIT:0>]<EOL>_certified_values = re.compile('<STR_LIT>')<EOL>_data = re.compile('<STR_LIT>')<EOL>_model = re.compile('<STR_LIT>')<EOL>values = None<EOL>data = None<EOL>fcn = None<EOL>for i,line in enumerate(lines):<EOL><INDENT>m = _certified_values.match(line)<EOL>if m is not None:<EOL><INDENT>values = (int(m.group(<NUM_LIT:1>)), int(m.group(<NUM_LIT:2>)))<EOL><DEDENT>m = _data.match(line)<EOL>if m is not None:<EOL><INDENT>data = (int(m.group(<NUM_LIT:1>)), int(m.group(<NUM_LIT:2>)))<EOL><DEDENT>m = _model.match(line)<EOL>if m is not None:<EOL><INDENT>fcn = "<STR_LIT>"<EOL>for j in range(i+<NUM_LIT:3>,values[<NUM_LIT:0>] - <NUM_LIT:1>):<EOL><INDENT>s = lines[j].strip()<EOL>if s == '<STR_LIT>':<EOL><INDENT>break<EOL><DEDENT>fcn += s<EOL><DEDENT><DEDENT>if None not in [values, data, fcn]:<EOL><INDENT>break<EOL><DEDENT><DEDENT>fcn = fcn[:-<NUM_LIT:4>]<EOL>s = fcn.split('<STR_LIT:[>')<EOL>if len(s) > <NUM_LIT:1>:<EOL><INDENT>_bracket = re.compile('<STR_LIT>')<EOL>nfcn = s[<NUM_LIT:0>]<EOL>for si in s[<NUM_LIT:1>:]:<EOL><INDENT>m = _bracket.match(si)<EOL>if m is not None:<EOL><INDENT>si = m.group(<NUM_LIT:1>) + '<STR_LIT:)>' + m.group(<NUM_LIT:2>)<EOL>si = '<STR_LIT:(>' + m.group(<NUM_LIT:1>) + '<STR_LIT:)>' + m.group(<NUM_LIT:2>)<EOL><DEDENT>nfcn += si<EOL><DEDENT>fcn = nfcn<EOL><DEDENT>nparam = values[<NUM_LIT:1>] - values[<NUM_LIT:0>] + <NUM_LIT:1> - <NUM_LIT:5><EOL>pnames = '<STR_LIT:U+002C>'.join(['<STR_LIT:b>' + str(i+<NUM_LIT:1>) for i in range(nparam)])<EOL>p = []<EOL>p0 = []<EOL>prior = []<EOL>for i in range(values[<NUM_LIT:0>] - <NUM_LIT:1>, values[<NUM_LIT:0>] - <NUM_LIT:1> + nparam):<EOL><INDENT>s = lines[i].split()<EOL>p.append(gv.gvar(s[-<NUM_LIT:2>] + '<STR_LIT>' + s[-<NUM_LIT:1>]))<EOL>if USE_2ND_STARTING_VALUE:<EOL><INDENT>p0.append(float(s[<NUM_LIT:3>]))<EOL><DEDENT>else:<EOL><INDENT>p0.append(float(s[<NUM_LIT:2>]))<EOL><DEDENT>prior.append(gv.gvar('<STR_LIT>' + str(<NUM_LIT:200> * p[-<NUM_LIT:1>].mean)))<EOL><DEDENT>p = np.array(p)<EOL>p0 = np.array(p0)<EOL>prior = list(gv.fmt(prior))<EOL>nistp = answers.get(name, str(p))<EOL>s = lines[values[<NUM_LIT:1>] - <NUM_LIT:3>].split()<EOL>yerr = '<STR_LIT>' + s[-<NUM_LIT:1>]<EOL>x = []<EOL>y = []<EOL>for i in range(data[<NUM_LIT:0>] - <NUM_LIT:1>, data[<NUM_LIT:1>]):<EOL><INDENT>s = lines[i].split()<EOL>if len(s) == <NUM_LIT:2>:<EOL><INDENT>x.append(float(s[-<NUM_LIT:1>]))<EOL>y.append(float(s[-<NUM_LIT:2>]))<EOL><DEDENT>elif len(s) > <NUM_LIT:2>:<EOL><INDENT>y.append(float(s[<NUM_LIT:0>]))<EOL>x.append([float(si) for si in s[<NUM_LIT:1>:]])<EOL><DEDENT><DEDENT>x = np.array(x)<EOL>if len(x.shape) > <NUM_LIT:1>:<EOL><INDENT>xnames = '<STR_LIT:U+002C>'.join(['<STR_LIT:x>' + str(i+<NUM_LIT:1>) for i in range(x.shape[<NUM_LIT:1>])])<EOL>x = x.T<EOL><DEDENT>else:<EOL><INDENT>xnames = '<STR_LIT:x>'<EOL><DEDENT>y = np.array(y)<EOL>if len(nistp.split('<STR_LIT:\n>')) > <NUM_LIT:1>:<EOL><INDENT>nistp = '<STR_LIT>'.join(nistp.split('<STR_LIT:\n>'))<EOL><DEDENT>if name == '<STR_LIT>':<EOL><INDENT>fcn = fcn.replace('<STR_LIT>', '<STR_LIT:y>')<EOL>yname = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>yname = '<STR_LIT:y>'<EOL><DEDENT>if name == '<STR_LIT>' and not USE_2ND_STARTING_VALUE:<EOL><INDENT>p0 = gv.sdev(gv.gvar(prior)) / <NUM_LIT><EOL><DEDENT>template =<EOL>{name}():<EOL>print(<NUM_LIT:20> * '<STR_LIT:=>', '<STR_LIT>')<EOL>x = np.{x}<EOL>y = np.{y}<EOL>y = {yname} + gv.gvar(len(y) * ['<STR_LIT>'])<EOL>def fcn(x, b):<EOL><INDENT>{xnames} = x<EOL>{pnames} = b<EOL>{fcn}<EOL>return y<EOL><DEDENT>prior = gv.gvar({prior})<EOL>p0 = np.{p0}<EOL>fit = lsqfit.nonlinear_fit(<EOL>prior=prior, data=(x,y), fcn=fcn, p0=p0, tol=<NUM_LIT>,<EOL>)<EOL>print(fit)<EOL>assert str(fit.p) == '<STR_LIT>'<EOL>return template.format(<EOL>name=name,<EOL>x=repr(x),<EOL>y=repr(y),<EOL>p0=repr(p0),<EOL>yerr=yerr,<EOL>fcn=fcn,<EOL>prior=repr(prior),<EOL>nistp=nistp,<EOL>pnames=pnames,<EOL>xnames=xnames,<EOL>yname=yname,<EOL>)<EOL>
Return the fit-test function corresponding to file ``filename``.