Skip to content

Repository files navigation

Note: A rendered version of this markdown readme file can be found here: github.com/BioroboticsLab/bb_network_decomposition

Social networks predict the life and death of honey bees

Analyze social networks using spectral decomposition over time.

Preprint: DOI 10.1101/2020.05.06.076943 Data: DOI 10.5281/zenodo.4438013

Usage example

This sample code showcases how to load the raw input data, calculate network age, and fit and evaluate the multinomial task regression and supplementary regression models.

importdatetimeimportpandasaspdimportnumpyasnp# https://github.com/BioroboticsLab/bb_network_decomposition# the module can be installed using pip:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_network_decomposition.git# the dependencies should be installed automatically:# https://github.com/BioroboticsLab/bb_network_decomposition/blob/master/requirements.txt# please note that you may have to install the dependency bb_utils manually:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_utils.gitimportbb_network_decompositionimportbb_network_decomposition.dataimportbb_network_decomposition.normalizationimportbb_network_decomposition.spectralimportbb_network_decomposition.projectionimportbb_network_decomposition.evaluation
# location of interaction network hdf5 fileraw_networks_path="zenodo/interaction_networks_20160729to20160827.h5"# location of bee metainfo (location descriptors, supplementary labels, ...)supplementary_data_path="zenodo/bee_daily_data.csv"# location of results of bayesian lifetime modelalive_path="zenodo/alive_bees_bayesian.csv"
# first date in the interaction tensor# used to match interaction data with supplementary data (locations, etc.)from_date=datetime.datetime(2016, 8, 12)
# number of days to use (incrase to reproduce paper results)num_days=1# load interaction data
(
interactions, # interaction tensorlabels, # names of interaction modes (proximity, trophallaxis, etc.)bee_ids, # unique BeesBook IDs of the individualsbee_ages, # tensor with ages of individuals over time
) =bb_network_decomposition.data.load_networks_h5(raw_networks_path, 0, num_days)
alive_df=bb_network_decomposition.data.load_alive_data(alive_path, bee_ids)
num_days=interactions.shape[0]
num_entities=interactions.shape[1]
num_modes=len(labels)
# number of spectral factors per interaction modenum_factors_per_mode=8
alive_matrices=bb_network_decomposition.data.get_daily_alive_matrices(
alive_df, num_days, num_entities, from_date
)
alive_matrices.shape
(1, 2010, 2010)

Boolean tensor containing lifetime data of every individual. Shape is Day x Inidividual x Individual.

If both individuals i and j were alive on day d, alive_matrices[d,i,j] is True.

interactions=bb_network_decomposition.normalization.rank_transform(
interactions, alive_matrices
)
interactions.shape
(1, 2010, 2010, 9)

Interaction strenghts of individuals over time. Shape is Day x Individual x Individual x Interaction mode.

labels
['proximity_counts',
'proximity_euclidean',
'proximity_rbf',
'velocity_pos_sum',
'velocity_neg_sum',
'velocity_pos_mean',
'velocity_neg_mean',
'trophallaxis_duration',
'trophallaxis_counts']

List of interaction modes in the same order as stored in interactions.

(
daily_factors,
num_factors_by_mode,
) =bb_network_decomposition.spectral.decomposition_by_day(
interactions, alive_matrices, num_factors_per_mode, num_jobs=4
)
daily_factors[0].shape
(2010, 104)

Spectral factors of interactions matrices over time before temporal alignment and CCA.

num_factors=daily_factors[0].shape[-1]
daily_factors_aligned=bb_network_decomposition.spectral.temporal_alignment(
daily_factors, alive_matrices
)

Spectral factors of interactions matrices over time after temporal alignment without CCA projection.

factor_df=bb_network_decomposition.data.get_factor_dataframe(
daily_factors_aligned, from_date, alive_df, bee_ids
)
factor_df
daydatebee_idagef_0f_1f_2f_3f_4f_5...f_94f_95f_96f_97f_98f_99f_100f_101f_102f_103
002016-08-122145-0.00724210.00314685-0.000766774-0.004236050.00082973-0.00254058...-0.000475807-0.01404020.00307980.0004382660.001079590.000104271-0.0006917950.000613057-0.000109924-0.000521939
102016-08-123945-0.00492436-0.00218363-0.00100829-0.00218637-0.001000590.00164908...-0.00290549-0.04439460.003473420.0002998580.000625530.000165619-0.000410046.26682e-05-0.000255383-0.000434362
202016-08-125945-0.005463520.000335544-0.00101128-0.003619590.004887990.00168936...-0.000275847-0.004856290.00108332-0.0003549530.000522480.00164634-0.0020490.00215299-0.004095160.00478023
302016-08-1217844-0.00129473-0.00042854-0.00443996-0.00169472-0.006091960.00286522...0.002574470.001067010.00191582-0.0004993890.0006594270.000257282-0.00259264-0.000812146-0.0004172690.00120451
402016-08-1219944-0.008276210.00464029-0.00073654-0.002505720.01109110.00379146...0.01690830.01181590.003241221.71778e-050.000502871-0.0019061-0.0009561350.001311780.000335653-0.000305509
..................................................................
119802016-08-12300410.005630970.00379659-0.00161652-0.0006765410.00236571-0.00542808...-0.004444120.00799384-0.00153584-0.002217960.0006548070.001758260.000222280.00097945-0.002379230.00154693
119902016-08-12300510.004821780.00242558-0.00278712-0.0002069290.00144706-0.000719776...0.00679757-0.000338297-0.003515840.001801670.0004625840.003039210.004347750.00354968-2.89882e-050.0117052
120002016-08-12300610.0062860.00478083-0.006039460.001926330.00080181-0.00546843...0.00212394-0.00339074-0.00372017-0.000963446-1.50815e-050.00101539-0.001304990.00107728-0.00114766-0.000493821
120102016-08-12300710.005020650.003500090.00158003-0.0008193858.74538e-050.00113418...0.0003666250.00208452-0.00438712-0.0004863560.001411150.00300085-0.000855138-0.00527713-0.0038038-0.00121933
120202016-08-12300810.005365170.00204567-0.00211659-0.000753905-0.0004564560.00402603...0.000891216-0.00229696-0.00692422-0.00129927-0.002518640.000189614-0.00128221-0.00567603-0.002198760.000853091

1203 rows × 108 columns

Each f_n column corresponds to factor of the spectral decomposition of one interaction mode of the interaction matrix of one day.

# Load location data, because we need it to compute the CCA projectionloc_df=bb_network_decomposition.data.load_location_data(supplementary_data_path)
cca_factor_df, cca=bb_network_decomposition.projection.get_cca_projection(
factor_df, loc_df, return_cca=True, num_components=3
)
cca_factor_df.sort_values("date", inplace=True)

cca_factor_df now contains the network age for all individuals on all dates in the dataset.

The column network_age contains the first dimension of network age (used throughout most of the paper), and the second and third dimensions are stored in the columns network_age_1 and network_age_2.

factor_df.to_csv("network_age_cca.csv")
# list of variables to use as predictors in task allocation regression tasksvariable_names= [
["age"],
["age", "network_age"],
["network_age"],
["network_age", "network_age_1"],
["network_age", "network_age_1", "network_age_2"],
]
# list of variables to use as dependent variables in regression taskstargets= [bb_network_decomposition.constants.supplementary_labels] +list(
map(lambdal: [l], bb_network_decomposition.constants.supplementary_labels)
)
target_cols=bb_network_decomposition.constants.supplementary_labels
# load all required supplementary datasup_df=bb_network_decomposition.data.load_supplementary_data(
supplementary_data_path,
keepcols=bb_network_decomposition.constants.default_location_data_cols+bb_network_decomposition.constants.default_supplementary_data_cols+ ["location_descriptor_count"],
)
location_cols=set(bb_network_decomposition.constants.location_labels).union(
set(bb_network_decomposition.constants.location_cols)
)
# remove location data from network age dataframe so that we can safely merge in all# supplementary datacca_factor_df=cca_factor_df[
[cforcincca_factor_df.columnsifcnotinlocation_cols]
]
sup_df=bb_network_decomposition.data.merge_location_data(cca_factor_df, sup_df)
# regression tasks bootstrapregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df,
variable_names,
targets,
regression=True,
use_tqdm=True,
num_bootstrap_samples=8,
)

These results correspond to section 5 of the manuscript: Network age predicts an individual's behavior and future role in the colony

# results of bootstrap analysis, grouped by dependent and independent variables, R^2 scoresregression_results.groupby(["predictors", "target"]).fitted_linear_r2.mean()
predictors target
age circadian_rhythm 0.331907
circadian_rhythm,days_left,velocity_day,velocity_night 0.172621
days_left 0.012523
velocity_day 0.083986
velocity_night 0.286554
age,network_age circadian_rhythm 0.403065
circadian_rhythm,days_left,velocity_day,velocity_night 0.210112
days_left 0.015316
velocity_day 0.095954
velocity_night 0.292630
network_age circadian_rhythm 0.387444
circadian_rhythm,days_left,velocity_day,velocity_night 0.199390
days_left 0.010289
velocity_day 0.112123
velocity_night 0.243061
network_age,network_age_1 circadian_rhythm 0.390725
circadian_rhythm,days_left,velocity_day,velocity_night 0.227511
days_left 0.071366
velocity_day 0.112483
velocity_night 0.266663
network_age,network_age_1,network_age_2 circadian_rhythm 0.433800
circadian_rhythm,days_left,velocity_day,velocity_night 0.226100
days_left 0.065899
velocity_day 0.148080
velocity_night 0.260883
Name: fitted_linear_r2, dtype: float64
# multinomial regression for task allocation taskregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df, variable_names, regression=False, use_tqdm=True, num_bootstrap_samples=8,
)
# results of bootstrap analysis, grouped by dependent and independent variables, R_McF^2 scoresregression_results.groupby(["predictors", "target"]).rho_mcf_linear.mean()
predictors target
age brood_area_total 0.546260
dance_floor 0.417913
dance_floor,honey_storage,brood_area_total,near_exit 0.415424
honey_storage 0.026411
near_exit 0.314711
age,network_age brood_area_total 0.584782
dance_floor 0.512601
dance_floor,honey_storage,brood_area_total,near_exit 0.475106
honey_storage 0.051840
near_exit 0.376673
network_age brood_area_total 0.555143
dance_floor 0.477920
dance_floor,honey_storage,brood_area_total,near_exit 0.443385
honey_storage 0.003832
near_exit 0.357418
network_age,network_age_1 brood_area_total 0.577571
dance_floor 0.477131
dance_floor,honey_storage,brood_area_total,near_exit 0.462893
honey_storage 0.166705
near_exit 0.386814
network_age,network_age_1,network_age_2 brood_area_total 0.575683
dance_floor 0.499749
dance_floor,honey_storage,brood_area_total,near_exit 0.475821
honey_storage 0.160835
near_exit 0.445180
Name: rho_mcf_linear, dtype: float64

These results correspond to section 3 of the manuscript: Network age correctly identifies task allocation

Citation

Social networks predict the life and death of honey bees
Benjamin Wild, David M Dormagen, Adrian Zachariae, Michael L Smith, Kirsten S Traynor, Dirk Brockmann, Iain D Couzin, Tim Landgraf
bioRxiv 2020.05.06.076943; doi: https://doi.org/10.1101/2020.05.06.076943

About

Analyze social networks using spectral decomposition over time

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
GitHub - BioroboticsLab/bb_network_decomposition: Analyze social networks using spectral decomposition over time · GitHub
Skip to content

