internal double CalculateMaximumFinalProbability(AutoResizeBigVector <double> cache, double[] initialStateProbabilities)
        {
            var cid = Nmdp.GetRootContinuationGraphLocationOfInitialState();

            cache?.Clear(cid);             //use cid as offset, because it is the smallest element
            return(CalculateMaximumProbabilityOfCid(cache, initialStateProbabilities, cid));
        }
Beispiel #2
0
        public double CalculateMinimumFinalProbability(AutoResizeBigVector <double> cache, PrecalculatedTransitionTarget[] precalculatedTransitionTargets, double[] initialStateProbabilities)
        {
            var cid = Ltmdp.GetRootContinuationGraphLocationOfInitialState();

            cache?.Clear(cid);             //use cid as offset, because it is the smallest element
            return(CalculateMinimumProbabilityOfCid(cache, precalculatedTransitionTargets, initialStateProbabilities, cid));
        }
 private void Clear(long cidRoot)
 {
     _probabilityOfCid.Clear(cidRoot);             // use cidRoot as offset, because it is the smallest element
     _continuationGraphLeafOfCid.Clear(cidRoot);
     _probabilityOfCid[cidRoot] = 1.0;
     _ltmdpContinuationDistributionMapper.Clear();
 }
        internal double[] MaximumIterator(AutoResizeBigVector <double> cache, Dictionary <int, bool> exactlyOneStates, Dictionary <int, bool> exactlyZeroStates, int steps)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var stateCount = Nmdp.States;

            var xold  = new double[stateCount];
            var xnew  = CreateDerivedVector(exactlyOneStates);
            var loops = 0;

            while (loops < steps)
            {
                // switch xold and xnew
                var xtemp = xold;
                xold = xnew;
                xnew = xtemp;
                loops++;
                for (var i = 0; i < stateCount; i++)
                {
                    if (exactlyOneStates.ContainsKey(i))
                    {
                        //we could remove this line, because already set by CreateDerivedVector and never changed when we initialize xold with CreateDerivedVector(directlySatisfiedStates)
                        xnew[i] = 1.0;
                    }
                    else if (exactlyZeroStates.ContainsKey(i))
                    {
                        //we could remove this line, because already set by CreateDerivedVector and never changed when we initialize xold with CreateDerivedVector(directlySatisfiedStates)
                        xnew[i] = 0.0;
                    }
                    else
                    {
                        var cid = Nmdp.GetRootContinuationGraphLocationOfState(i);
                        cache?.Clear(cid);                         //use cid as offset, because it is the smallest element
                        xnew[i] = CalculateMaximumProbabilityOfCid(cache, xold, cid);
                    }
                }

                if (loops % 10 == 0)
                {
                    stopwatch.Stop();
                    var currentProbability = CalculateMaximumFinalProbability(cache, xnew);
                    _output?.WriteLine(
                        $"{loops} Bounded Until iterations in {stopwatch.Elapsed}. Current probability={currentProbability.ToString(CultureInfo.InvariantCulture)}");
                    stopwatch.Start();
                }
            }
            stopwatch.Stop();
            return(xnew);
        }
Beispiel #5
0
        internal double[] MaximumIterator(AutoResizeBigVector <double> cache, PrecalculatedTransitionTarget[] precalculatedTransitionTargets, int steps)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var stateCount = Ltmdp.SourceStates.Count;

            var xold  = new double[stateCount];
            var xnew  = new double[stateCount];
            var loops = 0;

            while (loops < steps)
            {
                // switch xold and xnew
                var xtemp = xold;
                xold = xnew;
                xnew = xtemp;
                loops++;
                for (var i = 0; i < stateCount; i++)
                {
                    var cid = Ltmdp.GetRootContinuationGraphLocationOfState(i);
                    cache?.Clear(cid);                     //use cid as offset, because it is the smallest element
                    xnew[i] = CalculateMaximumProbabilityOfCid(cache, precalculatedTransitionTargets, xold, cid);
                }

                if (loops % 10 == 0)
                {
                    stopwatch.Stop();
                    var currentProbability = CalculateMaximumFinalProbability(cache, precalculatedTransitionTargets, xnew);
                    _output?.WriteLine(
                        $"{loops} Bounded Until iterations in {stopwatch.Elapsed}. Current probability={currentProbability.ToString(CultureInfo.InvariantCulture)}");
                    stopwatch.Start();
                }
            }
            stopwatch.Stop();
            return(xnew);
        }