public void TestProperties() { double x0 = 0.0; double y0 = 0.0; double sigmaX = 1.0; double sigmaY = 1.0; double theta = 0.0; double scale = 1.0; Gaussian theGaussian = new Gaussian(x0, y0, sigmaX, sigmaY, theta, scale); Assert.That(theGaussian.X0, Is.EqualTo(x0).Within(0.00001), "Initial x0"); Assert.That(theGaussian.Y0, Is.EqualTo(y0).Within(0.00001), "Initial y0"); Assert.That(theGaussian.SigmaX, Is.EqualTo(sigmaX).Within(0.00001), "Initial sigma X"); Assert.That(theGaussian.SigmaY, Is.EqualTo(sigmaY).Within(0.00001), "Initial sigma Y"); Assert.That(theGaussian.Theta, Is.EqualTo(theta).Within(0.00001), "Initial theta"); Assert.That(theGaussian.Scale, Is.EqualTo(scale).Within(0.00001), "Initial scale"); x0 += 10; theGaussian.X0 = x0; Assert.That(theGaussian.X0, Is.EqualTo(x0).Within(0.00001), "Changed x0"); y0 += 10; theGaussian.Y0 = y0; Assert.That(theGaussian.Y0, Is.EqualTo(y0).Within(0.00001), "Changed y0"); sigmaX += 0.5; theGaussian.SigmaX = sigmaX; Assert.That(theGaussian.SigmaX, Is.EqualTo(sigmaX).Within(0.00001), "Changed sigma X"); sigmaY += 0.5; theGaussian.SigmaY = sigmaY; Assert.That(theGaussian.SigmaY, Is.EqualTo(sigmaY).Within(0.00001), "Changed sigma Y"); theta += 30; theGaussian.Theta = theta; Assert.That(theGaussian.Theta, Is.EqualTo(theta).Within(0.00001), "Changed theta"); scale += 0.5; theGaussian.Scale = scale; Assert.That(theGaussian.Scale, Is.EqualTo(scale).Within(0.00001), "Changed scale"); double[] parameters = theGaussian.ParameterValues; Assert.That(theGaussian.X0, Is.EqualTo(parameters[(int)Gaussian.Parameters.X0]).Within(0.00001), "Parameter X0"); Assert.That(theGaussian.Y0, Is.EqualTo(parameters[(int)Gaussian.Parameters.Y0]).Within(0.00001), "Parameter Y0"); Assert.That(theGaussian.SigmaX, Is.EqualTo(parameters[(int)Gaussian.Parameters.SigmaX]).Within(0.00001), "Parameter SigmaX"); Assert.That(theGaussian.SigmaY, Is.EqualTo(parameters[(int)Gaussian.Parameters.SigmaY]).Within(0.00001), "Parameter SigmaY"); Assert.That(theGaussian.Theta, Is.EqualTo(parameters[(int)Gaussian.Parameters.Theta]).Within(0.00001), "Parameter Theta"); Assert.That(theGaussian.Scale, Is.EqualTo(parameters[(int)Gaussian.Parameters.Scale]).Within(0.00001), "Parameter Scale"); }
public void TestValues() { double x0 = 0.0; double y0 = 0.0; double sigmaX = 1.5; double sigmaX2 = sigmaX * sigmaX; double sigmaY = 0.75; double sigmaY2 = sigmaY * sigmaY; double theta = 0.0; double scale = 1.0; Gaussian theGaussian = new Gaussian(x0, y0, sigmaX, sigmaY, theta, scale); for (x0 = 0.0; x0 < 300; x0 += 100) { theGaussian.X0 = x0; for (y0 = 0; y0 < 300; y0 += 100) { theGaussian.Y0 = y0; for (scale = 0.5; scale < 2.0; scale += 0.5) { theGaussian.Scale = scale; for (theta = 0.0; theta < 180.0; theta += 30.0) { theGaussian.Theta = theta; double cosTheta = Math.Cos(Math.PI * theta / 180.0); double sinTheta = Math.Sin(Math.PI * theta / 180.0); for (double x = 0.5; x < 5 * sigmaX; x += 0.5) { for (double y = 0.5; y < 5 * sigmaY; y += 0.5) { double xPrime = cosTheta * x - sinTheta * y; double yPrime = sinTheta * x + cosTheta * y; double expectedValue = scale * Math.Exp(-0.5 * (xPrime * xPrime / sigmaX2 + yPrime * yPrime / sigmaY2)); double gauss = theGaussian[x0 + x, y0 + y]; Assert.That(theGaussian[x0 + x, y0 + y], Is.EqualTo(expectedValue).Within(0.00001), "Value [" + x + ", " + y + "]"); ; Assert.That(theGaussian[x0 - x, y0 - y], Is.EqualTo(expectedValue).Within(0.00001), "Value [" + x + ", " + y + "]"); } } } } } } }
public void TestDerivatives() { double x0 = 0.0; double y0 = 0.0; double sigmaX = 1.5; double sigmaX2 = sigmaX * sigmaX; double sigmaY = 0.75; double sigmaY2 = sigmaY * sigmaY; double theta = 0.0; double scale = 1.0; double delta = 0.00000001; double value; double value2; double expectedValue; Gaussian theGaussian = new Gaussian(x0, y0, sigmaX, sigmaY, theta, scale); // Derivative value = theGaussian[0.5, 0.5]; theGaussian.Scale += delta; value2 = theGaussian[0.5, 0.5]; expectedValue = (value2 - value) / delta; theGaussian.Scale = scale; Assert.That(theGaussian.PartialDerivativeScale(0.5, 0.5), Is.EqualTo(expectedValue).Within(0.00001), "N"); theGaussian.X0 += delta; value2 = theGaussian[0.5, 0.5]; expectedValue = (value2 - value) / delta; theGaussian.X0 = x0; Assert.That(theGaussian.PartialDerivativeX0(0.5, 0.5), Is.EqualTo(expectedValue).Within(0.00001), "X0"); theGaussian.Y0 += delta; value2 = theGaussian[0.5, 0.5]; expectedValue = (value2 - value) / delta; theGaussian.Y0 = y0; Assert.That(theGaussian.PartialDerivativeY0(0.5, 0.5), Is.EqualTo(expectedValue).Within(0.00001), "Y0"); theGaussian.SigmaX += delta; value2 = theGaussian[0.5, 0.5]; expectedValue = (value2 - value) / delta; theGaussian.SigmaX = sigmaX; Assert.That(theGaussian.PartialDerivativeSigmaX(0.5, 0.5), Is.EqualTo(expectedValue).Within(0.00001), "SigmaX"); theGaussian.SigmaY += delta; value2 = theGaussian[0.5, 0.5]; expectedValue = (value2 - value) / delta; theGaussian.SigmaY = sigmaY; Assert.That(theGaussian.PartialDerivativeSigmaY(0.5, 0.5), Is.EqualTo(expectedValue).Within(0.00001), "SigmaY"); theGaussian.Theta += delta; value2 = theGaussian[0.5, 0.5]; expectedValue = (value2 - value) / (delta * Math.PI / 180.0); theGaussian.Theta = theta; Assert.That(theGaussian.PartialDerivativeTheta(0.5, 0.5), Is.EqualTo(expectedValue).Within(0.00001), "Theta"); }