internal void MaxY_ReturnsExpectedResult() { // Arrange var function = SingletonFunction.Create(1); // Act var result = function.MaxY; // Assert Assert.Equal(UnitInterval.One(), result); }
internal void UpperBound_ReturnsExpectedResult() { // Arrange var function = SingletonFunction.Create(1); // Act var result = function.UpperBound; // Assert Assert.Equal(1, result); }
internal void GetMembership_VariousInputs_ReturnsExpectedResult(double x, double input, double expected) { // Arrange var function = SingletonFunction.Create(x); // Act var result = function.GetMembership(input); // Assert Assert.Equal(UnitInterval.Create(expected), result); }
private CustomResource CreateGrpcTargetGroup(Vpc vpc, Dictionary <string, object> properties) { // https://github.com/intercept6/example-aws-cdk-custom-resource // CustomResource Lambda for TargetGroup support ProtocolVersion Grpc var targetGroupEventHandler = new SingletonFunction(this, "grpc-targetgroup", new SingletonFunctionProps { Uuid = "4ddd3cf8-0a1b-43ee-994e-c15a2ffe1bd2", Code = Code.FromAsset(Path.Combine(Directory.GetCurrentDirectory(), "lambda"), new Amazon.CDK.AWS.S3.Assets.AssetOptions { AssetHashType = AssetHashType.OUTPUT, Bundling = new BundlingOptions { Image = Runtime.NODEJS_12_X.BundlingDockerImage, User = "******", Command = new[] { "bash", "-c", string.Join(" && ", new [] { "cp -au src package.json yarn.lock /tmp", "cd /tmp", "npm install --global yarn", "yarn install", "yarn -s esbuild src/lambda/target-group.ts --bundle --platform=node --target=node12 --outfile=/asset-output/index.js", }), }, }, }), Runtime = Runtime.NODEJS_12_X, Handler = "index.handler", MemorySize = 512, Timeout = Duration.Minutes(10), InitialPolicy = new[] { new PolicyStatement(new PolicyStatementProps { Actions = new [] { "elasticloadbalancing:*" }, Resources = new [] { "*" }, }) }, }); var provider = new Provider(this, "customProvider", new ProviderProps { OnEventHandler = targetGroupEventHandler, }); var grpcTargetGroupResource = new CustomResource(this, "grpc-target-group-lambda", new CustomResourceProps { ServiceToken = provider.ServiceToken, Properties = properties, }); return(grpcTargetGroupResource); }
internal void FuzzySetCollection_WhenUpperBoundLessThanHighestBoundOfFunctions_Throws() { // Arrange var fuzzySet1 = new FuzzySet("set1", TrapezoidalFunction.Create(1, 2, 3, 4)); var fuzzySet2 = new FuzzySet("set1", SingletonFunction.Create(1)); var fuzzySetCollection = new List <FuzzySet> { fuzzySet1, fuzzySet2 }; // Act // Assert Assert.Throws <ArgumentOutOfRangeException>(() => new LinguisticVariable("test", fuzzySetCollection, 1, 3)); }
internal void FuzzySetCollection_WhenLowerBoundGreaterThanUpperBound_Throws() { // Arrange var fuzzySet1 = new FuzzySet("set1", SingletonFunction.Create(1)); var fuzzySet2 = new FuzzySet("set1", SingletonFunction.Create(1)); var fuzzySetCollection = new List <FuzzySet> { fuzzySet1, fuzzySet2 }; // Act // Assert Assert.Throws <ArgumentException>(() => new LinguisticVariable("test", fuzzySetCollection, 1, 0)); }
/// <summary> /// Returns a <see cref="LinguisticVariable"/> representing fan speed. /// </summary> /// <returns> /// The <see cref="LinguisticVariable"/>. /// </returns> public static LinguisticVariable PumpSpeed() { return(new LinguisticVariable( InputVariable.PumpSpeed, new List <FuzzySet> { new FuzzySet(TestKit.PumpSpeed.Off, SingletonFunction.Create(0)), new FuzzySet(TestKit.PumpSpeed.VeryLow, TrapezoidalFunction.CreateWithLeftEdge(1, 200)), new FuzzySet(TestKit.PumpSpeed.Low, TriangularFunction.Create(0, 500, 1000)), new FuzzySet(TestKit.PumpSpeed.Moderate, TriangularFunction.Create(500, 1000, 2000)), new FuzzySet(TestKit.PumpSpeed.High, TriangularFunction.Create(3000, 3500, 4000)), new FuzzySet(TestKit.PumpSpeed.VeryHigh, TrapezoidalFunction.CreateWithRightEdge(3500, 4999)), new FuzzySet(TestKit.PumpSpeed.AtLimit, SingletonFunction.Create(5000)) })); }
/// <summary> /// Returns a <see cref="LinguisticVariable"/> representing water temperature. /// </summary> /// <returns> /// The <see cref="LinguisticVariable"/>. /// </returns> public static LinguisticVariable WaterTemp() { return(new LinguisticVariable( InputVariable.WaterTemp, new List <FuzzySet> { new FuzzySet(TestKit.WaterTemp.Frozen, SingletonFunction.Create(0)), new FuzzySet(TestKit.WaterTemp.Freezing, TriangularFunction.Create(0, 5, 10)), new FuzzySet(TestKit.WaterTemp.Cold, TrapezoidalFunction.Create(5, 10, 15, 20)), new FuzzySet(TestKit.WaterTemp.Warm, TrapezoidalFunction.Create(15, 25, 35, 40)), new FuzzySet(TestKit.WaterTemp.Hot, TrapezoidalFunction.Create(35, 60, 80, 100)), new FuzzySet(TestKit.WaterTemp.Boiling, TrapezoidalFunction.CreateWithRightEdge(95, 100)) }, -20, 200)); }
private InferenceSystem SetupInferenceSystem(byte minLuma, byte maxLuma, byte meanLuma) { var lumaIn = new LinguisticVariable("LumaIn", minLuma, maxLuma); var lumaOut = new LinguisticVariable("LumaOut", 0, 255); var darkFunction = new TrapezoidalFunction(minLuma, meanLuma, TrapezoidalFunction.EdgeType.Right); var darkSet = new FuzzySet("Dark", darkFunction); var mediumFunction = new TrapezoidalFunction(minLuma, meanLuma, maxLuma); var mediumSet = new FuzzySet("Medium", mediumFunction); var lightFunction = new TrapezoidalFunction(meanLuma, maxLuma, TrapezoidalFunction.EdgeType.Left); var lightSet = new FuzzySet("Light", lightFunction); lumaIn.AddLabel(darkSet); lumaIn.AddLabel(mediumSet); lumaIn.AddLabel(lightSet); var whiteFunction = new SingletonFunction(255); var whiteSet = new FuzzySet("White", whiteFunction); var blackFunction = new SingletonFunction(0); var blackSet = new FuzzySet("Black", blackFunction); var grayFunction = new SingletonFunction(128); var graySet = new FuzzySet("Gray", grayFunction); lumaOut.AddLabel(blackSet); lumaOut.AddLabel(graySet); lumaOut.AddLabel(whiteSet); var database = new Database(); database.AddVariable(lumaIn); database.AddVariable(lumaOut); var inferenceSystem = new InferenceSystem(database, new CogDefuzzifier()); inferenceSystem.NewRule("Rule 1", "IF LumaIn IS Dark THEN LumaOut is Black"); inferenceSystem.NewRule("Rule 2", "IF LumaIn IS Medium THEN LumaOut is Gray"); inferenceSystem.NewRule("Rule 3", "IF LumaIn IS Light THEN LumaOut is White"); return(inferenceSystem); }