https://www.mediawiki.org/wiki/Special:Code/MediaWiki/108042
Revision: 108042 Author: oren Date: 2012-01-04 15:34:48 +0000 (Wed, 04 Jan 2012) Log Message: ----------- deprecated from project - these classes do not seem to be in use by search. they will be removed in the next version together with thier data file Modified Paths: -------------- trunk/lucene-search-2/src/org/wikimedia/lsearch/util/MathFunc.java trunk/lucene-search-2/test/org/wikimedia/lsearch/util/MathFuncTest.java Modified: trunk/lucene-search-2/src/org/wikimedia/lsearch/util/MathFunc.java =================================================================== --- trunk/lucene-search-2/src/org/wikimedia/lsearch/util/MathFunc.java 2012-01-04 15:29:37 UTC (rev 108041) +++ trunk/lucene-search-2/src/org/wikimedia/lsearch/util/MathFunc.java 2012-01-04 15:34:48 UTC (rev 108042) @@ -1,19 +1,48 @@ package org.wikimedia.lsearch.util; -public class MathFunc { - - /** Calculate average value starting from start to end (end excluded) */ +/** + * this class is used only in its own tests. + * + * @deprecated + * + * + */ +public class MathFunc +{ + + /** + * Calculate arithmetic mean value of an array of doubles. + * + * note: only called from MathFuncTest. + * + * @param val - array of values to average. + * @param start - array index to start. + * @param end - array index to end with (excluded). + * @return the average. + * + */ public static double avg(double[] val, int start, int end){ + double s = 0; for(int i=start;i<end;i++) s+=val[i]; return s/(end-start); } - /** * Approximate the graph of function with num horizontal lines * (const functions), so to minimize the maximal deviation - * @return list of discontinuities (begin points of horizontal lines) + * + * input output for n =4 + * * ** + * * ** *** + * * * * *** ** + * ** * + * + * + * + * @param val the heights of the function being approximated + * @param num number of discrete lines + * @return list of discontinuities (begin points of horizontal lines) */ public static int[] partitionList(double[] val, int num){ //System.out.println("Doing: "+Arrays.toString(val)); @@ -74,6 +103,7 @@ return part; } + private static void extend(int[] part, int[] newpart, double[] val, int num) { for(int j=0;j<num;j++) newpart[j] = part[j]; Modified: trunk/lucene-search-2/test/org/wikimedia/lsearch/util/MathFuncTest.java =================================================================== --- trunk/lucene-search-2/test/org/wikimedia/lsearch/util/MathFuncTest.java 2012-01-04 15:29:37 UTC (rev 108041) +++ trunk/lucene-search-2/test/org/wikimedia/lsearch/util/MathFuncTest.java 2012-01-04 15:34:48 UTC (rev 108042) @@ -4,15 +4,45 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; +import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; - import org.wikimedia.lsearch.util.MathFunc; -public class MathFuncTest { + +/** + * This class is test MathFunc which is not used in the project + * The test is visual i.e. putput not a success failure + * also neither MathFunc nor MathFuncTest are referenced in the project + * + * @deprecated + * + * if the class isn't deprecated then the following should be addressed + * configure test file location from command line + * convert to unit test + * convert to output to log4j for non console execution + + * + */ +public class MathFuncTest +{ + + + /** + * prints the entries of an integer and a double arrays side by side + * + * + * @param p the integers + * @param val the doubles + */ public static void print(int[] p, double[] val){ + + //for each integer in p for(int i=0;i<p.length-1;i++){ + + //print the value of val[i] System.out.print(MathFunc.avg(val,p[i],p[i+1])+" -> "); + + //prints all a sequence of values from val for(int j=p[i];j<p[i+1];j++){ System.out.print(val[j]+" "); } @@ -21,19 +51,38 @@ System.out.println(); } - public static void main(String[] args) throws Exception{ + /** + * 1. loads data from "./test-data/mathfunc.test" + * 2. + * + * @param args + * @throws FileNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException { double[] val = {39.2,13.45,12.67,10.25,8.84,8.66,8.31,8.19,8.06,7.99,6.39,6.19,6,5.92,5.85}; String testfile = "./test-data/mathfunc.test"; int[] p = MathFunc.partitionList(val,3); print(p,val); + + //load data from file System.out.println("From "+testfile); BufferedReader r = new BufferedReader(new FileReader(new File(testfile))); String line; ArrayList<Double> val2a = new ArrayList<Double>(); - while((line = r.readLine()) != null){ - val2a.add(new Double(line)); + try { + while((line = r.readLine()) != null){ + val2a.add(new Double(line)); + } + } catch (NumberFormatException e) { + // TODO badly formated file + e.printStackTrace(); + } catch (IOException e) { + // TODO could not read file + e.printStackTrace(); + } + double[] val2 = new double[val2a.size()]; for(int i=0;i<val2.length;i++) val2[i] = val2a.get(i); @@ -42,6 +91,5 @@ double[] val3 = {1.5192982456140351, 1.222988282514404, 1.053690036900369, 1.053690036900369, 1.003690036900369, 0.5229882825144041}; print(MathFunc.partitionList(val3,5),val3); - } } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs