/// <summary> /// Saves the learner model as a json file to the filepath for he file. /// </summary> public void SaveLearnerModel() { LearnerModelData lm = new LearnerModelData(); lm.additionSimilar = this.GetRateofObservedNode(LearnerModel.Node.Similar, LearnerModel.Operation.ADDITION); lm.subtractionSimilar = this.GetRateofObservedNode(LearnerModel.Node.Similar, LearnerModel.Operation.SUBTRACTION); lm.similar = this.Infer(LearnerModel.Node.Similar); lm.additionEquivalent = this.GetRateofObservedNode(LearnerModel.Node.Equivalent, LearnerModel.Operation.ADDITION); lm.subtractionEquivalent = this.GetRateofObservedNode(LearnerModel.Node.Equivalent, LearnerModel.Operation.SUBTRACTION); lm.equivalent = this.Infer(LearnerModel.Node.Equivalent); lm.additionDissimilar = this.GetRateofObservedNode(LearnerModel.Node.Dissimilar, LearnerModel.Operation.ADDITION); lm.subtractionEquivalent = this.GetRateofObservedNode(LearnerModel.Node.Dissimilar, LearnerModel.Operation.SUBTRACTION); lm.dissimilar = this.Infer(LearnerModel.Node.Dissimilar); foreach (DenominatorMastery mastery in this.denominatorMastery) { DenominatorMasteryData data = new DenominatorMasteryData(); data.denominator = mastery.GetDenominator(); data.topic = SceneTopic.SIMILAR_ADD; data.mastery = mastery.Mastery(data.topic); lm.denominatorMasteries.Add(data); data = new DenominatorMasteryData(); data.denominator = mastery.GetDenominator(); data.topic = SceneTopic.SIMILAR_SUB; data.mastery = mastery.Mastery(data.topic); lm.denominatorMasteries.Add(data); data = new DenominatorMasteryData(); data.denominator = mastery.GetDenominator(); data.topic = SceneTopic.EQUIVALENT_ADD; data.mastery = mastery.Mastery(data.topic); lm.denominatorMasteries.Add(data); data = new DenominatorMasteryData(); data.denominator = mastery.GetDenominator(); data.topic = SceneTopic.EQUIVALENT_SUB; data.mastery = mastery.Mastery(data.topic); lm.denominatorMasteries.Add(data); data = new DenominatorMasteryData(); data.denominator = mastery.GetDenominator(); data.topic = SceneTopic.DISSIMILAR_ADD; data.mastery = mastery.Mastery(data.topic); lm.denominatorMasteries.Add(data); data = new DenominatorMasteryData(); data.denominator = mastery.GetDenominator(); data.topic = SceneTopic.DISSIMILAR_SUB; data.mastery = mastery.Mastery(data.topic); lm.denominatorMasteries.Add(data); } string newData = JsonUtility.ToJson(lm); File.WriteAllText(learnerModelDataPath, newData); }
/// <summary> /// Attempts to load an existing learner model if available. /// </summary> public void LoadLearnerModel() { if (File.Exists(this.learnerModelDataPath)) { LearnerModelData data = JsonUtility.FromJson <LearnerModelData> (File.ReadAllText(this.learnerModelDataPath)); this.bayesNet.fbSimilarAddition = data.additionSimilar; this.bayesNet.fbSimilarSubtraction = data.subtractionSimilar; this.bayesNet.UpdateSimilarProbability(); this.bayesNet.fbEquivalentAddition = data.additionEquivalent; this.bayesNet.fbEquivalentSubtraction = data.subtractionEquivalent; this.bayesNet.UpdateEquivalentProbability(); this.bayesNet.fbDissimilarAddition = data.additionDissimilar; this.bayesNet.fbDissimilarSubtraction = data.subtractionDissimilar; this.bayesNet.UpdateDissimilarProbability(); this.bayesNet.UpdateLearnerModel(); for (int i = 0; i < this.unlockableDenominators.Count; i++) { DenominatorMastery mastery = new DenominatorMastery(unlockableDenominators [i]); List <DenominatorMasteryData> masteries = data.denominatorMasteries.FindAll(x => x.denominator == this.unlockableDenominators [i]); foreach (DenominatorMasteryData masteryData in masteries) { mastery.AddMastery(masteryData.topic, masteryData.mastery); } denominatorMastery.Add(mastery); } } else { for (int i = 0; i < this.unlockableDenominators.Count; i++) { DenominatorMastery mastery = new DenominatorMastery(unlockableDenominators [i]); mastery.AddMastery(SceneTopic.SIMILAR_ADD); mastery.AddMastery(SceneTopic.SIMILAR_SUB); mastery.AddMastery(SceneTopic.EQUIVALENT_ADD); mastery.AddMastery(SceneTopic.EQUIVALENT_SUB); mastery.AddMastery(SceneTopic.DISSIMILAR_ADD); mastery.AddMastery(SceneTopic.DISSIMILAR_SUB); denominatorMastery.Add(mastery); } } }