-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskErrStatBase.cs
149 lines (131 loc) · 5.13 KB
/
TaskErrStatBase.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using EasyMLCore.Extensions;
using System;
using System.Collections.Generic;
namespace EasyMLCore.Data
{
/// <summary>
/// Base class for task output features error statistics.
/// </summary>
[Serializable]
public abstract class TaskErrStatBase : SerializableObject
{
//Attribute properties
/// <summary>
/// Names of output features in this statistics.
/// </summary>
public List<string> OutputFeatureNames { get; }
//Constructors
/// <summary>
/// Base constructor.
/// </summary>
/// <param name="outputFeatureNames">Names of output features in this statistics.</param>
protected TaskErrStatBase(IEnumerable<string> outputFeatureNames)
{
OutputFeatureNames = new List<string>(outputFeatureNames);
return;
}
/// <summary>
/// Copy constructor.
/// </summary>
/// <param name="source">The source instance.</param>
protected TaskErrStatBase(TaskErrStatBase source)
{
OutputFeatureNames = new List<string>(source.OutputFeatureNames);
return;
}
//Properties
/// <summary>
/// Number of output features in this statistics.
/// </summary>
public int NumOfOutputFeatures { get { return OutputFeatureNames.Count; } }
/// <summary>
/// Gets number of samples.
/// </summary>
public virtual int NumOfSamples { get { throw new NotImplementedException(); } }
//Static methods
protected static double ComputeLogLoss(double computedValue, double idealValue)
{
if (idealValue >= Common.BinDecisionBorder)
{
return -Math.Log(computedValue.Bound(Common.Epsilon, 1d - Common.Epsilon));
}
else
{
return -Math.Log(1d - computedValue.Bound(Common.Epsilon, 1d - Common.Epsilon));
}
}
//Methods
/// <summary>
/// Merges another statistics with this statistics.
/// </summary>
/// <param name="source">Another statistics.</param>
public abstract void Merge(TaskErrStatBase source);
/// <summary>
/// Merges other statistics with this statistics.
/// </summary>
/// <param name="sources">Other statistics.</param>
public void Merge(IEnumerable<TaskErrStatBase> sources)
{
foreach (TaskErrStatBase source in sources)
{
Merge(source);
}
return;
}
/// <summary>
/// Updates statistics.
/// </summary>
/// <param name="computedValue">Computed value.</param>
/// <param name="idealValue">Corresponding ideal value.</param>
public abstract void Update(double computedValue, double idealValue);
/// <summary>
/// Updates the statistics.
/// </summary>
/// <param name="computedVector">The vector of computed values.</param>
/// <param name="idealVector">The vector of corresponding ideal values.</param>
public virtual void Update(double[] computedVector,
double[] idealVector
)
{
for(int i = 0; i < computedVector.Length; i++)
{
Update(computedVector[i], idealVector[i]);
}
return;
}
/// <summary>
/// Updates the statistics.
/// </summary>
/// <param name="computedVectorCollection">The collection of computed vectors.</param>
/// <param name="idealVectorCollection">The collection of ideal vectors.</param>
public void Update(IEnumerable<double[]> computedVectorCollection,
IEnumerable<double[]> idealVectorCollection
)
{
IEnumerator<double[]> idealVectorEnumerator = idealVectorCollection.GetEnumerator();
foreach (double[] computedVector in computedVectorCollection)
{
idealVectorEnumerator.MoveNext();
double[] idealVector = idealVectorEnumerator.Current;
Update(computedVector, idealVector);
}
return;
}
/// <summary>
/// Decides whether another error stat is better than this stat.
/// </summary>
/// <param name="other">Other stat to be compared with this statistics.</param>
/// <returns>True if another error stat is better than this stat.</returns>
public abstract bool IsBetter(TaskErrStatBase other);
/// <summary>
/// Creates the deep copy instance.
/// </summary>
public abstract TaskErrStatBase DeepClone();
/// <summary>
/// Gets text containing the results report.
/// </summary>
/// <param name="detail">Specifies whether to report details if available.</param>
/// <param name="margin">Specifies left margin.</param>
public abstract string GetReportText(bool detail = false, int margin = 0);
}//TaskErrStatBase
}//Namespace