-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConcreteTypeIrisDataSet.cs
148 lines (138 loc) · 5.43 KB
/
ConcreteTypeIrisDataSet.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
using LinearAlgebra;
using MathVectorCharts.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MathVectorCharts
{
public class ConcreteTypeIrisDataSet
{
/// <summary>
/// Список ирисов ОДНОГО типа
/// </summary>
private List<Iris> _irises;
/// <summary>
/// Конструкор
/// </summary>
/// <param name="type">Тип ириса</param>
public ConcreteTypeIrisDataSet(string type)
{
_irises = new List<Iris>();
Type = type;
}
/// <summary>
/// Авто-свойство для типа ириса
/// </summary>
public string Type { get; set; }
/// <summary>
/// Свойство для получения списка ирисов
/// </summary>
public List<Iris> Irises
{
get { return _irises; }
}
/// <summary>
/// Метод для добавления ириса в дата-сет
/// </summary>
/// <param name="iris"></param>
public void Add(Iris iris)
{
_irises.Add(iris);
}
/// <summary>
/// Метод для вычисления усредненного вектора
/// </summary>
/// <returns>Усредненный математический вектор</returns>
public MathVector ArithmeticMeanVector()
{
IMathVector arithmeticMeansVector;
// Если список ирисов пуст, бросаем исключение
if (_irises.Any())
{
arithmeticMeansVector = new MathVector(_irises.ElementAt(0).VectorParams);
}
else
{
throw new ImpossibleCalculateMeanVectorException();
}
try
{
foreach (Iris iris in _irises)
{
arithmeticMeansVector = (arithmeticMeansVector as MathVector) + iris.VectorParams;
}
arithmeticMeansVector = (arithmeticMeansVector as MathVector) / _irises.Count;
}
// Если при вычислении усредненного вектора возникает исключительная ситуация (например, обращение к несуществующему индексу вектора), бросаем свое исключение
catch
{
throw new ImpossibleCalculateMeanVectorException();
}
return (arithmeticMeansVector as MathVector);
}
/// <summary>
/// Метод для вычисления среднего арифмитического значения по определенному столбцу списка векторов
/// </summary>
/// <param name="indexColumn">Индекс столбца. Нумерация с нуля</param>
/// <returns>Среднее арифмитическое значение</returns>
public double ArithmeticMeanOfColumn(int indexColumn)
{
// Если ирисов в списке нет, бросаем исключение
if (!_irises.Any())
{
throw new ImpossibleCalculateMeanValueOfColumn();
}
double sum = 0;
int counter = 0;
try
{
foreach (Iris iris in _irises)
{
sum += iris.VectorParams[indexColumn];
counter++;
}
}
// Если при вычислении усредненного вектора возникает исключительная ситуация (например, обращение к несуществующему индексу вектора), бросаем свое исключение
catch
{
throw new ImpossibleCalculateMeanValueOfColumn();
}
return sum / counter;
}
public double ArithmeticMeanSepalLength()
{
return ArithmeticMeanOfColumn(0);
}
public double ArithmeticMeanSepalWidth()
{
return ArithmeticMeanOfColumn(1);
}
public double ArithmeticMeanPetalLength()
{
return ArithmeticMeanOfColumn(2);
}
public double ArithmeticMeanPetalWidth()
{
return ArithmeticMeanOfColumn(3);
}
public override string ToString()
{
string result = "";
result += "-------------------------------------------------------------\n";
result += $"TYPE: {Type.ToUpper()}\n";
result += $"ArithmeticMeanSepalLength: {ArithmeticMeanSepalLength()}\n";
result += $"ArithmeticMeanSepalWidth: {ArithmeticMeanSepalWidth()}\n";
result += $"ArithmeticMeanPetalLength: {ArithmeticMeanPetalLength()}\n";
result += $"ArithmeticMeanPetalWidth: {ArithmeticMeanPetalWidth()}\n";
foreach (var iris in _irises)
{
result += iris;
result += '\n';
}
result += "-------------------------------------------------------------\n";
return result;
}
}
}