Пример #1
0
 private static void DrawTree(string[] args, IDecisionTree tree)
 {
     if (args.Contains(FlagDrawTree))
     {
         Console.WriteLine(tree.Draw());
     }
 }
Пример #2
0
        public void RemoveTree(IDecisionTree tree)
        {
            bool CanDelete = false;

            if (tree.IsDirty)
            {
                CanDelete = App.GetFloatingForm(
                    eFloatReason.NotSet,
                    new ucConfirmDropModel(tree, Mode == eDecisionTreeMode.DecisionModel))
                            .ShowDialog() == DialogResult.OK;
            }
            else
            {
                CanDelete = true;
            }

            if (CanDelete)
            {
                Trees.Remove(tree);
                RefreshTree(tvDecisionTree);

                App.SelectedTree   = Trees.Count > 0 ? Trees[0] : null;
                App.SelectedObject = Trees.Count > 0 ? Trees[0] : null;
            }
        }
 public ForexTradingAgentService(
     IDecisionTreesRepository decisionTreesRepository,
     IDecisionTree<ForexTreeData> decisionTree)
 {
     _decisionTreesRepository = decisionTreesRepository;
     _decisionTree = decisionTree;
 }
Пример #4
0
        private void mnuNodesReload_Click(object sender, EventArgs e)
        {
            IBaseNode currentNode = TreeNodeAsBaseNode(tvDecisionTree.SelectedNode);

            if (currentNode != null)
            {
                IDecisionTree tree = currentNode.Tree;

                bool CanDelete = false;

                if (tree.IsDirty)
                {
                    CanDelete = App.GetFloatingForm(eFloatReason.NotSet, new ucConfirmDropModel(tree)).ShowDialog() == DialogResult.OK;
                }
                else
                {
                    CanDelete = true;
                }

                if (CanDelete)
                {
                    int           treeIndex = Trees.IndexOf(tree);
                    IDecisionTree newTree   = App.NewDescisionTree();
                    newTree.Load(tree.Persistence.Clone(), tree.FullPath);

                    Trees.Remove(tree);
                    Trees.Insert(treeIndex, newTree);
                    RefreshTree(tvDecisionTree);

                    App.SelectedTree = Trees.Count > 0 ? Trees[0] : null;

                    App.SelectedObject = Trees.Count > 0 ? Trees[0] : null;
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Decision Manager Constructor
        /// </summary>
        /// <param name="surveyor">Convertion and table size storage unit. 
        /// (If null [default] - will be instantiated in constructor)</param>
        /// <param name="ricochetCalc">Ricochet calc unit. NOTE: working in mm. 
        /// (If null [default] - will be instantiated in constructor)</param>
        /// <param name="predictor">Predictor for ball coordinates
        /// (If null [default] - will be instantiated in constructor)</param>
        /// <param name="decisionTree">Full decision tree to make decisions per eacch rod.
        /// (If null [default] - will be instantiated in constructor)</param>
        /// <param name="controlledRods">Rods to be controlled by manager
        /// (If null [default] - will be instantiated in constructor)</param>
        public DecisionManager(ISurveyor surveyor = null, IInitializableRicochet ricochetCalc = null, IPredictor predictor = null, IDecisionTree decisionTree = null, List<IInitializableRod> controlledRods = null)
        {
            _surveyor =  surveyor ?? new Surveyor();

            IInitializableRicochet ricochetCalculator = ricochetCalc ?? new RicochetCalc(true, eUnits.Mm);

            _decisionTree = decisionTree ?? new FullDecisionTree(new PartialDecisionTree());

            _predictor = predictor ?? new Predictor(_surveyor, ricochetCalculator);

            //use given rods if not null
            if (controlledRods != null)
            {
                _controlledRods = controlledRods;
            }
            //create new rods and init them
            else
            {
                _controlledRods = new List<IInitializableRod>();
                foreach (eRod type in Enum.GetValues(typeof(eRod)))
                {
                    IInitializableRod rod = new ControlRod(type, _surveyor, ricochetCalculator);
                    rod.Initialize();
                    _controlledRods.Add(rod);
                }
            }
        }
Пример #6
0
        public static void Main(string[] args)
        {
            Args = args;

            int runs = GetRunCount();

            int totalAccuracy = 0;

            for (int i = 0; i < runs; i++)
            {
                DataSet       dataSets = CreateDataSet();
                IDecisionTree tree     = BuildTree(dataSets);

                DrawTree(args, tree);
                totalAccuracy += ValidateTree(args, dataSets, tree);
            }

            if (runs > 1)
            {
                Console.WriteLine($"Average accuracy {(double)totalAccuracy / runs}%");
            }

            if (!args.Contains(FlagNoPause))
            {
                Console.WriteLine("Press any key to close program...");
                Console.ReadKey();
            }
        }
Пример #7
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            if (Control.ModifierKeys == (Keys.Control | Keys.Shift))
            {
                IApplicationInterface.GetFloatingForm(
                    eFloatReason.NotSet,
                    new ucPropertyEditor(DataSourceManager.DataSourceFactories[0]))
                .ShowDialog(this);

                return;
            }

            // Open NewModel UserControl
            ucNewModel newModel = new ucNewModel();
            string     rootName = string.Format("Decision model-{0}", ctrl.Trees.Count + 1);

            if (IApplicationInterface.GetFloatingForm(eFloatReason.NotSet, newModel)
                .ShowDialog() == DialogResult.OK)
            {
                IDecisionTree tree = IApplicationInterface.NewDescisionTree(rootName);
                tree.Persistence = new XmlPersistenceImpl();
                (tree.RootNode as IRootNode).DomainTemplate = newModel.SelectedDomainModelFile;

                ctrl.AddTree(tree);
            }
        }
Пример #8
0
        public ExpressionString(IDecisionTree tree, string text)
        {
            _DecisionTree = tree;
            _Text         = text;

            ParseRawText();
        }
Пример #9
0
        private void AddNode(eNodeType nodeType)
        {
            IBaseNode     currentNode = TreeNodeAsBaseNode(tvDecisionTree.SelectedNode);
            IDecisionTree tree        = currentNode.Tree;

            if (tree != null)
            {
                IBaseNode newNode = tree.CreateNewNode(nodeType, currentNode);
                newNode.Updated += Node_Updated;
                if (newNode.NodeType == eNodeType.VarDefinition)
                {
                    (newNode as IVariableDef).VariableTypeChanged += VariableTypeChanged;
                }

                if (newNode.NodeType == eNodeType.DomainObject)
                {
                    (newNode as IDomainObject).UpdatedAndRefresh += UpdateAdRefresh;
                }

                TreeNode node = modelGUIConfig.BaseNodeAsTreeNode(newNode);

                tvDecisionTree.SelectedNode.Nodes.Add(node);
                tvDecisionTree.SelectedNode.Expand();
                tvDecisionTree.SelectedNode = node;
            }

            App.SelectedTree = tree;
        }
Пример #10
0
 public void AddTree(IDecisionTree tree)
 {
     Trees.Add(tree);
     RefreshTree(tvDecisionTree);
     tree.RootNode.UpdatedAndRefresh += UpdateAdRefresh;
     tree.UpdatedAndRefresh          += UpdateAdRefresh;
     App.SelectedTree = tree.RootNode.Nodes.Count > 1 ? tree : null;
 }
Пример #11
0
 public void AddExample(IDecisionTree <ValueType> example)
 {
     if (_examples.Any(x => x.Equals(example)))
     {
         return;
     }
     _examples.Add(example);
 }
Пример #12
0
 /// <summary>
 /// Create new if/then/else decision tree.
 /// </summary>
 /// <param name="condition">Condition subtree.</param>
 /// <param name="consequent">Consequent (true) subtree.</param>
 /// <param name="alternative">Alternative (false) subtree.</param>
 internal BooleanDecision(
     IDecisionTree <bool> condition,
     IDecisionTree <T> consequent,
     IDecisionTree <T> alternative)
     : base(consequent, alternative)
 {
     this.condition = condition;
 }
Пример #13
0
        public ucConfirmDropModel(IDecisionTree tree, bool isModel = true)
        {
            InitializeComponent();

            if (!isModel)
            {
                label2.Text        = label2.Text.Replace(UI_Constants.ModelName, UI_Constants.TemplateName);
                counterPanel1.Text = counterPanel1.Text.Replace(UI_Constants.ModelName, UI_Constants.TemplateName);
            }
        }
Пример #14
0
        public DataConnectionForm(IBaseNode selectedNode)
        {
            InitializeComponent();

            lbxAvailable.DrawItem += lbxAvailable_DrawItem;
            lbxSelected.DrawItem  += lbxAvailable_DrawItem;

            IDecisionTree tree = selectedNode.Tree;

            AddDataNodesToAvailable(tree.RootNode.GetNode(eNodeType.DataObjects));
        }
        public LinkDataDefinitionsForm(IBaseNode baseNode)
        {
            InitializeComponent();

            lbxAvailable.DrawItem += lbxAvailable_DrawItem;
            lbxSelected.DrawItem  += lbxAvailable_DrawItem;

            IDecisionTree tree = baseNode.Tree;

            AddDataNodesToAvailable(tree.RootNode.GetNode(eNodeType.DataSources));
        }
Пример #16
0
        private void SaveTreeFile(IDecisionTree tree, string fileName)
        {
            IPersistence persistence = new XmlPersistenceImpl(fileName, true);

            if (tree.Save(persistence, fileName))
            {
                if (persistence.SaveAs(fileName))
                {
                    IApplicationInterface.StatusLine = string.Format("{0} saved to disk", Path.GetFileName(fileName));
                }
            }
        }
Пример #17
0
        private void LoadFile(string fileName)
        {
            LastUsedFolder = fileName;
            IDecisionTree tree        = IApplicationInterface.NewDescisionTree();
            IPersistence  persistence = new XmlPersistenceImpl(fileName);

            if (tree.Load(persistence, fileName))
            {
                ctrl.AddTree(tree);
                IApplicationInterface.StatusLine = string.Format("Opened {0} from disk", Path.GetFileName(fileName)) + UI_Constants.ZoomPanHint;
            }
        }
Пример #18
0
        public static string Draw(this IDecisionTree tree)
        {
            numberOfLeafNodes = 0;
            maxDepth          = 0;

            var treeView = new StringBuilder();

            DrawTree(tree, depth: 0, treeView);

            treeView.Append($"\nMax depth: {maxDepth}, Leaf nodes: {numberOfLeafNodes}\n");

            return(treeView.ToString());
        }
Пример #19
0
        public NodeLinkForm(IBaseNode selectedNode, eNodeType rootNodeType, string title)
        {
            InitializeComponent();

            Text = title;

            lbxAvailable.DrawItem += lbxAvailable_DrawItem;
            lbxSelected.DrawItem  += lbxAvailable_DrawItem;

            IDecisionTree tree = selectedNode.Tree;

            AddDataNodesToAvailable(tree.RootNode.GetNode(rootNodeType));
        }
Пример #20
0
        bool IModelGraphics.ParseDecisionModel(IDecisionTree tree)
        {
            if (tree != null)
            {
                //IGraphBase connectedTo = AddGraphicCommand(new VerticalLine(0, 0));
                IGraphBase connectedTo = AddGraphicCommand(new ModelStart(0, 0));
                ParseNodes(tree.RootNode.Nodes, 0, 1, connectedTo);
            }

            //foreach (IGraphBase gb in GraphicCommands)
            //    log.Debug(string.Format("{4} - {0}, ({1},{2}) {3}", gb.GetType().ToString(), gb.HorizontalOffset, gb.VerticalOffset, gb.Label, gb.Index));

            return(GraphicCommands.Count > 0);
        }
Пример #21
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            string        rootName = string.Format("Domain template-{0}", ctrl.Trees.Count + 1);
            IDecisionTree tree     = IApplicationInterface.NewDescisionTree(rootName);

            IBaseNode dataObjects = tree.CreateNewNode(eNodeType.DataObjects, null, Constants.DataNodesTreeName);

            tree.RootNode.AddNode(dataObjects);

            IBaseNode dataSources = tree.CreateNewNode(eNodeType.DataSources, null, Constants.DataSourcesTreeName);

            tree.RootNode.AddNode(dataSources);

            ctrl.AddTree(tree);
        }
Пример #22
0
        public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            if (svc != null)
            {
                IBaseNode baseNode = context.Instance as IBaseNode;
                if (baseNode != null)
                {
                    using (DataConnectionForm frm = new DataConnectionForm(baseNode))
                    {
                        IDataPersistence dp = getDataPersistence(baseNode);
                        if (dp != null)
                        {
                            IDecisionTree tree     = baseNode.Tree;
                            List <string> Elements = new List <string>();
                            foreach (string reference in dp.DataConnections)
                            {
                                IBaseNode node = tree.GetNodeByReference(reference);
                                if (node != null)
                                {
                                    Elements.Add(node.Name);
                                }
                            }
                            frm.Elements = Elements;

                            if (svc.ShowDialog(frm) == DialogResult.OK)
                            {
                                List <string> result    = new List <string>();
                                IBaseNode     dataNodes = tree.RootNode.GetNode(eNodeType.DataObjects);
                                foreach (string name in frm.Elements)
                                {
                                    IBaseNode dc = dataNodes.GetNode(name);
                                    if (dc != null)
                                    {
                                        result.Add(dc.Reference);
                                    }
                                }

                                value = result.ToArray();
                            }
                        }
                    }
                }
            }

            return(value);
        }
