Example #1
0
        public static double Perturb(double value, PerturbSetting perturbSetting)
        {
            EnsureArg.IsNotNull(perturbSetting, nameof(perturbSetting));

            var noise = Noise(value, perturbSetting);

            return(Math.Round(value + noise, perturbSetting.RoundTo));
        }
Example #2
0
        public static AgeValue Perturb(AgeValue value, PerturbSetting perturbSetting)
        {
            EnsureArg.IsNotNull(perturbSetting, nameof(perturbSetting));

            var result = Perturb(value.Age, perturbSetting);

            return(new AgeValue(result, value.AgeType));
        }
Example #3
0
        public static ushort Perturb(ushort value, PerturbSetting perturbSetting)
        {
            EnsureArg.IsNotNull(perturbSetting, nameof(perturbSetting));

            perturbSetting.RoundTo = 0;
            var noise = Noise(value, perturbSetting);

            return((ushort)Math.Round(value + noise < 0 ? 0 : value + noise, perturbSetting.RoundTo));
        }
Example #4
0
        public static long Perturb(long value, PerturbSetting perturbSetting)
        {
            EnsureArg.IsNotNull(perturbSetting, nameof(perturbSetting));

            perturbSetting.RoundTo = 0;
            var noise = Noise(value, perturbSetting);

            return((long)Math.Round(value + noise, perturbSetting.RoundTo));
        }
Example #5
0
        private static double Noise(double value, PerturbSetting perturbSetting)
        {
            perturbSetting.Validation();

            var span = perturbSetting.Span;

            if (perturbSetting.RangeType == PerturbRangeType.Proportional)
            {
                span = Math.Abs(value * perturbSetting.Span);
            }

            return(perturbSetting.NoiseFunction == null?ContinuousUniform.Sample(-1 *span / 2, span / 2) : perturbSetting.NoiseFunction(span));
        }
Example #6
0
        public static string Perturb(string value, PerturbSetting perturbSetting)
        {
            EnsureArg.IsNotNull(value, nameof(value));
            EnsureArg.IsNotNull(perturbSetting, nameof(perturbSetting));

            try
            {
                var originValue    = decimal.Parse(value);
                var perturbedValue = Perturb(originValue, perturbSetting);
                return(perturbedValue.ToString());
            }
            catch (Exception ex)
            {
                throw new DeIDFunctionException();
            }
        }