// 50% overlap between phases
        public Hysteresis(double range, int phaseCount)
        {
            ArgAssert.GreaterThan(range, "range", 0);
            ArgAssert.AtLeast(phaseCount, "phaseCount", 2);

            var downwardsThresholds = new double[phaseCount];
            var upwardsThresholds   = new double[phaseCount];

            var step = range / (phaseCount + 1);

            downwardsThresholds[0] = 0;
            downwardsThresholds[1] = step;

            for (var i = 2; i < phaseCount; i++)
            {
                downwardsThresholds[i]   = i * step;
                upwardsThresholds[i - 2] = downwardsThresholds[i];
            }

            upwardsThresholds[phaseCount - 2] = phaseCount * step;
            upwardsThresholds[phaseCount - 1] = range;

            _downwardsThresholds = downwardsThresholds;
            _upwardsThresholds   = upwardsThresholds;
            _equilibria          = ComputeEquilibria();
        }
        public void Initialize(int phase, double state)
        {
            ArgAssert.GreaterThan(state, "state", _downwardsThresholds[phase], string.Format("_downwardsThresholds[{0}]", phase));
            ArgAssert.LessThan(state, "state", _upwardsThresholds[phase], string.Format("_upwardsThresholds[{0}]", phase));

            _phase = phase;
            _state = state;
        }
        private void ValidateThresholds()
        {
            ArgAssert.AtLeast(_downwardsThresholds.Count, "thresholds.Count", 2);
            ArgAssert.Equal(_downwardsThresholds.Count, "downwardsThreholds.Count", _upwardsThresholds.Count, "upwardsTresholds.Count");

            for (var i = 1; i < PhaseCount; i++)
            {
                ArgAssert.GreaterThan
                    (_upwardsThresholds[i - 1], string.Format("_upwardsThresholds[{0}]", i - 1),
                    _downwardsThresholds[i], string.Format("_downwardsThresholds[{0}]", i));

                ArgAssert.GreaterThan
                    (_upwardsThresholds[i], string.Format("_upwardsThresholds[{0}]", i),
                    _upwardsThresholds[i - 1], string.Format("_upwardsThresholds[{0}]", i - 1));

                ArgAssert.GreaterThan
                    (_downwardsThresholds[i], string.Format("_downwardsThresholds[{0}]", i),
                    _downwardsThresholds[i - 1], string.Format("_downwardsThresholds[{0}]", i - 1));
            }
        }