public void OptimizeTest() { var val = "(|0=0.7|2000=0.8|4000=0.9|5000=0.6|)"; var lut = Lut.FromValue(val); Assert.AreEqual("(|0=0.7|4000=0.9|5000=0.6|)", lut.Optimize().ToString()); }
public void ToStringTest() { var val = "(|0=0.7|1000=0.8|4000=0.9|)"; var lut = Lut.FromValue(val); Assert.AreEqual(val, lut.ToString()); }
public void LutValueParse() { var lut = Lut.FromValue("(|0=0.7|1000=0.8|4000=0.9|)"); Assert.IsTrue(lut.SequenceEqual(Lut.FromValue("(0=0.7|1000=0.8|4000=0.9)"))); Assert.AreEqual(3, lut.Count); Assert.AreEqual(2, Lut.FromValue("(0=0.7|=0.8|4000=0.9)").Count); Assert.AreEqual(0.75, lut.InterpolateLinear(500d), 0.00001); Assert.AreEqual(0.85, lut.InterpolateLinear(2500d), 0.00001); Assert.AreEqual(0.9, lut.InterpolateLinear(4500d), 0.00001); }
public Lut GetLut([NotNull, LocalizationRequired(false)] string key) { var value = GetNonEmpty(key); return(value == null ? null : Lut.FromValue(value)); }
private TyresMachine([NotNull] Stream stream, [CanBeNull] ITyresMachineExtras extras) { using (var zip = new ZipArchive(stream, ZipArchiveMode.Read, false)) { var manifest = Read <JObject>("Manifest.json"); if (manifest.GetIntValueOnly("version") != SaveFormatVersion) { throw new Exception("Unsupported version: " + manifest.GetIntValueOnly("version")); } TyresVersion = manifest.GetIntValueOnly("tyresVersion", 0); if (TyresVersion < 7) { throw new Exception("Unsupported tyres version: " + TyresVersion); } _loadedManifest = manifest; _options = Read <NeuralTyresOptions>("Options.json"); _tyresSources = Read <NeuralTyresSource[]>("Input/Sources.json"); _luts = Read <Dictionary <string, string>[]>("Input/LUTs.json") .Select(x => (IReadOnlyDictionary <string, Lut>)x.ToDictionary(y => y.Key, y => Lut.FromValue(y.Value))).ToArray(); _inputNormalizations = Read <Normalization[]>("Input/Normalizations.json"); _outputKeys = Read <string[]>("Output/Keys.json"); _outputNormalizations = Read <Normalization[]>("Output/Normalizations.json"); extras?.OnLoad(zip, manifest, this); if (_options.SeparateNetworks) { _networks = new INeuralNetwork[_outputKeys.Length]; for (var i = 0; i < _outputKeys.Length; i++) { var key = _outputKeys[i]; var typeName = zip.ReadString($"Networks/{key}/Type.txt"); var type = Type.GetType(typeName); if (type == null) { throw new Exception("Type not found: " + typeName); } var instance = (INeuralNetwork)Activator.CreateInstance(type); instance.SetOptions(_options); instance.Load(zip.ReadBytes($"Networks/{key}/Data.bin")); _networks[i] = instance; } } else { var typeName = zip.ReadString("Network/Type.txt"); var type = Type.GetType(typeName); if (type == null) { throw new Exception("Type not found: " + typeName); } var instance = (INeuralNetwork)Activator.CreateInstance(type); instance.SetOptions(_options); instance.Load(zip.ReadBytes("Network/Data.bin")); _singleNetwork = instance; } T Read <T>(string key) { return(JsonConvert.DeserializeObject <T>(zip.ReadString(key))); } } }