本文整理汇总了C#中this.Average方法的典型用法代码示例。如果您正苦于以下问题:C# this.Average方法的具体用法?C# this.Average怎么用?C# this.Average使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.Average方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Mean
public static ICartesianCoordinate Mean(this IEnumerable<ICartesianCoordinate> pointcloud)
{
var X = pointcloud.Average(p => p.X);
var Y = pointcloud.Average(p => p.Y);
return new Point(X, Y);
}
示例2: AsSextantBoundingBox
/// <summary>
/// Return a Rect structure indicating the bounding rectangle for the vertex
/// from the specified tuple and the next tuple.
/// </summary>
public static Rect AsSextantBoundingBox(this List<Tuple<double, double>> verticies, int startingPoint)
{
var centerX = verticies.Average(v => v.Item1);
var centerY = verticies.Average(v => v.Item2);
var point1X = verticies[startingPoint].Item1;
var point1Y = verticies[startingPoint].Item2;
var point2X = startingPoint == 5 ? verticies[0].Item1 : verticies[startingPoint + 1].Item1;
var point2Y = startingPoint == 5 ? verticies[0].Item2 : verticies[startingPoint + 1].Item2;
return new Rect(Math.Min(centerX, Math.Min(point1X, point2X)),
Math.Min(centerY, Math.Min(point1Y, point2Y)),
(Math.Max(centerX, Math.Max(point1X, point2X)) - Math.Min(centerX, Math.Min(point1X, point2X))),
(Math.Max(centerY, Math.Max(point1Y, point2Y)) - Math.Min(centerY, Math.Min(point1Y, point2Y))));
}
示例3: AsSextant
/// <summary>
/// Return a point collection of the specified point in the List of Tuples
/// and the next point and the derived center point, for a single sextant of the hexagon
/// </summary>
public static PointCollection AsSextant(this List<Tuple<double, double>> verticies, int startingPoint)
{
var pointCollection = new PointCollection(3);
var centerX = verticies.Average(v => v.Item1);
var centerY = verticies.Average(v => v.Item2);
var vertex1 = verticies[startingPoint];
var vertex2 = startingPoint == 5 ? verticies[0] : verticies[startingPoint + 1];
pointCollection.Add(new Point(centerX, centerY));
pointCollection.Add(vertex1.AsPoint());
pointCollection.Add(vertex2.AsPoint());
return pointCollection;
}
示例4: Variance
public static float Variance(this IEnumerable<float> source)
{
float avg = source.Average();
float d = source.Aggregate(0.0f,
(total, next) => total + (float) Math.Pow(next - avg, 2));
return d/(source.Count() - 1);
}
示例5: StdDev
public static double StdDev(this double[] data)
{
double avg = data.Average();
double sum = data.Sum(x => Math.Pow(x - avg, 2));
return Math.Sqrt(sum / data.Length);
}
示例6: Average
/// <summary>
/// Computes the average of a sequence of TimeSpan objects
/// </summary>
/// <param name="spans">A sequence of values to calculate the average of</param>
/// <returns>The average of the sequence of values</returns>
public static TimeSpan Average(this IEnumerable<TimeSpan> Spans)
{
double ticks = 0;
Spans.Check(Enumerable.Empty<TimeSpan>());
if (Spans.Any())
ticks = Spans.Average(a => a.Ticks);
return new TimeSpan((long)ticks);
}
示例7: StdevS
/// <summary>
/// Standard dev of population sqrt(sum((item-mean)^2) / (N-1))
/// </summary>
public static double StdevS(this IEnumerable<double> items)
{
double count = items.Count();
if (count < 2) throw new ArgumentException("StdevP called with < 2 items", "StdevP");
double mean = items.Average();
double sum = items.Sum<double>(d => (d - mean) * (d - mean));
return Math.Sqrt(sum / (count - 1));
}
示例8: GetStdDev
public static double GetStdDev(this float[] source)
{
if (source.Length <= 0)
return 0;
var avg = source.Average();
var sum = source.Sum(d => Math.Pow(d - avg, 2));
return Math.Sqrt(sum / (source.Length - 1));
}
示例9: Deviations
private static IEnumerable<Tuple<double, double>> Deviations(this ICollection<double> values)
{
if (values.Count == 0)
yield break;
var avg = values.Average();
foreach (var d in values)
yield return Tuple.Create(d, avg - d);
}
示例10: StdDev
public static double StdDev(this int[] values)
{
var mean = values.Average();
var variance = values
.Select(x => Math.Pow(mean - x, 2))
.Average();
return Math.Sqrt(variance);
}
示例11: StandardDeviation
/// <summary>
/// Computes the standard deviation of the given values.
/// </summary>
public static float StandardDeviation(this List<float> values)
{
if (values.Count == 0)
return 0;
float avg = values.Average();
// Calculates sum((xi - avg)²)
float sum = values.ConvertAll(val => (float)Math.Pow(val - avg, 2)).Sum();
return (float)Math.Sqrt(sum / values.Count);
}
示例12: StandardDeviation
public static double StandardDeviation(this IEnumerable<float> val)
{
double sumOfSqrs = 0;
double avg = val.Average();
foreach (var item in val)
{
sumOfSqrs += Math.Pow(((double)item - avg), 2);
}
double n = (double)val.Count();
return Math.Sqrt(sumOfSqrs / (n - 1));
}
示例13: RunningVarianceDecremental
/// <summary>
/// Calculates decremental running average and variance.
/// </summary>
/// <param name="samples">Sample data.</param>
/// <param name="onCalculated">
/// Action callback which fires on each element removal.
/// <para>Parameters are: (index, decremental average, decremental variance).</para>
/// </param>
/// <param name="weights">Sample weights.</param>
public static void RunningVarianceDecremental(this IList<double> samples, Action<int, double, double> onCalculated, IList<double> weights)
{
double sumWeight = weights.Sum(),
mean = samples.Average(weights),
M2 = samples.Variance(weights) * sumWeight;
for (int i = 0; i < samples.Count; i++)
{
var variance = UpdateVarianceDecremental(ref M2, ref sumWeight, ref mean, samples[i], weights[i]);
onCalculated(i, mean, variance);
}
}
示例14: RunningAverageDecremental
/// <summary>
/// Calculates decremental running average.
/// </summary>
/// <param name="data">Sample data.</param>
/// <param name="onCalculated">
/// Action callback which fires on each element removal.
/// <para>Parameters are: (index, decremental average).</para>
/// </param>
public static void RunningAverageDecremental(this IList<double> data, Action<int, double> onCalculated)
{
var avg = data.Average();
for (int i = 0; i < data.Count; i++)
{
var item = data[i];
avg -= UpdateAverageDecremental(avg, data.Count - i, item);
onCalculated(i, avg);
}
}
示例15: StandardDeviation
public static decimal StandardDeviation(this IEnumerable<decimal> values)
{
Contract.Requires(values != null);
decimal ret = 0;
var count = values.Count();
if (count > 1)
{
var avg = values.Average();
var sum = values.Sum(d => (d - avg) * (d - avg));
ret = (decimal) Math.Sqrt((double) (sum / count));
}
return ret;
}