Ejemplo n.º 1
0
        private static Rule SetRule(string mainRulePart)
        {
            var rule = new Rule { Level = mainRulePart.Split(new[] { "    " }, StringSplitOptions.None).Length - 1 };

            var properties = mainRulePart.Trim().Replace("   ", string.Empty).Split(new[] { " " }, StringSplitOptions.None);
            var relation = properties[1];

            rule.Property = properties[0];
            rule.Value = double.Parse(properties[2]);

            if (relation == "<=")
            {
                rule.Relation = RelationType.LessOrEqual;
            }
            else if (relation == ">")
            {
                rule.Relation = RelationType.Greater;
            }
            else
            {
                throw new InvalidDataException(string.Format("Operation {0} is unknown.", relation));
            }

            return rule;
        }
Ejemplo n.º 2
0
        public void TestInitialize()
        {
            _decisionTreeReaderMock = new Mock<IDecisionTreeReader>();
            _ruleBuilderMock = new Mock<IRuleBuilder>();
            _classifierMock = new Mock<IClassifier<FakeRecord>>();

            _decisionTreeReaderMock
                .Setup(x => x.ReadSubTrees(It.IsAny<string>()));

            var treeBuilder = new StringBuilder();
            treeBuilder.AppendLine("Ask <= 1.1:Sell (31.0/1.0)");
            treeBuilder.AppendLine("Ask > 1.1:");
            treeBuilder.AppendLine("    Bid <= 1.2:Buy (123.0/1.0)");
            treeBuilder.AppendLine("    Bid > 1.2:Hold (31.0/1.0)");
            _treeString = treeBuilder.ToString();

            _decisionTreeReaderMock
                .Setup(x => x.NormalizeTreeSource(It.IsAny<string>()))
                .Returns(_treeString);

            _decisionTreeReaderMock
                .Setup(x => x.NormalizeTree(It.IsAny<string>()))
                .Returns(_treeString);

            _fakeRule = new Rule {Level = 0};
            _ruleBuilderMock
                .Setup(x => x.Read(It.IsAny<string>()))
                .Returns(_fakeRule);

            _tree = new DecisionTree<FakeRecord>(
                _decisionTreeReaderMock.Object,
                _ruleBuilderMock.Object,
                _classifierMock.Object);
        }
Ejemplo n.º 3
0
 public void MapRules(Rule previousRule, Rule currentRule)
 {
     switch (currentRule.Relation)
     {
         case RelationType.LessOrEqual:
             previousRule.LessOrEqualRule = currentRule;
             break;
         case RelationType.Greater:
             previousRule.GreaterRule = currentRule;
             break;
         default:
             throw new ArgumentException("Relation Type unknown.");
     }
 }
Ejemplo n.º 4
0
 public void TestInitialize()
 {
     _classifier = new Classifier<FakeRecord>();
     _root = new Rule
     {
         LessOrEqualRule = new Rule
         {
             Property = "Ask",
             Value = 1.1,
             Relation = RelationType.LessOrEqual,
             Action = MarketAction.Sell
         },
         GreaterRule = new Rule
         {
             Property = "Ask",
             Value = 1.1,
             Relation = RelationType.Greater,
             LessOrEqualRule = new Rule
             {
                 Property = "Bid",
                 Value = 1.2,
                 Relation = RelationType.LessOrEqual,
                 Action = MarketAction.Buy
             },
             GreaterRule = new Rule
             {
                 Property = "Bid",
                 Value = 1.2,
                 Relation = RelationType.Greater,
                 Action = MarketAction.Hold
             }
         }
     };
 }