コード例 #1
0
ファイル: Program.cs プロジェクト: ralfw/instavote.open
        public Program()
        {
            var regDlg = new RegistrationDialog(this);
            var fbDlg = new FeedbackDialog(this);
            var tüDlg = new TrainingsübersichtDialog(this);
            var trDlg = new TrainingDialog(this);
            var rDlg = new RootDialog(this);

            regDlg.OnShowRequest += regDlg.Show;
            regDlg.OnRegistrationRequest += (tid, name, email) => {
                if (name == "x")
                    regDlg.Retry("someMatchcode", name, email, string.Format("Received: {0}, {1}, {2}", tid, name, email));
                else
                    regDlg.Ack("someMatchcode", name, email);
            };

            fbDlg.OnShowRequest += fbDlg.Show;
            fbDlg.OnFeedbackRequest += (tmatchcode, email, score, suggestions) =>
            {
                if (email == "x")
                    fbDlg.Retry(tmatchcode, email, score, suggestions, string.Format("Received: {0}, {1}, {2}, {3}", tmatchcode, email, score, suggestions));
                else
                    fbDlg.Ack(tmatchcode);
            };

            tüDlg.OnShowRequest += trainerMatchcode => tüDlg.Show(trainerMatchcode,
                new[] { new Tuple<string, string>("1", "training1"), new Tuple<string, string>("2", "training2") }, 
                "");
            tüDlg.OnTrainingCreationRequest += (trainerMatchcode, newTrainingMatchcode) => tüDlg.Show(trainerMatchcode, new[] { new Tuple<string, string>("1", "training1"), new Tuple<string, string>("2", "training2"), new Tuple<string, string>("3", newTrainingMatchcode), },
                                                                                                                    newTrainingMatchcode == "x" ? "Training matchcode already existent." : "");

            trDlg.OnShowRequest += trainingId =>
                {
                    var ti = new TrainingInfo {
                        Matchcode = "someTraining",
                        Votes = new[]
                            {
                                new VoteInfo {Name = "n1", Email = "e1@", Score = 6, Suggestions = "s1"},
                                new VoteInfo {Name = "n2", Email = "e2@", Score = 7, Suggestions = "s2"},
                            },
                        AverageScore = 6.5
                    };
                    trDlg.Show(ti);
                };

            Get["/hello"] = _ => "Hello from instavote.dialogs.tests, " + DateTime.Now;
        }
コード例 #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (network == null)
            {
                return;
            }

            var trainingFileContent = OpenFileWithDialog("Open news training data", "*.csv|*.csv");

            if (trainingFileContent == null)
            {
                return;
            }

            var trainingData = new List <TrainingSuite.TrainingData>();

            FillTrainingDataFromFile(ref trainingData, trainingFileContent, network.GetInputSize());

            var trainingSuite = new TrainingSuite(trainingData);

            trainingSuite.config.learningRate         = float.Parse(txtLearningRate.Text);
            trainingSuite.config.epochs               = int.Parse(txtEpochs.Text);
            trainingSuite.config.miniBatchSize        = int.Parse(txtMiniBatches.Text);
            trainingSuite.config.regularizationLambda = float.Parse(txtRegularizationLambda.Text);
            trainingSuite.config.shuffleTrainingData  = chkShuffleMinibatches.IsChecked == true;

            switch (cmbCostFunction.SelectedIndex)
            {
            case 1:
                trainingSuite.config.costFunction = new MeanSquaredErrorFunction();
                break;

            case 0:
            default:
                trainingSuite.config.costFunction = new CrossEntropyErrorFunction();
                break;
            }

            switch (cmbRegularization.SelectedIndex)
            {
            case 0:
                trainingSuite.config.regularization = TrainingSuite.TrainingConfig.Regularization.None;
                break;

            case 1:
                trainingSuite.config.regularization = TrainingSuite.TrainingConfig.Regularization.L1;
                break;

            case 2:
            default:
                trainingSuite.config.regularization = TrainingSuite.TrainingConfig.Regularization.L2;
                break;
            }

            var calculator = GetCalculator(cmbComputeDevice.SelectedIndex);

            var trainingProcess = network.Train(trainingSuite, calculator);

            var dialogWnd = new TrainingDialog(trainingProcess);

            dialogWnd.ShowDialog();
        }