public static void RunStocks(Random rnd, MonitoredFunction function, string cbName, int iterations, Tree <long> closestValueQuery, int numOfNodes, int window, DateTime startingDateTime, int minAmountAtDay, ApproximationType approximation, string stocksDirPath, string resultDir) { var vectorLength = closestValueQuery.Data.Length; var resultPath = PathBuilder.Create(resultDir, "Entropy_" + cbName) .AddProperty("Dataset", "Stocks") .AddProperty("VectorLength", vectorLength.ToString()) .AddProperty("Nodes", numOfNodes.ToString()) .AddProperty("Window", window.ToString()) .AddProperty("StartingTime", startingDateTime.ToShortDateString().Replace('/', '-')) .AddProperty("MinAmountAtDay", minAmountAtDay.ToString()) .AddProperty("Approximation", approximation.AsString()) .ToPath("csv"); using (var resultCsvFile = AutoFlushedTextFile.Create(resultPath, AccumaltedResult.Header(numOfNodes))) using (var stocksProbabilityWindow = StocksProbabilityWindow.Init(stocksDirPath, startingDateTime, minAmountAtDay, numOfNodes, window, closestValueQuery)) { var initProbabilityVectors = stocksProbabilityWindow.CurrentProbabilityVector(); if (!initProbabilityVectors.All(v => v.Sum().AlmostEqual(1.0, 0.000001))) { throw new Exception(); } var multiRunner = MultiRunner.InitAll(initProbabilityVectors, numOfNodes, vectorLength, approximation, function); int i = 0; while (stocksProbabilityWindow.MoveNext() && (i++ < iterations)) { var changeProbabilityVectors = stocksProbabilityWindow.CurrentChangeProbabilityVector(); if (!changeProbabilityVectors.All(v => v.Sum().AlmostEqual(0.0, 0.000001))) { throw new Exception(); } multiRunner.Run(changeProbabilityVectors, rnd, false) .Select(r => r.AsCsvString()) .ForEach(resultCsvFile.WriteLine); } } }
public static void RunStocks(Random rnd, int iterations, Tree <long> closestValueQuery, int numOfNodes, int window, int collapseDimension, DateTime startingDateTime, int minAmountAtDay, ApproximationType approximation, string stocksDirPath, string resultDir) { var vectorLength = closestValueQuery.Data.Length; var resultPath = PathBuilder.Create(resultDir, "EntropySketch") .AddProperty("Dataset", "Stocks") .AddProperty("BucketLength", vectorLength.ToString()) .AddProperty("SketchDimension", collapseDimension.ToString()) .AddProperty("Nodes", numOfNodes.ToString()) .AddProperty("Window", window.ToString()) .AddProperty("StartingTime", startingDateTime.ToShortDateString().Replace('/', '-')) .AddProperty("MinAmountAtDay", minAmountAtDay.ToString()) .AddProperty("Approximation", approximation.AsString()) .ToPath("csv"); var entropySketch = new EntropySketchFunction(collapseDimension); using (var resultCsvFile = AutoFlushedTextFile.Create(resultPath, AccumaltedResult.Header(numOfNodes) + ",Entropy")) using (var stocksProbabilityWindow = StocksProbabilityWindow.Init(stocksDirPath, startingDateTime, minAmountAtDay, numOfNodes, window, closestValueQuery)) { var initProbabilityVectors = stocksProbabilityWindow.CurrentProbabilityVector().Map(entropySketch.CollapseProbabilityVector); var multiRunner = MultiRunner.InitAll(initProbabilityVectors, numOfNodes, collapseDimension, approximation, entropySketch.MonitoredFunction); int i = 0; while (stocksProbabilityWindow.MoveNext() && (i++ < iterations)) { var changeProbabilityVectors = stocksProbabilityWindow.CurrentChangeProbabilityVector() .Map(entropySketch.CollapseProbabilityVector); var entropy = Vector.AverageVector(stocksProbabilityWindow.CurrentProbabilityVector()) .IndexedValues.Values.Sum(p => - p * Math.Log(p)); multiRunner.Run(changeProbabilityVectors, rnd, false) .Select(r => r.AsCsvString() + "," + entropy) .ForEach(resultCsvFile.WriteLine); } } }