You can subscribe to this list here.
| 2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(30) |
Oct
(20) |
Nov
(24) |
Dec
(1) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2002 |
Jan
(8) |
Feb
(11) |
Mar
(52) |
Apr
(67) |
May
(10) |
Jun
(1) |
Jul
|
Aug
(1) |
Sep
(8) |
Oct
(6) |
Nov
(91) |
Dec
(51) |
| 2003 |
Jan
(93) |
Feb
(89) |
Mar
(93) |
Apr
(33) |
May
(19) |
Jun
(14) |
Jul
(30) |
Aug
(13) |
Sep
(2) |
Oct
|
Nov
(9) |
Dec
|
| 2004 |
Jan
(42) |
Feb
(3) |
Mar
(23) |
Apr
(13) |
May
(53) |
Jun
(8) |
Jul
|
Aug
(10) |
Sep
(13) |
Oct
(19) |
Nov
(6) |
Dec
|
| 2005 |
Jan
(1) |
Feb
(9) |
Mar
(9) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(25) |
Sep
(1) |
Oct
|
Nov
(9) |
Dec
(3) |
| 2007 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Brendan M. <mc...@us...> - 2007-01-08 22:02:24
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv13703/src/edu/whitman/halfway/util Modified Files: ProcessUtil.java MiscUtil.java CernUtil.java EADoubleFactory1D.java TimingTree.java Log Message: Index: ProcessUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/ProcessUtil.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ProcessUtil.java 11 Nov 2006 02:04:56 -0000 1.6 --- ProcessUtil.java 8 Jan 2007 22:02:12 -0000 1.7 *************** *** 26,30 **** Process proc; try{ ! log.debug("Trying to execute command " + Arrays.asList(command)); proc = Runtime.getRuntime().exec(command, null, workingDir); }catch(IOException e){ --- 26,30 ---- Process proc; try{ ! if(log.isDebugEnabled())log.debug("Trying to execute command " + Arrays.asList(command)); proc = Runtime.getRuntime().exec(command, null, workingDir); }catch(IOException e){ *************** *** 33,37 **** } ! log.debug("Got process object, waiting to return."); if(out != null) { --- 33,37 ---- } ! if(log.isDebugEnabled())log.debug("Got process object, waiting to return."); if(out != null) { Index: MiscUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/MiscUtil.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** MiscUtil.java 28 Nov 2006 20:13:06 -0000 1.26 --- MiscUtil.java 8 Jan 2007 22:02:12 -0000 1.27 *************** *** 168,176 **** indexOfMin = i; } ! // else if(array[i] == minVal){ ! // if(Math.random() < 0.5){ ! // indexOfMin = i; ! // } ! // } } value = minVal; --- 168,176 ---- indexOfMin = i; } ! // else if(array[i] == minVal){ ! // if(Math.random() < 0.5){ ! // indexOfMin = i; ! // } ! // } } value = minVal; *************** *** 225,228 **** --- 225,229 ---- public static double value; public static int arg; + public final static double max(double[] r) { argMax(r); *************** *** 258,279 **** return min; } - public static double distValue = Double.NaN; public static double softValue = Double.NaN; ! ! public static double[] softMaxDistribution(double[] c, double alpha){ //if(alpha > 1.01){ // log.warn("Large alphas make the softmax value a bad approx to max (off by a alpha log(length(c)) factor"); //} double[] e = new double[c.length]; ! // first do hard max and subtract off exponents for // numerical stability double maxOverAlpha = -Double.MAX_VALUE; for (int i = 0; i < c.length; i++) { ! double ei = c[i]/alpha; e[i] = ei; ! if(ei > maxOverAlpha){ maxOverAlpha = ei; } --- 259,279 ---- return min; } public static double distValue = Double.NaN; public static double softValue = Double.NaN; ! ! public static double[] softMaxDistribution(double[] c, double alpha) { //if(alpha > 1.01){ // log.warn("Large alphas make the softmax value a bad approx to max (off by a alpha log(length(c)) factor"); //} double[] e = new double[c.length]; ! // first do hard max and subtract off exponents for // numerical stability double maxOverAlpha = -Double.MAX_VALUE; for (int i = 0; i < c.length; i++) { ! double ei = c[i] / alpha; e[i] = ei; ! if (ei > maxOverAlpha) { maxOverAlpha = ei; } *************** *** 281,286 **** //System.out.println("alpha = " + alpha); //System.out.println("maxOverAlpha = " + maxOverAlpha); ! ! double d=0; for (int i = 0; i < c.length; i++) { e[i] = Math.exp(e[i] - maxOverAlpha); --- 281,286 ---- //System.out.println("alpha = " + alpha); //System.out.println("maxOverAlpha = " + maxOverAlpha); ! ! double d = 0; for (int i = 0; i < c.length; i++) { e[i] = Math.exp(e[i] - maxOverAlpha); *************** *** 288,300 **** } //System.out.println("d = " + d + ", log(d) = " + Math.log(d)); ! ! softValue = alpha*(Math.log(d) + maxOverAlpha); ! if(alpha > 0){ ! double max = alpha*maxOverAlpha; ! assert softValue >= max -1e-10 : String.format("max = %s, softMax = %s", max, softValue); ! assert softValue <= alpha*maxOverAlpha + alpha*Math.log(c.length) + 1e-10; } ! distValue = 0; for (int i = 0; i < c.length; i++) { e[i] = e[i] / d; --- 288,302 ---- } //System.out.println("d = " + d + ", log(d) = " + Math.log(d)); ! ! softValue = alpha * (Math.log(d) + maxOverAlpha); ! if (alpha > 0) { ! double max = alpha * maxOverAlpha; ! assert softValue >= max - 1e-10 : String.format("max = %s, softMax = %s", ! max, softValue); ! assert softValue <= alpha * maxOverAlpha + alpha * Math.log(c.length) ! + 1e-10; } ! distValue = 0; for (int i = 0; i < c.length; i++) { e[i] = e[i] / d; *************** *** 303,382 **** return e; } ! ! public static double dot(double[] v1, double[] v2){ assert v1.length == v2.length; double d = 0; ! for(int i=0; i<v1.length; i++){ ! d += v1[i]*v2[i]; } return d; } ! ! // public static double[] softMinDistribution(double[] c, double alpha){ ! // double[] cp = new double[c.length]; ! // for(int i=0; i<cp.length; i++){ ! // cp[i] = -1.0 * c[i]; ! // } ! // double[] dist = softMaxDistribution(cp, alpha); ! // distValue *= -1.0; ! // return dist; ! // } ! ! public static double[] softMinDistribution(double[] c, double alpha){ //testing a better impl ! ! // double[] dist = softMinDistribution(c, alpha); ! // double td = distValue; ! // double sv = softValue; ! double[] dist2 = softMaxDistribution(c, -alpha); ! // assert MiscUtil.manhattanNorm(dist, dist2) < dist.length * 1e-8 : ! // String.format("%ndist1=%s\ndist2=%s%n", toString(dist), toString(dist2)); ! // assert MiscUtil.equals(td, distValue, 1e-8) : String.format("td1=%s, td2=%s", td, distValue); ! // assert MiscUtil.equals(sv, softValue, 1e-8) : String.format("sv1=%s, sv2=%s", sv, softValue); ! // ! sanityCheckSoftMin(c, alpha, softValue); return dist2; } ! ! private static boolean sanityCheckSoftMin(double[] c, double alpha, double softMin){ double min = min(c); assert softMin <= min + 1e-8; ! assert softMin >= min - alpha*Math.log(c.length) - 1e-10; return true; } ! ! public static double[] hardMaxDistribution(double[] c){ double max = -Double.MAX_VALUE; double maxCount = 0; for (int i = 0; i < c.length; i++) { ! if( c[i] > max){ max = c[i]; maxCount = 1; ! }else if(c[i] == max){ ! maxCount++; ! } } //System.out.println("br: maxCount = " + maxCount); double[] p = new double[c.length]; ! double probEachMax = 1.0/maxCount; for (int i = 0; i < c.length; i++) { ! if(c[i] == max){ p[i] = probEachMax; } ! } distValue = max; assert dot(c, p) == distValue; assert distValue == max(c) : distValue + " " + max(c) + "\n" ! + MiscUtil.toString(c, "%.5g"); return p; } ! /** Returns distribution that puts uniform weight on all indexes * of c corresponding to maximum values. */ ! public static double[] hardMinDistributionUniform(double[] c){ double[] cp = new double[c.length]; ! for(int i=0; i<cp.length; i++){ cp[i] = -1.0 * c[i]; } --- 305,387 ---- return e; } ! ! public static double dot(double[] v1, double[] v2) { assert v1.length == v2.length; double d = 0; ! for (int i = 0; i < v1.length; i++) { ! d += v1[i] * v2[i]; } return d; } ! ! // public static double[] softMinDistribution(double[] c, double alpha){ ! // double[] cp = new double[c.length]; ! // for(int i=0; i<cp.length; i++){ ! // cp[i] = -1.0 * c[i]; ! // } ! // double[] dist = softMaxDistribution(cp, alpha); ! // distValue *= -1.0; ! // return dist; ! // } ! ! public static double[] softMinDistribution(double[] c, double alpha) { //testing a better impl ! ! // double[] dist = softMinDistribution(c, alpha); ! // double td = distValue; ! // double sv = softValue; ! double[] dist2 = softMaxDistribution(c, -alpha); ! // assert MiscUtil.manhattanNorm(dist, dist2) < dist.length * 1e-8 : ! // String.format("%ndist1=%s\ndist2=%s%n", toString(dist), toString(dist2)); ! // assert MiscUtil.equals(td, distValue, 1e-8) : String.format("td1=%s, td2=%s", td, distValue); ! // assert MiscUtil.equals(sv, softValue, 1e-8) : String.format("sv1=%s, sv2=%s", sv, softValue); ! // ! sanityCheckSoftMin(c, alpha, softValue); return dist2; } ! ! private static boolean sanityCheckSoftMin(double[] c, double alpha, ! double softMin) { double min = min(c); assert softMin <= min + 1e-8; ! double lowerBound = min - alpha * Math.log(c.length); ! assert softMin >= lowerBound - 1e-5 : String.format( ! "softMin: %.5f, lower bound: %.5f", softMin, lowerBound); return true; } ! ! public static double[] hardMaxDistribution(double[] c) { double max = -Double.MAX_VALUE; double maxCount = 0; for (int i = 0; i < c.length; i++) { ! if (c[i] > max) { max = c[i]; maxCount = 1; ! } else if (c[i] == max) { ! maxCount++; ! } } //System.out.println("br: maxCount = " + maxCount); double[] p = new double[c.length]; ! double probEachMax = 1.0 / maxCount; for (int i = 0; i < c.length; i++) { ! if (c[i] == max) { p[i] = probEachMax; } ! } distValue = max; assert dot(c, p) == distValue; assert distValue == max(c) : distValue + " " + max(c) + "\n" ! + MiscUtil.toString(c, "%.5g"); return p; } ! /** Returns distribution that puts uniform weight on all indexes * of c corresponding to maximum values. */ ! public static double[] hardMinDistributionUniform(double[] c) { double[] cp = new double[c.length]; ! for (int i = 0; i < cp.length; i++) { cp[i] = -1.0 * c[i]; } *************** *** 386,405 **** return dist; } ! ! public static double[] hardMinDistributionArbitrary(double[] c){ ! double[] p = new double[c.length]; p[argMin(c)] = 1.0; distValue = value; // value set by argMin ! return p; } ! ! public static double[] hardMaxDistributionArbitrary(double[] c){ double[] p = new double[c.length]; p[argMax(c)] = 1.0; distValue = value;//value set by argMax ! return p; } ! ! public static void testDist(double[] c, double alpha){ double min = MiscUtil.min(c); double max = MiscUtil.max(c); --- 391,410 ---- return dist; } ! ! public static double[] hardMinDistributionArbitrary(double[] c) { ! double[] p = new double[c.length]; p[argMin(c)] = 1.0; distValue = value; // value set by argMin ! return p; } ! ! public static double[] hardMaxDistributionArbitrary(double[] c) { double[] p = new double[c.length]; p[argMax(c)] = 1.0; distValue = value;//value set by argMax ! return p; } ! ! public static void testDist(double[] c, double alpha) { double min = MiscUtil.min(c); double max = MiscUtil.max(c); *************** *** 409,449 **** //double[] minDist2 = softMinDistribution2(c, alpha); //double softMin2 = softValue; ! double[] maxDist = softMaxDistribution(c, alpha); double softMax = softValue; ! double minMix = dot(c, minDist); //double minMix2 = dot(c, minDist2); ! double maxMix = dot(c, maxDist); ! ! ! ! System.out.printf( ! "c=%s\t\talpha=%.4g%n"+ ! "\tsoftMaxDist =%s\tmax=%6.4g,\tmix=%6.4g,\tsoft=%6.4g%n" + ! "\tsoftMinDist =%s\tmin=%6.4g,\tmix=%6.4g,\tsoft=%6.4g%n", ! //"\tsoftMinDist2=%s\tmin=%6.4g,\tmix=%6.4g,\tsoft=%6.4g%n", ! MiscUtil.toString(c, "%.3g"), alpha, ! MiscUtil.toString(maxDist, "%.3g"), max, maxMix, softMax, ! MiscUtil.toString(minDist, "%.3g"), min, minMix, softMin ! //MiscUtil.toString(minDist2, "%.3g"), min, minMix2, softMin2 ! ); } ! ! ! ! public static void testSoftDistributions(){ double[][] tests = { { 1, 1, 1 }, { 0.3, 0.8, 1.0 }, { 990, 38, 70 }, { 9, 8.3, 11.3 }, { 0.01, 0.02, 0.015 } }; ! double[] alphas = { 15, 1, 0.1, 0.01, 0.0001 }; for (double[] c : tests) { for (double alpha : alphas) { ! testDist(c, alpha); } System.out.println(); } } - /** assumes rectangular, non-null array*/ --- 414,448 ---- //double[] minDist2 = softMinDistribution2(c, alpha); //double softMin2 = softValue; ! double[] maxDist = softMaxDistribution(c, alpha); double softMax = softValue; ! double minMix = dot(c, minDist); //double minMix2 = dot(c, minDist2); ! double maxMix = dot(c, maxDist); ! ! System.out.printf("c=%s\t\talpha=%.4g%n" ! + "\tsoftMaxDist =%s\tmax=%6.4g,\tmix=%6.4g,\tsoft=%6.4g%n" ! + "\tsoftMinDist =%s\tmin=%6.4g,\tmix=%6.4g,\tsoft=%6.4g%n", ! //"\tsoftMinDist2=%s\tmin=%6.4g,\tmix=%6.4g,\tsoft=%6.4g%n", ! MiscUtil.toString(c, "%.3g"), alpha, MiscUtil.toString(maxDist, ! "%.3g"), max, maxMix, softMax, MiscUtil.toString(minDist, ! "%.3g"), min, minMix, softMin ! //MiscUtil.toString(minDist2, "%.3g"), min, minMix2, softMin2 ! ); } ! ! public static void testSoftDistributions() { double[][] tests = { { 1, 1, 1 }, { 0.3, 0.8, 1.0 }, { 990, 38, 70 }, { 9, 8.3, 11.3 }, { 0.01, 0.02, 0.015 } }; ! double[] alphas = { 15, 1, 0.1, 0.01, 0.0001 }; for (double[] c : tests) { for (double alpha : alphas) { ! testDist(c, alpha); } System.out.println(); } } /** assumes rectangular, non-null array*/ *************** *** 558,562 **** buffer.append(String.format(format, array[i]) + ", "); } ! buffer.append(String.format(format, array[limit-1]) + "]"); } return buffer.toString(); --- 557,561 ---- buffer.append(String.format(format, array[i]) + ", "); } ! buffer.append(String.format(format, array[limit - 1]) + "]"); } return buffer.toString(); *************** *** 975,986 **** if (input[i] < 0) { throw new IllegalArgumentException( ! "Shouldn't be normalizing an input vector with negative entry."); } output[i] = input[i] / sum; } return output; - } /** Does a linear transformation on d so the min element of d maps * to a and the maximum element of d maps to b. returns a copy. --- 974,992 ---- if (input[i] < 0) { throw new IllegalArgumentException( ! "Shouldn't be normalizing an input vector with negative entry: " ! + input[i]); } output[i] = input[i] / sum; } return output; } + public static final void makeNonNegative(double[] input){ + int n = input.length; + for(int i=0; i<n; i++){ + if(input[i] < 0) input[i] = 0; + } + } + /** Does a linear transformation on d so the min element of d maps * to a and the maximum element of d maps to b. returns a copy. Index: CernUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/CernUtil.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** CernUtil.java 20 Nov 2006 19:52:24 -0000 1.13 --- CernUtil.java 8 Jan 2007 22:02:12 -0000 1.14 *************** *** 35,38 **** --- 35,40 ---- + + public static final String densityStatString(String prefix, DoubleMatrix1D vector, double approxThresh){ Index: EADoubleFactory1D.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/EADoubleFactory1D.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EADoubleFactory1D.java 12 Jan 2004 20:06:43 -0000 1.2 --- EADoubleFactory1D.java 8 Jan 2007 22:02:12 -0000 1.3 *************** *** 1,3 **** --- 1,4 ---- package edu.whitman.halfway.util; + // import cern.colt.function.DoubleDoubleFunction; import cern.colt.matrix.*; *************** *** 6,67 **** // import cern.colt.list.DoubleArrayList; - import org.apache.log4j.Logger; - /** This is a dense factory that returns ElementAccessDenseDoubleMatrix1D's*/ ! public class EADoubleFactory1D extends DoubleFactory1D{ static Logger log = Logger.getLogger(EADoubleFactory1D.class); ! public DoubleMatrix1D make(DoubleMatrix2D m) { ! if(!(m instanceof EADoubleFactory2D.ElementAccessDenseDoubleMatrix2D)){ ! log.warn("Slow..."); ! m = (CernUtil.dense2D.make(m.rows(), m.columns())).assign(m); ! ! } ! return new ElementAccessDenseDoubleMatrix1D ! ( ((EADoubleFactory2D.ElementAccessDenseDoubleMatrix2D)m).getElements()); ! } ! ! - public DoubleMatrix1D make(int size) { - return new ElementAccessDenseDoubleMatrix1D(size); } ! public DoubleMatrix1D make(double[] values) { ! return new ElementAccessDenseDoubleMatrix1D(values); ! } ! public static class ElementAccessDenseDoubleMatrix1D ! extends DenseDoubleMatrix1D{ ! protected ElementAccessDenseDoubleMatrix1D(int size, double[] elements, int zero, int stride) { ! super(size, elements, zero, stride); ! } ! /** elements is packed in row-major */ ! public ElementAccessDenseDoubleMatrix1D(int size){ ! super(size); ! } ! /** elements is packed in row-major */ ! public ElementAccessDenseDoubleMatrix1D(double[] elements){ ! super(elements.length, elements, 0, 1); ! } ! ! public double[] getElements(){ ! return elements; ! } ! public DoubleMatrix1D like(int size){ ! return new ElementAccessDenseDoubleMatrix1D(size); ! } ! public DoubleMatrix2D like2D(int rows, int columns){ ! return new EADoubleFactory2D.ElementAccessDenseDoubleMatrix2D(rows, columns); ! } } } --- 7,66 ---- // import cern.colt.list.DoubleArrayList; import org.apache.log4j.Logger; /** This is a dense factory that returns ElementAccessDenseDoubleMatrix1D's*/ ! public class EADoubleFactory1D extends DoubleFactory1D { static Logger log = Logger.getLogger(EADoubleFactory1D.class); ! public DoubleMatrix1D make(DoubleMatrix2D m) { ! if (!(m instanceof EADoubleFactory2D.ElementAccessDenseDoubleMatrix2D)) { ! log.warn("Slow..."); ! m = (CernUtil.dense2D.make(m.rows(), m.columns())).assign(m); } + return new ElementAccessDenseDoubleMatrix1D( + ((EADoubleFactory2D.ElementAccessDenseDoubleMatrix2D) m) + .getElements()); + } ! public DoubleMatrix1D make(int size) { ! return new ElementAccessDenseDoubleMatrix1D(size); ! } + public DoubleMatrix1D make(double[] values) { + return new ElementAccessDenseDoubleMatrix1D(values); + } ! public static class ElementAccessDenseDoubleMatrix1D extends ! DenseDoubleMatrix1D { ! protected ElementAccessDenseDoubleMatrix1D(int size, double[] elements, ! int zero, int stride) { ! super(size, elements, zero, stride); ! } ! /** elements is packed in row-major */ ! public ElementAccessDenseDoubleMatrix1D(int size) { ! super(size); ! } ! /** elements is packed in row-major */ ! public ElementAccessDenseDoubleMatrix1D(double[] elements) { ! super(elements.length, elements, 0, 1); ! } ! public double[] getElements() { ! return elements; ! } ! public DoubleMatrix1D like(int size) { ! return new ElementAccessDenseDoubleMatrix1D(size); ! } + public DoubleMatrix2D like2D(int rows, int columns) { + return new EADoubleFactory2D.ElementAccessDenseDoubleMatrix2D(rows, + columns); } + + } } Index: TimingTree.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/TimingTree.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TimingTree.java 19 Nov 2006 22:24:09 -0000 1.3 --- TimingTree.java 8 Jan 2007 22:02:12 -0000 1.4 *************** *** 18,21 **** --- 18,25 ---- protected Node root = null; protected Node activeNode = null; + + // the time of the last event timed (e.g., time between last start("name") and + // stopAndPop(). + private long lastTime; /** Creates and starts the root timer */ *************** *** 98,105 **** --- 102,114 ---- String stoppedName = activeNode.name; activeNode.timer.stop(); + lastTime = activeNode.timer.getLastEventTime(); activeNode = activeNode.parent; return stoppedName; } + public String lastEventTimeString(){ + return StringUtil.formatMillis(lastTime); + } + public String stopAndPop(String name){ if(!name.equals(activeNode.name)){ |
|
From: Brendan M. <mc...@us...> - 2006-12-04 21:06:52
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv14849/src/edu/whitman/halfway/util Modified Files: SequenceStats.java Log Message: Index: SequenceStats.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/SequenceStats.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SequenceStats.java 12 Jan 2004 20:06:43 -0000 1.2 --- SequenceStats.java 4 Dec 2006 21:06:47 -0000 1.3 *************** *** 8,57 **** /** A utility for keeping track of the min, max, and average of a * sequence of numbers, presented one at a time.*/ ! public final class SequenceStats{ ! int crntIndex; ! ! double min = Double.MAX_VALUE; ! int minIndex = -1; ! int minCount=0; //how many times this min occurred ! double max = -Double.MAX_VALUE; ! int maxIndex = -1; ! int maxCount=0; ! double sum = 0; ! public void show(double v){ ! sum += v; ! if(v > max){ ! max = v; ! maxIndex = crntIndex; ! maxCount = 1; ! }else if(v == max){ ! maxCount++; ! } ! if(v < min){ ! min = v; ! minIndex = crntIndex; ! minCount = 1; ! }else if(v == min){ ! minCount++; ! } ! crntIndex++; } - public String getStatString(){ - if(crntIndex == 0) - throw new IllegalArgumentException("Must put at least one number first."); - StringBuffer buf = new StringBuffer(); - buf.append("Mean of ").append(sum/(double)crntIndex).append(" from ").append(crntIndex).append(" values in range["); - buf.append(min).append(", ").append(max).append("]."); - buf.append(StringUtil.newline).append("Min occurred ").append(minCount).append(" times, "); - buf.append("Max occurred ").append(maxCount).append(" times."); - return buf.toString(); - } --- 8,80 ---- /** A utility for keeping track of the min, max, and average of a * sequence of numbers, presented one at a time.*/ ! public final class SequenceStats { ! int crntIndex; ! double min = Double.MAX_VALUE; ! int minIndex = -1; ! int minCount = 0; //how many times this min occurred ! double max = -Double.MAX_VALUE; ! int maxIndex = -1; ! int maxCount = 0; ! double sum = 0; ! public void show(double v) { ! sum += v; ! if (v > max) { ! max = v; ! maxIndex = crntIndex; ! maxCount = 1; ! } else if (v == max) { ! maxCount++; ! } ! if (v < min) { ! min = v; ! minIndex = crntIndex; ! minCount = 1; ! } else if (v == min) { ! minCount++; } + crntIndex++; + } + + public double getMax() { + return max; + } + + + public double getMin() { + return min; + } + + + public double getSum() { + return sum; + } + + public double getAverage() { + return sum/((double)crntIndex); + } + + + public String getStatString() { + if (crntIndex == 0) + throw new IllegalArgumentException("Must put at least one number first."); + + StringBuffer buf = new StringBuffer(); + buf.append("Mean of ").append(sum / (double) crntIndex).append(" from ") + .append(crntIndex).append(" values in range["); + buf.append(min).append(", ").append(max).append("]."); + buf.append(StringUtil.newline).append("Min occurred ").append(minCount) + .append(" times, "); + buf.append("Max occurred ").append(maxCount).append(" times."); + return buf.toString(); + + } |
|
From: Brent B. <bre...@us...> - 2006-12-01 15:45:17
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31180/src/edu/whitman/halfway/util Modified Files: PropProvider.java Log Message: Index: PropProvider.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/PropProvider.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PropProvider.java 28 Nov 2006 20:00:57 -0000 1.8 --- PropProvider.java 1 Dec 2006 15:45:13 -0000 1.9 *************** *** 164,166 **** return true; } ! } --- 164,166 ---- return true; } ! } \ No newline at end of file |
|
From: Brent B. <bre...@us...> - 2006-12-01 15:45:16
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/bcomponent In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31180/src/edu/whitman/halfway/bcomponent Modified Files: BToolBarTest.java Log Message: Index: BToolBarTest.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/bcomponent/BToolBarTest.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** BToolBarTest.java 22 Feb 2003 23:20:20 -0000 1.1.1.1 --- BToolBarTest.java 1 Dec 2006 15:45:13 -0000 1.2 *************** *** 8,35 **** public class BToolBarTest extends JFrame{ public BToolBarTest() { ! addWindowListener(new WindowAdapter() { ! public void windowClosing(WindowEvent e) {System.exit(0);} ! }); ! ! Container contentPane = getContentPane(); ! contentPane.setLayout(new BorderLayout()); ! JLabel l = new JLabel("Stuff"); ! contentPane.add(l, BorderLayout.CENTER); ! ! // Add toolbar ! BToolBar t = new BToolBar(); ! t.add(new BButton("One", new ImageIcon("../JigSpace/icons/Add16.gif"), new ImageIcon("../JigSpace/icons/Add24.gif"))); ! ! t.add(new BButton("One", new ImageIcon("../JigSpace/icons/Edit16.gif"), new ImageIcon("../JigSpace/icons/Edit24.gif"))); ! ! t.add(new BButton("One", new ImageIcon("../JigSpace/icons/Save16.gif"), new ImageIcon("../JigSpace/icons/Save24.gif"))); ! ! contentPane.add(t, BorderLayout.NORTH); } public static void main(String[] args) { ! BToolBarTest bt = new BToolBarTest(); ! bt.pack(); ! bt.show(); } } --- 8,35 ---- public class BToolBarTest extends JFrame{ public BToolBarTest() { ! addWindowListener(new WindowAdapter() { ! public void windowClosing(WindowEvent e) {System.exit(0);} ! }); ! ! Container contentPane = getContentPane(); ! contentPane.setLayout(new BorderLayout()); ! JLabel l = new JLabel("Stuff"); ! contentPane.add(l, BorderLayout.CENTER); ! ! // Add toolbar ! BToolBar t = new BToolBar(); ! t.add(new BButton("One", new ImageIcon("../JigSpace/icons/Add16.gif"), new ImageIcon("../JigSpace/icons/Add24.gif"))); ! ! t.add(new BButton("One", new ImageIcon("../JigSpace/icons/Edit16.gif"), new ImageIcon("../JigSpace/icons/Edit24.gif"))); ! ! t.add(new BButton("One", new ImageIcon("../JigSpace/icons/Save16.gif"), new ImageIcon("../JigSpace/icons/Save24.gif"))); ! ! contentPane.add(t, BorderLayout.NORTH); } public static void main(String[] args) { ! BToolBarTest bt = new BToolBarTest(); ! bt.pack(); ! bt.show(); } } |
|
From: Brendan M. <mc...@us...> - 2006-11-28 20:13:11
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26627/src/edu/whitman/halfway/util Modified Files: MiscUtil.java ExecutionTimer.java Log Message: Index: MiscUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/MiscUtil.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** MiscUtil.java 11 Nov 2006 02:04:56 -0000 1.25 --- MiscUtil.java 28 Nov 2006 20:13:06 -0000 1.26 *************** *** 261,287 **** public static double distValue = Double.NaN; public static double[] softMaxDistribution(double[] c, double alpha){ double[] e = new double[c.length]; ! ! // first do hard max and subtract of exponents for ! // numerical stability ! double max = MiscUtil.max(c); double d=0; for (int i = 0; i < c.length; i++) { ! e[i] = Math.exp((c[i] - max) / alpha); d += e[i]; } ! //the softMax value, not currently needed ! //double softMax = alpha * Math.log(d) + max; ! distValue = 0; //not needed currently ! double[] p = new double[c.length]; for (int i = 0; i < c.length; i++) { ! p[i] = e[i] / d; ! distValue += p[i] * c[i]; } ! return p; } --- 261,305 ---- public static double distValue = Double.NaN; + public static double softValue = Double.NaN; public static double[] softMaxDistribution(double[] c, double alpha){ + //if(alpha > 1.01){ + // log.warn("Large alphas make the softmax value a bad approx to max (off by a alpha log(length(c)) factor"); + //} double[] e = new double[c.length]; ! ! // first do hard max and subtract off exponents for ! // numerical stability ! double maxOverAlpha = -Double.MAX_VALUE; ! for (int i = 0; i < c.length; i++) { ! double ei = c[i]/alpha; ! e[i] = ei; ! if(ei > maxOverAlpha){ ! maxOverAlpha = ei; ! } ! } ! //System.out.println("alpha = " + alpha); ! //System.out.println("maxOverAlpha = " + maxOverAlpha); ! double d=0; for (int i = 0; i < c.length; i++) { ! e[i] = Math.exp(e[i] - maxOverAlpha); d += e[i]; } + //System.out.println("d = " + d + ", log(d) = " + Math.log(d)); ! softValue = alpha*(Math.log(d) + maxOverAlpha); ! if(alpha > 0){ ! double max = alpha*maxOverAlpha; ! assert softValue >= max -1e-10 : String.format("max = %s, softMax = %s", max, softValue); ! assert softValue <= alpha*maxOverAlpha + alpha*Math.log(c.length) + 1e-10; ! } ! distValue = 0; for (int i = 0; i < c.length; i++) { ! e[i] = e[i] / d; ! distValue += e[i] * c[i]; } ! return e; } *************** *** 295,308 **** } ! public static double[] softMinDistribution(double[] c, double alpha){ ! double[] cp = new double[c.length]; ! for(int i=0; i<cp.length; i++){ ! cp[i] = -1.0 * c[i]; ! } ! double[] dist = softMaxDistribution(cp, alpha); ! distValue *= -1.0; ! return dist; } public static double[] hardMaxDistribution(double[] c){ double max = -Double.MAX_VALUE; --- 313,351 ---- } ! // public static double[] softMinDistribution(double[] c, double alpha){ ! // double[] cp = new double[c.length]; ! // for(int i=0; i<cp.length; i++){ ! // cp[i] = -1.0 * c[i]; ! // } ! // double[] dist = softMaxDistribution(cp, alpha); ! // distValue *= -1.0; ! // return dist; ! // } ! ! public static double[] softMinDistribution(double[] c, double alpha){ ! //testing a better impl ! ! // double[] dist = softMinDistribution(c, alpha); ! // double td = distValue; ! // double sv = softValue; ! ! double[] dist2 = softMaxDistribution(c, -alpha); ! // assert MiscUtil.manhattanNorm(dist, dist2) < dist.length * 1e-8 : ! // String.format("%ndist1=%s\ndist2=%s%n", toString(dist), toString(dist2)); ! // assert MiscUtil.equals(td, distValue, 1e-8) : String.format("td1=%s, td2=%s", td, distValue); ! // assert MiscUtil.equals(sv, softValue, 1e-8) : String.format("sv1=%s, sv2=%s", sv, softValue); ! // ! ! sanityCheckSoftMin(c, alpha, softValue); ! return dist2; } + private static boolean sanityCheckSoftMin(double[] c, double alpha, double softMin){ + double min = min(c); + assert softMin <= min + 1e-8; + assert softMin >= min - alpha*Math.log(c.length) - 1e-10; + return true; + } + public static double[] hardMaxDistribution(double[] c){ double max = -Double.MAX_VALUE; *************** *** 362,377 **** double max = MiscUtil.max(c); double[] minDist = softMinDistribution(c, alpha); double[] maxDist = softMaxDistribution(c, alpha); double minMix = dot(c, minDist); double maxMix = dot(c, maxDist); System.out.printf( "c=%s\t\talpha=%.4g%n"+ ! "\tsoftMaxDist=%s\tmax=%6.4g,\tmix=%6.4g%n" + ! "\tsoftMinDist=%s\tmin=%6.4g,\tmix=%6.4g%n", MiscUtil.toString(c, "%.3g"), alpha, ! MiscUtil.toString(maxDist, "%.3g"), max, maxMix, ! MiscUtil.toString(minDist, "%.3g"), min, minMix ); } --- 405,432 ---- double max = MiscUtil.max(c); double[] minDist = softMinDistribution(c, alpha); + double softMin = softValue; + + //double[] minDist2 = softMinDistribution2(c, alpha); + //double softMin2 = softValue; + double[] maxDist = softMaxDistribution(c, alpha); + double softMax = softValue; double minMix = dot(c, minDist); + //double minMix2 = dot(c, minDist2); + double maxMix = dot(c, maxDist); + + System.out.printf( "c=%s\t\talpha=%.4g%n"+ ! "\tsoftMaxDist =%s\tmax=%6.4g,\tmix=%6.4g,\tsoft=%6.4g%n" + ! "\tsoftMinDist =%s\tmin=%6.4g,\tmix=%6.4g,\tsoft=%6.4g%n", ! //"\tsoftMinDist2=%s\tmin=%6.4g,\tmix=%6.4g,\tsoft=%6.4g%n", MiscUtil.toString(c, "%.3g"), alpha, ! MiscUtil.toString(maxDist, "%.3g"), max, maxMix, softMax, ! MiscUtil.toString(minDist, "%.3g"), min, minMix, softMin ! //MiscUtil.toString(minDist2, "%.3g"), min, minMix2, softMin2 ); } *************** *** 382,386 **** double[][] tests = { { 1, 1, 1 }, { 0.3, 0.8, 1.0 }, { 990, 38, 70 }, { 9, 8.3, 11.3 }, { 0.01, 0.02, 0.015 } }; ! double[] alphas = { 10000, 100, 10, 1, 0.1, 0.01, 0.0001 }; for (double[] c : tests) { for (double alpha : alphas) { --- 437,441 ---- double[][] tests = { { 1, 1, 1 }, { 0.3, 0.8, 1.0 }, { 990, 38, 70 }, { 9, 8.3, 11.3 }, { 0.01, 0.02, 0.015 } }; ! double[] alphas = { 15, 1, 0.1, 0.01, 0.0001 }; for (double[] c : tests) { for (double alpha : alphas) { Index: ExecutionTimer.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/ExecutionTimer.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ExecutionTimer.java 19 Nov 2006 22:24:09 -0000 1.5 --- ExecutionTimer.java 28 Nov 2006 20:13:06 -0000 1.6 *************** *** 131,134 **** --- 131,138 ---- } + public String toMicroString(){ + return formatNanoTime(getElapsedTimeNano()); + } + public static String formatTime(long ms) { return formatMicroTime(ms*1000); |
|
From: Brent B. <bre...@us...> - 2006-11-28 20:01:33
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21653/src/edu/whitman/halfway/util Modified Files: StringUtil.java SlowTranMatrix2D.java TranMatrix2D.java HashTranMatrix2D.java PropProvider.java Log Message: Index: StringUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/StringUtil.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** StringUtil.java 19 Nov 2006 22:24:09 -0000 1.15 --- StringUtil.java 28 Nov 2006 20:00:57 -0000 1.16 *************** *** 366,368 **** } ! } --- 366,376 ---- } ! public static String toString(double[] array) { ! StringBuilder sb = new StringBuilder("["); ! for (Object t : array) { ! sb.append(t+", "); ! } ! sb.setCharAt(sb.length()-1, ']'); ! return sb.toString(); ! } ! } \ No newline at end of file Index: SlowTranMatrix2D.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/SlowTranMatrix2D.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SlowTranMatrix2D.java 7 Nov 2004 00:57:17 -0000 1.1 --- SlowTranMatrix2D.java 28 Nov 2006 20:00:57 -0000 1.2 *************** *** 2,12 **** - import cern.colt.list.*; import cern.colt.matrix.*; import cern.colt.matrix.impl.*; - import cern.colt.map.*; - import cern.colt.matrix.linalg.Algebra; - import cern.colt.bitvector.*; - import cern.colt.function.IntDoubleProcedure; import org.apache.log4j.Logger; import cern.colt.function.IntDoubleFunction; --- 2,7 ---- Index: TranMatrix2D.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/TranMatrix2D.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TranMatrix2D.java 27 Oct 2004 19:00:44 -0000 1.3 --- TranMatrix2D.java 28 Nov 2006 20:00:57 -0000 1.4 *************** *** 3,13 **** //import cern.colt.list.*; ! import cern.colt.matrix.*; ! import cern.colt.matrix.impl.*; ! import cern.colt.map.*; //import cern.colt.matrix.linalg.Algebra; //import cern.colt.bitvector.*; //import cern.colt.function.IntDoubleProcedure; ! import org.apache.log4j.Logger; import cern.colt.function.IntDoubleFunction; --- 3,13 ---- //import cern.colt.list.*; ! //import cern.colt.matrix.*; ! //import cern.colt.matrix.impl.*; ! //import cern.colt.map.*; //import cern.colt.matrix.linalg.Algebra; //import cern.colt.bitvector.*; //import cern.colt.function.IntDoubleProcedure; ! //import org.apache.log4j.Logger; import cern.colt.function.IntDoubleFunction; Index: HashTranMatrix2D.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/HashTranMatrix2D.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** HashTranMatrix2D.java 7 Nov 2004 00:57:17 -0000 1.1 --- HashTranMatrix2D.java 28 Nov 2006 20:00:57 -0000 1.2 *************** *** 6,15 **** import cern.colt.matrix.impl.*; import cern.colt.map.*; - import cern.colt.matrix.linalg.Algebra; - import cern.colt.bitvector.*; - import cern.colt.function.IntDoubleProcedure; import org.apache.log4j.Logger; import cern.colt.function.IntDoubleFunction; - import cern.colt.function.IntProcedure; public class HashTranMatrix2D extends SparseDoubleMatrix2D --- 6,11 ---- Index: PropProvider.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/PropProvider.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PropProvider.java 20 Nov 2006 19:52:24 -0000 1.7 --- PropProvider.java 28 Nov 2006 20:00:57 -0000 1.8 *************** *** 1,8 **** package edu.whitman.halfway.util; - import java.util.*; - import org.apache.log4j.Logger; - import java.lang.reflect.*; import java.io.*; public class PropProvider { --- 1,11 ---- package edu.whitman.halfway.util; import java.io.*; + import java.lang.reflect.Field; + import java.lang.reflect.Modifier; + import java.util.Properties; + import java.util.Map.Entry; + + import org.apache.log4j.Logger; public class PropProvider { *************** *** 17,20 **** --- 20,54 ---- } + public String getFormattedString() { + return getFormattedString(""); + } + public String getFormattedString(String prefix) { + StringBuilder sb = new StringBuilder(); + Properties props = getProps(); + + int maxKeyLength = 0; + + for (Object key : props.keySet()) { + int length = key.toString().length(); + if (length > maxKeyLength) { + maxKeyLength = length; + } + } + maxKeyLength +=2; + + for (Entry entry : props.entrySet()) { + sb.append(prefix); + String key = entry.getKey().toString(); + sb.append(key+":"); + + for (int i=key.length(); i<maxKeyLength; i++) { + sb.append(" "); + } + sb.append(entry.getValue().toString()); + sb.append(StringUtil.newline); + } + return sb.toString(); + } + public Properties getProps(String prefix) { Class cl = getClass(); *************** *** 25,35 **** if (!Modifier.isStatic(mods) && !Modifier.isTransient(mods)) { try { - Object fldValue = fields[i].get(this); String s; if (fldValue == null) { s = "null"; } else { ! s = fldValue.toString(); } props.setProperty(fields[i].getName(), s); --- 59,79 ---- if (!Modifier.isStatic(mods) && !Modifier.isTransient(mods)) { try { Object fldValue = fields[i].get(this); String s; + if (fldValue == null) { s = "null"; + + } else if (fldValue.getClass().isArray()) { + if (fldValue.getClass().getComponentType() == Double.TYPE) { + double[] array = (double[])fldValue; + s = StringUtil.toString(array); + } else { + log.warn("Array Elements Not Converted to String."); + s = fldValue.toString(); + } + } else { ! s = fldValue.toString(); } props.setProperty(fields[i].getName(), s); |
|
From: Brendan M. <mc...@us...> - 2006-11-20 19:52:59
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26959/src/edu/whitman/halfway/util Modified Files: PropProvider.java CernUtil.java Log Message: Index: PropProvider.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/PropProvider.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PropProvider.java 11 Nov 2006 02:04:56 -0000 1.6 --- PropProvider.java 20 Nov 2006 19:52:24 -0000 1.7 *************** *** 6,104 **** import java.io.*; ! public class PropProvider{ ! static Logger log = Logger.getLogger(PropProvider.class.getName()); ! public String toString(){ ! return getProps().toString(); ! } ! ! public Properties getProps(){ ! return getProps(""); ! } ! public Properties getProps(String prefix){ ! Class cl = getClass(); ! Field[] fields = cl.getDeclaredFields(); ! Properties props = new Properties(); ! for(int i=0; i< fields.length; i++){ ! int mods = fields[i].getModifiers(); ! if(!Modifier.isStatic(mods) && !Modifier.isTransient(mods)){ ! try{ ! ! Object fldValue = fields[i].get(this); ! String s; ! if(fldValue == null){ ! s = "null"; ! }else{ ! s = fldValue.toString(); ! } ! props.setProperty(fields[i].getName(), s); ! }catch(IllegalAccessException e){ ! log.error("IllegalAccessException: Could not read value of field " + fields[i].getName()); ! } ! }else{ ! if(log.isDebugEnabled()){ ! log.debug("Skipping field " + fields[i].getName()); ! log.debug("Skipped because of modifiers: " + Modifier.toString(mods)); ! } ! } ! } ! return props; ! } ! public void setFromProps(Properties props){ ! if(props == null){ ! throw new IllegalArgumentException("Error, null props"); } ! ! Class cl = getClass(); ! Field[] fields = cl.getDeclaredFields(); ! for(int i=0; i< fields.length; i++){ ! int mods = fields[i].getModifiers(); ! if(!Modifier.isStatic(mods) && !Modifier.isTransient(mods)){ ! String s = props.getProperty(fields[i].getName()); ! if(s != null){ ! s = s.trim(); //XXX may not be necessary ! Object val = null; ! try{ ! val = PropUtil.makeObject(fields[i].getType(), s); ! fields[i].set(this, val); ! }catch(IllegalAccessException e){ ! log.error("IllegalAccessException: Could not set value of field " + fields[i].getName()); ! }catch(IllegalArgumentException e){ ! log.error("IllegalArgumentException: Could not set value of field " + fields[i].getName() + " to " + val); ! } ! }else{ ! log.warn("Got null string for field " + fields[i].getName()); ! } ! }else{ ! log.info("Skipping field " + fields[i].getName()); ! log.debug("Skipped because of modifiers: " + Modifier.toString(mods)); ! } } } ! public boolean saveToFile(File f){ ! Properties p = getProps(); ! try{ ! p.store(new FileOutputStream(f), null); ! }catch(IOException e){ ! return false; ! } ! return true; } ! public boolean loadFromFile(File f){ ! Properties p = new Properties(); ! try{ ! p.load(new FileInputStream(f)); ! setFromProps(p); ! }catch(IOException e){ ! return false; } ! ! return true; } } --- 6,122 ---- import java.io.*; ! public class PropProvider { ! static Logger log = Logger.getLogger(PropProvider.class.getName()); ! public String toString() { ! return getProps().toString(); ! } ! public Properties getProps() { ! return getProps(""); ! } + public Properties getProps(String prefix) { + Class cl = getClass(); + Field[] fields = cl.getDeclaredFields(); + Properties props = new Properties(); + for (int i = 0; i < fields.length; i++) { + int mods = fields[i].getModifiers(); + if (!Modifier.isStatic(mods) && !Modifier.isTransient(mods)) { + try { ! Object fldValue = fields[i].get(this); ! String s; ! if (fldValue == null) { ! s = "null"; ! } else { ! s = fldValue.toString(); ! } ! props.setProperty(fields[i].getName(), s); ! } catch (IllegalAccessException e) { ! log.error("IllegalAccessException: Could not read value of field " ! + fields[i].getName()); } ! } else { ! if (log.isDebugEnabled()) { ! log.debug("Skipping field " + fields[i].getName()); ! log.debug("Skipped because of modifiers: " + Modifier.toString(mods)); } + } } + return props; + } + public void setFromProps(Properties props, boolean includeSubclasses) { + if (!includeSubclasses) { + setFromProps(props); + } else { ! Class crntClass = this.getClass(); ! do { ! setFromProps(props, crntClass); ! } while ((crntClass = crntClass.getSuperclass()) != null); } + } ! public void setFromProps(Properties props) { ! setFromProps(props, getClass()); ! } ! ! protected void setFromProps(Properties props, Class myClass) { ! if (props == null) { ! throw new IllegalArgumentException("Error, null props"); ! } ! ! Field[] fields = myClass.getDeclaredFields(); ! for (int i = 0; i < fields.length; i++) { ! int mods = fields[i].getModifiers(); ! log.info("Processing field " + fields[i].getName()); ! if (!Modifier.isStatic(mods) && !Modifier.isTransient(mods)) { ! String s = props.getProperty(fields[i].getName()); ! if (s != null) { ! s = s.trim(); //XXX may not be necessary ! Object val = null; ! try { ! val = PropUtil.makeObject(fields[i].getType(), s); ! fields[i].set(this, val); ! log.info("set field " + fields[i].getName() + " to val " + val); ! } catch (IllegalAccessException e) { ! log.error("IllegalAccessException: Could not set value of field " ! + fields[i].getName()); ! } catch (IllegalArgumentException e) { ! log.error("IllegalArgumentException: Could not set value of field " ! + fields[i].getName() + " to " + val); ! } ! } else { ! log.warn("Got null string for field " + fields[i].getName()); } ! } else { ! log.info("Skipping field " + fields[i].getName()); ! log.debug("Skipped because of modifiers: " + Modifier.toString(mods)); ! } } + } + + public boolean saveToFile(File f) { + Properties p = getProps(); + try { + p.store(new FileOutputStream(f), null); + } catch (IOException e) { + return false; + } + return true; + } + + public boolean loadFromFile(File f) { + Properties p = new Properties(); + try { + p.load(new FileInputStream(f)); + setFromProps(p); + } catch (IOException e) { + return false; + } + + return true; + } } Index: CernUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/CernUtil.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** CernUtil.java 29 Aug 2006 19:29:56 -0000 1.12 --- CernUtil.java 20 Nov 2006 19:52:24 -0000 1.13 *************** *** 280,285 **** public static final double sum(DoubleMatrix1D a){ return a.aggregate(F.plus,F.identity); ! } ! public static final double sum(DoubleArrayList aList){ int n = aList.size(); --- 280,285 ---- public static final double sum(DoubleMatrix1D a){ return a.aggregate(F.plus,F.identity); ! } ! public static final double sum(DoubleArrayList aList){ int n = aList.size(); |
|
From: Brent B. <bre...@us...> - 2006-11-20 19:29:24
|
Update of /cvsroot/jigs/jigs In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv17476 Removed Files: .classpath .project Log Message: --- .classpath DELETED --- --- .project DELETED --- |
|
From: Brent B. <bre...@us...> - 2006-11-19 22:24:13
|
Update of /cvsroot/jigs//jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27624/src/edu/whitman/halfway/util Modified Files: ExecutionTimer.java TimingTree.java StringUtil.java Timing.java Log Message: Modified ExecutionTimer to reflect Brent's StopWatch class. This involved adding new methods and eliminating / replacing a confusing method. ET's are now in terms of ns, but return ms for default methods. Timings was changed to reflect changes in ET. Also, it was genericized to make loops more efficient. Index: ExecutionTimer.java =================================================================== RCS file: /cvsroot/jigs//jigs/src/edu/whitman/halfway/util/ExecutionTimer.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ExecutionTimer.java 10 Aug 2006 22:53:35 -0000 1.4 --- ExecutionTimer.java 19 Nov 2006 22:24:09 -0000 1.5 *************** *** 4,80 **** public final class ExecutionTimer{ ! protected static Logger log = Logger.getLogger(ExecutionTimer.class); ! ! boolean isRunning = false; ! long elapsedTime = 0; ! long lastStartTime = 0; ! ! protected String name; ! ! public ExecutionTimer(){ ! this("Unnamed"); ! } ! ! public ExecutionTimer(String name){ ! this.name = name; ! } ! ! public String getName() { ! return name; ! } ! public void setName(String name) { this.name = name; } ! ! public boolean isRunning(){ ! return isRunning; ! } ! ! public final void reset(){ ! isRunning = false; ! elapsedTime = 0; ! lastStartTime = 0; ! } ! ! public final void start(){ ! if(isRunning){ ! log.warn(String.format( ! "Timer %s is already running, ignoring call to start.", ! getName())); ! //throw new IllegalArgumentException("Timer is already running."); ! } ! isRunning = true; ! lastStartTime = System.currentTimeMillis(); ! } ! public long stop(){ ! return stop(System.currentTimeMillis()); ! } ! ! public void incTime(long ms){ ! elapsedTime += ms; ! } ! ! public long stop(long stopTime){ ! if(!isRunning){ ! log.warn("Timer " + getName() + " isn't running, so can't stop it."); ! //throw new IllegalArgumentException("Can't stop a timer that isn't running"); ! } ! long delta = stopTime - lastStartTime; ! elapsedTime += delta; ! isRunning = false; ! return delta; ! } ! public final long getElapsedTime(){ ! if(!isRunning) return elapsedTime; ! return elapsedTime + (System.currentTimeMillis() - lastStartTime); ! } ! ! public String toString(){ ! return StringUtil.formatMillis(getElapsedTime()); ! } ! } --- 4,153 ---- public final class ExecutionTimer{ ! private static final long nsInMs = 1000000; ! protected static Logger log = Logger.getLogger(ExecutionTimer.class); ! protected final String name; ! ! boolean isRunning = false; ! long elapsedTime = 0L; ! long lastStartTime = 0L; ! ! public ExecutionTimer(){ ! this("Unnamed"); ! } ! ! public ExecutionTimer(String name){ ! this.name = name; ! } ! ! public String getName() { ! return name; ! } ! ! /* public void setName(String name) { this.name = name; } ! */ ! ! public boolean isRunning(){ ! return isRunning; ! } ! ! ! public final void reset(){ ! // isRunning = false; ! elapsedTime = 0L; ! lastStartTime = 0L; ! } ! ! ! public final void start(){ ! if(isRunning()){ ! log.warn("Timer "+getName()+" is already running, ignoring call to start."); ! //throw new IllegalArgumentException("Timer is already running."); ! } ! isRunning = true; ! lastStartTime = System.nanoTime(); ! } ! ! public final void start(boolean reset) { ! if (reset) { ! reset(); ! } ! start(); ! } ! /** ! * Stops the Timer ! */ ! public ExecutionTimer stop(){ ! return stop(System.nanoTime()); ! } ! ! /** ! * Adds additional time (in ms) to the elapsed time of the watch. This method ! * does not depend on whether or not the watch is running. ! */ ! public void addTime(long ms){ ! elapsedTime += ms*1000000; ! } ! /** ! * Adds additional time (in ns) to the elapsed time of the watch. This method ! * does not depend on whether or not the watch is running. ! */ ! public void addTimeNano(long ns) { ! elapsedTime += ns; ! } ! ! /** ! * Stops the watch at the specified time. This is useful, if some processing must be done ! * between the time when the timed event ends and the time at which the stop method can be ! * called. StopTime is in nanoSeconds! ! */ ! public ExecutionTimer stop(long stopTime){ ! if(!isRunning()){ ! log.warn("Timer " + getName() + " isn't running, so can't stop it."); ! //throw new IllegalArgumentException("Can't stop a timer that isn't running"); ! } ! long delta = stopTime - lastStartTime; ! elapsedTime += delta; ! lastStartTime = delta; ! isRunning = false; ! return this; ! } ! /** ! * Return the time elapsed between the last start and stop of the timer if the ! * timer is stopped, or the time elapsed between the last start and now if the ! * timer is running in ms. This method explicitly precludes all execution time ! * before the start was last called. ! */ ! public final long getLastEventTime() { ! return getLastEventTimeNano()/nsInMs; ! } ! ! public final long getLastEventTimeNano() { ! if (!isRunning) { ! return lastStartTime; ! } ! return System.nanoTime() - lastStartTime; ! } ! ! /** Return the total elapsed time in ms */ ! public final long getElapsedTime(){ ! return getElapsedTimeNano()/nsInMs; ! } ! public final long getElapsedTimeNano(){ ! if(!isRunning()) { ! return elapsedTime; ! } ! return elapsedTime + (System.nanoTime() - lastStartTime); ! } ! ! public String toString(){ ! return StringUtil.formatMillis(getElapsedTime()); ! } ! ! public static String formatTime(long ms) { ! return formatMicroTime(ms*1000); ! } ! ! public static String formatNanoTime(long ns) { ! return formatMicroTime(ns/1000); ! } ! ! private static String formatMicroTime(long ts) { ! int min = (int)(ts/60000000); ! ts -= min*60000000; ! ! int sec = (int)(ts/1000000); ! ts -= sec*1000000; ! ! int ms = (int)(ts/1000); ! ts -= ms*1000; ! ! return String.format("%4dm %2ds %3d.%03dms", min, sec, ms, ts); ! } ! } \ No newline at end of file Index: TimingTree.java =================================================================== RCS file: /cvsroot/jigs//jigs/src/edu/whitman/halfway/util/TimingTree.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TimingTree.java 11 Sep 2006 15:05:22 -0000 1.2 --- TimingTree.java 19 Nov 2006 22:24:09 -0000 1.3 *************** *** 66,73 **** protected void incTime(long ms){ ! activeNode.timer.incTime(ms); Node parent = activeNode.parent; while(parent != null){ ! parent.timer.incTime(ms); parent = parent.parent; } --- 66,73 ---- protected void incTime(long ms){ ! activeNode.timer.addTime(ms); Node parent = activeNode.parent; while(parent != null){ ! parent.timer.addTime(ms); parent = parent.parent; } *************** *** 204,208 **** } } ! sumNode.timer.incTime(time); for(Object entryObj : childListMap.entrySet()){ --- 204,208 ---- } } ! sumNode.timer.addTime(time); for(Object entryObj : childListMap.entrySet()){ Index: StringUtil.java =================================================================== RCS file: /cvsroot/jigs//jigs/src/edu/whitman/halfway/util/StringUtil.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** StringUtil.java 11 Sep 2006 15:05:22 -0000 1.14 --- StringUtil.java 19 Nov 2006 22:24:09 -0000 1.15 *************** *** 81,86 **** Calendar c = Calendar.getInstance(); ! return c.get(c.MONTH) + "-" + c.get(c.DAY_OF_MONTH) + "-" + c.get(c.YEAR) ! + "_" + c.get(c.HOUR_OF_DAY) + "h-" + c.get(c.MINUTE) + "m"; } --- 81,87 ---- Calendar c = Calendar.getInstance(); ! return c.get(Calendar.MONTH) + "-" + c.get(Calendar.DAY_OF_MONTH) + ! "-" + c.get(Calendar.YEAR) + "_" + c.get(Calendar.HOUR_OF_DAY) + ! "h-" + c.get(Calendar.MINUTE) + "m"; } *************** *** 130,136 **** } ! public static AbstractList tokenize(String string) { StringTokenizer st = new StringTokenizer(string); ! ArrayList tokens = new ArrayList(); while (st.hasMoreTokens()) { tokens.add(st.nextToken()); --- 131,137 ---- } ! public static List<String> tokenize(String string) { StringTokenizer st = new StringTokenizer(string); ! ArrayList<String> tokens = new ArrayList<String>(); while (st.hasMoreTokens()) { tokens.add(st.nextToken()); *************** *** 139,146 **** } /** Tokenizes the string, treating strings quoted with " as a * single entry. Also parses numbers. The resulting List thus * has Strings and Doubles. Returns null if parsing fails.*/ ! public static AbstractList tokenizeWithQuotes(String string) { // StreamTokenizer seems to be pretty badly broken ... it // won't parse strings like "../CMU/Climbing" if number --- 140,157 ---- } + public static List<String> tokenize(String string, String delim) { + StringTokenizer st = new StringTokenizer(string, delim); + ArrayList<String> tokens = new ArrayList<String>(); + while (st.hasMoreTokens()) { + tokens.add(st.nextToken()); + } + return tokens; + } + + /** Tokenizes the string, treating strings quoted with " as a * single entry. Also parses numbers. The resulting List thus * has Strings and Doubles. Returns null if parsing fails.*/ ! public static List<Object> tokenizeWithQuotes(String string) { // StreamTokenizer seems to be pretty badly broken ... it // won't parse strings like "../CMU/Climbing" if number *************** *** 160,164 **** st.slashSlashComments(false); st.slashStarComments(false); ! LinkedList tokens = new LinkedList(); while (st.nextToken() != StreamTokenizer.TT_EOF) { if (st.ttype == StreamTokenizer.TT_WORD || st.ttype == '"') { --- 171,175 ---- st.slashSlashComments(false); st.slashStarComments(false); ! LinkedList<Object> tokens = new LinkedList<Object>(); while (st.nextToken() != StreamTokenizer.TT_EOF) { if (st.ttype == StreamTokenizer.TT_WORD || st.ttype == '"') { Index: Timing.java =================================================================== RCS file: /cvsroot/jigs//jigs/src/edu/whitman/halfway/util/Timing.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Timing.java 29 Aug 2006 19:29:56 -0000 1.2 --- Timing.java 19 Nov 2006 22:24:09 -0000 1.3 *************** *** 29,33 **** private static Timing t = new Timing(); ! protected Map map = new HashMap(); --- 29,33 ---- private static Timing t = new Timing(); ! protected Map<String,ExecutionTimer> map = new HashMap<String,ExecutionTimer>(); *************** *** 63,67 **** //we want to be as precise as possible, so we first read off the stop time // and only then look up the timer and call stop with the given time. ! long stopTime = System.currentTimeMillis(); ExecutionTimer timer = get(name); if(timer == null){ --- 63,68 ---- //we want to be as precise as possible, so we first read off the stop time // and only then look up the timer and call stop with the given time. ! // long stopTime = System.currentTimeMillis(); ! long stopTime = System.nanoTime(); ExecutionTimer timer = get(name); if(timer == null){ *************** *** 69,73 **** return -1; } ! return timer.stop(); } --- 70,75 ---- return -1; } ! timer.stop(stopTime); ! return timer.getLastEventTime(); } *************** *** 106,110 **** log.warn("Timer " + name + " doesn't exist, so can't increment it."); } ! timer.incTime(ms); } --- 108,112 ---- log.warn("Timer " + name + " doesn't exist, so can't increment it."); } ! timer.addTime(ms); } *************** *** 130,144 **** public String toString(){ ! ArrayList keys = new ArrayList(map.keySet()); Collections.sort(keys); int maxLength = 0; ! for(Object obj : keys){ ! String key = (String)obj; maxLength = (key.length() > maxLength) ? key.length() : maxLength; } StringBuffer sb = new StringBuffer(); String format = "%"+maxLength +"s = %s%n"; ! for(Object obj : keys){ ! String key = (String)obj; sb.append(String.format(format, key, get(key))); } --- 132,144 ---- public String toString(){ ! ArrayList<String> keys = new ArrayList<String>(map.keySet()); Collections.sort(keys); int maxLength = 0; ! for(String key : keys){ maxLength = (key.length() > maxLength) ? key.length() : maxLength; } StringBuffer sb = new StringBuffer(); String format = "%"+maxLength +"s = %s%n"; ! for(String key : keys){ sb.append(String.format(format, key, get(key))); } *************** *** 146,153 **** } ! public static long sumTimes(String name, Collection timings){ long totalTimeMS = 0; ! for(Object obj : timings){ ! Timing t = (Timing) obj; totalTimeMS += t.getElapsedTime(name); } --- 146,152 ---- } ! public static long sumTimes(String name, Collection<Timing> timings){ long totalTimeMS = 0; ! for(Timing t : timings){ totalTimeMS += t.getElapsedTime(name); } *************** *** 155,164 **** } ! public static Timing sumTimings(Collection timings){ if(timings.size()==0) return new Timing(); ! Set keys = ((Timing)timings.iterator().next()).map.keySet(); Timing timing = new Timing(); ! for(Object k : keys){ ! String key = (String) k; long total = sumTimes(key, timings); timing.reset(key); --- 154,162 ---- } ! public static Timing sumTimings(Collection<Timing> timings){ if(timings.size()==0) return new Timing(); ! Set<String> keys = (timings.iterator().next()).map.keySet(); Timing timing = new Timing(); ! for(String key : keys){ long total = sumTimes(key, timings); timing.reset(key); *************** *** 190,198 **** Timing.t.incTime(name[i], time[i]); } ! System.out.println(Timing.t); ! } ! ! ! ! } --- 188,192 ---- Timing.t.incTime(name[i], time[i]); } ! System.out.println(Timing.t); } ! } \ No newline at end of file |
|
From: Brent B. <bre...@us...> - 2006-11-19 22:24:12
|
Update of /cvsroot/jigs//jigs In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27624 Added Files: .project .classpath Log Message: Modified ExecutionTimer to reflect Brent's StopWatch class. This involved adding new methods and eliminating / replacing a confusing method. ET's are now in terms of ns, but return ms for default methods. Timings was changed to reflect changes in ET. Also, it was genericized to make loops more efficient. --- NEW FILE: .project --- <?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>jigs</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> </projectDescription> --- NEW FILE: .classpath --- <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="lib" path="jars/Chart2D.jar"/> <classpathentry kind="lib" path="jars/colt.jar"/> <classpathentry kind="lib" path="jars/gnu_getopt.jar"/> <classpathentry kind="lib" path="jars/ij.jar"/> <classpathentry kind="lib" path="jars/jakarta-oro-2.0.2-dev-2.jar"/> <classpathentry kind="lib" path="jars/jisp.jar"/> <classpathentry kind="lib" path="jars/junit.jar"/> <classpathentry kind="lib" path="jars/log4j.jar"/> <classpathentry kind="lib" path="jars/openjgraph.jar"/> <classpathentry combineaccessrules="false" kind="src" path="/mtj"/> <classpathentry kind="output" path="bin"/> </classpath> |
Update of /cvsroot/jigs//jigs/bin In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27624/bin Removed Files: DateAdjuster CopyOrig AddDescriptionField PictureDescriptionProgram JigSpace DateImageSorter LowercaseCategories TextJTLDriver EACopyDebug CategoryAdd ImageConverter FieldList JigsFast FindPicturesInCategory Jigs JigsPrefs JigsDebug ReorderFile PicturesWithField TextInfoExtractor ExplicitAlbumCopy TextOldSwigsDriver SetJigsPrefs ListSubalbums CategoryList RenameWithInfo AlbumList Log Message: Modified ExecutionTimer to reflect Brent's StopWatch class. This involved adding new methods and eliminating / replacing a confusing method. ET's are now in terms of ns, but return ms for default methods. Timings was changed to reflect changes in ET. Also, it was genericized to make loops more efficient. --- DateAdjuster DELETED --- --- CopyOrig DELETED --- --- AddDescriptionField DELETED --- --- PictureDescriptionProgram DELETED --- --- JigSpace DELETED --- --- DateImageSorter DELETED --- --- LowercaseCategories DELETED --- --- TextJTLDriver DELETED --- --- EACopyDebug DELETED --- --- CategoryAdd DELETED --- --- ImageConverter DELETED --- --- FieldList DELETED --- --- JigsFast DELETED --- --- FindPicturesInCategory DELETED --- --- Jigs DELETED --- --- JigsPrefs DELETED --- --- JigsDebug DELETED --- --- ReorderFile DELETED --- --- PicturesWithField DELETED --- --- TextInfoExtractor DELETED --- --- ExplicitAlbumCopy DELETED --- --- TextOldSwigsDriver DELETED --- --- SetJigsPrefs DELETED --- --- ListSubalbums DELETED --- --- CategoryList DELETED --- --- RenameWithInfo DELETED --- --- AlbumList DELETED --- |
|
From: Brent B. <bre...@us...> - 2006-11-19 22:24:11
|
Update of /cvsroot/jigs//jigs/src/edu/whitman/halfway/jigs In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27624/src/edu/whitman/halfway/jigs Modified Files: AlbumWithIncludes.java Log Message: Modified ExecutionTimer to reflect Brent's StopWatch class. This involved adding new methods and eliminating / replacing a confusing method. ET's are now in terms of ns, but return ms for default methods. Timings was changed to reflect changes in ET. Also, it was genericized to make loops more efficient. Index: AlbumWithIncludes.java =================================================================== RCS file: /cvsroot/jigs//jigs/src/edu/whitman/halfway/jigs/AlbumWithIncludes.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** AlbumWithIncludes.java 2 Aug 2006 21:36:15 -0000 1.12 --- AlbumWithIncludes.java 19 Nov 2006 22:24:08 -0000 1.13 *************** *** 131,135 **** while( (line = in.readLine()) != null){ //System.out.println("Processing line: " + line); ! AbstractList tokens = StringUtil.tokenizeWithQuotes(line); if(tokens.size() > 0){ if ( ((String)tokens.get(0)).startsWith("#")) --- 131,135 ---- while( (line = in.readLine()) != null){ //System.out.println("Processing line: " + line); ! List tokens = StringUtil.tokenizeWithQuotes(line); if(tokens.size() > 0){ if ( ((String)tokens.get(0)).startsWith("#")) |
|
From: Brendan M. <mc...@us...> - 2006-11-11 02:05:03
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv20896/src/edu/whitman/halfway/util Modified Files: ProcessUtil.java MathUtil.java MiscUtil.java PropProvider.java EADoubleFactory2D.java Log Message: Index: ProcessUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/ProcessUtil.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ProcessUtil.java 16 May 2005 22:59:47 -0000 1.5 --- ProcessUtil.java 11 Nov 2006 02:04:56 -0000 1.6 *************** *** 13,16 **** --- 13,20 ---- private static Logger log = Logger.getLogger(ProcessUtil.class.getName()); + + public static boolean exec(String[] command, OutputStream out){ + return exec(command, out, null); + } /** Tries to exec the command, waits for it to finsih, logs errors if *************** *** 19,27 **** becomes available ... pass in System.out to monitor progress.*/ ! public static boolean exec(String[] command, OutputStream out){ Process proc; try{ log.debug("Trying to execute command " + Arrays.asList(command)); ! proc = Runtime.getRuntime().exec(command); }catch(IOException e){ log.error("IOException while trying to execute " + command, e); --- 23,31 ---- becomes available ... pass in System.out to monitor progress.*/ ! public static boolean exec(String[] command, OutputStream out, File workingDir){ Process proc; try{ log.debug("Trying to execute command " + Arrays.asList(command)); ! proc = Runtime.getRuntime().exec(command, null, workingDir); }catch(IOException e){ log.error("IOException while trying to execute " + command, e); Index: MathUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/MathUtil.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MathUtil.java 20 Mar 2004 00:07:23 -0000 1.3 --- MathUtil.java 11 Nov 2006 02:04:56 -0000 1.4 *************** *** 23,26 **** --- 23,30 ---- public static final double TWO_PI = Math.PI * 2; + + + + /** Given the function f and the step-paramter t, returns * extimates of the gradients */ Index: MiscUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/MiscUtil.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** MiscUtil.java 11 Sep 2006 15:05:22 -0000 1.24 --- MiscUtil.java 11 Nov 2006 02:04:56 -0000 1.25 *************** *** 7,1175 **** import java.util.*; ! public final class MiscUtil{ ! ! private static Logger log = Logger.getLogger(MiscUtil.class); ! //private static DecimalFormat df = new DecimalFormat("0.000E0"); ! private static DecimalFormat df = new DecimalFormat("0.000"); ! private static Random rand = new Random(); [...2445 lines suppressed...] + } + System.out.println("Sorting Results (key array over value array): "); + MiscUtil.simpleSortDecPairs(key, value); + System.out.println(MiscUtil.toString(key)); + System.out.print(MiscUtil.toString(value)); + System.out.println(); ! System.out.println("Testing unpack methods on 1, ..., 9"); ! double[] d = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; ! System.out.println("Unpack Row Major:"); ! double[][] rm = unpackRowMajor(3, 3, d); ! System.out.println(MiscUtil.toString(rm)); ! System.out.println(MiscUtil.toString(MiscUtil.packRowMajor(rm))); ! System.out.println("Column Major:"); ! double[][] cm = unpackColMajor(3, 3, d); ! System.out.println(MiscUtil.toString(cm)); ! } } Index: PropProvider.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/PropProvider.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PropProvider.java 11 Sep 2006 15:05:22 -0000 1.5 --- PropProvider.java 11 Nov 2006 02:04:56 -0000 1.6 *************** *** 38,43 **** } }else{ ! log.info("Skipping field " + fields[i].getName()); log.debug("Skipped because of modifiers: " + Modifier.toString(mods)); } } --- 38,45 ---- } }else{ ! if(log.isDebugEnabled()){ ! log.debug("Skipping field " + fields[i].getName()); log.debug("Skipped because of modifiers: " + Modifier.toString(mods)); + } } } Index: EADoubleFactory2D.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/EADoubleFactory2D.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EADoubleFactory2D.java 12 Jan 2004 20:06:43 -0000 1.2 --- EADoubleFactory2D.java 11 Nov 2006 02:04:56 -0000 1.3 *************** *** 1,3 **** --- 1,4 ---- package edu.whitman.halfway.util; + // import cern.colt.function.DoubleDoubleFunction; import cern.colt.matrix.*; *************** *** 6,77 **** // import cern.colt.list.DoubleArrayList; - import org.apache.log4j.Logger; - /** a dense factory that makes ElementAccessDenseDoubleMatrix2D's*/ ! public class EADoubleFactory2D extends DoubleFactory2D{ ! static Logger log = Logger.getLogger(EADoubleFactory2D.class); ! public DoubleMatrix2D make(DoubleMatrix1D m, int rows, int cols) { ! if(!(m instanceof EADoubleFactory1D.ElementAccessDenseDoubleMatrix1D)){ ! log.warn("Slow..."); ! m = (CernUtil.dense1D.make(m.size())).assign(m); ! } ! return new ElementAccessDenseDoubleMatrix2D ! ( ((EADoubleFactory1D.ElementAccessDenseDoubleMatrix1D)m).getElements(), rows, cols); ! } ! public DoubleMatrix2D make(double[][] values) { ! return new ElementAccessDenseDoubleMatrix2D(values); } ! public DoubleMatrix2D make(int rows, int columns) { ! return new ElementAccessDenseDoubleMatrix2D(rows, columns); } ! public static class ElementAccessDenseDoubleMatrix2D ! extends DenseDoubleMatrix2D{ ! ! public ElementAccessDenseDoubleMatrix2D(double[][] array){ ! super(array); ! } ! ! public ElementAccessDenseDoubleMatrix2D(int rows, int cols){ ! super(rows, cols); ! } ! ! ! /** elements is packed in row-major */ ! public ElementAccessDenseDoubleMatrix2D(double[] elements, int rows, int cols){ ! super(rows, cols, elements, 0, 0, cols, 1); ! } ! ! public double[] getElements(){ ! return elements; ! } ! ! public DoubleMatrix1D like1D(int size){ ! return new EADoubleFactory1D.ElementAccessDenseDoubleMatrix1D(size); ! } ! public DoubleMatrix2D like(int rows, int columns){ ! return new ElementAccessDenseDoubleMatrix2D(rows, columns); ! } ! protected DoubleMatrix1D like1D(int size, int zero, int stride) { ! return new EADoubleFactory1D.ElementAccessDenseDoubleMatrix1D(size,this.elements,zero,stride); ! } } } - - - --- 7,72 ---- // import cern.colt.list.DoubleArrayList; import org.apache.log4j.Logger; /** a dense factory that makes ElementAccessDenseDoubleMatrix2D's*/ ! public class EADoubleFactory2D extends DoubleFactory2D { ! static Logger log = Logger.getLogger(EADoubleFactory2D.class); ! ! public DoubleMatrix2D make(DoubleMatrix1D m, int rows, int cols) { ! if (!(m instanceof EADoubleFactory1D.ElementAccessDenseDoubleMatrix1D)) { ! log.warn("Slow..."); ! m = (CernUtil.dense1D.make(m.size())).assign(m); ! log.info("...done"); ! } ! return new ElementAccessDenseDoubleMatrix2D( ! ((EADoubleFactory1D.ElementAccessDenseDoubleMatrix1D) m) ! .getElements(), rows, cols); ! } ! public DoubleMatrix2D make(double[][] values) { ! return new ElementAccessDenseDoubleMatrix2D(values); ! } + public DoubleMatrix2D make(int rows, int columns) { + return new ElementAccessDenseDoubleMatrix2D(rows, columns); + } + public static class ElementAccessDenseDoubleMatrix2D extends + DenseDoubleMatrix2D { ! public ElementAccessDenseDoubleMatrix2D(double[][] array) { ! super(array); } ! public ElementAccessDenseDoubleMatrix2D(int rows, int cols) { ! super(rows, cols); } ! /** elements is packed in row-major */ ! public ElementAccessDenseDoubleMatrix2D(double[] elements, int rows, ! int cols) { ! super(rows, cols, elements, 0, 0, cols, 1); ! } ! public double[] getElements() { ! return elements; ! } ! public DoubleMatrix1D like1D(int size) { ! return new EADoubleFactory1D.ElementAccessDenseDoubleMatrix1D(size); ! } + public DoubleMatrix2D like(int rows, int columns) { + return new ElementAccessDenseDoubleMatrix2D(rows, columns); } + protected DoubleMatrix1D like1D(int size, int zero, int stride) { + return new EADoubleFactory1D.ElementAccessDenseDoubleMatrix1D(size, + this.elements, zero, stride); + } + } } |
|
From: Brendan M. <mc...@us...> - 2006-09-11 15:05:28
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv29584/src/edu/whitman/halfway/util Modified Files: MiscUtil.java PropProvider.java StringUtil.java FileUtil.java TimingTree.java Log Message: Index: MiscUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/MiscUtil.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** MiscUtil.java 29 Aug 2006 19:29:56 -0000 1.23 --- MiscUtil.java 11 Sep 2006 15:05:22 -0000 1.24 *************** *** 16,19 **** --- 16,29 ---- private static Random rand = new Random(); + + public static final boolean isAssertEnabled(){ + try{ + assert false; + }catch(AssertionError e){ + return true; + } + return false; + } + public static final void fill(int[][] a, int v){ int n = a.length; *************** *** 741,746 **** } - - public static final long[] packRowMajor(long[][] data){ int nr = data.length; --- 751,754 ---- Index: PropProvider.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/PropProvider.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PropProvider.java 2 Mar 2005 17:54:58 -0000 1.4 --- PropProvider.java 11 Sep 2006 15:05:22 -0000 1.5 *************** *** 9,12 **** --- 9,16 ---- static Logger log = Logger.getLogger(PropProvider.class.getName()); + public String toString(){ + return getProps().toString(); + } + public Properties getProps(){ return getProps(""); Index: StringUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/StringUtil.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** StringUtil.java 29 Aug 2006 19:29:56 -0000 1.13 --- StringUtil.java 11 Sep 2006 15:05:22 -0000 1.14 *************** *** 180,183 **** --- 180,199 ---- } + + /** + * + * @param input A string, possibly with multiple lines. + * @param pad Padding string to be prefixed to the start of each line. + * @return A padded version of input. + */ + public static String padLines(String input, String pad){ + //System.out.printf("input:%n%s%n", input); + java.util.regex.Pattern p = java.util.regex.Pattern.compile("^", java.util.regex.Pattern.MULTILINE); + java.util.regex.Matcher m = p.matcher(input); + String output = m.replaceAll(pad); + //System.out.printf("output:%n%s%n", output); + return output; + } + /** Prefixes the string input with enough copies of pad that it has length equal to length. Returns null and logs an error if *************** *** 321,324 **** --- 337,348 ---- public static void main(String[] args) { + test(); + } + + public static void test(){ + String test = String.format("foo%nadlfkja34%nad3%n hllow now%n"); + System.out.println(padLines(test, " ")); + + long[] times = { 100, 13011, 60 * 60 * 1000 * 59 + 60 * 1000 * 32 + 1000 * 49 + 333, Index: FileUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/FileUtil.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** FileUtil.java 29 Aug 2006 19:29:56 -0000 1.14 --- FileUtil.java 11 Sep 2006 15:05:22 -0000 1.15 *************** *** 38,41 **** --- 38,42 ---- } + public static File makeNumFilename(String prefix, String suffix, File dir){ return makeNumFilename(prefix, suffix, dir, false); Index: TimingTree.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/TimingTree.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TimingTree.java 29 Aug 2006 19:29:56 -0000 1.1 --- TimingTree.java 11 Sep 2006 15:05:22 -0000 1.2 *************** *** 30,36 **** --- 30,55 ---- public void start(String name){ + if(nameIsBelow(name)){ + log.warn(String.format("Possible error: A timer of name \"%s\" is already running.", + name)); + } activeNode = activeNode.start(name); } + public boolean nameIsBelow(String name){ + if (name.equals(activeNode.name)){ + return true; + } + + Node node = activeNode; + while(node.parent != null){ + node = node.parent; + if(name.equals(node.name)){ + return true; + } + } + return false; + } + public ExecutionTimer getTimer(String dottedName){ String[] name = dottedName.split("."); |
|
From: Brendan M. <mc...@us...> - 2006-08-29 19:30:06
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv3714/src/edu/whitman/halfway/util Modified Files: Timing.java MiscUtil.java StringUtil.java FileUtil.java CernUtil.java Added Files: TimingTree.java Log Message: --- NEW FILE: TimingTree.java --- package edu.whitman.halfway.util; import java.util.*; import org.apache.log4j.Logger; import cern.colt.matrix.ObjectFactory2D; import cern.colt.matrix.ObjectMatrix2D; public class TimingTree { protected static Logger log = Logger.getLogger(TimingTree.class); /** * As with the static instance in the Timing class, use with care. */ public static TimingTree tt = new TimingTree(); protected Node root = null; protected Node activeNode = null; /** Creates and starts the root timer */ public TimingTree(){ this.root = new Node("root", null); this.activeNode = root; } public static void setStaticInstance(TimingTree t){ TimingTree.tt = t; } public void start(String name){ activeNode = activeNode.start(name); } public ExecutionTimer getTimer(String dottedName){ String[] name = dottedName.split("."); Node node = root; for(int i=0; i<name.length; i++){ node = (Node) node.children.get(name); if(node == null){ log.warn("Not timer of name " + dottedName); return null; } } return node.timer; } protected void incTime(long ms){ activeNode.timer.incTime(ms); Node parent = activeNode.parent; while(parent != null){ parent.timer.incTime(ms); parent = parent.parent; } } protected void incTimeRand(){ long time = MiscUtil.randLongInRange(0, 999);//ms if(MiscUtil.randDoubleInRange(0, 1) < 0.9){//sec time += MiscUtil.randLongInRange(0, 59) * 1000; } if(MiscUtil.randDoubleInRange(0, 1) < 0.8){//min time += MiscUtil.randLongInRange(0, 59) * 1000*60; } if(MiscUtil.randDoubleInRange(0, 1) < 0.10){//h time += MiscUtil.randLongInRange(0, 5) * 1000*60*60; } incTime(time); } public boolean areTimersRunning(){ return (activeNode != root); } public String stopAndPop(){ if(activeNode == root){ throw new IllegalArgumentException("Can't stop the root!"); } String stoppedName = activeNode.name; activeNode.timer.stop(); activeNode = activeNode.parent; return stoppedName; } public String stopAndPop(String name){ if(!name.equals(activeNode.name)){ log.warn(String.format("You're stopping %s, not %s like you thought.", activeNode.name, name)); } return stopAndPop(); } ArrayList nameCol, timeCol; public String toString(){ return toString(false); } public String toString(boolean printZeros){ nameCol = new ArrayList(); timeCol = new ArrayList(); StringBuffer sb = new StringBuffer(); ArrayList childList = new ArrayList(root.children.keySet()); Collections.sort(childList); for(Object childName : childList){ Node child = (Node)root.children.get(childName); buildString(child, 0, printZeros); } ObjectMatrix2D stringMatrix = ObjectFactory2D.dense.make(nameCol.size(),2); for(int i=0; i<nameCol.size(); i++){ stringMatrix.set(i, 0, nameCol.get(i)); stringMatrix.set(i, 1, timeCol.get(i)); } cern.colt.matrix.objectalgo.Formatter objFormatter = new cern.colt.matrix.objectalgo.Formatter(); //objFormatter.setAlignment(Formatter.RIGHT); objFormatter.setPrintShape(false); return objFormatter.toString(stringMatrix); } protected long buildString(Node node, int depth, boolean printZeros){ //depth first pre-order traversal nameCol.add(pad(depth) + node.name); timeCol.add(pad(depth) + "|" + StringUtil.formatMillis( node.timer.getElapsedTime(), printZeros)); long totalChildrenTime = 0; ArrayList childList = new ArrayList(node.children.keySet()); Collections.sort(childList); for(Object childName : childList){ Node child = (Node)node.children.get(childName); totalChildrenTime += buildString(child, depth+1, printZeros); } if(childList.size() > 0){ nameCol.add(pad(depth+1) + "[overhead]"); long overhead = node.timer.getElapsedTime() - totalChildrenTime; timeCol.add(pad(depth+1) + "|" + StringUtil.formatMillis(overhead, printZeros)); } return node.timer.getElapsedTime(); } protected String pad(int depth){ StringBuffer sb = new StringBuffer(); for(int i=0; i<depth; i++){ sb.append(" "); } return sb.toString(); } /** Takes a list of TimingTrees and returns a tree that is the "sum" of * timings across same-name timiers. * * Note: Sums times over the union of the trees: eg, sum has a leaf if any of * the timers have such a leaf. * * All timers should be stopped. * * */ public static TimingTree sum(List trees){ TimingTree sumTT = new TimingTree(); List roots = new ArrayList(); for(Object tree : trees){ roots.add(((TimingTree)tree).root); } sumNodeAndRecurse(sumTT.root, roots); return sumTT; } protected static void sumNodeAndRecurse(Node sumNode, List nodesToSum){ long time = 0; Map childListMap = new HashMap(); //map from String name -> Nodes of that name // calculate time for sumNode in the sumTree, and // create a list of all children of each name for(Object nodeObj : nodesToSum){ Node node = (Node) nodeObj; time += node.timer.getElapsedTime(); //if(node.timer.isRunning()){ //log.warn("Error, running timer " + node.name); //} for(Object childKey : node.children.keySet()){ if(!childListMap.containsKey(childKey)){ childListMap.put(childKey, new ArrayList()); } ArrayList listForName = (ArrayList) childListMap.get(childKey); listForName.add(node.children.get(childKey)); } } sumNode.timer.incTime(time); for(Object entryObj : childListMap.entrySet()){ Map.Entry entry = (Map.Entry) entryObj; String childKey = (String) entry.getKey(); List childNodeList = (List)entry.getValue(); Node sumChild = sumNode.getOrCreateChild(childKey); sumNodeAndRecurse(sumChild, childNodeList); } } class Node{ String name; ExecutionTimer timer; Node parent; Map children; // maps String name -> Node child protected Node(String name, Node parent){ this.parent = parent; this.name = name; this.timer = new ExecutionTimer(name); this.children = new HashMap(); } protected Node start(String name){ Node child = getOrCreateChild(name); assert !child.timer.isRunning(); child.timer.start(); return child; } protected Node getOrCreateChild(String name){ if(children.containsKey(name)){ return (Node) children.get(name); }else{ Node child = new Node(name, this); children.put(name, child); return child; } } } public static TimingTree getSampleTree(){ TimingTree tt = new TimingTree(); tt.start("root task 1"); tt.start("subroutine"); tt.start("super-sub"); tt.incTimeRand(); tt.stopAndPop();tt.incTimeRand(); tt.start("equally super sub");tt.incTimeRand(); tt.stopAndPop();tt.incTimeRand(); tt.stopAndPop();tt.incTimeRand(); tt.start("subroutine 2");tt.incTimeRand();tt.incTimeRand(); tt.stopAndPop();tt.incTimeRand(); tt.stopAndPop();tt.incTimeRand(); tt.start("root task 2");tt.incTimeRand(); tt.stopAndPop(); return tt; } public static void test(){ System.out.println("Timer One:"); TimingTree tt1 = getSampleTree(); assert(!tt1.areTimersRunning()); System.out.println(tt1); System.out.println(); System.out.println("Timer Two:"); TimingTree tt2 = getSampleTree(); assert(!tt2.areTimersRunning()); System.out.println(tt2); System.out.println(); System.out.println(); ArrayList trees = new ArrayList(2); trees.add(tt1); trees.add(tt2); TimingTree ttSum = TimingTree.sum(trees); assert(!ttSum.areTimersRunning()); System.out.println(ttSum); } } Index: Timing.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/Timing.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Timing.java 10 Aug 2006 22:53:35 -0000 1.1 --- Timing.java 29 Aug 2006 19:29:56 -0000 1.2 *************** *** 28,32 **** protected static Logger log = Logger.getLogger(Timing.class); ! public static Timing t = new Timing(); protected Map map = new HashMap(); --- 28,32 ---- protected static Logger log = Logger.getLogger(Timing.class); ! private static Timing t = new Timing(); protected Map map = new HashMap(); Index: MiscUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/MiscUtil.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** MiscUtil.java 6 Aug 2006 19:02:46 -0000 1.22 --- MiscUtil.java 29 Aug 2006 19:29:56 -0000 1.23 *************** *** 822,825 **** --- 822,831 ---- + public final static boolean isNonNegative(double[] a){ + for(double v : a){ + if( v < 0) return false; + } + return true; + } /** Checks that the values in dist sum to 1 (within 10e-6) */ *************** *** 827,830 **** --- 833,837 ---- double sum = 0; for(int i=0; i< dist.length; i++){ + if(dist[i] < 0) return false; sum += dist[i]; } Index: StringUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/StringUtil.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** StringUtil.java 10 Aug 2006 22:53:35 -0000 1.12 --- StringUtil.java 29 Aug 2006 19:29:56 -0000 1.13 *************** *** 7,317 **** import org.apache.oro.text.regex.*; ! public final class StringUtil{ ! public static final String newline = System.getProperty("line.separator"); ! ! static PatternMatcher matcher = new Perl5Matcher(); ! static PatternCompiler compiler = new Perl5Compiler(); ! static Perl5Util regxp = new Perl5Util(); ! static Logger log = Logger.getLogger(StringUtil.class.getName()); ! ! public static final String formatMillis(long ms){ ! String w = " "; ! long totalMillis = ms; ! long sec = ms / 1000; ! ms = ms % 1000; ! if(sec == 0){ ! return String.format("%s%s%s %03dms",w,w,w, ms); ! } ! long min = sec / 60; ! sec = sec % 60; ! if (min ==0){ ! return String.format("%s%s%02ds %03dms",w,w, sec, ms); ! } ! long hr = min / 60; ! min = min % 60; ! if (hr == 0){ ! return String.format("%s%02dm:%02ds %03dms", w, min, sec, ms); ! } ! ! assert 60*60*1000*hr + 60*1000*min + 1000*sec + ms == totalMillis; ! ! ! return String.format("%dh:%02dm:%02ds %03dms", hr, min, sec, ms); ! } ! public static final String stripLeadingNumsUnderscore(String s){ ! return regxp.substitute("s/^[0-9]+_//", s); } ! /** Returns true if the string is non-null and non-whitespace */ ! public static final boolean hasContents(String s){ ! if(s==null) return false; ! return !s.trim().equals(""); ! } ! /** Returns a representation of the current time without any ! * spaces, usefull for use in temprorary file names, etc. ! The format is month-day-year_[hr]h-[min]m ! */ ! public static final String timeForFile(){ ! Calendar c = Calendar.getInstance(); ! ! return c.get(c.MONTH) + "-" + ! c.get(c.DAY_OF_MONTH) + "-" + ! c.get(c.YEAR) + "_" + ! c.get(c.HOUR_OF_DAY) +"h-" + ! c.get(c.MINUTE) + "m"; ! } ! public static String readToString(InputStream in){ ! StringBuffer sb = new StringBuffer(); ! try{ ! BufferedReader inbr = new BufferedReader(new InputStreamReader(in)); ! String line; ! while((line = inbr.readLine() )!=null){ ! sb.append(line); ! } ! }catch(IOException e){ ! log.error("IOException while reading from stream " + in+ " to String.", e); ! return null; ! } ! ! return sb.toString(); } ! /** replaces all occurence of the "key" strings with the "value" ! * string in target String*/ ! public static final String simpleReplace(Map oldNew, String target){ ! Set entries = oldNew.entrySet(); ! Iterator iter = entries.iterator(); ! while(iter.hasNext()){ ! Map.Entry en = (Map.Entry)iter.next(); ! String key = (String)en.getKey(); ! String val = (String)en.getValue(); ! target = simpleReplace(target, key, val); ! } ! return target; } ! //replaces all occurences of old with subsValue in string ! public static final String simpleReplace(String string, String old, String subsValue){ ! try{ ! return Util.substitute ! (matcher, ! compiler.compile(Perl5Compiler.quotemeta(old)), ! new StringSubstitution(subsValue), ! string, ! Util.SUBSTITUTE_ALL ); ! }catch(MalformedPatternException e){ ! log.error("Error substituting for " + old + StringUtil.newline + ! " with subs value: " + StringUtil.newline + subsValue, e); ! return null; ! } } ! ! public static AbstractList tokenize(String string){ ! StringTokenizer st = new StringTokenizer(string); ! ArrayList tokens = new ArrayList(); ! while(st.hasMoreTokens()){ ! tokens.add(st.nextToken()); ! } ! return tokens; } ! ! /** Tokenizes the string, treating strings quoted with " as a ! * single entry. Also parses numbers. The resulting List thus ! * has Strings and Doubles. Returns null if parsing fails.*/ ! public static AbstractList tokenizeWithQuotes(String string){ ! // StreamTokenizer seems to be pretty badly broken ... it ! // won't parse strings like "../CMU/Climbing" if number ! // parsing is disabled. so we reset everything, make ! // everything except whitespace word characters. then, for ! // each word we try to parse it as a double, and if that ! // succeeds we keep it as a double, if not we put the string ! // in the list. ! ! ! try{ ! StringReader reader = new StringReader(string); ! StreamTokenizer st = new StreamTokenizer(reader); ! st.resetSyntax(); ! st.wordChars(0,255); ! st.whitespaceChars(0, ' '); ! st.quoteChar('"'); ! st.slashSlashComments(false); ! st.slashStarComments(false); ! LinkedList tokens = new LinkedList(); ! while(st.nextToken() != StreamTokenizer.TT_EOF){ ! if(st.ttype == StreamTokenizer.TT_WORD || st.ttype == '"'){ ! log.debug("Read Word or Quote" + st.sval); ! String s = st.sval; ! Double d = makeDouble(s); ! tokens.add( (d == null) ? (Object)s : (Object)d ); ! }else{//single character, convert to string and add ! char c = (char)st.ttype; ! log.warn("Got unexpected ttype " + st.ttype + " " + c+ ", sval = " + st.sval +", nval = " + st.nval); ! } ! } ! return tokens; ! }catch(IOException e){ ! log.error("tokenizing failed", e); ! return null; ! } ! } ! ! /** Prefixes the string input with enough copies of pad that it ! has length equal to length. Returns null and logs an error if ! padding with pad cannot produce a string of exactly length. ! Usually, pad should be a single character.*/ ! public static String pad(String input, int length, String pad){ ! StringBuffer sb = new StringBuffer(); ! int padLength = length - input.length(); ! while(sb.length() < padLength){ ! sb.append(pad); ! } ! sb.append(input); ! if(sb.length() != length){ ! log.error("Could not pad \"" + input +"\" with \"" + pad +"\" to get length " + length); ! return null; } ! return sb.toString(); } ! // --------------- Convert Objects to Strings, etc -------------------- // ! ! /** ! Takes an object input and makes an appropriate string, which can then ! be placed in the properties class. If the class type is unknown, ! returns the null string. ! @deprecated Use ObjectSerializer; ! */ ! public static String getObjectsString(Object o){ ! return ObjectSerializer.getStringForObject(o); ! } ! /** ! Takes the string input and tries to make it an instance of ! type. If type is primitive, tries to create the appropriate ! wrapped object. Returns null if input is null, if input is ! "null", or if some error in conversion occurs. ! @deprecated Use ObjectSerializer; ! */ ! ! public static Object makeStringObject(String input){ ! return ObjectSerializer.getObjectForString(input); ! } ! // --------------- String Conversion Methods --------------- // ! public static Integer makeInteger(String s){ ! if(s==null) return null; ! Integer rval = null; ! try{ ! rval = new Integer(s); ! }catch(NumberFormatException e){ ! return null; ! } ! return rval; ! } ! public static Short makeShort(String s){ ! if(s==null) return null; ! Short rval = null; ! try{ ! rval = new Short(s); ! }catch(NumberFormatException e){ ! return null; ! } ! return rval; } ! public static Long makeLong(String s){ ! if(s==null) return null; ! Long rval = null; ! try{ ! rval = new Long(s); ! }catch(NumberFormatException e){ ! return null; ! } ! return rval; } ! public static Float makeFloat(String s){ ! if(s==null) return null; ! Float rval = null; ! try{ ! rval = new Float(s); ! }catch(NumberFormatException e){ ! return null; ! } ! return rval; } ! public static Double makeDouble(String s){ ! if(s==null) return null; ! Double rval = null; ! try{ ! rval = new Double(s); ! }catch(NumberFormatException e){ ! return null; ! } ! return rval; } ! ! public static Boolean makeBoolean(String s){ ! if(s==null) return null; ! s=s.trim(); ! if(s.equalsIgnoreCase("true") ! || s.equalsIgnoreCase("yes") ! || s.equalsIgnoreCase("1") ) ! { ! return new Boolean(true); ! }else{ ! return new Boolean(false); ! } } ! public static Byte makeByte(String s){ ! if(s==null) return null; ! Byte rval; ! try{ ! rval = new Byte(s); ! }catch(NumberFormatException e){ ! return null; ! } ! return rval; } ! public static Character makeCharacter(String s){ ! if(s==null) return null; ! if(s.length() != 1) return null; ! return new Character(s.charAt(0)); } ! public static void main(String[] args){ ! long[] times = { 100, 13011, ! 60*60*1000*59 + 60*1000*32 + 1000*49 + 333, ! 60*60*1000*0 + 60*1000*32 + 1000*49 + 333, ! 60*60*1000*0 + 60*1000*0 + 1000*49 + 3, ! 60*60*1000*90 + 60*1000*0 + 1000*49 + 3, ! }; ! for (long t : times){ ! System.out.println(StringUtil.formatMillis(t)); ! } } ! } --- 7,333 ---- import org.apache.oro.text.regex.*; ! public final class StringUtil { ! public static final String newline = System.getProperty("line.separator"); ! static PatternMatcher matcher = new Perl5Matcher(); ! static PatternCompiler compiler = new Perl5Compiler(); ! static Perl5Util regxp = new Perl5Util(); ! static Logger log = Logger.getLogger(StringUtil.class.getName()); ! ! public static final String formatMemory(long bytes){ ! String format = "%.2f"; ! double bytesD = bytes; ! if(bytesD < 1024){ ! return String.format(format + " B", bytesD); ! }else if (bytesD < 1024*1024){ ! return String.format(format + " KB", bytesD/1024); ! }else if(bytesD < 1024*1024*1024){ ! return String.format(format + " MB", bytesD/(1024*1024)); ! }else{ ! return String.format(format + " GB", bytesD/(1024*1024*1024)); ! } ! } ! ! public static final String formatMillis(long ms){ ! return formatMillis(ms, false); ! } ! ! public static final String formatMillis(long ms, boolean printZeros) { ! String w = " "; ! long totalMillis = ms; ! long sec = ms / 1000; ! ms = ms % 1000; ! if (sec == 0 && !printZeros) { ! return String.format("%s%s%s %03dms", w, w, w, ms); ! } ! long min = sec / 60; ! sec = sec % 60; ! if (min == 0 && !printZeros) { ! return String.format("%s%s%02ds %03dms", w, w, sec, ms); ! } ! long hr = min / 60; ! min = min % 60; ! if (hr == 0 && !printZeros) { ! return String.format("%s%02dm:%02ds %03dms", w, min, sec, ms); } ! assert 60 * 60 * 1000 * hr + 60 * 1000 * min + 1000 * sec + ms == totalMillis; ! ! if(!printZeros){ ! return String.format("%2dh:%02dm:%02ds %03dms", hr, min, sec, ms); ! }else{ ! return String.format("%02dh:%02dm:%02ds %03dms", hr, min, sec, ms); } ! } + public static final String stripLeadingNumsUnderscore(String s) { + return regxp.substitute("s/^[0-9]+_//", s); + } ! /** Returns true if the string is non-null and non-whitespace */ ! public static final boolean hasContents(String s) { ! if (s == null) ! return false; ! return !s.trim().equals(""); ! } + /** Returns a representation of the current time without any + * spaces, usefull for use in temprorary file names, etc. + The format is month-day-year_[hr]h-[min]m + */ + public static final String timeForFile() { + Calendar c = Calendar.getInstance(); ! return c.get(c.MONTH) + "-" + c.get(c.DAY_OF_MONTH) + "-" + c.get(c.YEAR) ! + "_" + c.get(c.HOUR_OF_DAY) + "h-" + c.get(c.MINUTE) + "m"; ! } ! ! public static String readToString(InputStream in) { ! StringBuffer sb = new StringBuffer(); ! try { ! BufferedReader inbr = new BufferedReader(new InputStreamReader(in)); ! String line; ! while ((line = inbr.readLine()) != null) { ! sb.append(line); ! } ! } catch (IOException e) { ! log.error("IOException while reading from stream " + in + " to String.", ! e); ! return null; } + return sb.toString(); + } ! /** replaces all occurence of the "key" strings with the "value" ! * string in target String*/ ! public static final String simpleReplace(Map oldNew, String target) { ! Set entries = oldNew.entrySet(); ! Iterator iter = entries.iterator(); ! while (iter.hasNext()) { ! Map.Entry en = (Map.Entry) iter.next(); ! String key = (String) en.getKey(); ! String val = (String) en.getValue(); ! target = simpleReplace(target, key, val); } + return target; + } ! //replaces all occurences of old with subsValue in string ! public static final String simpleReplace(String string, String old, ! String subsValue) { ! try { ! return Util.substitute(matcher, compiler.compile(Perl5Compiler ! .quotemeta(old)), new StringSubstitution(subsValue), string, ! Util.SUBSTITUTE_ALL); ! } catch (MalformedPatternException e) { ! log.error("Error substituting for " + old + StringUtil.newline ! + " with subs value: " + StringUtil.newline + subsValue, e); ! return null; } + } ! public static AbstractList tokenize(String string) { ! StringTokenizer st = new StringTokenizer(string); ! ArrayList tokens = new ArrayList(); ! while (st.hasMoreTokens()) { ! tokens.add(st.nextToken()); } + return tokens; + } ! /** Tokenizes the string, treating strings quoted with " as a ! * single entry. Also parses numbers. The resulting List thus ! * has Strings and Doubles. Returns null if parsing fails.*/ ! public static AbstractList tokenizeWithQuotes(String string) { ! // StreamTokenizer seems to be pretty badly broken ... it ! // won't parse strings like "../CMU/Climbing" if number ! // parsing is disabled. so we reset everything, make ! // everything except whitespace word characters. then, for ! // each word we try to parse it as a double, and if that ! // succeeds we keep it as a double, if not we put the string ! // in the list. ! try { ! StringReader reader = new StringReader(string); ! StreamTokenizer st = new StreamTokenizer(reader); ! st.resetSyntax(); ! st.wordChars(0, 255); ! st.whitespaceChars(0, ' '); ! st.quoteChar('"'); ! st.slashSlashComments(false); ! st.slashStarComments(false); ! LinkedList tokens = new LinkedList(); ! while (st.nextToken() != StreamTokenizer.TT_EOF) { ! if (st.ttype == StreamTokenizer.TT_WORD || st.ttype == '"') { ! log.debug("Read Word or Quote" + st.sval); ! String s = st.sval; ! Double d = makeDouble(s); ! tokens.add((d == null) ? (Object) s : (Object) d); ! } else {//single character, convert to string and add ! char c = (char) st.ttype; ! log.warn("Got unexpected ttype " + st.ttype + " " + c + ", sval = " ! + st.sval + ", nval = " + st.nval); } ! } ! return tokens; ! } catch (IOException e) { ! log.error("tokenizing failed", e); ! return null; ! } ! } + /** Prefixes the string input with enough copies of pad that it + has length equal to length. Returns null and logs an error if + padding with pad cannot produce a string of exactly length. + Usually, pad should be a single character.*/ + public static String pad(String input, int length, String pad) { + StringBuffer sb = new StringBuffer(); + int padLength = length - input.length(); + while (sb.length() < padLength) { + sb.append(pad); + } + sb.append(input); + if (sb.length() != length) { + log.error("Could not pad \"" + input + "\" with \"" + pad + + "\" to get length " + length); + return null; } + return sb.toString(); ! } ! // --------------- Convert Objects to Strings, etc -------------------- // ! /** ! Takes an object input and makes an appropriate string, which can then ! be placed in the properties class. If the class type is unknown, ! returns the null string. ! @deprecated Use ObjectSerializer; ! */ ! public static String getObjectsString(Object o) { ! return ObjectSerializer.getStringForObject(o); ! } + /** + Takes the string input and tries to make it an instance of + type. If type is primitive, tries to create the appropriate + wrapped object. Returns null if input is null, if input is + "null", or if some error in conversion occurs. ! @deprecated Use ObjectSerializer; ! */ ! public static Object makeStringObject(String input) { ! return ObjectSerializer.getObjectForString(input); ! } ! // --------------- String Conversion Methods --------------- // ! ! public static Integer makeInteger(String s) { ! if (s == null) ! return null; ! Integer rval = null; ! try { ! rval = new Integer(s); ! } catch (NumberFormatException e) { ! return null; } + return rval; + } ! public static Short makeShort(String s) { ! if (s == null) ! return null; ! Short rval = null; ! try { ! rval = new Short(s); ! } catch (NumberFormatException e) { ! return null; } + return rval; + } ! public static Long makeLong(String s) { ! if (s == null) ! return null; ! Long rval = null; ! try { ! rval = new Long(s); ! } catch (NumberFormatException e) { ! return null; } + return rval; + } ! public static Float makeFloat(String s) { ! if (s == null) ! return null; ! Float rval = null; ! try { ! rval = new Float(s); ! } catch (NumberFormatException e) { ! return null; } ! return rval; ! } ! ! public static Double makeDouble(String s) { ! if (s == null) ! return null; ! Double rval = null; ! try { ! rval = new Double(s); ! } catch (NumberFormatException e) { ! return null; } + return rval; + } ! public static Boolean makeBoolean(String s) { ! if (s == null) ! return null; ! s = s.trim(); ! if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("yes") ! || s.equalsIgnoreCase("1")) { ! return new Boolean(true); ! } else { ! return new Boolean(false); } + } ! public static Byte makeByte(String s) { ! if (s == null) ! return null; ! Byte rval; ! try { ! rval = new Byte(s); ! } catch (NumberFormatException e) { ! return null; } + return rval; + } ! public static Character makeCharacter(String s) { ! if (s == null) ! return null; ! if (s.length() != 1) ! return null; ! return new Character(s.charAt(0)); ! } ! ! public static void main(String[] args) { ! long[] times = { 100, 13011, ! 60 * 60 * 1000 * 59 + 60 * 1000 * 32 + 1000 * 49 + 333, ! 60 * 60 * 1000 * 0 + 60 * 1000 * 32 + 1000 * 49 + 333, ! 60 * 60 * 1000 * 0 + 60 * 1000 * 0 + 1000 * 49 + 3, ! 60 * 60 * 1000 * 90 + 60 * 1000 * 0 + 1000 * 49 + 3, }; ! for (long t : times) { ! System.out.println(StringUtil.formatMillis(t)); } ! } } Index: FileUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/FileUtil.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** FileUtil.java 2 Aug 2006 21:36:16 -0000 1.13 --- FileUtil.java 29 Aug 2006 19:29:56 -0000 1.14 *************** *** 129,136 **** } public static boolean writeObjectToFile(File f, Serializable object){ try{ FileOutputStream ostream = new FileOutputStream(f); ! ObjectOutputStream p = new ObjectOutputStream(ostream); p.writeObject(object); p.flush(); --- 129,151 ---- } + public static boolean writeToFile(File f, double[] data){ + try { + Writer out = new FileWriter(f); + for(int i=0; i<data.length; i++){ + out.write(String.format("%.15g%n", data[i])); + } + out.close(); + } catch (IOException e) { + log.warn("Error writing array to file " + f, e); + return false; + } + return true; + } + + public static boolean writeObjectToFile(File f, Serializable object){ try{ FileOutputStream ostream = new FileOutputStream(f); ! ObjectOutputStream p = new ObjectOutputStream(new BufferedOutputStream(ostream)); p.writeObject(object); p.flush(); *************** *** 389,392 **** --- 404,409 ---- } + + public static DoubleArrayList readToDoubleArray(File f){ try{ Index: CernUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/CernUtil.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** CernUtil.java 29 Mar 2005 20:53:59 -0000 1.11 --- CernUtil.java 29 Aug 2006 19:29:56 -0000 1.12 *************** *** 3,6 **** --- 3,7 ---- import cern.colt.matrix.*; //import cern.colt.matrix.impl.*; + import cern.colt.matrix.impl.RCDoubleMatrix2D; import cern.colt.matrix.linalg.Algebra; import cern.colt.list.DoubleArrayList; *************** *** 11,14 **** --- 12,20 ---- import java.io.*; + import no.uib.cipr.matrix.Matrix; + import no.uib.cipr.matrix.MatrixEntry; + import no.uib.cipr.matrix.Vector; + import no.uib.cipr.matrix.VectorEntry; + import org.apache.log4j.Logger; *************** *** 18,25 **** public final class CernUtil{ - private static Logger log = Logger.getLogger(CernUtil.class); - - private static cern.jet.math.Functions F = cern.jet.math.Functions.functions; private static Algebra linalg = new Algebra(); --- 24,28 ---- *************** *** 32,35 **** --- 35,73 ---- + public static final String densityStatString(String prefix, + DoubleMatrix1D vector, double approxThresh){ + StringBuffer sb = new StringBuffer(prefix); + double fracNonzero = fractionNonzero(vector); + sb.append(String.format("%.3f%% nonzero", fracNonzero*100.0)); + if(approxThresh != 0){ + double approxNonzero = fractionNonzero(vector, approxThresh); + sb.append(String.format(", %.3f%% approx nonzero", + approxNonzero*100)); + } + return sb.toString(); + } + + + /** + * Note sure how efficient this actually is. + * @param m + * @return + */ + public static final DoubleMatrix2D makeRC(Matrix m){ + DoubleMatrix2D m2 = DoubleFactory2D.rowCompressed.make(m.numRows(), m.numColumns()); + for(MatrixEntry me : m){ + m2.set(me.row(), me.column(), me.get()); + } + return m2; + } + + public static final DoubleMatrix1D makeSparse(Vector v){ + DoubleMatrix1D nv = DoubleFactory1D.sparse.make(v.size()); + for(VectorEntry ve : v){ + nv.set(ve.index(), ve.get()); + } + return nv; + } + /* the bins are 1, ..., numBins (not 0, ... , numBins-1) so we can * use sparsity as a mask.*/ *************** *** 90,93 **** --- 128,138 ---- } + public static final int minNonzeroIndex(DoubleMatrix1D a){ + IntArrayList indexList = new IntArrayList(); + a.getNonZeros(indexList, null); + indexList.sort(); + return indexList.get(0); + } + protected static final boolean sanityCheckBins(DoubleMatrix2D in, DoubleMatrix2D out, int numBins){ int nr = in.rows(); *************** *** 166,169 **** --- 211,236 ---- } + public static final double fractionNonzero(DoubleMatrix1D a){ + return fractionNonzero(a, 0.0); + } + + public static final double fractionNonzero(DoubleMatrix1D a, double epsilon){ + if(epsilon == 0.0){ + return (double)a.cardinality()/a.size(); + }else{ + DoubleArrayList valueList = new DoubleArrayList(0); + a.getNonZeros(null, valueList); + int nnz = valueList.size(); + double count = 0; + for(int i = 0; i<nnz; i++){ + double v = valueList.get(i); + if(v > epsilon || v < -epsilon){ + count ++; + } + } + return count/(double)a.size(); + } + } + public static final double maxIgnoreZero(DoubleMatrix1D a){ int n = a.size(); |
|
From: Brendan M. <mc...@us...> - 2006-08-29 19:30:01
|
Update of /cvsroot/jigs/jigs/resource In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv3714/resource Modified Files: rl.lcf Log Message: Index: rl.lcf =================================================================== RCS file: /cvsroot/jigs/jigs/resource/rl.lcf,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** rl.lcf 2 Aug 2006 21:36:15 -0000 1.6 --- rl.lcf 29 Aug 2006 19:29:56 -0000 1.7 *************** *** 1,33 **** log4j.rootCategory=DEBUG, A1 - log4j.category.com.coyotegulch.jisp=DEBUG - log4j.category.edu.cmu.cs.mcmahan.rl.AdversaryLP.AdversaryLPSolver=DEBUG - log4j.category.edu.cmu.cs.mcmahan.rl.AdversaryLP.AdversaryPathPlanner=DEBUG - log4j.category.edu.whitman.util.ProcessUtil=DEBUG - - log4j.category.edu.cmu.cs.mcmahan.rl.PathPlan.CircularRewardRegion=DEBUG - log4j.category.edu.cmu.cs.mcmahan.rl.PathPlan.SequentialWrapper=DEBUG - log4j.category.edu.cmu.cs.mcmahan.rl.PathPlan.PathPlanPanel=INFO - log4j.category.edu.cmu.cs.mcmahan.rl.PathPlan.PathPlan=WARN - log4j.category.edu.cmu.cs.mcmahan.rl.PathPlan.AbstractPathPlanContinuousMDP=DEBUG - log4j.category.edu.cmu.cs.mcmahan.rl.PathPlan.PathPlanContinuousMDPSequential=DEBUG - - - log4j.category.edu.cmu.cs.mcmahan.rl.PathPlan.PathPlanExplicitMDP=DEBUG - - log4j.category.edu.cmu.cs.mcmahan.rl.ExplicitDiscretizedMDP=DEBUG - log4j.category.edu.cmu.cs.mcmahan.rl.PathPlan.DynamicAnimator=DEBUG - log4j.category.edu.cmu.cs.mcmahan.rl.PathPlan.DynamicPathPlannerImpl=DEBUG - log4j.category.edu.cmu.cs.mcmahan.rl.ValueIteration=DEBUG - log4j.category.edu.cmu.cs.mcmahan.rl.PolicyGradient=DEBUG - log4j.category.edu.cmu.cs.mcmahan.rl.PolicyGradient.GPOMDPEstimator=INFO - log4j.category.edu.cmu.cs.mcmahan.rl.PolicyGradient.ConjGradAscent=INFO - - - #log4j.category.edu.cmu.cs.mcmahan.rl.ValueIteration=WARN - #log4j.category.edu.whitman.util.PropProvider=WARN - # A1 is set to be a FileAppender which outputs to System.out. --- 1,7 ---- log4j.rootCategory=DEBUG, A1 + log4j.category.edu.cmu.cs.mcmahan.jmdp.game.convex.LbCplexConvexGameSolver=WARN # A1 is set to be a FileAppender which outputs to System.out. |
|
From: Brendan M. <mc...@us...> - 2006-08-10 22:53:39
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv11662/src/edu/whitman/halfway/util Modified Files: TimedQueue.java CplexUtil.java StringUtil.java ExecutionTimer.java Added Files: Timing.java Log Message: --- NEW FILE: Timing.java --- package edu.whitman.halfway.util; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; import org.apache.log4j.Logger; /** * Maintains a Map from strings (usually in a dotted notation) to ExecutionTimer * objects. Provides a useful way to print and manage a collection of named * ExcutionTimers for program instrumentation. * * Also provides a single static Timing object, Timing.t, which can be used for * convience for a single common set of timers for the currently running * application. Note: the instance that Timing.t can be changed. This is * useful if, say, individual timings for each iteration of a loop are need: * the code called inside the loop refers only to Timing.t, and the at the * beginning of each iteration a new Execution Timer is assigned to Timing.t. * * @author mcmahan * */ public class Timing { protected static Logger log = Logger.getLogger(Timing.class); public static Timing t = new Timing(); protected Map map = new HashMap(); public static void setStaticInstance(Timing t) { Timing.t = t; } /** Gets a timer from the map of name, or creates it if needed. */ protected ExecutionTimer getOrCreate(String name){ Object obj = map.get(name); if(obj != null) return (ExecutionTimer) obj; ExecutionTimer timer = new ExecutionTimer(name); map.put(name, timer); return timer; } protected ExecutionTimer get(String name){ return (ExecutionTimer) map.get(name); } /** * Starts the timer if it exists (without reseting), or creates and starts a * timer if it doesn't already exist. * @param name */ public void start(String name){ ExecutionTimer timer = getOrCreate(name); timer.start(); } public long stop(String name){ //we want to be as precise as possible, so we first read off the stop time // and only then look up the timer and call stop with the given time. long stopTime = System.currentTimeMillis(); ExecutionTimer timer = get(name); if(timer == null){ log.warn("Timer " + name + " doesn't exist, so can't stop it."); return -1; } return timer.stop(); } public long getElapsedTime(String name){ ExecutionTimer timer = get(name); if(timer == null){ log.warn("Timer " + name + " doesn't exist, so can't read from it."); return -1; } return timer.getElapsedTime(); } public boolean isRunning(String name){ ExecutionTimer timer = get(name); if(timer == null){ log.warn("Timer " + name + " doesn't exist, it can't be running."); return false; } return timer.isRunning(); } public String getAsString(String name){ ExecutionTimer timer = get(name); if(timer == null){ log.warn("Timer " + name + " doesn't exist, so can't read from it."); return "[invalid timer]"; } return timer.toString(); } public void incTime(String name, long ms){ ExecutionTimer timer = get(name); if(timer == null){ log.warn("Timer " + name + " doesn't exist, so can't increment it."); } timer.incTime(ms); } public int numRunning(){ int numRunning = 0; for(Object t : map.values()){ ExecutionTimer et = (ExecutionTimer) t; if(et.isRunning()) numRunning++; } return numRunning; } /** * Resets the timer to zero, stopping it if it is running. * If the timer doesn't already exist, it is created (but not started). * @param name */ public void reset(String name){ ExecutionTimer timer = getOrCreate(name); timer.reset(); } public String toString(){ ArrayList keys = new ArrayList(map.keySet()); Collections.sort(keys); int maxLength = 0; for(Object obj : keys){ String key = (String)obj; maxLength = (key.length() > maxLength) ? key.length() : maxLength; } StringBuffer sb = new StringBuffer(); String format = "%"+maxLength +"s = %s%n"; for(Object obj : keys){ String key = (String)obj; sb.append(String.format(format, key, get(key))); } return sb.toString(); } public static long sumTimes(String name, Collection timings){ long totalTimeMS = 0; for(Object obj : timings){ Timing t = (Timing) obj; totalTimeMS += t.getElapsedTime(name); } return totalTimeMS; } public static Timing sumTimings(Collection timings){ if(timings.size()==0) return new Timing(); Set keys = ((Timing)timings.iterator().next()).map.keySet(); Timing timing = new Timing(); for(Object k : keys){ String key = (String) k; long total = sumTimes(key, timings); timing.reset(key); timing.incTime(key, total); } return timing; } public static void main(String[] args){ long[] time = { 100, 13011, 60*60*1000*59 + 60*1000*32 + 1000*49 + 333, 60*60*1000*0 + 60*1000*32 + 1000*49 + 333, 60*60*1000*0 + 60*1000*0 + 1000*49 + 3, 60*60*1000*90 + 60*1000*0 + 1000*49 + 3}; String[] name = { "foo", "cplex.total", "cplex.build_problem", "row_oracle.compute", "funk.job", "zstart"}; //Timing t = new Timing(); for(int i=0; i<time.length; i++){ System.out.printf("adding %s with %s%n", name[i], time[i]); Timing.t.reset(name[i]); Timing.t.incTime(name[i], time[i]); } System.out.println(Timing.t); } } Index: TimedQueue.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/TimedQueue.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TimedQueue.java 6 Apr 2004 01:58:32 -0000 1.1 --- TimedQueue.java 10 Aug 2006 22:53:35 -0000 1.2 *************** *** 6,9 **** --- 6,10 ---- + /** Wrapper around a general int queue that times time spent by queue. Index: CplexUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/CplexUtil.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CplexUtil.java 12 Jan 2004 20:06:43 -0000 1.6 --- CplexUtil.java 10 Aug 2006 22:53:35 -0000 1.7 *************** *** 12,16 **** import org.apache.log4j.Logger; ! public class CplexUtil{ --- 12,21 ---- import org.apache.log4j.Logger; ! /** ! * Old way of accessing CPLEx via file system. ! * @deprecated ! * @author mcmahan ! * ! */ public class CplexUtil{ Index: StringUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/StringUtil.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** StringUtil.java 6 Aug 2006 18:35:30 -0000 1.11 --- StringUtil.java 10 Aug 2006 22:53:35 -0000 1.12 *************** *** 9,13 **** public final class StringUtil{ public static final String newline = System.getProperty("line.separator"); - public static final Formatter f = new Formatter(); static PatternMatcher matcher = new Perl5Matcher(); --- 9,12 ---- *************** *** 17,20 **** --- 16,45 ---- static Logger log = Logger.getLogger(StringUtil.class.getName()); + + public static final String formatMillis(long ms){ + String w = " "; + long totalMillis = ms; + long sec = ms / 1000; + ms = ms % 1000; + if(sec == 0){ + return String.format("%s%s%s %03dms",w,w,w, ms); + } + long min = sec / 60; + sec = sec % 60; + if (min ==0){ + return String.format("%s%s%02ds %03dms",w,w, sec, ms); + } + long hr = min / 60; + min = min % 60; + if (hr == 0){ + return String.format("%s%02dm:%02ds %03dms", w, min, sec, ms); + } + + assert 60*60*1000*hr + 60*1000*min + 1000*sec + ms == totalMillis; + + + return String.format("%dh:%02dm:%02ds %03dms", hr, min, sec, ms); + + } public static final String stripLeadingNumsUnderscore(String s){ *************** *** 277,280 **** --- 302,316 ---- } + public static void main(String[] args){ + long[] times = { 100, 13011, + 60*60*1000*59 + 60*1000*32 + 1000*49 + 333, + 60*60*1000*0 + 60*1000*32 + 1000*49 + 333, + 60*60*1000*0 + 60*1000*0 + 1000*49 + 3, + 60*60*1000*90 + 60*1000*0 + 1000*49 + 3, + }; + for (long t : times){ + System.out.println(StringUtil.formatMillis(t)); + } + } Index: ExecutionTimer.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/ExecutionTimer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ExecutionTimer.java 28 Feb 2005 15:50:53 -0000 1.3 --- ExecutionTimer.java 10 Aug 2006 22:53:35 -0000 1.4 *************** *** 1,5 **** --- 1,8 ---- package edu.whitman.halfway.util; + import org.apache.log4j.Logger; + public final class ExecutionTimer{ + protected static Logger log = Logger.getLogger(ExecutionTimer.class); boolean isRunning = false; *************** *** 7,10 **** --- 10,36 ---- long lastStartTime = 0; + protected String name; + + public ExecutionTimer(){ + this("Unnamed"); + } + + public ExecutionTimer(String name){ + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isRunning(){ + return isRunning; + } + + public final void reset(){ isRunning = false; *************** *** 15,19 **** public final void start(){ ! if(isRunning) throw new IllegalArgumentException("Timer is already running."); isRunning = true; lastStartTime = System.currentTimeMillis(); --- 41,50 ---- public final void start(){ ! if(isRunning){ ! log.warn(String.format( ! "Timer %s is already running, ignoring call to start.", ! getName())); ! //throw new IllegalArgumentException("Timer is already running."); ! } isRunning = true; lastStartTime = System.currentTimeMillis(); *************** *** 21,26 **** public long stop(){ ! long stopTime = System.currentTimeMillis(); ! if(!isRunning) throw new IllegalArgumentException("Can't stop a timer that isn't running"); long delta = stopTime - lastStartTime; elapsedTime += delta; --- 52,67 ---- public long stop(){ ! return stop(System.currentTimeMillis()); ! } ! ! public void incTime(long ms){ ! elapsedTime += ms; ! } ! ! public long stop(long stopTime){ ! if(!isRunning){ ! log.warn("Timer " + getName() + " isn't running, so can't stop it."); ! //throw new IllegalArgumentException("Can't stop a timer that isn't running"); ! } long delta = stopTime - lastStartTime; elapsedTime += delta; *************** *** 33,35 **** --- 74,80 ---- return elapsedTime + (System.currentTimeMillis() - lastStartTime); } + + public String toString(){ + return StringUtil.formatMillis(getElapsedTime()); + } } |
|
From: Brendan M. <mc...@us...> - 2006-08-06 19:02:49
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21205/src/edu/whitman/halfway/util Modified Files: MiscUtil.java Log Message: Index: MiscUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/MiscUtil.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** MiscUtil.java 6 Aug 2006 01:27:18 -0000 1.21 --- MiscUtil.java 6 Aug 2006 19:02:46 -0000 1.22 *************** *** 23,31 **** public static final void reverse(int[] a){ ! for(int i=0, j=a.length-1; i<a.length; i++, j--){ int temp = a[i]; a[i] = a[j]; a[j] = temp; } } --- 23,34 ---- public static final void reverse(int[] a){ ! //System.out.println("Reversing " + toString(a)); ! //dividing a.length by 2 is important, otherwise does nothing! ! for(int i=0, j=a.length-1; i<a.length/2; i++, j--){ int temp = a[i]; a[i] = a[j]; a[j] = temp; } + //System.out.println("reverse = " + toString(a)); } *************** *** 1011,1014 **** --- 1014,1018 ---- BitVector bv = new BitVector(n); for(int i=0; i<n; i++){ + if(a[i] < 0 || a[i] >= n) return false; bv.set(a[i]); } |
|
From: Brendan M. <mc...@us...> - 2006-08-06 18:35:34
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv10318/src/edu/whitman/halfway/util Modified Files: StringUtil.java Log Message: Index: StringUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/StringUtil.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** StringUtil.java 2 Aug 2006 21:36:16 -0000 1.10 --- StringUtil.java 6 Aug 2006 18:35:30 -0000 1.11 *************** *** 9,13 **** public final class StringUtil{ public static final String newline = System.getProperty("line.separator"); ! static PatternMatcher matcher = new Perl5Matcher(); static PatternCompiler compiler = new Perl5Compiler(); --- 9,14 ---- public final class StringUtil{ public static final String newline = System.getProperty("line.separator"); ! public static final Formatter f = new Formatter(); ! static PatternMatcher matcher = new Perl5Matcher(); static PatternCompiler compiler = new Perl5Compiler(); |
|
From: Brendan M. <mc...@us...> - 2006-08-06 01:27:31
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/jigs/renderers/swigs In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv12721/src/edu/whitman/halfway/jigs/renderers/swigs Modified Files: DesertRenderEngine.java Log Message: Index: DesertRenderEngine.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/jigs/renderers/swigs/DesertRenderEngine.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** DesertRenderEngine.java 2 Aug 2006 21:36:16 -0000 1.10 --- DesertRenderEngine.java 6 Aug 2006 01:27:18 -0000 1.11 *************** *** 23,27 **** //DesertThumbnailPage thumbnailPage; //see thumbnailPage in superclass ! DesertRenderUtil renderUtil = new DesertRenderUtil(); boolean stripLeadingNumbers = JigsPrefs.getBoolean(JigsPrefs.REMOVE_LEADING_FILE_NUMS); --- 23,27 ---- //DesertThumbnailPage thumbnailPage; //see thumbnailPage in superclass ! //DesertRenderUtil DesertRenderUtil = new DesertRenderUtil(); boolean stripLeadingNumbers = JigsPrefs.getBoolean(JigsPrefs.REMOVE_LEADING_FILE_NUMS); *************** *** 39,43 **** treePage = new DesertTreePage(getTemplateFile("tree.html")); ! thumbType = renderUtil.getThumbType(types); System.out.println("Using " + (useBrentsOptions ? "Brent's " : "Brendan's ") + "render options."); --- 39,43 ---- treePage = new DesertTreePage(getTemplateFile("tree.html")); ! thumbType = DesertRenderUtil.getThumbType(types); System.out.println("Using " + (useBrentsOptions ? "Brent's " : "Brendan's ") + "render options."); *************** *** 78,82 **** //log.warn("Getting treeTable."); Map subs = new HashMap(2); ! subs.put("<!--treeTable-->", renderUtil.getAlbumTree(album, outputDir, stripLeadingNumbers)); return subs; } --- 78,82 ---- //log.warn("Getting treeTable."); Map subs = new HashMap(2); ! subs.put("<!--treeTable-->", DesertRenderUtil.getAlbumTree(album, outputDir, stripLeadingNumbers)); return subs; } *************** *** 99,123 **** subs.put("<!--pathlinks-->", useBrentsOptions ? ! renderUtil.getPathLinks(album, outputDir, null, false, stripLeadingNumbers, null) ! : renderUtil.getPathLinks(album, outputDir, null, false, stripLeadingNumbers, null)); ! subs.put("<!--album_title-->", renderUtil.getTitle(album, stripLeadingNumbers)); ! subs.put("<!--album_date-->", renderUtil.getAlbumDateRange(album)); ! subs.put("<!--album_num_pictures_string-->", renderUtil.numPicsString(album)); ! subs.put("<!--album_desc-->", renderUtil.getShortDesc(album)); ! subs.put("<!--n-->", renderUtil.getNumPicturesAndAlbums(album)); ! subs.put("<!--dateNumInfo-->", renderUtil.getNumDateInfo(album)); ! subs.put("<!--thumb_page_links-->", renderUtil.getNumPageLinks(album, page, outputDir)); ! String next = renderUtil.makeRelativeLinkEnd(page, page.NEXT, "next", "first", outputDir); ! String prev = renderUtil.makeRelativeLinkEnd(page, page.PREV, "prev", "last", outputDir); subs.put("<!--next_thumb_page-->", next); --- 99,123 ---- subs.put("<!--pathlinks-->", useBrentsOptions ? ! DesertRenderUtil.getPathLinks(album, outputDir, null, false, stripLeadingNumbers, null) ! : DesertRenderUtil.getPathLinks(album, outputDir, null, false, stripLeadingNumbers, null)); ! subs.put("<!--album_title-->", DesertRenderUtil.getTitle(album, stripLeadingNumbers)); ! subs.put("<!--album_date-->", DesertRenderUtil.getAlbumDateRange(album)); ! subs.put("<!--album_num_pictures_string-->", DesertRenderUtil.numPicsString(album)); ! subs.put("<!--album_desc-->", DesertRenderUtil.getShortDesc(album)); ! subs.put("<!--n-->", DesertRenderUtil.getNumPicturesAndAlbums(album)); ! subs.put("<!--dateNumInfo-->", DesertRenderUtil.getNumDateInfo(album)); ! subs.put("<!--thumb_page_links-->", DesertRenderUtil.getNumPageLinks(album, page, outputDir)); ! String next = DesertRenderUtil.makeRelativeLinkEnd(page, page.NEXT, "next", "first", outputDir); ! String prev = DesertRenderUtil.makeRelativeLinkEnd(page, page.PREV, "prev", "last", outputDir); subs.put("<!--next_thumb_page-->", next); *************** *** 154,163 **** OutputPageSpec relpage = album.getOutputAlbum().getSpecForPicture(imagePage, pi); String imagePageURL = relpage.getLink().getRelativePath(outputDir); ! Image thumb = p.getImage(renderUtil.getThumbType(p)); table.append("<td align=\"center\" class=\""+clasType + "\">" + StringUtil.newline + "<a href=\"" + imagePageURL +"\">" ! + thumb.getLink().getLinkTag(renderUtil.getAlt(p, thumb), outputDir, "border=\"0\" class=\"thumbnail\"") + "</a>" + StringUtil.newline + "</td>" + StringUtil.newline); --- 154,163 ---- OutputPageSpec relpage = album.getOutputAlbum().getSpecForPicture(imagePage, pi); String imagePageURL = relpage.getLink().getRelativePath(outputDir); ! Image thumb = p.getImage(DesertRenderUtil.getThumbType(p)); table.append("<td align=\"center\" class=\""+clasType + "\">" + StringUtil.newline + "<a href=\"" + imagePageURL +"\">" ! + thumb.getLink().getLinkTag(DesertRenderUtil.getAlt(p, thumb), outputDir, "border=\"0\" class=\"thumbnail\"") + "</a>" + StringUtil.newline + "</td>" + StringUtil.newline); *************** *** 195,205 **** subs.put("<!--pathlinks-->", ! renderUtil.getPathLinks(album, outputDir, null, false, stripLeadingNumbers, null)); ! subs.put("<!--album_title-->", renderUtil.getTitle(album, stripLeadingNumbers)); ! subs.put("<!--album_date-->", renderUtil.getAlbumDateRange(album)); ! subs.put("<!--album_num_subalbums_string-->", renderUtil.numSubalbumsString(album)); ! subs.put("<!--album_desc-->", renderUtil.getShortDesc(album)); subs.put("<!--subalbum_table-->", getSubalbumTable(album, outputDir)); return subs; --- 195,205 ---- subs.put("<!--pathlinks-->", ! DesertRenderUtil.getPathLinks(album, outputDir, null, false, stripLeadingNumbers, null)); ! subs.put("<!--album_title-->", DesertRenderUtil.getTitle(album, stripLeadingNumbers)); ! subs.put("<!--album_date-->", DesertRenderUtil.getAlbumDateRange(album)); ! subs.put("<!--album_num_subalbums_string-->", DesertRenderUtil.numSubalbumsString(album)); ! subs.put("<!--album_desc-->", DesertRenderUtil.getShortDesc(album)); subs.put("<!--subalbum_table-->", getSubalbumTable(album, outputDir)); return subs; *************** *** 224,247 **** subs.put("<!--subalbum_title_link-->", ! sub.getOutputAlbum().getLink().getLinkTag(renderUtil.getTitle(sub, stripLeadingNumbers), outputDir)); ! subs.put("<!--subalbum_date-->", renderUtil.getAlbumDateRange(sub)); //subs.put("<!--subalbum_date_range-->", renderUtil.getAlbumDateRange(sub)); ! Picture samplePic = renderUtil.getSamplePicture(sub); ! Image sampleImage = samplePic.getImage(renderUtil.getThumbType(samplePic)); subs.put("<!--subalbum_thumbnail_img_link-->", sub.getOutputAlbum().getLink().getLinkTag (sampleImage.getLink().getLinkTag ! (renderUtil.getAlt(samplePic, sampleImage), outputDir, " border=\"0\" class=\"subalbum_thumbnail\""), outputDir)); if(!useBrentsOptions){ ! subs.put("<!--subalbum_desc-->", renderUtil.getShortDesc(sub)); }else{ ! String s = renderUtil.getShortDesc(sub); if (s == null || s.trim().equals("")) { subs.put("<!--subalbum_desc-->", ""); --- 224,247 ---- subs.put("<!--subalbum_title_link-->", ! sub.getOutputAlbum().getLink().getLinkTag(DesertRenderUtil.getTitle(sub, stripLeadingNumbers), outputDir)); ! subs.put("<!--subalbum_date-->", DesertRenderUtil.getAlbumDateRange(sub)); //subs.put("<!--subalbum_date_range-->", renderUtil.getAlbumDateRange(sub)); ! Picture samplePic = DesertRenderUtil.getSamplePicture(sub); ! Image sampleImage = samplePic.getImage(DesertRenderUtil.getThumbType(samplePic)); subs.put("<!--subalbum_thumbnail_img_link-->", sub.getOutputAlbum().getLink().getLinkTag (sampleImage.getLink().getLinkTag ! (DesertRenderUtil.getAlt(samplePic, sampleImage), outputDir, " border=\"0\" class=\"subalbum_thumbnail\""), outputDir)); if(!useBrentsOptions){ ! subs.put("<!--subalbum_desc-->", DesertRenderUtil.getShortDesc(sub)); }else{ ! String s = DesertRenderUtil.getShortDesc(sub); if (s == null || s.trim().equals("")) { subs.put("<!--subalbum_desc-->", ""); *************** *** 259,263 **** } ! subs.put("<!--subalbum_num_info-->", renderUtil.getNumPicturesAndAlbums(sub)); table.append(RenderUtil.doSubs(subAlbBlockString, subs, true)); --- 259,263 ---- } ! subs.put("<!--subalbum_num_info-->", DesertRenderUtil.getNumPicturesAndAlbums(sub)); table.append(RenderUtil.doSubs(subAlbBlockString, subs, true)); *************** *** 332,337 **** subs.put("<!--image_pathlinks-->", ! renderUtil.getPathLinks ! (album, outputDir, renderUtil.getTitle(p, stripLeadingNumbers), true, stripLeadingNumbers, thumbPages[index])); --- 332,337 ---- subs.put("<!--image_pathlinks-->", ! DesertRenderUtil.getPathLinks ! (album, outputDir, DesertRenderUtil.getTitle(p, stripLeadingNumbers), true, stripLeadingNumbers, thumbPages[index])); *************** *** 350,356 **** // Brents (now Brendan's too) Nav Strings ! next = renderUtil.makeRelativeLinkEnd(page, page.NEXT, "next", "first", outputDir); ! prev = renderUtil.makeRelativeLinkEnd(page, page.PREV, "prev", "last", outputDir); if( next != null && prev != null) navString = prev +" | " + next; --- 350,356 ---- // Brents (now Brendan's too) Nav Strings ! next = DesertRenderUtil.makeRelativeLinkEnd(page, page.NEXT, "next", "first", outputDir); ! prev = DesertRenderUtil.makeRelativeLinkEnd(page, page.PREV, "prev", "last", outputDir); if( next != null && prev != null) navString = prev +" | " + next; *************** *** 360,372 **** ! subs.put("<!--photographer-->", renderUtil.getPhotographer(p)); //we want to decide these strings all at once ! String title = renderUtil.getTitle(p, stripLeadingNumbers); //String btitle = renderUtil.getTitle(p, false); ! String dateTime = renderUtil.getPicDateString(p); String location = (String)p.getDescriptionInfo().getData("location"); ! String desc = renderUtil.getShortDesc(p); Image origImage = ImageSourceProvider.getDefaultImageSource().getImage(p.getMediaKey(), --- 360,372 ---- ! subs.put("<!--photographer-->", DesertRenderUtil.getPhotographer(p)); //we want to decide these strings all at once ! String title = DesertRenderUtil.getTitle(p, stripLeadingNumbers); //String btitle = renderUtil.getTitle(p, false); ! String dateTime = DesertRenderUtil.getPicDateString(p); String location = (String)p.getDescriptionInfo().getData("location"); ! String desc = DesertRenderUtil.getShortDesc(p); Image origImage = ImageSourceProvider.getDefaultImageSource().getImage(p.getMediaKey(), *************** *** 375,381 **** subs.put("<!--image_desc-->", useBrentsOptions ? ! renderUtil.getDesc(p) : desc); ! subs.put("<!--borig_image_size-->", renderUtil.getImageSizeFileSize(origImage)); subs.put("<!--borig_image_link-->", origImage.getLink().getRelativePath(outputDir)); --- 375,381 ---- subs.put("<!--image_desc-->", useBrentsOptions ? ! DesertRenderUtil.getDesc(p) : desc); ! subs.put("<!--borig_image_size-->", DesertRenderUtil.getImageSizeFileSize(origImage)); subs.put("<!--borig_image_link-->", origImage.getLink().getRelativePath(outputDir)); *************** *** 439,446 **** Image[] images = p.getImageArray(); Arrays.sort(images); ! ImageType thumbType = renderUtil.getThumbType(p); int nsil = images.length/2; ! noscriptImageLink = images[nsil].getLink().getLinkTag(renderUtil.getAlt(p, images[nsil]), outputDir, " border=\"0\" "); StringBuffer fb = new StringBuffer("["); --- 439,446 ---- Image[] images = p.getImageArray(); Arrays.sort(images); ! ImageType thumbType = DesertRenderUtil.getThumbType(p); int nsil = images.length/2; ! noscriptImageLink = images[nsil].getLink().getLinkTag(DesertRenderUtil.getAlt(p, images[nsil]), outputDir, " border=\"0\" "); StringBuffer fb = new StringBuffer("["); *************** *** 464,468 **** na++; ! String alt = renderUtil.getAlt(p, images[i]); ImageLink link = (ImageLink)images[i].getLink(); --- 464,468 ---- na++; ! String alt = DesertRenderUtil.getAlt(p, images[i]); ImageLink link = (ImageLink)images[i].getLink(); |
|
From: Brendan M. <mc...@us...> - 2006-08-06 01:27:22
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv12721/src/edu/whitman/halfway/util Modified Files: MiscUtil.java Log Message: Index: MiscUtil.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/MiscUtil.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** MiscUtil.java 29 Mar 2005 16:06:14 -0000 1.20 --- MiscUtil.java 6 Aug 2006 01:27:18 -0000 1.21 *************** *** 22,25 **** --- 22,33 ---- + public static final void reverse(int[] a){ + for(int i=0, j=a.length-1; i<a.length; i++, j--){ + int temp = a[i]; + a[i] = a[j]; + a[j] = temp; + } + } + /* Returns true if a contains any element appearing in b */ public static final boolean containsAny(Collection a, Collection b){ |
|
From: Brendan M. <mc...@us...> - 2006-08-04 14:45:14
|
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/util In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv3566/src/edu/whitman/halfway/util Modified Files: MatrixTextGridPainter.java Log Message: Fixed imports. Index: MatrixTextGridPainter.java =================================================================== RCS file: /cvsroot/jigs/jigs/src/edu/whitman/halfway/util/MatrixTextGridPainter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MatrixTextGridPainter.java 23 Feb 2005 00:10:17 -0000 1.1 --- MatrixTextGridPainter.java 4 Aug 2006 14:45:10 -0000 1.2 *************** *** 1,12 **** package edu.whitman.halfway.util; ! import org.apache.log4j.Logger; ! // import javax.swing.border.Border; ! // import javax.swing.*; ! import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; ! import cern.colt.list.*; ! import java.util.*; /** Display text (usually a single character) into each cell of a --- 1,17 ---- package edu.whitman.halfway.util; ! import java.awt.Color; ! import java.awt.Composite; ! import java.awt.Font; ! import java.awt.FontMetrics; ! import java.awt.Graphics2D; ! import java.awt.Rectangle; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; ! import java.util.ArrayList; ! ! import org.apache.log4j.Logger; ! ! import cern.colt.list.IntArrayList; /** Display text (usually a single character) into each cell of a |
|
From: Brendan M. <mc...@us...> - 2006-08-02 21:43:15
|
Update of /cvsroot/jigs/jigs/resource/renderer/swigs/gray_templates In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv14998/resource/renderer/swigs/gray_templates Added Files: image.html imagelist.html subalbum.html thumbnail.html tree.html Log Message: more good stuffcvs up -d --- NEW FILE: image.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> <title><!--title--></title> <LINK REL=StyleSheet HREF="<!--res:style.css-->" TYPE="text/css" MEDIA=screen> </head> <body class="outside"> <table cellpadding="0" border="0" > <tr><td colspan="2"> <table class="mainbody" border="0" cellpadding="0" cellspacing="0" align="center" width="600"> <tr><td> <table class="topbar" width="100%"><tr><td> <tr> <td valign=middle align=left> <span class="albumtitle"><!--title--></span> </td> <td align="right"> <A HREF = "<!--thumbpage-->">thumbnails</A> </td> </tr> <tr> <td colspan="2" class="pathlinks"> <!--albumPathLinks--> </td> </tr> </table> </td> </tr> <tr> <td> </td></tr> <tr > <td> <table align="center" border="0" cellpadding="0" cellspacing="0"> <tr class="picturelinks"> <td align="left"> <!--previmage--> </td> <td align="center"> <!--sizelinks--> </td> <td align="right"> <!--nextimage--> </td> </tr> <tr align="center"> <td colspan="3"> <!--image--> </td> </tr> <tr class="caption"> <td colspan=3 align = "right"><!--pictureinfo--> </td> </tr> </table> <tr> <td> </td></tr> <tr> <td> <!--desctable--> </td> </tr> <tr> <td> </td></tr> <tr> <td> <table class="bottombar" cellspacing=0 cellpadding=5 border=0 width="100%"> <tr> <td class="topbarlink" align=left width="33%"> <!--previmage--></td> <td class="topbarlink" align=center width="33%"> <A HREF = "<!--thumbpage-->">thumbnails</A> </td> <td class="topbarlink" align=right width="33%"> <!--nextimage--></td> </tr> </table> </td> </tr> </table> </td></tr> <tr class="footer"> <td width="50%" align="left"> return to <a href="http://www.cs.cmu.edu/~mcmahan">Brendan's Homepage</a> </td> <td align="right" width="50%"> created with <a href="http://jigs.sourceforge.net/">Jigs</a> </td></tr> </table> </body> </html> --- NEW FILE: imagelist.html --- <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> <title><!--albumTitle--></title> </head> <body bgcolor="<!--outside.backColor-->" vlink="#000000" link="#002085" alink="0000FF"> <table bgcolor="<!--inside.backColor-->" border="0" cellpadding="0" cellspacing="0" align="center" width="600"> <tr> <td> <table cellpadding="6" cellspacing="0" width="100%" border="0" bgcolor="<!--mainBar.backColor-->" ><tr><td> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tr> <td valign=middle align=left> <font size=4 color="<!--mainBar.titleColor-->"><!--albumTitle--></font> </td> <td align="right"> <font size=2 color="<!--mainBar.titleColor-->"><!--numInfo--></font> </td> </tr> <tr> <td colspan="2"> <!--albumPathLinks--> </td> </tr> </table> </td></tr></table> </td> </tr> <tr> <td> <table border="0" cellpadding="4" cellspacing="0" align="left" > <tr> <td valign=top bgcolor="<!--subBar.backColor-->"> <table cellpadding="1" cellspacing="0" border="0"> <tr> <td colspan="2"> In This Album: </td> </tr> <tr> <td> </td> <td> <table cellpadding="1" cellspacing="0" bgcolor="<!--subBar.backColor-->" border="0"> <!--navBarRows--> </table> </td> </tr> </table> </td><td> </td> <td valign="top"> <!--albumDesc--> </td> </tr> </table> </td> </tr> <tr> <td> </td> </tr> <tr> <td bgcolor ="<!--mainBar.backColor-->"> <table ><tr><td> <font size="3" color="<!--mainBar.titleColor-->"><b>Image List</b></font> </td></tr> </table> </td> </tr> <tr> <td> <br> <table width="100%" cellpadding="0" cellspacing="0" border=0> <tr><td> </td> <td> <!--imageListTable--> </td> </tr> </table> <br> </td> </tr> <tr> <td bgcolor ="<!--mainBar.backColor-->"> <table cellpadding="0"><tr><td> <font size="4"> </font> </td></tr> </table> </td> </tr> </table> </body> </html> --- NEW FILE: subalbum.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> <title><!--albumTitle--></title> <LINK REL=StyleSheet HREF="<!--res:style.css-->" TYPE="text/css" MEDIA=screen> </head> <body class="outside"> <table cellpadding="0" border="0" > <tr><td colspan="2"> <table class="mainbody" cellpadding="0" cellspacing="0" width="600" align="center"> <tr> <td> <table class="topbar" width="100%"><tr><td> <tr> <td valign=middle align=left> <span class="albumtitle"><!--albumTitle--></span </td> <td align="right"> <span class="dateinfo"><!--dateInfo--></span> </td> </tr> <tr> <td class="pathlinks"> <!--albumPathLinks--> </td> <td align="right"> <span class="numinfo"><!--numInfo--></span> </td> </tr> </table> </td> </tr> <tr> <td class="albumdesc"> <!--albumDesc--> </td> </tr> <tr> <td> </td> </tr> <tr > <td class="midbar"> Sub Albums </td> </tr> <tr class = "subalbumtable"> <td > <!--subalbumtable--> </td> </tr> <tr> <td class="bottombar"> </td> </tr> </table> </td></tr> <tr class="footer"> <td width="50%" align="left"> return to <a href="http://www.cs.cmu.edu/~mcmahan">Brendan's Homepage</a> </td> <td align="right" width="50%"> created with <a href="http://jigs.sourceforge.net/">Jigs</a> </td></tr> </table> </body> </html> --- NEW FILE: thumbnail.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> <title><!--albumTitle--></title> <LINK REL=StyleSheet HREF="<!--res:style.css-->" TYPE="text/css" MEDIA=screen> </head> <body class="outside"> <table cellpadding="0" border="0" > <tr><td colspan="2"> <table class="mainbody" cellpadding="0" border="0" cellspacing="0" align="center" width="800"> <tr> <td> <table class="topbar" width="100%"> <tr> <td valign=middle align=left> <span class="albumtitle"><!--albumTitle--></span> </td> <td align="right"> <span class="dateinfo"><!--dateInfo--></span> </td> </tr> <tr> <td class="pathlinks"> <!--albumPathLinks--> </td> <td align="right"> <span class="numinfo"><!--numInfo--></span> </td> </tr> </table> </td> </tr> <tr> <td class="albumdesc"> <!--albumDesc--> </td> </tr> <tr><td> </td></tr> <tr> <td> <table class="midbar" width="100%" > <tr > <td align="left"> Thumbnails <!--thumbNumberLinks--> </td> <td></td> <td align="right" valign=bottom> <!--thumbPageNumber--> </td> </tr> <tr> <td align="left"> <!--prevThumbpage--> </td> <td></td> <td align="right"> <!--nextThumbpage--> </td> </tr> </table> </td> </tr> <tr> <td> <table> <tr> <td valign = "top" align="center"> <!--thumbTable--> </td> </tr> </table> </td> </tr> <tr><td> <table class = "bottombar" width="100%"> <tr> <td align="left" > <!--prevThumbpage--> </td> <td align="center" width="100%"> <!--thumbNumberLinks--> </td> <td align="right" > <!--nextThumbpage--> </td> </tr> </table> </td></tr> </table> </td></tr> <tr class="footer"> <td width="50%" align="left"> return to <a href="http://www.cs.cmu.edu/~mcmahan">Brendan's Homepage</a> </td> <td align="right" width="50%"> created with <a href="http://jigs.sourceforge.net/">Jigs</a> </td></tr> </table> </body> </html> --- NEW FILE: tree.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> <title>Album Tree</title> <LINK REL=StyleSheet HREF="<!--res:style.css-->" TYPE="text/css" MEDIA=screen> </head> <body class="outside"> <table cellpadding="0" border="0" > <tr><td colspan="2"> <table class="mainbody" cellpadding="5" cellspacing="0" align="center" width="600"> <tr class="topbar" > <td class="albumtitle"> Album Tree </td> </tr> <tr> <td> <!--treeTable--> </td> </tr> <tr class="bottombar"> <td > </td> </tr> </table> </td></tr> <tr class="footer"> <td width="50%" aligh="left"> return to <a href="http://www.cs.cmu.edu/~mcmahan">Brendan's Homepage</a> </td> <td align="right" width="50%"> created with <a href="http://jigs.sourceforge.net/">Jigs</a> </td></tr> </table> </body> </html> |
Update of /cvsroot/jigs/jigs/src/edu/whitman/halfway/jigs/cmdline In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv14998/src/edu/whitman/halfway/jigs/cmdline Added Files: CopyOrig.java ExplicitAlbumCopy.java FindBadAlbums.java LowercaseCategories.java WriteCategoriesToExif.java Log Message: more good stuffcvs up -d --- NEW FILE: CopyOrig.java --- package edu.whitman.halfway.jigs.cmdline; import edu.whitman.halfway.jigs.*; import edu.whitman.halfway.util.*; // import gnu.getopt.Getopt; import java.util.Iterator; import org.apache.log4j.Logger; import java.io.File; public class CopyOrig extends AbstractCmdLine { protected static Logger log = Logger.getLogger(CategoryList.class); static int[] opts = { RECURSE_ALBUM, LOG4J_FILE, RECURSIVE, HELP }; public CopyOrig() { super(opts); } public String getAdditionalParseArgs() { return "O"; } protected int getDesiredNumArgs(){ return 1; } public static void main(String[] args) { (new CopyOrig()).mainDriver(args); } public void doMain() { CategorySet cats = new CategorySet(); Album album = getAlbum(); assert album.getAlbumHierarchy().getImageSource() == null; final File outputDir = new File(argsLeft[0]); if(!outputDir.exists()){ outputDir.mkdirs(); } System.out.println("Beginning to copy."); AlbumUtil.mediaItemWalk (album, new MediaItemFunction(){ public void process(MediaItem item){ if(item instanceof Picture){ Picture pic = (Picture)item; String path = pic.getMediaKey().getString(); File mediaFile = new File(path); if (! (mediaFile.exists() && mediaFile.isFile())){ log.error("Not copying invalid media key: " + mediaFile); }else{ String[] split = FileUtil.splitFileToArray(path); int n = split.length; String name = (n >= 2 ? StringUtil.stripLeadingNumsUnderscore(split[n-2]) + "_" + split[n-1] : split[n-1]); File target = new File(outputDir, name); //System.out.println("Copying " + mediaFile +"\n\t to " + target); if(!target.exists()){ FileUtil.copy(mediaFile, target); } //See if orig exists. if(hasOption('O')){ File origSource = new File(new File(mediaFile.getParentFile(), "orig"), mediaFile.getName()); if(origSource.isFile()){ // if(!hasOption("O")){ name = (n >= 2 ? StringUtil.stripLeadingNumsUnderscore(split[n-2]) + "_" + FileUtil.insertBeforeExtension(split[n-1], "_orig") : FileUtil.insertBeforeExtension(split[n-1], "_orig")); //}else{ // name = FileUtil.insertBeforeExtension(split[n-1], "_orig"); //} File target2 = new File(outputDir, name); //System.out.println("Copying " + origSource +"\n\t to " + target2); if(!target2.exists()){ FileUtil.copy(origSource, target2); } }else{ //System.out.println(origSource + " is not a file."); } } } } } }, recurse); } protected void specificUsage() { System.out.println( "Usage: CopyOrig -d [album_directory] [destination_directory]" +StringUtil.newline //"\tdefault is to copy \"flat\", all files into one directory" + //+StringUtil.newline+ //"\tdefault is to copy orig w/ \"_orig\" suffix" + //+ StringUtil.newline + "[destination_directory]: directory where originals are copied." + StringUtil.newline //+ "-T: copy directories (e.g., make tree structure)." + StringUtil.newline + "-O: copy originals as well" + StringUtil.newline); } } --- NEW FILE: ExplicitAlbumCopy.java --- package edu.whitman.halfway.jigs.cmdline; import edu.whitman.halfway.jigs.*; import edu.whitman.halfway.util.*; // import gnu.getopt.Getopt; import java.util.Iterator; import org.apache.log4j.Logger; import java.io.File; public class ExplicitAlbumCopy extends AbstractCmdLine { protected static Logger log = Logger.getLogger(CategoryList.class); static int[] opts = { RECURSE_ALBUM, LOG4J_FILE, RECURSIVE, HELP }; public ExplicitAlbumCopy() { super(opts); } protected int getDesiredNumArgs(){ return 1; } //public String getAdditionalParseArgs() { // return "A"; //} public static void main(String[] args) { (new ExplicitAlbumCopy()).mainDriver(args); } public void doMain() { CategorySet cats = new CategorySet(); Album album = getAlbum(); assert album.getAlbumHierarchy().getImageSource() == null; File outputDir = new File(argsLeft[0]); if(!outputDir.exists()){ outputDir.mkdirs(); } copyAlbum(album, outputDir); } File currentDir = null; protected void copyAlbum(Album album, File newDir){ //if(album.getDepth() <= 2){ // System.out.println("Copying " + album + " to " + newDir); //} // copy album.txt if applicable AlbumDescriptionInfo info = album.getAlbumDescriptionInfo(); File newAlbumInfo = new File(newDir, "album.txt"); info.saveFile(newAlbumInfo); //XXX to save memory, ditch info here // includes for pictures MediaItem[] pics = album.getMediaItems(); StringBuffer includeFileString = new StringBuffer(); for(int i=0; i<pics.length; i++){ includeFileString.append("PictureInclude "); String path = pics[i].getMediaKey().getString(); File mediaFile = new File(path); if (! (mediaFile.exists() && mediaFile.isFile())){ log.error("Not including invalid media key: " + mediaFile); }else{ includeFileString.append(path).append(StringUtil.newline); } } //XXX to save memory, ditch mediaItems here File includeFile = new File(newDir, "includes.txt"); if(!FileUtil.writeStringToFile(includeFile, includeFileString.toString())){ exitError("Failled to write to " + includeFile); } includeFileString = null; Album[] subalbums = album.getSubAlbums(); if((subalbums != null) && subalbums.length > 0){ for(int i=0; i< subalbums.length; i++){ String name = subalbums[i].getName(); name = StringUtil.simpleReplace(name, " ", "_"); name = StringUtil.simpleReplace(name, "'", ""); name = StringUtil.simpleReplace(name, "\"", ""); name = StringUtil.simpleReplace(name, "\\", ""); name = StringUtil.simpleReplace(name, "/", ""); File subDir = new File(newDir, name); subDir.mkdir(); copyAlbum(subalbums[i], subDir); } } //can clean all info from this album here. album.refresh();//frees memory } protected void specificUsage() { System.out.println( "Usage: ExplicitAlbumCopy -d [album_directory] [destination_directory]" + StringUtil.newline + "[destination_directory]: directory where copy is made" + StringUtil.newline); } } --- NEW FILE: FindBadAlbums.java --- package edu.whitman.halfway.jigs.cmdline; import edu.whitman.halfway.jigs.*; import java.io.*; import edu.whitman.halfway.util.*; import org.apache.log4j.Logger; import java.util.*; import gnu.getopt.Getopt; import java.util.Iterator; public class FindBadAlbums extends AbstractCmdLine { protected static Logger log = Logger.getLogger(FindBadAlbums.class); static int[] opts = {LOG4J_FILE, HELP, RECURSE_ALBUM}; public FindBadAlbums(){ super(opts); } public String getAdditionalParseArgs(){ return ""; } public static void main(String[] args){ (new FindBadAlbums()).mainDriver(args); } public void doMain(){ List badAlbums = getBadAlbums(); Iterator iter = badAlbums.iterator(); while(iter.hasNext()){ Album alb = (Album) iter.next(); System.out.println(alb); } } public List getBadAlbums(){ Album crnt = getAlbum(); AlbumFilter filt = new BadAlbumFilter(); return FilterUtil.findAlbums(crnt, filt, true); } static class BadAlbumFilter implements AlbumFilter{ public boolean accept(AlbumObject obj){ Album alb = (Album) obj; if(alb.getPictures().length > 0 && alb.getSubAlbums().length >0){ return true; } return false; } public boolean hasOpinion(AlbumObject obj){ return accept(obj); } } protected void specificUsage(){ System.out.println("Usage: FindBadAlbums " + StringUtil.newline ); System.out.println("\t Finds albums that contain both subalbums and pictures."); } } --- NEW FILE: LowercaseCategories.java --- package edu.whitman.halfway.jigs.cmdline; import edu.whitman.halfway.jigs.*; import edu.whitman.halfway.util.*; // import gnu.getopt.Getopt; import java.util.Iterator; import org.apache.log4j.Logger; public class LowercaseCategories extends AbstractCmdLine { protected static Logger log = Logger.getLogger(LowercaseCategories.class); static int[] opts = { RECURSE_ALBUM, LOG4J_FILE, RECURSIVE, HELP }; public LowercaseCategories() { super(opts); } public static void main(String[] args) { (new LowercaseCategories()).mainDriver(args); } public void doMain() { AlbumUtil.mediaItemWalk (getAlbum(), new MediaItemFunction(){ public void process(MediaItem item){ if(item instanceof Picture){ Picture pic = (Picture)item; AlbumObjectDescriptionInfo aoi = pic.getDescriptionInfo(); CategorySet cs = (CategorySet)aoi .getData(AlbumObjectDescriptionInfo.JIGS_CATEGORY); cs.lowercaseAll(); aoi.saveFile(); } } }, recurse); } protected void specificUsage() { System.out.println( "Usage: LowercaseCategories [-r] "); } } --- NEW FILE: WriteCategoriesToExif.java --- package edu.whitman.halfway.jigs.cmdline; import edu.whitman.halfway.jigs.*; import edu.whitman.halfway.util.ExifWriter; import org.apache.log4j.Logger; import java.io.File; import java.util.Calendar; /** Actually, does more than just write Categories. Tries to map all JIGS metainformation into EXIF metainformation, in particular those fields that can be read by ACDSee. Jigs doesn't have a fixed set of possible metadata fields. The one's I know I have used are: "location", "derived.date", "derived.time", "event", "location", "people", "description", "desc ", "photographer" and, of course, jigs.category and jigs.rating When we insert "all" jigs metadata, some fields will be modified for easier searching in ACDSee: The mapping will be: Jigs EXIF ACDSEE Database --------------------------------------------------------- [everything] ImageDescription Notes photographer Artist Author categories UserComment categories and keywords description Copyright caption */ public class WriteCategoriesToExif extends AbstractCmdLine { protected static final String USER_COMMENT = "UserComment"; protected static final String IMAGE_DESCRIPTION = "ImageDescription"; protected static final String COPYRIGHT = "Copyright"; protected static final String ARTIST = "Artist"; protected static Logger log = Logger.getLogger(WriteCategoriesToExif.class); static int[] opts = {RECURSE_ALBUM, LIST_ALBUM, LOG4J_FILE, HELP, RECURSIVE}; public WriteCategoriesToExif(){ super(opts); } public String getAdditionalParseArgs(){ return ""; } public void doMain(){ final Category[] ratingCats = new Category[10]; for(int i=0; i<10; i++){ ratingCats[i] = new Category("jigs_rating_is_" + (i+1)); } AlbumUtil.mediaItemWalk (getAlbum(), new MediaItemFunction(){ int processed = 0; public void process(MediaItem item){ if(item instanceof Picture){ Picture pic = (Picture)item; AlbumObjectDescriptionInfo aoi = pic.getDescriptionInfo(); File file = pic.getMediaKey().getFile(); long lastMod = file.lastModified(); Calendar yesterday = Calendar.getInstance(); yesterday.set(2006,5,27,20,0); //6/27/2006 , 8pm long lastRun = yesterday.getTimeInMillis(); processed ++; //System.out.println("lastRun = " + lastRun + " " + yesterday.getTime()); //yesterday.setTimeInMillis(lastMod); //System.out.println("lastMod = " + lastMod + " " + yesterday.getTime()); if(lastMod <= lastRun){ File descFile = aoi.getFile(); if(descFile != null && descFile.exists()){ System.out.println(processed + "\t processing " + file); //CATEGORIES => USER COMMENT CategorySet cs = (CategorySet)aoi .getData(AlbumObjectDescriptionInfo.JIGS_CATEGORY); Rating rating = (Rating)aoi.getData(aoi.JIGS_RATING); if(rating.isRated()){ //System.out.println("Raw rating is " + rating.getValue()); int sr = (int)(Math.round(9.0*(rating.getValue() - rating.MIN_VALUE)/rating.MAX_VALUE)); assert sr>= 0 && sr <= 9; Category rCat = ratingCats[sr]; cs.addCategory(rCat); } String tagValue = cs.toString(); boolean noError = true; noError &= ExifWriter.writeTag(USER_COMMENT, tagValue, file, false); //JIGS description file => IMAGE_DESCRIPTION noError &= ExifWriter.writeTagFromFile(IMAGE_DESCRIPTION, descFile, file); tagValue = (String)aoi.getData("photographer"); if(tagValue != null){ noError &= ExifWriter.writeTag(ARTIST, tagValue, file, false); } String title = (String)aoi.getData("title"); String desc = (String)aoi.getData("description"); String desc2 = (String)aoi.getData("desc"); if(title!= null || desc != null || desc2 != null){ tagValue = ((title != null) ? title : "") + ((desc != null) ? " " + desc : "") + ((desc2 != null) ? " " + desc2 : ""); noError &= ExifWriter.writeTag(COPYRIGHT, tagValue, file, false); } if(!noError){ log.error("Failed to write EXIF tag for " + file); //throw new JigsException("Exif Tag writing failed."); } }else{ System.out.println(processed + "\t skipping " + file); } }else{ System.out.println(processed + "\t already modified " + file); } } } }, recurse); } public static void main(String[] args){ (new WriteCategoriesToExif()).mainDriver(args); } protected void specificUsage(){ System.out.println(" usage: WriteCategoriesToExif [options] [file or album list]"); System.out.println("Writes categories to the UserComment EXIF field in the original image."); } } |
|
From: Brendan M. <mc...@us...> - 2006-08-02 21:43:14
|
Update of /cvsroot/jigs/jigs/resource/renderer/swigs/gray_templates/bak In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv14998/resource/renderer/swigs/gray_templates/bak Added Files: image.html imagelist.html subalbum.html thumbnail.html tree.html Log Message: more good stuffcvs up -d --- NEW FILE: image.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> <title><!--title--></title> <LINK REL=StyleSheet HREF="<!--res:style.css-->" TYPE="text/css" MEDIA=screen> </head> <body class="outside"> <!-- MAIN TABLE (Title, Image, Description)--> <table class="mainbody" border="0" cellpadding="0" cellspacing="0" align="center" width="600" > <tr><td> <table class="topbar" width="100%"><tr><td> <tr> <td valign=middle align=left> <span class="albumtitle"><!--title--></span> </td> <td align="right"> <A HREF = "<!--thumbpage-->">thumbnails</A> </td> </tr> <tr> <td colspan="2" class="pathlinks"> <!--albumPathLinks--> </td> </tr> </table> </td> </tr> <tr> <td> </td></tr> <tr > <td> <table align="center" border="0" cellpadding="0" cellspacing="0"> <tr class="picturelinks"> <td align="left"> <!--previmage--> </td> <td align="center"> <!--sizelinks--> </td> <td align="right"> <!--nextimage--> </td> </tr> <tr align="center"> <td colspan="3"> <!--image--> </td> </tr> <tr class="caption"> <td colspan=3 align = "right"><!--pictureinfo--> </td> </tr> </table> <tr> <td> </td></tr> <tr> <td> <!--desctable--> </td> </tr> <tr> <td> </td></tr> <tr> <td> <table class="bottombar" cellspacing=0 cellpadding=5 border=0 width="100%"> <tr> <td class="topbarlink" align=left width="33%"> <!--previmage--></td> <td class="topbarlink" align=center width="33%"> <A HREF = "<!--thumbpage-->">thumbnails</A> </td> <td class="topbarlink" align=right width="33%"> <!--nextimage--></td> </tr> </table> </td> </tr> </table> <table class="footer" cellpadding="5" cellspacing="0" width="600" background="#FF0000"> <tr> <td width="100%" align="right"> created with <a href="http://jigs.sourceforge.net/">Jigs</a> </td> </tr> </table> </body> </html> --- NEW FILE: imagelist.html --- <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> <title><!--albumTitle--></title> </head> <body bgcolor="<!--outside.backColor-->" vlink="#000000" link="#002085" alink="0000FF"> <table bgcolor="<!--inside.backColor-->" border="0" cellpadding="0" cellspacing="0" align="center" width="600"> <tr> <td> <table cellpadding="6" cellspacing="0" width="100%" border="0" bgcolor="<!--mainBar.backColor-->" ><tr><td> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tr> <td valign=middle align=left> <font size=4 color="<!--mainBar.titleColor-->"><!--albumTitle--></font> </td> <td align="right"> <font size=2 color="<!--mainBar.titleColor-->"><!--numInfo--></font> </td> </tr> <tr> <td colspan="2"> <!--albumPathLinks--> </td> </tr> </table> </td></tr></table> </td> </tr> <tr> <td> <table border="0" cellpadding="4" cellspacing="0" align="left" > <tr> <td valign=top bgcolor="<!--subBar.backColor-->"> <table cellpadding="1" cellspacing="0" border="0"> <tr> <td colspan="2"> In This Album: </td> </tr> <tr> <td> </td> <td> <table cellpadding="1" cellspacing="0" bgcolor="<!--subBar.backColor-->" border="0"> <!--navBarRows--> </table> </td> </tr> </table> </td><td> </td> <td valign="top"> <!--albumDesc--> </td> </tr> </table> </td> </tr> <tr> <td> </td> </tr> <tr> <td bgcolor ="<!--mainBar.backColor-->"> <table ><tr><td> <font size="3" color="<!--mainBar.titleColor-->"><b>Image List</b></font> </td></tr> </table> </td> </tr> <tr> <td> <br> <table width="100%" cellpadding="0" cellspacing="0" border=0> <tr><td> </td> <td> <!--imageListTable--> </td> </tr> </table> <br> </td> </tr> <tr> <td bgcolor ="<!--mainBar.backColor-->"> <table cellpadding="0"><tr><td> <font size="4"> </font> </td></tr> </table> </td> </tr> </table> </body> </html> --- NEW FILE: subalbum.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> <title><!--albumTitle--></title> <LINK REL=StyleSheet HREF="<!--res:style.css-->" TYPE="text/css" MEDIA=screen> </head> <body class="outside"> <table class="mainbody" cellpadding="0" cellspacing="0" align="center" width="600"> <tr> <td> <table class="topbar" width="100%"><tr><td> <tr> <td valign=middle align=left> <span class="albumtitle"><!--albumTitle--></span </td> <td align="right"> <span class="numinfo"><!--numInfo--></span> </td> </tr> <tr> <td colspan="2" class="pathlinks"> <!--albumPathLinks--> </td> </tr> </table> </td> </tr> <tr> <td> <table border="0" cellpadding="4" cellspacing="0" align="left" > <tr> <td class="albumnav" valign=top > In This Album: <table class="navbarrows"> <!--navBarRows--> </table> </td> <td> </td> <td class="albumdesc" valign="top"> <!--albumDesc--> </td> </tr> </table> </td> </tr> <tr> <td> </td> </tr> <tr > <td class="midbar"> Sub Albums </td> </tr> <tr class = "subalbumtable"> <td > <!--subalbumtable--> </td> </tr> <tr> <td class="bottombar"> </td> </tr> </table> <table class="footer" cellpadding="5" cellspacing="0" width="600" background="#FF0000"> <tr> <td width="100%" align="right"> created with <a href="http://jigs.sourceforge.net/">Jigs</a> </td> </tr> </table> </body> </html> --- NEW FILE: thumbnail.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> <title><!--albumTitle--></title> <LINK REL=StyleSheet HREF="<!--res:style.css-->" TYPE="text/css" MEDIA=screen> </head> <body class="outside"> <table class="mainbody" cellpadding="0" border="0" cellspacing="0" align="center" width="600"> <tr> <td > <table class="topbar" width="100%"> <tr> <td valign=middle align=left> <span class="albumtitle"><!--albumTitle--></span> </td> <td align="right"> <span class="numinfo"><!--numInfo--></span> </td> </tr> <tr> <td colspan="2" class="pathlinks"> <!--albumPathLinks--> </td> </tr> </table> </td> </tr> <tr> <td > <table border="0" cellpadding="4" cellspacing="0" align="left"> <tr> <td class="albumnav" valign=top > In This Album: <table class="navbarrows"> <!--navBarRows--> </table> </td> <td> </td> <td class="albumdesc" valign="top"> <!--albumDesc--> </td> </tr> </table> </td> </tr> <tr> <td> </td></tr> <tr><td > <table class="midbar" width="100%" > <tr > <td align="left"> Thumbnails <!--thumbNumberLinks--> </td> <td></td> <td align="right" valign=bottom> <!--thumbPageNumber--> </td> </tr> <tr> <td align="left"> <!--prevThumbpage--> </td> <td></td> <td align="right"> <!--nextThumbpage--> </td> </tr> </table> </tr></td> <tr> <td> <table> <tr> <td valign = "top" align="center"> <!--thumbTable--> </td> </tr> </table> </td> </tr> <tr><td> <table class = "bottombar" width="100%"> <tr> <td align="left" > <!--prevThumbpage--> </td> <td align="center" width="100%"> <!--thumbNumberLinks--> </td> <td align="right" > <!--nextThumbpage--> </td> </tr> </table> </td></tr> </table> <table class="footer" cellpadding="5" cellspacing="0" width="600" background="#FF0000"> <tr> <td width="100%" align="right"> created with <a href="http://jigs.sourceforge.net/">Jigs</a> </td> </tr> </table> </body> </html> --- NEW FILE: tree.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> <title>Album Tree</title> <LINK REL=StyleSheet HREF="<!--res:style.css-->" TYPE="text/css" MEDIA=screen> </head> <body class="outside"> <table class="mainbody" cellpadding="5" cellspacing="0" align="center" width="600"> <tr class="topbar" > <td class="albumtitle"> Album Tree </td> </tr> <tr> <td> <!--treeTable--> </td> </tr> <tr class="bottombar"> <td > </td> </tr> </table> <table class="footer" cellpadding="5" cellspacing="0" width="600" background="#FF0000"> <tr> <td width="100%" align="right"> created with <a href="http://jigs.sourceforge.net/">Jigs</a> </td> </tr> </table> </body> </html> |