public override void UpdateWeights(ILearnable learnableLayer, int iteration = 1) { // update all weights by stochastic gradient descent double[][][][] weights = learnableLayer.Weights; double[][][][] dWeights = learnableLayer.Dweights; int lx0 = weights.Length; int lx1 = weights[0].Length; int lx2 = weights[0][0].Length; int lx3 = weights[0][0][0].Length; for (int i = 0; i < lx0; i++) { for (int j = 0; j < lx1; j++) { for (int k = 0; k < lx2; k++) { for (int l = 0; l < lx3; l++) { weights[i][j][k][l] -= learningRate * dWeights[i][j][k][l]; } } } } // update biases double[] biases = learnableLayer.Biases; double[] dBiases = learnableLayer.Dbiases; for (int i = 0; i < biases.Length; i++) { biases[i] -= learningRate * dBiases[i]; } }
public override void Consume(ILearnable item) { if (!IsFull) { calorieIntake += item.Calories; if (item.IsSweet) { calorieIntake += 10; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"{Name} screams: yes please more of that (+ 10 points to my brain power) \n"); Console.ResetColor(); } ConsumptionHistory.Add(item); Console.BackgroundColor = ConsoleColor.DarkBlue; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine("(‡▼益▼) JACK is learning: "); Console.WriteLine(item.GetInfo()); Console.ResetColor(); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{Name} says: My brain hurts cant study anymore \n"); Console.ResetColor(); } }
public override void Consume(ILearnable item) { if (!IsFull) { calorieIntake += item.Calories; if (item.IsSpicy) { calorieIntake -= 5; Console.ForegroundColor = ConsoleColor.DarkBlue; Console.WriteLine($"{Name} that book is too hard !!! (-5 points to brain power)\n"); Console.ResetColor(); } ConsumptionHistory.Add(item); Console.BackgroundColor = ConsoleColor.DarkYellow; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine("ᕙ(▀̿̿Ĺ̯̿̿▀̿ ̿) ᕗ SAM is learning: "); Console.WriteLine(item.GetInfo()); Console.ResetColor(); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{Name} says: My brain hurts cant study anymore \n"); Console.ResetColor(); } }
public void AddAbility(ILearnable ability) { this.ability = ability; icon.sprite = this.ability.Icon; icon.color = Color.white; spellName.text = ability.DisplayName; description.text = ability.GetShortDescription() + "\nLearned at level " + Mathf.Clamp(ability.RequiredLevel, 1, 1000); }
public void AddExperienceFeedback(ILearnable learnable) { if (learnable != null) { experienceInfo.parent.SetActive(true); learnable.AddExperienceFeedback(experienceInfo.healthBar, experienceInfo.healthText); } }
/// <summary> /// /// </summary> /// <param name="learnable"></param> /// <returns></returns> public bool Learn(ILearnable learnable) { if (!learnable.CanLearn(this)) { return(false); } return(learnable.Learn(this)); }
private ITrainer getTrainer(LearningSubject subject, ILearnable learnable, Type type, bool useCache) { if (trainers.ContainsKey(new Tuple <LearningSubject, Type>(subject, type))) { return ((ITrainer) Activator.CreateInstance(trainers[new Tuple <LearningSubject, Type>(subject, type)], learnable, useCache)); } return(null); }
public ILearnable Serve() { Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine(" ***NEW ROUND ***"); Console.ResetColor(); Random rand = new Random(); ILearnable item = Menu[rand.Next(Menu.Count)]; return(item); }
private void HandleLearnFinished(object s, EventArgs e) { ((ILearnable)s).LearningFinished -= new EventHandler(this.HandleLearnFinished); this.learning = false; this.currentlearn = null; if (base.InvokeRequired) { base.Invoke(new Action(this.updateUIPostLearn)); } else { this.updateUIPostLearn(); } this.rules.InputUsed = false; }
public ITrainer GetTrainer(LearningSubject subject, ILearnable learnable) { var all = learnable.GetType().GetInterfaces(); var learnableInterfaces = all.Except(all.SelectMany(x => x.GetInterfaces())) .Where(x => x.GetInterfaces().Contains(typeof(ILearnable))); var res = new List <ITrainer>(); foreach (Type type in learnableInterfaces) { res.Add(getTrainer(subject, learnable, type, false)); } return(res.First()); }
public override void UpdateWeights(ILearnable learnableLayer, int iteration = 1) { // update all weights by stochastic gradient descent double[][][][] weights = learnableLayer.Weights; double[][][][] dWeights = learnableLayer.Dweights; int lx0 = weights.Length; int lx1 = weights[0].Length; int lx2 = weights[0][0].Length; int lx3 = weights[0][0][0].Length; int index = ((AbstractLayer)learnableLayer).Index; // if it is first iteration we will init fields if (!m.ContainsKey(index)) { m.Add(index, Utils.Init4dArr(lx0, lx1, lx2, lx3)); } if (!r.ContainsKey(index)) { r.Add(index, Utils.Init4dArr(lx0, lx1, lx2, lx3)); } m[index] = MatOp.Add(MatOp.MultiplyByConst(dWeights, 1d - beta1), MatOp.MultiplyByConst(m[index], beta1)); r[index] = MatOp.Add(MatOp.MultiplyByConst(MatOp.Cwise(dWeights, dWeights), 1d - beta2), MatOp.MultiplyByConst(r[index], beta2)); double[][][][] mExt = MatOp.DivideByConst(m[index], 1d - Math.Pow(beta1, iteration)); double[][][][] rExt = MatOp.DivideByConst(r[index], 1d - Math.Pow(beta2, iteration)); var a = MatOp.MultiplyByConst(mExt, learningRate); var b = MatOp.AddConst(MatOp.Sqrt(rExt), epsilon); var c = MatOp.Mwise(a, b); learnableLayer.Weights = MatOp.Substract(weights, c); // update biases double[] biases = learnableLayer.Biases; double[] dBiases = learnableLayer.Dbiases; for (int i = 0; i < biases.Length; i++) { biases[i] -= learningRate * dBiases[i]; } }
private void btChoose_Click(object sender, RoutedEventArgs e) { TravellerChar character = SheetWindow.Character; if (tvSkillList.SelectedItem == null) { return; } ILearnable item = (ILearnable)tvSkillList.SelectedItem; if (!item.Learnable) { return; } if (item.GetType() == typeof(Skill)) { Skill skillitem = (Skill)item; var skill = new LearnedSkill() { SkillData = skillitem, Level = 0, Skillname = skillitem.Name }; character.LearnedSkills.Add(skill); } if (item.GetType() == typeof(SkillSpecialty)) { SkillSpecialty skillspecitem = (SkillSpecialty)item; LearnedSkill parentskill = character.LearnedSkills.First(x => x.SkillData.Name == skillspecitem.Skill.Name); var skillspec = new LearnedSkillSpecialty() { SkillData = parentskill, Level = 0, Name = skillspecitem.Name, SkillName = parentskill.Skillname, SpecialtyData = skillspecitem }; parentskill.LearnedSkillSpecialties.Add(skillspec); } Close(); }
private void BeginLearn() { if (this.ruleSetGrid.SelectedRows.Count > 0) { if (this.rules.InputDevice != null && !this.learning) { this.learning = true; this.beginLearnToolStrip.Enabled = false; this.cancelLearnToolStripMenuItem.Enabled = true; DataGridViewRow selected = this.ruleSetGrid.SelectedRows[0]; DeviceRule obj = this.rules.Rules[selected.Index]; obj.LearningFinished += new EventHandler(this.HandleLearnFinished); obj.BeginLearn(); this.currentlearn = obj; this.ruleSetGrid.Refresh(); this.ruleInfo.Refresh(); this.rules.InputUsed = true; this.rules.InputDevice.LearnMessage += new EventHandler <MidiEventArgs>(this.HandleLearnMessage); this.rules.InputDevice.EnterLearnMode(); } } }
public override Tuple <double, double> Evaluate(double[][][][] testImages, double[][] testLabels, bool print = true) { double[][][][] output = ComputeOutput(testImages); double loss = lossFunction.Compute(output, testLabels); for (int i = 0; i < layers.Count; i++) { if (layers[i] is ILearnable && ((ILearnable)layers[i]).Regularizer != null) { ILearnable learnableLayer = (ILearnable)layers[i]; int numSamples = learnableLayer.Weights.Length; loss += learnableLayer.Regularizer.ComputeAdditionToCostFunc(learnableLayer.Weights, numSamples); } } double acc = lossFunction.ComputeAccuracy(output, testLabels); if (print) { Logger.Log.Info("Test accuracy is " + acc.ToString("0.####")); } return(Tuple.Create <double, double>(acc, loss)); }
public abstract void Consume(ILearnable item);
private void CancelLearn() { this.currentlearn.CancelLearn(); this.currentlearn = null; }
/// <summary> /// Method for updating weights and biases during /// backpropagation. /// </summary> /// <param name="learnableLayer">Layer with weights and biases which /// will be updated.</param> /// <param name="iteration">Number of iteration of learning call.</param> public abstract void UpdateWeights(ILearnable learnableLayer, int iteration = 1);