Repository files navigation

Note: A rendered version of this markdown readme file can be found here: github.com/BioroboticsLab/bb_network_decomposition

Social networks predict the life and death of honey bees

Analyze social networks using spectral decomposition over time.

Preprint: DOI 10.1101/2020.05.06.076943 Data: DOI 10.5281/zenodo.4438013

Usage example

This sample code showcases how to load the raw input data, calculate network age, and fit and evaluate the multinomial task regression and supplementary regression models.

importdatetimeimportpandasaspdimportnumpyasnp# https://github.com/BioroboticsLab/bb_network_decomposition# the module can be installed using pip:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_network_decomposition.git# the dependencies should be installed automatically:# https://github.com/BioroboticsLab/bb_network_decomposition/blob/master/requirements.txt# please note that you may have to install the dependency bb_utils manually:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_utils.gitimportbb_network_decompositionimportbb_network_decomposition.dataimportbb_network_decomposition.normalizationimportbb_network_decomposition.spectralimportbb_network_decomposition.projectionimportbb_network_decomposition.evaluation
# location of interaction network hdf5 fileraw_networks_path="zenodo/interaction_networks_20160729to20160827.h5"# location of bee metainfo (location descriptors, supplementary labels, ...)supplementary_data_path="zenodo/bee_daily_data.csv"# location of results of bayesian lifetime modelalive_path="zenodo/alive_bees_bayesian.csv"
# first date in the interaction tensor# used to match interaction data with supplementary data (locations, etc.)from_date=datetime.datetime(2016, 8, 12)
# number of days to use (incrase to reproduce paper results)num_days=1# load interaction data
(
interactions, # interaction tensorlabels, # names of interaction modes (proximity, trophallaxis, etc.)bee_ids, # unique BeesBook IDs of the individualsbee_ages, # tensor with ages of individuals over time
) =bb_network_decomposition.data.load_networks_h5(raw_networks_path, 0, num_days)
alive_df=bb_network_decomposition.data.load_alive_data(alive_path, bee_ids)
num_days=interactions.shape[0]
num_entities=interactions.shape[1]
num_modes=len(labels)
# number of spectral factors per interaction modenum_factors_per_mode=8
alive_matrices=bb_network_decomposition.data.get_daily_alive_matrices(
alive_df, num_days, num_entities, from_date
)
alive_matrices.shape
(1, 2010, 2010)

Boolean tensor containing lifetime data of every individual. Shape is Day x Inidividual x Individual.

If both individuals i and j were alive on day d, alive_matrices[d,i,j] is True.

interactions=bb_network_decomposition.normalization.rank_transform(
interactions, alive_matrices
)
interactions.shape
(1, 2010, 2010, 9)

Interaction strenghts of individuals over time. Shape is Day x Individual x Individual x Interaction mode.

labels
['proximity_counts',
'proximity_euclidean',
'proximity_rbf',
'velocity_pos_sum',
'velocity_neg_sum',
'velocity_pos_mean',
'velocity_neg_mean',
'trophallaxis_duration',
'trophallaxis_counts']

List of interaction modes in the same order as stored in interactions.

(
daily_factors,
num_factors_by_mode,
) =bb_network_decomposition.spectral.decomposition_by_day(
interactions, alive_matrices, num_factors_per_mode, num_jobs=4
)
daily_factors[0].shape
(2010, 104)

Spectral factors of interactions matrices over time before temporal alignment and CCA.

num_factors=daily_factors[0].shape[-1]
daily_factors_aligned=bb_network_decomposition.spectral.temporal_alignment(
daily_factors, alive_matrices
)

Spectral factors of interactions matrices over time after temporal alignment without CCA projection.

factor_df=bb_network_decomposition.data.get_factor_dataframe(
daily_factors_aligned, from_date, alive_df, bee_ids
)
factor_df
daydatebee_idagef_0f_1f_2f_3f_4f_5...f_94f_95f_96f_97f_98f_99f_100f_101f_102f_103
002016-08-122145-0.00724210.00314685-0.000766774-0.004236050.00082973-0.00254058...-0.000475807-0.01404020.00307980.0004382660.001079590.000104271-0.0006917950.000613057-0.000109924-0.000521939
102016-08-123945-0.00492436-0.00218363-0.00100829-0.00218637-0.001000590.00164908...-0.00290549-0.04439460.003473420.0002998580.000625530.000165619-0.000410046.26682e-05-0.000255383-0.000434362
202016-08-125945-0.005463520.000335544-0.00101128-0.003619590.004887990.00168936...-0.000275847-0.004856290.00108332-0.0003549530.000522480.00164634-0.0020490.00215299-0.004095160.00478023
302016-08-1217844-0.00129473-0.00042854-0.00443996-0.00169472-0.006091960.00286522...0.002574470.001067010.00191582-0.0004993890.0006594270.000257282-0.00259264-0.000812146-0.0004172690.00120451
402016-08-1219944-0.008276210.00464029-0.00073654-0.002505720.01109110.00379146...0.01690830.01181590.003241221.71778e-050.000502871-0.0019061-0.0009561350.001311780.000335653-0.000305509
..................................................................
119802016-08-12300410.005630970.00379659-0.00161652-0.0006765410.00236571-0.00542808...-0.004444120.00799384-0.00153584-0.002217960.0006548070.001758260.000222280.00097945-0.002379230.00154693
119902016-08-12300510.004821780.00242558-0.00278712-0.0002069290.00144706-0.000719776...0.00679757-0.000338297-0.003515840.001801670.0004625840.003039210.004347750.00354968-2.89882e-050.0117052
120002016-08-12300610.0062860.00478083-0.006039460.001926330.00080181-0.00546843...0.00212394-0.00339074-0.00372017-0.000963446-1.50815e-050.00101539-0.001304990.00107728-0.00114766-0.000493821
120102016-08-12300710.005020650.003500090.00158003-0.0008193858.74538e-050.00113418...0.0003666250.00208452-0.00438712-0.0004863560.001411150.00300085-0.000855138-0.00527713-0.0038038-0.00121933
120202016-08-12300810.005365170.00204567-0.00211659-0.000753905-0.0004564560.00402603...0.000891216-0.00229696-0.00692422-0.00129927-0.002518640.000189614-0.00128221-0.00567603-0.002198760.000853091

1203 rows × 108 columns

Each f_n column corresponds to factor of the spectral decomposition of one interaction mode of the interaction matrix of one day.

# Load location data, because we need it to compute the CCA projectionloc_df=bb_network_decomposition.data.load_location_data(supplementary_data_path)
cca_factor_df, cca=bb_network_decomposition.projection.get_cca_projection(
factor_df, loc_df, return_cca=True, num_components=3
)
cca_factor_df.sort_values("date", inplace=True)

cca_factor_df now contains the network age for all individuals on all dates in the dataset.

The column network_age contains the first dimension of network age (used throughout most of the paper), and the second and third dimensions are stored in the columns network_age_1 and network_age_2.

factor_df.to_csv("network_age_cca.csv")
# list of variables to use as predictors in task allocation regression tasksvariable_names= [
["age"],
["age", "network_age"],
["network_age"],
["network_age", "network_age_1"],
["network_age", "network_age_1", "network_age_2"],
]
# list of variables to use as dependent variables in regression taskstargets= [bb_network_decomposition.constants.supplementary_labels] +list(
map(lambdal: [l], bb_network_decomposition.constants.supplementary_labels)
)
target_cols=bb_network_decomposition.constants.supplementary_labels
# load all required supplementary datasup_df=bb_network_decomposition.data.load_supplementary_data(
supplementary_data_path,
keepcols=bb_network_decomposition.constants.default_location_data_cols+bb_network_decomposition.constants.default_supplementary_data_cols+ ["location_descriptor_count"],
)
location_cols=set(bb_network_decomposition.constants.location_labels).union(
set(bb_network_decomposition.constants.location_cols)
)
# remove location data from network age dataframe so that we can safely merge in all# supplementary datacca_factor_df=cca_factor_df[
[cforcincca_factor_df.columnsifcnotinlocation_cols]
]
sup_df=bb_network_decomposition.data.merge_location_data(cca_factor_df, sup_df)
# regression tasks bootstrapregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df,
variable_names,
targets,
regression=True,
use_tqdm=True,
num_bootstrap_samples=8,
)

These results correspond to section 5 of the manuscript: Network age predicts an individual's behavior and future role in the colony

# results of bootstrap analysis, grouped by dependent and independent variables, R^2 scoresregression_results.groupby(["predictors", "target"]).fitted_linear_r2.mean()
predictors target
age circadian_rhythm 0.331907
circadian_rhythm,days_left,velocity_day,velocity_night 0.172621
days_left 0.012523
velocity_day 0.083986
velocity_night 0.286554
age,network_age circadian_rhythm 0.403065
circadian_rhythm,days_left,velocity_day,velocity_night 0.210112
days_left 0.015316
velocity_day 0.095954
velocity_night 0.292630
network_age circadian_rhythm 0.387444
circadian_rhythm,days_left,velocity_day,velocity_night 0.199390
days_left 0.010289
velocity_day 0.112123
velocity_night 0.243061
network_age,network_age_1 circadian_rhythm 0.390725
circadian_rhythm,days_left,velocity_day,velocity_night 0.227511
days_left 0.071366
velocity_day 0.112483
velocity_night 0.266663
network_age,network_age_1,network_age_2 circadian_rhythm 0.433800
circadian_rhythm,days_left,velocity_day,velocity_night 0.226100
days_left 0.065899
velocity_day 0.148080
velocity_night 0.260883
Name: fitted_linear_r2, dtype: float64
# multinomial regression for task allocation taskregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df, variable_names, regression=False, use_tqdm=True, num_bootstrap_samples=8,
)
# results of bootstrap analysis, grouped by dependent and independent variables, R_McF^2 scoresregression_results.groupby(["predictors", "target"]).rho_mcf_linear.mean()
predictors target
age brood_area_total 0.546260
dance_floor 0.417913
dance_floor,honey_storage,brood_area_total,near_exit 0.415424
honey_storage 0.026411
near_exit 0.314711
age,network_age brood_area_total 0.584782
dance_floor 0.512601
dance_floor,honey_storage,brood_area_total,near_exit 0.475106
honey_storage 0.051840
near_exit 0.376673
network_age brood_area_total 0.555143
dance_floor 0.477920
dance_floor,honey_storage,brood_area_total,near_exit 0.443385
honey_storage 0.003832
near_exit 0.357418
network_age,network_age_1 brood_area_total 0.577571
dance_floor 0.477131
dance_floor,honey_storage,brood_area_total,near_exit 0.462893
honey_storage 0.166705
near_exit 0.386814
network_age,network_age_1,network_age_2 brood_area_total 0.575683
dance_floor 0.499749
dance_floor,honey_storage,brood_area_total,near_exit 0.475821
honey_storage 0.160835
near_exit 0.445180
Name: rho_mcf_linear, dtype: float64

These results correspond to section 3 of the manuscript: Network age correctly identifies task allocation

Citation

Social networks predict the life and death of honey bees
Benjamin Wild, David M Dormagen, Adrian Zachariae, Michael L Smith, Kirsten S Traynor, Dirk Brockmann, Iain D Couzin, Tim Landgraf
bioRxiv 2020.05.06.076943; doi: https://doi.org/10.1101/2020.05.06.076943

About

Analyze social networks using spectral decomposition over time

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - BioroboticsLab/bb_network_decomposition: Analyze social networks using spectral decomposition over time · GitHub
Skip to content

