package iterators; import java.io.*; import main.BetterTokenizer; import main.GeneralInput; import main.MoreMath; import parameters.Parameter; import parameters.ParameterSet; import java.util.Vector; import java.util.Enumeration; /** */ public class FindVolumeIterator extends ModelIterator { int numRounds = 2; int numPositionsToTry = 5; float thresholdScore = 0.8f; float precision = 0.05f; public FindVolumeIterator() { setPrint(true); } public ModelIterator copy() throws Exception { FindVolumeIterator newIter = new FindVolumeIterator(); newIter.init(this.network, this.model); newIter.nParsTV = this.nParsTV; newIter.parsTV = this.parsTV.copy(); newIter.theFunction = this.theFunction.copy(); newIter.numRounds = this.numRounds; newIter.thresholdScore = this.thresholdScore; newIter.precision = this.precision; newIter.numPositionsToTry = this.numPositionsToTry; return newIter; } /** Loads parameters specific to this iterator. */ protected void loadParameter(String info, BetterTokenizer tokenizer) throws Exception { if(info.equals("NumRounds")) {GeneralInput.nextToken(tokenizer); numRounds = (int)tokenizer.nval; } else if(info.equals("NumPositionsToTry")) {GeneralInput.nextToken(tokenizer); numPositionsToTry = (int)tokenizer.nval; } else if(info.equals("Threshold")) {GeneralInput.nextToken(tokenizer); thresholdScore = (float)tokenizer.nval; } else if(info.equals("Precision")) {GeneralInput.nextToken(tokenizer); precision = (float)tokenizer.nval; } else super.loadParameter(info, tokenizer); } public void doRun() { int par; reset(); int [] par_order = new int[parsTV.getNumParams()]; float [] longest_dimensions = new float[parsTV.getNumParams()]; for(par = 0; par < parsTV.getNumParams(); par++) { par_order[par] = par; longest_dimensions[par] = 0; } for(int round = 0; round < numRounds; round++) { System.out.println("Round " + round); // MoreMath.randomize(par_order); System.out.println("Parameter " + par_order[0]); MultiFloatReturn ret = IteratorUtilFuncs.findEdgesForParameter(par_order[0], parsTV, p, precision, this); if(ret.f2 - ret.f1 > longest_dimensions[par_order[0]]) longest_dimensions[par_order[0]] = ret.f2 - ret.f1; for(par = 1; par < parsTV.getNumParams(); par++) { System.out.println("Parameter " + par_order[par]); ret = findLongestPosition(par_order[par - 1], ret.f1, ret.f2, par_order[par]); if(ret.f2 - ret.f1 > longest_dimensions[par_order[par]]) longest_dimensions[par_order[par]] = ret.f2 - ret.f1; p[par_order[par-1]] = ret.f3; } } finalScore = 1; for(par = 0; par < parsTV.getNumParams(); par++) { if(parsTV.getVariationMode(par) == Parameter.LINEAR) finalScore *= longest_dimensions[par] / (parsTV.getUpperBound(par) - parsTV.getLowerBound(par)); else { finalScore *= Math.log(longest_dimensions[par]) / (Math.log(parsTV.getUpperBound(par)) - Math.log(parsTV.getLowerBound(par))); } } // Save out the longest dimensions for each parameter for(par = 0; par < parsTV.getNumParams(); par++) { // if(parsTV.getVariationMode(par) == Parameter.LINEAR) // { ps.print(parsTV.getName(par) + "\t" + longest_dimensions[par] + "\t"); ps.println((parsTV.getUpperBound(par) - parsTV.getLowerBound(par))); /* } else { ps.print(parsTV.getName(par) + "\t" + Math.log(longest_dimensions[par]) + "\t"); ps.println(Math.log(parsTV.getUpperBound(par)) - Math.log(parsTV.getLowerBound(par))); } */ } System.out.println("Final score " + finalScore); super.stopRun(); } private MultiFloatReturn findLongestPosition(int guiding_par_num, float guide_min, float guide_max, int search_par_num) { // For now, just pick a certain number of random positions along the guiding parameters axis and return // the one of those with the longest range. float best_val = p[guiding_par_num]; MultiFloatReturn ret = new MultiFloatReturn(p[search_par_num], p[search_par_num]); for(int i = 0; i < numPositionsToTry; i++) { if(parsTV.getVariationMode(guiding_par_num) == Parameter.LINEAR) { p[guiding_par_num] = MoreMath.pickRandomLinear(guide_min, guide_max); } else if(parsTV.getVariationMode(guiding_par_num) == Parameter.LOGARITHMIC) { p[guiding_par_num] = MoreMath.pickRandomLogarithmic(guide_min, guide_max); } MultiFloatReturn ret2 = IteratorUtilFuncs.findEdgesForParameter(search_par_num, parsTV, p, precision, this); if(ret2.f2 - ret2.f1 > ret.f2 - ret.f1) { best_val = p[guiding_par_num]; ret = ret2; } } ret.f3 = best_val; return ret; } }