Beispiel #1
0
        private void BtnSaveTrainings_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(tbTitle.Text) && string.IsNullOrEmpty(tbInstitution.Text) && string.IsNullOrEmpty(tbLocation.Text))
            {
                trainCollection.Remove(selectedTrainItem);
            }
            else
            {
                if (TrainingValidation())
                {
                    var item = selectedTrainItem;
                    item._TITLE             = tbTitle.Text;
                    item._INSTITUTION       = tbInstitution.Text;
                    item._TRAINING_LOCATION = tbLocation.Text;
                    item._TRAINING_DATE     = dpTrainingFinished.Text;
                }
            }
            hasSelectedTraining = false;
            ChangeTrainBtnIcon();
            ClearTrainingFields();
            cbTrainingCollection.SelectedIndex = -1;

            selectedTrainItem = null;

            MessageBox.Show("Training record successfully updated.");
        }
Beispiel #2
0
        private void SetTrainBackground(string empId)
        {
            TrainingManager     mTrainManager = new TrainingManager();
            List <TrainingItem> trainList     = new List <TrainingItem>();

            if (trainCollection.Count != 0)
            {
                trainCollection.Remove(selectedTrainItem);

                foreach (var item in trainCollection)
                {
                    trainList.Add(item);
                }
            }

            if (!string.IsNullOrEmpty(tbTitle.Text))
            {
                var trainItem = new TrainingItem();
                trainItem._EMP_ID            = empId;
                trainItem._TITLE             = tbTitle.Text;
                trainItem._INSTITUTION       = tbInstitution.Text;
                trainItem._TRAINING_LOCATION = tbLocation.Text;
                trainItem._TRAINING_DATE     = dpTrainingFinished.Text;

                trainList.Add(trainItem);
            }

            mTrainManager.DeleteTrainData(empId);

            foreach (var item in trainList)
            {
                mTrainManager.SaveTrainingData(item);
            }
        }
        public void Next()
        {
            DigitImage   img     = Program.RandomTestingData;
            TrainingItem ti      = MnistReader.ConvertSingleImage(img);
            Image        realImg = img.ToBitMap();

            input.Image = new Bitmap(realImg, input.Size);
            byte b = 0;

            for (int i = 0; i < 4; i++)
            {
                b += (byte)(ti.outputs[i] > 0.5 ? Math.Pow(2, i) : 0);
            }
            byte o = Program.GetOutput(ti.inputs);

            output.Text = (timerRunning ? "Test in progress : \n" : "") + "Found : " + o + "\nExpected : " + b;

            if (timerRunning)
            {
                loop++;
                if (o == b)
                {
                    worked++;
                }
                if (loop >= 100)
                {
                    timerRunning = false;
                    timer.Stop();
                    output.Text = "Test finished\nSuccess : " + worked + " %";
                }
            }
        }
