public EntropyFunction(int dimension) { Dimension = dimension; MonitoredFunction = new MonitoredFunction(ComputeEntropy, UpperBound, LowerBound, GlobalVectorType.Average, 1); MinEntropy = 0.0; MaxEntropy = Math.Log(Dimension); }
public static NodeServer <NodeType> Create( Vector[] initVectors, int numOfNodes, int vectorLength, GlobalVectorType globalVectorType, ApproximationType approximation, MonitoredFunction monitoredFunction, ResolveNodesFunction <NodeType> resolveNodes, Func <Vector, ConvexBound, int, int, NodeType> createNode) { initVectors = initVectors.Map(v => v.Clone()); var globalVector = globalVectorType.GetValue(initVectors); var(lowerBound, upperBound) = approximation.Calc(monitoredFunction.Function(globalVector)); var upperConvexBound = monitoredFunction.UpperBound(globalVector, upperBound); var lowerConvexBound = monitoredFunction.LowerBound(globalVector, lowerBound); var upperNodes = ArrayUtils.Init(numOfNodes, i => createNode(globalVector.Clone(), upperConvexBound, i, vectorLength)); var lowerNodes = ArrayUtils.Init(numOfNodes, i => createNode(globalVector.Clone(), lowerConvexBound, i, vectorLength)); NodeServer <NodeType> ReCreate(Vector[] newInitVectors) => Create(newInitVectors, numOfNodes, vectorLength, globalVectorType, approximation, monitoredFunction, resolveNodes, createNode); return(new NodeServer <NodeType>(initVectors, numOfNodes, vectorLength, globalVectorType, upperBound, lowerBound, monitoredFunction.Function, approximation, upperNodes, lowerNodes, resolveNodes, ReCreate)); }
public static OracleServer Create( Vector[] initVectors, int numOfNodes, int vectorLength, GlobalVectorType globalVectorType, ApproximationType approximation, MonitoredFunction monitoredFunction) { initVectors = initVectors.Map(v => v.Clone()); var globalVector = globalVectorType.GetValue(initVectors); var(lowerBound, upperBound) = approximation.Calc(monitoredFunction.Function(globalVector)); return(new OracleServer(initVectors, numOfNodes, vectorLength, globalVectorType, upperBound, lowerBound, monitoredFunction.Function, approximation)); }
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 SphereFunction(int dimension) { Dimension = dimension; MonitoredFunction = new MonitoredFunction(Compute, UpperBound, LowerBound, GlobalVectorType.Average, 2); }
public EntropySketchFunction(int dimension) { Dimension = dimension; MonitoredFunction = new MonitoredFunction(ComputeEntropySketch, UpperBound, LowerBound, GlobalVectorType.Average, 1); }
public SecondMoment(int width, int height) { Width = width; Height = height; MonitoredFunction = new MonitoredFunction(Compute, UpperBound, LowerBound, GlobalVectorType.Sum, 2, 0); }
public InnerProductFunction(int dimension) { Dimension = dimension; MonitoredFunction = new MonitoredFunction(Compute, UpperBound, LowerBound, GlobalVectorType.Sum, 2); }