-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskOutputDetailBase.cs
81 lines (72 loc) · 3.04 KB
/
TaskOutputDetailBase.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Globalization;
namespace EasyMLCore.Data
{
/// <summary>
/// Base class for task specific output details.
/// </summary>
[Serializable]
public abstract class TaskOutputDetailBase : SerializableObject
{
//Attribute properties
/// <summary>
/// Contains original data.
/// </summary>
public double[] RawData { get; }
/// <summary>
/// Contains mapped pairs Feature name - Feature raw value
/// </summary>
public List<Tuple<string, double>> MappedRawData { get; }
//Attributes
protected int _featureNameMaxLength;
protected int _dataValueIntegerPartMaxLength;
/// <summary>
/// Base constructor prepares RawData a MappedRawData.
/// </summary>
/// <param name="featureNames">Names of output features.</param>
/// <param name="rawData">Vector of corresponding values.</param>
protected TaskOutputDetailBase(List<string> featureNames, double[] rawData)
{
if(featureNames == null)
{
throw new ArgumentNullException(nameof(featureNames));
}
if (rawData == null)
{
throw new ArgumentNullException(nameof(rawData));
}
if(featureNames.Count == 0)
{
throw new ArgumentException("Feature names can not be empty.", nameof(featureNames));
}
if(featureNames.Count != rawData.Length)
{
throw new ArgumentException("Number of feature names does not correspond to length of raw data.", nameof(featureNames));
}
RawData = (double[])rawData.Clone();
MappedRawData = new List<Tuple<string, double>>(RawData.Length);
_featureNameMaxLength = 0;
_dataValueIntegerPartMaxLength = 0;
for (int i = 0; i < RawData.Length; i++)
{
int featureNameLength = featureNames[i].Length;
if(featureNameLength == 0)
{
throw new ArgumentException("Feature names contain one or more zero-length name(s).", nameof(featureNames));
}
_featureNameMaxLength = Math.Max(_featureNameMaxLength, featureNameLength);
int integerPartMaxLength = ((int)Math.Floor(RawData[i])).ToString(CultureInfo.InvariantCulture).Length;
_dataValueIntegerPartMaxLength = Math.Max(_dataValueIntegerPartMaxLength, integerPartMaxLength);
MappedRawData.Add(new Tuple<string, double>(featureNames[i], RawData[i]));
}
return;
}
/// <summary>
/// Gets formatted text describing an output.
/// </summary>
/// <param name="margin">Specifies left margin to be applied.</param>
/// <returns>Formatted text describing an output.</returns>
public abstract string GetTextInfo(int margin = 0);
}//TaskOutputDetailBase
}//Namespace