Changeset 2485
 Timestamp:
 03/20/07 12:57:14 (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/loci/apps/slim/SlimPlotter.java
r2479 r2485 806 806 miscRow3.add(scalePanel); 807 807 miscRow3.add(Box.createHorizontalStrut(5)); 808 miscRow3.add(numCurves); 809 miscRow3.add(Box.createHorizontalStrut(5)); 808 810 miscRow3.add(exportData); 809 //miscRow3.add(numCurves);810 811 811 812 JPanel miscPanel = new JPanel(); … … 1156 1157 samps = new float[numChanVis * timeBins]; 1157 1158 maxVal = 0; 1159 float[] maxVals = new float[numChanVis]; 1158 1160 for (int c=0, cc=0; c<channels; c++) { 1159 1161 if (!cVisible[c]) continue; … … 1172 1174 if (doLog) samps[ndx] = (float) Math.log(samps[ndx] + 1); 1173 1175 if (samps[ndx] > maxVal) maxVal = samps[ndx]; 1176 if (samps[ndx] > maxVals[cc]) maxVals[cc] = samps[ndx]; 1174 1177 setProgress(progress, ++p); 1175 1178 if (progress.isCanceled()) plotCanceled = true; … … 1189 1192 for (int c=0; c<channels; c++) Arrays.fill(tau[c], Float.NaN); 1190 1193 ExpFunction func = new ExpFunction(numExp); 1191 float[] params = new float[ 3 * numExp];1194 float[] params = new float[2 * numExp + 1]; 1192 1195 if (numExp == 1) { 1193 params[0] = maxVal;1196 //params[0] = maxVal; 1194 1197 params[1] = picoToBins(1000); 1195 1198 params[2] = 0; 1196 1199 } 1197 1200 else if (numExp == 2) { 1198 params[0] = maxVal / 2;1201 //params[0] = maxVal / 2; 1199 1202 params[1] = picoToBins(800); 1200 params[2] = 0; 1201 params[0] = maxVal / 2; 1202 params[1] = picoToBins(2000); 1203 params[2] = 0; 1204 } 1205 //for (int i=0; i<numExp; i++) { 1206 // // initial guess for (a, b, c) 1207 // int e = 3 * i; 1208 // params[e] = (numExp  i) * maxVal / (numExp + 1); 1209 // params[e + 1] = picoToBins(1000 * (i + 1)); 1210 // params[e + 2] = 0; 1211 //} 1203 //params[2] = maxVal / 2; 1204 params[3] = picoToBins(2000); 1205 params[4] = 0; 1206 } 1212 1207 int num = timeBins  maxPeak; 1213 1208 … … 1224 1219 float[] weights = new float[num]; 1225 1220 Arrays.fill(weights, 1); // no weighting 1226 log("Computing fit parameters: y(t) = a * e^(t/" + TAU + ") + c"); 1221 StringBuffer equation = new StringBuffer(); 1222 equation.append("y(t) = "); 1223 for (int i=0; i<numExp; i++) { 1224 equation.append("a"); 1225 equation.append(i + 1); 1226 equation.append(" * e^(t/"); 1227 equation.append(TAU); 1228 equation.append(i + 1); 1229 equation.append(") + "); 1230 } 1231 equation.append("c"); 1232 log("Computing fit parameters: " + equation.toString()); 1227 1233 for (int c=0, cc=0; c<channels; c++) { 1228 1234 if (!cVisible[c]) { … … 1233 1239 System.arraycopy(samps, timeBins * cc + maxPeak, yVals, 0, num); 1234 1240 LMA lma = null; 1241 for (int i=0; i<numExp; i++) { 1242 int e = 2 * i; 1243 params[e] = maxVals[cc] / numExp; 1244 } 1235 1245 lma = new LMA(func, params, new float[][] {xVals, yVals}, 1236 1246 weights, new JAMAMatrix(params.length, params.length)); 1237 1247 lma.fit(); 1238 1248 log("\t\titerations=" + lma.iterationCount); 1249 // normalize chi2 by the channel's peak value 1250 if (maxVals[cc] != 0) lma.chi2 /= maxVals[cc]; 1251 // scale chi2 by degrees of freedom 1252 lma.chi2 /= num  params.length; 1239 1253 log("\t\tchi2=" + lma.chi2); 1240 1254 for (int i=0; i<numExp; i++) { 1241 int e = 3* i;1242 log("\t\ta" + i+ "=" + lma.parameters[e]);1255 int e = 2 * i; 1256 log("\t\ta" + (i + 1) + "=" + lma.parameters[e]); 1243 1257 tau[c][i] = binsToPico((float) (1 / lma.parameters[e + 1])); 1244 log("\t\t" + TAU + i + "=" + tau[c][i] + " ps"); 1245 log("\t\tc" + i + "=" + lma.parameters[e + 2]); 1258 log("\t\t" + TAU + (i + 1) + "=" + tau[c][i] + " ps"); 1246 1259 } 1260 log("\t\tc=" + lma.parameters[2 * numExp]); 1247 1261 fitResults[c] = lma.parameters; 1248 1262 setProgress(progress, ++p); … … 1337 1351 float sum = 0; 1338 1352 for (int i=0; i<numExp; i++) { 1339 int e = 3* i;1340 sum += (float) (q[e] * Math.exp(q[e + 1] * et) + q[e + 2]);1353 int e = 2 * i; 1354 sum += (float) (q[e] * Math.exp(q[e + 1] * et)); 1341 1355 } 1356 sum += (float) q[2 * numExp]; 1342 1357 fitSamps[ndx] = sum; 1343 1358 residuals[ndx] = samps[ndx]  fitSamps[ndx]; … … 1586 1601 double sum = 0; 1587 1602 for (int i=0; i<numExp; i++) { 1588 int e = 3 * i; 1589 sum += a[e] * Math.exp(a[e + 1] * x) + a[e + 2]; 1590 } 1603 int e = 2 * i; 1604 sum += a[e] * Math.exp(a[e + 1] * x); 1605 } 1606 sum += a[2 * numExp]; 1591 1607 return sum; 1592 1608 } 1593 1609 1594 1610 public double getPartialDerivate(double x, double[] a, int parameterIndex) { 1595 int e = parameterIndex / 3; 1596 int off = parameterIndex % 3; 1611 if (parameterIndex == 2 * numExp) return 1; // c 1612 int e = parameterIndex / 2; 1613 int off = parameterIndex % 2; 1597 1614 switch (off) { 1598 case 0: return Math.exp(a[e + 1] * x);1599 case 1: return a[e] * x * Math.exp(a[e + 1] * x);1600 case 2: return 1;1601 default:1602 throw new RuntimeException("No such parameter index: " +1603 parameterIndex);1604 }1615 case 0: 1616 return Math.exp(a[e + 1] * x); // a 1617 case 1: 1618 return a[e] * x * Math.exp(a[e + 1] * x); // b 1619 } 1620 throw new RuntimeException("No such parameter index: " + 1621 parameterIndex); 1605 1622 } 1606 1623 }
Note: See TracChangeset
for help on using the changeset viewer.