Vectorflow noob
Jiyan via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Aug 10 12:10:05 PDT 2017
Hey,
wanted to the following simple thing with vectorflow:
I want to develop a simple MLP, which has 2 input neurons and one
output neuron.
The network should simply add the input values together, so [1,2]
predicts [3] i guess.
I started in a newbish way to build the following code:
import vectorflow;
struct Obs // The represeneted data
{
float label; // Did i get that right that label would be the
DESIRED output (3=1+2)
float []features; // The features are the input i guess, so
features = f.e. [1,2]
}
void main()
{
auto net = NeuralNet()
.stack(DenseData(2))
.stack(Linear(10)); // Is this the right way to construct
the Net?
// The training data
Obs []data;
data.length = 10;
import std.random;
import std.algorithm;
foreach(ref Obs n; data)
{
// The features are getting fille with random numbers between
0.5 and 5
// The label becomes the sum of feature[0] and feature[1]
n.features.length = 2;
n.features[0] = uniform(0.5, 5);
n.features[1] = uniform(0.5, 5);
n.label = n.features.sum;
writeln(n.features[0], " ", n.features[1], " ", n.label);
assert (n.label == n.features[0] + n.features[1]);
}
net.learn(data, "logistic", AdaGrad(10, 0.1, 500), true, 3);
auto val = net.predict(data[0]); // is this wrong?
val.writeln;
}
Thanks :)
More information about the Digitalmars-d-learn
mailing list