Example #1
0
        private TyresMachine([NotNull] NeuralTyresEntry[] tyres, [NotNull] NeuralTyresOptions options)
        {
            if (tyres == null)
            {
                throw new ArgumentNullException(nameof(tyres));
            }
            if (tyres.Length == 0)
            {
                throw new ArgumentException("Value cannot be an empty collection.", nameof(tyres));
            }
            _options = options ?? throw new ArgumentNullException(nameof(options));

            // Some details to identify Machine later if needed
            _tyresSources = tyres.Cast <NeuralTyresSource>().ToArray();

            // Tyres version
            TyresVersion = tyres[0].Version;
            if (tyres.Any(x => x.Version != TyresVersion))
            {
                throw new ArgumentException("Inconsistent versions");
            }

            // LUTs, just in case
            _luts = tyres.Select(x => x.Luts).ToArray();

            // Input normalizations and values
            _inputNormalized = new double[tyres.Length][];
            for (var i = 0; i < tyres.Length; i++)
            {
                _inputNormalized[i] = new double[3];
            }

            _inputNormalizations = new Normalization[options.InputKeys.Length];
            for (var i = 0; i < _inputNormalizations.Length; i++)
            {
                var limits = _options.NormalizationLimits.GetLimits(options.InputKeys[i]) ?? Tuple.Create(double.NegativeInfinity, double.PositiveInfinity);
                _inputNormalizations[i] = Normalization.BuildNormalization(tyres, options.InputKeys[i], options.ValuePadding,
                                                                           out var normalized, limits.Item1, limits.Item2);
                for (var j = 0; j < normalized.Length; j++)
                {
                    _inputNormalized[j][i] = normalized[j];
                }
            }

            // Output normalizations and values
            _outputKeys = tyres[0].Keys.Where(x => Array.IndexOf(options.IgnoredKeys, x) == -1 &&
                                              (options.OverrideOutputKeys == null || Array.IndexOf(options.OverrideOutputKeys, x) != -1)).ToArray();
            _outputNormalizations = new Normalization[_outputKeys.Length];
            _outputNormalized     = new double[_outputKeys.Length][];

            for (var i = 0; i < _outputKeys.Length; i++)
            {
                var limits = _options.NormalizationLimits.GetLimits(_outputKeys[i]) ?? Tuple.Create(double.NegativeInfinity, double.PositiveInfinity);
                _outputNormalizations[i] = Normalization.BuildNormalization(tyres, _outputKeys[i], options.ValuePadding,
                                                                            out _outputNormalized[i], limits.Item1, limits.Item2);
            }
        }