# Tasks

## Introduction

heartKIT provides several built-in __heart-monitoring__ tasks. Each task is designed to address a unique aspect such as ECG denoising, segmentation, and rhythm/beat classification. The tasks are designed to be modular and can be used independently or in combination to address specific use cases. In addition to the built-in tasks, custom tasks can be created by extending the [HKTask](https://ambiqai.github.io/heartkit/api/heartkit/tasks/task) base class and registering it with the task factory.

---

## Available Tasks

### [Signal Denoise](https://ambiqai.github.io/heartkit/tasks/denoise/)

[Signal denoise](https://ambiqai.github.io/heartkit/tasks/denoise/) is the process of removing noise from a physiological signal such as ECG. This task is useful for improving the quality of the signal and for further downstream tasks such as segmentation in which noise can interfere with the delineation of individual waves.

### [Signal Segmentation](https://ambiqai.github.io/heartkit/tasks/segmentation/)

[Signal segmentation](https://ambiqai.github.io/heartkit/tasks/segmentation/) is the process of delineating a signal into its constituent parts. In the context of ECG, segmentation refers to delineating the ECG signal into individual waves (e.g. P-wave, QRS, T-wave). This task is useful for extracting features (e.g. HRV) from the ECG signal and for further analysis such as rhythm classification.

### [Rhythm Classification](https://ambiqai.github.io/heartkit/tasks/rhythm/)

[Rhythm classification](https://ambiqai.github.io/heartkit/tasks/rhythm/) is the process of identifying abnormal heart rhythms, also known as arrhythmias, such as atrial fibrillation (AFIB) and atrial flutter (AFL) from ECG signals. Cardiovascular diseases such as AFIB are a leading cause of morbidity and mortality worldwide. Being able to remotely identify heart arrhtyhmias is important for early detection and intervention.

### [Beat Classification](https://ambiqai.github.io/heartkit/tasks/beat/)

[Beat classification](https://ambiqai.github.io/heartkit/tasks/beat/) is the process of identifying and classifying individual heart beats such as normal, premature, and escape beats from ECG signals. By identifying abnormal heart beats, it is possible to detect and monitor various heart conditions.

### [Bring-Your-Own-Task (BYOT)](https://ambiqai.github.io/heartkit/tasks/byot/)

[Bring-Your-Own-Task (BYOT)](https://ambiqai.github.io/heartkit/tasks/byot/) is a feature that allows users to create custom tasks by extending the [HKTask](https://ambiqai.github.io/heartkit/api/heartkit/tasks/task) base class and registering it with the `TaskFactory`. This feature is useful for addressing specific use cases that are not covered by the built-in tasks.

---

## Task Factory

The task factory, `TaskFactory`, provides a convenient way to access the built-in tasks. The factory is a thread-safe singleton class that provides a single point of access to the tasks via the tasks' slug names. The benefit of using the factory is it allows registering custom tasks that can then be used just like built-in tasks.

The dataset factory provides the following methods:

* **hk.TaskFactory.register**: Register a custom task
* **hk.TaskFactory.unregister**: Unregister a custom task
* **hk.TaskFactory.has**: Check if a task is registered
* **hk.TaskFactory.get**: Get a task
* **hk.TaskFactory.list**: List all available tasks

```py title="Python example" linenums="1"

import heartkit as hk

# Grab a rhythm task
task = hk.TaskFactory.get("rhythm")

task.train(hk.HKTrainParams(
    ...
))

```

---

## Choose a task

| Task | Purpose |
| --- | --- |
| [Signal denoising](https://ambiqai.github.io/heartkit/tasks/denoise/) | Remove noise from physiological signals. |
| [Signal segmentation](https://ambiqai.github.io/heartkit/tasks/segmentation/) | Delineate physiological signals into constituent parts. |
| [Rhythm classification](https://ambiqai.github.io/heartkit/tasks/rhythm/) | Identify rhythm-level arrhythmias such as AFIB and AFL. |
| [Beat classification](https://ambiqai.github.io/heartkit/tasks/beat/) | Identify premature and escape beats. |
| [Bring your own task](https://ambiqai.github.io/heartkit/tasks/byot/) | Create and register a custom task. |
