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
/
Copy pathMulTransformer.cs
56 lines (49 loc) · 1.83 KB
/
MulTransformer.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
56
using RCNet.Extensions;
using System;
using System.Collections.Generic;
namespace RCNet.Neural.Data.Transformers
{
/// <summary>
/// Implements the transformer of values from two input fields. Multiplies the value of the first input field by the value from the second input field.
/// </summary>
[Serializable]
public class MulTransformer : ITransformer
{
//Attributes
private readonly int _xFieldIdx;
private readonly int _yFieldIdx;
private readonly MulTransformerSettings _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 MulTransformer(List<string> availableFieldNames, MulTransformerSettings cfg)
{
_cfg = (MulTransformerSettings)cfg.DeepClone();
_xFieldIdx = availableFieldNames.IndexOf(_cfg.XInputFieldName);
_yFieldIdx = availableFieldNames.IndexOf(_cfg.YInputFieldName);
return;
}
//Methods
/// <inheritdoc />
public void Reset()
{
return;
}
/// <inheritdoc />
public double Transform(double[] data)
{
if (double.IsNaN(data[_xFieldIdx]))
{
throw new InvalidOperationException($"Invalid data value at input field index {_xFieldIdx} (NaN).");
}
if (double.IsNaN(data[_yFieldIdx]))
{
throw new InvalidOperationException($"Invalid data value at input field index {_yFieldIdx} (NaN).");
}
return data[_xFieldIdx].Bound() * data[_yFieldIdx].Bound();
}
}//MulTransformer
}//Namespace