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)); }
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)); }
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)); }
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)); }
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)); }
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(); } }