This repository was 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 pathExpTransformer.cs
50 lines (44 loc) · 1.56 KB
/
ExpTransformer.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
using RCNet.Extensions;
using System;
using System.Collections.Generic;
namespace RCNet.Neural.Data.Transformers
{
/// <summary>
/// Implements the transformer of values from one input field. Raises the fixed base (by default the Euler's number) to the power of the value from the input field.
/// </summary>
[Serializable]
public class ExpTransformer : ITransformer
{
//Attributes
private readonly int _fieldIdx;
private readonly ExpTransformerSettings _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 ExpTransformer(List<string> availableFieldNames, ExpTransformerSettings cfg)
{
_cfg = (ExpTransformerSettings)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();
return Math.Pow(_cfg.Base, arg).Bound();
}
}//ExpTransformer
}//Namespace