digitalmars.D.learn - Vectorflow noob

• Jiyan (51/51) Aug 10 2017 Hey,
• Michael (6/9) Aug 11 2017 I'm worried there might not be many on the forums who can help
• BitR (41/44) Aug 11 2017 You'll want to end your stack with your wanted output size (1 -
Jiyan <jiyan jiyan.info> writes:
```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]);
}

auto val = net.predict(data[0]); // is this wrong?
val.writeln;
}

Thanks :)
```
Aug 10 2017
Michael <michael toohuman.io> writes:
```On Thursday, 10 August 2017 at 19:10:05 UTC, Jiyan wrote:
Hey,
wanted to the following simple thing with vectorflow:

[...]

I'm worried there might not be many on the forums who can help
too much with vectorflow given how new it is. Maybe some in the
community are more familiar with neural nets and have played wit
vectorflow already, but I'm not sure. I hope somebody can drop in
to give you a hand.
```
Aug 11 2017
BitR <bitr bitsaw.com> writes:
```On Thursday, 10 August 2017 at 19:10:05 UTC, Jiyan wrote:
Hey,
wanted to the following simple thing with vectorflow:
...

You'll want to end your stack with your wanted output size (1 -
being the sum).
Training it with the "square" function seems to give the best

Hope you can use it:

import std.stdio;
import std.random;
import std.algorithm;
import std.range;
import std.math;

import vectorflow;

struct Obs
{
float label;
float[] features;
}

void main()
{
const
learning_rate = 0.01,
epochs = 200,
verbose = true,
cores = 3;
auto net = NeuralNet()
.stack(DenseData(2))
.stack(Linear(1));
net.initialize(0.1);

Obs [] data;
foreach(i; iota(20000))
{
auto features = [uniform(0.0f, 100.0f), uniform(0.0f,
100.0f)];
data ~= Obs(features.sum, features);
}