This repository has been archived by the owner on May 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
CDivTransformer.cs
55 lines (48 loc) · 1.71 KB
/
CDivTransformer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using RCNet.Extensions;
using System;
using System.Collections.Generic;
namespace RCNet.Neural.Data.Transformers
{
/// <summary>
/// Implements the transformer of values from one input field. Divides the constant by the value from the input field.
/// </summary>
[Serializable]
public class CDivTransformer : ITransformer
{
//Attributes
private readonly int _fieldIdx;
private readonly CDivTransformerSettings _cfg;
//Constructor
/// <summary>
/// Creates an initialized instance.
/// </summary>
/// <param name="availableFieldNames">The collection of names of all available input fields.</param>
/// <param name="cfg">The configuration.</param>
public CDivTransformer(List<string> availableFieldNames, CDivTransformerSettings cfg)
{
_cfg = (CDivTransformerSettings)cfg.DeepClone();
_fieldIdx = availableFieldNames.IndexOf(_cfg.InputFieldName);
return;
}
//Methods
/// <inheritdoc/>
public void Reset()
{
return;
}
/// <inheritdoc/>
public double Transform(double[] data)
{
if (double.IsNaN(data[_fieldIdx]))
{
throw new InvalidOperationException($"Invalid data value at input field index {_fieldIdx} (NaN).");
}
double arg = data[_fieldIdx].Bound();
if (Math.Abs(arg) < DoubleExtensions.ReasonableAbsMin)
{
arg = arg < 0 ? -1d * DoubleExtensions.ReasonableAbsMin : DoubleExtensions.ReasonableAbsMin;
}
return (_cfg.C / arg).Bound();
}
}//CDivTransformer
}//Namespace