예제 #1
0
        void OnLearningFinished(ILearningTask learningTask)
        {
            Dispatcher.Invoke(delegate
            {
                if (Model.BayesianNetwork != learningTask.BayesianNetwork)
                {
                    return;
                }

                // If this learning finished for the network we're currently
                // looking at.

                xLearningInspector.SetIsLearning(false);
                SetBayesianNetwork(learningTask.BayesianNetwork, "");

                xGraphInspector.SetInferenceResults(null, 1, null);
                xGraphInspector.SetInferenceResults(null, 2, null);
                if (Model.BayesianNetwork.VariablesOrdered.All(rv => rv.Distributions.EnumerateDistributions().Any()))
                {
                    Scenario scenario           = new Scenario("1", new FObservation(), learningTask.BayesianNetwork);
                    scenario.InferenceUpdated  += OnScenarioInferenceUpdated;
                    scenario.InferenceFinished += OnScenarioInferenceFinished;
                    Model.Scenarios.Add(scenario);
                }

                WriteMessage("learning completed");
            });
        }
예제 #2
0
 void OnLearningStarted(ILearningTask learningTask)
 {
     Dispatcher.Invoke(delegate
     {
         SetBayesianNetwork(learningTask.BayesianNetwork, "");
         WriteMessage("learning...");
     });
 }
예제 #3
0
        private void LearningTaskFinishedFunction(object sender, SchoolEventArgs e)
        {
            ILearningTask lt = e.Task;

            if (lt != null)
            {
                lt.Fini();
            }
        }
예제 #4
0
        private void UpdateTaskData(ILearningTask runningTask)
        {
            if (CurrentTask == null || runningTask == null)
            {
                return;
            }
            CurrentTask.Steps    = (int)m_mainForm.SimulationHandler.SimulationStep - m_stepOffset;
            CurrentTask.Progress = (int)runningTask.Progress;
            TimeSpan diff = m_currentLtStopwatch.Elapsed;

            CurrentTask.Time   = (float)Math.Round(diff.TotalSeconds, 2);
            CurrentTask.Status = m_school.TaskResult;

            UpdateGridData();
        }
예제 #5
0
        private void SimulationHandler_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (!Visible)
            {
                return;
            }

            Invoke((MethodInvoker)(() =>
            {
                ILearningTask runningTask = m_school.CurrentLearningTask;
                if (runningTask != null && CurrentTask != null)
                {
                    UpdateTaskData(runningTask);
                }
            }));
        }
예제 #6
0
        public static ILearningTask CreateLearningTask(Type taskType, Type worldType)
        {
            // check if task type is valid
            if (!KnownLearningTasks.ContainsKey(taskType))
            {
                return(null);
            }

            // check if the world is valid for this task
            if (!KnownLearningTasks[taskType].Contains(worldType))
            {
                return(null);
            }

            // everything is OK - create the task
            SchoolWorld   world = (SchoolWorld)Activator.CreateInstance(worldType);
            ILearningTask task  = (ILearningTask)Activator.CreateInstance(taskType, world);

            return(task);
        }
예제 #7
0
 public LTDesign(ILearningTask task)
 {
     TaskType = task.GetType().AssemblyQualifiedName;
     WorldType = task.RequiredWorldType.AssemblyQualifiedName;
 }
예제 #8
0
        private void UpdateTaskData(ILearningTask runningTask)
        {
            if (CurrentTask == null || runningTask == null)
                return;
            CurrentTask.Steps = (int)m_mainForm.SimulationHandler.SimulationStep - m_stepOffset;
            CurrentTask.Progress = (int)runningTask.Progress;
            TimeSpan diff = m_currentLtStopwatch.Elapsed;
            CurrentTask.Time = (float)Math.Round(diff.TotalSeconds, 2);
            CurrentTask.Status = m_school.TaskResult;

            UpdateGridData();
        }
예제 #9
0
 public SchoolEventArgs(ILearningTask task)
 {
     Task = task;
 }
예제 #10
0
 void OnLearningStarted(ILearningTask learningTask)
 {
     Dispatcher.Invoke(delegate
     {
         SetBayesianNetwork(learningTask.BayesianNetwork, "");
         WriteMessage("learning...");
     });
 }
예제 #11
0
        void OnLearningFinished(ILearningTask learningTask)
        {
            Dispatcher.Invoke(delegate
            {
                if (Model.BayesianNetwork != learningTask.BayesianNetwork)
                {
                    return;
                }

                // If this learning finished for the network we're currently
                // looking at.

                xLearningInspector.SetIsLearning(false);
                SetBayesianNetwork(learningTask.BayesianNetwork, "");

                xGraphInspector.SetInferenceResults(null, 1, null);
                xGraphInspector.SetInferenceResults(null, 2, null);
                if (Model.BayesianNetwork.VariablesOrdered.All(rv => rv.Distributions.EnumerateDistributions().Any()))
                {
                    Scenario scenario = new Scenario("1", new FObservation(), learningTask.BayesianNetwork);
                    scenario.InferenceUpdated += OnScenarioInferenceUpdated;
                    scenario.InferenceFinished += OnScenarioInferenceFinished;
                    Model.Scenarios.Add(scenario);
                }

                WriteMessage("learning completed");
            });
        }