Repository files navigation

Note: A rendered version of this markdown readme file can be found here: github.com/BioroboticsLab/bb_network_decomposition

Social networks predict the life and death of honey bees

Analyze social networks using spectral decomposition over time.

Preprint: DOI 10.1101/2020.05.06.076943 Data: DOI 10.5281/zenodo.4438013

Usage example

This sample code showcases how to load the raw input data, calculate network age, and fit and evaluate the multinomial task regression and supplementary regression models.

importdatetimeimportpandasaspdimportnumpyasnp# https://github.com/BioroboticsLab/bb_network_decomposition# the module can be installed using pip:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_network_decomposition.git# the dependencies should be installed automatically:# https://github.com/BioroboticsLab/bb_network_decomposition/blob/master/requirements.txt# please note that you may have to install the dependency bb_utils manually:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_utils.gitimportbb_network_decompositionimportbb_network_decomposition.dataimportbb_network_decomposition.normalizationimportbb_network_decomposition.spectralimportbb_network_decomposition.projectionimportbb_network_decomposition.evaluation
# location of interaction network hdf5 fileraw_networks_path="zenodo/interaction_networks_20160729to20160827.h5"# location of bee metainfo (location descriptors, supplementary labels, ...)supplementary_data_path="zenodo/bee_daily_data.csv"# location of results of bayesian lifetime modelalive_path="zenodo/alive_bees_bayesian.csv"
# first date in the interaction tensor# used to match interaction data with supplementary data (locations, etc.)from_date=datetime.datetime(2016, 8, 12)
# number of days to use (incrase to reproduce paper results)num_days=1# load interaction data
(
interactions, # interaction tensorlabels, # names of interaction modes (proximity, trophallaxis, etc.)bee_ids, # unique BeesBook IDs of the individualsbee_ages, # tensor with ages of individuals over time
) =bb_network_decomposition.data.load_networks_h5(raw_networks_path, 0, num_days)
alive_df=bb_network_decomposition.data.load_alive_data(alive_path, bee_ids)
num_days=interactions.shape[0]
num_entities=interactions.shape[1]
num_modes=len(labels)
# number of spectral factors per interaction modenum_factors_per_mode=8
alive_matrices=bb_network_decomposition.data.get_daily_alive_matrices(
alive_df, num_days, num_entities, from_date
)
alive_matrices.shape
(1, 2010, 2010)

Boolean tensor containing lifetime data of every individual. Shape is Day x Inidividual x Individual.

If both individuals i and j were alive on day d, alive_matrices[d,i,j] is True.

interactions=bb_network_decomposition.normalization.rank_transform(
interactions, alive_matrices
)
interactions.shape
(1, 2010, 2010, 9)

Interaction strenghts of individuals over time. Shape is Day x Individual x Individual x Interaction mode.

labels
['proximity_counts',
'proximity_euclidean',
'proximity_rbf',
'velocity_pos_sum',
'velocity_neg_sum',
'velocity_pos_mean',
'velocity_neg_mean',
'trophallaxis_duration',
'trophallaxis_counts']

List of interaction modes in the same order as stored in interactions.

(
daily_factors,
num_factors_by_mode,
) =bb_network_decomposition.spectral.decomposition_by_day(
interactions, alive_matrices, num_factors_per_mode, num_jobs=4
)
daily_factors[0].shape
(2010, 104)

Spectral factors of interactions matrices over time before temporal alignment and CCA.

num_factors=daily_factors[0].shape[-1]
daily_factors_aligned=bb_network_decomposition.spectral.temporal_alignment(
daily_factors, alive_matrices
)

Spectral factors of interactions matrices over time after temporal alignment without CCA projection.

factor_df=bb_network_decomposition.data.get_factor_dataframe(
daily_factors_aligned, from_date, alive_df, bee_ids
)
factor_df
daydatebee_idagef_0f_1f_2f_3f_4f_5...f_94f_95f_96f_97f_98f_99f_100f_101f_102f_103
002016-08-122145-0.00724210.00314685-0.000766774-0.004236050.00082973-0.00254058...-0.000475807-0.01404020.00307980.0004382660.001079590.000104271-0.0006917950.000613057-0.000109924-0.000521939
102016-08-123945-0.00492436-0.00218363-0.00100829-0.00218637-0.001000590.00164908...-0.00290549-0.04439460.003473420.0002998580.000625530.000165619-0.000410046.26682e-05-0.000255383-0.000434362
202016-08-125945-0.005463520.000335544-0.00101128-0.003619590.004887990.00168936...-0.000275847-0.004856290.00108332-0.0003549530.000522480.00164634-0.0020490.00215299-0.004095160.00478023
302016-08-1217844-0.00129473-0.00042854-0.00443996-0.00169472-0.006091960.00286522...0.002574470.001067010.00191582-0.0004993890.0006594270.000257282-0.00259264-0.000812146-0.0004172690.00120451
402016-08-1219944-0.008276210.00464029-0.00073654-0.002505720.01109110.00379146...0.01690830.01181590.003241221.71778e-050.000502871-0.0019061-0.0009561350.001311780.000335653-0.000305509
..................................................................
119802016-08-12300410.005630970.00379659-0.00161652-0.0006765410.00236571-0.00542808...-0.004444120.00799384-0.00153584-0.002217960.0006548070.001758260.000222280.00097945-0.002379230.00154693
119902016-08-12300510.004821780.00242558-0.00278712-0.0002069290.00144706-0.000719776...0.00679757-0.000338297-0.003515840.001801670.0004625840.003039210.004347750.00354968-2.89882e-050.0117052
120002016-08-12300610.0062860.00478083-0.006039460.001926330.00080181-0.00546843...0.00212394-0.00339074-0.00372017-0.000963446-1.50815e-050.00101539-0.001304990.00107728-0.00114766-0.000493821
120102016-08-12300710.005020650.003500090.00158003-0.0008193858.74538e-050.00113418...0.0003666250.00208452-0.00438712-0.0004863560.001411150.00300085-0.000855138-0.00527713-0.0038038-0.00121933
120202016-08-12300810.005365170.00204567-0.00211659-0.000753905-0.0004564560.00402603...0.000891216-0.00229696-0.00692422-0.00129927-0.002518640.000189614-0.00128221-0.00567603-0.002198760.000853091

1203 rows × 108 columns

Each f_n column corresponds to factor of the spectral decomposition of one interaction mode of the interaction matrix of one day.

# Load location data, because we need it to compute the CCA projectionloc_df=bb_network_decomposition.data.load_location_data(supplementary_data_path)
cca_factor_df, cca=bb_network_decomposition.projection.get_cca_projection(
factor_df, loc_df, return_cca=True, num_components=3
)
cca_factor_df.sort_values("date", inplace=True)

cca_factor_df now contains the network age for all individuals on all dates in the dataset.

The column network_age contains the first dimension of network age (used throughout most of the paper), and the second and third dimensions are stored in the columns network_age_1 and network_age_2.

factor_df.to_csv("network_age_cca.csv")
# list of variables to use as predictors in task allocation regression tasksvariable_names= [
["age"],
["age", "network_age"],
["network_age"],
["network_age", "network_age_1"],
["network_age", "network_age_1", "network_age_2"],
]
# list of variables to use as dependent variables in regression taskstargets= [bb_network_decomposition.constants.supplementary_labels] +list(
map(lambdal: [l], bb_network_decomposition.constants.supplementary_labels)
)
target_cols=bb_network_decomposition.constants.supplementary_labels
# load all required supplementary datasup_df=bb_network_decomposition.data.load_supplementary_data(
supplementary_data_path,
keepcols=bb_network_decomposition.constants.default_location_data_cols+bb_network_decomposition.constants.default_supplementary_data_cols+ ["location_descriptor_count"],
)
location_cols=set(bb_network_decomposition.constants.location_labels).union(
set(bb_network_decomposition.constants.location_cols)
)
# remove location data from network age dataframe so that we can safely merge in all# supplementary datacca_factor_df=cca_factor_df[
[cforcincca_factor_df.columnsifcnotinlocation_cols]
]
sup_df=bb_network_decomposition.data.merge_location_data(cca_factor_df, sup_df)
# regression tasks bootstrapregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df,
variable_names,
targets,
regression=True,
use_tqdm=True,
num_bootstrap_samples=8,
)

These results correspond to section 5 of the manuscript: Network age predicts an individual's behavior and future role in the colony

# results of bootstrap analysis, grouped by dependent and independent variables, R^2 scoresregression_results.groupby(["predictors", "target"]).fitted_linear_r2.mean()
predictors target
age circadian_rhythm 0.331907
circadian_rhythm,days_left,velocity_day,velocity_night 0.172621
days_left 0.012523
velocity_day 0.083986
velocity_night 0.286554
age,network_age circadian_rhythm 0.403065
circadian_rhythm,days_left,velocity_day,velocity_night 0.210112
days_left 0.015316
velocity_day 0.095954
velocity_night 0.292630
network_age circadian_rhythm 0.387444
circadian_rhythm,days_left,velocity_day,velocity_night 0.199390
days_left 0.010289
velocity_day 0.112123
velocity_night 0.243061
network_age,network_age_1 circadian_rhythm 0.390725
circadian_rhythm,days_left,velocity_day,velocity_night 0.227511
days_left 0.071366
velocity_day 0.112483
velocity_night 0.266663
network_age,network_age_1,network_age_2 circadian_rhythm 0.433800
circadian_rhythm,days_left,velocity_day,velocity_night 0.226100
days_left 0.065899
velocity_day 0.148080
velocity_night 0.260883
Name: fitted_linear_r2, dtype: float64
# multinomial regression for task allocation taskregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df, variable_names, regression=False, use_tqdm=True, num_bootstrap_samples=8,
)
# results of bootstrap analysis, grouped by dependent and independent variables, R_McF^2 scoresregression_results.groupby(["predictors", "target"]).rho_mcf_linear.mean()
predictors target
age brood_area_total 0.546260
dance_floor 0.417913
dance_floor,honey_storage,brood_area_total,near_exit 0.415424
honey_storage 0.026411
near_exit 0.314711
age,network_age brood_area_total 0.584782
dance_floor 0.512601
dance_floor,honey_storage,brood_area_total,near_exit 0.475106
honey_storage 0.051840
near_exit 0.376673
network_age brood_area_total 0.555143
dance_floor 0.477920
dance_floor,honey_storage,brood_area_total,near_exit 0.443385
honey_storage 0.003832
near_exit 0.357418
network_age,network_age_1 brood_area_total 0.577571
dance_floor 0.477131
dance_floor,honey_storage,brood_area_total,near_exit 0.462893
honey_storage 0.166705
near_exit 0.386814
network_age,network_age_1,network_age_2 brood_area_total 0.575683
dance_floor 0.499749
dance_floor,honey_storage,brood_area_total,near_exit 0.475821
honey_storage 0.160835
near_exit 0.445180
Name: rho_mcf_linear, dtype: float64

These results correspond to section 3 of the manuscript: Network age correctly identifies task allocation

Citation

Social networks predict the life and death of honey bees
Benjamin Wild, David M Dormagen, Adrian Zachariae, Michael L Smith, Kirsten S Traynor, Dirk Brockmann, Iain D Couzin, Tim Landgraf
bioRxiv 2020.05.06.076943; doi: https://doi.org/10.1101/2020.05.06.076943

About

Analyze social networks using spectral decomposition over time

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - BioroboticsLab/bb_network_decomposition: Analyze social networks using spectral decomposition over time · GitHub
Skip to content

