boolean showoptions(double[] params, int[] fixes) { // GenericDialog gd=new NonBlockingGenericDialog("Options"); GenericDialog gd = new GenericDialog("Options"); gd.addCheckbox("Check Chi Squared", checkc2); for (int i = 0; i < 10; i++) { gd.addNumericField("P" + (i + 1), params[i], 5, 10, null); gd.addCheckbox("Fix?", (fixes[i] == 1)); } gd.addCheckbox("Get_Errors", false); gd.addCheckbox("Set_Constraints", false); gd.addNumericField("Iterations", iterations, 0, 10, null); gd.addNumericField("chi squared", c2, 5, 10, null); gd.addDialogListener(this); gd.showDialog(); if (gd.wasCanceled()) { return false; } checkc2 = gd.getNextBoolean(); for (int i = 0; i < 10; i++) { params[i] = gd.getNextNumber(); if (gd.getNextBoolean()) { fixes[i] = 1; } else { fixes[i] = 0; } } boolean geterrors = gd.getNextBoolean(); boolean setconstraints = gd.getNextBoolean(); for (int i = 0; i < 10; i++) { if (function.indexOf("P" + (i + 1)) < 0) { fixes[i] = 1; } } if (geterrors) { if (!get_errors(params, fixes)) { return false; } } if (setconstraints) constraints = get_constraints(params); return true; }
public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) { checkc2 = gd.getNextBoolean(); double[] params = new double[10]; int[] fixes = new int[10]; for (int i = 0; i < params.length; i++) { params[i] = gd.getNextNumber(); if (gd.getNextBoolean()) { fixes[i] = 1; } else { fixes[i] = 0; } } gd.getNextBoolean(); gd.getNextNumber(); gd.getNextNumber(); NLLSfit_v2 fitclass = new NLLSfit_v2(this, 0); double[] stats = new double[2]; float[] fit = fitclass.fitdata(params, fixes, null, tempdata, null, stats, true); pw.updateSeries(fit, series, false); c2 = (float) stats[1]; return true; }
boolean init_functions() { GenericDialog gd = new GenericDialog("Fitting Options"); gd.addStringField("Extra Definitions", exdef, 50); gd.addCheckbox("Weight Using Plot Errors", false); gd.addStringField("Weighting Equation (y is for data)", weightfunction, 50); gd.addStringField("Fit_Equation", function, 50); gd.showDialog(); if (gd.wasCanceled()) { return false; } exdef = gd.getNextString(); boolean errweights = gd.getNextBoolean(); weightfunction = gd.getNextString(); function = gd.getNextString(); // first initialize the weights weights = new float[tempdata.length]; if (errweights || weightfunction.equals("") || weightfunction == null || weightfunction == "1.0") { if (errweights) { for (int i = 0; i < tempdata.length; i++) weights[i] = 1.0f / (errs[i] * errs[i]); } else { for (int i = 0; i < tempdata.length; i++) weights[i] = 1.0f; } } else { for (int i = 0; i < tempdata.length; i++) { String script = "y =" + tempdata[i] + "; " + "x =" + tempx[i] + "; " + "retval=" + weightfunction + ";"; Double temp = new Double(0.0); try { temp = (Double) engine.eval(script); } catch (Exception e) { IJ.log(e.getMessage()); } if (!(temp.isInfinite() || temp.isNaN())) { weights[i] = temp.floatValue(); } } } // now compile the function script try { String script1 = exdef + "; retval=" + function + ";"; cs = ce.compile(script1); } catch (Exception e) { IJ.log(e.toString()); return false; } return true; }