예제 #1
0
Created on 2015��12��9��

@author: Rhapsody
'''

import numpy as np
import pylab as pl
import GeneData
import Calculate

def func(x):
    return np.sin(x * 2.0 * np.pi)

n = 10
m = 20
sqare = 0.1
x, y0 = GeneData.average(n, 0.0, 1.0, func)
y1 = np.random.normal(0, sqare, n) + y0
_w = Calculate.descent(x, y1, m, 100000, 0.01, Calculate.func_df)

w = list(_w[0])

print 'w =', w

pl.plot(x, y0, label='Pure')
pl.plot(x, y1, 'o', label='Impurity')
_x, _y = Calculate.showLine(0.0, 1.0, w)
pl.plot(np.array(_x), np.array(_y), label='Around')

pl.legend()
pl.show()