Exemplo n.º 1
0
        // Lifted multiplication operation
        public LiftedSet <γ, Cp> Mult(LiftedSet <γ, Cp> a, LiftedSet <γ, Cp> b)
        {
            List <γ> coefficients = new List <γ>();

            // Sanity check to make sure we have the right number of coefficients
            Debug.Assert(a.coefficients.Count() == _p.Symbols().Count);
            Debug.Assert(b.coefficients.Count() == _p.Symbols().Count);

            foreach (var operandIndices in _multMap)
            {
                γ k = _semiring.AdditiveIdentity;

                foreach (var tuple in operandIndices)
                {
                    var i = tuple.Item1;
                    var j = tuple.Item2;

                    var combined = _semiring.Mult(a.coefficients.ElementAt(i),
                                                  b.coefficients.ElementAt(j));

                    // This Add combines two values to one using the underlying semiring
                    k = _semiring.Add(k, combined);
                }

                // This is List.Add tacking the next coefficient onto the end of the list
                coefficients.Add(k);
            }

            return(new LiftedSet <γ, Cp> {
                coefficients = coefficients
            });
        }
Exemplo n.º 2
0
        public LiftedSet <γ, Cp> Prepare(T element)
        {
            var prepped = _hPredicate.Prepare(element);
            int index   = _hPredicate.Symbols().IndexOf(prepped);

            // Build a "one-hot" vector with a single coefficient set
            IList <γ> coefficients = _hPredicate.Symbols()
                                     .Select(x => _underlying.Semiring.AdditiveIdentity)
                                     .ToList();

            coefficients[index] = _underlying.Prepare(element);

            return(new LiftedSet <γ, Cp>
            {
                coefficients = coefficients
            });
        }
Exemplo n.º 3
0
        public LiftedSemiring(ISemiring <γ> semiring, HPredicate <Cp, T> p, List <List <Tuple <int, int> > > multMap)
        {
            // Sanity check to make sure there's an entry in the multiplication map for
            // each element of the predicate's state set
            if (multMap.Count != p.Symbols().Count)
            {
                throw new System.Exception(string.Format("Assert failed, multMap.Count = {0} p.Symbols().Count = {1}",
                                                         multMap.Count,
                                                         p.Symbols().Count));
            }

            Debug.Assert(multMap.Count == p.Symbols().Count);

            _semiring = semiring;
            _p        = p;
            _multMap  = multMap;
        }