public static ParamsContainer TestingDeltaIndexes(int n, double coeff, double initialStep = 1, double accuracy = 0.0000001) { double[] deltaIndexes = new double[n]; double[] deltaIndexesSteps = new double[n]; for (int i = 0; i < deltaIndexesSteps.Length; i++) { deltaIndexesSteps[i] = initialStep / (Math.Pow(2, i)); } ParamsContainer container = new ParamsContainer(); container.N = n; container.Coeff = coeff; DACEmulator emulator = new DACEmulator(n, 0, deltaIndexes, 0); emulator.DeltaIndexes = deltaIndexes; bool isContinue = true; while (isContinue) { isContinue = deltaIndexesSteps.Select(x => Math.Abs(x)).Max() >= accuracy; for (int i = deltaIndexes.Length - 1; i >= 0; i--) { deltaIndexes[i] += deltaIndexesSteps[i]; emulator.DeltaIndexes = deltaIndexes; bool noErrors = ErrorChecking(emulator); if (!noErrors) { deltaIndexes[i] -= deltaIndexesSteps[i]; deltaIndexesSteps[i] /= 2; } } } for (int i = deltaIndexes.Length - 1; i >= 0; i--) { emulator.DeltaIndexes[i] += deltaIndexesSteps[i]; } container.DeltaIndexes = deltaIndexes; return(container); }
public static ParamsContainer TestingDelta(int n, double coeff, DACEmulator.Delta delta, double initialStep = 1, double accuracy = 0.0001, double deltaCoeff = 0, double deltaIndex = 0, double deltaSM = 0, bool isAllowedValues = false) { int countNumbers = (int)Math.Pow(2, n); List <int> indexes = new List <int>(); ParamsContainer container = new ParamsContainer(n, coeff, deltaCoeff, deltaIndex, deltaSM); LongBits inputBinaryCode = new LongBits(0, n), outputBinaryCode = inputBinaryCode; DACEmulator emulator = new DACEmulator(n, coeff, deltaCoeff, deltaIndex, deltaSM); while (Math.Abs(initialStep * 2) > accuracy) { inputBinaryCode = outputBinaryCode; while (inputBinaryCode == outputBinaryCode) { emulator.DeltaCoeff = deltaCoeff; emulator.DeltaIndex = deltaIndex; emulator.DeltaSM = deltaSM; for (int x = 0; x < countNumbers; x++) { inputBinaryCode = new LongBits(x, n); outputBinaryCode = emulator.GetDKFromComparators(x); if (inputBinaryCode != outputBinaryCode) { break; } } if (inputBinaryCode == outputBinaryCode) { if (delta == DACEmulator.Delta.Coeff) { deltaCoeff += initialStep; } else if (delta == DACEmulator.Delta.Index) { deltaIndex += initialStep; } else if (delta == DACEmulator.Delta.SM) { deltaSM += initialStep; } } } if (delta == DACEmulator.Delta.Coeff) { deltaCoeff -= initialStep; } else if (delta == DACEmulator.Delta.Index) { deltaIndex -= initialStep; } else if (delta == DACEmulator.Delta.SM) { deltaSM -= initialStep; } initialStep /= 2; } //Корректировка значений, если необходимо if (isAllowedValues) { if (delta == DACEmulator.Delta.Coeff) { emulator.DeltaCoeff -= initialStep * 2; } else if (delta == DACEmulator.Delta.Index) { emulator.DeltaIndex -= initialStep * 2; } else if (delta == DACEmulator.Delta.SM) { emulator.DeltaSM -= initialStep * 2; } } for (int x = 0; x < countNumbers; x++) { indexes.AddRange(emulator.GetEKPErrorFromComparators(x).ToList()); inputBinaryCode = new LongBits(x, n); outputBinaryCode = emulator.GetDKFromComparators(x); if (inputBinaryCode != outputBinaryCode) { container.ErrorIndexesFromInputAndOutputCodes.Add(x); } container.InputBinaryCodes.Add(inputBinaryCode); container.OutputBinaryCodes.Add(outputBinaryCode); } container.DeltaCoeff = emulator.DeltaCoeff; container.DeltaIndex = emulator.DeltaIndex; container.DeltaSM = emulator.DeltaSM; container.ComparatorsErrorIndexes = indexes.Distinct().ToArray(); return(container); }