# Wolfram 语言™

## 学习一个流形的参数化

In[1]:=
```manifold = Table[AngleVector[{x, 0.9 Pi x}] + x/20*RandomVariate[NormalDistribution[], 2], {x, 0, 1, 0.001}]; plot = ListPlot[manifold, PlotStyle -> Orange]```
Out[1]=

In[2]:=
`net = NetChain[{25, Ramp, 1, 25, Ramp, 2}, "Input" -> 2]`
Out[2]=

In[3]:=
```lossNet = NetGraph[{net, MeanSquaredLossLayer[]}, {1 -> 2, NetPort["Input"] -> NetPort[2, "Target"]}]```
Out[3]=

In[4]:=
```lossNet = NetTrain[lossNet, <|"Input" -> manifold|>, BatchSize -> 4096]; trained = NetExtract[lossNet, 1];```

In[5]:=
```{{xmin, xmax}, {ymin, ymax}} = CoordinateBounds[manifold, .2]; Show[plot, StreamPlot[ trained[{x, y}] - {x, y}, {x, xmin, xmax}, {y, ymin, ymax}]]```
Out[5]=

In[6]:=
```decoder = Drop[trained, 3] encoder = Take[trained, 3]```
Out[6]=
Out[6]=

In[7]:=
`ListPlot[Style[#, Hue[First[0.3 + encoder[#]]/3]] & /@ manifold]`
Out[7]=

In[8]:=
`{min, max} = MinMax[encoder[manifold]]`
Out[8]=

In[9]:=
`Show[plot, ListLinePlot[Table[decoder[x], {x, min, max, .01}]]]`
Out[9]=