ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data.Knowledge.Analytics Namespace / KnowledgeGraphCentralityScores Class / RawScores Property
Example

In This Topic
    RawScores Property
    In This Topic
    Gets the "raw" array of all scores for all entities used in the centrality analysis.
    Syntax
    Public ReadOnly Property RawScores As Double()
    public double[] RawScores {get;}
    Remarks
    Within the array, the scores are ordered by measure by entity. Use the following formula to do your own indexing into the array:

    score = ([measure_index * entity_count] + entity_index)

    Example: Assume you calculated 3 centrality measures across 1000 entities:

    total number of scores = 3 * 1000 = 3000.
    where:
    measure_index = 0 for the first measure, 1 for the second measure, 2 for the third measure.
    entity_count = 1000.
    entity_index = index for the given entity uid in the KnowledgeGraphCentralityResults.RawUids array (i.e. the 0-based index of the uid in RawUids)
    The first 1000 scores in the array will be the scores for the first measure, the second 1000 scores will be for the second measure and the third 1000 scores will be for the third measure.
    Example
    Get Max and Min Centrality Result Scores No Sort or LINQ
    {
      //using ArcGIS.Core.Data.Knowledge.Extensions;
    
      await QueuedTask.Run(() =>
      {
        //using(var kg = ...) {
        //var kgResults = kg.ComputeCentrality(...);
        var count_entities = kgResults.RawUids.Count();
        var score_len = kgResults.Scores.RawScores.Length;
        //Find the max and min score for each measure w/out
        //using LINQ or sorting
        for (int m = 0; m < kgResults.Scores.Measures.Length; m++)
        {
          //index into the scores array for the current measure
          var start_idx = count_entities * m;
          var end_idx = start_idx + count_entities;
    
          double max_score = double.MinValue;
          double min_score = double.MaxValue;
          List<object> max_uids = new List<object>();
          List<object> min_uids = new List<object>();
    
          for (int i = 0, s = start_idx; s < end_idx; i++, s++)
          {
            var score = kgResults.Scores.RawScores[s];
            //max
            if (score > max_score)
            {
              max_score = score;
              max_uids.Clear();
              max_uids.Add(kgResults.RawUids[i]);
            }
            else if (score == max_score)
            {
              //Collect all uids with the max score
              max_uids.Add(kgResults.RawUids[i]);
            }
            //min
            if (score < min_score)
            {
              min_score = score;
              min_uids.Clear();
              min_uids.Add(kgResults.RawUids[i]);
            }
            else if (score == min_score)
            {
              //Collect all uids with the min score
              min_uids.Add(kgResults.RawUids[i]);
            }
          }
          //TODO - use the max and min scores and uids for
          //the current measure "measures[m]"
          //max_score, max_uids
          //min_score, min_uids
    
        }
      });
    }
    Get Max and Min Centrality Result Scores With Sort and Linq
    {
      //using ArcGIS.Core.Data.Knowledge.Extensions;
    
      await QueuedTask.Run(() =>
      {
        //using(var kg = ...) {
        //var kgResults = kg.ComputeCentrality(...);
    
        var count_entities = kgResults.RawUids.Count();
        var score_len = kgResults.Scores.RawScores.Length;
        //Find the max and min score for each measure using LINQ
        for (int m = 0; m < kgResults.Scores.Measures.Length; m++)
        {
          //index into the scores array for the current measure
          var start_idx = count_entities * m;
          var end_idx = start_idx + count_entities;
    
          //Get the scores for the specified measure
          var scores = Enumerable.Range(start_idx, count_entities)
            .Select(i => kgResults.Scores.RawScores[i]).ToArray();
    
          //max + min
          var max_score = scores.Max();
          var min_score = scores.Min();
    
          //uids with the max score
          var max_uids = Enumerable.Range(0, count_entities)
          .Where(i => scores[i] == max_score)
                           .Select(i => kgResults.RawUids[i])
                           .ToList();
    
          //uids with the min score
          var min_uids = Enumerable.Range(0, count_entities)
                           .Where(i => scores[i] == min_score)
                           .Select(i => kgResults.RawUids[i])
                           .ToList();
          //TODO - use the max and min scores and uids for
          //the current measure "measures[m]"
          //max_score, max_uids
          //min_score, min_uids
        }
      });
    }
    Get Top or Bottom N Centrality Result Scores
    {
      //using ArcGIS.Core.Data.Knowledge.Extensions;
    
      //Note: logic uses the following custom class:
      //
      //public class KG_Score_Value {
      //   public KG_Score_Value(double score, int uid_idx) {
      //      Score = score;
      //      Uid_idx = uid_idx;
      //   }
      //
      //   public double Score { get; set; }
      //   public int Uid_idx { get; set; }
      //}
    
      //var kgResults = kg.ComputeCentrality(...);
    
      var count_entities = kgResults.RawUids.Count();
      var score_len = kgResults.Scores.RawScores.Length;
      int n = 100;
    
      //Find the top and bottom "n" scores for each measure
      for (int m = 0; m < kgResults.Scores.Measures.Length; m++)
      {
        //index into the scores array for the current measure
        var start_idx = count_entities * m;
        var end_idx = start_idx + count_entities;
    
        //Get the scores for the specified measure
        var scores = Enumerable.Range(start_idx, count_entities)
          .Select(i => kgResults.Scores.RawScores[i]).ToArray();
    
        //use "KG_Score_Value" to hold the score and uid index
        var uid_idx = 0;
        var kg_score_vals = Enumerable.Range(start_idx, count_entities)
               .Select(i => new KG_Score_Value(kgResults.Scores.RawScores[i], uid_idx++))
               .OrderByDescending(k => k.Score)
               .ToArray();
    
        //get up to the top or bottom N scores
        if (n > kg_score_vals.Length)
          n = kg_score_vals.Length;
    
        //get the top N scores and uids - largest first
        var top_n = kg_score_vals.Take(n).ToList();
    
        //get the bottom N scores and uids - smallest first
        var bottom_n = kg_score_vals.TakeLast(n)
                          .Reverse().ToList();
    
        foreach (var kg_score in top_n)
        {
          //TODO - use top "n" scores
          var score = kg_score.Score;
          var uid1 = kgResults.RawUids[kg_score.Uid_idx];
          //...use it
        }
    
        foreach (var kg_score in bottom_n)
        {
          //TODO - use bottom "n" scores
          var score = kg_score.Score;
          var uid1 = kgResults.RawUids[kg_score.Uid_idx];
          //...use it
        }
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.6 or higher.
    See Also