本文整理汇总了C#中Common.List.Average方法的典型用法代码示例。如果您正苦于以下问题:C# List.Average方法的具体用法?C# List.Average怎么用?C# List.Average使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Common.List
的用法示例。
在下文中一共展示了List.Average方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main()
{
int num = Helpers.ValidateInputAsInt("How many numbers you would like to enter: ");
List<double> numbers = new List<double>();
// Fill array with numbers
for (int i = 0; i < num; i++)
{
numbers.Add(Helpers.ValidateInputAsDouble("Enter value " + (i + 1) + ": "));
}
// Use of List methods
Console.WriteLine("Minimal number is : {0}", numbers.Min());
Console.WriteLine("Maximal number is : {0}", numbers.Max());
Console.WriteLine("Sum number is : {0}", numbers.Sum());
Console.WriteLine("Average number is : {0}", numbers.Average());
}
示例2: AutoCorrelation
public double AutoCorrelation(int radiusToTest, int numberOfSamplesInEachDimension)
{
List<int> samples1 = new List<int>(numberOfSamplesInEachDimension);
List<int> samples2 = new List<int>(numberOfSamplesInEachDimension);
for (int i = 0; i < numberOfSamplesInEachDimension; i++) {
int xIdx = rand.Next(0, width - radiusToTest);
int yIdx = rand.Next(0, width);
int zIdx = rand.Next(0, width);
if(systemState[xIdx][yIdx][zIdx])
samples1.Add(1);
else samples1.Add(-1);
if (systemState[xIdx+radiusToTest][yIdx][zIdx])
samples2.Add(1);
else samples2.Add(-1);
xIdx = rand.Next(0, width);
yIdx = rand.Next(0, width - radiusToTest);
zIdx = rand.Next(0, width);
if (systemState[xIdx][yIdx][zIdx])
samples1.Add(1);
else samples1.Add(-1);
if (systemState[xIdx][yIdx + radiusToTest][zIdx])
samples2.Add(1);
else samples2.Add(-1);
xIdx = rand.Next(0, width);
yIdx = rand.Next(0, width);
zIdx = rand.Next(0, width - radiusToTest);
if (systemState[xIdx][yIdx][zIdx])
samples1.Add(1);
else samples1.Add(-1);
if (systemState[xIdx][yIdx][zIdx + radiusToTest])
samples2.Add(1);
else samples2.Add(-1);
}
double mean1 = samples1.Average();
double mean2 = samples2.Average();
List<double> nextSet = new List<double>(numberOfSamplesInEachDimension);
for (int i = 0; i < numberOfSamplesInEachDimension; i++) {
nextSet.Add((samples1[i] - mean1) * (samples2[i] - mean2));
}
return nextSet.Average();
}
示例3: AverageMagnitizationPerSpinAfterTime
public double AverageMagnitizationPerSpinAfterTime(double beta, int initialSteps = 100000, int statisticalTrials = 50000, int pertubationsPerTrial = 1)
{
Magnitization = 0;
//randomize();
initializeToZero();
SetBeta(beta);
Perturb(initialSteps);
var magnitizationPerSpinsReading = new List<double>(statisticalTrials);
for (int i = 0; i < statisticalTrials; i++) {
Perturb(pertubationsPerTrial);
magnitizationPerSpinsReading.Add(MagnitizationPerSpin());
}
return magnitizationPerSpinsReading.Average();
}
示例4: CorrelationLength
public double CorrelationLength(int maxRadius, int autoCorrelationSamples)
{
List<double> correlationLengthResults = new List<double>();
for(int i=1; i < maxRadius; i++){
var autoCorrelation = AutoCorrelation(i, autoCorrelationSamples);
var result = (-i) / (Math.Log(autoCorrelation));
if (result < width) {
correlationLengthResults.Add(result);
}
}
return correlationLengthResults.Average();
}
示例5: PrintWealth
public void PrintWealth()
{
double totalValue = 0;
List<double> assets = new List<double>();
for(int i=0; i < Members.Count(); i++){
var a = Members[i].GetAssets();
//Debug.Print(i.ToString() + ": " + Members[i].GetAssets().ToString());
totalValue += a;
assets.Add(a);
//cumulativeSignal.Add(a);
}
//if (iterationIdx > 300) {
var h = new Histogram(new Signal(assets), .3);
//h.Graph();
h.SaveImage("chart " + iterationIdx.ToString() + ".bmp");
//cumulativeSignal.RankOrder().Graph();
//}
double average = assets.Average();
double SD = assets.CalculateStdDev();
Debug.Print("Total value: " + totalValue.ToString() +" average wealth: " + average.ToString() + " standard deviation: " + SD.ToString());
}