0

I want to insert piecewise linear interpolation of the hyperbolic tangent into the neural network. An error occurs at the stage of training the network.

trainingData:

sampledata[sd_] := 
  RandomVariate[MultinormalDistribution[{0, 0}, sd*IdentityMatrix[2]],
    500];
clusters = Map[sampledata, {3, 1.5, 0.2}];
ListPlot[clusters, 
 PlotStyle -> 
  Map[Directive[#, PointSize[0.015]] &, {RGBColor[1, 0.21, 
     0.35000000000000003`], RGBColor[0.3, 0.78, 0.38], 
    RGBColor[0.46, 0.5700000000000001, 1]}], Axes -> None, 
 AspectRatio -> 1]
trainingData = 
  Join[Thread[clusters[[1]] -> Red], Thread[clusters[[2]] -> Green], 
   Thread[clusters[[3]] -> Blue]];
RandomSample[trainingData, 8]

Interpolation of hyperbolic tangent

ifun = Interpolation[Table[{x, Tanh[x]}, {x, -100, 100, 0.2}], 
  InterpolationOrder -> 1]
InterpolationToPiecewise[if_, x_] := 
  Module[{main, default, grid}, grid = if["Grid"];
    Piecewise[{if@"GetPolynomial"[#, x - #], x < First@#} & /@ 
      grid[[2 ;; -2]], if@"GetPolynomial"[#, x - #] &@grid[[-1]]]] /; 
   if["InterpolationMethod"] == "Hermite";

pwfun[x_] = InterpolationToPiecewise[ifun, x];

At the stage of creating the network, everything is fine.

net = NetChain[{30, ElementwiseLayer[pwfun], 20, 
   ElementwiseLayer[pwfun], 3, {SoftmaxLayer[]}}, "Input" -> {2}, 
  "Output" -> NetDecoder[{"Class", {Red, Green, Blue}}]]

But during training this is what happens.

trained = NetTrain[net, trainingData]

NetTrain::interr2: An unknown internal error occurred. Consult Internal`$LastInternalFailure for potential information.

Consult Internal`$LastInternalFailure
```
InvalidJSON
Non-JSON value:{{KeyAbsent,$Failed},{KeyAbsent,$Failed}}
Глеб
  • 11
  • 2

0 Answers0