public void SimpleExampleTest() { RunMTAThread(() => { string dataFilename = GetDataPath(TestDatasets.msm.trainFilename); ///********* Training a model *******// // assume data is in memory in matrix/vector form. Sparse format also supported. Float[][] data; Float[] labels; // below just reads some actual data into these arrays PredictionUtil.ReadInstancesAsArrays(dataFilename, out data, out labels); // Create an Instances dataset. ListInstances instances = new ListInstances(); for (int i = 0; i < data.Length; i++) { instances.AddInst(data[i], labels[i]); } instances.CopyMetadata(null); // Create a predictor and specify some non-default settings var sub = new SubComponent <ITrainer <Instances, IPredictor <Instance, Float> >, SignatureOldBinaryClassifierTrainer>( "FastRank", "nl=5 lr =0.25 iter= 20"); var trainer = sub.CreateInstance(new TrainHost(new Random(1), 0)); // Train a predictor trainer.Train(instances); var predictor = trainer.CreatePredictor(); ///********* Several ways to save models. Only binary can be used to-reload in TLC. *******// // Save the model in internal binary format that can be used for loading it. string modelFilename = Path.GetTempFileName(); PredictorUtils.Save(modelFilename, predictor, instances, null); // Save the model as a plain-text description string modelFilenameText = Path.GetTempFileName(); PredictorUtils.SaveText(predictor, instances.Schema.FeatureNames, modelFilenameText); // Save the model in Bing's INI format string modelFilenameIni = Path.GetTempFileName(); PredictorUtils.SaveIni(predictor, instances.Schema.FeatureNames, modelFilenameIni); ///********* Loading and making predictions with a previously saved model *******// // Note: there are several alternative ways to construct instances // For example, see FactoryExampleTest below that demonstrates named-feature : value pairs. // Load saved model IDataModel dataModel; IDataStats dataStats; var pred = PredictorUtils.LoadPredictor <Float>(out dataModel, out dataStats, modelFilename); var dp = pred as IDistributionPredictor <Instance, Float, Float>; // Get predictions for instances Float[] probPredictions = new Float[instances.Count]; Float[] rawPredictions = new Float[instances.Count]; Float[] rawPredictions1 = new Float[instances.Count]; for (int i = 0; i < instances.Count; i++) { probPredictions[i] = dp.PredictDistribution(instances[i], out rawPredictions[i]); rawPredictions1[i] = dp.Predict(new Instance(data[i])); } Float[] bulkPredictions = ((IBulkPredictor <Instance, Instances, Float, Float[]>)pred).BulkPredict(instances); Assert.Equal(rawPredictions.Length, bulkPredictions.Length); Assert.Equal(rawPredictions.Length, rawPredictions1.Length); for (int i = 0; i < rawPredictions.Length; i++) { Assert.Equal(rawPredictions[i], bulkPredictions[i]); } for (int i = 0; i < rawPredictions.Length; i++) { Assert.Equal(rawPredictions[i], rawPredictions1[i]); } //test new testers { var results = new ClassifierTester(new ProbabilityPredictorTesterArguments()).Test(pred, instances); // Get metric names and print them alongside numbers for (int i = 0; i < results.Length; i++) { Log("{0,-30} {1}", results[i].Name, results[i].Value); } // sanity check vs. original predictor var results2 = new ClassifierTester(new ProbabilityPredictorTesterArguments()).Test(predictor, instances); Assert.Equal(results.Length, results2.Length); for (int i = 0; i < results.Length; i++) { Assert.Equal(results[i].Name, results2[i].Name); Assert.Equal(results[i].Value, results2[i].Value); } } File.Delete(modelFilename); File.Delete(modelFilenameText); File.Delete(modelFilenameIni); }); Done(); }
[Ignore] // REVIEW: OVA no longer implements BulkPredict. public void MulticlassExampleTest() { string dataFilename = GetDataPath(TestDatasets.msm.trainFilename); ///********* Training a model *******// // assume data is in memory in matrix/vector form. Sparse format also supported. Float[][] data; Float[] labels; // below just reads some actual data into these arrays PredictionUtil.ReadInstancesAsArrays(dataFilename, out data, out labels); // Create an Instances dataset. ListInstances instances = new ListInstances(); for (int i = 0; i < data.Length; i++) { instances.AddInst(data[i], labels[i]); } instances.CopyMetadata(null); // Create a predictor and specify some non-default settings var args = new OVA.OldArguments(); PredictionUtil.ParseArguments(args, "p=FR ps=iter:20"); ITrainer <Instances, IPredictor <Instance, Float[]> > trainer = new OVA(args, new TrainHost(new Random(1), 0)); // Train a predictor trainer.Train(instances); var predictor = trainer.CreatePredictor(); ///********* Several ways to save models. Only binary can be used to-reload in TLC. *******// // Save the model in internal binary format that can be used for loading it. string modelFilename = Path.GetTempFileName(); PredictorUtils.Save(modelFilename, predictor, instances, null); // Save the model as a plain-text description string modelFilenameText = Path.GetTempFileName(); PredictorUtils.SaveText(predictor, instances.Schema.FeatureNames, modelFilenameText); // Save the model in Bing's INI format string modelFilenameIni = Path.GetTempFileName(); PredictorUtils.SaveIni(predictor, instances.Schema.FeatureNames, modelFilenameIni); ///********* Loading and making predictions with a previously saved model *******// // Note: there are several alternative ways to construct instances // For example, see FactoryExampleTest below that demonstrates named-feature : value pairs. // Load saved model IDataModel dataModel; IDataStats dataStats; var pred = PredictorUtils.LoadPredictor <Float[]>(out dataModel, out dataStats, modelFilename); // Get predictions for instances Float[][] predictions = new Float[instances.Count][]; for (int i = 0; i < instances.Count; i++) { predictions[i] = pred.Predict(instances[i]); } // REVIEW: This looks like it wasn't doing what was expected - OVA didn't override // BulkPredict, so this wasn't using FastRank's BulkPredict. Float[][] bulkPredictions = ((IBulkPredictor <Instance, Instances, Float[], Float[][]>)pred).BulkPredict(instances); Assert.Equal(predictions.Length, bulkPredictions.Length); for (int i = 0; i < predictions.Length; i++) { Assert.Equal(predictions[i].Length, bulkPredictions[i].Length); for (int j = 0; j < predictions[i].Length; j++) { Assert.Equal(predictions[i][j], bulkPredictions[i][j]); } } //test new testers { var results = new MulticlassTester(new MulticlassTesterArguments()).Test(pred, instances); // Get metric names and print them alongside numbers for (int i = 0; i < results.Length; i++) { Log("{0,-30} {1}", results[i].Name, results[i].Value); } // sanity check vs. original predictor var results2 = new MulticlassTester(new MulticlassTesterArguments()).Test(predictor, instances); Assert.Equal(results.Length, results2.Length); for (int i = 0; i < results.Length; i++) { Assert.Equal(results[i].Name, results2[i].Name); Assert.Equal(results[i].Value, results2[i].Value); } } File.Delete(modelFilename); File.Delete(modelFilenameText); File.Delete(modelFilenameIni); Done(); }
public ColInfoEx(ArgumentsBase args) { Separators = PredictionUtil.SeparatorFromString(args.TermSeparators); Contracts.CheckUserArg(Utils.Size(Separators) > 0, nameof(args.TermSeparators)); }
public ColInfoEx(Arguments args, int iinfo) { Separators = PredictionUtil.SeparatorFromString(args.Column[iinfo].TermSeparators ?? args.TermSeparators); Contracts.CheckUserArg(Utils.Size(Separators) > 0, nameof(args.TermSeparators)); }
public override void OnJungleClear() { var minions = EntityManager.MinionsAndMonsters.Monsters.Where(t => t.IsValidTarget(1000)); var jungleclear = Features.Find(f => f.NameFeature == "Jungle Clear"); if (minions == null || !minions.Any(t => t.IsValidTarget(1000)) || jungleclear.SliderValue("jungleclear.mana") > Player.Instance.ManaPercent) { return; } var Q = ((Spell.Chargeable)Spells[0]); var W = ((Spell.Skillshot)Spells[1]); var E = ((Spell.Skillshot)Spells[2]); if (jungleclear.IsChecked("jungleclear.q") && Q.IsReady()) { var bestFarmPostion = PredictionUtil.GetBestLineFarmLocation(minions.Select(o => o.ServerPosition.To2D()).ToList(), Q.Width, Q.MaximumRange); if (!Q.IsCharging) { Q.StartCharging(); } else if (Q.Range == Q.MaximumRange) { if (Q.Cast(minions.FirstOrDefault().ServerPosition)) { } } else { if (bestFarmPostion.Position.Distance(Player.Instance) > Q.Range && Q.IsCharging) { return; } Q.Cast(bestFarmPostion.Position.To3D()); } } if (Q.IsCharging) { return; } if (jungleclear.IsChecked("jungleclear.w") && W.IsReady()) { var bestFarmPosition = PredictionUtil.GetBestCircularFarmLocation(minions.Select(o => o.ServerPosition.To2D()).ToList(), W.Width, W.Range); W.Cast(bestFarmPosition.Position.To3D()); } if (jungleclear.IsChecked("jungleclear.e") && E.IsReady() && E.IsInRange(minions.FirstOrDefault())) { var predictionE = E.GetPrediction(minions.FirstOrDefault()); if (predictionE.HitChancePercent >= 85) { E.Cast(predictionE.CastPosition); } } }
/* * Spells[0] = Q * Spells[1] = W * Spells[2] = E * Spells[3] = R */ public override void OnCombo() { var combo = Features.Find(f => f.NameFeature == "Combo"); var comboMisc = Features.Find(f => f.NameFeature == "ComboMisc"); if (R.IsReady() && combo.IsChecked("combo.r")) { var targetR = TargetSelector.GetTarget(R.Range, DamageType.Mixed); if (targetR != null && targetR.IsValidTarget(R.Range)) { if (Player.Instance.Distance(targetR) > comboMisc.SliderValue("combo.misc.minDistance") && targetR != null && targetR.IsValidTarget() && DamageUtil.Killable(targetR, SpellSlot.R, 89)) { var predictionR = R.GetPrediction(targetR); if (predictionR.HitChance >= HitChance.High) { R.Cast(predictionR.CastPosition); } else { var castPosition = Prediction.Position.PredictUnitPosition(targetR, (int)Math.Round(PredictionUtil.GetArrivalTime(Player.Instance.Distance(targetR), 0.5f, R.Speed))); R.Cast(castPosition.To3D()); } } } } var target = TargetSelector.GetTarget(Q.Range, DamageType.Mixed); if (target == null || !target.IsValidTarget(Q.Range) || !target.IsValidTargetUtil()) { return; } if (combo.IsChecked("combo.q") && Q.IsReady()) { if (comboMisc.IsChecked("combo.misc.q")) { castQ = true; } else { var qPredict = Q.GetPrediction(target); if (qPredict.HitChancePercent >= 75) { if (Q.Cast(qPredict.CastPosition)) { castQ = false; } } } } if (combo.IsChecked("combo.w") && W.IsReady() && W.IsInRange(target)) { var wPredict = W.GetPrediction(target); if (wPredict.HitChancePercent >= 85) { W.Cast(wPredict.CastPosition); } } if (combo.IsChecked("combo.e") && E.IsReady() && E.IsInRange(target)) { if (target.CountEnemiesInRange(700) < target.CountAlliesInRange(475) && DamageUtil.Killable(target, SpellSlot.E)) { E.Cast(target.ServerPosition); } } }
public ColInfoEx(Arguments args, int iinfo) { // Use character array separator if any otherwise default to the comma separated string Separators = args.CharArrayTermSeparators ?? PredictionUtil.SeparatorFromString(args.Column[iinfo].TermSeparators ?? args.TermSeparators); Contracts.CheckUserArg(Utils.Size(Separators) > 0, nameof(args.TermSeparators)); }