Skip to content

Commit

Permalink
Remove duplication of examples and tests (#95)
Browse files Browse the repository at this point in the history
* Added ex 6.3 to docs/source/examples/
* Deleted gpfit/examples/ dir
* Consolidated ex 6.3 into t_examples (deleted t_ex6_3.py)
  • Loading branch information
pgkirsch committed Jul 10, 2021
1 parent 5b2b316 commit 6387927
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 108 deletions.
2 changes: 0 additions & 2 deletions docs/source/examples/hoburgabbeel_ex6_1.py
@@ -1,9 +1,7 @@
"Fits an example function"
from __future__ import division
from numpy import logspace, log, log10, random
from gpfit.fit import fit

# fixed initial guess for fitting
random.seed(33404)

u = logspace(0, log10(3), 101)
Expand Down
22 changes: 22 additions & 0 deletions docs/source/examples/hoburgabbeel_ex6_3.py
@@ -0,0 +1,22 @@
"Example 6.3 from Hoburg/Abbeel GPfit paper"
import numpy as np
from numpy.random import seed, random_sample
from gpfit.fit import fit

seed(33404)

Vdd = random_sample(1000,) + 1
Vth = 0.2*random_sample(1000,) + 0.2
P = Vdd**2 + 30*Vdd*np.exp(-(Vth - 0.06*Vdd)/0.039)
u = np.vstack((Vdd, Vth))
x = np.log(u)
y = np.log(P)
K = 4

_, errorMA = fit(x, y, K, "MA")
_, errorSMA = fit(x, y, K, "SMA")
_, errorISMA = fit(x, y, K, "ISMA")

print("MA RMS Error: %.5g" % errorMA)
print("SMA RMS Error: %.5g" % errorSMA)
print("ISMA RMS Error: %.5g" % errorISMA)
18 changes: 18 additions & 0 deletions docs/source/examples/hoburgabbeel_ex6_3_output.txt
@@ -0,0 +1,18 @@
MA fit from params
w = 0.0877784 * (u_1)**2.3499 * (u_2)**-1.86683
w = 0.824389 * (u_1)**2.02321 * (u_2)**-0.203195
w = 0.0175649 * (u_1)**2.84017 * (u_2)**-2.78935
w = 0.38541 * (u_1)**2.13119 * (u_2)**-0.826143
SMA fit from params
w**2.22467 = 5.42035e-05 * (u_1)**5.24451 * (u_2)**-6.68343
+ 3.61239e-08 * (u_1)**9.613 * (u_2)**-9.4893
+ 1.07674e-05 * (u_1)**0.538839 * (u_2)**-6.12098
+ 1.0777 * (u_1)**4.43371 * (u_2)**0.0978425
ISMA fit from params
1 = (0.309986/w**0.309511) * (u_1)**0.6327 * (u_2)**-0.813931
+ (0.012176/w**0.67353) * (u_1)**2.61311 * (u_2)**-2.59033
+ (0.889774/w**0.242028) * (u_1)**0.485343 * (u_2)**-0.0942005
+ (1.00588/w**0.0753052) * (u_1)**0.149934 * (u_2)**0.0116639
MA RMS Error: 0.007382
SMA RMS Error: 0.00016261
ISMA RMS Error: 0.00017923
13 changes: 0 additions & 13 deletions gpfit/examples/ex61setup.py

This file was deleted.

14 changes: 0 additions & 14 deletions gpfit/examples/ex63.py

This file was deleted.

3 changes: 0 additions & 3 deletions gpfit/tests/run_tests.py
Expand Up @@ -17,9 +17,6 @@
from gpfit.tests import t_print_fit
TESTS += t_print_fit.TESTS

from gpfit.tests import t_ex6_3
TESTS += t_ex6_3.TESTS

from gpfit.tests import t_examples
TESTS += t_examples.TESTS

Expand Down
76 changes: 0 additions & 76 deletions gpfit/tests/t_ex6_3.py

This file was deleted.

6 changes: 6 additions & 0 deletions gpfit/tests/t_examples.py
Expand Up @@ -34,6 +34,12 @@ def test_hoburgabbeel_ex6_1(self, example):
self.assertTrue(example.errorSMA < 1e-4)
self.assertTrue(example.errorISMA < 1e-5)

def test_hoburgabbeel_ex6_3(self, example):
"""test_hoburgabbeel_ex6_3"""
self.assertTrue(example.errorMA < 1e-2)
self.assertTrue(example.errorSMA < 1e-3)
self.assertTrue(example.errorISMA < 1e-3)


FILE_DIR = os.path.dirname(os.path.realpath(__file__))
EXAMPLE_DIR = os.path.abspath(FILE_DIR + '../../../docs/source/examples')
Expand Down

0 comments on commit 6387927

Please sign in to comment.