package stat; import java.awt.*; import java.io.*; import parameters.Parameter; import parameters.ParameterSet; import parameters.ParameterSetArray; import main.MoreMath; /** Saves a parameter set with the minimum and maximum values set to encompass the most common values for each parameter in all the loaded sets. The statistic uses the following algorithm to find those ranges: First it sorts all the values for a parameter from all the parameter sets from lowest to highest. Then it finds the the position that is proportionIncluded along the list (for instance, if proportionIncluded is 0.5 and there are 100 parameter sets then it finds the value at position 50). It stores the ratio of the value at this position divided by the value at position 1. It then moves up one position, and finds the ratio between the two values starting at the new position (ratio of position 51 to position 2 in example). It keeps going till it reaches the end of the list, always storing the smallest ratio found. It then saves out a minimum and maximum corresponding to where that smallest ratio was found - this min and max will then encompass the most concentrated proportionIncluded of the values in the set. If the smallest ratio was below minRestriction, it saves out a minimum value at the minimum value found for the lowest ratio, but a maximum value that is minRestriction times that minimum value (thus, the range is never less than minRestriction). If the smallest ratio is more than maxRestriction, it saves out the full original range with no restriction.

Blech. It might be easier just to read the code. This needs some work, anyway. */ public class ParamTendenciesStat extends Stat implements Runnable, MoreMath.Comparer { public ParamTendenciesStat() {} float minRestriction = 10, maxRestriction = 50, proportionIncluded = 0.5f; public void calculateStat() { int i, j, k, l; String [] largest_names = new String[10]; float [] largest_values = new float[10]; for(k = 0; k < 10; k++) largest_values[k] = 0; if(paramSets == null) { System.out.println("No Cam loaded - Stat did nothing"); return; } FileDialog fd = new FileDialog(new Frame(), "Save into file:", FileDialog.SAVE); fd.show(); if(fd.getFile() == null) return; try { PrintWriter ps = new PrintWriter(new FileOutputStream(fd.getDirectory() + fd.getFile())); double [] mat = makeParameterMatrix(); if(mat == null) { System.out.println("Problem making matrix of parameters"); ps.close(); return; } if(numSets < 2) { System.out.println("You need at least two sets of parameters in the cam in order to find tendencies"); ps.close(); return; } int num_param_sets = mat.length / prototype.getNumParams(); int num_params = prototype.getNumParams(); Float [] param_array = new Float[num_param_sets]; for(int param_num = 0; param_num < num_params; param_num++) { ps.print("&" + prototype.getName(param_num) + "\t" + mat[param_num] + "\t"); // Print the param label and an initial value for(j = 0; j < num_param_sets; j++) param_array[j] = new Float(mat[j * num_params + param_num]); MoreMath.sort(param_array, this); int target_num_values = Math.round(proportionIncluded * num_param_sets); int low_end = 0; float restrict_span = param_array[low_end + target_num_values - 1].floatValue() / param_array[low_end].floatValue(); int best_low_end = 0; float best_span = restrict_span; low_end++; while(low_end < num_param_sets - target_num_values) { restrict_span = param_array[low_end + target_num_values - 1].floatValue() / param_array[low_end].floatValue(); if(restrict_span < best_span) { best_span = restrict_span; best_low_end = low_end; } low_end++; } if(best_span > maxRestriction) { ps.print(prototype.getLowerBound(param_num) + "\t" + prototype.getUpperBound(param_num)); System.out.println(prototype.getName(param_num) + " No Restriction"); } else if(best_span < minRestriction) { if(param_array[best_low_end].floatValue() * minRestriction > prototype.getUpperBound(param_num)) ps.print((prototype.getUpperBound(param_num) / minRestriction) + "\t" + prototype.getUpperBound(param_num)); else ps.print(param_array[best_low_end].floatValue() + "\t" + param_array[best_low_end].floatValue() * minRestriction); System.out.println(prototype.getName(param_num) + " Min Restriction"); } else { ps.print(param_array[best_low_end].floatValue() + "\t" + param_array[best_low_end + target_num_values].floatValue()); System.out.println(prototype.getName(param_num) + " Restriction"); } if(prototype.getVariationMode(param_num) == Parameter.LINEAR) ps.println("\t" + "Linear"); else ps.println("\t" + "Logarithmic"); } ps.flush(); ps.close(); } catch(Exception e) { System.out.println("Error in ParamTendenciesStat: " + e.toString()); } System.out.println("Parameter tendencies saved"); } public int compare(Object a, Object b) { if( ((Float)a).floatValue() < ((Float)b).floatValue()) return -1; else if( ((Float)a).floatValue() == ((Float)b).floatValue() ) return 0; else return 1; } }