UnivariateTimeTypeToContinuous returns negative / wrong values for Time data when min_dt + step wraps past midnight

Đang mở Phù hợp với người mới
#101 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Lĩnh vực
data

Hướng nghiên cứu

Bắt đầu với src/transformers/other_transformers/univariate_time_type_to_continuous.jl, nơi issue chỉ ra phép tính độ dài bước và nhánh xử lý thời điểm qua nửa đêm. Tái hiện lỗi với Time(13), Time(14) và Time(19) bằng bước mặc định, Hour(13) và Hour(36), sau đó kiểm tra các bài kiểm thử hiện có cho transformer này. Công việc hoàn tất khi mỗi phép biến đổi trả về các giá trị không âm như mong đợi, được tính theo bước tương ứng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

UnivariateTimeTypeToContinuous gives wrong results, including negative values, for Dates.Time input whenever min_dt + step wraps past midnight. With the default step = Hour(24), that happens as soon as the earliest time in the training data is at or after 12:00.

Minimal example
using MLJBase, MLJTransforms, Dates

fitt(model, X) = (m = machine(model, X); fit!(m, verbosity=0); m)

X1 = [Time(9),  Time(10), Time(15)]
X2 = [Time(13), Time(14), Time(19)]

transform(fitt(UnivariateTimeTypeToContinuous(), X1), X1)
# [0.0, 0.041666666666666664, 0.25]      (correct: 1/24, 6/24)

transform(fitt(UnivariateTimeTypeToContinuous(), X2), X2)
# [-0.0, -0.041666666666666664, -0.25]   (expected [0.0, 1/24, 6/24])

transform(fitt(UnivariateTimeTypeToContinuous(step=Hour(13)), X2), X2)
# [-0.0, -0.0909..., -0.5454...]         (expected [0.0, 1/13, 6/13] ≈ [0.0, 0.0769, 0.4615])

transform(fitt(UnivariateTimeTypeToContinuous(step=Hour(36)), X2), X2)
# [-0.0, -0.0833..., -0.5]               (expected [0.0, 1/36, 6/36])

transform(fitt(UnivariateTimeTypeToContinuous(step=Hour(1)), X2), X2)
# [0.0, 1.0, 6.0]                        (correct, because there's no wrap-around)

I ran this on MLJTransforms 0.2.3 with MLJBase 1.15.0 and Julia 1.13.3. The output above is copied from that session.

Cause

In src/transformers/other_transformers/univariate_time_type_to_continuous.jl, transform gets the step size from Dates.value(min_dt + step) - Dates.value(min_dt). In the next_time == min_dt branch it uses min_dt + Hour(12) instead. Time arithmetic wraps modulo 24 h, so:

  • with the default Hour(24) and min_dt ≥ 12:00, min_dt + Hour(12) wraps, delta comes out negative, and every output changes sign;
  • for any other step where min_dt + step crosses midnight (e.g. Hour(13) from 13:00, or any step longer than 24 h that isn't a multiple of 24 h), delta has the wrong magnitude and usually the wrong sign.

The same code is on dev (184aae1).

Expected

The output should be (X - min_dt) / step no matter what time of day min_dt is, i.e. [0, 1/24, 6/24] for X2 with the default step.

Possible fix (not tested)

For Time data the step length doesn't depend on min_dt, so the wrap-around branch can be skipped by computing the step length directly, e.g.

if min_dt isa Dates.Time
    delta = Float64(Dates.value(convert(Nanosecond, step)))
else
    delta = Float64(Dates.value(min_dt + step) - Dates.value(min_dt))
end

A regression test could fit on [Time(13), Time(14), Time(19)] with the default step, Hour(13) and Hour(36), and check the outputs are [0, 1, 6] ./ 24, ./ 13 and ./ 36.

Ngôn ngữ chính
Julia
Star
1
Fork
5
Merge trung bình
1 ngày 45 phút
Pull request đã merge (30 ngày)
8

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của JuliaAI/MLJTransforms.jl

Tất cả issue của JuliaAI/MLJTransforms.jl

Issue tương tự

Thêm issue về Julia

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.