Beispiel #4
0
        private void BtnAddTrainings_Click(object sender, RoutedEventArgs e)
        {
            if (TrainingValidation())
            {
                if (hasSelectedTraining)
                {
                    hasSelectedTraining = false;
                    ChangeTrainBtnIcon();
                    ClearTrainingFields();
                    cbTrainingCollection.SelectedIndex = -1;

                    selectedTrainItem = null;
                }
                else
                {
                    var trainItem = new TrainingItem();
                    trainItem._EMP_ID            = tbEmployeeId.Text;
                    trainItem._TITLE             = tbTitle.Text;
                    trainItem._INSTITUTION       = tbInstitution.Text;
                    trainItem._TRAINING_LOCATION = tbLocation.Text;
                    trainItem._TRAINING_DATE     = dpTrainingFinished.Text;
                    trainItem._TRAIN_HOLDER      = "Training " + (trainCollection.Count + 1);

                    trainCollection.Add(trainItem);

                    cbTrainingCollection.ItemsSource = trainCollection;

                    ClearTrainingFields();

                    MessageBox.Show("New work training record added.");
                }
            }
        }
        public void AddTrainingData(List <double> observations, string name, double treshhold)
        {
            var _newTrainingItem = new TrainingItem(name, treshhold)
            {
                Data = observations
            };

            _trainingstore.Items.Add(_newTrainingItem);
            TrainHiddenMarkovModel();
        }
        public ActionResult CommitBreakInterval(TrainingItemViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;

            //if (!ModelState.IsValid)
            //{
            //    ViewBag.ModelState = this.ModelState;
            //    return View(Settings.Default.ReportInputError);
            //}

            TrainingExecution execution = models.GetTable <TrainingExecution>().Where(t => t.ExecutionID == viewModel.ExecutionID).FirstOrDefault();

            if (execution == null)
            {
                return(Json(new { result = false, message = "預編課程項目不存在!!" }));
            }

            var stage = models.GetTable <TrainingStage>().Where(s => s.StageID == viewModel.StageID).FirstOrDefault();

            if (stage == null)
            {
                return(View("~/Views/Shared/JsAlert.cshtml", model: "資料錯誤!!"));
            }

            TrainingItem item = execution.TrainingItem.Where(i => i.ItemID == viewModel.ItemID).FirstOrDefault();

            if (item == null)
            {
                item = new TrainingItem
                {
                    ExecutionID = execution.ExecutionID,
                    Sequence    = execution.TrainingItem.Count,
                    TrainingID  = stage.TrainingStageItem
                                  .Select(t => t.TrainingType)
                                  .Where(t => t.BreakMark == true)
                                  .Select(t => t.TrainingID).FirstOrDefault()
                };
                execution.TrainingItem.Add(item);
            }

            item.BreakIntervalInSecond = viewModel.BreakInterval = viewModel.BreakInterval.GetEfficientString();
            item.Repeats = viewModel.Repeats = viewModel.Repeats.GetEfficientString();
            item.Remark  = viewModel.Remark;

            models.SubmitChanges();

            if (item.Repeats != null)
            {
                calculateTotalMinutes(execution, stage.StageID);
            }

            return(Json(new { result = true, message = "", stage.StageID }));
        }
Beispiel #7
0
        private void CbTrainingCollection_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cbTrainingCollection.SelectedIndex != -1)
            {
                var item = cbTrainingCollection.SelectedItem as TrainingItem;
                selectedTrainItem = item;

                ViewSelectedTrain();
                hasSelectedTraining = true;
                ChangeTrainBtnIcon();
            }
        }
        private bool Step(TrainingItem sample)
        {
            var x = sample.Volume;
            var y = sample.ClassIndex;

            if (sample.IsValidation)
            {
                // use x to build our estimate of validation error
                _net.Forward(x);
                int yhat   = _net.GetPrediction();
                var valAcc = yhat == y ? 1 : 0;
                _validationAccuracyBuffer.Add(valAcc);
                return(true);
            }

            // train on it with network
            _trainer.Train(x, y);

            // keep track of stats such as the average training error and loss
            int prediction = _net.GetPrediction();
            var trainAcc   = prediction == y ? 1 : 0;

            _lossBuffer.Add(_trainer.Loss);
            _trainAccuracyBuffer.Add(trainAcc);

            if (_stepCount % 200 == 0)
            {
                double loss             = _lossBuffer.Items.Average();
                double trainAvgAcc      = _trainAccuracyBuffer.Items.Average();
                double validationAvgAcc = _validationAccuracyBuffer.Items.Average();

                if (_infoOutputFunc != null)
                {
                    _infoOutputFunc(
                        string.Format("Ошибка: {0}\t\t Пройденных тестовых примеров: {1}\t\t Пройденных валидационных примеров: {2}",
                                      loss,
                                      Math.Round(trainAvgAcc * 100.0, 2),
                                      Math.Round(validationAvgAcc * 100.0, 2)));
                }

                if (_trainAccuracyBuffer.Items.All(i => i == 1) && _validationAccuracyBuffer.Items.All(i => i == 1))
                {
                    return(false);
                }
            }

            _stepCount++;

            return(true);
        }
Beispiel #9
0
        public static MeetingItemDto Build(TrainingItem arg)
        {
            if (arg == null)
            {
                throw new ArgumentNullException(nameof(arg));
            }

            return(new MeetingItemDto
            {
                Name = arg.Name,
                Url = arg.UrlPath,
                ScoId = arg.ScoId,
            });
        }
Beispiel #10
0
        public async void Train()
        {
            List<TrainingItem> data = new List<TrainingItem>();

            for (double x = 0; x <= 1; x += 0.01)
            {
                var entry = new TrainingItem();
                entry.input = new double[1] { x };
                entry.output = new double[1] { x * x };
                data.Add(entry);
            }

            var result = (await network.train(data));
            Console.WriteLine(result.ToString());
        }
    public static void GetEventTraning()
    {
        ApiDTO        apiDTO;
        CustomCsodDTO customCsodDTO;

        ApiObjects(out apiDTO, out customCsodDTO);

        //apiDTO.Resource = "/Services/api/LO/GetDetails?objectId=243bae9c-dfa8-433f-b8d2-6a79ffa41855&format=json";
        apiDTO.Resource = "/Services/api/LO/GetDetails?objectId=243bae9c-dfa8-433f-b8d2-6a79ffa41855&format=json";

        var loApi = new LoApi(apiDTO, customCsodDTO);

        //  LOResponse loResponse = loApi.CreateMaterial(loItem);
        TrainingItem      loResponse = loApi.Get();
        EventTrainingItem e          = (EventTrainingItem)loResponse;
    }
Beispiel #12
0
        public ActionResult EditTrainingItem(TrainingItemViewModel viewModel)
        {
            if (!models.GetTable <TrainingExecution>().Any(t => t.ExecutionID == viewModel.ExecutionID))
            {
                return(View("~/Views/ConsoleHome/Shared/AlertMessage.cshtml", model: "資料錯誤!!"));
            }

            var stage = models.GetTable <TrainingStage>().Where(s => s.StageID == viewModel.StageID).FirstOrDefault();

            if (stage == null)
            {
                return(View("~/Views/ConsoleHome/Shared/AlertMessage.cshtml", model: "資料錯誤!!"));
            }
            ViewBag.TrainingStage = stage;

            TrainingItem item = models.GetTable <TrainingItem>().Where(x => x.ItemID == viewModel.ItemID).FirstOrDefault();

            if (item != null)
            {
                viewModel.ItemID            = item.ItemID;
                viewModel.TrainingID        = item.TrainingID;
                viewModel.GoalTurns         = item.GoalTurns;
                viewModel.GoalStrength      = item.GoalStrength;
                viewModel.ExecutionID       = item.ExecutionID;
                viewModel.Description       = item.Description;
                viewModel.ActualStrength    = item.ActualStrength;
                viewModel.ActualTurns       = item.ActualTurns;
                viewModel.Remark            = item.Remark;
                viewModel.Repeats           = item.Repeats;
                viewModel.DurationInSeconds = item.DurationInMinutes * 60;
                viewModel.BreakInterval     = item.BreakIntervalInSecond;
                viewModel.PurposeID         = item.PurposeID;

                viewModel.AidID = item.TrainingItemAids.Select(s => s.AidID).ToArray();
            }

            ViewBag.ViewModel = viewModel;
            if (item == null)
            {
                return(View("~/Views/LearnerProfile/ProfileModal/CreateTrainingItem.cshtml", item));
            }
            else
            {
                return(View("~/Views/LearnerProfile/ProfileModal/EditTrainingItem.cshtml", item));
            }
        }
        private bool Step(TrainingItem sample)
        {
            var x = sample.Volume;
            var y = sample.ClassIndex;

            if (sample.IsValidation)
            {
                // use x to build our estimate of validation error
                _net.Forward(x);
                int yhat   = _net.GetPrediction();
                var valAcc = yhat == y ? 1 : 0;
                _validationAccuracyBuffer.Add(valAcc);
                return(true);
            }

            // train on it with network
            _trainer.Train(x, y);

            // keep track of stats such as the average training error and loss
            int prediction = _net.GetPrediction();
            var trainAcc   = prediction == y ? 1 : 0;

            _lossBuffer.Add(_trainer.Loss);
            _trainAccuracyBuffer.Add(trainAcc);

            if (_stepCount % 200 == 0)
            {
                double loss             = _lossBuffer.Items.Average();
                double trainAvgAcc      = _trainAccuracyBuffer.Items.Average();
                double validationAvgAcc = _validationAccuracyBuffer.Items.Average();

                Console.WriteLine("Loss: {0} Train accuray: {1} Test accuracy: {2}", loss,
                                  Math.Round(trainAvgAcc * 100.0, 2),
                                  Math.Round(validationAvgAcc * 100.0, 2));

                if (_trainAccuracyBuffer.Items.All(i => i == 1) && _validationAccuracyBuffer.Items.All(i => i == 1))
                {
                    return(false);
                }
            }

            _stepCount++;

            return(true);
        }
        public ActionResult CommitTrainingItem(TrainingItemViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;

            viewModel.Description = viewModel.Description.GetEfficientString();
            if (viewModel.Description == null)
            {
                ModelState.AddModelError("Description", "請輸入動作");
            }

            //viewModel.ActualStrength = viewModel.ActualStrength.GetEfficientString();
            //if(viewModel.ActualStrength == null)
            //{
            //    ModelState.AddModelError("ActualStrength", "請輸入強度");
            //}

            //viewModel.ActualTurns = viewModel.ActualTurns.GetEfficientString();
            //if (viewModel.ActualTurns == null)
            //{
            //    ModelState.AddModelError("ActualTurns", "請輸入次數");
            //}

            if (!viewModel.DurationInSeconds.HasValue)
            {
                ModelState.AddModelError("DurationInSeconds", "請輸入時間");
            }

            if (!viewModel.TrainingID.HasValue)
            {
                ModelState.AddModelError("TrainingID", "請選擇類別");
            }

            viewModel.Remark = viewModel.Remark.GetEfficientString();
            if (viewModel.PurposeID.HasValue && viewModel.Remark == null)
            {
                ModelState.AddModelError("Remark", "請輸入里程碑內容");
            }

            if (!ModelState.IsValid)
            {
                ViewBag.ModelState = this.ModelState;
                return(View(Settings.Default.ReportInputError));
            }

            TrainingExecution execution = models.GetTable <TrainingExecution>().Where(t => t.ExecutionID == viewModel.ExecutionID).FirstOrDefault();

            if (execution == null)
            {
                return(Json(new { result = false, message = "預編課程項目不存在!!" }));
            }

            TrainingItem item = execution.TrainingItem.Where(i => i.ItemID == viewModel.ItemID).FirstOrDefault();

            if (item == null)
            {
                item = new TrainingItem
                {
                    ExecutionID = execution.ExecutionID,
                    Sequence    = execution.TrainingItem.Count
                };
                execution.TrainingItem.Add(item);
            }

            item.GoalStrength      = viewModel.GoalStrength;
            item.GoalTurns         = viewModel.GoalTurns;
            item.Description       = viewModel.Description;
            item.TrainingID        = viewModel.TrainingID;
            item.Remark            = viewModel.Remark;
            item.DurationInMinutes = viewModel.DurationInMinutes;

            models.SubmitChanges();

            models.ExecuteCommand("delete TrainingItemAids where ItemID = {0}", item.ItemID);
            if (viewModel.AidID != null && viewModel.AidID.Length > 0)
            {
                foreach (var aid in viewModel.AidID)
                {
                    item.TrainingItemAids.Add(new TrainingItemAids {
                        AidID = aid
                    });
                }
                models.SubmitChanges();
            }

            calculateTotalMinutes(execution, viewModel.StageID.Value);
            bool UpdatePurpose = false;

            if (item.PurposeID.HasValue)
            {
                if (viewModel.PurposeID.HasValue)
                {
                    models.ExecuteCommand("Update PersonalExercisePurposeItem set PurposeItem = {0} where ItemID = {1}", viewModel.Remark, item.PurposeID);
                }
                else
                {
                    models.ExecuteCommand("delete PersonalExercisePurposeItem where ItemID = {0}", item.PurposeID);
                }
                UpdatePurpose = true;
            }
            else if (viewModel.PurposeID == -1 && item.Remark != null)
            {
                var purpose = item.TrainingExecution.TrainingPlan.LessonTime.RegisterLesson.UserProfile.AssertPurposeItem(models, item.Remark);
                purpose.CompleteDate = item.TrainingExecution.TrainingPlan.LessonTime.ClassTime;    //DateTime.Now;
                item.PurposeID       = purpose.ItemID;
                models.SubmitChanges();
                UpdatePurpose = true;
            }

            return(Json(new { result = true, message = "", viewModel.StageID, UpdatePurpose }));
        }
Beispiel #15
0
 /// <summary>
 /// Trains the network with one item
 /// </summary>
 /// <param name="item"></param>
 public void Train(TrainingItem item)
 {
     Train(item.input, item.expected);
 }