public async Task <IActionResult> Add(string name, double trainingRate, string description) { try { if (string.IsNullOrEmpty(name) || trainingRate < 0.01) { return(BadRequest()); } var model = new NeuralNetDto { Name = name, Description = description, TrainingRate = trainingRate }; var dbModel = _neuralNetCreator.CreateNeuralNet(model); await _dbcontext.NeuralNets.AddAsync(dbModel); await _dbcontext.SaveChangesAsync(); return(Ok(dbModel)); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <IActionResult> Update(NeuralNetDto model) { try { if (ModelState.IsValid) { var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; var dbModel = await _dbcontext.NeuralNets.Where(n => n.Id == model.Id && n.UserId == userId).FirstOrDefaultAsync(); if (dbModel == null) { return(NotFound()); } dbModel.Name = model.Name; dbModel.Description = model.Description; dbModel.Training = model.Training; await _dbcontext.SaveChangesAsync(); return(Ok()); } return(BadRequest(ModelState)); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <int> Create(NeuralNetDto neuralNetDto) { var neuralNet = ConvertNeuralNetDtoToEntity(neuralNetDto); await _repository.AddNeuralNet(neuralNet); return(neuralNet.Id); }
public virtual NeuralNet CreateNeuralNet(NeuralNetDto neuralNetDto) { var neuralNet = new NeuralNet { Name = neuralNetDto.Name, Description = neuralNetDto.Description, TrainingRate = neuralNetDto.TrainingRate, Training = false, TrainingIterations = 0, UserId = _httpContext.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value }; neuralNet.Layers = CreateLayerIteration(neuralNet); return(neuralNet); }
private NeuralNet ConvertNeuralNetDtoToEntity(NeuralNetDto neuralNetDto) { var neuralNet = _mapper.Map <NeuralNet>(neuralNetDto); neuralNet.Neurons = _mapper.Map <List <Neuron> >(neuralNetDto.Neurons); neuralNet.Synapses = _mapper.Map <List <Synapse> >(neuralNetDto.Synapses); foreach (var neuron in neuralNet.Neurons) { neuron.NeuralNet = neuralNet; neuron.InputSynapses = neuralNet.Synapses.Where(s => s.NeuronIdOutput == neuron.Id).ToList(); foreach (var synapse in neuron.InputSynapses) { synapse.OutputNeuron = neuron; } neuron.OutputSynapses = neuralNet.Synapses.Where(s => s.NeuronIdInput == neuron.Id).ToList(); foreach (var synapse in neuron.OutputSynapses) { synapse.InputNeuron = neuron; } } return(neuralNet); }
public async Task <int> Post([FromBody] NeuralNetDto neuralNetDto) { return(await _neuralNetworkApplicationService.Create(neuralNetDto)); }