import java.io.*; import java.util.*; import java.text.DecimalFormat; /// Sets up noisy data pixels, and uses Levenberg-Marquardt to /// fit a 2-D Gaussian: intensity, xcentroid, ycentroid. /// Assumes background is known = 10000 units /pixel. /// Assumes Gaussian RMS breadth is known = 4.00 pixels. /// Iterates with fresh noise to get some statistics on the fitted parms. /// M.Lampton UCB SSL 2006; 2013 interface Constants // includes all constants that are to be shared among classes { final static int NPARMS = 3; // three parms: intensity, x, y. final static int NX = 50; // image width pixels final static int NY = 50; // image height pixels final static int NPTS = NX*NY; } public class Gaus2D implements Constants { final static int NREPS = 9; static double trueparms[] = new double[NPARMS]; static double fittedparms[] = new double[NPARMS]; static double cleandata[] = new double[NPTS]; static double errors[] = new double[NPTS]; static double noisydata[] = new double[NPTS]; static double stats[][] = new double[2][NPARMS]; static double parmerrors[] = new double[NPARMS]; public static void main (String args[]) { showHeader(); setTrueParms(trueparms); showParms("True ", trueparms); setCleanData(trueparms, cleandata); setErrors(cleandata, errors); zeroStats(stats); for (int n=1; n<=NREPS; n++) { setNoisyData(cleandata, errors, noisydata); initParms(trueparms, fittedparms); int niter = solve(fittedparms, noisydata, errors); String title = "Fit "+n; showParmsIter(title, fittedparms, niter); addStats(fittedparms, stats); } finishStats(stats); showParms("Means ", stats[0]); // the parameter means showParms("RMSerr", stats[1]); // the rms errors on the parms. } static void showHeader() { System.out.println(" Signal pix pix niters"); System.out.println(" ----------------------------------------"); } static void setTrueParms(double p[]) { p[0] = 1E4; // total signal p[1] = 22.0; // x centroid, pixels p[2] = 26.5; // y centroid, pixels } static void setCleanData(double p[], double d[]) { for (int i=0; i w) { s = ""; for (int i=0; i0.0) return Math.log(arg)/2.302585092994046; return -999.9; } static double dex(double arg) { if (arg > 300.0) arg = 300.0; if (arg < -300.0) arg = -300.0; return Math.pow(10.0, arg); } static void beep() { char c = 7; String s = ""+c; System.out.print(s); } }