---
title: "Fast Time Series Feature Extraction with minirocketR"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Fast Time Series Feature Extraction with minirocketR}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

## Introduction

`minirocketR` provides an optimized R implementation of the **MiniRocket** time series feature extraction algorithm (Dempster et al., 2021). Built with a native C++ core via `Rcpp` and accelerated with OpenMP multithreading, it generates $9,996$ Proportion of Positive Values (PPV) features per time series while maintaining exact mathematical parity with the Python reference implementation (`sktime`).

## Getting Started

Load the package and generate synthetic time series data (where rows represent $N$ time series instances and columns represent time points $L$):

```{r setup}
library(minirocketR)

# Generate synthetic data: 50 training series, 20 test series, length 100
set.seed(42)
N_train <- 50
N_test  <- 20
L       <- 100

X_train <- matrix(rnorm(N_train * L), nrow = N_train, ncol = L)
X_test  <- matrix(rnorm(N_test * L),  nrow = N_test,  ncol = L)
```

## Fitting the Transformer

Fit the `minirocket` model on the training data. This step samples dilation values, generates golden-ratio quasi-random quantiles, and calibrates feature biases using single-series convolutions:

```{r fit}
model <- minirocket_fit(X_train, num_features = 10000, seed = 42)
```

## Extracting Features

Apply the fitted transformer to both training and test matrices. You can configure the `num_threads` argument to leverage multi-core CPU acceleration (requires OpenMP support):

```{r transform}
# Transform the time series into the feature space
X_train_feat <- minirocket_transform(model, X_train, num_threads = 2)
X_test_feat  <- minirocket_transform(model, X_test,  num_threads = 2)

# Verify the dimensions of the output feature matrices
dim(X_train_feat)
dim(X_test_feat)
```

Both outputs produce matrices with $9,996$ columns bounded strictly in the range $[0, 1]$. These standardized features are now ready to be fed into downstream classification or regression models, such as Ridge Regression (e.g., via the `glmnet` package) or XGBoost.

## References

Dempster, A., Petitjean, F., & Webb, G. I. (2021). *MINIROCKET: A Very Fast (Almost) Deterministic Transform for Time Series Classification*. Data Mining and Knowledge Discovery, 35(5), 2154–2177.
