Esempio n. 1
0
        private void InitializeHistogram(List <double> probabilities)
        {
            histogram = new AliasHistogramTable();

            // Aliases default to a self-reference.
            histogram.Alias = new List <int>();
            histogram.Alias.FillWithIndex(probabilities.Count);

            // Scale probabilities to an average of 1.0
            histogram.Probability = new List <double>(probabilities);
            histogram.Probability.ForEach(probability => probability *= histogram.Probability.Count);
        }
Esempio n. 2
0
        public void Load(string fileURI)
        {
            try
            {
                using (var file = File.Open(fileURI, FileMode.Open))
                {
                    var binaryFormatter = new BinaryFormatter();
                    histogram = (AliasHistogramTable)binaryFormatter.Deserialize(file);
                }
            }
            catch (IOException exception)
            {
                throw new IOException("Error accessing histogram file.", exception);
            }

            if (!histogram.IsValid())
            {
                throw new Exception("Histogram is invalid.");
            }
        }