Writing tests

Creating tests for Kelp.Net is incredibly simple. Each test that you author needs only a single Run function exposed. The rest is your logic as to how you want your network to operate. The general guidelines for your Run function would be:

  • Load data (real or simulated):
Real[][] trainData = new Real[N][];
Real[][] trainLabel = new Real[N][];

for (int i = 0; i < N; i++)
{
//Prepare Sin wave for one cycle
Real radian = -Math.PI + Math.PI * 2.0 * i / (N - 1);
trainData[i] = new[] { radian };
trainLabel[i] = new Real[] { Math.Sin(radian) };
}
  • Create your function stack:
FunctionStack nn = new FunctionStack(
new Linear(1, 4, name: "l1 Linear"),
new Tanh(name: "l1 Tanh"),
new Linear(4, 1, name: "l2 Linear")
);
  • Select your optimizer:
 nn.SetOptimizer(new SGD());
  • Train your data:
for (int i = 0; i < EPOCH; i++)
{
Real loss = 0;
for (int j = 0; j < N; j++)
{
//When training is executed in the network, an error is returned to the return value
loss += Trainer.Train(nn, trainData[j], trainLabel[j], new MeanSquaredError());
}
if (i % (EPOCH / 10) == 0)
{
RILogManager.Default?.SendDebug("loss:" + loss / N);
RILogManager.Default?.SendDebug("");
}
}
  • Test your data:
            RILogManager.Default?.SendDebug("Test Start...");
foreach (Real[] val in trainData)
{
RILogManager.Default?.SendDebug(val[0] + ":" + nn.Predict(val)[0].Data[0]);
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset