예제 #1
0
파일: sdwSSA.cs 프로젝트: clorton/IDM-CMS
        private void CrossEntropy2(ref StateDependentGammaInfo gammaInfo, double tempRareEvent)
        {
            IBoolean tempRareEventExpression = new EqualTo(_reExpression, new ConstantValue(tempRareEvent));

            var startPC          = Enumerable.Repeat(1.0, _reactions.NumReactions).ToArray();
            var endPC            = new double[_reactions.NumReactions];
            var rateUpdateMethod = new ReactionRatesUpdateMethod(_reactions.UpdateRatesIteration2);

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

                for (int j = 0; j < _reactions.NumReactions; j++)
                {
                    n.Add(new int[(gammaInfo.IntermediatePropensityCutoff[j]).Length + 1]);
                    lambda.Add(new double[(gammaInfo.IntermediatePropensityCutoff[j]).Length + 1]);
                }

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

                    GenericStepOnce(ref weight, gammaInfo, ref startPC, ref endPC, ref n, ref lambda, rateUpdateMethod, ref _binIndex, null);
                }
            }

            gammaInfo.SetIntermediateGamma();
        }
예제 #2
0
파일: sdwSSA.cs 프로젝트: clorton/IDM-CMS
        private void CrossEntropy1(ref StateDependentGammaInfo gammaInfo, ref double intermediateRareEvent, ref double[] startPC, ref double[] endPC, ref bool rareEventFlag)
        {
            var maxRareEventValue = new double[_crossEntropyRuns];
            int counter           = 0;

            var rateUpdateMethod     = new ReactionRatesUpdateMethod(_reactions.UpdateRatesIteration1);
            var binEdgesUpdateMethod = new BinEdgesUpdateMethod(UpdateBinEdges);

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

                for (int j = 0; j < _reactions.NumReactions; j++)
                {
                    n.Add(new int[(gammaInfo.IntermediatePropensityCutoff[j]).Length + 1]);
                    lambda.Add(new double[(gammaInfo.IntermediatePropensityCutoff[j]).Length + 1]);
                }

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

                    GenericStepOnce(ref weight, gammaInfo, ref startPC, ref endPC, ref n, ref lambda, rateUpdateMethod, ref _gammaIndex, binEdgesUpdateMethod);
                    double tempMin = _rareEventType * (_rareEventValue - _reExpression.Value);
                    currentMin = Math.Min(currentMin, tempMin);
                }

                maxRareEventValue[i] = currentMin;
            }

            Array.Sort(maxRareEventValue);
            double ireComp = maxRareEventValue[(int)Math.Ceiling(_crossEntropyRuns * _crossEntropyThreshold)];
            double pastIntermediateRareEvent = intermediateRareEvent;

            intermediateRareEvent = ireComp < 0 ? _rareEventValue : _rareEventType * (_rareEventValue - ireComp);

            if ((pastIntermediateRareEvent - intermediateRareEvent) * _rareEventType >= 0)
            {
                _crossEntropyThreshold *= 0.8;
                Console.WriteLine("Cross entropy threshold changed to : " + _crossEntropyThreshold);

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

            if (intermediateRareEvent >= _rareEventValue && counter >= (int)(_crossEntropyRuns * _crossEntropyThreshold))
            {
                rareEventFlag = true;
                gammaInfo.SetIntermediateGamma();
            }
        }