Summands of Pendant Pendant Sums


1. SUMMANDS of Pendant Pendant Sums:

Code
#=======================================================
# INITIALIZE
# Read in the Fieldmark and its associated dataframes
#=======================================================
import pandas as pd
import numpy as np
import plotly
import plotly.graph_objs as go
import plotly.express as px

import utils_loom as uloom
import utils_khipu as ukhipu
import qollqa_chuspa as qc 
from statistics import mean, mode

from fieldmark_ascher_pendant_pendant_sum import FieldmarkPendantPendantSum
aFieldmark = FieldmarkPendantPendantSum()
khipu_df = aFieldmark.dataframes[0].dataframe
sum_cord_df = aFieldmark.dataframes[1].dataframe

(khipu_dict, all_khipus) = qc.fetch_khipus()

# Initialize plotly
plotly.offline.init_notebook_mode(connected = False);

2. NUMBER of SUMMANDS - Sums per Sum Cord:

Any guess how many summands there are typically in a sum?

Code
def cords_from_sum_string(aKhipu, sum_string):
    # sum_string = "[27, 0]:6 +[27, 1]:7 "
    # Be on guard for malformed strings
    try:
        if "?" in sum_string: 
            cords = [] # Malformed sum string
        else:
            cord_reps = [aString for aString in sum_string.strip().split("+")] 
            cords = [cord_from_rep(aKhipu, aRep) for aRep in cord_reps]
    except:
        cords = []
    return cords

def cord_from_rep(aKhipu, cord_rep):
    # sum_string = "'DB-W'@[27, 0]:6  "
    cord_rep = cord_rep.split(":")[0].strip() if ":" in cord_rep else cord_rep
    cord_rep = cord_rep.split("@")[1].strip() if "@" in cord_rep else cord_rep
    def group_from_rep(aRep): return int(aRep.split(",")[0].strip().replace("[","")) 
    def cord_from_rep(aRep): return int(aRep.split(",")[1].strip().replace("]",""))
    group = aKhipu[group_from_rep(cord_rep)]
    cord = group[cord_from_rep(cord_rep)]
    return cord
    
def calculate_num_pendant_sum_cords(aKhipu, relation_df):
    sum_cords = []
    summand_cords = []
    for cord_pos in relation_df.cord_index.values:
        sum_cords +=  cords_from_sum_string(aKhipu, cord_pos) 
    for summand_string in relation_df.summand_string.values:
        summand_cords += cords_from_sum_string(aKhipu, summand_string) 
    return (sum_cords, summand_cords)
Code
from statistics import mean, stdev
from collections import Counter

def draw_num_summands(summand_list, title="Number of Summands, by Frequency"):
    summands_length_counter = Counter(summand_list)
    x_vec = [x for (x,y) in summands_length_counter.most_common()]
    y_vec = [y for (x,y) in summands_length_counter.most_common()]
    fig = px.bar(x=x_vec, y=y_vec, log_x = True,
                 labels={"x": "Number of Summands", "y": "Frequency of that Sum"},
                 title=title,     
                 width=944, height=944).update_layout(showlegend=False).show()
                 
num_summands_right = [float(x) for x in list(sum_cord_df[sum_cord_df.handedness >= 0].num_summands.values)]
num_summands_left = [float(x) for x in list(sum_cord_df[sum_cord_df.handedness < 0].num_summands.values)]
print(f"({len(num_summands_right)}) Right Num_Summands: Range=({min(num_summands_right)},{max(num_summands_right)}), Mean={mean(num_summands_right):.2f}, Std_dev={stdev(num_summands_right):.2f}")
print(f"({len(num_summands_left)})  Left Num_Summands: Range=({min(num_summands_left)},{max(num_summands_left)}), Mean={mean(num_summands_left):.2f}, Std_dev={stdev(num_summands_left):.2f}")

draw_num_summands(list(sum_cord_df.num_summands.values))
(3505) Right Num_Summands: Range=(2.0,200.0), Mean=8.04, Std_dev=13.97
(2938)  Left Num_Summands: Range=(2.0,132.0), Mean=7.24, Std_dev=11.80

The statistics show our first evidence of the predominance of right-handed sums. While the general distribution of num_summands is similar, the maximum range is two-thirds narrower for the number of summands in left-handed sums.

There appears to be a small spike at 20. Is it significant? A quick view of the Data View for this relationship (sort by num summands in the header row), shows that the majority of these sums have a white sum cord.

3. Number of Sums that Reference a Particular Summand:

What about summands. Are there khipus that reference a summand in many ways? We can examine this visually using the Ascher X-Ray sum diagrams. A count of one sum referencing a given summand makes sense. Two sums referencing a given summand makes sense if there exists a left and a right-handed sum referencing the same summand. Beyond that?

Code
khipu_names = sorted(list(set(list(sum_cord_df.kfg_name.values))))
summands_by_sum = dict()
for aKFGName in khipu_names:
    sum_cord_df.head()
    summand_df = sum_cord_df[sum_cord_df.kfg_name == aKFGName]
    summand_strings = summand_df.summand_string.tolist() 
    summand_cords = uloom.flatten_list([ukhipu.cords_from_sum_string(khipu_dict[aKFGName], summand_string) for summand_string in summand_strings])
    summand_cord_indices = Counter([aCord.cord_name for aCord in summand_cords])
    num_multiple_summands = sum([y for (x,y) in summand_cord_indices.most_common() if y>1])
    max_num_summands = summand_cord_indices.most_common(1)[0][1]
    summands_by_sum[aKFGName] = (num_multiple_summands, max_num_summands)  

summands_by_sum_df = pd.DataFrame.from_dict(summands_by_sum, orient='index', columns=["Num_Multiple_Summands", "Max_Num_Sums"]).sort_values(by="Num_Multiple_Summands", ascending=False)
summands_by_sum_df.head(5)
Num_Multiple_Summands Max_Num_Sums
AS069 5667 21
UR231 4811 23
UR004 2064 14
KH0081 1475 24
UR113 1232 13
Code
fig = px.histogram(summands_by_sum_df, 
                   x="Num_Multiple_Summands", log_y=True,
                   labels={"Num_Multiple_Summands": "Number of Sums Referencing a Given Summand"}, 
                   title="Count of Number of Sums Referencing a Given Summand")
fig.update_layout(width=944).show()

What are these khipus with such key summands? Let’s look at the top 5

   1. AS069
   2. UR231
   3. UR004
   4. KH0081
   5. UR113

UR113 is interesting (Cord group 2 has lots of unique values for summands that are referenced a lot). UR1084 has the same block structure as Urton’s Pachacamac khipu UR1104. The number 22 is referenced a lot (a calendar measure?).

4. Conclusions:

The statistics show our first evidence of the predominance of right-handed sums.

3505 Right Num_Summands: Range=(2.0,200.0), Mean=8.04, Std_dev=13.97
2938 Left Num_Summands: Range=(2.0,132.0), Mean=7.24, Std_dev=11.80

CASE STUDIES

UR113:
Cord group 2 has lots of unique values for summands that are referenced a lot.

UR1084:
UR1084 has block structure similar to Urton’s Pachacamac khipu UR1104.
The number 22 is referenced a lot (a calendar measure?).