Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
Remove unused imports

Remove unused imports

Removed unneeded line endings

Remove header in test_finite_difference

Remove unneeded empty lines
  • Loading branch information
pckroon authored and antonykamp committed Dec 7, 2019
1 parent be69afc commit f874839
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 470 deletions.
19 changes: 3 additions & 16 deletions tests/test_argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,8 @@
import pytest
import sys
import sympy
import warnings

import numpy as np
import scipy.stats
from scipy.optimize import curve_fit, minimize

from symfit import (
Variable, Parameter, Fit, FitResults, log, variables,
parameters, Model, Eq, Ge
)
from symfit.core.minimizers import BFGS, MINPACK, SLSQP, LBFGSB
from symfit.core.objectives import LogLikelihood
from symfit.distributions import Gaussian, Exp
from symfit import Variable, Parameter

if sys.version_info >= (3, 0):
import inspect as inspect_sig
Expand Down Expand Up @@ -62,13 +51,11 @@ def test_pickle():
"""
A = Parameter('A', min=0., max=1e3, fixed=True)
new_A = pickle.loads(pickle.dumps(A))
assert (A.min, A.value, A.max, A.fixed, A.name) == (
new_A.min, new_A.value, new_A.max, new_A.fixed, new_A.name)
assert (A.min, A.value, A.max, A.fixed, A.name) == (new_A.min, new_A.value, new_A.max, new_A.fixed, new_A.name)

A = Parameter(min=0., max=1e3, fixed=True)
new_A = pickle.loads(pickle.dumps(A))
assert (A.min, A.value, A.max, A.fixed, A.name) == (
new_A.min, new_A.value, new_A.max, new_A.fixed, new_A.name)
assert (A.min, A.value, A.max, A.fixed, A.name) == (new_A.min, new_A.value, new_A.max, new_A.fixed, new_A.name)


def test_slots():
Expand Down
29 changes: 14 additions & 15 deletions tests/test_auto_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def test_global_fitting():
y_1: a_1 * x_1**2 + b_1 * x_1,
})
fit = Fit(model, x_1=xdata[0], y_1=ydata[0])
assert model.shared_parameters == False
assert model.shared_parameters is False
assert isinstance(fit.minimizer, BFGS)


Expand All @@ -229,6 +229,9 @@ def test_gaussian_2d_fitting():
mean = (0.6, 0.4) # x, y mean 0.6, 0.4
cov = [[0.2**2, 0], [0, 0.1**2]]

# TODO: Since we bin this data later on in a 100 bins, just evaluate 100
# points on a Gaussian, and add an appropriate amount of noise. This
# burns CPU cycles without good reason.
data = np.random.multivariate_normal(mean, cov, 1000000)

# Insert them as y,x here as np fucks up cartesian conventions.
Expand Down Expand Up @@ -256,10 +259,8 @@ def test_gaussian_2d_fitting():

assert fit_result.value(x0) == pytest.approx(np.mean(data[:, 0]), 1e-3)
assert fit_result.value(y0) == pytest.approx(np.mean(data[:, 1]), 1e-3)
assert np.abs(fit_result.value(sig_x)) == pytest.approx(
np.std(data[:, 0]), 1e-2)
assert np.abs(fit_result.value(sig_y)) == pytest.approx(
np.std(data[:, 1]), 1e-2)
assert np.abs(fit_result.value(sig_x)) == pytest.approx(np.std(data[:, 0]), 1e-2)
assert np.abs(fit_result.value(sig_y)) == pytest.approx(np.std(data[:, 1]), 1e-2)
assert fit_result.r_squared >= 0.96


Expand All @@ -272,6 +273,9 @@ def test_gaussian_2d_fitting_background():
cov = [[0.2**2, 0], [0, 0.1**2]]
background = 3.0

# TODO: Since we bin this data later on in a 100 bins, just evaluate 100
# points on a Gaussian, and add an appropriate amount of noise. This
# burns CPU cycles without good reason.
data = np.random.multivariate_normal(mean, cov, 500000)
# print(data.shape)
# Insert them as y,x here as np fucks up cartesian conventions.
Expand All @@ -294,20 +298,15 @@ def test_gaussian_2d_fitting_background():
y = Variable('y')
g = Variable('g')

model = GradientModel(
{g: A * Gaussian(x, x0, sig_x) * Gaussian(y, y0, sig_y) + b})
model = GradientModel({g: A * Gaussian(x, x0, sig_x) * Gaussian(y, y0, sig_y) + b})

# ydata, = model(x=xx, y=yy, x0=mean[0], y0=mean[1], sig_x=np.sqrt(cov[0][0]), sig_y=np.sqrt(cov[1][1]), A=1, b=3.0)
fit = Fit(model, x=xx, y=yy, g=ydata)
fit_result = fit.execute()

assert fit_result.value(
x0) / np.mean(data[:, 0]) == pytest.approx(1.0, 1e-2)
assert fit_result.value(
y0) / np.mean(data[:, 1]) == pytest.approx(1.0, 1e-2)
assert np.abs(fit_result.value(sig_x)) / \
np.std(data[:, 0]) == pytest.approx(1.0, 1e-2)
assert np.abs(fit_result.value(sig_y)) / \
np.std(data[:, 1]) == pytest.approx(1.0, 1e-2)
assert fit_result.value(x0) / np.mean(data[:, 0]) == pytest.approx(1.0, 1e-2)
assert fit_result.value(y0) / np.mean(data[:, 1]) == pytest.approx(1.0, 1e-2)
assert np.abs(fit_result.value(sig_x)) / np.std(data[:, 0]) == pytest.approx(1.0, 1e-2)
assert np.abs(fit_result.value(sig_y)) / np.std(data[:, 1]) == pytest.approx(1.0, 1e-2)
assert background / fit_result.value(b) == pytest.approx(1.0, 1e-1)
assert fit_result.r_squared >= 0.96

0 comments on commit f874839

Please sign in to comment.