Published
Edited
Jun 10, 2019
Fork of Untitled
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function get_neighborhood_words_across_decades(word, num_neighbors) {
var word_index = swapped_words[word];
var neighborhood_dict = {}
var decades = [...Array(21).keys()].map(i => 2000 - i*10)
// Get values for all decades for which we have values
for (const dec of decades) {
var neighbors = word_neighborhoods_full[dec+"_neighbors"][word_index];
var similarities = word_neighborhoods_full[dec+"_cosine"][word_index];
neighbors = neighbors.slice(0, num_neighbors);
similarities = similarities.slice(0, num_neighbors);
var neighb_i
for (neighb_i = 0; neighb_i < neighbors.length; neighb_i++) { //(const neighb_i of [...Array(neighbors.length)]) {
const neighb = neighbors[neighb_i]
const sim = similarities[neighb_i]
if (!(neighb in neighborhood_dict)) {
neighborhood_dict[neighb] = {}
}

neighborhood_dict[neighb][dec] = sim
}
}
// fill in dummy similarities for all other values
for (const neighb in neighborhood_dict) {
for (const dec of decades) {
if (!(dec in neighborhood_dict[neighb])) {
neighborhood_dict[neighb][dec] = -2.
}
}
}
return neighborhood_dict
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more