public float[] fitdata( double[] params, int[] fixes1, double[][] constraints, float[] data, float[] weights1, double[] stats) { // this function fits the array data to an arbitrary function denoted by // the NLLSfitinterface // the returned array is the fit // stats returns the chisquared // the weights are set to 1 if weights1 is null // if fixes[i] is zero, the ith parameter is fit, if not, the ith // parameter is fixed // constraints is a 3 by nparams array containing the upper and lower // bounds for each parameter // and the parameter shift for the grid search int nparams = params.length; int npts = data.length; int fitparams = nparams; int[] fixes = new int[nparams]; if (fixes1 != null) { for (int i = 0; i < nparams; i++) { fitparams -= fixes1[i]; fixes[i] = fixes1[i]; } } for (int i = 0; i < nparams; i++) { if (fixes[i] == 0) { if (Math.abs(constraints[1][i] - constraints[0][i]) < constraints[2][i]) { fixes[i] = 1; params[i] = 0.5 * (constraints[0][i] + constraints[1][i]); fitparams--; } } } double[] weights = new double[npts]; if (weights1 == null) { for (int i = 0; i < npts; i++) { weights[i] = 1.0; } } else { for (int i = 0; i < npts; i++) { weights[i] = weights1[i]; } } stats[1] = search_param(0, fitparams, params, fixes, constraints, data, weights); StringBuffer resstring = new StringBuffer(); resstring.append("final minc2 =" + (float) stats[1]); for (int i = 0; i < params.length; i++) { resstring.append(" , " + (float) params[i]); } if (output) { fitclass.showresults(resstring.toString()); } double[] fit = fitclass.fitfunc(params); float[] ffit = new float[fit.length]; for (int i = 0; i < fit.length; i++) { ffit[i] = (float) fit[i]; } return ffit; }
public double calculate_c2_params( double[] params, int numfit, float[] data, double[] weights, boolean[] fitmask) { // this function calculates chisquared using the parameter array double[] tempfit = fitclass.fitfunc(params); return calculate_c2_fit(tempfit, numfit, data, weights, fitmask); }