ScalerByLeo/Src/Kernels/ScalerDbl.cl

133 lines
4.2 KiB
Common Lisp

2025-12-23 15:59:47 -05:00
//+------------------------------------------------------------------+
//| Scaler.cl |
//| Copyright 2025, Niquel Mendoza. |
//| https://www.mql5.com/es/users/nique_372/news |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Definiciones generales |
//+------------------------------------------------------------------+
2026-09-16 09:57:52 -05:00
#define USE_DOUBLE_PRECISION
2025-12-23 15:59:47 -05:00
2026-09-16 09:57:52 -05:00
//--- Activamos real_t
#ifdef USE_DOUBLE_PRECISION
typedef double real_t;
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
#define REAL_MAX REAL_MAX
#else
typedef float real_t;
#define REAL_MAX FLT_MAX
#endif
2025-12-23 15:59:47 -05:00
2026-09-16 09:57:52 -05:00
#define MATRIX_IDX(row, col, cols) (((row)*(cols))+(col))
2025-12-23 15:59:47 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
__kernel void standard_scaler_tranform_matrix(
2026-09-16 09:57:52 -05:00
__global const real_t* mean,
__global const real_t* std_inv,
__global real_t* matrix,
2026-09-16 18:51:57 -05:00
const uint cols,
const uint istart
2025-12-23 15:59:47 -05:00
)
{
2026-09-16 09:57:52 -05:00
//---
const uint row = get_global_id(0);
const uint col = get_global_id(1);
2025-12-23 15:59:47 -05:00
2026-09-16 09:57:52 -05:00
//--- final
2026-09-16 18:51:57 -05:00
const uint matrix_idx = MATRIX_IDX(row, istart + col, cols);
2026-09-16 09:57:52 -05:00
matrix[matrix_idx] = (matrix[matrix_idx] - mean[col]) * std_inv[col];
2025-12-23 15:59:47 -05:00
}
//+------------------------------------------------------------------+
__kernel void standard_scaler_inverse_tranform_matrix(
2026-09-16 09:57:52 -05:00
__global const real_t* mean,
__global const real_t* std,
__global real_t* matrix,
2026-09-16 18:51:57 -05:00
const uint cols,
const uint istart
2025-12-23 15:59:47 -05:00
)
{
//2 dimensiones
2026-09-16 09:57:52 -05:00
const uint row = get_global_id(0);
const uint col = get_global_id(1);
2025-12-23 15:59:47 -05:00
2026-09-16 18:51:57 -05:00
const uint matrix_idx = MATRIX_IDX(row, istart + col, cols);
2026-09-16 09:57:52 -05:00
matrix[matrix_idx] = (matrix[matrix_idx] * std[col]) + mean[col];
}
2025-12-23 15:59:47 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
__kernel void max_min_scaler_tranform_matrix(
2026-09-16 09:57:52 -05:00
__global const real_t* min_values,
__global const real_t* diff_inv,
__global real_t* matrix,
2026-09-16 18:51:57 -05:00
const uint cols,
const uint istart
2025-12-23 15:59:47 -05:00
)
{
2026-09-16 09:57:52 -05:00
//---
const uint row = get_global_id(0);
const uint col = get_global_id(1);
2025-12-23 15:59:47 -05:00
2026-09-16 09:57:52 -05:00
//--- final
2026-09-16 18:51:57 -05:00
const uint matrix_idx = MATRIX_IDX(row, istart + col, cols);
2026-09-16 09:57:52 -05:00
matrix[matrix_idx] = (matrix[matrix_idx] - min_values[col]) * diff_inv[col];
2025-12-23 15:59:47 -05:00
}
//+------------------------------------------------------------------+
2026-09-16 09:57:52 -05:00
__kernel void max_min_scaler_inverse_tranform_matrix(
__global const real_t* min_values,
__global const real_t* diff,
__global real_t* matrix,
2026-09-16 18:51:57 -05:00
const uint cols,
const uint istart
2025-12-23 15:59:47 -05:00
)
{
//2 dimensiones
2026-09-16 09:57:52 -05:00
const uint row = get_global_id(0);
const uint col = get_global_id(1);
2025-12-23 15:59:47 -05:00
2026-09-16 18:51:57 -05:00
const uint matrix_idx = MATRIX_IDX(row, istart + col, cols);
2026-09-16 09:57:52 -05:00
matrix[matrix_idx] = (matrix[matrix_idx] * diff[col]) + min_values[col];
2025-12-23 15:59:47 -05:00
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
2026-09-16 09:57:52 -05:00
__kernel void robust_scaler_tranform_matrix(
__global const real_t* median,
__global const real_t* iqr_inv,
__global real_t* matrix,
2026-09-16 18:51:57 -05:00
const uint cols,
const uint istart
2025-12-23 15:59:47 -05:00
)
{
2026-09-16 09:57:52 -05:00
//---
const uint row = get_global_id(0);
const uint col = get_global_id(1);
2025-12-23 15:59:47 -05:00
2026-09-16 09:57:52 -05:00
//--- final
2026-09-16 18:51:57 -05:00
const uint matrix_idx = MATRIX_IDX(row, istart + col, cols);
2026-09-16 09:57:52 -05:00
matrix[matrix_idx] = (matrix[matrix_idx] - median[col]) * iqr_inv[col];
2025-12-23 15:59:47 -05:00
}
//+------------------------------------------------------------------+
2026-09-16 09:57:52 -05:00
__kernel void robust_scaler_inverse_tranform_matrix(
__global const real_t* median,
__global const real_t* iqr,
__global real_t* matrix,
2026-09-16 18:51:57 -05:00
const uint cols,
const uint istart
2025-12-23 15:59:47 -05:00
)
{
2026-09-16 09:57:52 -05:00
//2 dimensiones
const uint row = get_global_id(0);
const uint col = get_global_id(1);
2025-12-23 15:59:47 -05:00
2026-09-16 18:51:57 -05:00
const uint matrix_idx = MATRIX_IDX(row, istart + col, cols);
2026-09-16 09:57:52 -05:00
matrix[matrix_idx] = (matrix[matrix_idx] * iqr[col]) + median[col];
2025-12-23 15:59:47 -05:00
}