Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Client.Engine
- {
- /// <summary>
- /// Класс описывает модель решения
- /// </summary>
- [Serializable]
- class Combination : IEquatable<Combination>, IComparable
- {
- public SortedSet<Variable> Variables { get; set; }
- public double MeanError { get; private set; }
- public double[] A { get; private set; }
- public Combination()
- {
- Variables = new SortedSet<Variable>();
- MeanError = double.NaN;
- }
- /// <summary>
- /// Подсчет среднеквадратической ошибки
- /// </summary>
- /// <param name="x">Выборочные значения X</param>
- /// <param name="y">Значения Y</param>
- /// <param name="a">Тестовые значения A, начиная с a0</param>
- /// <returns>Успешность выполнения функции</returns>
- public bool Test(double[][] x, double[] y, double[] a)
- {
- if (a.Length != (Variables.Count + 1) || x.Length != y.Length)
- return false;
- A = a;
- MeanError = 0;
- for (var k0 = 0; k0 < x.Length; k0++)
- {
- var ty = a[0];
- for (var k1 = 1; k1 < a.Length; k1++)
- {
- ty += x[k0][k1 - 1]*a[k1];
- }
- MeanError += Math.Pow(y[k0] - ty, 2.0);
- }
- return true;
- }
- public override bool Equals(object obj)
- {
- return Equals(obj as Combination);
- }
- bool IEquatable<Combination>.Equals(Combination other)
- {
- return Equals(other);
- }
- public bool Equals(Combination other)
- {
- if (Variables.Count != other.Variables.Count)
- return false;
- for (var i = 0; i < Variables.Count; i++)
- {
- if (!Variables.ElementAt(i).Equals(other.Variables.ElementAt(i)))
- return false;
- }
- return true;
- }
- public int CompareTo(object obj)
- {
- return CompareTo(obj as Combination);
- }
- public int CompareTo(Combination obj)
- {
- if (Equals(obj))
- return 0;
- return Variables.Count < obj.Variables.Count ? -1 : 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement