Re: Vectorflow noob

2017-08-11 Thread BitR via Digitalmars-d-learn

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 
result for simple additions.


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(2))
{
auto features = [uniform(0.0f, 100.0f), uniform(0.0f, 
100.0f)];

data ~= Obs(features.sum, features);
}

net.learn(data, "square", AdaGrad(epochs, learning_rate), 
verbose, cores);


auto val = net.predict([50.0f, 200.0f]);
val.writeln;
assert(fabs(250.0f - val[0]) < 0.1);
}


Re: Vectorflow noob

2017-08-11 Thread Michael via Digitalmars-d-learn

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.