Topic: from a exercises in the book
To solve the following nonlinear programming problem:
Data input:,1,1 [1], the output target: 2
Data input: [1, 1], the output target: 1
Data input: [1, 2, 3], the output target: 3
The following is the code I wrote:
The import tensorflow as tf
The import numpy as np
RowCount=3
([xData=https://bbs.csdn.net/topics/np.array
,1,1 [1],
(1, 1],
[1, 2, 3]])
XTrainData,1,3 [2]=https://bbs.csdn.net/topics/
X=tf. Placeholder (dtype=tf. Float32)
YTrain=tf. Placeholder (dtype=tf. Float32)
W=tf. Variable (tf) zeros ([3]), dtype=tf. Float32)
B=tf. Variable (1, dtype=tf. Float32)
N=w * x
Y=tf. Reduce_sum (n) + b
Loss=tf. Abs (y - yTrain)
Optimizer=tf. Train. RMSPropOptimizer (0.001)
"Train"=optimizer. Minimize (loss)
Sess=tf. The Session ()
Sess. Run (tf) global_variables_initializer ())
For I in range (10000) :
For j in range (rowCount) :
Result=sess. Run ([" train ", x, w, b, yTrain, y, loss], feed_dict={x: xData [j], yTrain: xTrainData [j]})
Print (result)
Textbooks say is nonlinear problem, I write is linear, y=wx + b, but subject to implement nonlinear, with sigmoid cannot output 2,1,3 these values, is to be able to use other nonlinear activation function, (linear)???????
CodePudding user response:
Don't quite understand, just three samples to train a model? This is a matter of classification and regression problems, if it is a classification problem, suggest ask the Lord to see logistic regression of multiple classification problems, also with sigmoid function; If it is a regression problems, textbooks say is not linear, meaning is to use polynomial regression to solve?
CodePudding user response:
I think this is a nonlinear system of equations, but is not a classification problem, so don't use sigmoid function to classification,xData=https://bbs.csdn.net/topics/np.array ([[1, 1, 1],
(1, 0, 1],
[1, 2, 3]])
YTrainData=https://bbs.csdn.net/topics/np.array ([2, 1, 3])
X=tf. Placeholder (shape=[3], dtype=tf float32)
YTrain=tf. Placeholder (dtype=tf. Float32)
W=tf. Variable (tf) zeros ([3]), dtype=tf. Float32)
B=tf. Variable (1, dtype=tf. Float32)
N1=x * w
N2=tf. Reduce_sum (n1) - b
Y=n2
Loss=tf. Abs (y - yTrain)
Optimizer=tf. Train. RMSPropOptimizer (0.01)
"Train"=optimizer. Minimize (loss)
Sess=tf. The Session ()
Sess. Run (tf) global_variables_initializer ())
For I in range (1000) :
For j in range (3) :
Result=sess. Run ([" train ", x, yTrain, w, b, n2, loss], feed_dict={x: xData [j], yTrain: yTrainData [j]})
Print (result)