예제 #1
0
def test_f1f2(capsys):
    funcs.f1(3)
    funcs.f2(5)
    captureout, captureerr = capsys.readouterr()
    capturename = 'capturedstdout'
    fhd = open(capturename, 'w')
    fhd.write(captureout)
    fhd.close() # ensure that it has been saved
    assert filecmp.cmp(capturename, 'funcsexpected')
예제 #2
0
def drawline(dataSet, realDataSet, setnum, dim=3):
    x = dataSet[0]
    y = dataSet[1]

    pmse = cmaUser(dataSet, funcs.mse1, dim)
    pmpe = cmaUser(dataSet, funcs.mpe1, dim)
    pmae = cmaUser(dataSet, funcs.mae1, dim)
    print "------------pmse:%s pmpe:%s pmae:%s---------" % (pmse, pmpe, pmae)
    if (setnum < 3):
        ymse = list(map(funcs.f1(pmse), x))
        ympe = list(map(funcs.f1(pmpe), x))
        ymae = list(map(funcs.f1(pmae), x))
    else:
        ymse = list(map(funcs.f2(pmse), x))
        ympe = list(map(funcs.f2(pmpe), x))
        ymae = list(map(funcs.f2(pmae), x))

    plt.plot(realDataSet[0],
             realDataSet[1],
             c="black",
             lw=3,
             ls="-",
             alpha=0.6,
             label="real")
    plt.plot(x, ymse, c="red", lw=2, ls="-", alpha=0.5, label="mse")
    plt.plot(x, ympe, c="green", lw=2, ls="-", alpha=0.5, label="mpe")
    plt.plot(x, ymae, c="blue", lw=2, ls="-", alpha=0.5, label="mae")
    plt.scatter(x, y, alpha=0.3, marker=u'o', s=5, c=u'b')
    plt.legend(loc='best')
    if setnum > 2:
        plt.xlim(-2, 20)
        plt.ylim(-100, 1000)
    else:
        plt.xlim(-2, 25)
        plt.ylim(-50, 1000)
    plt.xlabel('x')
    plt.ylabel('y')
    plt.title('fitting of set %s' % setnum)
예제 #3
0
	def test_f2(self):
		f=funcs.f2([1,1])
		self.assertEquals(f(0),0)
예제 #4
0
x3.sort()
x4=np.linspace(0,20,150)
x5=np.hstack((np.random.exponential(5,300),x4))
x5.sort()
x6=np.hstack((np.random.exponential(1,300),x4))
x6.sort()

dataSet=[]
p1=[2,1,0]  #多项式函数参数
p2=[0.5,2]	#指数函数参数
y1=list(map(funcs.f11(p1),x1))
dataSet.append([x1,y1])
y2=list(map(funcs.f11(p1),x2))
dataSet.append([x2,y2])
y3=list(map(funcs.f11(p1),x3))
dataSet.append([x3,y3])
y4=list(map(funcs.f21(p2),x4))
dataSet.append([x4,y4])
y5=list(map(funcs.f21(p2),x5))
dataSet.append([x5,y5])
y6=list(map(funcs.f21(p2),x6))
dataSet.append([x6,y6])

realDataSet=[]
y1r=list(map(funcs.f1(p1),x1))
realDataSet.append([x1,y1r])
y2r=list(map(funcs.f2(p2),x4))
realDataSet.append([x4,y2r])


예제 #5
0
def test_f1f2():
    funcs.f1(3)
    funcs.f2(5)