public void GenerateNetwork_ShouldReturnNoTNull() { var bots = Builder <Bot> .CreateListOfSize(10) .TheFirst(1) .With(x => x.Id = 1) .All() .With(x => x.Id > 0 && x.IsDeleted == false) .Build(); var networks = Builder <NeuralNetworkData> .CreateListOfSize(10) .All() .With(x => x.Id > 0) .Build(); this._unitOfWork = new Mock <IUnitOfWork>(); this._unitOfWork.Setup(x => x.NeuralNetworkDataRepository.All()) .Returns(networks.AsEnumerable()); this._unitOfWork.Setup(x => x.BotRepository.All()) .Returns(bots.AsEnumerable()); this._unitOfWork.Setup(x => x.SaveChanges()) .Returns(1); this._service = new NeuralNetworkService(this._unitOfWork.Object); var result = this._service.GenerateNetwork(1, 1, false); Assert.IsNotNull(result); }
public void RegisterNewNetwork_ShouldThrowCorrectException_IfNoDataFound() { var bots = Builder <Bot> .CreateListOfSize(10) .TheFirst(1) .With(x => x.Id = 1) .All() .With(x => x.Id > 0 && x.Id < 99 && x.IsDeleted == false) .Build(); var networks = Builder <NeuralNetworkData> .CreateListOfSize(10) .All() .With(x => x.Id > 0) .Build(); this._unitOfWork = new Mock <IUnitOfWork>(); this._unitOfWork.Setup(x => x.NeuralNetworkDataRepository.All()) .Returns(networks.AsEnumerable()); this._unitOfWork.Setup(x => x.BotRepository.All()) .Returns(bots.AsEnumerable()); this._unitOfWork.Setup(x => x.SaveChanges()) .Returns(1); this._service = new NeuralNetworkService(this._unitOfWork.Object); Assert.Throws <NotFoundException>(() => this._service.RegisterNewNetwork(new NeuralNetwork(1, 1, false), 100, "test", NeuralNetworkType.Test)); }
private void OnNetworkTrainingComplete(object sender, ProcessResult result) { trainingInProgress = false; if (result == ProcessResult.Success) { neuralNetworkService = (NeuralNetworkService)sender; UpdatePredictionGrid(inputsGrid); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { StartupFolder = new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.FullName; Capture = new VideoCapture(1); NeuralNetworks = NeuralNetworkService.GetNeuralNetworks(); cmbNeuralNetwork.ItemsSource = NeuralNetworks; cmbNeuralNetwork.DisplayMemberPath = "Name"; SetDefaultImage(); DeleteTemporalImages(); }
private void OnClickStart(object sender, EventArgs e) { if (!trainingInProgress) { double learningRate; double learningDataRatio; if (!Double.TryParse(textBoxLearningRate.Text, out learningRate)) { ShowError("Could not parse learning rate value."); return; } if (!Double.TryParse(textBoxLearningDataRatio.Text, out learningDataRatio)) { ShowError("Could not parse learning data ratio value."); return; } if (learningDataRatio >= 1d) { ShowError("Learning ratio must be less than 1."); return; } var intervals = outputIntervalsBindingSource.Cast <Limits>(); if (!ValidateLimits(intervals)) { return; } var neuralNetworkService = new NeuralNetworkService( columnSettings: columnsBindingSource.List.Cast <ColumnSetting>(), trainingLogger: trainingLogger, predictingLogger: predictionLogger, outputIntervals: intervals, learningRate: learningRate, learningDataRatio: learningDataRatio); neuralNetworkService.TrainingCompleted += OnNetworkTrainingComplete; neuralNetworkService.PredictionCompleted += OnPredictionComplete; var thread = new Thread(neuralNetworkService.Start); thread.Start(); trainingInProgress = true; } }
private void CmbNeuralNetwork_SelectionChanged(object sender, SelectionChangedEventArgs e) { cmbPredictedObject.Items.Clear(); var nn = cmbNeuralNetwork.SelectedValue; if (nn != null) { btnCreateFile.IsEnabled = true; TrainingConfig = TrainingService.GetTrainingConfig(((NeuralNetworkDto)nn).Id); ImageProcessingConfig = NeuralNetworkService.GetImageProcessingActiveConfig(((NeuralNetworkDto)nn).Id); cmbPredictedObject.ItemsSource = TrainingConfig.PredictedObjects; cmbPredictedObject.DisplayMemberPath = "ObjectName"; } else { btnCreateFile.IsEnabled = false; } }
public void Start() { using (var uw = new UnitOfWork()) { var nnService = new NeuralNetworkService(uw); double[][] input = new double[][] { new double[] { 1, 1, 1, 0, 0, 0, 0, 0, 0 }, new double[] { 0, 0, 0, 1, 1, 1, 0, 0, 0 }, new double[] { 1, 0, 0, 0, 0, 0, 1, 1, 0 }, new double[] { 0, 1, 1, 0, 0, 0, 0, 1, 1 }, }; double[][] output = new double[][] { new double[] { 1, 0 }, new double[] { 1, 0 }, new double[] { 0, 1 }, new double[] { 0, 1 } }; var network = nnService.GenerateNetwork(input[0].Length, output[0].Length, true); Console.ReadLine(); nnService.TrainNetwork(network, input, output, 0.001); //var network = nnService.LoadNeuralNetwork(1); nnService.TestNetwork(network, input, output); //using (var fileStream = File.Create("test1.txt")) //{ // network.Save(fileStream); //} //var id = nnService.RegisterNewNetwork(network, 1, "admin", NeuralNetworkType.Test); //Console.WriteLine(id); //var bot = uw.BotRepository.FindFirstByFilter(new BotFilter() { Id = 1 }); //Console.WriteLine(bot.NeuralNetworkDatas.Count); } }
public void RegisterNewNetwork_ShouldReturnCorrectDataType() { var bot = Builder <Bot> .CreateNew() .With(x => x.Id == 1 && x.IsDeleted == false) .Build(); this._unitOfWork = new Mock <IUnitOfWork>(); this._unitOfWork.Setup(x => x.BotRepository.FindById(It.IsAny <long>(), false)) .Returns(bot); this._unitOfWork.Setup(x => x.NeuralNetworkDataRepository.Add(It.IsAny <NeuralNetworkData>())); this._unitOfWork.Setup(x => x.SaveChanges()) .Returns(1); this._service = new NeuralNetworkService(this._unitOfWork.Object); var result = this._service.RegisterNewNetwork(new NeuralNetwork(1, 1, false), 1, "test", NeuralNetworkType.Test); Assert.IsNotNull(result); }
public void Setup() { neuralNetworkService = new NeuralNetworkService(); }