Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        public void ToStringTest()
        {
            var val = "(|0=0.7|1000=0.8|4000=0.9|)";
            var lut = Lut.FromValue(val);

            Assert.AreEqual(val, lut.ToString());
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public Lut GetLut([NotNull, LocalizationRequired(false)] string key)
        {
            var value = GetNonEmpty(key);

            return(value == null ? null : Lut.FromValue(value));
        }
Esempio n. 5
0
        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)));
                }
            }
        }