【Mathematica】用神经网络来拟合数据

 时间:2026-02-14 06:31:33

1、把非线性数据,转化为训练集:

data = Table[x -> Sin[10 x]*Exp[-x^2], {x, -3, 3, .1}]

训练集一定是个集合的元素的一一对应。

【Mathematica】用神经网络来拟合数据

2、可视化数据:

d0=Table[{x , Sin[10 x]*Exp[-x^2]}, {x, -3, 3, .1}];

ListLinePlot[d0,PlotRange->All]

【Mathematica】用神经网络来拟合数据

3、创建一个神经网络:

net = NetChain[{10, Ramp, 10, Tanh, 1}, "Input" -> "Scalar", "Output" -> "Scalar"];

里面有五个层。

【Mathematica】用神经网络来拟合数据

4、用训练集来训练这个网络:

tnet= NetTrain[net, data, MaxTrainingRounds -> Quantity[1, "Seconds"]];

训练10秒。

【Mathematica】用神经网络来拟合数据

5、可视化训练结果:

Show[ListLinePlot[d0,PlotStyle->Red,PlotRange->All],


Plot[tnet[x],{x,-3,3},PlotStyle->Green,PlotRange->All]]

【Mathematica】用神经网络来拟合数据

6、如果只训练1秒,结果会如何?

tnet= NetTrain[net, data, MaxTrainingRounds -> Quantity[1, "Seconds"]];

可以看到,拟合结果很差。

【Mathematica】用神经网络来拟合数据

7、下面是训练2秒的结果:

【Mathematica】用神经网络来拟合数据

8、训练20秒的结果:

tnet= NetTrain[net, data, MaxTrainingRounds -> Quantity[20, "Seconds"]];

【Mathematica】用神经网络来拟合数据

  • VS中如何设置加粗所选选项卡上的文本
  • Visual Studio Code怎么设置隐藏选项卡
  • js怎么判断事件是否绑定
  • Arduino初始化器列表声明中初始化数组编程解读
  • matlab中创建线条动画
  • 热门搜索
    尿道感染是怎么引起的 松露怎么吃 眼皮跳是怎么回事 机票怎么取 机油加多了会怎么样 东南大学怎么样 泰迪狗怎么养 银行卡的钱怎么转到支付宝 小辣椒手机怎么样 toilet怎么读