static void Main(string[] args) { Random rnd = new Random(); //Creating an array with values, corresponding to linear function with added white noise const int n = 360; double[] array = new double[n]; for (int i = 0; i < n; i++) { double noise = 0; noise = (double)rnd.Next(Int32.MinValue, Int32.MaxValue) / (Int32.MaxValue / rnd.Next(1, 30)); //if (i % 10 == 0) noise = 100; //Noise for tukey filter testing array[i] = (double)i + noise; } BSDataObject source = new BSDataObject(array, "SourceData"); IVisualizer visualizer = new SimpleVisualizationHandler(); visualizer.AddToGraph(source); visualizer.AddToGraph(new MedianPreprocessor().Process(source)); using (var ms = new MemoryStream(n * (sizeof(double) + sizeof(char)))) { StreamWriter sw = new StreamWriter(ms); for (int i = 0; i < n; i++) { array[i] = 80 * Math.Sin((double)i * Math.PI / 180.0); sw.WriteLine(array[i]); } sw.Flush(); ms.Position = 0; BSDataObject target = DataObjectSupplier.GetDataObjectForStream(ms, "Sine from memory stream"); visualizer.AddToGraph(target); } (visualizer as SimpleVisualizationHandler)._TestShow(); }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion /// <summary> /// A test for GenerateInputAndOutput ///</summary> //[TestMethod()] public void GenerateInputAndOutputTest() { uint iLag = 1; uint iWindowSize = 5; int pointsNum = 360; IInputProvider target = new WindowingInputProvider(iLag, iWindowSize); Random rnd = new Random(); double[] iTimeSeries = new double[pointsNum]; for (int i = 0; i < pointsNum; i++) { iTimeSeries[i] = 1 * Math.Sin(2 * i * Math.PI / 180.0) + (Convert.ToDouble(rnd.Next(-2, 2)) / 5) * ((i % 3 == 0) ? 1 : 0); } double[][] oInput = null; double[][] oOutput = null; target.GenerateInputAndOutput(iTimeSeries, out oInput, out oOutput); IForecastingModelBuilder modelBuilder = new ANNmodelBuilder(); IForecastingModel model = modelBuilder.TrainNewModel(oInput, oOutput); double[] forecast = new double[oInput.LongLength], actual = new double[oInput.LongLength]; for (int i = 0; i < oInput.LongLength; ++i) { forecast[i] = model.CalculateOutput(oInput[i])[0]; actual[i] = oOutput[i][0]; } BSDataObject forecastDO = new BSDataObject(forecast, "Forecast"), actualDO = new BSDataObject(actual, "Actual"); SimpleVisualizationHandler handler = new SimpleVisualizationHandler(); handler.AddToGraph(actualDO); handler.AddToGraph(forecastDO); handler._TestShow(); }
/// <summary> /// A test for GenerateInputAndOutput ///</summary> //[TestMethod()] public void GenerateInputAndOutputTest() { uint iLag = 1; uint iWindowSize = 5; int pointsNum = 360; IInputProvider target = new WindowingInputProvider(iLag, iWindowSize); Random rnd = new Random(); double[] iTimeSeries = new double[pointsNum]; for (int i = 0; i < pointsNum; i++) { iTimeSeries[i] = 1 * Math.Sin(2 * i * Math.PI / 180.0) + (Convert.ToDouble(rnd.Next(-2, 2)) / 5) * ((i % 3 == 0) ? 1 : 0); } double[][] oInput = null; double[][] oOutput = null; target.GenerateInputAndOutput(iTimeSeries, out oInput, out oOutput); IForecastingModelBuilder modelBuilder = new ANNmodelBuilder(); IForecastingModel model = modelBuilder.TrainNewModel(oInput, oOutput); double[] forecast = new double[oInput.LongLength], actual = new double[oInput.LongLength]; for (int i = 0; i < oInput.LongLength; ++i) { forecast[i] = model.CalculateOutput(oInput[i])[0]; actual[i] = oOutput[i][0]; } BSDataObject forecastDO = new BSDataObject(forecast, "Forecast"), actualDO = new BSDataObject(actual, "Actual"); SimpleVisualizationHandler handler = new SimpleVisualizationHandler(); handler.AddToGraph(actualDO); handler.AddToGraph(forecastDO); handler._TestShow(); }
/// <summary> ///A test for Visualize ///</summary> //[TestMethod()] public void VisualizeTest() { SimpleVisualizationHandler target = new SimpleVisualizationHandler(); double[] iArray = {1.2, 3.4, 5.6, 2.2, 7.7}; BSDataObject obj = new BSDataObject(iArray, "asdasd"); target.AddToGraph(obj); iArray = new double[] { 2.6, 7.8, 12.2, 10, 2.2, 3.3, 4.4, 5.5, 3.3, -5, 30}; target.AddToGraph(new BSDataObject(iArray, "anotherGraph")); target._TestShow(); }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion /// <summary> ///A test for Visualize ///</summary> //[TestMethod()] public void VisualizeTest() { SimpleVisualizationHandler target = new SimpleVisualizationHandler(); double[] iArray = { 1.2, 3.4, 5.6, 2.2, 7.7 }; BSDataObject obj = new BSDataObject(iArray, "asdasd"); target.AddToGraph(obj); iArray = new double[] { 2.6, 7.8, 12.2, 10, 2.2, 3.3, 4.4, 5.5, 3.3, -5, 30 }; target.AddToGraph(new BSDataObject(iArray, "anotherGraph")); target._TestShow(); }
public override void Start() { CheckIfInputsAreProvided(); foreach (BSDataObject dataObj in Inputs) { visualizer.AddToGraph(dataObj); } visualizer.ShowGraph(); //Will possibly need refactoring. visualizer = new SimpleVisualizationHandler(); // }