本文整理汇总了C#中Madingley.FunctionalGroupDefinitions.GetAllTraitNames方法的典型用法代码示例。如果您正苦于以下问题:C# FunctionalGroupDefinitions.GetAllTraitNames方法的具体用法?C# FunctionalGroupDefinitions.GetAllTraitNames怎么用?C# FunctionalGroupDefinitions.GetAllTraitNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Madingley.FunctionalGroupDefinitions
的用法示例。
在下文中一共展示了FunctionalGroupDefinitions.GetAllTraitNames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateFunctionalDiversity
/// <summary>
/// Calculates functional diversity of cohorts in a grid cell as functional richness and functional diveregence (using the Rao Index)
/// </summary>
/// <param name="ecosystemModelGrid">The model grid</param>
/// <param name="cohortDefinitions">The functional group definitions for cohorts in the model</param>
/// <param name="cellIndices">The list of cell indices in the current model simulation</param>
/// <param name="cellIndex">The index of the current cell within the list of cells to run</param>
/// <returns>A pair of values representing the functional richness and functional divergence (functional richness currently disabled!)</returns>
public double[] CalculateFunctionalDiversity(ModelGrid ecosystemModelGrid, FunctionalGroupDefinitions cohortDefinitions,
List<uint[]> cellIndices, int cellIndex)
{
//Get the cohorts for the specified cell
GridCellCohortHandler CellCohorts = ecosystemModelGrid.GetGridCellCohorts(cellIndices[cellIndex][0], cellIndices[cellIndex][1]);
//Variable to hold the functional richness value for the current cohorts
double FunctionalRichness;
//Variable to hold the functional divergence value for the current cohorts
double RaoFunctionalDivergence = 0.0;
double[,] Distances= new double[CellCohorts.GetNumberOfCohorts(), CellCohorts.GetNumberOfCohorts()];
List<string> AllTraitNames = cohortDefinitions.GetAllTraitNames().ToList();
AllTraitNames.Remove("realm");
AllTraitNames.Remove("heterotroph/autotroph");
AllTraitNames.Remove("diet");
string[] TraitNames = AllTraitNames.ToArray();
//Define upper and lower limits for body mass
double MinMass = cohortDefinitions.GetBiologicalPropertyAllFunctionalGroups("minimum mass").Min();
double MaxMass = cohortDefinitions.GetBiologicalPropertyAllFunctionalGroups("maximum mass").Max();
//Define upp and lower limits for trophic index
double MaxTI = 40.0;
double MinTI = 1.0;
// Construct an array of functional trait values for each cohort
// Rows are specific cohorts
// Columns are the functional traits (these include different types:
// quantative: current mass, trophic index
// nominal: diet, reproductive strategy, mobility, metabolism
Tuple<double[], string[]>[] CohortFunctionalTraits = new Tuple<double[], string[]>[CellCohorts.GetNumberOfCohorts()];
double[] IndividualBodyMasses = new double[CellCohorts.GetNumberOfCohorts()];
double[] TrophicIndex = new double[CellCohorts.GetNumberOfCohorts()];
string[][] CohortNominalTraitValues= new string[TraitNames.Length][];
for (int i = 0; i < TraitNames.Length; i++)
{
CohortNominalTraitValues[i] = new string[CellCohorts.GetNumberOfCohorts()];
}
// Construct a vector of cohort biomass (in case we want to weight by them)
double[] CohortTotalBiomasses = new double[CellCohorts.GetNumberOfCohorts()];
string[] TraitValues = new string[TraitNames.Length];
double[] QuantitativeTraitValues= new double[2];
int CohortNumberCounter = 0;
for (int fg = 0; fg < CellCohorts.Count; fg++)
{
foreach (Cohort c in CellCohorts[fg])
{
TraitValues = cohortDefinitions.GetTraitValues(TraitNames, fg);
for (int ii = 0; ii < TraitValues.Length; ii++)
{
CohortNominalTraitValues[ii][CohortNumberCounter] = TraitValues[ii];
}
IndividualBodyMasses[CohortNumberCounter] = c.IndividualBodyMass;
TrophicIndex[CohortNumberCounter] = c.TrophicIndex;
QuantitativeTraitValues[0] = c.IndividualBodyMass;
QuantitativeTraitValues[1] = c.TrophicIndex;
CohortFunctionalTraits[CohortNumberCounter] = new Tuple<double[], string[]>(QuantitativeTraitValues, TraitValues);
CohortTotalBiomasses[CohortNumberCounter] = (c.IndividualBodyMass + c.IndividualReproductivePotentialMass) * c.CohortAbundance;
CohortNumberCounter++;
}
}
List<double[,]> DistanceList = new List<double[,]>();
DistanceList.Add(CalculateDistanceMatrix(IndividualBodyMasses, MaxMass, MinMass));
DistanceList.Add(CalculateDistanceMatrix(TrophicIndex, MaxTI, MinTI));
foreach (string[] t in CohortNominalTraitValues)
{
DistanceList.Add(CalculateDistanceMatrix(t));
}
Distances = CalculateAggregateDistance(DistanceList);
RaoFunctionalDivergence = RaoEntropy(Distances, CohortTotalBiomasses);
return new double[] {0.0,RaoFunctionalDivergence};
}