Пример #23
0
        bool IDecisionTree.LoadDomainTemplate(IRootNode rootNode)
        {
            IPersistence persistence = Persistence.Clone(rootNode.DomainTemplate);

            if (persistence != null)
            {
                IDecisionTree subTree = IDecisionTreeInterface.Clone();

                IBaseNode variables = subTree.LoadVariables(persistence);
                IDecisionTreeInterface.ImportVariables(variables);

                return(true);
            }

            return(false);
        }
Пример #24
0
        public static void DecisionManager_ClassInitialize(TestContext context)
        {
            _surveyorMock = Substitute.For<ISurveyor>();
            _ricochetCalcMock = Substitute.For<IInitializableRicochet>();
            _predictorMock = Substitute.For<IPredictor>();
            _decisionTreeMock = Substitute.For<IDecisionTree>();
            
            _rodGoalKeaperMock = Substitute.For<IInitializableRod>();
            _rodDefenceMock = Substitute.For<IInitializableRod>();
            _rodMidFieldMock = Substitute.For<IInitializableRod>();
            _rodAttackMock = Substitute.For<IInitializableRod>();

            _rodMockList = new List<IInitializableRod>()
            {  
                _rodGoalKeaperMock, _rodDefenceMock,
                _rodMidFieldMock, _rodAttackMock
            };
        }
