private static void RunDatabaseAccessesEntropy(Random random) { int numOfNodes = 10; var window = 14; var vectorLength = 11654; var distrubteUsers = UsersDistributing.RoundRobin(); var approximation = new MultiplicativeApproximation(0.02); EntropyRunner.RunDatabaseAccesses(random, numOfNodes, window, approximation, vectorLength, distrubteUsers, databaseAccessesPath, resultDir); }
public static void RunDatabaseAccesses(Random rnd, int numOfNodes, int window, ApproximationType approximation, int vectorLength, UsersDistributing distributing, string databaseAccessesPath, string resultDir) { var resultPath = PathBuilder.Create(resultDir, "Entropy") .AddProperty("Dataset", "DatabaseAccesses") .AddProperty("Nodes", numOfNodes.ToString()) .AddProperty("Window", window.ToString()) .AddProperty("Approximation", approximation.AsString()) .AddProperty("DistributingMethod", distributing.Name) .ToPath("csv"); var hashUser = new Func <int, int>(userId => userId % numOfNodes); var entropy = new EntropyFunction(vectorLength); using (var resultCsvFile = AutoFlushedTextFile.Create(resultPath, AccumaltedResult.Header(numOfNodes))) using (var databaseAccessesStatistics = DatabaseAccessesStatistics.Init(databaseAccessesPath, numOfNodes, window, distributing.DistributeFunc)) { var initProbabilityVectors = databaseAccessesStatistics.InitProbabilityVectors(); if (!initProbabilityVectors.All(v => v.Sum().AlmostEqual(1.0, 0.000001))) { throw new Exception(); } var multiRunner = MultiRunner.InitAll(initProbabilityVectors, numOfNodes, vectorLength, approximation, entropy.MonitoredFunction); while (databaseAccessesStatistics.TakeStep()) { var changeProbabilityVectors = databaseAccessesStatistics.GetChangeProbabilityVectors(); if (!changeProbabilityVectors.All(v => v.Sum().AlmostEqual(0.0, 0.000001))) { throw new Exception(); } multiRunner.Run(changeProbabilityVectors, rnd, true) .Select(r => r.AsCsvString()) .ForEach(resultCsvFile.WriteLine); } } }
public static void RunDatabaseAccesses(Random rnd, int numOfNodes, int window, ApproximationType approximation, int width, int height, UsersDistributing distributing, string databaseAccessesPath, string resultDir) { var vectorLength = width * height; var hashFunction = FourwiseIndepandantFunction.Init(rnd); var hashFunctionsTable = HashFunctionTable.Init(numOfNodes, vectorLength, hashFunction); var secondMomentFunction = new SecondMoment(width, height); var resultPath = PathBuilder.Create(resultDir, "AMS_F2") .AddProperty("Dataset", "DatabaseAccesses") .AddProperty("Nodes", numOfNodes.ToString()) .AddProperty("VectorLength", vectorLength.ToString()) .AddProperty("Width", width.ToString()) .AddProperty("Height", height.ToString()) .AddProperty("Window", window.ToString()) .AddProperty("Distributing", distributing.Name) .AddProperty("Approximation", approximation.AsString()) .ToPath("csv"); using (var resultCsvFile = AutoFlushedTextFile.Create(resultPath, AccumaltedResult.Header(numOfNodes))) using (var databaseAccessesStatistics = DatabaseAccessesStatistics.Init(databaseAccessesPath, numOfNodes, window, distributing.DistributeFunc)) { var initCountVectors = databaseAccessesStatistics.InitCountVectors(); var initVectors = hashFunction.TransformToAMSSketch(initCountVectors, vectorLength, hashFunctionsTable); var multiRunner = MultiRunner.InitAll(initVectors, numOfNodes, vectorLength, approximation, secondMomentFunction.MonitoredFunction); while (databaseAccessesStatistics.TakeStep()) { var changeCountVectors = databaseAccessesStatistics.GetChangeCountVectors(); var changeVectors = hashFunction.TransformToAMSSketch(changeCountVectors, vectorLength, hashFunctionsTable); multiRunner.Run(changeVectors, rnd, true) .Select(r => r.AsCsvString()) .ForEach(resultCsvFile.WriteLine); } } }