Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRU example #60

Open
BernhardGlueck opened this issue Nov 24, 2016 · 2 comments
Open

GRU example #60

BernhardGlueck opened this issue Nov 24, 2016 · 2 comments

Comments

@BernhardGlueck
Copy link

BernhardGlueck commented Nov 24, 2016

First, hats off for this great library, its so much better designed than Encog or Accord.Net ... and DotnetCore support jay !!

On to my question:

You recently added GRU support to the library, and i was wondering how to use it to do time series prediction ( I now the theory behind it etc, i am just wondering about how to use descriptors and generally the library to achieve this. )

Lets assume we have these classes ( i am using a simple, artifical example here, i know that this is not a good model, but it shows the principle )

class SensorReading
{
DateTime TimeStamp;
double Temperature
}

Let assume we have those readings in 1 minute intervals.
So we get lets say a List[SensorReading] with 1.000.000 entries.

Now usually i would apply a sliding window to this input so i get the following timeseries entities out of it: (

class SensorTimeSeries
{
IList[SensorReading] Input;
SensorReading Output;
}

So i get a List[SensorTimeSeries] out of the List[SensorReading] with lets say 5 Input data points and the corresponding output ( the 6th reading ) to predict and a total of 1.000.000 - 6 entries.

My question is now, how do i create a GRU model for this ? How to train and evaluate this lateron ?

To reiterate my training data would be List[SensorTimeSeries] with 999.994 entries each containing 5 readings as input and one as the to predicted label...

@bdschrisk
Copy link
Collaborator

bdschrisk commented Dec 8, 2016

Thanks @BernhardGlueck and apologies for the delay.

The GRU model is still being refined and further developed, so hold off using it for now. When ready, it'll have the same usage as the other models in the library - which is describing the data and fitting a model to it. The sliding window is automagically handled by the internal state representation of the GRU thus predicting on a new sample acts as a sliding window and updates the state for future predictions.

A GRU representation could look like this (untested):

public class SensorReading
{
public DateTime Date { get; set; }
public double Value { get; set; }

public SensorReading Next(IModel timeseriesModel)
{
	return timeseriesModel.Predict(this);
}
}

public void Main()
{
DateTime now = DateTime.Now;
var dataset = new {
	new SensorReading { Date = now, Value = 1 },
	new SensorReading { Date = now.AddMinutes(1), Value = 2 },
	new SensorReading { Date = now.AddMinutes(2), Value = 3 },
	new SensorReading { Date = now.AddMinutes(3), Value = 4 },
};

var descriptor = Descriptor.For<SensorReading>()
			   .WithDateTime(i => i.Date, DatePortion.Time)
			   .Learn(i => i.Value);

IModel timeseries = new GatedRecurrentGenerator()
                                     .Generate(descriptor, dataset);

SensorReading current = dataset.First();
while (true)
{
	current = current.Next(timeseries);
	Console.WriteLine($"{current.Date}\t={current.Value}");
            Thread.Sleep(TimeSpan.FromMinutes(1)); // :)
}
}

I'll post an update here when it's ready.

@BernhardGlueck
Copy link
Author

No apologies neccessary. Thank you for your detailed explanation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants