是否可以使用深度学习来近似三角函数?
我已使用此代码。它只给了我一条水平线(y = 0)。有什么办法可以使它像sin函数一样变化?
def f(x):
return sin(x)
t = arange(0.0, 1.0, 0.01)
y = f(t)
model=Sequential()
model.add(Dense(512,input_shape=(1,), activation='relu'))
model.add(Dense(256, activation='linear'))
model.add(Dense(128, activation='relu'))
model.add(Dense(64, activation='relu'))
model.add(Dense(32, activation='relu'))
model.add(Dense(16, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(4, activation='relu'))
model.add(Dense(1, activation='softplus'))
model.compile(optimizer='adam',
loss='mean_absolute_percentage_error',
metrics=['accuracy'])
model.fit(t,y, epochs=75000,batch_size=10)
def fit(t):
return model.predict(t)