Skip to content

Implement AI-Based Anomaly Detection for Astronomical Data in Stingray.jl #40

@youssefnabil2030

Description

@youssefnabil2030

Issue Description:
Currently, Stingray.jl lacks an automated mechanism to detect anomalies in astronomical time series data. This feature would be useful for identifying rare astrophysical events, such as unexpected X-ray bursts or irregular pulsar behavior.

Adding machine learning-based anomaly detection would enhance the software’s capabilities by automating the detection of unusual patterns in light curves.

Proposed Solution:
Integrate an Autoencoder-based anomaly detection model using Flux.jl.

Train the model on historical astronomical datasets to learn normal patterns.

Flag outliers that deviate significantly from expected behavior.

using Flux, Random

Simulated Light Curve Data (10 features)

X_train = rand(100, 10) # Training data
X_test = rand(10, 10) # Test data with potential anomalies

Define Autoencoder Model

encoder = Chain(Dense(10, 5, relu), Dense(5, 2, relu))
decoder = Chain(Dense(2, 5, relu), Dense(5, 10, relu))
autoencoder = Chain(encoder, decoder)

Loss Function (Mean Squared Error)

loss(x) = Flux.mse(autoencoder(x), x)

Training Process

opt = Flux.ADAM(0.01)
for epoch in 1:100
Flux.train!(loss, Flux.params(autoencoder), [(X_train,)], opt)
end

Test the model

reconstructed = autoencoder(X_test)
anomaly_scores = sum(abs.(X_test .- reconstructed), dims=2) # Compute anomaly scores

Flag anomalies based on threshold

threshold = quantile(anomaly_scores, 0.95)
anomalies = anomaly_scores .> threshold

println("Anomalies detected: ", anomalies)

Next Steps:
Refine the model using real astrophysical data from NASA HEASARC.

Implement visualization tools to highlight detected anomalies.

Optimize for efficiency in large datasets.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions