/// <summary> /// Chebyshev norm for the given utility list. /// </summary> /// <param name="this">Utility list.</param> public static float Chebyshev(this ICollection <Utility> @this) { if (@this.Count == 0) { return(0.0f); } var wsum = @this.SumWeights(); if (CrMath.AeqZero(wsum)) { return(0.0f); } var vlist = new List <float>(@this.Count); foreach (var util in @this) { var v = util.Value * (util.Weight / wsum); vlist.Add(v); } var ret = vlist.Max <float>(); return(ret); }
/// <summary> /// Calculate the Chebyshev measure for the given set of elements. /// </summary> /// <param name="elements"></param> /// <returns></returns> public float Calculate(ICollection <Utility> elements) { var wsum = 0.0f; int count = elements.Count; if (count == 0) { return(0.0f); } foreach (var el in elements) { wsum += el.Weight; } if (CrMath.AeqZero(wsum)) { return(0.0f); } var vlist = new List <float>(count); foreach (var el in elements) { vlist.Add(el.Value * (el.Weight / wsum)); } var ret = vlist.Max <float>(); return(ret); }
/// <summary> /// Calculate the l-p weighted metrics measure for the given set of elements. /// </summary> /// <param name="elements"></param> /// <returns></returns> public float Calculate(ICollection <Utility> elements) { var count = elements.Count; if (count == 0) { return(0.0f); } var wsum = 0.0f; foreach (var el in elements) { wsum += el.Weight; } if (CrMath.AeqZero(wsum)) { return(0.0f); } var vlist = new List <float>(count); foreach (var el in elements) { var v = el.Weight / wsum * (float)Math.Pow(el.Value, _p); vlist.Add(v); } var sum = vlist.Sum(); var res = (float)Math.Pow(sum, _oneOverP); return(res); }
/// <summary> /// Returns true if the interval defined by @this is to the right of the interval defined /// by other and is adjacent, i.e. if other = [b, c] and @this = [c, d]. /// </summary> /// <returns><c>true</c>, if adjacent to the right, <c>false</c> otherwise.</returns> /// <param name="this">Value.</param> /// <param name="other">Other.</param> public static bool RightAdjacent(this Interval <float> @this, Interval <float> other) { if (CrMath.AeqB(@this.LowerBound, other.UpperBound) && @this.LowerBoundType == Closed && other.UpperBoundType == Closed) { return(true); } return(false); }
/// <summary> /// Rescales the given value to the interval [0,1]. If the value is smaller than min, it will be /// clamped to min and if the value is larger than max it will be clamped to max. /// WARNING: Never use this extension like this: 1.0.Normalize(min, max), since if the value is negative /// the sign (if there is one) will not be passed to the extension method leading to unexpected results. /// </summary> public static double Normalize01(this double @this, double min, double max) { @this = @this.Clamp <double>(min, max); @this = @this - min; var df = max - min; if (CrMath.AeqZero(df)) { throw new MinEqualMaxException(); } return(@this / df); }
/// <summary> /// Rescales the given value to the interval [0,1]. If the value is smaller than min, it will be /// clamped to min and if the value is larger than max it will be clamped to max. /// WARNING: Never use this extension like this: 1.0f.Normalize01(min, max), since if the value is negative /// the sign (if there is one) will not be passed to the extension method leading to unexpected results. /// </summary> public static float Normalize01(this float @this, float min, float max) { @this = @this.Clamp <float>(min, max); @this = @this - min; var df = max - min; if (CrMath.AeqZero(df)) { throw new MinEqualMaxException(); } return(@this / df); }
void Initialize(float xA, float yA, float xB, float yB) { if (CrMath.AeqB(xA, xB)) { throw new EvaluatorDxZeroException(); } if (xA > xB) { throw new EvaluatorXaGreaterThanXbException(); } Xa = xA; Xb = xB; Ya = yA.Clamp01(); Yb = yB.Clamp01(); }
/// <summary> /// Determines whether the specified <see cref="T:Crystal.Utility"/> is equal to the current /// <see cref="T:Crystal.Utility"/>. /// </summary> /// <param name="other">The <see cref="T:Crystal.Utility"/> to compare with the current <see cref="T:Crystal.Utility"/>.</param> /// <returns> /// <c>true</c> if the specified <see cref="T:Crystal.Utility"/> is equal to the current /// <see cref="T:Crystal.Utility"/>; otherwise, <c>false</c>. /// </returns> public bool Equals(Utility other) { return(CrMath.AeqB(Value, other.Value) && CrMath.AeqB(Weight, other.Weight)); }
/// <param name="a">The alpha component.</param> /// <param name="b">The blue component.</param> public static bool operator !=(Utility a, Utility b) { return(CrMath.AneqB(a.Value, b.Value) || CrMath.AneqB(a.Weight, b.Weight)); }