-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add Time Series Block #239
Changes from 2 commits
62e05d8
f34952d
dd57498
9117ac6
6d85a5d
d432f41
b4fffa1
972fa0c
4229f7e
c0cbc53
19b1af4
06e6b07
4ba57d9
aab2c1f
e543dc7
024bc58
371ae47
8b73ead
cd79590
234d3fc
a5236c8
9f84954
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,51 @@ | ||||||||||
""" | ||||||||||
TSPreprocessing() <: Encoding | ||||||||||
|
||||||||||
Encodes 'TimeSeriesRow's by normalizing the time-series values. The time-series can | ||||||||||
either be normalized by each variable or time-step. | ||||||||||
|
||||||||||
Encodes | ||||||||||
- 'TimeSeriesRow' -> 'TimeSeriesRow' | ||||||||||
""" | ||||||||||
|
||||||||||
struct TSPreprocessing <: Encoding | ||||||||||
tfms | ||||||||||
end | ||||||||||
|
||||||||||
function TSPreprocessing() | ||||||||||
base_tfms = [ | ||||||||||
] | ||||||||||
return TSPreprocessing(base_tfms) | ||||||||||
end | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What kind of transforms will be in here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently only Standardize, that's the only used in the tutorials. |
||||||||||
|
||||||||||
function encodedblock(p::TSPreprocessing, block::TimeSeriesRow) | ||||||||||
return block | ||||||||||
end | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the format of the time series is changed by the encoding, this should return a different block There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No the format won't be changed, as I discussed with Brian earlier that different models might require different formats and so the encoding shouldn't depend on the model. |
||||||||||
|
||||||||||
function encode(p::TSPreprocessing, context, block::TimeSeriesRow, obs) | ||||||||||
for tfm in values(p.tfms) | ||||||||||
obs = tfm(obs) | ||||||||||
end | ||||||||||
obs | ||||||||||
end | ||||||||||
|
||||||||||
function tsdatasetstats( | ||||||||||
data; | ||||||||||
by_var=false, | ||||||||||
by_step=false | ||||||||||
) | ||||||||||
drop_axes = [] | ||||||||||
if (by_var) | ||||||||||
append!(drop_axes,2) | ||||||||||
else | ||||||||||
append!(drop_axes,3) | ||||||||||
end | ||||||||||
axes = [ax for ax in [1, 2, 3] if !(ax in drop_axes)] | ||||||||||
codeboy5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
mean = Statistics.mean(data, dims=axes) | ||||||||||
std = Statistics.std(data, dims=axes) | ||||||||||
return mean, std | ||||||||||
end | ||||||||||
|
||||||||||
function setup(::Type{TSPreprocessing}, ::TimeSeriesRow, data) | ||||||||||
means, stds = tsdatasetstats(data) | ||||||||||
end | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
TSClassificationSingle(blocks[, data]) | ||
Learning task for single-label time-series classification. Samples are normalized and | ||
classified into of the 'classes'. | ||
""" | ||
function TSClassificationSingle( | ||
blocks::Tuple{<:TimeSeriesRow, <:Label}, | ||
data | ||
) | ||
return SupervisedTask( | ||
blocks, | ||
( | ||
OneHot() | ||
) | ||
) | ||
end | ||
|
||
_tasks["tsclfsingle"] = ( | ||
id = "timeseries/single", | ||
name = "Time-Series Classification (single-label)", | ||
constructor = TSClassificationSingle, | ||
blocks = (TimeSeriesRow, Label), | ||
category = "supervised", | ||
description = """ | ||
Time-Series classification task where every time-series has a single | ||
class label associated with it. | ||
""", | ||
package = @__MODULE__, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.