Repository files navigation

Note: A rendered version of this markdown readme file can be found here: github.com/BioroboticsLab/bb_network_decomposition

Social networks predict the life and death of honey bees

Analyze social networks using spectral decomposition over time.

Preprint: DOI 10.1101/2020.05.06.076943 Data: DOI 10.5281/zenodo.4438013

Usage example

This sample code showcases how to load the raw input data, calculate network age, and fit and evaluate the multinomial task regression and supplementary regression models.

importdatetimeimportpandasaspdimportnumpyasnp# https://github.com/BioroboticsLab/bb_network_decomposition# the module can be installed using pip:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_network_decomposition.git# the dependencies should be installed automatically:# https://github.com/BioroboticsLab/bb_network_decomposition/blob/master/requirements.txt# please note that you may have to install the dependency bb_utils manually:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_utils.gitimportbb_network_decompositionimportbb_network_decomposition.dataimportbb_network_decomposition.normalizationimportbb_network_decomposition.spectralimportbb_network_decomposition.projectionimportbb_network_decomposition.evaluation
# location of interaction network hdf5 fileraw_networks_path="zenodo/interaction_networks_20160729to20160827.h5"# location of bee metainfo (location descriptors, supplementary labels, ...)supplementary_data_path="zenodo/bee_daily_data.csv"# location of results of bayesian lifetime modelalive_path="zenodo/alive_bees_bayesian.csv"
# first date in the interaction tensor# used to match interaction data with supplementary data (locations, etc.)from_date=datetime.datetime(2016, 8, 12)
# number of days to use (incrase to reproduce paper results)num_days=1# load interaction data
(
interactions, # interaction tensorlabels, # names of interaction modes (proximity, trophallaxis, etc.)bee_ids, # unique BeesBook IDs of the individualsbee_ages, # tensor with ages of individuals over time
) =bb_network_decomposition.data.load_networks_h5(raw_networks_path, 0, num_days)
alive_df=bb_network_decomposition.data.load_alive_data(alive_path, bee_ids)
num_days=interactions.shape[0]
num_entities=interactions.shape[1]
num_modes=len(labels)
# number of spectral factors per interaction modenum_factors_per_mode=8
alive_matrices=bb_network_decomposition.data.get_daily_alive_matrices(
alive_df, num_days, num_entities, from_date
)
alive_matrices.shape
(1, 2010, 2010)

Boolean tensor containing lifetime data of every individual. Shape is Day x Inidividual x Individual.

If both individuals i and j were alive on day d, alive_matrices[d,i,j] is True.

interactions=bb_network_decomposition.normalization.rank_transform(
interactions, alive_matrices
)
interactions.shape
(1, 2010, 2010, 9)

Interaction strenghts of individuals over time. Shape is Day x Individual x Individual x Interaction mode.

labels
['proximity_counts',
'proximity_euclidean',
'proximity_rbf',
'velocity_pos_sum',
'velocity_neg_sum',
'velocity_pos_mean',
'velocity_neg_mean',
'trophallaxis_duration',
'trophallaxis_counts']

List of interaction modes in the same order as stored in interactions.

(
daily_factors,
num_factors_by_mode,
) =bb_network_decomposition.spectral.decomposition_by_day(
interactions, alive_matrices, num_factors_per_mode, num_jobs=4
)
daily_factors[0].shape
(2010, 104)

Spectral factors of interactions matrices over time before temporal alignment and CCA.

num_factors=daily_factors[0].shape[-1]
daily_factors_aligned=bb_network_decomposition.spectral.temporal_alignment(
daily_factors, alive_matrices
)

Spectral factors of interactions matrices over time after temporal alignment without CCA projection.

factor_df=bb_network_decomposition.data.get_factor_dataframe(
daily_factors_aligned, from_date, alive_df, bee_ids
)
factor_df
daydatebee_idagef_0f_1f_2f_3f_4f_5...f_94f_95f_96f_97f_98f_99f_100f_101f_102f_103
002016-08-122145-0.00724210.00314685-0.000766774-0.004236050.00082973-0.00254058...-0.000475807-0.01404020.00307980.0004382660.001079590.000104271-0.0006917950.000613057-0.000109924-0.000521939
102016-08-123945-0.00492436-0.00218363-0.00100829-0.00218637-0.001000590.00164908...-0.00290549-0.04439460.003473420.0002998580.000625530.000165619-0.000410046.26682e-05-0.000255383-0.000434362
202016-08-125945-0.005463520.000335544-0.00101128-0.003619590.004887990.00168936...-0.000275847-0.004856290.00108332-0.0003549530.000522480.00164634-0.0020490.00215299-0.004095160.00478023
302016-08-1217844-0.00129473-0.00042854-0.00443996-0.00169472-0.006091960.00286522...0.002574470.001067010.00191582-0.0004993890.0006594270.000257282-0.00259264-0.000812146-0.0004172690.00120451
402016-08-1219944-0.008276210.00464029-0.00073654-0.002505720.01109110.00379146...0.01690830.01181590.003241221.71778e-050.000502871-0.0019061-0.0009561350.001311780.000335653-0.000305509
..................................................................
119802016-08-12300410.005630970.00379659-0.00161652-0.0006765410.00236571-0.00542808...-0.004444120.00799384-0.00153584-0.002217960.0006548070.001758260.000222280.00097945-0.002379230.00154693
119902016-08-12300510.004821780.00242558-0.00278712-0.0002069290.00144706-0.000719776...0.00679757-0.000338297-0.003515840.001801670.0004625840.003039210.004347750.00354968-2.89882e-050.0117052
120002016-08-12300610.0062860.00478083-0.006039460.001926330.00080181-0.00546843...0.00212394-0.00339074-0.00372017-0.000963446-1.50815e-050.00101539-0.001304990.00107728-0.00114766-0.000493821
120102016-08-12300710.005020650.003500090.00158003-0.0008193858.74538e-050.00113418...0.0003666250.00208452-0.00438712-0.0004863560.001411150.00300085-0.000855138-0.00527713-0.0038038-0.00121933
120202016-08-12300810.005365170.00204567-0.00211659-0.000753905-0.0004564560.00402603...0.000891216-0.00229696-0.00692422-0.00129927-0.002518640.000189614-0.00128221-0.00567603-0.002198760.000853091

1203 rows × 108 columns

Each f_n column corresponds to factor of the spectral decomposition of one interaction mode of the interaction matrix of one day.

# Load location data, because we need it to compute the CCA projectionloc_df=bb_network_decomposition.data.load_location_data(supplementary_data_path)
cca_factor_df, cca=bb_network_decomposition.projection.get_cca_projection(
factor_df, loc_df, return_cca=True, num_components=3
)
cca_factor_df.sort_values("date", inplace=True)

cca_factor_df now contains the network age for all individuals on all dates in the dataset.

The column network_age contains the first dimension of network age (used throughout most of the paper), and the second and third dimensions are stored in the columns network_age_1 and network_age_2.

factor_df.to_csv("network_age_cca.csv")
# list of variables to use as predictors in task allocation regression tasksvariable_names= [
["age"],
["age", "network_age"],
["network_age"],
["network_age", "network_age_1"],
["network_age", "network_age_1", "network_age_2"],
]
# list of variables to use as dependent variables in regression taskstargets= [bb_network_decomposition.constants.supplementary_labels] +list(
map(lambdal: [l], bb_network_decomposition.constants.supplementary_labels)
)
target_cols=bb_network_decomposition.constants.supplementary_labels
# load all required supplementary datasup_df=bb_network_decomposition.data.load_supplementary_data(
supplementary_data_path,
keepcols=bb_network_decomposition.constants.default_location_data_cols+bb_network_decomposition.constants.default_supplementary_data_cols+ ["location_descriptor_count"],
)
location_cols=set(bb_network_decomposition.constants.location_labels).union(
set(bb_network_decomposition.constants.location_cols)
)
# remove location data from network age dataframe so that we can safely merge in all# supplementary datacca_factor_df=cca_factor_df[
[cforcincca_factor_df.columnsifcnotinlocation_cols]
]
sup_df=bb_network_decomposition.data.merge_location_data(cca_factor_df, sup_df)
# regression tasks bootstrapregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df,
variable_names,
targets,
regression=True,
use_tqdm=True,
num_bootstrap_samples=8,
)

These results correspond to section 5 of the manuscript: Network age predicts an individual's behavior and future role in the colony

# results of bootstrap analysis, grouped by dependent and independent variables, R^2 scoresregression_results.groupby(["predictors", "target"]).fitted_linear_r2.mean()
predictors target
age circadian_rhythm 0.331907
circadian_rhythm,days_left,velocity_day,velocity_night 0.172621
days_left 0.012523
velocity_day 0.083986
velocity_night 0.286554
age,network_age circadian_rhythm 0.403065
circadian_rhythm,days_left,velocity_day,velocity_night 0.210112
days_left 0.015316
velocity_day 0.095954
velocity_night 0.292630
network_age circadian_rhythm 0.387444
circadian_rhythm,days_left,velocity_day,velocity_night 0.199390
days_left 0.010289
velocity_day 0.112123
velocity_night 0.243061
network_age,network_age_1 circadian_rhythm 0.390725
circadian_rhythm,days_left,velocity_day,velocity_night 0.227511
days_left 0.071366
velocity_day 0.112483
velocity_night 0.266663
network_age,network_age_1,network_age_2 circadian_rhythm 0.433800
circadian_rhythm,days_left,velocity_day,velocity_night 0.226100
days_left 0.065899
velocity_day 0.148080
velocity_night 0.260883
Name: fitted_linear_r2, dtype: float64
# multinomial regression for task allocation taskregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df, variable_names, regression=False, use_tqdm=True, num_bootstrap_samples=8,
)
# results of bootstrap analysis, grouped by dependent and independent variables, R_McF^2 scoresregression_results.groupby(["predictors", "target"]).rho_mcf_linear.mean()
predictors target
age brood_area_total 0.546260
dance_floor 0.417913
dance_floor,honey_storage,brood_area_total,near_exit 0.415424
honey_storage 0.026411
near_exit 0.314711
age,network_age brood_area_total 0.584782
dance_floor 0.512601
dance_floor,honey_storage,brood_area_total,near_exit 0.475106
honey_storage 0.051840
near_exit 0.376673
network_age brood_area_total 0.555143
dance_floor 0.477920
dance_floor,honey_storage,brood_area_total,near_exit 0.443385
honey_storage 0.003832
near_exit 0.357418
network_age,network_age_1 brood_area_total 0.577571
dance_floor 0.477131
dance_floor,honey_storage,brood_area_total,near_exit 0.462893
honey_storage 0.166705
near_exit 0.386814
network_age,network_age_1,network_age_2 brood_area_total 0.575683
dance_floor 0.499749
dance_floor,honey_storage,brood_area_total,near_exit 0.475821
honey_storage 0.160835
near_exit 0.445180
Name: rho_mcf_linear, dtype: float64

These results correspond to section 3 of the manuscript: Network age correctly identifies task allocation

Citation

Social networks predict the life and death of honey bees
Benjamin Wild, David M Dormagen, Adrian Zachariae, Michael L Smith, Kirsten S Traynor, Dirk Brockmann, Iain D Couzin, Tim Landgraf
bioRxiv 2020.05.06.076943; doi: https://doi.org/10.1101/2020.05.06.076943

About

Analyze social networks using spectral decomposition over time

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' GitHub - BioroboticsLab/bb_network_decomposition: Analyze social networks using spectral decomposition over time · GitHub
Skip to content

Repository files navigation

Note: A rendered version of this markdown readme file can be found here: github.com/BioroboticsLab/bb_network_decomposition

Social networks predict the life and death of honey bees

Analyze social networks using spectral decomposition over time.

Preprint: DOI 10.1101/2020.05.06.076943 Data: DOI 10.5281/zenodo.4438013

Usage example

This sample code showcases how to load the raw input data, calculate network age, and fit and evaluate the multinomial task regression and supplementary regression models.

importdatetimeimportpandasaspdimportnumpyasnp# https://github.com/BioroboticsLab/bb_network_decomposition# the module can be installed using pip:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_network_decomposition.git# the dependencies should be installed automatically:# https://github.com/BioroboticsLab/bb_network_decomposition/blob/master/requirements.txt# please note that you may have to install the dependency bb_utils manually:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_utils.gitimportbb_network_decompositionimportbb_network_decomposition.dataimportbb_network_decomposition.normalizationimportbb_network_decomposition.spectralimportbb_network_decomposition.projectionimportbb_network_decomposition.evaluation
# location of interaction network hdf5 fileraw_networks_path="zenodo/interaction_networks_20160729to20160827.h5"# location of bee metainfo (location descriptors, supplementary labels, ...)supplementary_data_path="zenodo/bee_daily_data.csv"# location of results of bayesian lifetime modelalive_path="zenodo/alive_bees_bayesian.csv"
# first date in the interaction tensor# used to match interaction data with supplementary data (locations, etc.)from_date=datetime.datetime(2016, 8, 12)
# number of days to use (incrase to reproduce paper results)num_days=1# load interaction data
(
interactions, # interaction tensorlabels, # names of interaction modes (proximity, trophallaxis, etc.)bee_ids, # unique BeesBook IDs of the individualsbee_ages, # tensor with ages of individuals over time
) =bb_network_decomposition.data.load_networks_h5(raw_networks_path, 0, num_days)
alive_df=bb_network_decomposition.data.load_alive_data(alive_path, bee_ids)
num_days=interactions.shape[0]
num_entities=interactions.shape[1]
num_modes=len(labels)
# number of spectral factors per interaction modenum_factors_per_mode=8
alive_matrices=bb_network_decomposition.data.get_daily_alive_matrices(
alive_df, num_days, num_entities, from_date
)
alive_matrices.shape
(1, 2010, 2010)

Boolean tensor containing lifetime data of every individual. Shape is Day x Inidividual x Individual.

If both individuals i and j were alive on day d, alive_matrices[d,i,j] is True.

interactions=bb_network_decomposition.normalization.rank_transform(
interactions, alive_matrices
)
interactions.shape
(1, 2010, 2010, 9)

Interaction strenghts of individuals over time. Shape is Day x Individual x Individual x Interaction mode.

labels
['proximity_counts',
'proximity_euclidean',
'proximity_rbf',
'velocity_pos_sum',
'velocity_neg_sum',
'velocity_pos_mean',
'velocity_neg_mean',
'trophallaxis_duration',
'trophallaxis_counts']

List of interaction modes in the same order as stored in interactions.

(
daily_factors,
num_factors_by_mode,
) =bb_network_decomposition.spectral.decomposition_by_day(
interactions, alive_matrices, num_factors_per_mode, num_jobs=4
)
daily_factors[0].shape
(2010, 104)

Spectral factors of interactions matrices over time before temporal alignment and CCA.

num_factors=daily_factors[0].shape[-1]
daily_factors_aligned=bb_network_decomposition.spectral.temporal_alignment(
daily_factors, alive_matrices
)

Spectral factors of interactions matrices over time after temporal alignment without CCA projection.

factor_df=bb_network_decomposition.data.get_factor_dataframe(
daily_factors_aligned, from_date, alive_df, bee_ids
)
factor_df
daydatebee_idagef_0f_1f_2f_3f_4f_5...f_94f_95f_96f_97f_98f_99f_100f_101f_102f_103
002016-08-122145-0.00724210.00314685-0.000766774-0.004236050.00082973-0.00254058...-0.000475807-0.01404020.00307980.0004382660.001079590.000104271-0.0006917950.000613057-0.000109924-0.000521939
102016-08-123945-0.00492436-0.00218363-0.00100829-0.00218637-0.001000590.00164908...-0.00290549-0.04439460.003473420.0002998580.000625530.000165619-0.000410046.26682e-05-0.000255383-0.000434362
202016-08-125945-0.005463520.000335544-0.00101128-0.003619590.004887990.00168936...-0.000275847-0.004856290.00108332-0.0003549530.000522480.00164634-0.0020490.00215299-0.004095160.00478023
302016-08-1217844-0.00129473-0.00042854-0.00443996-0.00169472-0.006091960.00286522...0.002574470.001067010.00191582-0.0004993890.0006594270.000257282-0.00259264-0.000812146-0.0004172690.00120451
402016-08-1219944-0.008276210.00464029-0.00073654-0.002505720.01109110.00379146...0.01690830.01181590.003241221.71778e-050.000502871-0.0019061-0.0009561350.001311780.000335653-0.000305509
..................................................................
119802016-08-12300410.005630970.00379659-0.00161652-0.0006765410.00236571-0.00542808...-0.004444120.00799384-0.00153584-0.002217960.0006548070.001758260.000222280.00097945-0.002379230.00154693
119902016-08-12300510.004821780.00242558-0.00278712-0.0002069290.00144706-0.000719776...0.00679757-0.000338297-0.003515840.001801670.0004625840.003039210.004347750.00354968-2.89882e-050.0117052
120002016-08-12300610.0062860.00478083-0.006039460.001926330.00080181-0.00546843...0.00212394-0.00339074-0.00372017-0.000963446-1.50815e-050.00101539-0.001304990.00107728-0.00114766-0.000493821
120102016-08-12300710.005020650.003500090.00158003-0.0008193858.74538e-050.00113418...0.0003666250.00208452-0.00438712-0.0004863560.001411150.00300085-0.000855138-0.00527713-0.0038038-0.00121933
120202016-08-12300810.005365170.00204567-0.00211659-0.000753905-0.0004564560.00402603...0.000891216-0.00229696-0.00692422-0.00129927-0.002518640.000189614-0.00128221-0.00567603-0.002198760.000853091

1203 rows × 108 columns

Each f_n column corresponds to factor of the spectral decomposition of one interaction mode of the interaction matrix of one day.

# Load location data, because we need it to compute the CCA projectionloc_df=bb_network_decomposition.data.load_location_data(supplementary_data_path)
cca_factor_df, cca=bb_network_decomposition.projection.get_cca_projection(
factor_df, loc_df, return_cca=True, num_components=3
)
cca_factor_df.sort_values("date", inplace=True)

cca_factor_df now contains the network age for all individuals on all dates in the dataset.

The column network_age contains the first dimension of network age (used throughout most of the paper), and the second and third dimensions are stored in the columns network_age_1 and network_age_2.

factor_df.to_csv("network_age_cca.csv")
# list of variables to use as predictors in task allocation regression tasksvariable_names= [
["age"],
["age", "network_age"],
["network_age"],
["network_age", "network_age_1"],
["network_age", "network_age_1", "network_age_2"],
]
# list of variables to use as dependent variables in regression taskstargets= [bb_network_decomposition.constants.supplementary_labels] +list(
map(lambdal: [l], bb_network_decomposition.constants.supplementary_labels)
)
target_cols=bb_network_decomposition.constants.supplementary_labels
# load all required supplementary datasup_df=bb_network_decomposition.data.load_supplementary_data(
supplementary_data_path,
keepcols=bb_network_decomposition.constants.default_location_data_cols+bb_network_decomposition.constants.default_supplementary_data_cols+ ["location_descriptor_count"],
)
location_cols=set(bb_network_decomposition.constants.location_labels).union(
set(bb_network_decomposition.constants.location_cols)
)
# remove location data from network age dataframe so that we can safely merge in all# supplementary datacca_factor_df=cca_factor_df[
[cforcincca_factor_df.columnsifcnotinlocation_cols]
]
sup_df=bb_network_decomposition.data.merge_location_data(cca_factor_df, sup_df)
# regression tasks bootstrapregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df,
variable_names,
targets,
regression=True,
use_tqdm=True,
num_bootstrap_samples=8,
)

These results correspond to section 5 of the manuscript: Network age predicts an individual's behavior and future role in the colony

# results of bootstrap analysis, grouped by dependent and independent variables, R^2 scoresregression_results.groupby(["predictors", "target"]).fitted_linear_r2.mean()
predictors target
age circadian_rhythm 0.331907
circadian_rhythm,days_left,velocity_day,velocity_night 0.172621
days_left 0.012523
velocity_day 0.083986
velocity_night 0.286554
age,network_age circadian_rhythm 0.403065
circadian_rhythm,days_left,velocity_day,velocity_night 0.210112
days_left 0.015316
velocity_day 0.095954
velocity_night 0.292630
network_age circadian_rhythm 0.387444
circadian_rhythm,days_left,velocity_day,velocity_night 0.199390
days_left 0.010289
velocity_day 0.112123
velocity_night 0.243061
network_age,network_age_1 circadian_rhythm 0.390725
circadian_rhythm,days_left,velocity_day,velocity_night 0.227511
days_left 0.071366
velocity_day 0.112483
velocity_night 0.266663
network_age,network_age_1,network_age_2 circadian_rhythm 0.433800
circadian_rhythm,days_left,velocity_day,velocity_night 0.226100
days_left 0.065899
velocity_day 0.148080
velocity_night 0.260883
Name: fitted_linear_r2, dtype: float64
# multinomial regression for task allocation taskregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df, variable_names, regression=False, use_tqdm=True, num_bootstrap_samples=8,
)
# results of bootstrap analysis, grouped by dependent and independent variables, R_McF^2 scoresregression_results.groupby(["predictors", "target"]).rho_mcf_linear.mean()
predictors target
age brood_area_total 0.546260
dance_floor 0.417913
dance_floor,honey_storage,brood_area_total,near_exit 0.415424
honey_storage 0.026411
near_exit 0.314711
age,network_age brood_area_total 0.584782
dance_floor 0.512601
dance_floor,honey_storage,brood_area_total,near_exit 0.475106
honey_storage 0.051840
near_exit 0.376673
network_age brood_area_total 0.555143
dance_floor 0.477920
dance_floor,honey_storage,brood_area_total,near_exit 0.443385
honey_storage 0.003832
near_exit 0.357418
network_age,network_age_1 brood_area_total 0.577571
dance_floor 0.477131
dance_floor,honey_storage,brood_area_total,near_exit 0.462893
honey_storage 0.166705
near_exit 0.386814
network_age,network_age_1,network_age_2 brood_area_total 0.575683
dance_floor 0.499749
dance_floor,honey_storage,brood_area_total,near_exit 0.475821
honey_storage 0.160835
near_exit 0.445180
Name: rho_mcf_linear, dtype: float64

These results correspond to section 3 of the manuscript: Network age correctly identifies task allocation

Citation

Social networks predict the life and death of honey bees
Benjamin Wild, David M Dormagen, Adrian Zachariae, Michael L Smith, Kirsten S Traynor, Dirk Brockmann, Iain D Couzin, Tim Landgraf
bioRxiv 2020.05.06.076943; doi: https://doi.org/10.1101/2020.05.06.076943

About

Analyze social networks using spectral decomposition over time

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - BioroboticsLab/bb_network_decomposition: Analyze social networks using spectral decomposition over time · GitHub
Skip to content

Repository files navigation

Note: A rendered version of this markdown readme file can be found here: github.com/BioroboticsLab/bb_network_decomposition

Social networks predict the life and death of honey bees

Analyze social networks using spectral decomposition over time.

Preprint: DOI 10.1101/2020.05.06.076943 Data: DOI 10.5281/zenodo.4438013

Usage example

This sample code showcases how to load the raw input data, calculate network age, and fit and evaluate the multinomial task regression and supplementary regression models.

importdatetimeimportpandasaspdimportnumpyasnp# https://github.com/BioroboticsLab/bb_network_decomposition# the module can be installed using pip:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_network_decomposition.git# the dependencies should be installed automatically:# https://github.com/BioroboticsLab/bb_network_decomposition/blob/master/requirements.txt# please note that you may have to install the dependency bb_utils manually:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_utils.gitimportbb_network_decompositionimportbb_network_decomposition.dataimportbb_network_decomposition.normalizationimportbb_network_decomposition.spectralimportbb_network_decomposition.projectionimportbb_network_decomposition.evaluation
# location of interaction network hdf5 fileraw_networks_path="zenodo/interaction_networks_20160729to20160827.h5"# location of bee metainfo (location descriptors, supplementary labels, ...)supplementary_data_path="zenodo/bee_daily_data.csv"# location of results of bayesian lifetime modelalive_path="zenodo/alive_bees_bayesian.csv"
# first date in the interaction tensor# used to match interaction data with supplementary data (locations, etc.)from_date=datetime.datetime(2016, 8, 12)
# number of days to use (incrase to reproduce paper results)num_days=1# load interaction data
(
interactions, # interaction tensorlabels, # names of interaction modes (proximity, trophallaxis, etc.)bee_ids, # unique BeesBook IDs of the individualsbee_ages, # tensor with ages of individuals over time
) =bb_network_decomposition.data.load_networks_h5(raw_networks_path, 0, num_days)
alive_df=bb_network_decomposition.data.load_alive_data(alive_path, bee_ids)
num_days=interactions.shape[0]
num_entities=interactions.shape[1]
num_modes=len(labels)
# number of spectral factors per interaction modenum_factors_per_mode=8
alive_matrices=bb_network_decomposition.data.get_daily_alive_matrices(
alive_df, num_days, num_entities, from_date
)
alive_matrices.shape
(1, 2010, 2010)

Boolean tensor containing lifetime data of every individual. Shape is Day x Inidividual x Individual.

If both individuals i and j were alive on day d, alive_matrices[d,i,j] is True.

interactions=bb_network_decomposition.normalization.rank_transform(
interactions, alive_matrices
)
interactions.shape
(1, 2010, 2010, 9)

Interaction strenghts of individuals over time. Shape is Day x Individual x Individual x Interaction mode.

labels
['proximity_counts',
'proximity_euclidean',
'proximity_rbf',
'velocity_pos_sum',
'velocity_neg_sum',
'velocity_pos_mean',
'velocity_neg_mean',
'trophallaxis_duration',
'trophallaxis_counts']

List of interaction modes in the same order as stored in interactions.

(
daily_factors,
num_factors_by_mode,
) =bb_network_decomposition.spectral.decomposition_by_day(
interactions, alive_matrices, num_factors_per_mode, num_jobs=4
)
daily_factors[0].shape
(2010, 104)

Spectral factors of interactions matrices over time before temporal alignment and CCA.

num_factors=daily_factors[0].shape[-1]
daily_factors_aligned=bb_network_decomposition.spectral.temporal_alignment(
daily_factors, alive_matrices
)

Spectral factors of interactions matrices over time after temporal alignment without CCA projection.

factor_df=bb_network_decomposition.data.get_factor_dataframe(
daily_factors_aligned, from_date, alive_df, bee_ids
)
factor_df
daydatebee_idagef_0f_1f_2f_3f_4f_5...f_94f_95f_96f_97f_98f_99f_100f_101f_102f_103
002016-08-122145-0.00724210.00314685-0.000766774-0.004236050.00082973-0.00254058...-0.000475807-0.01404020.00307980.0004382660.001079590.000104271-0.0006917950.000613057-0.000109924-0.000521939
102016-08-123945-0.00492436-0.00218363-0.00100829-0.00218637-0.001000590.00164908...-0.00290549-0.04439460.003473420.0002998580.000625530.000165619-0.000410046.26682e-05-0.000255383-0.000434362
202016-08-125945-0.005463520.000335544-0.00101128-0.003619590.004887990.00168936...-0.000275847-0.004856290.00108332-0.0003549530.000522480.00164634-0.0020490.00215299-0.004095160.00478023
302016-08-1217844-0.00129473-0.00042854-0.00443996-0.00169472-0.006091960.00286522...0.002574470.001067010.00191582-0.0004993890.0006594270.000257282-0.00259264-0.000812146-0.0004172690.00120451
402016-08-1219944-0.008276210.00464029-0.00073654-0.002505720.01109110.00379146...0.01690830.01181590.003241221.71778e-050.000502871-0.0019061-0.0009561350.001311780.000335653-0.000305509
..................................................................
119802016-08-12300410.005630970.00379659-0.00161652-0.0006765410.00236571-0.00542808...-0.004444120.00799384-0.00153584-0.002217960.0006548070.001758260.000222280.00097945-0.002379230.00154693
119902016-08-12300510.004821780.00242558-0.00278712-0.0002069290.00144706-0.000719776...0.00679757-0.000338297-0.003515840.001801670.0004625840.003039210.004347750.00354968-2.89882e-050.0117052
120002016-08-12300610.0062860.00478083-0.006039460.001926330.00080181-0.00546843...0.00212394-0.00339074-0.00372017-0.000963446-1.50815e-050.00101539-0.001304990.00107728-0.00114766-0.000493821
120102016-08-12300710.005020650.003500090.00158003-0.0008193858.74538e-050.00113418...0.0003666250.00208452-0.00438712-0.0004863560.001411150.00300085-0.000855138-0.00527713-0.0038038-0.00121933
120202016-08-12300810.005365170.00204567-0.00211659-0.000753905-0.0004564560.00402603...0.000891216-0.00229696-0.00692422-0.00129927-0.002518640.000189614-0.00128221-0.00567603-0.002198760.000853091

1203 rows × 108 columns

Each f_n column corresponds to factor of the spectral decomposition of one interaction mode of the interaction matrix of one day.

# Load location data, because we need it to compute the CCA projectionloc_df=bb_network_decomposition.data.load_location_data(supplementary_data_path)
cca_factor_df, cca=bb_network_decomposition.projection.get_cca_projection(
factor_df, loc_df, return_cca=True, num_components=3
)
cca_factor_df.sort_values("date", inplace=True)

cca_factor_df now contains the network age for all individuals on all dates in the dataset.

The column network_age contains the first dimension of network age (used throughout most of the paper), and the second and third dimensions are stored in the columns network_age_1 and network_age_2.

factor_df.to_csv("network_age_cca.csv")
# list of variables to use as predictors in task allocation regression tasksvariable_names= [
["age"],
["age", "network_age"],
["network_age"],
["network_age", "network_age_1"],
["network_age", "network_age_1", "network_age_2"],
]
# list of variables to use as dependent variables in regression taskstargets= [bb_network_decomposition.constants.supplementary_labels] +list(
map(lambdal: [l], bb_network_decomposition.constants.supplementary_labels)
)
target_cols=bb_network_decomposition.constants.supplementary_labels
# load all required supplementary datasup_df=bb_network_decomposition.data.load_supplementary_data(
supplementary_data_path,
keepcols=bb_network_decomposition.constants.default_location_data_cols+bb_network_decomposition.constants.default_supplementary_data_cols+ ["location_descriptor_count"],
)
location_cols=set(bb_network_decomposition.constants.location_labels).union(
set(bb_network_decomposition.constants.location_cols)
)
# remove location data from network age dataframe so that we can safely merge in all# supplementary datacca_factor_df=cca_factor_df[
[cforcincca_factor_df.columnsifcnotinlocation_cols]
]
sup_df=bb_network_decomposition.data.merge_location_data(cca_factor_df, sup_df)
# regression tasks bootstrapregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df,
variable_names,
targets,
regression=True,
use_tqdm=True,
num_bootstrap_samples=8,
)

These results correspond to section 5 of the manuscript: Network age predicts an individual's behavior and future role in the colony

# results of bootstrap analysis, grouped by dependent and independent variables, R^2 scoresregression_results.groupby(["predictors", "target"]).fitted_linear_r2.mean()
predictors target
age circadian_rhythm 0.331907
circadian_rhythm,days_left,velocity_day,velocity_night 0.172621
days_left 0.012523
velocity_day 0.083986
velocity_night 0.286554
age,network_age circadian_rhythm 0.403065
circadian_rhythm,days_left,velocity_day,velocity_night 0.210112
days_left 0.015316
velocity_day 0.095954
velocity_night 0.292630
network_age circadian_rhythm 0.387444
circadian_rhythm,days_left,velocity_day,velocity_night 0.199390
days_left 0.010289
velocity_day 0.112123
velocity_night 0.243061
network_age,network_age_1 circadian_rhythm 0.390725
circadian_rhythm,days_left,velocity_day,velocity_night 0.227511
days_left 0.071366
velocity_day 0.112483
velocity_night 0.266663
network_age,network_age_1,network_age_2 circadian_rhythm 0.433800
circadian_rhythm,days_left,velocity_day,velocity_night 0.226100
days_left 0.065899
velocity_day 0.148080
velocity_night 0.260883
Name: fitted_linear_r2, dtype: float64
# multinomial regression for task allocation taskregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df, variable_names, regression=False, use_tqdm=True, num_bootstrap_samples=8,
)
# results of bootstrap analysis, grouped by dependent and independent variables, R_McF^2 scoresregression_results.groupby(["predictors", "target"]).rho_mcf_linear.mean()
predictors target
age brood_area_total 0.546260
dance_floor 0.417913
dance_floor,honey_storage,brood_area_total,near_exit 0.415424
honey_storage 0.026411
near_exit 0.314711
age,network_age brood_area_total 0.584782
dance_floor 0.512601
dance_floor,honey_storage,brood_area_total,near_exit 0.475106
honey_storage 0.051840
near_exit 0.376673
network_age brood_area_total 0.555143
dance_floor 0.477920
dance_floor,honey_storage,brood_area_total,near_exit 0.443385
honey_storage 0.003832
near_exit 0.357418
network_age,network_age_1 brood_area_total 0.577571
dance_floor 0.477131
dance_floor,honey_storage,brood_area_total,near_exit 0.462893
honey_storage 0.166705
near_exit 0.386814
network_age,network_age_1,network_age_2 brood_area_total 0.575683
dance_floor 0.499749
dance_floor,honey_storage,brood_area_total,near_exit 0.475821
honey_storage 0.160835
near_exit 0.445180
Name: rho_mcf_linear, dtype: float64

These results correspond to section 3 of the manuscript: Network age correctly identifies task allocation

Citation

Social networks predict the life and death of honey bees
Benjamin Wild, David M Dormagen, Adrian Zachariae, Michael L Smith, Kirsten S Traynor, Dirk Brockmann, Iain D Couzin, Tim Landgraf
bioRxiv 2020.05.06.076943; doi: https://doi.org/10.1101/2020.05.06.076943

About

Analyze social networks using spectral decomposition over time

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - BioroboticsLab/bb_network_decomposition: Analyze social networks using spectral decomposition over time · GitHub
Skip to content

Repository files navigation

Note: A rendered version of this markdown readme file can be found here: github.com/BioroboticsLab/bb_network_decomposition

Social networks predict the life and death of honey bees

Analyze social networks using spectral decomposition over time.

Preprint: DOI 10.1101/2020.05.06.076943 Data: DOI 10.5281/zenodo.4438013

Usage example

This sample code showcases how to load the raw input data, calculate network age, and fit and evaluate the multinomial task regression and supplementary regression models.

importdatetimeimportpandasaspdimportnumpyasnp# https://github.com/BioroboticsLab/bb_network_decomposition# the module can be installed using pip:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_network_decomposition.git# the dependencies should be installed automatically:# https://github.com/BioroboticsLab/bb_network_decomposition/blob/master/requirements.txt# please note that you may have to install the dependency bb_utils manually:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_utils.gitimportbb_network_decompositionimportbb_network_decomposition.dataimportbb_network_decomposition.normalizationimportbb_network_decomposition.spectralimportbb_network_decomposition.projectionimportbb_network_decomposition.evaluation
# location of interaction network hdf5 fileraw_networks_path="zenodo/interaction_networks_20160729to20160827.h5"# location of bee metainfo (location descriptors, supplementary labels, ...)supplementary_data_path="zenodo/bee_daily_data.csv"# location of results of bayesian lifetime modelalive_path="zenodo/alive_bees_bayesian.csv"
# first date in the interaction tensor# used to match interaction data with supplementary data (locations, etc.)from_date=datetime.datetime(2016, 8, 12)
# number of days to use (incrase to reproduce paper results)num_days=1# load interaction data
(
interactions, # interaction tensorlabels, # names of interaction modes (proximity, trophallaxis, etc.)bee_ids, # unique BeesBook IDs of the individualsbee_ages, # tensor with ages of individuals over time
) =bb_network_decomposition.data.load_networks_h5(raw_networks_path, 0, num_days)
alive_df=bb_network_decomposition.data.load_alive_data(alive_path, bee_ids)
num_days=interactions.shape[0]
num_entities=interactions.shape[1]
num_modes=len(labels)
# number of spectral factors per interaction modenum_factors_per_mode=8
alive_matrices=bb_network_decomposition.data.get_daily_alive_matrices(
alive_df, num_days, num_entities, from_date
)
alive_matrices.shape
(1, 2010, 2010)

Boolean tensor containing lifetime data of every individual. Shape is Day x Inidividual x Individual.

If both individuals i and j were alive on day d, alive_matrices[d,i,j] is True.

interactions=bb_network_decomposition.normalization.rank_transform(
interactions, alive_matrices
)
interactions.shape
(1, 2010, 2010, 9)

Interaction strenghts of individuals over time. Shape is Day x Individual x Individual x Interaction mode.

labels
['proximity_counts',
'proximity_euclidean',
'proximity_rbf',
'velocity_pos_sum',
'velocity_neg_sum',
'velocity_pos_mean',
'velocity_neg_mean',
'trophallaxis_duration',
'trophallaxis_counts']

List of interaction modes in the same order as stored in interactions.

(
daily_factors,
num_factors_by_mode,
) =bb_network_decomposition.spectral.decomposition_by_day(
interactions, alive_matrices, num_factors_per_mode, num_jobs=4
)
daily_factors[0].shape
(2010, 104)

Spectral factors of interactions matrices over time before temporal alignment and CCA.

num_factors=daily_factors[0].shape[-1]
daily_factors_aligned=bb_network_decomposition.spectral.temporal_alignment(
daily_factors, alive_matrices
)

Spectral factors of interactions matrices over time after temporal alignment without CCA projection.

factor_df=bb_network_decomposition.data.get_factor_dataframe(
daily_factors_aligned, from_date, alive_df, bee_ids
)
factor_df
daydatebee_idagef_0f_1f_2f_3f_4f_5...f_94f_95f_96f_97f_98f_99f_100f_101f_102f_103
002016-08-122145-0.00724210.00314685-0.000766774-0.004236050.00082973-0.00254058...-0.000475807-0.01404020.00307980.0004382660.001079590.000104271-0.0006917950.000613057-0.000109924-0.000521939
102016-08-123945-0.00492436-0.00218363-0.00100829-0.00218637-0.001000590.00164908...-0.00290549-0.04439460.003473420.0002998580.000625530.000165619-0.000410046.26682e-05-0.000255383-0.000434362
202016-08-125945-0.005463520.000335544-0.00101128-0.003619590.004887990.00168936...-0.000275847-0.004856290.00108332-0.0003549530.000522480.00164634-0.0020490.00215299-0.004095160.00478023
302016-08-1217844-0.00129473-0.00042854-0.00443996-0.00169472-0.006091960.00286522...0.002574470.001067010.00191582-0.0004993890.0006594270.000257282-0.00259264-0.000812146-0.0004172690.00120451
402016-08-1219944-0.008276210.00464029-0.00073654-0.002505720.01109110.00379146...0.01690830.01181590.003241221.71778e-050.000502871-0.0019061-0.0009561350.001311780.000335653-0.000305509
..................................................................
119802016-08-12300410.005630970.00379659-0.00161652-0.0006765410.00236571-0.00542808...-0.004444120.00799384-0.00153584-0.002217960.0006548070.001758260.000222280.00097945-0.002379230.00154693
119902016-08-12300510.004821780.00242558-0.00278712-0.0002069290.00144706-0.000719776...0.00679757-0.000338297-0.003515840.001801670.0004625840.003039210.004347750.00354968-2.89882e-050.0117052
120002016-08-12300610.0062860.00478083-0.006039460.001926330.00080181-0.00546843...0.00212394-0.00339074-0.00372017-0.000963446-1.50815e-050.00101539-0.001304990.00107728-0.00114766-0.000493821
120102016-08-12300710.005020650.003500090.00158003-0.0008193858.74538e-050.00113418...0.0003666250.00208452-0.00438712-0.0004863560.001411150.00300085-0.000855138-0.00527713-0.0038038-0.00121933
120202016-08-12300810.005365170.00204567-0.00211659-0.000753905-0.0004564560.00402603...0.000891216-0.00229696-0.00692422-0.00129927-0.002518640.000189614-0.00128221-0.00567603-0.002198760.000853091

1203 rows × 108 columns

Each f_n column corresponds to factor of the spectral decomposition of one interaction mode of the interaction matrix of one day.

# Load location data, because we need it to compute the CCA projectionloc_df=bb_network_decomposition.data.load_location_data(supplementary_data_path)
cca_factor_df, cca=bb_network_decomposition.projection.get_cca_projection(
factor_df, loc_df, return_cca=True, num_components=3
)
cca_factor_df.sort_values("date", inplace=True)

cca_factor_df now contains the network age for all individuals on all dates in the dataset.

The column network_age contains the first dimension of network age (used throughout most of the paper), and the second and third dimensions are stored in the columns network_age_1 and network_age_2.

factor_df.to_csv("network_age_cca.csv")
# list of variables to use as predictors in task allocation regression tasksvariable_names= [
["age"],
["age", "network_age"],
["network_age"],
["network_age", "network_age_1"],
["network_age", "network_age_1", "network_age_2"],
]
# list of variables to use as dependent variables in regression taskstargets= [bb_network_decomposition.constants.supplementary_labels] +list(
map(lambdal: [l], bb_network_decomposition.constants.supplementary_labels)
)
target_cols=bb_network_decomposition.constants.supplementary_labels
# load all required supplementary datasup_df=bb_network_decomposition.data.load_supplementary_data(
supplementary_data_path,
keepcols=bb_network_decomposition.constants.default_location_data_cols+bb_network_decomposition.constants.default_supplementary_data_cols+ ["location_descriptor_count"],
)
location_cols=set(bb_network_decomposition.constants.location_labels).union(
set(bb_network_decomposition.constants.location_cols)
)
# remove location data from network age dataframe so that we can safely merge in all# supplementary datacca_factor_df=cca_factor_df[
[cforcincca_factor_df.columnsifcnotinlocation_cols]
]
sup_df=bb_network_decomposition.data.merge_location_data(cca_factor_df, sup_df)
# regression tasks bootstrapregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df,
variable_names,
targets,
regression=True,
use_tqdm=True,
num_bootstrap_samples=8,
)

These results correspond to section 5 of the manuscript: Network age predicts an individual's behavior and future role in the colony

# results of bootstrap analysis, grouped by dependent and independent variables, R^2 scoresregression_results.groupby(["predictors", "target"]).fitted_linear_r2.mean()
predictors target
age circadian_rhythm 0.331907
circadian_rhythm,days_left,velocity_day,velocity_night 0.172621
days_left 0.012523
velocity_day 0.083986
velocity_night 0.286554
age,network_age circadian_rhythm 0.403065
circadian_rhythm,days_left,velocity_day,velocity_night 0.210112
days_left 0.015316
velocity_day 0.095954
velocity_night 0.292630
network_age circadian_rhythm 0.387444
circadian_rhythm,days_left,velocity_day,velocity_night 0.199390
days_left 0.010289
velocity_day 0.112123
velocity_night 0.243061
network_age,network_age_1 circadian_rhythm 0.390725
circadian_rhythm,days_left,velocity_day,velocity_night 0.227511
days_left 0.071366
velocity_day 0.112483
velocity_night 0.266663
network_age,network_age_1,network_age_2 circadian_rhythm 0.433800
circadian_rhythm,days_left,velocity_day,velocity_night 0.226100
days_left 0.065899
velocity_day 0.148080
velocity_night 0.260883
Name: fitted_linear_r2, dtype: float64
# multinomial regression for task allocation taskregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df, variable_names, regression=False, use_tqdm=True, num_bootstrap_samples=8,
)
# results of bootstrap analysis, grouped by dependent and independent variables, R_McF^2 scoresregression_results.groupby(["predictors", "target"]).rho_mcf_linear.mean()
predictors target
age brood_area_total 0.546260
dance_floor 0.417913
dance_floor,honey_storage,brood_area_total,near_exit 0.415424
honey_storage 0.026411
near_exit 0.314711
age,network_age brood_area_total 0.584782
dance_floor 0.512601
dance_floor,honey_storage,brood_area_total,near_exit 0.475106
honey_storage 0.051840
near_exit 0.376673
network_age brood_area_total 0.555143
dance_floor 0.477920
dance_floor,honey_storage,brood_area_total,near_exit 0.443385
honey_storage 0.003832
near_exit 0.357418
network_age,network_age_1 brood_area_total 0.577571
dance_floor 0.477131
dance_floor,honey_storage,brood_area_total,near_exit 0.462893
honey_storage 0.166705
near_exit 0.386814
network_age,network_age_1,network_age_2 brood_area_total 0.575683
dance_floor 0.499749
dance_floor,honey_storage,brood_area_total,near_exit 0.475821
honey_storage 0.160835
near_exit 0.445180
Name: rho_mcf_linear, dtype: float64

These results correspond to section 3 of the manuscript: Network age correctly identifies task allocation

Citation

Social networks predict the life and death of honey bees
Benjamin Wild, David M Dormagen, Adrian Zachariae, Michael L Smith, Kirsten S Traynor, Dirk Brockmann, Iain D Couzin, Tim Landgraf
bioRxiv 2020.05.06.076943; doi: https://doi.org/10.1101/2020.05.06.076943

About

Analyze social networks using spectral decomposition over time

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); GitHub - BioroboticsLab/bb_network_decomposition: Analyze social networks using spectral decomposition over time · GitHub
Skip to content

Repository files navigation