예제 #12
0
 public LTDesign(ILearningTask task)
 {
     TaskType  = task.GetType().AssemblyQualifiedName;
     WorldType = task.RequiredWorldType.AssemblyQualifiedName;
 }
예제 #13
0
        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            Invoke((MethodInvoker)(() =>
            {
                LearningTaskNode ltNode = SelectedLearningTask;

                // if no selection, clear table and return
                if (ltNode == null)
                {
                    tabControlLevels.TabPages.Clear();
                    prevGridViewSelection = null;
                    return;
                }
                // if there is no change, do nothing
                if (ltNode.Equals(prevGridViewSelection))
                {
                    return;
                }
                prevGridViewSelection = ltNode;

                //
                // LT text hint
                //

                richTextBoxLTInfo.Clear();

                const string HTML_DIRECTORY = @"Resources\html";
                string htmlFileName = (ltNode as LearningTaskNode).TaskType.Name + ".html";
                string fullPath = MyResources.GetMyAssemblyPath() + "\\" + HTML_DIRECTORY + "\\" + htmlFileName;


                if (File.Exists(fullPath))
                {
                    // Create a file to write to.
                    string htmlPage = File.ReadAllText(fullPath);

                    string name = System.Text.RegularExpressions.Regex.Match(htmlPage, "<title>.*</title>").ToString();
                    if (name.Length > 0)
                    {
                        name = name.Split('>', '<')[2];
                    }
                    richTextBoxLTInfo.AppendText(name + "\r\n\r\n");
                    richTextBoxLTInfo.SelectAll();
                    richTextBoxLTInfo.SelectionFont = new Font(richTextBoxLTInfo.Font, FontStyle.Bold);

                    string description = System.Text.RegularExpressions.Regex.Match(htmlPage,
                                                                                    "Description(.*?)<td(.*?)</td>", System.Text.RegularExpressions.RegexOptions.Singleline).ToString();
                    if (description.Length > 0)
                    {
                        description = description.Split('>', '<')[4];
                    }
                    description = description.Replace(System.Environment.NewLine, "");
                    richTextBoxLTInfo.AppendText(description);
                }

                //
                // LVL tab
                //
                tabControlLevels.TabPages.Clear();

                Type ltType = ltNode.TaskType;
                ILearningTask lt = LearningTaskFactory.CreateLearningTask(ltType);
                TrainingSetHints hints = lt.TSProgression[0];

                Levels = new List <LevelNode>();
                LevelGrids = new List <DataGridView>();
                Attributes = new List <List <AttributeNode> >();
                AttributesChange = new List <List <int> >();

                for (int i = 0; i < lt.TSProgression.Count; i++)
                {
                    // create tab
                    LevelNode ln = new LevelNode(i + 1);
                    Levels.Add(ln);
                    TabPage tp = new TabPage(ln.Text);
                    tabControlLevels.TabPages.Add(tp);

                    // create grid
                    DataGridView dgv = new DataGridView();

                    dgv.Parent = tp;
                    dgv.Margin = new Padding(3);
                    dgv.Dock = DockStyle.Fill;
                    dgv.RowHeadersVisible = false;
                    dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                    dgv.AllowUserToResizeRows = false;
                    // create attributes
                    Attributes.Add(new List <AttributeNode>());
                    if (i > 0)
                    {
                        hints.Set(lt.TSProgression[i]);
                    }
                    foreach (var attribute in hints)
                    {
                        AttributeNode an = new AttributeNode(attribute.Key, attribute.Value);
                        Attributes[i].Add(an);
                        // create tooltips
                    }

                    Attributes[i].Sort(Comparer <AttributeNode> .Create((x, y) => x.Name.CompareTo(y.Name)));
                    dgv.DataSource = Attributes[i];

                    dgv.Columns[0].Width = 249;
                    dgv.Columns[0].ReadOnly = true;
                    dgv.Columns[1].ReadOnly = true;

                    AttributesChange.Add(new List <int>());
                    if (i > 0)
                    {
                        foreach (var attribute in lt.TSProgression[i])
                        {
                            int attributeIdx = Attributes[i].IndexOf(new AttributeNode(attribute.Key.Name));
                            AttributesChange[i].Add(attributeIdx);
                        }
                    }

                    LevelGrids.Add(dgv);
                    dgv.ColumnWidthChanged += levelGridColumnSizeChanged;
                    dgv.CellFormatting += levelGrid_CellFormatting;
                    dgv.SelectionChanged += levelGrid_SelectionChanged;
                    dgv.ClearSelection();

                    tabControlLevels.Update();
                }
            }
                                   ));
        }