public TrainingRecord[] Parse(string imagesFile, string labelsFile) { var records = new List <TrainingRecord>(); using (var imagesFileReader = new BinaryReader(File.Open(imagesFile, FileMode.Open))) using (var labelsFileReader = new BinaryReader(File.Open(labelsFile, FileMode.Open))) { imagesFileReader.ReadInt32(); int images = ReadBigEndianInt32(imagesFileReader); int columns = ReadBigEndianInt32(imagesFileReader); int rows = ReadBigEndianInt32(imagesFileReader); int imageSize = columns * rows; labelsFileReader.ReadInt32(); int labels = ReadBigEndianInt32(labelsFileReader); Debug.Assert(images == labels); for (int i = 0; i < images; i++) { var record = new TrainingRecord { Input = ConvertToInput(imagesFileReader.ReadBytes(imageSize)), Output = ConvertToOutput(labelsFileReader.ReadByte()) }; records.Add(record); } return(records.ToArray()); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description,TimeStamp")] TrainingRecord trainingRecord) { if (id != trainingRecord.Id || !userService.IsCurrentUsersTraining(id, await _userManager.GetUserAsync(User))) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(trainingRecord); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TrainingRecordExists(trainingRecord.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(trainingRecord)); }
public ActionResult DeleteConfirmed(int id) { TrainingRecord trainingRecord = db.TrainingRecords.Find(id); db.TrainingRecords.Remove(trainingRecord); db.SaveChanges(); return(RedirectToAction("Index")); }
public void Train(TrainingRecord[] trainingData, double learningRate, int miniBatchSize) { var batches = Batch.Split(Batch.Shuffle(trainingData), miniBatchSize); foreach (var batch in batches) { Train(batch, learningRate); } }
public ActionResult Edit([Bind(Include = "id,nonPlayer_id,date,location,description,accidents")] TrainingRecord trainingRecord) { if (ModelState.IsValid) { db.Entry(trainingRecord).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(trainingRecord)); }
private Gradient BackPropagate(TrainingRecord record) { int layers = Weights.Length; //Feedforward double[][] a = new double[layers + 1][]; double[][] z = new double[layers + 1][]; a[0] = record.Input; for (int layer = 0; layer < layers; layer++) { z[layer + 1] = Math.Add( Math.Product(Weights[layer], a[layer]), Biases[layer + 1]); a[layer + 1] = Math.Sigmoid(z[layer + 1]); } //Backpropagate double[][] delta = Math.EmptyClone(Biases); delta[layers] = Math.HadamardProduct( Math.Subtract(a[layers], record.Output), Math.SigmoidPrime(z[layers])); for (int layer = layers - 1; layer > 0; layer--) { delta[layer] = Math.HadamardProduct( Math.Product(Math.Transpose(Weights[layer]), delta[layer + 1]), Math.SigmoidPrime(z[layer])); } //Gradient var gradient = new Gradient { Weights = Math.EmptyClone(Weights) }; for (int layer = 0; layer < layers; layer++) { for (int j = 0; j < Weights[layer].Length; j++) { for (int k = 0; k < Weights[layer][j].Length; k++) { gradient.Weights[layer][j][k] = a[layer][k] * delta[layer + 1][j]; } } } gradient.Biases = delta; return(gradient); }
// GET: TrainingRecords/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TrainingRecord trainingRecord = db.TrainingRecords.Find(id); if (trainingRecord == null) { return(HttpNotFound()); } return(View(trainingRecord)); }
private Gradient BackPropagate(TrainingRecord record) { int layers = Weights.Length; //Feedforward double[][] a = new double[layers + 1][]; double[][] z = new double[layers + 1][]; a[0] = record.Input; for (int layer = 0; layer < layers; layer++) { z[layer + 1] = Math.Add( Math.Product(Weights[layer], a[layer]), Biases[layer + 1]); a[layer + 1] = Math.Sigmoid(z[layer + 1]); } //Backpropagate double[][] delta = Math.EmptyClone(Biases); delta[layers] = Math.HadamardProduct( Math.Subtract(a[layers], record.Output), Math.SigmoidPrime(z[layers])); for (int layer = layers - 1; layer > 0; layer--) { delta[layer] = Math.HadamardProduct( Math.Product(Math.Transpose(Weights[layer]), delta[layer + 1]), Math.SigmoidPrime(z[layer])); } //Gradient var gradient = new Gradient {Weights = Math.EmptyClone(Weights)}; for (int layer = 0; layer < layers; layer++) { for (int j = 0; j < Weights[layer].Length; j++) { for (int k = 0; k < Weights[layer][j].Length; k++) { gradient.Weights[layer][j][k] = a[layer][k]*delta[layer + 1][j]; } } } gradient.Biases = delta; return gradient; }
// GET: TrainingRecords/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TrainingRecord trainingRecord = db.TrainingRecords.Find(id); if (trainingRecord == null) { return(HttpNotFound()); } ViewBag.nonPlayer_id = new SelectList(db.nonPlayers, "id", "FullName", trainingRecord.nonPlayer_id); return(View(trainingRecord)); }
public async Task <IActionResult> Create([Bind("Id,Title,Description,TimeStamp")] TrainingRecord trainingRecord) { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(User); trainingRecord.TimeStamp = DateTime.Now; trainingRecord.User = user; _context.TrainingRecords.Add(trainingRecord); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(trainingRecord)); }
public ActionResult Create(CoachesViewModel trainingRecord) { if (ModelState.IsValid) { TrainingRecord tr = new TrainingRecord(); tr.nonPlayer_id = trainingRecord.nonplayer_id; tr.description = trainingRecord.description; tr.date = trainingRecord.date; tr.location = trainingRecord.location; tr.accidents = trainingRecord.accidents; tr.nonPlayer = db.nonPlayers.Find(tr.nonPlayer_id); tr.FullName = tr.nonPlayer.FullName; db.TrainingRecords.Add(tr); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(trainingRecord)); }
// Use this for initialization void Start() { List <TrainingRecord> training = new List <TrainingRecord>(); TrainingRecord training1 = new TrainingRecord(TRAINING_TYPE.COIN_BANK); training1.AddScore(2); training1.AddScore(3); training1.AddScore(4); training1.AddScore(2); training1.AddScore(5); TrainingRecord training2 = new TrainingRecord(TRAINING_TYPE.DRESS_CHOICE); training2.AddScore(1); training2.AddScore(2); training2.AddScore(3); training2.AddScore(4); training2.AddScore(5); TrainingRecord training3 = new TrainingRecord(TRAINING_TYPE.PICTURE_PUZZLE); training3.AddScore(5); training3.AddScore(2); training3.AddScore(3); training3.AddScore(2); training3.AddScore(4); training.Add(training1); training.Add(training2); training.Add(training3); this.training = training; //you have to change in the ChangeChartScale's method. barchart.MakeChart(training, ExtractRecordListUnitFromTrainingRecord, ExtractIntFromRecordUnit, ExtractNameFromTrainingRecord ); }
private void Train(TrainingRecord[] batch, double learningRate) { var gradient = new Gradient { Weights = Math.EmptyClone(Weights), Biases = Math.EmptyClone(Biases) }; foreach (var trainingRecord in batch) { var batchGradient = BackPropagate(trainingRecord); gradient.Weights = Math.Add(gradient.Weights, batchGradient.Weights); gradient.Biases = Math.Add(gradient.Biases, batchGradient.Biases); } Weights = Math.Subtract( Weights, Math.Product(learningRate/batch.Length, gradient.Weights)); Biases = Math.Subtract( Biases, Math.Product(learningRate/batch.Length, gradient.Biases)); }
public TrainingRecord Post([FromBody] TrainingRecord view) { //TODO - Move validation errors to API way of doing things log.DebugFormat("POST {0} {1} {2}", Request.RequestUri, User.Identity.Name, JsonConvert.SerializeObject(view)); if (!User.IsInRole("cdb.trainingeditors")) { ThrowAuthError(); } // if (!Permissions.IsAdmin && !Permissions.IsSelf(view.MemberId) && !Permissions.IsMembershipForPerson(view.MemberId)) return GetAjaxLoginError<MemberContactView>(null); //List<SubmitError> errors = new List<SubmitError>(); //if (view.Member.Id == Guid.Empty) //{ // ThrowSubmitErrors(new [] { new SubmitError { Error = Strings.API_Required, Property = "Member" } }); //} Data.TrainingAward model; model = (from a in db.TrainingAward.Include("Member").Include("Course") where a.Id == view.ReferenceId select a).FirstOrDefault(); if (model == null) { model = new Data.TrainingAward(); model.Member = db.Members.Where(f => f.Id == view.Member.Id).FirstOrDefault(); //if (model.Member == null) //{ // errors.Add(new SubmitError { Property = "Member", Error = Strings.API_NotFound }); // ThrowSubmitErrors(errors); //} db.TrainingAward.Add(model); } //try //{ model.UploadsPending = (view.PendingUploads > 0); DateTime completed; if (string.IsNullOrWhiteSpace(view.Completed)) { // errors.Add(new SubmitError { Property = "Completed", Error = Strings.API_Required }); } else if (!DateTime.TryParse(view.Completed, out completed)) { // errors.Add(new SubmitError { Error = Strings.API_InvalidDate, Property = "Completed" }); } else { model.Completed = completed; } if (model.metadata != view.Comments) { model.metadata = view.Comments; } if (model.Member.Id != view.Member.Id) { throw new InvalidOperationException("Don't know how to change member yet"); } if (view.Course.Id == null) { // errors.Add(new SubmitError { Error = Strings.API_Required, Id = new[] { view.ReferenceId }, Property = "Course" }); } else if (model.Course == null || model.Course.Id != view.Course.Id) { model.Course = (from c in db.TrainingCourses where c.Id == view.Course.Id select c).First(); } switch (view.ExpirySrc) { case "default": model.Expiry = model.Course.ValidMonths.HasValue ? model.Completed.AddMonths(model.Course.ValidMonths.Value) : (DateTime?)null; break; case "custom": if (!string.IsNullOrWhiteSpace(view.Expires)) { model.Expiry = DateTime.Parse(view.Expires); } else { // errors.Add(new SubmitError { Error = Strings.API_TrainingRecord_CustomExpiryRequired, Property = "Expiry", Id = new[] { view.ReferenceId } }); } break; case "never": model.Expiry = null; break; } // Documentation required. if (!model.UploadsPending && string.IsNullOrWhiteSpace(model.metadata)) { // errors.Add(new SubmitError { Error = Strings.API_TrainingRecord_DocumentationRequired, Property = BaseApiController.ModelRootNodeName }); } // Prevent duplicate records if (db.TrainingAward.Where(f => f.Id != model.Id && f.Completed == model.Completed && f.Course.Id == model.Course.Id && f.Member.Id == model.Member.Id).Count() > 0) { // ThrowSubmitErrors(new [] { new SubmitError { Error = Strings.API_TrainingRecord_Duplicate, Id = new[] { model.Id }, Property = BaseApiController.ModelRootNodeName }}); } //if (errors.Count == 0) //{ db.SaveChanges(); Data.TrainingRecordCalculator calculator = new Data.TrainingRecordCalculator(db); calculator.Calculate(model.Member.Id); db.SaveChanges(); //} view.ReferenceId = model.Id; view.Course.Title = model.Course.DisplayName; //} //catch (RuleViolationsException ex) //{ // foreach (RuleViolation v in ex.Errors) // { // errors.Add(new SubmitError { Error = v.ErrorMessage, Property = v.PropertyName, Id = new[] { v.EntityKey } }); // } // // throw new InvalidOperationException("TODO: report errors"); //} //if (errors.Count > 0) //{ // ThrowSubmitErrors(errors); //} return(view); }
public List <RecordUnit> ExtractRecordListUnitFromTrainingRecord(TrainingRecord tr) { return(tr.scores); }