Пример #25
0
        public static void DecisionManager_ClassInitialize(TestContext context)
        {
            _surveyorMock     = Substitute.For <ISurveyor>();
            _ricochetCalcMock = Substitute.For <IInitializableRicochet>();
            _predictorMock    = Substitute.For <IPredictor>();
            _decisionTreeMock = Substitute.For <IDecisionTree>();

            _rodGoalKeaperMock = Substitute.For <IInitializableRod>();
            _rodDefenceMock    = Substitute.For <IInitializableRod>();
            _rodMidFieldMock   = Substitute.For <IInitializableRod>();
            _rodAttackMock     = Substitute.For <IInitializableRod>();

            _rodMockList = new List <IInitializableRod>()
            {
                _rodGoalKeaperMock, _rodDefenceMock,
                _rodMidFieldMock, _rodAttackMock
            };
        }
Пример #26
0
        public EnumFromModelForm(IBaseNode selectedNode)
        {
            InitializeComponent();

            lbxAvailable.DrawItem += lbxAvailable_DrawItem;
            lbxSelected.DrawItem  += lbxAvailable_DrawItem;

            IDecisionTree tree = selectedNode.Tree;

            AddBranchToAvailable(tree.RootNode);

            toolTip.SetToolTip(btnOk, UI_Constants.CommitEnumToolTip);
            toolTip.SetToolTip(btnClose, UI_Constants.RevertEnumToolTip);

            toolTip.SetToolTip(btnAdd, UI_Constants.AddEnumToolTip);
            toolTip.SetToolTip(btnRemove, UI_Constants.RemoveEnumToolTip);
            toolTip.SetToolTip(btnNew, UI_Constants.NewEnumToolTip);
            toolTip.SetToolTip(btnMoveUp, UI_Constants.MoveUpEnumToolTip);
            toolTip.SetToolTip(btnMoveDown, UI_Constants.MoveDownEnumToolTip);
        }
Пример #27
0
        public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            if (svc != null)
            {
                IBaseNode baseNode = context.Instance as IBaseNode;
                if (baseNode != null)
                {
                    using (LinkDataDefinitionsForm frm = new LinkDataDefinitionsForm(baseNode))
                    {
                        IDataPersistence dp = getDataPersistence(baseNode);
                        if (dp != null)
                        {
                            IDecisionTree tree = baseNode.Tree;
                            List <LinkDataDefinitionsForm.ListBoxItem> Elements = new List <LinkDataDefinitionsForm.ListBoxItem>();
                            foreach (string reference in dp.DataConnections)
                            {
                                IBaseNode node = tree.GetNodeByReference(reference);
                                if (node != null)
                                {
                                    Elements.Add(new LinkDataDefinitionsForm.ListBoxItem(node, 0));
                                }
                            }
                            frm.Elements = Elements;

                            if (svc.ShowDialog(frm) == DialogResult.OK)
                            {
                                dp.DataConnections.Clear();
                                foreach (LinkDataDefinitionsForm.ListBoxItem lbi in frm.Elements)
                                {
                                    dp.DataConnections.Add(lbi.Node.Reference);
                                }
                            }
                        }
                    }
                }
            }

            return(value);
        }
Пример #28
0
        } //FloatingForm IApplication.GetFloatingForm( ...

        IDecisionTree IApplication.NewDescisionTree(string rootName, PostNodeInitialize nodeInitialization)
        {
            Assembly asm = Assembly.GetCallingAssembly();

            SakwaMapping mapping = new SakwaMapping("0.0");

            mapping.SakwaObjectMapping.Add(typeof(IBaseNodeImpl).ToString(), typeof(UI_BaseNode).ToString());
            mapping.SakwaObjectMapping.Add(typeof(IRootNodeImpl).ToString(), typeof(UI_RootNode).ToString());

            mapping.SakwaObjectMapping.Add(typeof(CharVariableImpl).ToString(), typeof(UI_CharVariable).ToString());
            mapping.SakwaObjectMapping.Add(typeof(NumericVariableImpl).ToString(), typeof(UI_NumericVariable).ToString());
            mapping.SakwaObjectMapping.Add("sakwa.IntVariableImpl", typeof(UI_NumericVariable).ToString());
            mapping.SakwaObjectMapping.Add(typeof(EnumVariableImpl).ToString(), typeof(UI_EnumVariable).ToString());
            mapping.SakwaObjectMapping.Add(typeof(BoolVariableImpl).ToString(), typeof(UI_BoolVariable).ToString());
            mapping.SakwaObjectMapping.Add(typeof(DateVariableImpl).ToString(), typeof(UI_DateVariable).ToString());

            mapping.SakwaObjectMapping.Add(typeof(IDomainObjectImpl).ToString(), typeof(UI_DomainObject).ToString());
            mapping.SakwaObjectMapping.Add(typeof(IExpressionImpl).ToString(), typeof(UI_Expression).ToString());
            mapping.SakwaObjectMapping.Add("sakwa.IAssignmentImpl", typeof(UI_Expression).ToString());
            mapping.SakwaObjectMapping.Add(typeof(IBranchImpl).ToString(), typeof(UI_Branch).ToString());

            mapping.SakwaObjectMapping.Add(typeof(IDataObjectImpl).ToString(), typeof(UI_DataObject).ToString());
            mapping.SakwaObjectMapping.Add(typeof(IDataSourceImpl).ToString(), typeof(UI_DataSource).ToString());
            mapping.SakwaObjectMapping.Add(typeof(IDataDefinitionImpl).ToString(), typeof(UI_DataDefinition).ToString());

            if (nodeInitialization == null)
            {
                nodeInitialization = Result_PostNodeInitialize;
            }

            IDecisionTree result = rootName != ""
                ? new IDecisionTreeImpl(asm, mapping, nodeInitialization, rootName)
                : new IDecisionTreeImpl(asm, mapping, nodeInitialization);

            result.LinkSubtreeError += LinkSubtreeError;

            return(result);
        } //IApplication.NewDescisionTree
Пример #29
0
        private void ShowTemplatePreview()
        {
            tvTemplate.Nodes.Clear();
            IDecisionTree tree = App.NewDescisionTree();

            IBaseNode baseNode = tree.CreateNewNode(eNodeType.Root, null, "Domain template");
            TreeNode  rootNode = modelGUIConfig.BaseNodeAsTreeNode(baseNode);

            modelGUIConfig.ConfigureTreeNode(rootNode);
            tvTemplate.Nodes.Add(modelGUIConfig.ConfigureTreeNode(rootNode));

            baseNode = tree.CreateNewNode(eNodeType.DataObjects, null, "Data objects");
            TreeNode dataobjs = modelGUIConfig.BaseNodeAsTreeNode(baseNode);

            rootNode.Nodes.Add(modelGUIConfig.ConfigureTreeNode(dataobjs));

            baseNode = tree.CreateNewNode(eNodeType.DataObject, null, "Data object");
            TreeNode node = modelGUIConfig.BaseNodeAsTreeNode(baseNode);

            dataobjs.Nodes.Add(modelGUIConfig.ConfigureTreeNode(node));

            baseNode = tree.CreateNewNode(eNodeType.DataSources, null, "Data sources");
            TreeNode dataSources = modelGUIConfig.BaseNodeAsTreeNode(baseNode);

            rootNode.Nodes.Add(modelGUIConfig.ConfigureTreeNode(dataSources));

            baseNode = tree.CreateNewNode(eNodeType.DataSource, null, "Data source");
            TreeNode dataSource = modelGUIConfig.BaseNodeAsTreeNode(baseNode);

            dataSources.Nodes.Add(modelGUIConfig.ConfigureTreeNode(dataSource));

            baseNode = tree.CreateNewNode(eNodeType.DataDefinition, null, "Data definition");
            node     = modelGUIConfig.BaseNodeAsTreeNode(baseNode);
            dataSource.Nodes.Add(modelGUIConfig.ConfigureTreeNode(node));

            tvTemplate.ExpandAll();
        }
Пример #30
0
        private void ShowModelPreview()
        {
            tvModel.Nodes.Clear();
            IDecisionTree tree = App.NewDescisionTree();

            IBaseNode baseNode = tree.CreateNewNode(eNodeType.Root, null, "Decision model");
            TreeNode  rootNode = modelGUIConfig.BaseNodeAsTreeNode(baseNode);

            modelGUIConfig.ConfigureTreeNode(rootNode);
            tvModel.Nodes.Add(modelGUIConfig.ConfigureTreeNode(rootNode));

            baseNode = tree.CreateNewNode(eNodeType.VariableDefinitions, null, "Variable definitions");
            TreeNode vars = modelGUIConfig.BaseNodeAsTreeNode(baseNode);

            rootNode.Nodes.Add(modelGUIConfig.ConfigureTreeNode(vars));

            baseNode = tree.CreateNewNode(eNodeType.VarDefinition, null, "Variable definition");
            TreeNode node = modelGUIConfig.BaseNodeAsTreeNode(baseNode);

            vars.Nodes.Add(modelGUIConfig.ConfigureTreeNode(node));

            baseNode = tree.CreateNewNode(eNodeType.DomainObject, null, "Domain object");
            TreeNode decision = modelGUIConfig.BaseNodeAsTreeNode(baseNode);

            vars.Nodes.Add(modelGUIConfig.ConfigureTreeNode(decision));


            baseNode = tree.CreateNewNode(eNodeType.Expression, null, "Expression");
            node     = modelGUIConfig.BaseNodeAsTreeNode(baseNode);
            rootNode.Nodes.Add(modelGUIConfig.ConfigureTreeNode(node));

            baseNode = tree.CreateNewNode(eNodeType.Branch, null, "Branch");
            node     = modelGUIConfig.BaseNodeAsTreeNode(baseNode);
            rootNode.Nodes.Add(modelGUIConfig.ConfigureTreeNode(node));

            tvModel.ExpandAll();
        }