Note: A rendered version of this markdown readme file can be found here: github.com/BioroboticsLab/bb_network_decomposition

Social networks predict the life and death of honey bees

Analyze social networks using spectral decomposition over time.

Preprint: DOI 10.1101/2020.05.06.076943 Data: DOI 10.5281/zenodo.4438013

Usage example

This sample code showcases how to load the raw input data, calculate network age, and fit and evaluate the multinomial task regression and supplementary regression models.

importdatetimeimportpandasaspdimportnumpyasnp# https://github.com/BioroboticsLab/bb_network_decomposition# the module can be installed using pip:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_network_decomposition.git# the dependencies should be installed automatically:# https://github.com/BioroboticsLab/bb_network_decomposition/blob/master/requirements.txt# please note that you may have to install the dependency bb_utils manually:# $ pip3 install --user git+https://github.com/BioroboticsLab/bb_utils.gitimportbb_network_decompositionimportbb_network_decomposition.dataimportbb_network_decomposition.normalizationimportbb_network_decomposition.spectralimportbb_network_decomposition.projectionimportbb_network_decomposition.evaluation
# location of interaction network hdf5 fileraw_networks_path="zenodo/interaction_networks_20160729to20160827.h5"# location of bee metainfo (location descriptors, supplementary labels, ...)supplementary_data_path="zenodo/bee_daily_data.csv"# location of results of bayesian lifetime modelalive_path="zenodo/alive_bees_bayesian.csv"
# first date in the interaction tensor# used to match interaction data with supplementary data (locations, etc.)from_date=datetime.datetime(2016, 8, 12)
# number of days to use (incrase to reproduce paper results)num_days=1# load interaction data
(
interactions, # interaction tensorlabels, # names of interaction modes (proximity, trophallaxis, etc.)bee_ids, # unique BeesBook IDs of the individualsbee_ages, # tensor with ages of individuals over time
) =bb_network_decomposition.data.load_networks_h5(raw_networks_path, 0, num_days)
alive_df=bb_network_decomposition.data.load_alive_data(alive_path, bee_ids)
num_days=interactions.shape[0]
num_entities=interactions.shape[1]
num_modes=len(labels)
# number of spectral factors per interaction modenum_factors_per_mode=8
alive_matrices=bb_network_decomposition.data.get_daily_alive_matrices(
alive_df, num_days, num_entities, from_date
)
alive_matrices.shape
(1, 2010, 2010)

Boolean tensor containing lifetime data of every individual. Shape is Day x Inidividual x Individual.

If both individuals i and j were alive on day d, alive_matrices[d,i,j] is True.

interactions=bb_network_decomposition.normalization.rank_transform(
interactions, alive_matrices
)
interactions.shape
(1, 2010, 2010, 9)

Interaction strenghts of individuals over time. Shape is Day x Individual x Individual x Interaction mode.

labels
['proximity_counts',
'proximity_euclidean',
'proximity_rbf',
'velocity_pos_sum',
'velocity_neg_sum',
'velocity_pos_mean',
'velocity_neg_mean',
'trophallaxis_duration',
'trophallaxis_counts']

List of interaction modes in the same order as stored in interactions.

(
daily_factors,
num_factors_by_mode,
) =bb_network_decomposition.spectral.decomposition_by_day(
interactions, alive_matrices, num_factors_per_mode, num_jobs=4
)
daily_factors[0].shape
(2010, 104)

Spectral factors of interactions matrices over time before temporal alignment and CCA.

num_factors=daily_factors[0].shape[-1]
daily_factors_aligned=bb_network_decomposition.spectral.temporal_alignment(
daily_factors, alive_matrices
)

Spectral factors of interactions matrices over time after temporal alignment without CCA projection.

factor_df=bb_network_decomposition.data.get_factor_dataframe(
daily_factors_aligned, from_date, alive_df, bee_ids
)
factor_df
daydatebee_idagef_0f_1f_2f_3f_4f_5...f_94f_95f_96f_97f_98f_99f_100f_101f_102f_103
002016-08-122145-0.00724210.00314685-0.000766774-0.004236050.00082973-0.00254058...-0.000475807-0.01404020.00307980.0004382660.001079590.000104271-0.0006917950.000613057-0.000109924-0.000521939
102016-08-123945-0.00492436-0.00218363-0.00100829-0.00218637-0.001000590.00164908...-0.00290549-0.04439460.003473420.0002998580.000625530.000165619-0.000410046.26682e-05-0.000255383-0.000434362
202016-08-125945-0.005463520.000335544-0.00101128-0.003619590.004887990.00168936...-0.000275847-0.004856290.00108332-0.0003549530.000522480.00164634-0.0020490.00215299-0.004095160.00478023
302016-08-1217844-0.00129473-0.00042854-0.00443996-0.00169472-0.006091960.00286522...0.002574470.001067010.00191582-0.0004993890.0006594270.000257282-0.00259264-0.000812146-0.0004172690.00120451
402016-08-1219944-0.008276210.00464029-0.00073654-0.002505720.01109110.00379146...0.01690830.01181590.003241221.71778e-050.000502871-0.0019061-0.0009561350.001311780.000335653-0.000305509
..................................................................
119802016-08-12300410.005630970.00379659-0.00161652-0.0006765410.00236571-0.00542808...-0.004444120.00799384-0.00153584-0.002217960.0006548070.001758260.000222280.00097945-0.002379230.00154693
119902016-08-12300510.004821780.00242558-0.00278712-0.0002069290.00144706-0.000719776...0.00679757-0.000338297-0.003515840.001801670.0004625840.003039210.004347750.00354968-2.89882e-050.0117052
120002016-08-12300610.0062860.00478083-0.006039460.001926330.00080181-0.00546843...0.00212394-0.00339074-0.00372017-0.000963446-1.50815e-050.00101539-0.001304990.00107728-0.00114766-0.000493821
120102016-08-12300710.005020650.003500090.00158003-0.0008193858.74538e-050.00113418...0.0003666250.00208452-0.00438712-0.0004863560.001411150.00300085-0.000855138-0.00527713-0.0038038-0.00121933
120202016-08-12300810.005365170.00204567-0.00211659-0.000753905-0.0004564560.00402603...0.000891216-0.00229696-0.00692422-0.00129927-0.002518640.000189614-0.00128221-0.00567603-0.002198760.000853091

1203 rows × 108 columns

Each f_n column corresponds to factor of the spectral decomposition of one interaction mode of the interaction matrix of one day.

# Load location data, because we need it to compute the CCA projectionloc_df=bb_network_decomposition.data.load_location_data(supplementary_data_path)
cca_factor_df, cca=bb_network_decomposition.projection.get_cca_projection(
factor_df, loc_df, return_cca=True, num_components=3
)
cca_factor_df.sort_values("date", inplace=True)

cca_factor_df now contains the network age for all individuals on all dates in the dataset.

The column network_age contains the first dimension of network age (used throughout most of the paper), and the second and third dimensions are stored in the columns network_age_1 and network_age_2.

factor_df.to_csv("network_age_cca.csv")
# list of variables to use as predictors in task allocation regression tasksvariable_names= [
["age"],
["age", "network_age"],
["network_age"],
["network_age", "network_age_1"],
["network_age", "network_age_1", "network_age_2"],
]
# list of variables to use as dependent variables in regression taskstargets= [bb_network_decomposition.constants.supplementary_labels] +list(
map(lambdal: [l], bb_network_decomposition.constants.supplementary_labels)
)
target_cols=bb_network_decomposition.constants.supplementary_labels
# load all required supplementary datasup_df=bb_network_decomposition.data.load_supplementary_data(
supplementary_data_path,
keepcols=bb_network_decomposition.constants.default_location_data_cols+bb_network_decomposition.constants.default_supplementary_data_cols+ ["location_descriptor_count"],
)
location_cols=set(bb_network_decomposition.constants.location_labels).union(
set(bb_network_decomposition.constants.location_cols)
)
# remove location data from network age dataframe so that we can safely merge in all# supplementary datacca_factor_df=cca_factor_df[
[cforcincca_factor_df.columnsifcnotinlocation_cols]
]
sup_df=bb_network_decomposition.data.merge_location_data(cca_factor_df, sup_df)
# regression tasks bootstrapregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df,
variable_names,
targets,
regression=True,
use_tqdm=True,
num_bootstrap_samples=8,
)

These results correspond to section 5 of the manuscript: Network age predicts an individual's behavior and future role in the colony

# results of bootstrap analysis, grouped by dependent and independent variables, R^2 scoresregression_results.groupby(["predictors", "target"]).fitted_linear_r2.mean()
predictors target
age circadian_rhythm 0.331907
circadian_rhythm,days_left,velocity_day,velocity_night 0.172621
days_left 0.012523
velocity_day 0.083986
velocity_night 0.286554
age,network_age circadian_rhythm 0.403065
circadian_rhythm,days_left,velocity_day,velocity_night 0.210112
days_left 0.015316
velocity_day 0.095954
velocity_night 0.292630
network_age circadian_rhythm 0.387444
circadian_rhythm,days_left,velocity_day,velocity_night 0.199390
days_left 0.010289
velocity_day 0.112123
velocity_night 0.243061
network_age,network_age_1 circadian_rhythm 0.390725
circadian_rhythm,days_left,velocity_day,velocity_night 0.227511
days_left 0.071366
velocity_day 0.112483
velocity_night 0.266663
network_age,network_age_1,network_age_2 circadian_rhythm 0.433800
circadian_rhythm,days_left,velocity_day,velocity_night 0.226100
days_left 0.065899
velocity_day 0.148080
velocity_night 0.260883
Name: fitted_linear_r2, dtype: float64
# multinomial regression for task allocation taskregression_results=bb_network_decomposition.evaluation.get_bootstrap_results(
sup_df, variable_names, regression=False, use_tqdm=True, num_bootstrap_samples=8,
)
# results of bootstrap analysis, grouped by dependent and independent variables, R_McF^2 scoresregression_results.groupby(["predictors", "target"]).rho_mcf_linear.mean()
predictors target
age brood_area_total 0.546260
dance_floor 0.417913
dance_floor,honey_storage,brood_area_total,near_exit 0.415424
honey_storage 0.026411
near_exit 0.314711
age,network_age brood_area_total 0.584782
dance_floor 0.512601
dance_floor,honey_storage,brood_area_total,near_exit 0.475106
honey_storage 0.051840
near_exit 0.376673
network_age brood_area_total 0.555143
dance_floor 0.477920
dance_floor,honey_storage,brood_area_total,near_exit 0.443385
honey_storage 0.003832
near_exit 0.357418
network_age,network_age_1 brood_area_total 0.577571
dance_floor 0.477131
dance_floor,honey_storage,brood_area_total,near_exit 0.462893
honey_storage 0.166705
near_exit 0.386814
network_age,network_age_1,network_age_2 brood_area_total 0.575683
dance_floor 0.499749
dance_floor,honey_storage,brood_area_total,near_exit 0.475821
honey_storage 0.160835
near_exit 0.445180
Name: rho_mcf_linear, dtype: float64

These results correspond to section 3 of the manuscript: Network age correctly identifies task allocation

Citation

Social networks predict the life and death of honey bees
Benjamin Wild, David M Dormagen, Adrian Zachariae, Michael L Smith, Kirsten S Traynor, Dirk Brockmann, Iain D Couzin, Tim Landgraf
bioRxiv 2020.05.06.076943; doi: https://doi.org/10.1101/2020.05.06.076943

About

Analyze social networks using spectral decomposition over time

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages