Example #1
0
 private static double buildHistograms(InputParser inputParser, HistogramComputer histogramComputer, 
     KnuthPosteriorComputer knuthPosteriorComputer, string filename, int spaceDimension, int pointNO, 
     double[] minElems, double[] maxElems, int serverNO, int upperBoundOfPostVals, 
     double[] posteriorValues, double[] centralDiffs, int initialHistRes, List<DataRow> data)
 {
     double posteriorSum = 0.0;
     for (int histogramResolution = initialHistRes; histogramResolution <= upperBoundOfPostVals;
         histogramResolution++)
     {
         int[] binHefts = histogramComputer.buildHistogram(histogramResolution, data, spaceDimension,
             minElems, maxElems);
         posteriorSum = innerBuildHistograms(inputParser, knuthPosteriorComputer, filename, spaceDimension,
             pointNO, serverNO, upperBoundOfPostVals, posteriorValues, centralDiffs, initialHistRes, posteriorSum,
             histogramResolution, binHefts);
     }
     return posteriorSum;
 }
Example #2
0
 private static double buildHistogramsStreamMode(InputParser inputParser, HistogramComputer histogramComputer,
     KnuthPosteriorComputer knuthPosteriorComputer, string filename, int spaceDimension, int pointNO,
     double[] minElems, double[] maxElems, int serverNO, int upperBoundOfPostVals,
     double[] posteriorValues, double[] centralDiffs, int initialHistRes)
 {
     double posteriorSum = 0.0;
     for (int histogramResolution = initialHistRes; histogramResolution <= upperBoundOfPostVals;
         histogramResolution++)
     {
         int[] binHefts = new int[(int)Math.Pow(histogramResolution, spaceDimension)];
         var lines = File.ReadLines(filename);
         int lineIdx = 0;
         foreach (var line in lines)
         {
             string[] lineParts = line.Split(InputParser.delimiter);
             if (lineParts.Length < spaceDimension)
                 throw new ArgumentException("The line " + lineIdx + " has invalid dimension!");
             else if (lineParts.Length > spaceDimension)
             {
                 string[] tempLineParts = new string[spaceDimension];
                 for (int idx = 0; idx < spaceDimension; idx++)
                 {
                     tempLineParts[idx] = lineParts[idx];
                 }
                 lineParts = tempLineParts;
             }
             double[] coords = new double[spaceDimension];
             for (int coordIdx = 0; coordIdx < lineParts.Length; coordIdx++)
             {
                 coords[coordIdx] = Double.Parse(lineParts[coordIdx], NumberStyles.Float,
                     CultureInfo.InvariantCulture);
             }
             histogramComputer.buildHistogramForDataRowTuple(histogramResolution, spaceDimension, minElems,
                 maxElems, binHefts, coords);
             lineIdx++;
         }
         posteriorSum = innerBuildHistograms(inputParser, knuthPosteriorComputer, filename, spaceDimension,
             pointNO, serverNO, upperBoundOfPostVals, posteriorValues, centralDiffs, initialHistRes, posteriorSum,
             histogramResolution, binHefts);
     }
     return posteriorSum;
 }
Example #3
0
 private static void writeOutInputSizes(InputParser inputParser, string filename, int spaceDimension, 
     int histogramResolution, int serverNO, int[] binHefts)
 {
     StringBuilder strBldr = new StringBuilder();
     strBldr.AppendLine(spaceDimension.ToString());
     strBldr.AppendLine(histogramResolution.ToString());
     strBldr.AppendLine(serverNO.ToString());
     for (int binIdx = 0; binIdx < binHefts.Length - 1; binIdx++)
     {
         strBldr.Append(binHefts[binIdx]).Append(" ");
     }
     strBldr.Append(binHefts[binHefts.Length - 1]);
     filename = Path.GetFileNameWithoutExtension(filename);
     string inputSizesOutput = @"c:\temp\data\" + filename + "_input_sizes_serv_" + serverNO
         + "_res_" + histogramResolution + ".dat";
     System.IO.File.WriteAllText(inputSizesOutput, strBldr.ToString());
 }
Example #4
0
 static void Main(string[] args)
 {
     InputParser inputParser = new InputParser();
     HistogramComputer histogramComputer = new HistogramComputer();
     KnuthPosteriorComputer knuthPosteriorComputer = new KnuthPosteriorComputer();
     LMethod lMethod = new LMethod();
     FurthestPointFromLineMethod furthestPointFromLineMethod = new FurthestPointFromLineMethod();
     string filename;
     int spaceDimension, pointNO, serverNO, upperBoundOfPostVals, initialHistRes;
     double[] minElems, maxElems, posteriorValues, centralDiffs;
     double posteriorSum;
     Console.WriteLine("How would you like to execute histogram building? " +
         "Would you like to apply stream mode?");
     Console.WriteLine("(Please choose this mode only if you have prior information about " +
         "object number and bounding box)");
     bool streamMode = bool.Parse(Console.ReadLine());
     if (streamMode)
     {
         handleStreamMode(inputParser, histogramComputer, knuthPosteriorComputer, out filename, out spaceDimension,
             out pointNO, out serverNO, out upperBoundOfPostVals, out initialHistRes, out minElems, out maxElems,
             out posteriorValues, out centralDiffs, out posteriorSum);
     }
     else
     {
         handleNormalMode(inputParser, histogramComputer, knuthPosteriorComputer, out filename, out spaceDimension,
             out pointNO, out serverNO, out upperBoundOfPostVals, out initialHistRes, out minElems, out maxElems,
             out posteriorValues, out centralDiffs, out posteriorSum);
     }
     writeOutStats(lMethod, furthestPointFromLineMethod, upperBoundOfPostVals, initialHistRes,
         posteriorValues, centralDiffs, posteriorSum);
     Console.WriteLine("Press any key to continue...");
     Console.Read();
 }
Example #5
0
 private static double innerBuildHistograms(InputParser inputParser, KnuthPosteriorComputer knuthPosteriorComputer,
     string filename, int spaceDimension, int pointNO, int serverNO, int upperBoundOfPostVals,
     double[] posteriorValues, double[] centralDiffs, int initialHistRes, double posteriorSum,
     int histogramResolution, int[] binHefts)
 {
     writeOutInputSizes(inputParser, filename, spaceDimension, histogramResolution, serverNO, binHefts);
     double posteriorValue = knuthPosteriorComputer.evaluate(Math.Pow(histogramResolution, spaceDimension),
         pointNO, binHefts);
     int idx = histogramResolution - initialHistRes;
     posteriorValues[idx] = posteriorValue;
     determineCentralDiff(upperBoundOfPostVals, posteriorValues, centralDiffs, initialHistRes,
         histogramResolution, idx);
     Console.WriteLine("Histogram resolution: {0}, posterior value: {1}, central diff: {2}",
         histogramResolution, posteriorValue, centralDiffs[idx]);
     posteriorSum += posteriorValue;
     return posteriorSum;
 }
Example #6
0
 private static void initializeVariables(InputParser inputParser, int pointNO, out int serverNO,
     out int upperBoundOfPostVals, out double[] posteriorValues, out double[] centralDiffs,
     out int initialHistRes)
 {
     serverNO = inputParser.parseServerNO();
     upperBoundOfPostVals = (int)(Math.Sqrt(pointNO));
     //upperBoundOfPostVals = 150;
     Console.WriteLine(upperBoundOfPostVals);
     posteriorValues = new double[upperBoundOfPostVals - 1];
     // The central difference approximations of second derivative of posterior:
     centralDiffs = new double[upperBoundOfPostVals - 1];
     initialHistRes = 2;
 }
Example #7
0
 private static void handleStreamMode(InputParser inputParser, HistogramComputer histogramComputer, 
     KnuthPosteriorComputer knuthPosteriorComputer, out string filename, out int spaceDimension, 
     out int pointNO, out int serverNO, out int upperBoundOfPostVals, out int initialHistRes, 
     out double[] minElems, out double[] maxElems, out double[] posteriorValues, out double[] centralDiffs, 
     out double posteriorSum)
 {
     inputParser.parseInputFileStreamMode(out filename, out spaceDimension, out pointNO,
         out minElems, out maxElems);
     initializeVariables(inputParser, pointNO, out serverNO, out upperBoundOfPostVals, out posteriorValues,
         out centralDiffs, out initialHistRes);
     posteriorSum = buildHistogramsStreamMode(inputParser, histogramComputer, knuthPosteriorComputer,
         filename, spaceDimension, pointNO, minElems, maxElems, serverNO, upperBoundOfPostVals,
         posteriorValues, centralDiffs, initialHistRes);
 }