DateEncoder and example of timeOfDay usage

Hi, could you please tell me if the setting below is correct to encode Date input to Morning, Noon,Afternoon, Evening and night.
If it is not correct could you suggest a correct setting. I need this for anomaly detection for vital sign readings.

‘timeOfDay’: (21, 4)

or It should be ‘timeOfDay’: (4)

Please provide me with example of code.

1 Like

Here are the DateEncoder docs:

screen shot 2017-12-07 at 8 05 33 am

Let’s ignore the tuple option and just provide an integer for timeOfDay in the constructor, which means how long, in hours, the time window will be. The default is a 4-hour window, which gives you time periods like morning, afternoon, evening, early night, late night, etc.

The code will look different depending on what interface you are using. If you create the encoder directly, it would be:

de = DateEncoder(timeOfDay=(21, 4))

I got it now!, Thanks for your help. Regards.

I am now getting the error below

Exception: Width must be an odd number (4.000000)

Sorry, I gave you bad advice (I’ll correct it). I found a decent resource for this in this video and supplemental code.

import datetime
from nupic.encoders.date import DateEncoder

de = DateEncoder(timeOfDay=(21, 4))
now = datetime.datetime.strptime("2014-05-02 13:08:58", "%Y-%m-%d %H:%M:%S")
print de.encode(now)

Prints this:

[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

So these two lines are functionally equivalent:

de = DateEncoder(timeOfDay=(21, 4))
de = DateEncoder(timeOfDay=21)

You should experiment a bit if you want more or less resolution. Remember this will be combined with any other encodings you include in the input. These values are used as w and radius when creating a periodic scalar encoder to represent the time of day period: