public static TyresEntry ToTyresEntry([NotNull] this NeuralTyresEntry values, [CanBeNull] TyresEntry original, [CanBeNull] string name, [CanBeNull] string shortName) { var mainSection = original?.MainSection.Clone() ?? new IniFileSection(null); var thermalSection = original?.ThermalSection.Clone() ?? new IniFileSection(null); mainSection.Set("NAME", name.Or(values.Name)); mainSection.Set("SHORT_NAME", shortName.Or(values.ShortName)); foreach (var key in values.Keys.ApartFrom(NeuralTyresEntry.TemporaryKeys)) { if (key.StartsWith(ThermalPrefix)) { var actualKey = key.Substring(ThermalPrefix.Length); thermalSection.Set(actualKey, Fix(values[key], key)); } else { mainSection.Set(key, Fix(values[key], key)); } } return(new TyresEntry(original?.SourceCarId, values.Version, mainSection, thermalSection, original?.WearCurveData, original?.PerformanceCurveData, original?.RearTyres ?? false, null)); double Fix(double value, string key) { var digits = GetValueDigits(key); return(digits.HasValue ? FlexibleParser.ParseDouble(value.ToString($@"F{digits.Value}"), value) : value); } }
public NeuralTyresEntry Conjure(params double[] input) { var name = Sources.Select(x => x.Name).GroupBy(x => x).MaxEntry(x => x.Count()).Key; var shortName = Sources.Select(x => x.ShortName).GroupBy(x => x).MaxEntry(x => x.Count()).Key; var result = new NeuralTyresEntry(name, shortName, TyresVersion); SetInputs(input, result); if (_singleNetwork != null) { var data = _singleNetwork.Compute(input); if (data.Length != _outputKeys.Length) { throw new Exception($"Amount of computed data doesn’t match output keys: {data.Length}≠{_outputKeys.Length}"); } for (var i = 0; i < _outputKeys.Length; i++) { SetValue(result, _outputKeys[i], _outputNormalizations[i].Denormalize(data[i])); } } else if (_networks != null) { for (var i = 0; i < _networks.Length; i++) { SetValue(result, _outputKeys[i], _outputNormalizations[i].Denormalize(_networks[i].Compute(input)[0])); } } else { throw new Exception("Invalid state"); } return(result); }
private void SetInputs(double[] input, NeuralTyresEntry result) { if (input.Length != _options.InputKeys.Length) { throw new Exception("Input keys and inputs lengths don’t match"); } for (var i = 0; i < _options.InputKeys.Length; i++) { var key = _options.InputKeys[i]; var normalization = _inputNormalizations[i]; if (!normalization.Fits(input[i])) { throw new Exception($"Value {input[i]} for {key} is out of range {normalization}"); } if (!IsProceduralValue(key)) { SetValue(result, key, input[i]); input[i] = normalization.Normalize(input[i]); } } for (var i = 0; i < _options.InputKeys.Length; i++) { var key = _options.InputKeys[i]; if (IsProceduralValue(key)) { SetValue(result, key, input[i]); input[i] = _inputNormalizations[i].Normalize(input[i]); } } }
private static double GetValue(NeuralTyresEntry tyre, string key) { if (key == NeuralTyresOptions.InputProfile) { return(tyre[NeuralTyresOptions.InputRadius] - tyre[NeuralTyresOptions.InputRimRadius]); } return(tyre[key]); }
private static void SetValue(NeuralTyresEntry tyre, string key, double value) { tyre[key] = value; }