131 lines
4.1 KiB
Common Lisp
131 lines
4.1 KiB
Common Lisp
//+------------------------------------------------------------------+
|
|
//| Scaler.cl |
|
|
//| Copyright 2025, Niquel Mendoza. |
|
|
//| https://www.mql5.com/es/users/nique_372/news |
|
|
//+------------------------------------------------------------------+
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Definiciones generales |
|
|
//+------------------------------------------------------------------+
|
|
//--- 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
|
|
|
|
#define MATRIX_IDX(row, col, cols) (((row)*(cols))+(col))
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
__kernel void standard_scaler_tranform_matrix(
|
|
__global const real_t* mean,
|
|
__global const real_t* std_inv,
|
|
__global real_t* matrix,
|
|
const uint cols,
|
|
const uint istart
|
|
)
|
|
{
|
|
//---
|
|
const uint row = get_global_id(0);
|
|
const uint col = get_global_id(1);
|
|
|
|
//--- final
|
|
const uint matrix_idx = MATRIX_IDX(row, istart + col, cols);
|
|
matrix[matrix_idx] = (matrix[matrix_idx] - mean[col]) * std_inv[col];
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
__kernel void standard_scaler_inverse_tranform_matrix(
|
|
__global const real_t* mean,
|
|
__global const real_t* std,
|
|
__global real_t* matrix,
|
|
const uint cols,
|
|
const uint istart
|
|
)
|
|
{
|
|
//2 dimensiones
|
|
const uint row = get_global_id(0);
|
|
const uint col = get_global_id(1);
|
|
|
|
const uint matrix_idx = MATRIX_IDX(row, istart + col, cols);
|
|
matrix[matrix_idx] = (matrix[matrix_idx] * std[col]) + mean[col];
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
__kernel void max_min_scaler_tranform_matrix(
|
|
__global const real_t* min_values,
|
|
__global const real_t* diff_inv,
|
|
__global real_t* matrix,
|
|
const uint cols,
|
|
const uint istart
|
|
)
|
|
{
|
|
//---
|
|
const uint row = get_global_id(0);
|
|
const uint col = get_global_id(1);
|
|
|
|
//--- final
|
|
const uint matrix_idx = MATRIX_IDX(row, istart + col, cols);
|
|
matrix[matrix_idx] = (matrix[matrix_idx] - min_values[col]) * diff_inv[col];
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
__kernel void max_min_scaler_inverse_tranform_matrix(
|
|
__global const real_t* min_values,
|
|
__global const real_t* diff,
|
|
__global real_t* matrix,
|
|
const uint cols,
|
|
const uint istart
|
|
)
|
|
{
|
|
//2 dimensiones
|
|
const uint row = get_global_id(0);
|
|
const uint col = get_global_id(1);
|
|
|
|
const uint matrix_idx = MATRIX_IDX(row, istart + col, cols);
|
|
matrix[matrix_idx] = (matrix[matrix_idx] * diff[col]) + min_values[col];
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
__kernel void robust_scaler_tranform_matrix(
|
|
__global const real_t* median,
|
|
__global const real_t* iqr_inv,
|
|
__global real_t* matrix,
|
|
const uint cols,
|
|
const uint istart
|
|
)
|
|
{
|
|
//---
|
|
const uint row = get_global_id(0);
|
|
const uint col = get_global_id(1);
|
|
|
|
//--- final
|
|
const uint matrix_idx = MATRIX_IDX(row, istart + col, cols);
|
|
matrix[matrix_idx] = (matrix[matrix_idx] - median[col]) * iqr_inv[col];
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
__kernel void robust_scaler_inverse_tranform_matrix(
|
|
__global const real_t* median,
|
|
__global const real_t* iqr,
|
|
__global real_t* matrix,
|
|
const uint cols,
|
|
const uint istart
|
|
)
|
|
{
|
|
//2 dimensiones
|
|
const uint row = get_global_id(0);
|
|
const uint col = get_global_id(1);
|
|
|
|
const uint matrix_idx = MATRIX_IDX(row, istart + col, cols);
|
|
matrix[matrix_idx] = (matrix[matrix_idx] * iqr[col]) + median[col];
|
|
}
|