Example #1
0
        private static Prediction.Entry[] ReadLookupTable(ExtendedBinaryReader reader)
        {
            int numEntries = reader.ReadInt32();
            var lut        = new Prediction.Entry[numEntries];

            for (var i = 0; i < numEntries; i++)
            {
                lut[i] = Prediction.Entry.ReadEntry(reader);
            }
            return(lut);
        }
        private static Prediction.Entry[] ReadLookupTable(BinaryReader reader)
        {
            var numEntries = reader.ReadInt32();
            var lut        = new Prediction.Entry[numEntries];

            for (int i = 0; i < numEntries; i++)
            {
                lut[i] = Prediction.Entry.Read(reader);
            }
            return(lut);
        }
Example #3
0
        public static Prediction.Entry[] ConvertLookupTable(RoundedEntry[] lut)
        {
            var newLut = new Prediction.Entry[lut.Length];

            for (int i = 0; i < lut.Length; i++)
            {
                var entry = lut[i];
                newLut[i] = new Prediction.Entry(entry.Score / MaxValue, entry.EnumIndex);
            }

            return(newLut);
        }
        private static (Prediction.Entry[] Lut, Dictionary <RoundedEntry, byte> RoundedEntryToLutIndex) CreateLut(
            IEnumerable <RoundedEntryPrediction[]> roundedPredictionsPerRef)
        {
            var scores = new HashSet <RoundedEntry>();

            foreach (var roundedPredictions in roundedPredictionsPerRef)
            {
                if (roundedPredictions == null)
                {
                    continue;
                }

                foreach (var roundedPrediction in roundedPredictions)
                {
                    foreach (var roundedEntry in roundedPrediction.Entries)
                    {
                        if (roundedEntry.Score > 1000)
                        {
                            continue;
                        }
                        scores.Add(roundedEntry);
                    }
                }
            }

            if (scores.Count > 255)
            {
                throw new InvalidDataException($"Unable to create lookup table, too many LUT entries: {scores.Count} (max 255).");
            }

            var lut = new Prediction.Entry[scores.Count];
            var roundedEntryToLutIndex = new Dictionary <RoundedEntry, byte>();

            var currentIndex = 0;

            foreach (var entry in scores.OrderBy(x => x.EnumIndex).ThenBy(x => x.Score))
            {
                roundedEntryToLutIndex[entry] = (byte)currentIndex;
                lut[currentIndex++]           = new Prediction.Entry(entry.Score / 1000.0, entry.EnumIndex);
            }

            return(lut, roundedEntryToLutIndex);
        }