Подготовка к рефакторингу MLCore
This commit is contained in:
parent
84a039e631
commit
1eb7f69f7b
|
|
@ -15,7 +15,7 @@ internal static class RevisionClass
|
||||||
public const string Major = "3";
|
public const string Major = "3";
|
||||||
public const string Minor = "11";
|
public const string Minor = "11";
|
||||||
public const string Build = "1";
|
public const string Build = "1";
|
||||||
public const string Revision = "3826";
|
public const string Revision = "3827";
|
||||||
|
|
||||||
public const string MainVersion = Major + "." + Minor;
|
public const string MainVersion = Major + "." + Minor;
|
||||||
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;
|
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
%COREVERSION%=1
|
|
||||||
%REVISION%=3826
|
|
||||||
%MINOR%=11
|
%MINOR%=11
|
||||||
|
%REVISION%=3827
|
||||||
|
%COREVERSION%=1
|
||||||
%MAJOR%=3
|
%MAJOR%=3
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
3.11.1.3826
|
3.11.1.3827
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
!define VERSION '3.11.1.3826'
|
!define VERSION '3.11.1.3827'
|
||||||
|
|
|
||||||
|
|
@ -718,7 +718,7 @@ namespace VisualPascalABC
|
||||||
private NamedValue GetNullBasedArray(Value val)
|
private NamedValue GetNullBasedArray(Value val)
|
||||||
{
|
{
|
||||||
IList<FieldInfo> flds = val.Type.GetFields();
|
IList<FieldInfo> flds = val.Type.GetFields();
|
||||||
if (flds.Count != 3) return null;
|
//if (flds.Count != 3) return null;
|
||||||
foreach (FieldInfo fi in flds)
|
foreach (FieldInfo fi in flds)
|
||||||
if (fi.Name == "NullBasedArray") return fi.GetValue(val);
|
if (fi.Name == "NullBasedArray") return fi.GetValue(val);
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,9 @@ uses MLCoreABC;
|
||||||
uses LinearAlgebraML;
|
uses LinearAlgebraML;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
MatrixPipeline = class;
|
||||||
|
UMatrixPipeline = class;
|
||||||
|
|
||||||
{$region Activations}
|
{$region Activations}
|
||||||
/// Активационные функции для моделей
|
/// Активационные функции для моделей
|
||||||
Activations = static class
|
Activations = static class
|
||||||
|
|
@ -1790,6 +1793,15 @@ type
|
||||||
/// Возвращает сконструированный конвейер.
|
/// Возвращает сконструированный конвейер.
|
||||||
static function Build(params steps: array of IPipelineStep): MatrixPipeline;
|
static function Build(params steps: array of IPipelineStep): MatrixPipeline;
|
||||||
|
|
||||||
|
/// Строит supervised-конвейер для задачи классификации.
|
||||||
|
static function BuildClassification(params steps: array of IPipelineStep): MatrixPipeline;
|
||||||
|
|
||||||
|
/// Строит supervised-конвейер для задачи регрессии.
|
||||||
|
static function BuildRegression(params steps: array of IPipelineStep): MatrixPipeline;
|
||||||
|
|
||||||
|
/// Строит unsupervised-конвейер для задачи кластеризации.
|
||||||
|
static function BuildClustering(params steps: array of IPipelineStep): UMatrixPipeline;
|
||||||
|
|
||||||
/// Устанавливает или заменяет модель.
|
/// Устанавливает или заменяет модель.
|
||||||
function SetModel(m: ISupervisedModel): MatrixPipeline;
|
function SetModel(m: ISupervisedModel): MatrixPipeline;
|
||||||
|
|
||||||
|
|
@ -8479,6 +8491,24 @@ begin
|
||||||
Result := pipe;
|
Result := pipe;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function MatrixPipeline.BuildClassification(params steps: array of IPipelineStep): MatrixPipeline;
|
||||||
|
begin
|
||||||
|
var stepsCopy := Copy(steps);
|
||||||
|
Result := Build(stepsCopy);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function MatrixPipeline.BuildRegression(params steps: array of IPipelineStep): MatrixPipeline;
|
||||||
|
begin
|
||||||
|
var stepsCopy := Copy(steps);
|
||||||
|
Result := Build(stepsCopy);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function MatrixPipeline.BuildClustering(params steps: array of IPipelineStep): UMatrixPipeline;
|
||||||
|
begin
|
||||||
|
var stepsCopy := Copy(steps);
|
||||||
|
Result := UMatrixPipeline.Build(stepsCopy);
|
||||||
|
end;
|
||||||
|
|
||||||
function MatrixPipeline.Add(t: ITransformer): MatrixPipeline;
|
function MatrixPipeline.Add(t: ITransformer): MatrixPipeline;
|
||||||
begin
|
begin
|
||||||
if t = nil then
|
if t = nil then
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,12 @@ type
|
||||||
TaskKind = (tkRegression, tkClassification);
|
TaskKind = (tkRegression, tkClassification);
|
||||||
|
|
||||||
type
|
type
|
||||||
|
DataPipeline = class;
|
||||||
|
UDataPipeline = class;
|
||||||
|
ClassificationDataPipeline = class;
|
||||||
|
RegressionDataPipeline = class;
|
||||||
|
ClusteringDataPipeline = class;
|
||||||
|
|
||||||
PipelineBase = abstract class
|
PipelineBase = abstract class
|
||||||
protected
|
protected
|
||||||
fDataSteps: List<IPreprocessor>;
|
fDataSteps: List<IPreprocessor>;
|
||||||
|
|
@ -65,12 +71,11 @@ type
|
||||||
/// • target — целевая переменная.
|
/// • target — целевая переменная.
|
||||||
///
|
///
|
||||||
DataPipeline = class(PipelineBase, IModel)
|
DataPipeline = class(PipelineBase, IModel)
|
||||||
private
|
protected
|
||||||
fModel: ISupervisedModel;
|
fModel: ISupervisedModel;
|
||||||
fTask: TaskKind;
|
fTask: TaskKind;
|
||||||
fTarget: string;
|
fTarget: string;
|
||||||
|
|
||||||
protected
|
|
||||||
procedure ValidateSchema(df: DataFrame); override;
|
procedure ValidateSchema(df: DataFrame); override;
|
||||||
public
|
public
|
||||||
/// Создаёт пустой конвейер
|
/// Создаёт пустой конвейер
|
||||||
|
|
@ -97,6 +102,26 @@ type
|
||||||
params steps: array of IPipelineStep
|
params steps: array of IPipelineStep
|
||||||
): DataPipeline;
|
): DataPipeline;
|
||||||
|
|
||||||
|
/// Строит supervised-конвейер для задачи классификации.
|
||||||
|
static function BuildClassification(
|
||||||
|
target: string;
|
||||||
|
features: array of string;
|
||||||
|
params steps: array of IPipelineStep
|
||||||
|
): ClassificationDataPipeline;
|
||||||
|
|
||||||
|
/// Строит supervised-конвейер для задачи регрессии.
|
||||||
|
static function BuildRegression(
|
||||||
|
target: string;
|
||||||
|
features: array of string;
|
||||||
|
params steps: array of IPipelineStep
|
||||||
|
): RegressionDataPipeline;
|
||||||
|
|
||||||
|
/// Строит unsupervised-конвейер для задачи кластеризации.
|
||||||
|
static function BuildClustering(
|
||||||
|
features: array of string;
|
||||||
|
params steps: array of IPipelineStep
|
||||||
|
): ClusteringDataPipeline;
|
||||||
|
|
||||||
/// Строит только preprocessing-часть supervised-конвейера без модели.
|
/// Строит только preprocessing-часть supervised-конвейера без модели.
|
||||||
/// Модель затем можно присоединить методом WithModel
|
/// Модель затем можно присоединить методом WithModel
|
||||||
static function BuildPreprocessing(
|
static function BuildPreprocessing(
|
||||||
|
|
@ -160,6 +185,18 @@ type
|
||||||
function Clone: IModel;
|
function Clone: IModel;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
/// Конвейер DataFrame-предобработки и классификации.
|
||||||
|
/// Специализированный тип будет постепенно получать
|
||||||
|
/// собственный контракт Predict/PredictLabels.
|
||||||
|
ClassificationDataPipeline = class(DataPipeline)
|
||||||
|
end;
|
||||||
|
|
||||||
|
/// Конвейер DataFrame-предобработки и регрессии.
|
||||||
|
/// Специализированный тип будет постепенно получать
|
||||||
|
/// собственный контракт Predict.
|
||||||
|
RegressionDataPipeline = class(DataPipeline)
|
||||||
|
end;
|
||||||
|
|
||||||
/// UDataPipeline — конвейер подготовки данных и обучения модели без учителя на DataFrame.
|
/// UDataPipeline — конвейер подготовки данных и обучения модели без учителя на DataFrame.
|
||||||
///
|
///
|
||||||
/// Поддерживает два уровня шагов:
|
/// Поддерживает два уровня шагов:
|
||||||
|
|
@ -176,12 +213,11 @@ type
|
||||||
/// • features — признаки (целевая переменная отсутствует).
|
/// • features — признаки (целевая переменная отсутствует).
|
||||||
///
|
///
|
||||||
UDataPipeline = class(PipelineBase, IModel)
|
UDataPipeline = class(PipelineBase, IModel)
|
||||||
private
|
protected
|
||||||
fModel: IUnsupervisedModel;
|
fModel: IUnsupervisedModel;
|
||||||
|
|
||||||
procedure ValidateNumericFeatures(df: DataFrame);
|
procedure ValidateNumericFeatures(df: DataFrame);
|
||||||
function TransformToMatrix(df: DataFrame): Matrix;
|
function TransformToMatrix(df: DataFrame): Matrix;
|
||||||
protected
|
|
||||||
procedure ValidateSchema(df: DataFrame); override;
|
procedure ValidateSchema(df: DataFrame); override;
|
||||||
public
|
public
|
||||||
/// Создаёт пустой конвейер
|
/// Создаёт пустой конвейер
|
||||||
|
|
@ -248,6 +284,13 @@ type
|
||||||
function Clone: IModel;
|
function Clone: IModel;
|
||||||
|
|
||||||
function Name: string := Self.GetType.Name;
|
function Name: string := Self.GetType.Name;
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
/// Конвейер DataFrame-предобработки и кластеризации.
|
||||||
|
/// Специализированный тип будет постепенно получать
|
||||||
|
/// собственный контракт Predict.
|
||||||
|
ClusteringDataPipeline = class(UDataPipeline)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
@ -598,19 +641,17 @@ begin
|
||||||
if f = target then
|
if f = target then
|
||||||
ArgumentError(ER_DATAPIPE_TARGET_IN_FEATURES, target);
|
ArgumentError(ER_DATAPIPE_TARGET_IN_FEATURES, target);
|
||||||
|
|
||||||
if (steps = nil) or (Length(steps) = 0) then
|
if steps <> nil then
|
||||||
ArgumentError(ER_PIPELINE_NO_STEPS);
|
for var i := 0 to High(steps) do
|
||||||
|
begin
|
||||||
|
var step := steps[i];
|
||||||
|
|
||||||
for var i := 0 to High(steps) do
|
if step = nil then
|
||||||
begin
|
ArgumentError(ER_PIPELINE_STEP_NULL, i);
|
||||||
var step := steps[i];
|
|
||||||
|
|
||||||
if step = nil then
|
if step is ISupervisedModel then
|
||||||
ArgumentError(ER_PIPELINE_STEP_NULL, i);
|
ArgumentError(ER_PIPELINE_INVALID_STEP_ORDER);
|
||||||
|
end;
|
||||||
if step is ISupervisedModel then
|
|
||||||
ArgumentError(ER_PIPELINE_INVALID_STEP_ORDER);
|
|
||||||
end;
|
|
||||||
|
|
||||||
var p := new DataPipeline;
|
var p := new DataPipeline;
|
||||||
p.fTarget := target;
|
p.fTarget := target;
|
||||||
|
|
@ -674,6 +715,77 @@ begin
|
||||||
.WithModel(last as ISupervisedModel);
|
.WithModel(last as ISupervisedModel);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function DataPipeline.BuildClassification(
|
||||||
|
target: string;
|
||||||
|
features: array of string;
|
||||||
|
params steps: array of IPipelineStep
|
||||||
|
): ClassificationDataPipeline;
|
||||||
|
begin
|
||||||
|
ValidateFeatureList(features);
|
||||||
|
|
||||||
|
if (target = nil) or (target = '') then
|
||||||
|
ArgumentError(ER_TARGET_EMPTY);
|
||||||
|
|
||||||
|
foreach var f in features do
|
||||||
|
if f = target then
|
||||||
|
ArgumentError(ER_DATAPIPE_TARGET_IN_FEATURES, target);
|
||||||
|
|
||||||
|
var p := new ClassificationDataPipeline;
|
||||||
|
p.fTarget := target;
|
||||||
|
p.fFeatures := Copy(features);
|
||||||
|
p.fTask := TaskKind.tkClassification;
|
||||||
|
|
||||||
|
if steps <> nil then
|
||||||
|
for var i := 0 to High(steps) do
|
||||||
|
p.Add(steps[i]);
|
||||||
|
|
||||||
|
Result := p;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function DataPipeline.BuildRegression(
|
||||||
|
target: string;
|
||||||
|
features: array of string;
|
||||||
|
params steps: array of IPipelineStep
|
||||||
|
): RegressionDataPipeline;
|
||||||
|
begin
|
||||||
|
ValidateFeatureList(features);
|
||||||
|
|
||||||
|
if (target = nil) or (target = '') then
|
||||||
|
ArgumentError(ER_TARGET_EMPTY);
|
||||||
|
|
||||||
|
foreach var f in features do
|
||||||
|
if f = target then
|
||||||
|
ArgumentError(ER_DATAPIPE_TARGET_IN_FEATURES, target);
|
||||||
|
|
||||||
|
var p := new RegressionDataPipeline;
|
||||||
|
p.fTarget := target;
|
||||||
|
p.fFeatures := Copy(features);
|
||||||
|
p.fTask := TaskKind.tkRegression;
|
||||||
|
|
||||||
|
if steps <> nil then
|
||||||
|
for var i := 0 to High(steps) do
|
||||||
|
p.Add(steps[i]);
|
||||||
|
|
||||||
|
Result := p;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function DataPipeline.BuildClustering(
|
||||||
|
features: array of string;
|
||||||
|
params steps: array of IPipelineStep
|
||||||
|
): ClusteringDataPipeline;
|
||||||
|
begin
|
||||||
|
ValidateFeatureList(features);
|
||||||
|
|
||||||
|
var p := new ClusteringDataPipeline;
|
||||||
|
p.fFeatures := Copy(features);
|
||||||
|
|
||||||
|
if steps <> nil then
|
||||||
|
for var i := 0 to High(steps) do
|
||||||
|
p.Add(steps[i]);
|
||||||
|
|
||||||
|
Result := p;
|
||||||
|
end;
|
||||||
|
|
||||||
function DataPipeline.WithModel(model: ISupervisedModel): DataPipeline;
|
function DataPipeline.WithModel(model: ISupervisedModel): DataPipeline;
|
||||||
begin
|
begin
|
||||||
if model = nil then
|
if model = nil then
|
||||||
|
|
@ -1005,25 +1117,24 @@ class function UDataPipeline.BuildPreprocessing(features: array of string;
|
||||||
begin
|
begin
|
||||||
ValidateFeatureList(features);
|
ValidateFeatureList(features);
|
||||||
|
|
||||||
if (steps = nil) or (Length(steps) = 0) then
|
if steps <> nil then
|
||||||
ArgumentError(ER_PIPELINE_NO_STEPS);
|
for var i := 0 to High(steps) do
|
||||||
|
begin
|
||||||
|
var step := steps[i];
|
||||||
|
|
||||||
for var i := 0 to High(steps) do
|
if step = nil then
|
||||||
begin
|
ArgumentError(ER_PIPELINE_STEP_NULL, i);
|
||||||
var step := steps[i];
|
|
||||||
|
|
||||||
if step = nil then
|
if step is IUnsupervisedModel then
|
||||||
ArgumentError(ER_PIPELINE_STEP_NULL, i);
|
ArgumentError(ER_PIPELINE_INVALID_STEP_ORDER);
|
||||||
|
end;
|
||||||
if step is IUnsupervisedModel then
|
|
||||||
ArgumentError(ER_PIPELINE_INVALID_STEP_ORDER);
|
|
||||||
end;
|
|
||||||
|
|
||||||
var p := new UDataPipeline;
|
var p := new UDataPipeline;
|
||||||
p.fFeatures := Copy(features);
|
p.fFeatures := Copy(features);
|
||||||
|
|
||||||
for var i := 0 to High(steps) do
|
if steps <> nil then
|
||||||
p.Add(steps[i]);
|
for var i := 0 to High(steps) do
|
||||||
|
p.Add(steps[i]);
|
||||||
|
|
||||||
Result := p;
|
Result := p;
|
||||||
end;
|
end;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue