public void DistributionSpaceIterator_SingleIntervalTest() { Console.WriteLine("DistributionSpaceIterator_SingleIntervalTest"); int dim = 1; string [] names = new string [1] { "x" }; double [] mins = new double [1] { 0.00 }; double [] maxs = new double [1] { 100.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); double min = 20.0; double max = 80.0; IDistribution d = new Distribution_Interval(s, min, max); SingletonLogger.Instance().DebugLog(typeof(dist_tests), "original distribution: " + d); DistributionSpace ds = new DistributionSpace(d); int [] steps = new int[ds.ParamSpace.Dimension]; for (int N = 3; N <= 5; N++) { for (int i = 0; i < ds.ParamSpace.Dimension; i++) { steps[i] = N; } IDistributionSpaceIterator it = ds.iterator(steps); int count = 0; int validCt = 0; foreach (IDistribution d2 in it) { if (d2.IsValid()) { validCt++; SingletonLogger.Instance().DebugLog(typeof(dist_tests), "iterator distribution: " + d2); } count++; } Assert.AreEqual((N + 1) * (N + 1), count); SingletonLogger.Instance().InfoLog(typeof(dist_tests), "N=" + N + " valid distributions: " + validCt + " / total: " + count); } }
public void Distribution_IntervalSerializationTest() { Console.WriteLine("Distribution_IntervalSerializationTest"); int dim = 1; string [] names = new string [1] { "x" }; double [] mins = new double [1] { 0.00 }; double [] maxs = new double [1] { 100.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); double min = 10.0; double max = 30.0; IDistribution d = new Distribution_Interval(s, min, max); SingletonLogger.Instance().DebugLog(typeof(dist_tests), "distribution: " + d); SoapFormatter formatter = new SoapFormatter(); FileStream fs = new FileStream("interval.xml", FileMode.Create); formatter.Serialize(fs, d); fs.Close(); fs = new FileStream("interval.xml", FileMode.Open); IDistribution d2 = (IDistribution)formatter.Deserialize(fs); fs.Close(); Assert.AreEqual(d.SampleSpace == d2.SampleSpace, true); Assert.AreEqual(d is Distribution_Interval, true); Assert.AreEqual(d2 is Distribution_Interval, true); Distribution_Interval g1 = (Distribution_Interval)d; Distribution_Interval g2 = (Distribution_Interval)d2; Assert.AreEqual(g1.Max, g2.Max); Assert.AreEqual(g1.Min, g2.Min); Assert.AreEqual(g1.Params, g2.Params); Assert.AreEqual(g1.SampleSpace, g2.SampleSpace); SingletonLogger.Instance().DebugLog(typeof(dist_tests), "All distributions coincide as expected"); }
public void Distribution_Interval1DTest() { Console.WriteLine("Distribution_Interval1DTest"); int dim = 1; string [] names = new string [1] { "x" }; double [] mins = new double [1] { 0.00 }; double [] maxs = new double [1] { 100.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); double min = 10.0; double max = 30.0; IDistribution d = new Distribution_Interval(s, min, max); SingletonLogger.Instance().DebugLog(typeof(dist_tests), "distribution: " + d); for (int i = 0; i < 1000; i++) { IBlauPoint p = d.getSample(); SingletonLogger.Instance().DebugLog(typeof(dist_tests), "=> " + p); for (int x = 0; x < dim; x++) { double diff = p.getCoordinate(x) - min; Assert.AreEqual(diff < 0.0, false); diff = max - p.getCoordinate(x); Assert.AreEqual(diff < 0.0, false); } } }
public static void MakeUniform_Main(string[] args) { Console.WriteLine("MakeUniform"); // Command line parsing Arguments CommandLine = new Arguments(args); bool err = false; string errString = ""; double lower, upper, min, max; string variable = "unassigned"; string outfile = "unassigned"; lower = upper = min = max = -1.0; // Look for specific arguments values and display // them if they exist (return null if they don't) if (CommandLine["lower"] != null) { try { lower = Double.Parse(CommandLine["lower"]); } catch (Exception) { errString += ("The specified 'lower' was not valid. "); err = true; } } else { errString += ("The 'lower' was not specified. "); err = true; } if (CommandLine["upper"] != null) { try { upper = Double.Parse(CommandLine["upper"]); } catch (Exception) { errString += ("The specified 'upper' was not valid. "); err = true; } } else { errString += ("The 'upper' was not specified. "); err = true; } if (CommandLine["variable"] != null) { variable = CommandLine["variable"]; } else { errString += ("The 'variable' was not specified. "); err = true; } if (CommandLine["min"] != null) { try { min = Double.Parse(CommandLine["min"]); } catch (Exception) { errString += ("The specified 'min' was not valid. "); err = true; } } else { errString += ("The 'min' was not specified. "); err = true; } if (CommandLine["max"] != null) { try { max = Double.Parse(CommandLine["max"]); } catch (Exception) { errString += ("The specified 'max' was not valid. "); err = true; } } else { errString += ("The 'max' was not specified. "); err = true; } if (CommandLine["outfile"] != null) { outfile = CommandLine["outfile"]; } else { errString += ("The 'outfile' was not specified. "); err = true; } if (err) { Console.Out.WriteLine("Arguments parsing failed."); Console.Out.WriteLine(" " + errString); } else { Console.Out.WriteLine("Arguments parsing successful."); Console.Out.WriteLine(" lower = " + lower); Console.Out.WriteLine(" upper = " + upper); Console.Out.WriteLine(" variable = " + variable); Console.Out.WriteLine(" min = " + min); Console.Out.WriteLine(" max = " + max); Console.Out.WriteLine(" outfile = " + outfile); int dim = 1; string [] names = new string [1] { "" }; double [] mins = new double [1] { 0.00 }; double [] maxs = new double [1] { 0.0 }; names[0] = variable; mins[0] = min; maxs[0] = max; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); IDistribution d = new Distribution_Interval(s, lower, upper); Console.Out.WriteLine("Distribution: " + d); SoapFormatter formatter = new SoapFormatter(); FileStream fs = new FileStream(outfile, FileMode.Create); formatter.Serialize(fs, d); fs.Close(); } }