 Timestamp:
 02/17/12 20:34:14 (8 years ago)
 File:

 1 moved
Legend:
 Unmodified
 Added
 Removed

trunk/projects/slimplugin/src/main/java/loci/slim/heuristics/CursorHelper.java
r7875 r7892 33 33 */ 34 34 35 package loci.slim ;35 package loci.slim.heuristics; 36 36 37 37 import loci.curvefitter.CurveFitData; … … 39 39 import loci.curvefitter.ICurveFitter; 40 40 import loci.curvefitter.ICurveFitter.FitAlgorithm; 41 import loci.curvefitter.ICurveFitter.NoiseModel; 41 42 import loci.curvefitter.SLIMCurveFitter; 42 43 … … 53 54 private static final int ATTEMPTS = 10; 54 55 55 public static float[] estimateExcitationCursors(float[] excitation) {56 floatbaseline;57 floatmaxval;56 public static double[] estimateExcitationCursors(double[] excitation) { 57 double baseline; 58 double maxval; 58 59 int index; 59 60 int startp = 0; 60 61 int endp = 0; 61 62 int i; 62 float[] diffed = new float[excitation.length];63 double[] diffed = new double[excitation.length]; 63 64 int steepp; 64 65 … … 117 118 } 118 119 119 float[] returnValue = new float[3];120 double[] returnValue = new double[3]; 120 121 returnValue[0] = startp; 121 122 returnValue[1] = endp; … … 124 125 } 125 126 126 public static int[] estimateDecayCursors( floatxInc, double[] decay) {127 public static int[] estimateDecayCursors(double xInc, double[] decay) { 127 128 int maxIndex = findMax(decay); 128 129 double[] diffed = new double[maxIndex]; … … 147 148 } 148 149 149 public static float[] estimateCursors(float xInc, float[] prompt, double[] decay) {150 float[] returnValue = new float[5];151 floatbaseline;152 float maxval; // TRCursors.c has "unsigned short maxsval, maxval; floatmaxfval, *diffed;"150 public static double[] estimateCursors(double xInc, double[] prompt, double[] decay) { 151 double[] returnValue = new double[5]; 152 double baseline; 153 double maxval; // TRCursors.c has "unsigned short maxsval, maxval; double maxfval, *diffed;" 153 154 int index; 154 155 int startp = 0; … … 157 158 int endt = 0; 158 159 int i; 159 float[] diffed = new float[prompt.length];160 double[] diffed = new double[prompt.length]; 160 161 int steepp; 161 162 int steept; … … 227 228 228 229 // "Differentiate" 229 double[] diffedd = new double[decay.length]; //TODO double vs float issues230 double[] diffedd = new double[decay.length]; 230 231 for (i = 0; i < index; ++i) { 231 232 diffedd[i] = decay[i + 1]  decay[i]; … … 264 265 System.out.println("prompt " + prompt.length + " decay " + decay.length); 265 266 266 //TODO convert everything to float, not double267 double[] response = new double[decay.length];268 for (int n = 0; n < decay.length; ++n) {269 response[n] = decay[index];270 }271 272 267 for (i = 0; i < 2 * ATTEMPTS + 1; ++i, ++transStartIndex) { 273 268 … … 283 278 curveFitData.setParams(param); //TODO param has random values!! 284 279 curveFitData.setYCount(decay); 280 curveFitData.setTransStartIndex(0); 281 curveFitData.setTransFitStartIndex(fitStart); 282 curveFitData.setTransEstimateStartIndex(fitStart); 283 curveFitData.setTransEndIndex(fitStop); 284 285 285 curveFitData.setSig(null); 286 286 curveFitData.setYFitted(yFitted); … … 291 291 curveFitter.setXInc(xInc); 292 292 curveFitter.setFree(free); 293 curveFitter.setInstrumentResponse(response); 294 295 int ret = curveFitter.fitData(data, fitStart, fitStop); 293 curveFitter.setInstrumentResponse(decay); 294 curveFitter.setNoiseModel(NoiseModel.POISSON_DATA); 295 296 int ret = curveFitter.fitData(data); 296 297 297 298 if (ret >= 0) { … … 346 347 * @return 347 348 */ 348 private static float calcBgFromPrepulse(float[] prepulse, int n) {349 floatz = 0.0f;349 private static double calcBgFromPrepulse(double[] prepulse, int n) { 350 double z = 0.0f; 350 351 351 352 if (z > 0) { 352 floatval = 0.0f;353 double val = 0.0f; 353 354 for (int i = 0; i <n; ++i) { 354 355 val += prepulse[i]; … … 357 358 } 358 359 return z; 360 } 361 362 /** 363 * Calculates the start index to use for a triple integral/RLD estimate 364 * fit before a LMA fit. 365 * 366 * Based on expParameterEstimation from TRFitting.c. 367 * 368 * @param trans 369 * @param transFitStartIndex 370 * @param transEndIndex 371 * @return 372 */ 373 public static int getEstimateStartIndex(double[] trans, int transFitStartIndex, int transEndIndex) { 374 int transEstimateStartIndex = transFitStartIndex + findMax(trans, transFitStartIndex, transEndIndex); 375 return transEstimateStartIndex; 359 376 } 360 377 … … 365 382 * @return 366 383 */ 367 public static float[] estimateParameters(boolean useRLD,384 public static double[] estimateParameters(boolean useRLD, 368 385 boolean useBackground, 369 float[] trans,386 double[] trans, 370 387 int transFitStartIndex, 371 388 int transStartIndex, 372 389 int transEndIndex) { 373 floata, t, z;374 375 // initial ize390 double a, t, z; 391 392 // initial guess 376 393 a = 1000.0f; 377 394 t = 2.0f; … … 392 409 } 393 410 394 return new float[] { z, a, t };395 } 396 397 private static int findMax( float[] values) {411 return new double[] { z, a, t }; 412 } 413 414 private static int findMax(double[] values) { 398 415 return findMax(values, 0, values.length); 399 416 } 400 417 401 private static int findMax( float[] values, int endIndex) {418 private static int findMax(double[] values, int endIndex) { 402 419 return findMax(values, 0, endIndex); 403 420 } 404 421 405 private static int findMax( float[] values, int startIndex, int endIndex) {422 private static int findMax(double[] values, int startIndex, int endIndex) { 406 423 int index = startIndex; 407 floatmax = values[startIndex];424 double max = values[startIndex]; 408 425 for (int i = startIndex; i < endIndex; ++i) { 409 426 if (values[i] > max) { … … 415 432 } 416 433 417 private static int findMin( float[] values, int endIndex) {434 private static int findMin(double[] values, int endIndex) { 418 435 return findMin(values, 0, endIndex); 419 436 } 420 437 421 private static int findMin( float[] values, int startIndex, int endIndex) {438 private static int findMin(double[] values, int startIndex, int endIndex) { 422 439 int index = startIndex; 423 floatmin = values[startIndex];440 double min = values[startIndex]; 424 441 for (int i = startIndex; i < endIndex; ++i) { 425 442 if (values[i] < min) { … … 430 447 return index; 431 448 } 432 433 private static int findMax(double[] values) {434 return findMax(values, values.length);435 }436 437 private static int findMax(double[] values, int endIndex) {438 int index = 0;439 double max = 0.0f;440 for (int i = 0; i < endIndex; ++i) {441 if (values[i] > max) {442 max = values[i];443 index = i;444 }445 }446 return index;447 }448 449 private static int findMin(double[] values, int endIndex) {450 int index = 0;451 double min = Double.MAX_VALUE;452 for (int i = 0; i < endIndex; ++i) {453 if (values[i] < min) {454 min = values[i];455 index = i;456 }457 }458 return index;459 }460 449 }
Note: See TracChangeset
for help on using the changeset viewer.