Пример #31
0
        private void RootNode_NodeLoaded(object sender, EventArgs e)
        {
            IBaseNode node = sender as IBaseNode;

            if (node != null && node.NodeType == eNodeType.VariableDefinitions)
            {
                if (Persistence != null)
                {
                    int i = 0;
                    while (i < SubModels.Keys.Count)
                    {
                        IPersistence persistence = getSubModel(i);

                        if (persistence != null)
                        {
                            IDecisionTree subTree = IDecisionTreeInterface.Clone();

                            IBaseNode variables = subTree.LoadVariables(persistence);
                            foreach (IBaseNode subModel in subTree.SubModels.Keys)
                            {
                                IDecisionTreeInterface.AddSubModel(subModel as IDomainObject);
                            }

                            IBaseNode baseNode = SubModels.Keys.ElementAt(i);

                            List <IBaseNode> linkedVariables = LinkVariables(node, variables);
                            foreach (IBaseNode linkedNode in linkedVariables)
                            {
                                baseNode.AddNode(linkedNode);
                            }
                        }

                        i++;
                    }
                }
            }
        }
Пример #32
0
        private static int ValidateTree(string[] args, DataSet dataSets, IDecisionTree tree)
        {
            int totalPredictions   = 0;
            int correctPredictions = 0;

            foreach (var row in dataSets.TestData.Rows())
            {
                string predictedClassification = tree.Classify(row);

                string @class = row[dataSets.TargetAttribute];
                if (@class == predictedClassification)
                {
                    correctPredictions++;
                }

                totalPredictions++;
            }

            int accuracy = (int)((double)correctPredictions / totalPredictions * 100);

            Console.WriteLine($"Total predictions: {totalPredictions}, correct: {correctPredictions} ({accuracy}%)");

            return(accuracy);
        }
Пример #33
0
        private void LoadFile(string fileName)
        {
            LastUsedFolder = fileName;
            IDecisionTree tree        = IApplicationInterface.NewDescisionTree();
            IPersistence  persistence = new XmlPersistenceImpl(fileName);

            if (tree.Load(persistence, fileName))
            {
                if (tree.RootNode.GetNode(eNodeType.DataObjects) == null)
                {
                    IBaseNode dataObjects = tree.CreateNewNode(eNodeType.DataObjects, null, Constants.DataNodesTreeName);
                    tree.RootNode.AddNode(dataObjects);
                }

                if (tree.RootNode.GetNode(eNodeType.DataSources) == null)
                {
                    IBaseNode dataSources = tree.CreateNewNode(eNodeType.DataSources, null, Constants.DataSourcesTreeName);
                    tree.RootNode.AddNode(dataSources);
                }

                ctrl.AddTree(tree);
                IApplicationInterface.StatusLine = string.Format("Opened {0} from disk", Path.GetFileName(fileName)) + UI_Constants.ZoomPanHint;
            }
        }
Пример #34
0
 /// <summary>
 /// Decision Tree Constructor
 /// </summary>
 /// <param name="subtree">Decision Sub Tree</param>
 /// <param name="decisionHelper">Decision Helper [default is null then will be constructed using Configuration File]</param>
 /// <param name="ballRadius">Ball Radius in mm [default is -1 will be taken from Configuration File]</param>
 /// <param name="tableWidth">Table Width (Y Axe) in mm [default is -1 will be taken from Configuration File]</param>
 /// <param name="playerWidth">Player Width in mm [default is -1 will be taken from Configuration File]</param>
 public FullDecisionTree(IDecisionTree subtree, IDecisionHelper decisionHelper = null, int ballRadius = -1, int tableWidth = -1, int playerWidth = -1)
     : base(subtree, decisionHelper, ballRadius, tableWidth, playerWidth)
 {
 }
Пример #35
0
 /// <summary>
 /// Decision Tree Constructor for Tree with a Subtree
 /// </summary>
 /// <param name="subTree">Decision Subtree</param>
 /// <param name="decisionHelper">Decision Helper Instance [default is null then will be constructed using Configuration File]</param>
 /// <param name="ballRadius">Ball Radius in mm [default is -1 will be taken from Configuration File]</param>
 /// <param name="tableWidth">Table Width (Y Axe) in mm [default is -1 will be taken from Configuration File]</param>
 /// <param name="playerWidth">Player Width in mm [default is -1 will be taken from Configuration File]</param>
 public DecisionTree(IDecisionTree subTree, IDecisionHelper helper = null, int ballRadius = -1, int tableWidth = -1, int playerWidth = -1)
     :this(helper, ballRadius, tableWidth, playerWidth)
 {
     _subTree = subTree;
 }