public Guid Evaluate([FromBody] StocksEvaluationJobRequest request) { var net = Net.FromDescription(request.Net); var data = _events.TrainingEvents .Select(evt => Tuple.Create(evt.GetInputArray(), evt.GetOutputArray())); return(_evalJobRepository.CreateProcess((action, token) => { var eval = net.GetEvaluationFunction(); var results = new List <Tuple <float, float> >(); var avgError = 0d; var testCount = 0; foreach (var test in data) { testCount += 1; var result = eval(test.Item1); avgError += Math.Abs(result[0] - test.Item2[0]); results.Add(Tuple.Create(test.Item2[0], result[0])); if (token.IsCancellationRequested) { break; } } action(new EvaluationJob() { AvgError = (float)(avgError / testCount), ExpectedActuals = results, Net = net.Description }); })); }
public Guid Post(StocksTrainingJobRequest request) { // build description request.HiddenLayerNodeCounts = request.HiddenLayerNodeCounts ?? new List <int>(); request.HiddenLayerNodeCounts.Add(1); var description = SimpleDescriptionBuilder.GetDescription(4, request.HiddenLayerNodeCounts.ToArray()); foreach (var id in description.Outputs) { var outNode = description.Nodes.Single(n => n.NodeId == id); outNode.Processor = null; } // get training events var tests = _events.TrainingEvents .Select(evt => Tuple.Create(evt.GetInputArray(), evt.GetOutputArray())); // get net var net = Net.FromDescription(description); // initialize weights WeightFiller.FillWeights(net, request.WeightVariance); // create a trainer var trainer = new Trainer(tests, net); // add to the repository and return the id return(_trainingJobRepository .CreateProcess((progress, token) => { trainer.Train( learnFactor: request.InitialLearningRate, inertia: request.InitialMomentum, desiredError: request.DesiredError, maxRuns: request.MaxIterations, progress: progress, cancel: token); })); }
public async Task <List <dynamic> > ReadFile(string filename, string subject) { string company = ""; List <string> entityIndex = new List <string>(); if (subject.ToUpper().Contains("SULAMERICA")) { company = "Sulamerica"; } else if (subject.ToUpper().Contains("UNIMED")) { company = "Unimed"; } List <ColumnControl> control = await _columnControlRepository.FindByCompany(company); string[] lines = File.ReadAllLines(Directory.GetCurrentDirectory() + filename); Process process = await _processRepository.CreateProcess(company); string field = ""; foreach (string line in lines) { foreach (ColumnControl item in control) { for (int i = item.Start; i <= item.End; i++) { if (field.Length != item.Size) { field += line[i]; } else { break; } } entityIndex.Add(field); field = ""; } if (subject.ToUpper().Contains("SULAMERICA")) { Sulamerica obj = new Sulamerica { Sequencia = entityIndex[0], Carteirinha = entityIndex[1], Nome = entityIndex[2], CPF = entityIndex[3], DataRegistro = entityIndex[4], Mais = entityIndex[5], Valor = InsertDot(entityIndex[6]), CodigoAleatorio = entityIndex[7], Nascimento = entityIndex[8], CNPJ = entityIndex[9], NomeColaborador = entityIndex[10], NE = entityIndex[11], Process = process }; list.Add(obj); await _sulamericaRepository.Create(obj); entityIndex.Clear(); } else if (subject.ToUpper().Contains("UNIMED")) { Unimed obj = new Unimed { TipoServico = entityIndex[0], DataConsumo = DateTime.ParseExact(entityIndex[1], "ddMMyyyy", CultureInfo.CreateSpecificCulture("pt-BR")), ne = entityIndex[2], CodigoDependenteSistema = entityIndex[3], Nome = entityIndex[4], Crm = entityIndex[5], ValorDespesa = decimal.Parse(entityIndex[6]), Amb = entityIndex[7], ControleUnimedLotacao = entityIndex[8], ControleUnimedAcomodacao = entityIndex[9], Pago = entityIndex[10], Process = process }; list.Add(obj); await _unimedRepository.Create(obj); entityIndex.Clear(); } } return(list); }