Пример #1
0
 def test_custom_opt(self):
     myPWLF = pwlf.piecewise_lin_fit(self.x_small,self.y_small)
     xGuess = np.array((0.9, 1.1))
     from scipy.optimize import minimize
     res = minimize(myPWLF.fitWithBreaksOpt, xGuess)
     print(res)
     self.assertTrue(np.isclose(res['fun'],0.0))
Пример #2
0
 def test_break_point_diff_x0_4(self):   
     # check if my duplicate is in a different location
     x0 = self.x_small.copy()
     my_fit6 = pwlf.piecewise_lin_fit(self.x_small,self.y_small)
     x0[2] = 1.4
     ssr6 = my_fit6.fitWithBreaks(x0)
     self.assertTrue(np.isclose(ssr6,0.0))
Пример #3
0
 def test_break_point_diff_x0_0(self):
     # check diff loc
     my_fit2 = pwlf.piecewise_lin_fit(self.x_small,self.y_small)
     x0 = self.x_small.copy()        
     x0[1] = 1.00001
     x0[2] = 1.50001
     ssr2 = my_fit2.fitWithBreaks(x0)
     self.assertTrue(np.isclose(ssr2,0.0))
Пример #4
0
    7.03872000e-03, 1.85494500e-02, 3.00926700e-02, 4.17617000e-02,
    5.37279600e-02, 6.54941000e-02, 7.68092100e-02, 8.76596300e-02,
    9.80525800e-02, 1.07961810e-01, 1.17305210e-01, 1.26063930e-01,
    1.34180360e-01, 1.41725010e-01, 1.48629710e-01, 1.55374770e-01,
    0.00000000e+00, 1.65610200e-02, 3.91016100e-02, 6.18679400e-02,
    8.30997400e-02, 1.02132890e-01, 1.19011260e-01, 1.34620080e-01,
    1.49429370e-01, 1.63539960e-01, -0.00000000e+00, 1.01980300e-02,
    3.28642800e-02, 5.59461900e-02, 7.81388400e-02, 9.84458400e-02,
    1.16270210e-01, 1.31279040e-01, 1.45437090e-01, 1.59627540e-01,
    0.00000000e+00, 1.63404300e-02, 4.00086000e-02, 6.34390200e-02,
    8.51085900e-02, 1.04787860e-01, 1.22120350e-01, 1.36931660e-01,
    1.50958760e-01, 1.65299640e-01, 1.79942720e-01
])

#   initialize piecwise linear fit with your x and y data
myPWLF = pwlf.piecewise_lin_fit(x, y)

#   initilize custom optimization
numberOfLineSegments = 3
myPWLF.useCustomOpt(numberOfLineSegments)

#   i have numberOfLineSegments - 1 number of variables
#   let's guess the correct location of the two unkown variables
#   (the program defualts to have end segments at x0= min(x) and xn=max(x)
xGuess = np.zeros(numberOfLineSegments - 1)
xGuess[0] = 0.02
xGuess[1] = 0.10

#   import custom optimization library
from scipy.optimize import minimize
res = minimize(myPWLF.fitWithBreaksOpt, xGuess)
import numpy as np
import pwlf

x = np.array((0.0, 1.0, 1.5, 2.0))
y = np.array((0.0, 1.0, 1.1, 1.5))

my_fit1 = pwlf.piecewise_lin_fit(x, y)
x0 = x.copy()
# check that I can fit when break poitns spot on a
ssr = my_fit1.fitWithBreaks(x0)

# check that i can fit when I slightly modify x0
my_fit2 = pwlf.piecewise_lin_fit(x, y)
x0[1] = 1.00001
x0[2] = 1.50001
ssr2 = my_fit2.fitWithBreaks(x0)

# check if my duplicate is in a different location
x0 = x.copy()
my_fit3 = pwlf.piecewise_lin_fit(x, y)
x0[1] = 0.9
ssr3 = my_fit3.fitWithBreaks(x0)

# check if my duplicate is in a different location
x0 = x.copy()
my_fit4 = pwlf.piecewise_lin_fit(x, y)
x0[1] = 1.1
ssr4 = my_fit4.fitWithBreaks(x0)

# check if my duplicate is in a different location
x0 = x.copy()
Пример #6
0
 def test_diff_evo(self):
     myPWLF = pwlf.piecewise_lin_fit(self.x_small,self.y_small)
     res = myPWLF.fit(4, disp=False)
     self.assertTrue(np.isclose(res[0],0.0))
Пример #7
0
 def test_break_point_spot_on(self):
     # check that I can fit when break poitns spot on a
     my_fit1 = pwlf.piecewise_lin_fit(self.x_small,self.y_small)
     x0 = self.x_small.copy()
     ssr = my_fit1.fitWithBreaks(x0)
     self.assertTrue(np.isclose(ssr,0.0))