示例#1
0
文件: dwSSA.cs 项目: clorton/IDM-CMS
        private GammaInfo CrossEntropy2(GammaInfo gammaInfo)
        {
            IBoolean tempRareEventExpression = new EqualTo(_reExpression, new ConstantValue(gammaInfo.IntermediateRareEvent));
            var      gammaInfoOut            = new GammaInfo(_reactions.NumReactions)
            {
                IntermediateRareEvent = gammaInfo.IntermediateRareEvent,
                IntermediateGamma     = gammaInfo.IntermediateGamma
            };

            for (int i = 0; i < _crossEntropyRuns; i++)
            {
                StartRealization();
                var    n      = new int[_reactions.NumReactions];
                var    lambda = new double[_reactions.NumReactions];
                double weight = 1.0;

                while (CurrentTime < duration)
                {
                    if (tempRareEventExpression.Value)
                    {
                        gammaInfoOut.UpdateGamma(weight, n, lambda);
                        break;
                    }

                    StepOnce(ref weight, gammaInfoOut.IntermediateGamma, ref n, ref lambda);
                }
            }

            gammaInfoOut.SetIntermediateGamma();

            return(gammaInfoOut);
        }
示例#2
0
        private GammaInfo CrossEntropy1(GammaInfo gammaInfo)
        {
            var maxRareEventValue = new float[_crossEntropyRuns];
            int counter           = 0;

            for (int i = 0; i < _crossEntropyRuns; i++)
            {
                StartRealization();
                float  currentMin = _rareEventType * (_rareEventValue - _reExpression.Value);
                var    n          = new int[_reactions.NumReactions];
                var    lambda     = new double[_reactions.NumReactions];
                double weight     = 1.0;

                while (CurrentTime < duration)
                {
                    if (_rareEventTest.Value)
                    {
                        counter++;
                        gammaInfo.UpdateGamma(weight, n, lambda);
                        break;
                    }

                    StepOnce(ref weight, gammaInfo.IntermediateGamma, ref n, ref lambda);
                    float tempMin = _rareEventType * (_rareEventValue - _reExpression.Value);
                    currentMin = Math.Min(currentMin, tempMin);
                }

                maxRareEventValue[i] = currentMin;
            }

            Array.Sort(maxRareEventValue);
            float ireComp = maxRareEventValue[(int)Math.Ceiling(_crossEntropyRuns * _crossEntropyThreshold)];
            float pastIntermediateRareEvent = gammaInfo.IntermediateRareEvent;

            gammaInfo.IntermediateRareEvent = ireComp < 0 ? _rareEventValue : _rareEventType * (_rareEventValue - ireComp);

            if (gammaInfo.IntermediateRareEvent >= _rareEventValue && counter >= (int)(_crossEntropyRuns * _crossEntropyThreshold))
            {
                gammaInfo.SetIntermediateGamma();
                var gammaInfoOut = new GammaInfo(_reactions.NumReactions)
                {
                    IntermediateRareEvent = _rareEventValue
                };

                for (int i = 0; i < _reactions.NumReactions; i++)
                {
                    gammaInfoOut.IntermediateGamma[i] = gammaInfo.IntermediateGamma[i];
                }

                return(gammaInfoOut);
            }

            var cetCriteria = (pastIntermediateRareEvent - gammaInfo.IntermediateRareEvent) * _rareEventType;

            if (cetCriteria > 0)
            {
                _crossEntropyThreshold *= 0.8f;
                Console.WriteLine("Cross entropy threshold changed to : " + _crossEntropyThreshold);
                Console.WriteLine("CETC: {0}   pire: {1}   ire:{2} ", cetCriteria, pastIntermediateRareEvent, gammaInfo.IntermediateRareEvent);

                if (_crossEntropyThreshold * _crossEntropyRuns * 0.8 < _crossEntropyMinDataSize)
                {
                    _crossEntropyRuns = (int)Math.Ceiling(_crossEntropyMinDataSize / _crossEntropyThreshold);
                    Console.WriteLine("Number of cross entropy simulations changed to : " + _crossEntropyRuns);
                }
            }

            return(gammaInfo);
        }