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 OracleServer(Vector[] nodesVectors, int numOfNodes, int vectorLength, GlobalVectorType globalVectorType, double upperBound, double lowerBound, Func <Vector, double> function, ApproximationType approximation) : base(nodesVectors, numOfNodes, vectorLength, globalVectorType, upperBound, lowerBound, function, approximation) { Init(); }
protected AbstractServer(Vector[] nodesVectors, int numOfNodes, int vectorLength, GlobalVectorType globalVectorType, double upperBound, double lowerBound, Func <Vector, double> function, ApproximationType approximation) { NodesVectors = nodesVectors; NumOfNodes = numOfNodes; VectorLength = vectorLength; GlobalVectorType = globalVectorType; UpperBound = upperBound; LowerBound = lowerBound; Function = function; Approximation = approximation; }
public MonitoredFunction( Func <Vector, double> function, Func <Vector, threshold, ConvexBound> upperBound, Func <Vector, threshold, ConvexBound> lowerBound, GlobalVectorType globalVectorType, params int[] norms) { Function = function; UpperBound = upperBound; LowerBound = lowerBound; GlobalVectorType = globalVectorType; Norms = norms; }
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 NodeServer(Vector[] nodesVectors, int numOfNodes, int vectorLength, GlobalVectorType globalVectorType, double upperBound, double lowerBound, Func <Vector, double> function, ApproximationType approximation, NodeType[] upperNodes, NodeType[] lowerNodes, ResolveNodesFunction <NodeType> resolveNodes, Func <Vector[], NodeServer <NodeType> > reCreate) : base(nodesVectors, numOfNodes, vectorLength, globalVectorType, upperBound, lowerBound, function, approximation) { UpperNodes = upperNodes; LowerNodes = lowerNodes; ResolveNodes = resolveNodes; ReCreate = reCreate; }
protected override (NodeServer <NodeType>, Communication, bool fullSync) LocalChange(Vector[] changeMatrix, Random rnd) { double mulBy = GlobalVectorType.MulBy(NumOfNodes); for (int nodeNum = 0; nodeNum < NumOfNodes; nodeNum++) { this.UpperNodes[nodeNum].Change(changeMatrix[nodeNum] * mulBy); this.LowerNodes[nodeNum].Change(changeMatrix[nodeNum] * mulBy); } var(newServerLowerResolved, lowerCommunication, isFullSync1) = this.Resolve(this.LowerNodes, rnd); var(newServerAllResolved, upperCommunication, isFullSync2) = newServerLowerResolved.Resolve(newServerLowerResolved.UpperNodes, rnd); if (newServerAllResolved.FunctionValue > newServerAllResolved.UpperBound) { newServerAllResolved = newServerLowerResolved; } return(newServerAllResolved, lowerCommunication.Add(upperCommunication, setLatency: false), isFullSync1 || isFullSync2); }