From 175ac10904d0f31c3ffeeeed507c8914f13d0b15 Mon Sep 17 00:00:00 2001 From: leshe4ka46 Date: Sat, 13 Dec 2025 19:41:40 +0300 Subject: linr, logr --- R_LinR/Rplots.pdf | Bin 1834842 -> 5522525 bytes R_LinR/aaaaaa.md | 23 + ...2AI+2019Spring+type@asset+block@mlclass-ex1.zip | Bin 0 -> 408733 bytes .../ex1.pdf | Bin 0 -> 453500 bytes .../mlclass-ex1/computeCost.m | 23 + .../mlclass-ex1/computeCostMulti.m | 22 + .../mlclass-ex1/ex1.m | 122 ++ .../mlclass-ex1/ex1_multi.m | 160 ++ .../mlclass-ex1/featureNormalize.m | 41 + .../mlclass-ex1/gradientDescent.m | 34 + .../mlclass-ex1/gradientDescentMulti.m | 37 + .../mlclass-ex1/normalEqn.m | 25 + .../mlclass-ex1/octave-workspace | Bin 0 -> 3957 bytes .../mlclass-ex1/plotData.m | 27 + .../mlclass-ex1/submit.m | 336 ++++ .../mlclass-ex1/warmUpExercise.m | 21 + R_LinR/ftests.pdf | Bin 0 -> 63716 bytes R_LinR/image1.png | Bin 0 -> 42534 bytes R_LinR/image2.png | Bin 0 -> 24483 bytes R_LinR/main.r | 42 +- R_LogR/Rplots.pdf | Bin 0 -> 11835 bytes ...2AI+2019Spring+type@asset+block@mlclass-ex2.zip | Bin 0 -> 245817 bytes R_LogR/ex2.pdf | Bin 0 -> 258794 bytes R_LogR/main.r | 41 + R_LogR/mlclass-ex2/costFunction.m | 35 + R_LogR/mlclass-ex2/costFunctionReg.m | 36 + R_LogR/mlclass-ex2/ex2.m | 135 ++ R_LogR/mlclass-ex2/ex2_reg.m | 117 ++ R_LogR/mlclass-ex2/mapFeature.m | 21 + R_LogR/mlclass-ex2/plotData.m | 33 + R_LogR/mlclass-ex2/plotDecisionBoundary.m | 49 + R_LogR/mlclass-ex2/predict.m | 32 + R_LogR/mlclass-ex2/sigmoid.m | 18 + R_LogR/mlclass-ex2/submit.m | 333 ++++ R_LogR/mlclass-ex2/submitWeb.m | 349 ++++ R_LogR/survey.csv | 751 +++++++++ shit.ipynb | 1757 -------------------- 37 files changed, 2859 insertions(+), 1761 deletions(-) create mode 100644 R_LinR/aaaaaa.md create mode 100644 R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1.zip create mode 100644 R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/ex1.pdf create mode 100644 R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/computeCost.m create mode 100644 R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/computeCostMulti.m create mode 100644 R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/ex1.m create mode 100644 R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/ex1_multi.m create mode 100644 R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/featureNormalize.m create mode 100644 R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/gradientDescent.m create mode 100644 R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/gradientDescentMulti.m create mode 100644 R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/normalEqn.m create mode 100644 R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/octave-workspace create mode 100644 R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/plotData.m create mode 100644 R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/submit.m create mode 100644 R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/warmUpExercise.m create mode 100644 R_LinR/ftests.pdf create mode 100644 R_LinR/image1.png create mode 100644 R_LinR/image2.png create mode 100644 R_LogR/Rplots.pdf create mode 100644 R_LogR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex2.zip create mode 100644 R_LogR/ex2.pdf create mode 100755 R_LogR/main.r create mode 100644 R_LogR/mlclass-ex2/costFunction.m create mode 100644 R_LogR/mlclass-ex2/costFunctionReg.m create mode 100644 R_LogR/mlclass-ex2/ex2.m create mode 100644 R_LogR/mlclass-ex2/ex2_reg.m create mode 100644 R_LogR/mlclass-ex2/mapFeature.m create mode 100644 R_LogR/mlclass-ex2/plotData.m create mode 100644 R_LogR/mlclass-ex2/plotDecisionBoundary.m create mode 100644 R_LogR/mlclass-ex2/predict.m create mode 100644 R_LogR/mlclass-ex2/sigmoid.m create mode 100644 R_LogR/mlclass-ex2/submit.m create mode 100644 R_LogR/mlclass-ex2/submitWeb.m create mode 100644 R_LogR/survey.csv delete mode 100644 shit.ipynb diff --git a/R_LinR/Rplots.pdf b/R_LinR/Rplots.pdf index 778337e..c96086d 100644 Binary files a/R_LinR/Rplots.pdf and b/R_LinR/Rplots.pdf differ diff --git a/R_LinR/aaaaaa.md b/R_LinR/aaaaaa.md new file mode 100644 index 0000000..8ad7cd1 --- /dev/null +++ b/R_LinR/aaaaaa.md @@ -0,0 +1,23 @@ +t-value estimate / std_error + +R^2 = 1 - SS_{res}/SS_{tot} + +SS_{rss} = sum((y_i - y_pred)^2) # residual sum of squares +SS_{tot} = sum((y_i - y_mean)^2) + + +F = ((SS_{tot} - SS_{res})/p)/(SS_{res}/(n-p-1)) +n - number of points +p - number of inputs + +# https://www.rose-hulman.edu/class/ma/inlow/Math485/ftests.pdf + + + +p-value -> 0 high significance + +adjusted R^2 = 1 - (1-R^2)(n-1)/(n-p-1) - it adjusts the r-squared value by penalizing the inclusion of irrelevant, by which we mean highly collinear, variables. It does this by taking into account both the number of predictors and the sample size. + + + +https://mjt.cs.illinois.edu/ml/lec2.pdf \ No newline at end of file diff --git a/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1.zip b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1.zip new file mode 100644 index 0000000..0172afd Binary files /dev/null and b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1.zip differ diff --git a/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/ex1.pdf b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/ex1.pdf new file mode 100644 index 0000000..f07bfe8 Binary files /dev/null and b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/ex1.pdf differ diff --git a/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/computeCost.m b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/computeCost.m new file mode 100644 index 0000000..3dc1543 --- /dev/null +++ b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/computeCost.m @@ -0,0 +1,23 @@ +function J = computeCost(X, y, theta) +%COMPUTECOST Compute cost for linear regression +% J = COMPUTECOST(X, y, theta) computes the cost of using theta as the +% parameter for linear regression to fit the data points in X and y + +% Initialize some useful values +m = length(y); % number of training examples + +% You need to return the following variables correctly +J = 0; + +% ====================== YOUR CODE HERE ====================== +% Instructions: Compute the cost of a particular choice of theta +% You should set J to the cost. + +# https://www.kaggle.com/discussions/general/156593 +# dot - element by element operation +J = 1 / 2 / m * sum((X * theta - y) .^ 2); + + +% ========================================================================= + +end diff --git a/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/computeCostMulti.m b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/computeCostMulti.m new file mode 100644 index 0000000..3dc9b06 --- /dev/null +++ b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/computeCostMulti.m @@ -0,0 +1,22 @@ +function J = computeCostMulti(X, y, theta) +%COMPUTECOSTMULTI Compute cost for linear regression with multiple variables +% J = COMPUTECOSTMULTI(X, y, theta) computes the cost of using theta as the +% parameter for linear regression to fit the data points in X and y + +% Initialize some useful values +m = length(y); % number of training examples + +% You need to return the following variables correctly +J = 0; + +% ====================== YOUR CODE HERE ====================== +% Instructions: Compute the cost of a particular choice of theta +% You should set J to the cost. +J = 1 / 2 / m * sum((X * theta - y) .^ 2); + + + + +% ========================================================================= + +end diff --git a/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/ex1.m b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/ex1.m new file mode 100644 index 0000000..f3aacb5 --- /dev/null +++ b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/ex1.m @@ -0,0 +1,122 @@ +%% Machine Learning Online Class - Exercise 1: Linear Regression + +% Instructions +% ------------ +% +% This file contains code that helps you get started on the +% linear exercise. You will need to complete the following functions +% in this exericse: +% +% warmUpExercise.m +% plotData.m +% gradientDescent.m +% computeCost.m +% gradientDescentMulti.m +% computeCostMulti.m +% featureNormalize.m +% normalEqn.m +% +% For this exercise, you will not need to change any code in this file, +% or any other files other than those mentioned above. +% +% x refers to the population size in 10,000s +% y refers to the profit in $10,000s +% + +%% Initialization +clear all; close all; clc + +%% ==================== Part 1: Basic Function ==================== +% Complete warmUpExercise.m +fprintf('Running warmUpExercise ... \n'); +fprintf('5x5 Identity Matrix: \n'); +warmUpExercise() + +fprintf('Program paused. Press enter to continue.\n'); +pause; + + +%% ======================= Part 2: Plotting ======================= +fprintf('Plotting Data ...\n') +data = load('ex1data1.txt'); +X = data(:, 1); y = data(:, 2); +m = length(y); % number of training examples + +% Plot Data +% Note: You have to complete the code in plotData.m +plotData(X, y); + +fprintf('Program paused. Press enter to continue.\n'); +pause; + +%% =================== Part 3: Gradient descent =================== +fprintf('Running Gradient Descent ...\n') + +X = [ones(m, 1), data(:,1)]; % Add a column of ones to x +theta = zeros(2, 1); % initialize fitting parameters + +% Some gradient descent settings +iterations = 1500; +alpha = 0.01; + +% compute and display initial cost +computeCost(X, y, theta) + +% run gradient descent +theta = gradientDescent(X, y, theta, alpha, iterations); + +% print theta to screen +fprintf('Theta found by gradient descent: '); +fprintf('%f %f \n', theta(1), theta(2)); + +% Plot the linear fit +hold on; % keep previous plot visible +plot(X(:,2), X*theta, '-') +legend('Training data', 'Linear regression') +hold off % don't overlay any more plots on this figure + +% Predict values for population sizes of 35,000 and 70,000 +predict1 = [1, 3.5] *theta; +fprintf('For population = 35,000, we predict a profit of %f\n',... + predict1*10000); +predict2 = [1, 7] * theta; +fprintf('For population = 70,000, we predict a profit of %f\n',... + predict2*10000); + +fprintf('Program paused. Press enter to continue.\n'); +pause; + +%% ============= Part 4: Visualizing J(theta_0, theta_1) ============= +fprintf('Visualizing J(theta_0, theta_1) ...\n') + +% Grid over which we will calculate J +theta0_vals = linspace(-10, 10, 100); +theta1_vals = linspace(-1, 4, 100); + +% initialize J_vals to a matrix of 0's +J_vals = zeros(length(theta0_vals), length(theta1_vals)); + +% Fill out J_vals +for i = 1:length(theta0_vals) + for j = 1:length(theta1_vals) + t = [theta0_vals(i); theta1_vals(j)]; + J_vals(i,j) = computeCost(X, y, t); + end +end + + +% Because of the way meshgrids work in the surf command, we need to +% transpose J_vals before calling surf, or else the axes will be flipped +J_vals = J_vals'; +% Surface plot +figure; +surf(theta0_vals, theta1_vals, J_vals) +xlabel('\theta_0'); ylabel('\theta_1'); + +% Contour plot +figure; +% Plot J_vals as 15 contours spaced logarithmically between 0.01 and 100 +contour(theta0_vals, theta1_vals, J_vals, logspace(-2, 3, 20)) +xlabel('\theta_0'); ylabel('\theta_1'); +hold on; +plot(theta(1), theta(2), 'rx', 'MarkerSize', 10, 'LineWidth', 2); diff --git a/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/ex1_multi.m b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/ex1_multi.m new file mode 100644 index 0000000..7a8ceab --- /dev/null +++ b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/ex1_multi.m @@ -0,0 +1,160 @@ +%% Machine Learning Online Class +% Exercise 1: Linear regression with multiple variables +% +% Instructions +% ------------ +% +% This file contains code that helps you get started on the +% linear regression exercise. +% +% You will need to complete the following functions in this +% exericse: +% +% warmUpExercise.m +% plotData.m +% gradientDescent.m +% computeCost.m +% gradientDescentMulti.m +% computeCostMulti.m +% featureNormalize.m +% normalEqn.m +% +% For this part of the exercise, you will need to change some +% parts of the code below for various experiments (e.g., changing +% learning rates). +% + +%% Initialization + +%% ================ Part 1: Feature Normalization ================ + +%% Clear and Close Figures +clear all; close all; clc + +fprintf('Loading data ...\n'); + +%% Load Data +data = load('ex1data2.txt'); +X = data(:, 1:2); +y = data(:, 3); +m = length(y); + +% Print out some data points +fprintf('First 10 examples from the dataset: \n'); +fprintf(' x = [%.0f %.0f], y = %.0f \n', [X(1:10,:) y(1:10,:)]'); + +fprintf('Program paused. Press enter to continue.\n'); +pause; + +% Scale features and set them to zero mean +fprintf('Normalizing Features ...\n'); + +[X mu sigma] = featureNormalize(X); + +% Add intercept term to X +X = [ones(m, 1) X]; + + +%% ================ Part 2: Gradient Descent ================ + +% ====================== YOUR CODE HERE ====================== +% Instructions: We have provided you with the following starter +% code that runs gradient descent with a particular +% learning rate (alpha). +% +% Your task is to first make sure that your functions - +% computeCost and gradientDescent already work with +% this starter code and support multiple variables. +% +% After that, try running gradient descent with +% different values of alpha and see which one gives +% you the best result. +% +% Finally, you should complete the code at the end +% to predict the price of a 1650 sq-ft, 3 br house. +% +% Hint: By using the 'hold on' command, you can plot multiple +% graphs on the same figure. +% +% Hint: At prediction, make sure you do the same feature normalization. +% + +fprintf('Running gradient descent ...\n'); + +% Choose some alpha value +alpha = 0.01; +num_iters = 100; + +% Init Theta and Run Gradient Descent +theta = zeros(3, 1); +[theta, J_history] = gradientDescentMulti(X, y, theta, alpha, num_iters); + +% Plot the convergence graph +figure; +plot(1:numel(J_history), J_history, '-b', 'LineWidth', 2); +xlabel('Number of iterations'); +ylabel('Cost J'); + +% Display gradient descent's result +fprintf('Theta computed from gradient descent: \n'); +fprintf(' %f \n', theta); +fprintf('\n'); + +% Estimate the price of a 1650 sq-ft, 3 br house +% ====================== YOUR CODE HERE ====================== +% Recall that the first column of X is all-ones. Thus, it does +% not need to be normalized. +price = 0; % You should change this + + +% ============================================================ + +fprintf(['Predicted price of a 1650 sq-ft, 3 br house ' ... + '(using gradient descent):\n $%f\n'], price); + +fprintf('Program paused. Press enter to continue.\n'); +pause; + +%% ================ Part 3: Normal Equations ================ + +fprintf('Solving with normal equations...\n'); + +% ====================== YOUR CODE HERE ====================== +% Instructions: The following code computes the closed form +% solution for linear regression using the normal +% equations. You should complete the code in +% normalEqn.m +% +% After doing so, you should complete this code +% to predict the price of a 1650 sq-ft, 3 br house. +% + +%% Load Data +data = csvread('ex1data2.txt'); +X = data(:, 1:2); +y = data(:, 3); +m = length(y); + +% Add intercept term to X +X = [ones(m, 1) X]; + +% Calculate the parameters from the normal equation +theta = normalEqn(X, y); + +% Display normal equation's result +fprintf('Theta computed from the normal equations: \n'); +fprintf(' %f \n', theta); +fprintf('\n'); + + +% Estimate the price of a 1650 sq-ft, 3 br house +% ====================== YOUR CODE HERE ====================== +area = 1650; % You should change this +br = 3; +price = [1, area, br] * theta; + +% ============================================================ + +fprintf(['Predicted price of a 1650 sq-ft, 3 br house ' ... + '(using normal equations):\n $%f\n'], price); + diff --git a/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/featureNormalize.m b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/featureNormalize.m new file mode 100644 index 0000000..ea5c7d2 --- /dev/null +++ b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/featureNormalize.m @@ -0,0 +1,41 @@ +function [X_norm, mu, sigma] = featureNormalize(X) +%FEATURENORMALIZE Normalizes the features in X +% FEATURENORMALIZE(X) returns a normalized version of X where +% the mean value of each feature is 0 and the standard deviation +% is 1. This is often a good preprocessing step to do when +% working with learning algorithms. + +% You need to set these values correctly +% X_norm = X; +mu = zeros(1, size(X, 2)); +sigma = zeros(1, size(X, 2)); + +% ====================== YOUR CODE HERE ====================== +% Instructions: First, for each feature dimension, compute the mean +% of the feature and subtract it from the dataset, +% storing the mean value in mu. Next, compute the +% standard deviation of each feature and divide +% each feature by it's standard deviation, storing +% the standard deviation in sigma. +% +% Note that X is a matrix where each column is a +% feature and each row is an example. You need +% to perform the normalization separately for +% each feature. +% +% Hint: You might find the 'mean' and 'std' functions useful. +% + + + +mu = mean(X); +sigma = std(X); +X_norm = (X - mu) ./ sigma; + + + + + +% ============================================================ + +end diff --git a/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/gradientDescent.m b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/gradientDescent.m new file mode 100644 index 0000000..b74dd2c --- /dev/null +++ b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/gradientDescent.m @@ -0,0 +1,34 @@ +function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters) +%GRADIENTDESCENT Performs gradient descent to learn theta +% theta = GRADIENTDESENT(X, y, theta, alpha, num_iters) updates theta by +% taking num_iters gradient steps with learning rate alpha + +% Initialize some useful values +m = length(y); % number of training examples +J_history = zeros(num_iters, 1); + +for iter = 1:num_iters + + % ====================== YOUR CODE HERE ====================== + % Instructions: Perform a single gradient step on the parameter vector + % theta. + % + % Hint: While debugging, it can be useful to print out the values + % of the cost function (computeCost) and gradient here. + % + + +# X' - transpose +# https://mjt.cs.illinois.edu/ml/lec2.pdf +theta = theta - alpha / m * (X' * (X * theta - y)); + + + + % ============================================================ + + % Save the cost J in every iteration + J_history(iter) = computeCost(X, y, theta); + +end + +end diff --git a/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/gradientDescentMulti.m b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/gradientDescentMulti.m new file mode 100644 index 0000000..99a10aa --- /dev/null +++ b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/gradientDescentMulti.m @@ -0,0 +1,37 @@ +function [theta, J_history] = gradientDescentMulti(X, y, theta, alpha, num_iters) +%GRADIENTDESCENTMULTI Performs gradient descent to learn theta +% theta = GRADIENTDESCENTMULTI(x, y, theta, alpha, num_iters) updates theta by +% taking num_iters gradient steps with learning rate alpha + +% Initialize some useful values +m = length(y); % number of training examples +J_history = zeros(num_iters, 1); + +for iter = 1:num_iters + + % ====================== YOUR CODE HERE ====================== + % Instructions: Perform a single gradient step on the parameter vector + % theta. + % + % Hint: While debugging, it can be useful to print out the values + % of the cost function (computeCostMulti) and gradient here. + % + + + + + +theta = theta - alpha / m * (X' * (X * theta - y)); + + + + + + % ============================================================ + + % Save the cost J in every iteration + J_history(iter) = computeCostMulti(X, y, theta); + +end + +end diff --git a/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/normalEqn.m b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/normalEqn.m new file mode 100644 index 0000000..56984a3 --- /dev/null +++ b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/normalEqn.m @@ -0,0 +1,25 @@ +function [theta] = normalEqn(X, y) +%NORMALEQN Computes the closed-form solution to linear regression +% NORMALEQN(X,y) computes the closed-form solution to linear +% regression using the normal equations. + +theta = zeros(size(X, 2), 1); + +% ====================== YOUR CODE HERE ====================== +% Instructions: Complete the code to compute the closed form solution +% to linear regression and put the result in theta. +% + +% ---------------------- Sample Solution ---------------------- + +theta = pinv(X' * X) * X' * y; + + + + +% ------------------------------------------------------------- + + +% ============================================================ + +end diff --git a/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/octave-workspace b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/octave-workspace new file mode 100644 index 0000000..787b037 Binary files /dev/null and b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/octave-workspace differ diff --git a/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/plotData.m b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/plotData.m new file mode 100644 index 0000000..ba825d0 --- /dev/null +++ b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/plotData.m @@ -0,0 +1,27 @@ +function plotData(x, y) +%PLOTDATA Plots the data points x and y into a new figure +% PLOTDATA(x,y) plots the data points and gives the figure axes labels of +% population and profit. + +% ====================== YOUR CODE HERE ====================== +% Instructions: Plot the training data into a figure using the +% "figure" and "plot" commands. Set the axes labels using +% the "xlabel" and "ylabel" commands. Assume the +% population and revenue data have been passed in +% as the x and y arguments of this function. +% +% Hint: You can use the 'rx' option with plot to have the markers +% appear as red crosses. Furthermore, you can make the +% markers larger by using plot(..., 'rx', 'MarkerSize', 10); + +figure; % open a new figure window + + +plot(x, y, 'rx', 'MarkerSize', 10); +xlabel('population'); +ylabel('profit'); + + +% ============================================================ + +end diff --git a/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/submit.m b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/submit.m new file mode 100644 index 0000000..48f3e71 --- /dev/null +++ b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/submit.m @@ -0,0 +1,336 @@ +function submit(part) +%SUBMIT Submit your code and output to the ml-class servers +% SUBMIT() will connect to the ml-class server and submit your solution + + fprintf('==\n== [ml-class] Submitting Solutions | Programming Exercise %s\n==\n', ... + homework_id()); + if ~exist('part', 'var') || isempty(part) + partId = promptPart(); + end + + % Check valid partId + partNames = validParts(); + if ~isValidPartId(partId) + fprintf('!! Invalid homework part selected.\n'); + fprintf('!! Expected an integer from 1 to %d.\n', numel(partNames) + 1); + fprintf('!! Submission Cancelled\n'); + return + end + + [login password] = loginPrompt(); + if isempty(login) + fprintf('!! Submission Cancelled\n'); + return + end + + fprintf('\n== Connecting to ml-class ... '); + if exist('OCTAVE_VERSION') + fflush(stdout); + end + + % Setup submit list + if partId == numel(partNames) + 1 + submitParts = 1:numel(partNames); + else + submitParts = [partId]; + end + + for s = 1:numel(submitParts) + % Submit this part + partId = submitParts(s); + + % Get Challenge + [login, ch, signature] = getChallenge(login); + if isempty(login) || isempty(ch) || isempty(signature) + % Some error occured, error string in first return element. + fprintf('\n!! Error: %s\n\n', login); + return + end + + % Attempt Submission with Challenge + ch_resp = challengeResponse(login, password, ch); + [result, str] = submitSolution(login, ch_resp, partId, output(partId), ... + source(partId), signature); + + fprintf('\n== [ml-class] Submitted Homework %s - Part %d - %s\n', ... + homework_id(), partId, partNames{partId}); + fprintf('== %s\n', strtrim(str)); + if exist('OCTAVE_VERSION') + fflush(stdout); + end + end + +end + +% ================== CONFIGURABLES FOR EACH HOMEWORK ================== + +function id = homework_id() + id = '1'; +end + +function [partNames] = validParts() + partNames = { 'Warm up exercise ', ... + 'Computing Cost (for one variable)', ... + 'Gradient Descent (for one variable)', ... + 'Feature Normalization', ... + 'Computing Cost (for multiple variables)', ... + 'Gradient Descent (for multiple variables)', ... + 'Normal Equations'}; +end + +function srcs = sources() + % Separated by part + srcs = { { 'warmUpExercise.m' }, ... + { 'computeCost.m' }, ... + { 'gradientDescent.m' }, ... + { 'featureNormalize.m' }, ... + { 'computeCostMulti.m' }, ... + { 'gradientDescentMulti.m' }, ... + { 'normalEqn.m' }, ... + }; +end + +function out = output(partId) + % Random Test Cases + X1 = [ones(20,1) (exp(1) + exp(2) * (0.1:0.1:2))']; + Y1 = X1(:,2) + sin(X1(:,1)) + cos(X1(:,2)); + X2 = [X1 X1(:,2).^0.5 X1(:,2).^0.25]; + Y2 = Y1.^0.5 + Y1; + if partId == 1 + out = sprintf('%0.5f ', warmUpExercise()); + elseif partId == 2 + out = sprintf('%0.5f ', computeCost(X1, Y1, [0.5 -0.5]')); + elseif partId == 3 + out = sprintf('%0.5f ', gradientDescent(X1, Y1, [0.5 -0.5]', 0.01, 10)); + elseif partId == 4 + out = sprintf('%0.5f ', featureNormalize(X2(:,2:4))); + elseif partId == 5 + out = sprintf('%0.5f ', computeCostMulti(X2, Y2, [0.1 0.2 0.3 0.4]')); + elseif partId == 6 + out = sprintf('%0.5f ', gradientDescentMulti(X2, Y2, [-0.1 -0.2 -0.3 -0.4]', 0.01, 10)); + elseif partId == 7 + out = sprintf('%0.5f ', normalEqn(X2, Y2)); + end +end + +function url = challenge_url() + url = 'http://www.ml-class.org/course/homework/challenge'; +end + +function url = submit_url() + url = 'http://www.ml-class.org/course/homework/submit'; +end + +% ========================= CHALLENGE HELPERS ========================= + +function src = source(partId) + src = ''; + src_files = sources(); + if partId <= numel(src_files) + flist = src_files{partId}; + for i = 1:numel(flist) + fid = fopen(flist{i}); + while ~feof(fid) + line = fgets(fid); + src = [src line]; + end + src = [src '||||||||']; + end + end +end + +function ret = isValidPartId(partId) + partNames = validParts(); + ret = (~isempty(partId)) && (partId >= 1) && (partId <= numel(partNames) + 1); +end + +function partId = promptPart() + fprintf('== Select which part(s) to submit:\n', ... + homework_id()); + partNames = validParts(); + srcFiles = sources(); + for i = 1:numel(partNames) + fprintf('== %d) %s [', i, partNames{i}); + fprintf(' %s ', srcFiles{i}{:}); + fprintf(']\n'); + end + fprintf('== %d) All of the above \n==\nEnter your choice [1-%d]: ', ... + numel(partNames) + 1, numel(partNames) + 1); + selPart = input('', 's'); + partId = str2num(selPart); + if ~isValidPartId(partId) + partId = -1; + end +end + +function [email,ch,signature] = getChallenge(email) + str = urlread(challenge_url(), 'post', {'email_address', email}); + + str = strtrim(str); + [email, str] = strtok (str, '|'); + [ch, str] = strtok (str, '|'); + [signature, str] = strtok (str, '|'); +end + + +function [result, str] = submitSolution(email, ch_resp, part, output, ... + source, signature) + + params = {'homework', homework_id(), ... + 'part', num2str(part), ... + 'email', email, ... + 'output', output, ... + 'source', source, ... + 'challenge_response', ch_resp, ... + 'signature', signature}; + + str = urlread(submit_url(), 'post', params); + + % Parse str to read for success / failure + result = 0; + +end + +% =========================== LOGIN HELPERS =========================== + +function [login password] = loginPrompt() + % Prompt for password + [login password] = basicPrompt(); + + if isempty(login) || isempty(password) + login = []; password = []; + end +end + + +function [login password] = basicPrompt() + login = input('Login (Email address): ', 's'); + password = input('Password: ', 's'); +end + + +function [str] = challengeResponse(email, passwd, challenge) + salt = ')~/|]QMB3[!W`?OVt7qC"@+}'; + str = sha1([challenge sha1([salt email passwd])]); + sel = randperm(numel(str)); + sel = sort(sel(1:16)); + str = str(sel); +end + + +% =============================== SHA-1 ================================ + +function hash = sha1(str) + + % Initialize variables + h0 = uint32(1732584193); + h1 = uint32(4023233417); + h2 = uint32(2562383102); + h3 = uint32(271733878); + h4 = uint32(3285377520); + + % Convert to word array + strlen = numel(str); + + % Break string into chars and append the bit 1 to the message + mC = [double(str) 128]; + mC = [mC zeros(1, 4-mod(numel(mC), 4), 'uint8')]; + + numB = strlen * 8; + if exist('idivide') + numC = idivide(uint32(numB + 65), 512, 'ceil'); + else + numC = ceil(double(numB + 65)/512); + end + numW = numC * 16; + mW = zeros(numW, 1, 'uint32'); + + idx = 1; + for i = 1:4:strlen + 1 + mW(idx) = bitor(bitor(bitor( ... + bitshift(uint32(mC(i)), 24), ... + bitshift(uint32(mC(i+1)), 16)), ... + bitshift(uint32(mC(i+2)), 8)), ... + uint32(mC(i+3))); + idx = idx + 1; + end + + % Append length of message + mW(numW - 1) = uint32(bitshift(uint64(numB), -32)); + mW(numW) = uint32(bitshift(bitshift(uint64(numB), 32), -32)); + + % Process the message in successive 512-bit chs + for cId = 1 : double(numC) + cSt = (cId - 1) * 16 + 1; + cEnd = cId * 16; + ch = mW(cSt : cEnd); + + % Extend the sixteen 32-bit words into eighty 32-bit words + for j = 17 : 80 + ch(j) = ch(j - 3); + ch(j) = bitxor(ch(j), ch(j - 8)); + ch(j) = bitxor(ch(j), ch(j - 14)); + ch(j) = bitxor(ch(j), ch(j - 16)); + ch(j) = bitrotate(ch(j), 1); + end + + % Initialize hash value for this ch + a = h0; + b = h1; + c = h2; + d = h3; + e = h4; + + % Main loop + for i = 1 : 80 + if(i >= 1 && i <= 20) + f = bitor(bitand(b, c), bitand(bitcmp(b), d)); + k = uint32(1518500249); + elseif(i >= 21 && i <= 40) + f = bitxor(bitxor(b, c), d); + k = uint32(1859775393); + elseif(i >= 41 && i <= 60) + f = bitor(bitor(bitand(b, c), bitand(b, d)), bitand(c, d)); + k = uint32(2400959708); + elseif(i >= 61 && i <= 80) + f = bitxor(bitxor(b, c), d); + k = uint32(3395469782); + end + + t = bitrotate(a, 5); + t = bitadd(t, f); + t = bitadd(t, e); + t = bitadd(t, k); + t = bitadd(t, ch(i)); + e = d; + d = c; + c = bitrotate(b, 30); + b = a; + a = t; + + end + h0 = bitadd(h0, a); + h1 = bitadd(h1, b); + h2 = bitadd(h2, c); + h3 = bitadd(h3, d); + h4 = bitadd(h4, e); + + end + + hash = reshape(dec2hex(double([h0 h1 h2 h3 h4]), 8)', [1 40]); + + hash = lower(hash); + +end + +function ret = bitadd(iA, iB) + ret = double(iA) + double(iB); + ret = bitset(ret, 33, 0); + ret = uint32(ret); +end + +function ret = bitrotate(iA, places) + t = bitshift(iA, places - 32); + ret = bitshift(iA, places); + ret = bitor(ret, t); +end diff --git a/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/warmUpExercise.m b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/warmUpExercise.m new file mode 100644 index 0000000..5133fa5 --- /dev/null +++ b/R_LinR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex1/mlclass-ex1/warmUpExercise.m @@ -0,0 +1,21 @@ +function A = warmUpExercise() +%WARMUPEXERCISE Example function in octave +% A = WARMUPEXERCISE() is an example function that returns the 5x5 identity matrix + +A = []; +% ============= YOUR CODE HERE ============== +% Instructions: Return the 5x5 identity matrix +% In octave, we return values by defining which variables +% represent the return values (at the top of the file) +% and then set them accordingly. + + +# create diagonal matrix +A = eye(5); + + + +% =========================================== + + +end diff --git a/R_LinR/ftests.pdf b/R_LinR/ftests.pdf new file mode 100644 index 0000000..dc634ab Binary files /dev/null and b/R_LinR/ftests.pdf differ diff --git a/R_LinR/image1.png b/R_LinR/image1.png new file mode 100644 index 0000000..ea6e914 Binary files /dev/null and b/R_LinR/image1.png differ diff --git a/R_LinR/image2.png b/R_LinR/image2.png new file mode 100644 index 0000000..893d4d7 Binary files /dev/null and b/R_LinR/image2.png differ diff --git a/R_LinR/main.r b/R_LinR/main.r index d7b5856..3bb98fb 100755 --- a/R_LinR/main.r +++ b/R_LinR/main.r @@ -5,7 +5,7 @@ df <- subset(df, sex == "F") df <- subset(df, select = -c(zcta, sex)) df <- subset(df, 8 < meaneducation & meaneducation < 18) df <- subset(df, 10000 < meanhouseholdincome & meanhouseholdincome < 200000) -df <- subset(df, 10000 < meanhouseholdincome & meanhouseholdincome < 200000) +df <- subset(df, 0 < meanemployment & meanemployment < 3) df <- subset(df, 20 < meanage & meanage < 60) df$log_income <- log10(df$meanhouseholdincome) @@ -15,12 +15,46 @@ names(df) <- c("X", "age", "education", "employment", "income", "log_income") library(ggplot2) -ggplot(df, aes(x = age, y = log_income)) + - geom_point(alpha = 0.2) + - labs(x = "age", y = "income", title = "log_income(age)") +# b model <- lm(log_income ~ age, df) +# a +ggplot(df, aes(x = age, y = log_income)) + + geom_point(alpha = 0.2) + + geom_abline( + intercept = coef(model)[1], + slope = coef(model)[2], + color = "red", + size = 1 + ) + + labs(x = "age", y = "income", title = "log_income(age)") + +# bcde print(model) summary(model) + +model_2 <- lm(log_income ~ education, df) +print(model_2) +summary(model_2) + +ggplot(df, aes(x = education, y = log_income)) + + geom_point(alpha = 0.2) + + geom_abline( + intercept = coef(model_2)[1], + slope = coef(model_2)[2], + color = "red", + size = 1 + ) + + labs(x = "education", y = "income", title = "log_income(education)") + + +model_3 <- lm(log_income ~ education + age + employment, df) +print(model_3) +summary(model_3) + +ggplot(df) + + geom_point(aes(x = log_income, y = fitted(model_3)), alpha = 0.2) + + geom_line(aes(x = log_income, y = log_income), col = "red") + + labs(x = "actual", y = "predicted") diff --git a/R_LogR/Rplots.pdf b/R_LogR/Rplots.pdf new file mode 100644 index 0000000..5a71719 Binary files /dev/null and b/R_LogR/Rplots.pdf differ diff --git a/R_LogR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex2.zip b/R_LogR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex2.zip new file mode 100644 index 0000000..36ed86a Binary files /dev/null and b/R_LogR/asset-v1_MEPhIx+CSA12AI+2019Spring+type@asset+block@mlclass-ex2.zip differ diff --git a/R_LogR/ex2.pdf b/R_LogR/ex2.pdf new file mode 100644 index 0000000..78d3d35 Binary files /dev/null and b/R_LogR/ex2.pdf differ diff --git a/R_LogR/main.r b/R_LogR/main.r new file mode 100755 index 0000000..748b0f4 --- /dev/null +++ b/R_LogR/main.r @@ -0,0 +1,41 @@ +#!/usr/bin/env Rscript + +# https://www.r-bloggers.com/2015/09/how-to-perform-a-logistic-regression-in-r/ + +data <- read.csv("survey.csv") + + +str(data) +head(data) + +data$price20 <- ifelse(data$Price == 20, 1, 0) +data$price30 <- ifelse(data$Price == 30, 1, 0) +head(data) + +model <- glm( + MYDEPV ~ Income + Age + price20 + price30, + family = binomial(link = "logit"), + data = data +) +summary(model) + +coef(model) + +plot(data$Income, data$MYDEPV) + + +test_dat <- data.frame(Income = seq(20, 100, 1), Age = 20, price20 = 1, price30 = 0) +pred <- predict(model, newdata = test_dat, type = "response") + +lines(test_dat$Income, pred, col = "blue", lwd = 2) + + +new_data3 <- data.frame( + Income = c(58), + Age = c(25), + price20 = c(1), + price30 = c(0) +) + +predicted <- predict(model, newdata = new_data3) +print(1 / (1 + exp(-predicted))) diff --git a/R_LogR/mlclass-ex2/costFunction.m b/R_LogR/mlclass-ex2/costFunction.m new file mode 100644 index 0000000..6e6118c --- /dev/null +++ b/R_LogR/mlclass-ex2/costFunction.m @@ -0,0 +1,35 @@ +function [J, grad] = costFunction(theta, X, y) +%COSTFUNCTION Compute cost and gradient for logistic regression +% J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the +% parameter for logistic regression and the gradient of the cost +% w.r.t. to the parameters. + +% Initialize some useful values +m = length(y); % number of training examples + +% You need to return the following variables correctly +% J = 0; +% grad = zeros(size(theta)); + +% ====================== YOUR CODE HERE ====================== +% Instructions: Compute the cost of a particular choice of theta. +% You should set J to the cost. +% Compute the partial derivatives and set grad to the partial +% derivatives of the cost w.r.t. each parameter in theta +% +% Note: grad should have the same dimensions as theta +% + +pred = sigmoid(X*theta); + +% J = 1 /m .* sum(-y .* log(pred) - (1-y) .* log(1-pred)); + +% grad = 1 / m .* (X' * (pred - y)); + +J = (1 / (2*m)) * sum((pred - y).^2); + +grad = (1 / m) * X' * (pred - y); + +% ============================================================= + +end diff --git a/R_LogR/mlclass-ex2/costFunctionReg.m b/R_LogR/mlclass-ex2/costFunctionReg.m new file mode 100644 index 0000000..cc73386 --- /dev/null +++ b/R_LogR/mlclass-ex2/costFunctionReg.m @@ -0,0 +1,36 @@ +function [J, grad] = costFunctionReg(theta, X, y, lambda) +%COSTFUNCTIONREG Compute cost and gradient for logistic regression with regularization +% J = COSTFUNCTIONREG(theta, X, y, lambda) computes the cost of using +% theta as the parameter for regularized logistic regression and the +% gradient of the cost w.r.t. to the parameters. + +% Initialize some useful values +m = length(y); % number of training examples + +% You need to return the following variables correctly +% J = 0; +% grad = zeros(size(theta)); + +% ====================== YOUR CODE HERE ====================== +% Instructions: Compute the cost of a particular choice of theta. +% You should set J to the cost. +% Compute the partial derivatives and set grad to the partial +% derivatives of the cost w.r.t. each parameter in theta + + +pred = sigmoid(X*theta); + +J = 1./m .* sum(-y .* log(pred) - (1-y) .* log(1-pred)) + lambda ./ 2 ./ m .* sum(theta.^2); + + +reg = lambda .* theta ./ m; +reg(1) = 0; +grad = 1 / m .* (X' * (pred - y)) + reg; + + + + + +% ============================================================= + +end diff --git a/R_LogR/mlclass-ex2/ex2.m b/R_LogR/mlclass-ex2/ex2.m new file mode 100644 index 0000000..c0a7774 --- /dev/null +++ b/R_LogR/mlclass-ex2/ex2.m @@ -0,0 +1,135 @@ +%% Machine Learning Online Class - Exercise 2: Logistic Regression +% +% Instructions +% ------------ +% +% This file contains code that helps you get started on the logistic +% regression exercise. You will need to complete the following functions +% in this exericse: +% +% sigmoid.m +% costFunction.m +% predict.m +% costFunctionReg.m +% +% For this exercise, you will not need to change any code in this file, +% or any other files other than those mentioned above. +% + +%% Initialization +clear ; close all; clc + +%% Load Data +% The first two columns contains the exam scores and the third column +% contains the label. + +data = load('ex2data1.txt'); +X = data(:, [1, 2]); y = data(:, 3); + +%% ==================== Part 1: Plotting ==================== +% We start the exercise by first plotting the data to understand the +% the problem we are working with. + +fprintf(['Plotting data with + indicating (y = 1) examples and o ' ... + 'indicating (y = 0) examples.\n']); + +plotData(X, y); + +% Put some labels +hold on; +% Labels and Legend +xlabel('Exam 1 score') +ylabel('Exam 2 score') + +% Specified in plot order +% legend('Admitted', 'Not admitted') +hold off; + +fprintf('\nProgram paused. Press enter to continue.\n'); +pause; + + +%% ============ Part 2: Compute Cost and Gradient ============ +% In this part of the exercise, you will implement the cost and gradient +% for logistic regression. You neeed to complete the code in +% costFunction.m + +% Setup the data matrix appropriately, and add ones for the intercept term +[m, n] = size(X); + +% Add intercept term to x and X_test +X = [ones(m, 1) X]; + +% Initialize fitting parameters +initial_theta = zeros(n + 1, 1); + +% Compute and display initial cost and gradient +[cost, grad] = costFunction(initial_theta, X, y); + +fprintf('Cost at initial theta (zeros): %f\n', cost); +fprintf('Gradient at initial theta (zeros): \n'); +fprintf(' %f \n', grad); + +fprintf('\nProgram paused. Press enter to continue.\n'); +%pause; + + +%% ============= Part 3: Optimizing using fminunc ============= +% In this exercise, you will use a built-in function (fminunc) to find the +% optimal parameters theta. + +% Set options for fminunc +options = optimset('GradObj', 'on', 'MaxIter', 400); + +% Run fminunc to obtain the optimal theta +% This function will return theta and the cost +[theta, cost] = ... + fminunc(@(t)(costFunction(t, X, y)), initial_theta, options); + +% Print theta to screen +fprintf('Cost at theta found by fminunc: %f\n', cost); +fprintf('theta: \n'); +fprintf(' %f \n', theta); + +% Plot Boundary +plotDecisionBoundary(theta, X, y); + +% Put some labels +hold on; +% Labels and Legend +xlabel('Exam 1 score') +ylabel('Exam 2 score') + +% Specified in plot order +legend('Admitted', 'Not admitted') +hold off; + +fprintf('\nProgram paused. Press enter to continue.\n'); +%pause; + +%% ============== Part 4: Predict and Accuracies ============== +% After learning the parameters, you'll like to use it to predict the outcomes +% on unseen data. In this part, you will use the logistic regression model +% to predict the probability that a student with score 20 on exam 1 and +% score 80 on exam 2 will be admitted. +% +% Furthermore, you will compute the training and test set accuracies of +% our model. +% +% Your task is to complete the code in predict.m + +% Predict probability for a student with score 45 on exam 1 +% and score 85 on exam 2 + +prob = sigmoid([1 45 85] * theta); +fprintf(['For a student with scores 45 and 85, we predict an admission ' ... + 'probability of %f\n\n'], prob); + +% Compute accuracy on our training set +p = predict(theta, X); + +fprintf('Train Accuracy: %f\n', mean(double(p == y)) * 100); + +fprintf('\nProgram paused. Press enter to continue.\n'); +%pause; + diff --git a/R_LogR/mlclass-ex2/ex2_reg.m b/R_LogR/mlclass-ex2/ex2_reg.m new file mode 100644 index 0000000..a7b95c2 --- /dev/null +++ b/R_LogR/mlclass-ex2/ex2_reg.m @@ -0,0 +1,117 @@ +%% Machine Learning Online Class - Exercise 2: Logistic Regression +% +% Instructions +% ------------ +% +% This file contains code that helps you get started on the second part +% of the exercise which covers regularization with logistic regression. +% +% You will need to complete the following functions in this exericse: +% +% sigmoid.m +% costFunction.m +% predict.m +% costFunctionReg.m +% +% For this exercise, you will not need to change any code in this file, +% or any other files other than those mentioned above. +% + +%% Initialization +clear ; close all; clc + +%% Load Data +% The first two columns contains the exam scores and the third column +% contains the label. + +data = load('ex2data2.txt'); +X = data(:, [1, 2]); y = data(:, 3); + +plotData(X, y); + +% Put some labels +hold on; + +% Labels and Legend +xlabel('Microchip Test 1') +ylabel('Microchip Test 2') + +% Specified in plot order +legend('y = 1', 'y = 0') +hold off; + + +%% =========== Part 1: Regularized Logistic Regression ============ +% In this part, you are given a dataset with data points that are not +% linearly separable. However, you would still like to use logistic +% regression to classify the data points. +% +% To do so, you introduce more features to use -- in particular, you add +% polynomial features to our data matrix (similar to polynomial +% regression). +% + +% Add Polynomial Features + +% Note that mapFeature also adds a column of ones for us, so the intercept +% term is handled +X = mapFeature(X(:,1), X(:,2)); + +% Initialize fitting parameters +initial_theta = zeros(size(X, 2), 1); + +% Set regularization parameter lambda to 1 +lambda = 1; + +% Compute and display initial cost and gradient for regularized logistic +% regression +[cost, grad] = costFunctionReg(initial_theta, X, y, lambda); + +fprintf('Cost at initial theta (zeros): %f\n', cost); + +fprintf('\nProgram paused. Press enter to continue.\n'); +% pause; + +%% ============= Part 2: Regularization and Accuracies ============= +% Optional Exercise: +% In this part, you will get to try different values of lambda and +% see how regularization affects the decision coundart +% +% Try the following values of lambda (0, 1, 10, 100). +% +% How does the decision boundary change when you vary lambda? How does +% the training set accuracy vary? +% + +% Initialize fitting parameters +initial_theta = zeros(size(X, 2), 1); + +% Set regularization parameter lambda to 1 (you should vary this) +lambda = 0.1; + +% Set Options +options = optimset('GradObj', 'on', 'MaxIter', 400); + +% Optimize +[theta, J, exit_flag] = ... + fminunc(@(t)(costFunctionReg(t, X, y, lambda)), initial_theta, options); + +% Plot Boundary +plotDecisionBoundary(theta, X, y); +hold on; +title(sprintf('lambda = %g', lambda)) + +% Labels and Legend +xlabel('Microchip Test 1') +ylabel('Microchip Test 2') + +legend('y = 1', 'y = 0', 'Decision boundary') +hold off; + +% Compute accuracy on our training set +p = predict(theta, X); + +fprintf('Train Accuracy: %f\n', mean(double(p == y)) * 100); + + + diff --git a/R_LogR/mlclass-ex2/mapFeature.m b/R_LogR/mlclass-ex2/mapFeature.m new file mode 100644 index 0000000..d02a72a --- /dev/null +++ b/R_LogR/mlclass-ex2/mapFeature.m @@ -0,0 +1,21 @@ +function out = mapFeature(X1, X2) +% MAPFEATURE Feature mapping function to polynomial features +% +% MAPFEATURE(X1, X2) maps the two input features +% to quadratic features used in the regularization exercise. +% +% Returns a new feature array with more features, comprising of +% X1, X2, X1.^2, X2.^2, X1*X2, X1*X2.^2, etc.. +% +% Inputs X1, X2 must be the same size +% + +degree = 6; +out = ones(size(X1(:,1))); +for i = 1:degree + for j = 0:i + out(:, end+1) = (X1.^(i-j)).*(X2.^j); + end +end + +end \ No newline at end of file diff --git a/R_LogR/mlclass-ex2/plotData.m b/R_LogR/mlclass-ex2/plotData.m new file mode 100644 index 0000000..2eda757 --- /dev/null +++ b/R_LogR/mlclass-ex2/plotData.m @@ -0,0 +1,33 @@ +function plotData(X, y) +%PLOTDATA Plots the data points X and y into a new figure +% PLOTDATA(x,y) plots the data points with + for the positive examples +% and o for the negative examples. X is assumed to be a Mx2 matrix. + +% Create New Figure +figure; hold on; + +% ====================== YOUR CODE HERE ====================== +% Instructions: Plot the positive and negative examples on a +% 2D plot, using the option 'k+' for the positive +% examples and 'ko' for the negative examples. +% + +#positive_vals = find(y == 1); +#negative_vals = find(y == 0); + + +#plot(X(positive_vals, 1), X(positive_vals, 2), 'k+', 'MarkerSize', 7); +#plot(X(negative_vals, 1), X(negative_vals, 2), 'ko', 'MarkerSize', 7); + + +pos = find(y==1); neg = find(y == 0); +plot(X(pos, 1), X(pos, 2), 'k+', 'MarkerSize', 7); +plot(X(neg, 1), X(neg, 2), 'ko', 'MarkerSize', 7); + +% ========================================================================= + + + +hold off; + +end diff --git a/R_LogR/mlclass-ex2/plotDecisionBoundary.m b/R_LogR/mlclass-ex2/plotDecisionBoundary.m new file mode 100644 index 0000000..cfdf3e4 --- /dev/null +++ b/R_LogR/mlclass-ex2/plotDecisionBoundary.m @@ -0,0 +1,49 @@ +function plotDecisionBoundary(theta, X, y) +%PLOTDECISIONBOUNDARY Plots the data points X and y into a new figure with +%the decision boundary defined by theta +% PLOTDECISIONBOUNDARY(theta, X,y) plots the data points with + for the +% positive examples and o for the negative examples. X is assumed to be +% a either +% 1) Mx3 matrix, where the first column is an all-ones column for the +% intercept. +% 2) MxN, N>3 matrix, where the first column is all-ones + +% Plot Data +plotData(X(:,2:3), y); +hold on + +if size(X, 2) <= 3 + % Only need 2 points to define a line, so choose two endpoints + plot_x = [min(X(:,2))-2, max(X(:,2))+2]; + + % Calculate the decision boundary line + plot_y = (-1./theta(3)).*(theta(2).*plot_x + theta(1)); + + % Plot, and adjust axes for better viewing + plot(plot_x, plot_y) + + % Legend, specific for the exercise + legend('Admitted', 'Not admitted', 'Decision Boundary') + axis([30, 100, 30, 100]) +else + % Here is the grid range + u = linspace(-1, 1.5, 50); + v = linspace(-1, 1.5, 50); + + z = zeros(length(u), length(v)); + % Evaluate z = theta*x over the grid + for i = 1:length(u) + for j = 1:length(v) + z(i,j) = mapFeature(u(i), v(j))*theta; + end + end + z = z'; % important to transpose z before calling contour + + % Plot z = 0 + % Notice you need to specify the range [0, 0] + contour(u, v, z, [0, 0], 'LineWidth', 2) +end +hold off + +end + diff --git a/R_LogR/mlclass-ex2/predict.m b/R_LogR/mlclass-ex2/predict.m new file mode 100644 index 0000000..7af3a20 --- /dev/null +++ b/R_LogR/mlclass-ex2/predict.m @@ -0,0 +1,32 @@ +function p = predict(theta, X) +%PREDICT Predict whether the label is 0 or 1 using learned logistic +%regression parameters theta +% p = PREDICT(theta, X) computes the predictions for X using a +% threshold at 0.5 (i.e., if sigmoid(theta'*x) >= 0.5, predict 1) + +m = size(X, 1); % Number of training examples + +% You need to return the following variables correctly +p = zeros(m, 1); + +% ====================== YOUR CODE HERE ====================== +% Instructions: Complete the following code to make predictions using +% your learned logistic regression parameters. +% You should set p to a vector of 0's and 1's +% +thresh = 0.5 + +pred = sigmoid(X * theta); +for i = 1:m + if pred(i) >= thresh + p(i) = 1; + else + p(i) = 0; + endif + + + +% ========================================================================= + + +end diff --git a/R_LogR/mlclass-ex2/sigmoid.m b/R_LogR/mlclass-ex2/sigmoid.m new file mode 100644 index 0000000..a79fccd --- /dev/null +++ b/R_LogR/mlclass-ex2/sigmoid.m @@ -0,0 +1,18 @@ +function g = sigmoid(z) +%SIGMOID Compute sigmoid functoon +% J = SIGMOID(z) computes the sigmoid of z. + +% You need to return the following variables correctly +% g = zeros(size(z)); + +% ====================== YOUR CODE HERE ====================== +% Instructions: Compute the sigmoid of each value of z (z can be a matrix, +% vector or scalar). + + +g = 1 ./ (1 + exp(-z)); + + +% ============================================================= + +end diff --git a/R_LogR/mlclass-ex2/submit.m b/R_LogR/mlclass-ex2/submit.m new file mode 100644 index 0000000..224a541 --- /dev/null +++ b/R_LogR/mlclass-ex2/submit.m @@ -0,0 +1,333 @@ +function submit(partId) +%SUBMIT Submit your code and output to the ml-class servers +% SUBMIT() will connect to the ml-class server and submit your solution + + fprintf('==\n== [ml-class] Submitting Solutions | Programming Exercise %s\n==\n', ... + homework_id()); + if ~exist('partId', 'var') || isempty(partId) + partId = promptPart(); + end + + % Check valid partId + partNames = validParts(); + if ~isValidPartId(partId) + fprintf('!! Invalid homework part selected.\n'); + fprintf('!! Expected an integer from 1 to %d.\n', numel(partNames) + 1); + fprintf('!! Submission Cancelled\n'); + return + end + + [login password] = loginPrompt(); + if isempty(login) + fprintf('!! Submission Cancelled\n'); + return + end + + fprintf('\n== Connecting to ml-class ... '); + if exist('OCTAVE_VERSION') + fflush(stdout); + end + + % Setup submit list + if partId == numel(partNames) + 1 + submitParts = 1:numel(partNames); + else + submitParts = [partId]; + end + + for s = 1:numel(submitParts) + % Submit this part + partId = submitParts(s); + + % Get Challenge + [login, ch, signature] = getChallenge(login); + if isempty(login) || isempty(ch) || isempty(signature) + % Some error occured, error string in first return element. + fprintf('\n!! Error: %s\n\n', login); + return + end + + % Attempt Submission with Challenge + ch_resp = challengeResponse(login, password, ch); + [result, str] = submitSolution(login, ch_resp, partId, output(partId), ... + source(partId), signature); + + fprintf('\n== [ml-class] Submitted Homework %s - Part %d - %s\n', ... + homework_id(), partId, partNames{partId}); + fprintf('== %s\n', strtrim(str)); + if exist('OCTAVE_VERSION') + fflush(stdout); + end + end + +end + +% ================== CONFIGURABLES FOR EACH HOMEWORK ================== + +function id = homework_id() + id = '2'; +end + +function [partNames] = validParts() + partNames = { 'Sigmoid Function ', ... + 'Logistic Regression Cost', ... + 'Logistic Regression Gradient', ... + 'Predict', ... + 'Regularized Logistic Regression Cost' ... + 'Regularized Logistic Regression Gradient' ... + }; +end + +function srcs = sources() + % Separated by part + srcs = { { 'sigmoid.m' }, ... + { 'costFunction.m' }, ... + { 'costFunction.m' }, ... + { 'predict.m' }, ... + { 'costFunctionReg.m' }, ... + { 'costFunctionReg.m' } }; +end + +function out = output(partId) + % Random Test Cases + X = [ones(20,1) (exp(1) * sin(1:1:20))' (exp(0.5) * cos(1:1:20))']; + y = sin(X(:,1) + X(:,2)) > 0; + if partId == 1 + out = sprintf('%0.5f ', sigmoid(X)); + elseif partId == 2 + out = sprintf('%0.5f ', costFunction([0.25 0.5 -0.5]', X, y)); + elseif partId == 3 + [cost, grad] = costFunction([0.25 0.5 -0.5]', X, y); + out = sprintf('%0.5f ', grad); + elseif partId == 4 + out = sprintf('%0.5f ', predict([0.25 0.5 -0.5]', X)); + elseif partId == 5 + out = sprintf('%0.5f ', costFunctionReg([0.25 0.5 -0.5]', X, y, 0.1)); + elseif partId == 6 + [cost, grad] = costFunctionReg([0.25 0.5 -0.5]', X, y, 0.1); + out = sprintf('%0.5f ', grad); + end +end + +function url = challenge_url() + url = 'http://www.ml-class.org/course/homework/challenge'; +end + +function url = submit_url() + url = 'http://www.ml-class.org/course/homework/submit'; +end + +% ========================= CHALLENGE HELPERS ========================= + +function src = source(partId) + src = ''; + src_files = sources(); + if partId <= numel(src_files) + flist = src_files{partId}; + for i = 1:numel(flist) + fid = fopen(flist{i}); + while ~feof(fid) + line = fgets(fid); + src = [src line]; + end + fclose(fid); + src = [src '||||||||']; + end + end +end + +function ret = isValidPartId(partId) + partNames = validParts(); + ret = (~isempty(partId)) && (partId >= 1) && (partId <= numel(partNames) + 1); +end + +function partId = promptPart() + fprintf('== Select which part(s) to submit:\n', ... + homework_id()); + partNames = validParts(); + srcFiles = sources(); + for i = 1:numel(partNames) + fprintf('== %d) %s [', i, partNames{i}); + fprintf(' %s ', srcFiles{i}{:}); + fprintf(']\n'); + end + fprintf('== %d) All of the above \n==\nEnter your choice [1-%d]: ', ... + numel(partNames) + 1, numel(partNames) + 1); + selPart = input('', 's'); + partId = str2num(selPart); + if ~isValidPartId(partId) + partId = -1; + end +end + +function [email,ch,signature] = getChallenge(email) + str = urlread(challenge_url(), 'post', {'email_address', email}); + + str = strtrim(str); + [email, str] = strtok (str, '|'); + [ch, str] = strtok (str, '|'); + [signature, str] = strtok (str, '|'); +end + + +function [result, str] = submitSolution(email, ch_resp, part, output, ... + source, signature) + + params = {'homework', homework_id(), ... + 'part', num2str(part), ... + 'email', email, ... + 'output', output, ... + 'source', source, ... + 'challenge_response', ch_resp, ... + 'signature', signature}; + + str = urlread(submit_url(), 'post', params); + + % Parse str to read for success / failure + result = 0; + +end + +% =========================== LOGIN HELPERS =========================== + +function [login password] = loginPrompt() + % Prompt for password + [login password] = basicPrompt(); + + if isempty(login) || isempty(password) + login = []; password = []; + end +end + + +function [login password] = basicPrompt() + login = input('Login (Email address): ', 's'); + password = input('Password: ', 's'); +end + + +function [str] = challengeResponse(email, passwd, challenge) + salt = ')~/|]QMB3[!W`?OVt7qC"@+}'; + str = sha1([challenge sha1([salt email passwd])]); + sel = randperm(numel(str)); + sel = sort(sel(1:16)); + str = str(sel); +end + + +% =============================== SHA-1 ================================ + +function hash = sha1(str) + + % Initialize variables + h0 = uint32(1732584193); + h1 = uint32(4023233417); + h2 = uint32(2562383102); + h3 = uint32(271733878); + h4 = uint32(3285377520); + + % Convert to word array + strlen = numel(str); + + % Break string into chars and append the bit 1 to the message + mC = [double(str) 128]; + mC = [mC zeros(1, 4-mod(numel(mC), 4), 'uint8')]; + + numB = strlen * 8; + if exist('idivide') + numC = idivide(uint32(numB + 65), 512, 'ceil'); + else + numC = ceil(double(numB + 65)/512); + end + numW = numC * 16; + mW = zeros(numW, 1, 'uint32'); + + idx = 1; + for i = 1:4:strlen + 1 + mW(idx) = bitor(bitor(bitor( ... + bitshift(uint32(mC(i)), 24), ... + bitshift(uint32(mC(i+1)), 16)), ... + bitshift(uint32(mC(i+2)), 8)), ... + uint32(mC(i+3))); + idx = idx + 1; + end + + % Append length of message + mW(numW - 1) = uint32(bitshift(uint64(numB), -32)); + mW(numW) = uint32(bitshift(bitshift(uint64(numB), 32), -32)); + + % Process the message in successive 512-bit chs + for cId = 1 : double(numC) + cSt = (cId - 1) * 16 + 1; + cEnd = cId * 16; + ch = mW(cSt : cEnd); + + % Extend the sixteen 32-bit words into eighty 32-bit words + for j = 17 : 80 + ch(j) = ch(j - 3); + ch(j) = bitxor(ch(j), ch(j - 8)); + ch(j) = bitxor(ch(j), ch(j - 14)); + ch(j) = bitxor(ch(j), ch(j - 16)); + ch(j) = bitrotate(ch(j), 1); + end + + % Initialize hash value for this ch + a = h0; + b = h1; + c = h2; + d = h3; + e = h4; + + % Main loop + for i = 1 : 80 + if(i >= 1 && i <= 20) + f = bitor(bitand(b, c), bitand(bitcmp(b), d)); + k = uint32(1518500249); + elseif(i >= 21 && i <= 40) + f = bitxor(bitxor(b, c), d); + k = uint32(1859775393); + elseif(i >= 41 && i <= 60) + f = bitor(bitor(bitand(b, c), bitand(b, d)), bitand(c, d)); + k = uint32(2400959708); + elseif(i >= 61 && i <= 80) + f = bitxor(bitxor(b, c), d); + k = uint32(3395469782); + end + + t = bitrotate(a, 5); + t = bitadd(t, f); + t = bitadd(t, e); + t = bitadd(t, k); + t = bitadd(t, ch(i)); + e = d; + d = c; + c = bitrotate(b, 30); + b = a; + a = t; + + end + h0 = bitadd(h0, a); + h1 = bitadd(h1, b); + h2 = bitadd(h2, c); + h3 = bitadd(h3, d); + h4 = bitadd(h4, e); + + end + + hash = reshape(dec2hex(double([h0 h1 h2 h3 h4]), 8)', [1 40]); + + hash = lower(hash); + +end + +function ret = bitadd(iA, iB) + ret = double(iA) + double(iB); + ret = bitset(ret, 33, 0); + ret = uint32(ret); +end + +function ret = bitrotate(iA, places) + t = bitshift(iA, places - 32); + ret = bitshift(iA, places); + ret = bitor(ret, t); +end diff --git a/R_LogR/mlclass-ex2/submitWeb.m b/R_LogR/mlclass-ex2/submitWeb.m new file mode 100644 index 0000000..22688ac --- /dev/null +++ b/R_LogR/mlclass-ex2/submitWeb.m @@ -0,0 +1,349 @@ +function submitWeb(partId) +%SUBMITWEB Generates a base64 encoded string for web-based submissions +% SUBMITWEB() will generate a base64 encoded string so that you can submit your +% solutions via a web form + + fprintf('==\n== [ml-class] Submitting Solutions | Programming Exercise %s\n==\n', ... + homework_id()); + if ~exist('partId', 'var') || isempty(partId) + partId = promptPart(); + end + + % Check valid partId + partNames = validParts(); + if ~isValidPartId(partId) + fprintf('!! Invalid homework part selected.\n'); + fprintf('!! Expected an integer from 1 to %d.\n', numel(partNames)); + fprintf('!! Submission Cancelled\n'); + return + end + + [login] = loginPrompt(); + if isempty(login) + fprintf('!! Submission Cancelled\n'); + return + end + + [result] = submitSolution(login, partId, output(partId), ... + source(partId)); + result = base64encode(result); + + fprintf('\nSave as submission file [submit_ex%s_part%d.txt]: ', ... + homework_id(), partId); + saveAsFile = input('', 's'); + if (isempty(saveAsFile)) + saveAsFile = sprintf('submit_ex%s_part%d.txt', homework_id(), partId); + end + + fid = fopen(saveAsFile, 'w'); + if (fid) + fwrite(fid, result); + fclose(fid); + fprintf('\nSaved your solutions to %s.\n\n', saveAsFile); + fprintf(['You can now submit your solutions through the web \n' ... + 'form in the programming exercises. Select the corresponding \n' ... + 'programming exercise to access the form.\n']); + + else + fprintf('Unable to save to %s\n\n', saveAsFile); + fprintf(['You can create a submission file by saving the \n' ... + 'following text in a file: (press enter to continue)\n\n']); + pause; + fprintf(result); + end + +end + +% ================== CONFIGURABLES FOR EACH HOMEWORK ================== + +function id = homework_id() + id = '2'; +end + +function [partNames] = validParts() + partNames = { 'Sigmoid Function ', ... + 'Logistic Regression Cost', ... + 'Logistic Regression Gradient', ... + 'Predict', ... + 'Regularized Logistic Regression Cost' ... + 'Regularized Logistic Regression Gradient' ... + }; +end + +function srcs = sources() + % Separated by part + srcs = { { 'sigmoid.m' }, ... + { 'costFunction.m' }, ... + { 'costFunction.m' }, ... + { 'predict.m' }, ... + { 'costFunctionReg.m' }, ... + { 'costFunctionReg.m' } }; +end + +function out = output(partId) + % Random Test Cases + X = [ones(20,1) (exp(1) * sin(1:1:20))' (exp(0.5) * cos(1:1:20))']; + y = sin(X(:,1) + X(:,2)) > 0; + if partId == 1 + out = sprintf('%0.5f ', sigmoid(X)); + elseif partId == 2 + out = sprintf('%0.5f ', costFunction([0.25 0.5 -0.5]', X, y)); + elseif partId == 3 + [cost, grad] = costFunction([0.25 0.5 -0.5]', X, y); + out = sprintf('%0.5f ', grad); + elseif partId == 4 + out = sprintf('%0.5f ', predict([0.25 0.5 -0.5]', X)); + elseif partId == 5 + out = sprintf('%0.5f ', costFunctionReg([0.25 0.5 -0.5]', X, y, 0.1)); + elseif partId == 6 + [cost, grad] = costFunctionReg([0.25 0.5 -0.5]', X, y, 0.1); + out = sprintf('%0.5f ', grad); + end +end + + +% ========================= SUBMIT HELPERS ========================= + +function src = source(partId) + src = ''; + src_files = sources(); + if partId <= numel(src_files) + flist = src_files{partId}; + for i = 1:numel(flist) + fid = fopen(flist{i}); + while ~feof(fid) + line = fgets(fid); + src = [src line]; + end + fclose(fid); + src = [src '||||||||']; + end + end +end + +function ret = isValidPartId(partId) + partNames = validParts(); + ret = (~isempty(partId)) && (partId >= 1) && (partId <= numel(partNames)); +end + +function partId = promptPart() + fprintf('== Select which part(s) to submit:\n', ... + homework_id()); + partNames = validParts(); + srcFiles = sources(); + for i = 1:numel(partNames) + fprintf('== %d) %s [', i, partNames{i}); + fprintf(' %s ', srcFiles{i}{:}); + fprintf(']\n'); + end + fprintf('\nEnter your choice [1-%d]: ', ... + numel(partNames)); + selPart = input('', 's'); + partId = str2num(selPart); + if ~isValidPartId(partId) + partId = -1; + end +end + + +function [result, str] = submitSolution(email, part, output, source) + + result = ['a:5:{' ... + p_s('homework') p_s64(homework_id()) ... + p_s('part') p_s64(part) ... + p_s('email') p_s64(email) ... + p_s('output') p_s64(output) ... + p_s('source') p_s64(source) ... + '}']; + +end + +function s = p_s(str) + s = ['s:' num2str(numel(str)) ':"' str '";']; +end + +function s = p_s64(str) + str = base64encode(str, ''); + s = ['s:' num2str(numel(str)) ':"' str '";']; +end + +% =========================== LOGIN HELPERS =========================== + +function [login] = loginPrompt() + % Prompt for password + [login] = basicPrompt(); +end + + +function [login] = basicPrompt() + login = input('Login (Email address): ', 's'); +end + + +% =========================== Base64 Encoder ============================ +% Thanks to Peter John Acklam +% + +function y = base64encode(x, eol) +%BASE64ENCODE Perform base64 encoding on a string. +% +% BASE64ENCODE(STR, EOL) encode the given string STR. EOL is the line ending +% sequence to use; it is optional and defaults to '\n' (ASCII decimal 10). +% The returned encoded string is broken into lines of no more than 76 +% characters each, and each line will end with EOL unless it is empty. Let +% EOL be empty if you do not want the encoded string broken into lines. +% +% STR and EOL don't have to be strings (i.e., char arrays). The only +% requirement is that they are vectors containing values in the range 0-255. +% +% This function may be used to encode strings into the Base64 encoding +% specified in RFC 2045 - MIME (Multipurpose Internet Mail Extensions). The +% Base64 encoding is designed to represent arbitrary sequences of octets in a +% form that need not be humanly readable. A 65-character subset +% ([A-Za-z0-9+/=]) of US-ASCII is used, enabling 6 bits to be represented per +% printable character. +% +% Examples +% -------- +% +% If you want to encode a large file, you should encode it in chunks that are +% a multiple of 57 bytes. This ensures that the base64 lines line up and +% that you do not end up with padding in the middle. 57 bytes of data fills +% one complete base64 line (76 == 57*4/3): +% +% If ifid and ofid are two file identifiers opened for reading and writing, +% respectively, then you can base64 encode the data with +% +% while ~feof(ifid) +% fwrite(ofid, base64encode(fread(ifid, 60*57))); +% end +% +% or, if you have enough memory, +% +% fwrite(ofid, base64encode(fread(ifid))); +% +% See also BASE64DECODE. + +% Author: Peter John Acklam +% Time-stamp: 2004-02-03 21:36:56 +0100 +% E-mail: pjacklam@online.no +% URL: http://home.online.no/~pjacklam + + if isnumeric(x) + x = num2str(x); + end + + % make sure we have the EOL value + if nargin < 2 + eol = sprintf('\n'); + else + if sum(size(eol) > 1) > 1 + error('EOL must be a vector.'); + end + if any(eol(:) > 255) + error('EOL can not contain values larger than 255.'); + end + end + + if sum(size(x) > 1) > 1 + error('STR must be a vector.'); + end + + x = uint8(x); + eol = uint8(eol); + + ndbytes = length(x); % number of decoded bytes + nchunks = ceil(ndbytes / 3); % number of chunks/groups + nebytes = 4 * nchunks; % number of encoded bytes + + % add padding if necessary, to make the length of x a multiple of 3 + if rem(ndbytes, 3) + x(end+1 : 3*nchunks) = 0; + end + + x = reshape(x, [3, nchunks]); % reshape the data + y = repmat(uint8(0), 4, nchunks); % for the encoded data + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Split up every 3 bytes into 4 pieces + % + % aaaaaabb bbbbcccc ccdddddd + % + % to form + % + % 00aaaaaa 00bbbbbb 00cccccc 00dddddd + % + y(1,:) = bitshift(x(1,:), -2); % 6 highest bits of x(1,:) + + y(2,:) = bitshift(bitand(x(1,:), 3), 4); % 2 lowest bits of x(1,:) + y(2,:) = bitor(y(2,:), bitshift(x(2,:), -4)); % 4 highest bits of x(2,:) + + y(3,:) = bitshift(bitand(x(2,:), 15), 2); % 4 lowest bits of x(2,:) + y(3,:) = bitor(y(3,:), bitshift(x(3,:), -6)); % 2 highest bits of x(3,:) + + y(4,:) = bitand(x(3,:), 63); % 6 lowest bits of x(3,:) + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Now perform the following mapping + % + % 0 - 25 -> A-Z + % 26 - 51 -> a-z + % 52 - 61 -> 0-9 + % 62 -> + + % 63 -> / + % + % We could use a mapping vector like + % + % ['A':'Z', 'a':'z', '0':'9', '+/'] + % + % but that would require an index vector of class double. + % + z = repmat(uint8(0), size(y)); + i = y <= 25; z(i) = 'A' + double(y(i)); + i = 26 <= y & y <= 51; z(i) = 'a' - 26 + double(y(i)); + i = 52 <= y & y <= 61; z(i) = '0' - 52 + double(y(i)); + i = y == 62; z(i) = '+'; + i = y == 63; z(i) = '/'; + y = z; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Add padding if necessary. + % + npbytes = 3 * nchunks - ndbytes; % number of padding bytes + if npbytes + y(end-npbytes+1 : end) = '='; % '=' is used for padding + end + + if isempty(eol) + + % reshape to a row vector + y = reshape(y, [1, nebytes]); + + else + + nlines = ceil(nebytes / 76); % number of lines + neolbytes = length(eol); % number of bytes in eol string + + % pad data so it becomes a multiple of 76 elements + y = [y(:) ; zeros(76 * nlines - numel(y), 1)]; + y(nebytes + 1 : 76 * nlines) = 0; + y = reshape(y, 76, nlines); + + % insert eol strings + eol = eol(:); + y(end + 1 : end + neolbytes, :) = eol(:, ones(1, nlines)); + + % remove padding, but keep the last eol string + m = nebytes + neolbytes * (nlines - 1); + n = (76+neolbytes)*nlines - neolbytes; + y(m+1 : n) = ''; + + % extract and reshape to row vector + y = reshape(y, 1, m+neolbytes); + + end + + % output is a character array + y = char(y); + +end diff --git a/R_LogR/survey.csv b/R_LogR/survey.csv new file mode 100644 index 0000000..f39e287 --- /dev/null +++ b/R_LogR/survey.csv @@ -0,0 +1,751 @@ +MYDEPV,Price,Income,Age +1,10,33,37 +0,20,21,55 +1,30,59,55 +1,20,76,44 +0,30,24,37 +0,20,22,32 +1,10,28,32 +1,10,49,38 +0,30,76,43 +1,20,59,55 +0,30,45,32 +0,30,21,46 +0,30,49,44 +0,10,23,30 +1,10,55,55 +0,20,29,32 +1,10,49,44 +0,20,45,32 +0,20,24,37 +0,10,30,32 +0,10,24,55 +1,10,59,55 +0,30,31,32 +0,20,33,32 +0,30,22,32 +0,30,29,32 +0,10,30,32 +0,20,28,32 +1,30,59,55 +0,30,56,43 +1,30,77,43 +1,20,97,18 +0,20,23,32 +0,30,25,37 +0,30,23,32 +0,30,88,43 +0,30,49,44 +1,30,76,44 +1,20,67,25 +1,10,55,55 +0,20,26,37 +1,20,49,44 +1,20,68,25 +0,30,45,32 +1,20,68,43 +0,20,32,35 +1,30,22,55 +1,30,55,55 +1,20,66,43 +0,20,29,32 +1,10,49,44 +1,10,28,32 +1,10,23,37 +0,20,45,32 +0,30,22,37 +1,10,66,25 +0,20,30,32 +0,20,43,27 +0,20,34,55 +0,30,32,32 +1,10,67,25 +0,20,25,27 +1,20,49,38 +0,30,33,55 +0,20,30,32 +1,10,34,37 +0,30,33,32 +0,10,32,27 +0,20,30,32 +1,20,66,25 +0,30,29,32 +1,10,25,37 +1,20,55,55 +0,30,22,32 +1,10,28,38 +0,20,22,44 +0,30,28,32 +0,10,45,32 +1,20,65,22 +1,10,78,21 +1,30,66,25 +1,20,99,25 +0,10,21,44 +0,20,23,37 +0,30,22,37 +1,30,88,43 +0,30,28,32 +1,30,49,55 +1,10,55,55 +0,20,29,32 +0,30,87,43 +1,30,66,25 +1,20,77,22 +1,10,26,37 +0,30,45,32 +0,20,43,22 +1,30,64,33 +0,20,45,32 +0,10,30,32 +0,30,56,43 +0,20,30,32 +0,30,30,32 +1,10,78,25 +1,20,77,43 +1,20,49,38 +0,30,32,35 +0,10,29,32 +1,20,89,22 +0,30,30,32 +1,30,55,55 +0,20,22,32 +0,20,32,32 +0,30,30,32 +0,30,49,44 +1,10,77,43 +1,20,59,55 +0,20,30,32 +0,30,22,27 +1,20,68,25 +1,10,59,55 +1,30,17,23 +0,20,22,32 +1,10,44,43 +1,20,76,21 +0,20,29,32 +1,10,59,55 +0,20,29,32 +0,30,23,30 +1,20,49,44 +0,20,33,32 +0,20,23,32 +1,10,64,33 +1,10,49,44 +1,30,57,25 +1,10,28,32 +0,10,22,32 +0,30,22,44 +0,20,33,23 +0,30,46,43 +0,30,22,32 +1,20,59,55 +0,10,22,32 +1,20,59,55 +1,10,33,24 +0,10,55,44 +0,30,49,38 +1,30,77,25 +0,20,22,37 +1,30,55,55 +1,30,22,25 +1,10,44,37 +0,30,21,37 +1,20,49,44 +1,20,55,55 +0,30,33,32 +0,10,30,32 +0,10,29,32 +0,30,49,38 +1,10,21,37 +1,10,55,25 +0,30,22,32 +0,20,28,32 +0,10,25,27 +1,20,98,43 +1,20,43,37 +0,30,49,38 +1,20,76,43 +0,10,30,32 +0,30,32,27 +1,10,59,55 +0,20,21,27 +0,30,55,44 +1,20,77,24 +0,30,34,37 +1,10,59,55 +1,10,65,25 +1,10,78,65 +0,20,19,46 +1,10,65,22 +1,20,59,55 +1,30,55,27 +0,20,29,32 +1,20,49,38 +0,20,23,38 +1,20,34,37 +0,30,30,32 +1,30,59,55 +1,10,22,25 +1,10,55,23 +0,30,29,32 +0,20,22,32 +0,20,33,27 +1,10,56,43 +1,10,49,44 +1,10,68,25 +0,10,22,32 +0,20,33,32 +0,20,22,27 +0,30,28,32 +0,20,45,32 +0,30,28,38 +0,30,24,27 +0,20,30,32 +0,20,29,32 +0,10,24,32 +1,10,28,32 +1,10,55,55 +0,20,20,47 +0,20,30,32 +0,30,28,32 +0,10,30,32 +0,20,22,37 +0,30,20,47 +0,30,45,32 +0,10,30,32 +0,20,22,27 +1,10,33,25 +0,10,30,32 +0,10,21,55 +0,10,45,32 +1,30,68,25 +0,10,30,32 +1,30,65,22 +0,30,49,44 +1,30,44,25 +0,20,28,32 +1,10,49,32 +1,10,66,43 +0,30,45,32 +1,10,65,25 +1,20,55,23 +1,30,78,21 +1,10,66,22 +0,20,25,37 +0,10,43,22 +1,10,66,43 +0,30,21,55 +0,20,23,27 +0,30,29,32 +1,20,56,43 +0,30,24,27 +1,10,55,44 +1,20,59,55 +0,10,34,25 +0,20,34,23 +1,20,66,25 +0,30,34,25 +0,20,32,32 +0,10,33,27 +1,10,88,23 +0,30,29,32 +0,30,22,27 +1,20,17,23 +1,10,54,25 +1,20,77,25 +1,10,59,55 +0,10,33,32 +0,20,32,37 +0,10,22,37 +1,20,55,37 +1,30,59,55 +0,10,29,32 +1,10,32,32 +1,20,28,38 +1,10,66,25 +0,10,45,32 +1,20,55,55 +0,10,19,46 +0,30,21,44 +1,20,49,44 +0,10,33,32 +0,20,30,32 +1,30,89,22 +0,30,30,32 +0,20,34,25 +1,30,55,55 +0,30,30,32 +0,20,55,44 +0,20,30,32 +1,30,59,55 +0,30,34,55 +0,10,33,23 +0,10,30,32 +0,10,45,32 +0,10,29,32 +0,30,78,43 +0,30,30,32 +0,30,22,37 +1,20,49,44 +1,20,49,38 +1,30,33,24 +1,20,57,25 +1,10,17,23 +1,10,55,55 +1,10,76,21 +0,10,29,32 +0,10,23,32 +0,20,33,55 +0,30,29,32 +0,20,29,32 +0,10,29,32 +0,20,28,32 +1,20,55,25 +0,10,22,32 +0,30,32,32 +1,20,78,43 +1,10,87,43 +1,10,49,44 +0,10,43,27 +0,30,26,37 +0,20,29,32 +0,20,30,32 +0,10,22,66 +1,30,66,25 +0,10,30,32 +1,10,88,43 +0,20,33,34 +1,10,99,25 +1,20,55,55 +1,10,34,33 +0,30,28,32 +0,10,29,32 +0,30,29,32 +0,30,49,38 +0,30,33,44 +0,10,33,32 +1,10,59,55 +1,20,55,44 +1,20,66,43 +1,10,67,25 +0,10,30,32 +0,30,21,37 +0,30,30,32 +0,20,22,37 +0,20,30,32 +0,30,45,32 +0,30,28,38 +1,20,65,25 +0,30,30,32 +1,10,76,44 +1,10,49,44 +1,30,34,33 +0,30,22,27 +0,10,33,44 +0,10,30,32 +1,30,55,44 +1,20,77,25 +0,10,21,27 +1,10,76,43 +0,20,22,45 +0,30,29,32 +0,20,21,37 +0,30,33,37 +0,20,43,24 +1,10,59,55 +1,10,55,37 +1,20,49,44 +1,30,88,23 +0,20,25,37 +0,30,55,37 +0,10,34,55 +0,20,28,32 +0,30,30,32 +0,30,28,32 +0,10,45,32 +1,10,59,55 +0,30,29,32 +0,20,24,32 +0,10,30,32 +1,10,77,25 +1,20,87,43 +0,10,23,38 +1,10,28,38 +1,30,98,43 +0,20,33,32 +1,10,59,55 +0,20,45,32 +1,20,67,25 +0,10,21,46 +0,20,22,32 +1,20,28,38 +1,10,21,37 +1,30,44,22 +0,10,33,27 +0,20,28,32 +0,30,29,32 +1,20,78,65 +0,20,24,27 +0,30,67,43 +1,30,97,18 +0,30,28,32 +0,10,30,32 +0,30,24,55 +0,20,33,37 +0,30,33,32 +1,20,33,24 +1,30,55,25 +0,10,33,34 +1,10,55,55 +0,10,24,37 +0,10,30,32 +0,10,22,37 +0,30,22,45 +0,30,30,32 +1,30,55,55 +1,30,66,25 +0,30,29,32 +1,10,22,55 +0,30,29,32 +0,10,30,32 +0,30,30,32 +0,30,33,23 +0,20,31,32 +1,30,55,55 +0,30,29,32 +0,10,32,35 +0,30,33,32 +0,30,30,32 +1,10,49,44 +0,30,23,38 +1,20,64,33 +1,20,78,43 +1,10,67,43 +1,30,78,65 +0,20,33,23 +0,30,49,44 +1,10,28,32 +0,20,28,32 +0,20,30,32 +0,20,30,32 +0,30,22,37 +1,10,49,44 +1,10,88,43 +1,10,32,32 +1,20,33,43 +1,20,56,26 +0,30,44,37 +0,20,32,27 +0,10,22,37 +0,20,33,27 +1,10,98,43 +0,20,21,37 +0,30,30,32 +0,30,31,32 +0,30,33,23 +0,30,30,32 +0,20,29,32 +0,30,29,32 +1,20,49,38 +1,30,59,55 +1,30,59,55 +0,30,43,27 +0,30,21,54 +0,10,22,44 +1,10,56,26 +0,30,30,32 +0,10,22,27 +1,10,68,25 +1,10,66,25 +1,30,77,25 +0,20,28,32 +0,30,49,44 +0,10,33,32 +1,30,33,25 +1,10,28,32 +0,20,22,27 +0,20,33,32 +0,20,30,32 +1,30,33,43 +1,10,33,43 +1,20,59,55 +0,10,34,23 +0,30,49,44 +1,10,77,22 +1,20,49,44 +1,10,56,43 +1,20,65,25 +0,10,23,27 +1,10,78,43 +1,30,55,55 +0,20,22,66 +1,10,59,55 +0,10,25,37 +1,10,59,55 +0,30,33,32 +0,10,45,32 +0,20,22,32 +0,20,28,32 +0,10,21,54 +1,10,44,22 +0,30,43,37 +0,20,45,32 +0,20,25,27 +1,20,49,44 +0,30,43,22 +0,10,33,55 +1,10,55,23 +0,10,22,32 +0,30,29,32 +0,10,30,32 +1,20,22,55 +0,20,33,44 +1,30,55,55 +0,10,29,32 +1,30,65,25 +1,30,99,25 +1,30,66,43 +0,10,22,32 +0,20,29,32 +1,30,67,25 +1,20,66,25 +0,20,22,27 +0,30,30,32 +0,30,22,32 +0,20,29,32 +1,10,49,38 +0,30,24,32 +0,20,21,54 +0,10,29,32 +0,30,23,27 +1,10,28,32 +0,30,49,44 +1,30,49,32 +0,20,29,32 +1,20,66,25 +0,30,33,34 +0,20,29,32 +1,10,46,43 +0,10,30,32 +1,30,65,25 +1,20,44,25 +1,10,59,55 +0,10,24,27 +0,10,22,27 +0,20,22,37 +1,10,77,25 +0,20,30,32 +0,10,33,32 +1,10,55,25 +1,30,56,26 +0,30,68,43 +1,20,55,55 +1,30,77,24 +0,30,49,44 +1,30,59,55 +0,10,29,32 +0,30,49,38 +1,20,49,44 +1,20,59,55 +0,30,49,44 +1,20,55,27 +0,30,19,46 +0,10,29,32 +0,10,29,32 +1,30,66,43 +1,20,55,55 +1,10,55,55 +1,10,28,32 +0,30,22,32 +1,20,59,55 +0,30,45,32 +1,10,49,38 +1,20,28,38 +0,10,33,32 +1,10,22,37 +0,30,33,27 +0,30,33,32 +1,10,28,38 +1,20,59,55 +0,30,33,37 +1,20,33,25 +1,10,55,55 +0,30,78,43 +1,20,67,43 +1,20,49,32 +0,10,30,32 +1,10,66,25 +1,10,49,38 +1,20,56,43 +1,20,78,25 +1,30,55,55 +0,30,22,37 +1,30,59,55 +1,20,55,55 +0,30,23,37 +1,10,49,44 +1,10,49,38 +0,10,43,24 +0,10,23,32 +1,20,49,44 +0,30,31,32 +0,30,33,27 +0,20,22,37 +1,30,77,22 +1,30,59,55 +0,20,22,32 +1,30,55,23 +0,30,30,32 +1,10,49,44 +0,20,22,32 +1,10,68,43 +1,10,49,55 +1,20,49,55 +0,20,29,32 +0,10,24,27 +1,20,36,37 +0,30,32,37 +1,10,57,25 +0,10,21,37 +1,20,59,55 +0,30,22,32 +0,10,31,32 +0,30,29,32 +1,20,55,25 +1,10,89,22 +0,30,22,66 +0,10,22,27 +0,30,34,23 +0,20,29,32 +1,20,34,33 +0,10,45,32 +0,10,20,47 +1,10,33,37 +0,20,30,32 +0,10,45,32 +0,30,28,38 +0,20,21,37 +1,30,76,21 +0,30,29,32 +0,30,49,38 +0,20,55,36 +1,10,55,27 +0,10,29,32 +0,20,24,27 +1,10,28,32 +0,30,22,27 +0,30,29,32 +1,10,97,18 +1,30,67,25 +1,30,55,55 +0,30,25,37 +1,10,22,37 +0,30,28,32 +0,20,33,32 +0,30,49,44 +1,20,22,25 +1,10,77,24 +0,10,29,32 +0,30,55,36 +0,10,32,37 +1,20,59,55 +0,20,29,32 +1,10,28,38 +1,20,88,43 +0,20,29,32 +0,20,23,30 +1,30,55,25 +1,20,88,43 +1,10,49,44 +1,30,54,25 +1,20,55,55 +0,30,28,32 +1,20,88,23 +0,20,44,37 +0,20,21,46 +1,10,49,38 +1,20,55,23 +0,10,29,32 +1,10,44,25 +0,20,31,32 +0,30,29,32 +0,30,33,24 +0,10,33,23 +0,10,31,32 +1,30,59,55 +0,10,22,27 +0,10,22,32 +1,20,55,55 +1,10,43,37 +0,30,22,32 +0,10,25,27 +0,20,31,32 +0,20,29,32 +1,20,44,43 +0,20,45,32 +0,10,29,32 +1,30,55,23 +0,20,30,32 +0,30,30,32 +1,10,49,44 +0,20,30,32 +0,30,25,27 +0,10,29,32 +0,20,33,24 +1,20,55,55 +0,30,44,43 +0,10,29,32 +1,10,36,37 +0,30,21,27 +1,20,66,43 +0,30,49,44 +0,30,36,37 +0,30,30,32 +1,20,88,23 +1,20,49,38 +0,30,45,32 +1,20,46,43 +0,20,21,44 +1,20,66,22 +0,30,23,32 +1,20,59,55 +0,10,22,45 +0,20,30,32 +0,10,33,24 +0,10,29,32 +0,30,29,32 +0,10,31,32 +1,10,78,43 +0,20,33,37 +1,20,78,21 +1,10,88,23 +1,20,59,55 +1,30,59,55 +0,30,43,24 +1,30,78,25 +1,30,88,23 +1,30,66,22 +1,20,54,25 +0,20,45,32 +1,20,49,44 +0,20,24,55 +1,10,66,43 +1,20,44,22 +1,10,55,55 +1,30,59,55 +0,20,30,32 +0,10,22,32 +1,20,49,44 +0,30,66,43 +1,30,68,25 +1,30,59,55 +0,20,28,38 +1,10,59,55 +0,20,29,32 +1,10,55,55 +0,30,25,27 +0,10,29,32 +0,10,55,36 +0,30,21,37 +0,30,28,38 \ No newline at end of file diff --git a/shit.ipynb b/shit.ipynb deleted file mode 100644 index a40f014..0000000 --- a/shit.ipynb +++ /dev/null @@ -1,1757 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Fundamentals of Accelerated Data Science # " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 02 - K-Means ##\n", - "\n", - "**Table of Contents**\n", - "
\n", - "This notebook uses GPU-accelerated K-means to find the best locations for a fixed number of humanitarian supply airdrop depots. This notebook covers the below sections: \n", - "1. [Environment](#Environment)\n", - "2. [Load Data](#Load-Data)\n", - "3. [K-Means Clustering](#K-Means-Clustering)\n", - " * [Exercise #1 - Make Another `KMeans` Instance](#Exercise-#1---Make-Another-KMeans-Instance)\n", - "4. [Visualize the Clusters](#Visualize-the-Clusters)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Environment ##\n", - "For the first time we import `cuml`, the RAPIDS GPU-accelerated library containing many common machine learning algorithms. We will be visualizing the results of your work in this notebook, so we also import `cuxfilter`." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "# DO NOT CHANGE THIS CELL\n", - "import cudf\n", - "import cuml\n", - "import cupy as cp\n", - "import cuxfilter as cxf" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Load Data ##\n", - "For this notebook we load again the cleaned UK population data--in this case, we are not specifically looking at counties, so we omit that column and just keep the grid coordinate columns." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "northing float64\n", - "easting float64\n", - "dtype: object\n" - ] - }, - { - "data": { - "text/plain": [ - "(58479894, 2)" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# DO NOT CHANGE THIS CELL\n", - "gdf = cudf.read_csv('./data/clean_uk_pop.csv', usecols=['easting', 'northing'])\n", - "print(gdf.dtypes)\n", - "gdf.shape" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
northingeastingcluster
0515491.5313430772.18751
1503572.4688434685.87501
2517903.6563432565.53131
3517059.9063427660.62501
4509228.6875425527.78131
\n", - "
" - ], - "text/plain": [ - " northing easting cluster\n", - "0 515491.5313 430772.1875 1\n", - "1 503572.4688 434685.8750 1\n", - "2 517903.6563 432565.5313 1\n", - "3 517059.9063 427660.6250 1\n", - "4 509228.6875 425527.7813 1" - ] - }, - "execution_count": 30, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "gdf.head()" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "# DO NOT CHANGE THIS CELL\n", - "# instantaite\n", - "km = cuml.KMeans(n_clusters=5)\n", - "\n", - "# fit\n", - "km.fit(gdf)\n", - "\n", - "km.cluster_centers_\n", - "\n", - "gdf['cluster'] = km.labels_.astype('uint8')" - ] - }, - { - "cell_type": "code", - "execution_count": 44, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{0: '#ff0000', 1: '#cbff00', 2: '#00ff66', 3: '#0066ff', 4: '#cc00ff'}" - ] - }, - "execution_count": 44, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "labels = sorted([int(i) for i in gdf['cluster'].unique().values])\n", - "\n", - "import colorsys\n", - "\n", - "def col(i, a):\n", - " r, g, b = colorsys.hsv_to_rgb(i/a, 1, 1)\n", - " return '#%02x%02x%02x' % (int(r*255), int(g*255), int(b*255))\n", - " \n", - "color_key = {i: col(i, len(labels)) for i in labels}\n", - "color_key" - ] - }, - { - "cell_type": "code", - "execution_count": 53, - "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "scatter() got an unexpected keyword argument 'color_column'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[53], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m cxf_data \u001b[38;5;241m=\u001b[39m cxf\u001b[38;5;241m.\u001b[39mDataFrame\u001b[38;5;241m.\u001b[39mfrom_dataframe(gdf)\n\u001b[0;32m----> 3\u001b[0m scatter_chart \u001b[38;5;241m=\u001b[39m \u001b[43mcxf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcharts\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdatashader\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mscatter\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 4\u001b[0m \u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43measting\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 5\u001b[0m \u001b[43m \u001b[49m\u001b[43my\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mnorthing\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 6\u001b[0m \u001b[43m \u001b[49m\u001b[43mpoint_size\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 7\u001b[0m \u001b[43m \u001b[49m\u001b[43mpixel_shade_type\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mlinear\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 8\u001b[0m \u001b[43m \u001b[49m\u001b[43maggregate_col\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mcluster\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 9\u001b[0m \u001b[43m \u001b[49m\u001b[43mcolor_column\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mcluster\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 10\u001b[0m \u001b[43m)\u001b[49m\n\u001b[1;32m 12\u001b[0m cluster_widget \u001b[38;5;241m=\u001b[39m cxf\u001b[38;5;241m.\u001b[39mcharts\u001b[38;5;241m.\u001b[39mpanel_widgets\u001b[38;5;241m.\u001b[39mmulti_select(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcluster\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", - "\u001b[0;31mTypeError\u001b[0m: scatter() got an unexpected keyword argument 'color_column'" - ] - } - ], - "source": [ - "cxf_data = cxf.DataFrame.from_dataframe(gdf)\n", - "\n", - "scatter_chart = cxf.charts.datashader.scatter(\n", - " x='easting',\n", - " y='northing',\n", - " point_size=1,\n", - " pixel_shade_type='linear',\n", - " aggregate_col='cluster',\n", - " color_column='cluster',\n", - ")\n", - "\n", - "cluster_widget = cxf.charts.panel_widgets.multi_select('cluster')" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/javascript": [ - "(function(root) {\n", - " function now() {\n", - " return new Date();\n", - " }\n", - "\n", - " const force = true;\n", - " const py_version = '3.5.2'.replace('rc', '-rc.').replace('.dev', '-dev.');\n", - " const reloading = false;\n", - " const Bokeh = root.Bokeh;\n", - "\n", - " // Set a timeout for this load but only if we are not already initializing\n", - " if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n", - " root._bokeh_timeout = Date.now() + 5000;\n", - " root._bokeh_failed_load = false;\n", - " }\n", - "\n", - " function run_callbacks() {\n", - " try {\n", - " root._bokeh_onload_callbacks.forEach(function(callback) {\n", - " if (callback != null)\n", - " callback();\n", - " });\n", - " } finally {\n", - " delete root._bokeh_onload_callbacks;\n", - " }\n", - " console.debug(\"Bokeh: all callbacks have finished\");\n", - " }\n", - "\n", - " function load_libs(css_urls, js_urls, js_modules, js_exports, callback) {\n", - " if (css_urls == null) css_urls = [];\n", - " if (js_urls == null) js_urls = [];\n", - " if (js_modules == null) js_modules = [];\n", - " if (js_exports == null) js_exports = {};\n", - "\n", - " root._bokeh_onload_callbacks.push(callback);\n", - "\n", - " if (root._bokeh_is_loading > 0) {\n", - " // Don't load bokeh if it is still initializing\n", - " console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", - " return null;\n", - " } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n", - " // There is nothing to load\n", - " run_callbacks();\n", - " return null;\n", - " }\n", - "\n", - " function on_load() {\n", - " root._bokeh_is_loading--;\n", - " if (root._bokeh_is_loading === 0) {\n", - " console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n", - " run_callbacks()\n", - " }\n", - " }\n", - " window._bokeh_on_load = on_load\n", - "\n", - " function on_error(e) {\n", - " const src_el = e.srcElement\n", - " console.error(\"failed to load \" + (src_el.href || src_el.src));\n", - " }\n", - "\n", - " const skip = [];\n", - " if (window.requirejs) {\n", - " window.requirejs.config({'packages': {}, 'paths': {'h3': 'https://cdn.jsdelivr.net/npm/h3-js@4.1.0/dist/h3-js.umd', 'deck-gl': 'https://cdn.jsdelivr.net/npm/deck.gl@9.0.20/dist.min', 'deck-json': 'https://cdn.jsdelivr.net/npm/@deck.gl/json@9.0.20/dist.min', 'loader-csv': 'https://cdn.jsdelivr.net/npm/@loaders.gl/csv@4.2.2/dist/dist.min', 'loader-json': 'https://cdn.jsdelivr.net/npm/@loaders.gl/json@4.2.2/dist/dist.min', 'loader-tiles': 'https://cdn.jsdelivr.net/npm/@loaders.gl/3d-tiles@4.2.2/dist/dist.min', 'mapbox-gl': 'https://api.mapbox.com/mapbox-gl-js/v3.0.1/mapbox-gl', 'carto': 'https://cdn.jsdelivr.net/npm/@deck.gl/carto@^9.0.20/dist.min'}, 'shim': {'deck-json': {'deps': ['deck-gl']}, 'deck-gl': {'deps': ['h3']}}});\n", - " require([\"h3\"], function(h3) {\n", - " window.h3 = h3\n", - " on_load()\n", - " })\n", - " require([\"deck-gl\"], function(deck) {\n", - " window.deck = deck\n", - " on_load()\n", - " })\n", - " require([\"deck-json\"], function() {\n", - " on_load()\n", - " })\n", - " require([\"loader-csv\"], function() {\n", - " on_load()\n", - " })\n", - " require([\"loader-json\"], function() {\n", - " on_load()\n", - " })\n", - " require([\"loader-tiles\"], function() {\n", - " on_load()\n", - " })\n", - " require([\"mapbox-gl\"], function(mapboxgl) {\n", - " window.mapboxgl = mapboxgl\n", - " on_load()\n", - " })\n", - " require([\"carto\"], function() {\n", - " on_load()\n", - " })\n", - " root._bokeh_is_loading = css_urls.length + 8;\n", - " } else {\n", - " root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n", - " }\n", - "\n", - " const existing_stylesheets = []\n", - " const links = document.getElementsByTagName('link')\n", - " for (let i = 0; i < links.length; i++) {\n", - " const link = links[i]\n", - " if (link.href != null) {\n", - " existing_stylesheets.push(link.href)\n", - " }\n", - " }\n", - " for (let i = 0; i < css_urls.length; i++) {\n", - " const url = css_urls[i];\n", - " const escaped = encodeURI(url)\n", - " if (existing_stylesheets.indexOf(escaped) !== -1) {\n", - " on_load()\n", - " continue;\n", - " }\n", - " const element = document.createElement(\"link\");\n", - " element.onload = on_load;\n", - " element.onerror = on_error;\n", - " element.rel = \"stylesheet\";\n", - " element.type = \"text/css\";\n", - " element.href = url;\n", - " console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n", - " document.body.appendChild(element);\n", - " } if (((window.deck !== undefined) && (!(window.deck instanceof HTMLElement))) || window.requirejs) {\n", - " var urls = ['https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/h3-js@4.1.0/dist/h3-js.umd.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/deck.gl@9.0.20/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/json@9.0.20/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/csv@4.2.2/dist/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/json@4.2.2/dist/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/3d-tiles@4.2.2/dist/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/mapbox-gl-js/v3.0.1/mapbox-gl.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/maplibre-gl/dist/maplibre-gl.js'];\n", - " for (var i = 0; i < urls.length; i++) {\n", - " skip.push(encodeURI(urls[i]))\n", - " }\n", - " } if (((window.mapboxgl !== undefined) && (!(window.mapboxgl instanceof HTMLElement))) || window.requirejs) {\n", - " var urls = ['https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/carto@^9.0.20/dist.min.js'];\n", - " for (var i = 0; i < urls.length; i++) {\n", - " skip.push(encodeURI(urls[i]))\n", - " }\n", - " } var existing_scripts = []\n", - " const scripts = document.getElementsByTagName('script')\n", - " for (let i = 0; i < scripts.length; i++) {\n", - " var script = scripts[i]\n", - " if (script.src != null) {\n", - " existing_scripts.push(script.src)\n", - " }\n", - " }\n", - " for (let i = 0; i < js_urls.length; i++) {\n", - " const url = js_urls[i];\n", - " const escaped = encodeURI(url)\n", - " if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n", - " if (!window.requirejs) {\n", - " on_load();\n", - " }\n", - " continue;\n", - " }\n", - " const element = document.createElement('script');\n", - " element.onload = on_load;\n", - " element.onerror = on_error;\n", - " element.async = false;\n", - " element.src = url;\n", - " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", - " document.head.appendChild(element);\n", - " }\n", - " for (let i = 0; i < js_modules.length; i++) {\n", - " const url = js_modules[i];\n", - " const escaped = encodeURI(url)\n", - " if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n", - " if (!window.requirejs) {\n", - " on_load();\n", - " }\n", - " continue;\n", - " }\n", - " var element = document.createElement('script');\n", - " element.onload = on_load;\n", - " element.onerror = on_error;\n", - " element.async = false;\n", - " element.src = url;\n", - " element.type = \"module\";\n", - " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", - " document.head.appendChild(element);\n", - " }\n", - " for (const name in js_exports) {\n", - " const url = js_exports[name];\n", - " const escaped = encodeURI(url)\n", - " if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n", - " if (!window.requirejs) {\n", - " on_load();\n", - " }\n", - " continue;\n", - " }\n", - " var element = document.createElement('script');\n", - " element.onerror = on_error;\n", - " element.async = false;\n", - " element.type = \"module\";\n", - " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", - " element.textContent = `\n", - " import ${name} from \"${url}\"\n", - " window.${name} = ${name}\n", - " window._bokeh_on_load()\n", - " `\n", - " document.head.appendChild(element);\n", - " }\n", - " if (!js_urls.length && !js_modules.length) {\n", - " on_load()\n", - " }\n", - " };\n", - "\n", - " function inject_raw_css(css) {\n", - " const element = document.createElement(\"style\");\n", - " element.appendChild(document.createTextNode(css));\n", - " document.body.appendChild(element);\n", - " }\n", - "\n", - " const js_urls = [\"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/h3-js@4.1.0/dist/h3-js.umd.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/deck.gl@9.0.20/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/json@9.0.20/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/csv@4.2.2/dist/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/json@4.2.2/dist/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/3d-tiles@4.2.2/dist/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/mapbox-gl-js/v3.0.1/mapbox-gl.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/maplibre-gl/dist/maplibre-gl.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/carto@^9.0.20/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-3.5.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.5.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.5.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.5.2.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/panel.min.js\"];\n", - " const js_modules = [];\n", - " const js_exports = {};\n", - " const css_urls = [\"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/mapbox-gl-js/v3.0.1/mapbox-gl.css?v=1.5.2\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/maplibre-gl@4.4.1/dist/maplibre-gl.css?v=1.5.2\"];\n", - " const inline_js = [ function(Bokeh) {\n", - " inject_raw_css(\"\\n.dataframe table{\\n border: none;\\n}\\n\\n.panel-df table{\\n width: 100%;\\n border-collapse: collapse;\\n border: none;\\n}\\n.panel-df td{\\n white-space: nowrap;\\n overflow: auto;\\n text-overflow: ellipsis;\\n}\\n\");\n", - " }, function(Bokeh) {\n", - " inject_raw_css(\"\\n.multi-select{\\n color: white;\\n z-index: 100;\\n background: rgba(44,43,43,0.5);\\n border-radius: 1px;\\n width: 120px !important;\\n height: 30px !important;\\n}\\n.multi-select > .bk {\\n padding: 5px;\\n width: 120px !important;\\n height: 30px !important;\\n}\\n\\n.deck-chart {\\n z-index: 10;\\n position: initial !important;\\n}\\n\");\n", - " }, function(Bokeh) {\n", - " inject_raw_css(\"\\n.center-header {\\n text-align: center\\n}\\n.bk-input-group {\\n padding: 10px;\\n}\\n#sidebar {\\n padding-top: 10px;\\n}\\n.custom-widget-box {\\n margin-top: 20px;\\n padding: 5px;\\n border: None !important;\\n}\\n.custom-widget-box > p {\\n margin: 0px;\\n}\\n.bk-input-group {\\n color: None !important;\\n}\\n.indicator {\\n text-align: center;\\n}\\n.widget-card {\\n margin: 5px 10px;\\n}\\n.number-card {\\n margin: 5px 10px;\\n text-align: center;\\n}\\n.number-card-value {\\n width: 100%;\\n margin: 0px;\\n}\\n\");\n", - " }, function(Bokeh) {\n", - " Bokeh.set_log_level(\"info\");\n", - " },\n", - " function(Bokeh) {\n", - " (function(root, factory) {\n", - " factory(root[\"Bokeh\"]);\n", - " })(this, function(Bokeh) {\n", - " let define;\n", - " return (function outer(modules, entry) {\n", - " if (Bokeh != null) {\n", - " return Bokeh.register_plugin(modules, entry);\n", - " } else {\n", - " throw new Error(\"Cannot find Bokeh. You have to load it prior to loading plugins.\");\n", - " }\n", - " })\n", - " ({\n", - " \"custom/main\": function(require, module, exports) {\n", - " const models = {\n", - " \"CustomInspectTool\": require(\"custom/cuxfilter.charts.datashader.custom_extensions.graph_inspect_widget.custom_inspect_tool\").CustomInspectTool\n", - " };\n", - " require(\"base\").register_models(models);\n", - " module.exports = models;\n", - " },\n", - " \"custom/cuxfilter.charts.datashader.custom_extensions.graph_inspect_widget.custom_inspect_tool\": function(require, module, exports) {\n", - " \"use strict\";\n", - " var _a;\n", - " Object.defineProperty(exports, \"__esModule\", { value: true });\n", - " exports.CustomInspectTool = exports.CustomInspectToolView = void 0;\n", - " const inspect_tool_1 = require(\"models/tools/inspectors/inspect_tool\");\n", - " class CustomInspectToolView extends inspect_tool_1.InspectToolView {\n", - " connect_signals() {\n", - " super.connect_signals();\n", - " this.on_change([this.model.properties.active], () => {\n", - " this.model._active = this.model.active;\n", - " });\n", - " }\n", - " }\n", - " exports.CustomInspectToolView = CustomInspectToolView;\n", - " CustomInspectToolView.__name__ = \"CustomInspectToolView\";\n", - " class CustomInspectTool extends inspect_tool_1.InspectTool {\n", - " constructor(attrs) {\n", - " super(attrs);\n", - " }\n", - " }\n", - " exports.CustomInspectTool = CustomInspectTool;\n", - " _a = CustomInspectTool;\n", - " CustomInspectTool.__name__ = \"CustomInspectTool\";\n", - " (() => {\n", - " _a.prototype.default_view = CustomInspectToolView;\n", - " _a.define(({ Boolean }) => ({\n", - " _active: [Boolean, true]\n", - " }));\n", - " _a.register_alias(\"customInspect\", () => new _a());\n", - " })();\n", - " //# sourceMappingURL=graph_inspect_widget.py:CustomInspectTool.js.map\n", - " }\n", - " }, \"custom/main\");\n", - " ;\n", - " });\n", - "\n", - " },\n", - "function(Bokeh) {} // ensure no trailing comma for IE\n", - " ];\n", - "\n", - " function run_inline_js() {\n", - " if ((root.Bokeh !== undefined) || (force === true)) {\n", - " for (let i = 0; i < inline_js.length; i++) {\n", - " try {\n", - " inline_js[i].call(root, root.Bokeh);\n", - " } catch(e) {\n", - " if (!reloading) {\n", - " throw e;\n", - " }\n", - " }\n", - " }\n", - " // Cache old bokeh versions\n", - " if (Bokeh != undefined && !reloading) {\n", - " var NewBokeh = root.Bokeh;\n", - " if (Bokeh.versions === undefined) {\n", - " Bokeh.versions = new Map();\n", - " }\n", - " if (NewBokeh.version !== Bokeh.version) {\n", - " Bokeh.versions.set(NewBokeh.version, NewBokeh)\n", - " }\n", - " root.Bokeh = Bokeh;\n", - " }\n", - " } else if (Date.now() < root._bokeh_timeout) {\n", - " setTimeout(run_inline_js, 100);\n", - " } else if (!root._bokeh_failed_load) {\n", - " console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n", - " root._bokeh_failed_load = true;\n", - " }\n", - " root._bokeh_is_initializing = false\n", - " }\n", - "\n", - " function load_or_wait() {\n", - " // Implement a backoff loop that tries to ensure we do not load multiple\n", - " // versions of Bokeh and its dependencies at the same time.\n", - " // In recent versions we use the root._bokeh_is_initializing flag\n", - " // to determine whether there is an ongoing attempt to initialize\n", - " // bokeh, however for backward compatibility we also try to ensure\n", - " // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n", - " // before older versions are fully initialized.\n", - " if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n", - " // If the timeout and bokeh was not successfully loaded we reset\n", - " // everything and try loading again\n", - " root._bokeh_timeout = Date.now() + 5000;\n", - " root._bokeh_is_initializing = false;\n", - " root._bokeh_onload_callbacks = undefined;\n", - " root._bokeh_is_loading = 0\n", - " console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n", - " load_or_wait();\n", - " } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n", - " setTimeout(load_or_wait, 100);\n", - " } else {\n", - " root._bokeh_is_initializing = true\n", - " root._bokeh_onload_callbacks = []\n", - " const bokeh_loaded = root.Bokeh != null && (root.Bokeh.version === py_version || (root.Bokeh.versions !== undefined && root.Bokeh.versions.has(py_version)));\n", - " if (!reloading && !bokeh_loaded) {\n", - " if (root.Bokeh) {\n", - " root.Bokeh = undefined;\n", - " }\n", - " console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", - " }\n", - " load_libs(css_urls, js_urls, js_modules, js_exports, function() {\n", - " console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n", - " run_inline_js();\n", - " });\n", - " }\n", - " }\n", - " // Give older versions of the autoload script a head-start to ensure\n", - " // they initialize before we start loading newer version.\n", - " setTimeout(load_or_wait, 100)\n", - "}(window));" - ], - "application/vnd.holoviews_load.v0+json": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = true;\n const py_version = '3.5.2'.replace('rc', '-rc.').replace('.dev', '-dev.');\n const reloading = false;\n const Bokeh = root.Bokeh;\n\n // Set a timeout for this load but only if we are not already initializing\n if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks;\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, js_modules, js_exports, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n if (js_modules == null) js_modules = [];\n if (js_exports == null) js_exports = {};\n\n root._bokeh_onload_callbacks.push(callback);\n\n if (root._bokeh_is_loading > 0) {\n // Don't load bokeh if it is still initializing\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n // There is nothing to load\n run_callbacks();\n return null;\n }\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n window._bokeh_on_load = on_load\n\n function on_error(e) {\n const src_el = e.srcElement\n console.error(\"failed to load \" + (src_el.href || src_el.src));\n }\n\n const skip = [];\n if (window.requirejs) {\n window.requirejs.config({'packages': {}, 'paths': {'h3': 'https://cdn.jsdelivr.net/npm/h3-js@4.1.0/dist/h3-js.umd', 'deck-gl': 'https://cdn.jsdelivr.net/npm/deck.gl@9.0.20/dist.min', 'deck-json': 'https://cdn.jsdelivr.net/npm/@deck.gl/json@9.0.20/dist.min', 'loader-csv': 'https://cdn.jsdelivr.net/npm/@loaders.gl/csv@4.2.2/dist/dist.min', 'loader-json': 'https://cdn.jsdelivr.net/npm/@loaders.gl/json@4.2.2/dist/dist.min', 'loader-tiles': 'https://cdn.jsdelivr.net/npm/@loaders.gl/3d-tiles@4.2.2/dist/dist.min', 'mapbox-gl': 'https://api.mapbox.com/mapbox-gl-js/v3.0.1/mapbox-gl', 'carto': 'https://cdn.jsdelivr.net/npm/@deck.gl/carto@^9.0.20/dist.min'}, 'shim': {'deck-json': {'deps': ['deck-gl']}, 'deck-gl': {'deps': ['h3']}}});\n require([\"h3\"], function(h3) {\n window.h3 = h3\n on_load()\n })\n require([\"deck-gl\"], function(deck) {\n window.deck = deck\n on_load()\n })\n require([\"deck-json\"], function() {\n on_load()\n })\n require([\"loader-csv\"], function() {\n on_load()\n })\n require([\"loader-json\"], function() {\n on_load()\n })\n require([\"loader-tiles\"], function() {\n on_load()\n })\n require([\"mapbox-gl\"], function(mapboxgl) {\n window.mapboxgl = mapboxgl\n on_load()\n })\n require([\"carto\"], function() {\n on_load()\n })\n root._bokeh_is_loading = css_urls.length + 8;\n } else {\n root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n }\n\n const existing_stylesheets = []\n const links = document.getElementsByTagName('link')\n for (let i = 0; i < links.length; i++) {\n const link = links[i]\n if (link.href != null) {\n existing_stylesheets.push(link.href)\n }\n }\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const escaped = encodeURI(url)\n if (existing_stylesheets.indexOf(escaped) !== -1) {\n on_load()\n continue;\n }\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n } if (((window.deck !== undefined) && (!(window.deck instanceof HTMLElement))) || window.requirejs) {\n var urls = ['https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/h3-js@4.1.0/dist/h3-js.umd.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/deck.gl@9.0.20/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/json@9.0.20/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/csv@4.2.2/dist/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/json@4.2.2/dist/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/3d-tiles@4.2.2/dist/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/mapbox-gl-js/v3.0.1/mapbox-gl.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/maplibre-gl/dist/maplibre-gl.js'];\n for (var i = 0; i < urls.length; i++) {\n skip.push(encodeURI(urls[i]))\n }\n } if (((window.mapboxgl !== undefined) && (!(window.mapboxgl instanceof HTMLElement))) || window.requirejs) {\n var urls = ['https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/carto@^9.0.20/dist.min.js'];\n for (var i = 0; i < urls.length; i++) {\n skip.push(encodeURI(urls[i]))\n }\n } var existing_scripts = []\n const scripts = document.getElementsByTagName('script')\n for (let i = 0; i < scripts.length; i++) {\n var script = scripts[i]\n if (script.src != null) {\n existing_scripts.push(script.src)\n }\n }\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (let i = 0; i < js_modules.length; i++) {\n const url = js_modules[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (const name in js_exports) {\n const url = js_exports[name];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onerror = on_error;\n element.async = false;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n element.textContent = `\n import ${name} from \"${url}\"\n window.${name} = ${name}\n window._bokeh_on_load()\n `\n document.head.appendChild(element);\n }\n if (!js_urls.length && !js_modules.length) {\n on_load()\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n const js_urls = [\"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/h3-js@4.1.0/dist/h3-js.umd.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/deck.gl@9.0.20/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/json@9.0.20/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/csv@4.2.2/dist/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/json@4.2.2/dist/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/3d-tiles@4.2.2/dist/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/mapbox-gl-js/v3.0.1/mapbox-gl.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/maplibre-gl/dist/maplibre-gl.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/carto@^9.0.20/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-3.5.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.5.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.5.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.5.2.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/panel.min.js\"];\n const js_modules = [];\n const js_exports = {};\n const css_urls = [\"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/mapbox-gl-js/v3.0.1/mapbox-gl.css?v=1.5.2\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/maplibre-gl@4.4.1/dist/maplibre-gl.css?v=1.5.2\"];\n const inline_js = [ function(Bokeh) {\n inject_raw_css(\"\\n.dataframe table{\\n border: none;\\n}\\n\\n.panel-df table{\\n width: 100%;\\n border-collapse: collapse;\\n border: none;\\n}\\n.panel-df td{\\n white-space: nowrap;\\n overflow: auto;\\n text-overflow: ellipsis;\\n}\\n\");\n }, function(Bokeh) {\n inject_raw_css(\"\\n.multi-select{\\n color: white;\\n z-index: 100;\\n background: rgba(44,43,43,0.5);\\n border-radius: 1px;\\n width: 120px !important;\\n height: 30px !important;\\n}\\n.multi-select > .bk {\\n padding: 5px;\\n width: 120px !important;\\n height: 30px !important;\\n}\\n\\n.deck-chart {\\n z-index: 10;\\n position: initial !important;\\n}\\n\");\n }, function(Bokeh) {\n inject_raw_css(\"\\n.center-header {\\n text-align: center\\n}\\n.bk-input-group {\\n padding: 10px;\\n}\\n#sidebar {\\n padding-top: 10px;\\n}\\n.custom-widget-box {\\n margin-top: 20px;\\n padding: 5px;\\n border: None !important;\\n}\\n.custom-widget-box > p {\\n margin: 0px;\\n}\\n.bk-input-group {\\n color: None !important;\\n}\\n.indicator {\\n text-align: center;\\n}\\n.widget-card {\\n margin: 5px 10px;\\n}\\n.number-card {\\n margin: 5px 10px;\\n text-align: center;\\n}\\n.number-card-value {\\n width: 100%;\\n margin: 0px;\\n}\\n\");\n }, function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\n function(Bokeh) {\n (function(root, factory) {\n factory(root[\"Bokeh\"]);\n })(this, function(Bokeh) {\n let define;\n return (function outer(modules, entry) {\n if (Bokeh != null) {\n return Bokeh.register_plugin(modules, entry);\n } else {\n throw new Error(\"Cannot find Bokeh. You have to load it prior to loading plugins.\");\n }\n })\n ({\n \"custom/main\": function(require, module, exports) {\n const models = {\n \"CustomInspectTool\": require(\"custom/cuxfilter.charts.datashader.custom_extensions.graph_inspect_widget.custom_inspect_tool\").CustomInspectTool\n };\n require(\"base\").register_models(models);\n module.exports = models;\n },\n \"custom/cuxfilter.charts.datashader.custom_extensions.graph_inspect_widget.custom_inspect_tool\": function(require, module, exports) {\n \"use strict\";\n var _a;\n Object.defineProperty(exports, \"__esModule\", { value: true });\n exports.CustomInspectTool = exports.CustomInspectToolView = void 0;\n const inspect_tool_1 = require(\"models/tools/inspectors/inspect_tool\");\n class CustomInspectToolView extends inspect_tool_1.InspectToolView {\n connect_signals() {\n super.connect_signals();\n this.on_change([this.model.properties.active], () => {\n this.model._active = this.model.active;\n });\n }\n }\n exports.CustomInspectToolView = CustomInspectToolView;\n CustomInspectToolView.__name__ = \"CustomInspectToolView\";\n class CustomInspectTool extends inspect_tool_1.InspectTool {\n constructor(attrs) {\n super(attrs);\n }\n }\n exports.CustomInspectTool = CustomInspectTool;\n _a = CustomInspectTool;\n CustomInspectTool.__name__ = \"CustomInspectTool\";\n (() => {\n _a.prototype.default_view = CustomInspectToolView;\n _a.define(({ Boolean }) => ({\n _active: [Boolean, true]\n }));\n _a.register_alias(\"customInspect\", () => new _a());\n })();\n //# sourceMappingURL=graph_inspect_widget.py:CustomInspectTool.js.map\n }\n }, \"custom/main\");\n ;\n });\n\n },\nfunction(Bokeh) {} // ensure no trailing comma for IE\n ];\n\n function run_inline_js() {\n if ((root.Bokeh !== undefined) || (force === true)) {\n for (let i = 0; i < inline_js.length; i++) {\n try {\n inline_js[i].call(root, root.Bokeh);\n } catch(e) {\n if (!reloading) {\n throw e;\n }\n }\n }\n // Cache old bokeh versions\n if (Bokeh != undefined && !reloading) {\n var NewBokeh = root.Bokeh;\n if (Bokeh.versions === undefined) {\n Bokeh.versions = new Map();\n }\n if (NewBokeh.version !== Bokeh.version) {\n Bokeh.versions.set(NewBokeh.version, NewBokeh)\n }\n root.Bokeh = Bokeh;\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n }\n root._bokeh_is_initializing = false\n }\n\n function load_or_wait() {\n // Implement a backoff loop that tries to ensure we do not load multiple\n // versions of Bokeh and its dependencies at the same time.\n // In recent versions we use the root._bokeh_is_initializing flag\n // to determine whether there is an ongoing attempt to initialize\n // bokeh, however for backward compatibility we also try to ensure\n // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n // before older versions are fully initialized.\n if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n // If the timeout and bokeh was not successfully loaded we reset\n // everything and try loading again\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_is_initializing = false;\n root._bokeh_onload_callbacks = undefined;\n root._bokeh_is_loading = 0\n console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n load_or_wait();\n } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n setTimeout(load_or_wait, 100);\n } else {\n root._bokeh_is_initializing = true\n root._bokeh_onload_callbacks = []\n const bokeh_loaded = root.Bokeh != null && (root.Bokeh.version === py_version || (root.Bokeh.versions !== undefined && root.Bokeh.versions.has(py_version)));\n if (!reloading && !bokeh_loaded) {\n if (root.Bokeh) {\n root.Bokeh = undefined;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n }\n load_libs(css_urls, js_urls, js_modules, js_exports, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n }\n // Give older versions of the autoload script a head-start to ensure\n // they initialize before we start loading newer version.\n setTimeout(load_or_wait, 100)\n}(window));" - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/javascript": [ - "\n", - "if ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n", - " window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n", - "}\n", - "\n", - "\n", - " function JupyterCommManager() {\n", - " }\n", - "\n", - " JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n", - " if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n", - " var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n", - " comm_manager.register_target(comm_id, function(comm) {\n", - " comm.on_msg(msg_handler);\n", - " });\n", - " } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n", - " window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n", - " comm.onMsg = msg_handler;\n", - " });\n", - " } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n", - " google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n", - " var messages = comm.messages[Symbol.asyncIterator]();\n", - " function processIteratorResult(result) {\n", - " var message = result.value;\n", - " console.log(message)\n", - " var content = {data: message.data, comm_id};\n", - " var buffers = []\n", - " for (var buffer of message.buffers || []) {\n", - " buffers.push(new DataView(buffer))\n", - " }\n", - " var metadata = message.metadata || {};\n", - " var msg = {content, buffers, metadata}\n", - " msg_handler(msg);\n", - " return messages.next().then(processIteratorResult);\n", - " }\n", - " return messages.next().then(processIteratorResult);\n", - " })\n", - " }\n", - " }\n", - "\n", - " JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n", - " if (comm_id in window.PyViz.comms) {\n", - " return window.PyViz.comms[comm_id];\n", - " } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n", - " var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n", - " var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n", - " if (msg_handler) {\n", - " comm.on_msg(msg_handler);\n", - " }\n", - " } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n", - " var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n", - " comm.open();\n", - " if (msg_handler) {\n", - " comm.onMsg = msg_handler;\n", - " }\n", - " } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n", - " var comm_promise = google.colab.kernel.comms.open(comm_id)\n", - " comm_promise.then((comm) => {\n", - " window.PyViz.comms[comm_id] = comm;\n", - " if (msg_handler) {\n", - " var messages = comm.messages[Symbol.asyncIterator]();\n", - " function processIteratorResult(result) {\n", - " var message = result.value;\n", - " var content = {data: message.data};\n", - " var metadata = message.metadata || {comm_id};\n", - " var msg = {content, metadata}\n", - " msg_handler(msg);\n", - " return messages.next().then(processIteratorResult);\n", - " }\n", - " return messages.next().then(processIteratorResult);\n", - " }\n", - " }) \n", - " var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n", - " return comm_promise.then((comm) => {\n", - " comm.send(data, metadata, buffers, disposeOnDone);\n", - " });\n", - " };\n", - " var comm = {\n", - " send: sendClosure\n", - " };\n", - " }\n", - " window.PyViz.comms[comm_id] = comm;\n", - " return comm;\n", - " }\n", - " window.PyViz.comm_manager = new JupyterCommManager();\n", - " \n", - "\n", - "\n", - "var JS_MIME_TYPE = 'application/javascript';\n", - "var HTML_MIME_TYPE = 'text/html';\n", - "var EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\n", - "var CLASS_NAME = 'output';\n", - "\n", - "/**\n", - " * Render data to the DOM node\n", - " */\n", - "function render(props, node) {\n", - " var div = document.createElement(\"div\");\n", - " var script = document.createElement(\"script\");\n", - " node.appendChild(div);\n", - " node.appendChild(script);\n", - "}\n", - "\n", - "/**\n", - " * Handle when a new output is added\n", - " */\n", - "function handle_add_output(event, handle) {\n", - " var output_area = handle.output_area;\n", - " var output = handle.output;\n", - " if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n", - " return\n", - " }\n", - " var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n", - " var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n", - " if (id !== undefined) {\n", - " var nchildren = toinsert.length;\n", - " var html_node = toinsert[nchildren-1].children[0];\n", - " html_node.innerHTML = output.data[HTML_MIME_TYPE];\n", - " var scripts = [];\n", - " var nodelist = html_node.querySelectorAll(\"script\");\n", - " for (var i in nodelist) {\n", - " if (nodelist.hasOwnProperty(i)) {\n", - " scripts.push(nodelist[i])\n", - " }\n", - " }\n", - "\n", - " scripts.forEach( function (oldScript) {\n", - " var newScript = document.createElement(\"script\");\n", - " var attrs = [];\n", - " var nodemap = oldScript.attributes;\n", - " for (var j in nodemap) {\n", - " if (nodemap.hasOwnProperty(j)) {\n", - " attrs.push(nodemap[j])\n", - " }\n", - " }\n", - " attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n", - " newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n", - " oldScript.parentNode.replaceChild(newScript, oldScript);\n", - " });\n", - " if (JS_MIME_TYPE in output.data) {\n", - " toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n", - " }\n", - " output_area._hv_plot_id = id;\n", - " if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n", - " window.PyViz.plot_index[id] = Bokeh.index[id];\n", - " } else {\n", - " window.PyViz.plot_index[id] = null;\n", - " }\n", - " } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n", - " var bk_div = document.createElement(\"div\");\n", - " bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n", - " var script_attrs = bk_div.children[0].attributes;\n", - " for (var i = 0; i < script_attrs.length; i++) {\n", - " toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\n", - " }\n", - " // store reference to server id on output_area\n", - " output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n", - " }\n", - "}\n", - "\n", - "/**\n", - " * Handle when an output is cleared or removed\n", - " */\n", - "function handle_clear_output(event, handle) {\n", - " var id = handle.cell.output_area._hv_plot_id;\n", - " var server_id = handle.cell.output_area._bokeh_server_id;\n", - " if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n", - " var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n", - " if (server_id !== null) {\n", - " comm.send({event_type: 'server_delete', 'id': server_id});\n", - " return;\n", - " } else if (comm !== null) {\n", - " comm.send({event_type: 'delete', 'id': id});\n", - " }\n", - " delete PyViz.plot_index[id];\n", - " if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n", - " var doc = window.Bokeh.index[id].model.document\n", - " doc.clear();\n", - " const i = window.Bokeh.documents.indexOf(doc);\n", - " if (i > -1) {\n", - " window.Bokeh.documents.splice(i, 1);\n", - " }\n", - " }\n", - "}\n", - "\n", - "/**\n", - " * Handle kernel restart event\n", - " */\n", - "function handle_kernel_cleanup(event, handle) {\n", - " delete PyViz.comms[\"hv-extension-comm\"];\n", - " window.PyViz.plot_index = {}\n", - "}\n", - "\n", - "/**\n", - " * Handle update_display_data messages\n", - " */\n", - "function handle_update_output(event, handle) {\n", - " handle_clear_output(event, {cell: {output_area: handle.output_area}})\n", - " handle_add_output(event, handle)\n", - "}\n", - "\n", - "function register_renderer(events, OutputArea) {\n", - " function append_mime(data, metadata, element) {\n", - " // create a DOM node to render to\n", - " var toinsert = this.create_output_subarea(\n", - " metadata,\n", - " CLASS_NAME,\n", - " EXEC_MIME_TYPE\n", - " );\n", - " this.keyboard_manager.register_events(toinsert);\n", - " // Render to node\n", - " var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n", - " render(props, toinsert[0]);\n", - " element.append(toinsert);\n", - " return toinsert\n", - " }\n", - "\n", - " events.on('output_added.OutputArea', handle_add_output);\n", - " events.on('output_updated.OutputArea', handle_update_output);\n", - " events.on('clear_output.CodeCell', handle_clear_output);\n", - " events.on('delete.Cell', handle_clear_output);\n", - " events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n", - "\n", - " OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n", - " safe: true,\n", - " index: 0\n", - " });\n", - "}\n", - "\n", - "if (window.Jupyter !== undefined) {\n", - " try {\n", - " var events = require('base/js/events');\n", - " var OutputArea = require('notebook/js/outputarea').OutputArea;\n", - " if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n", - " register_renderer(events, OutputArea);\n", - " }\n", - " } catch(err) {\n", - " }\n", - "}\n" - ], - "application/vnd.holoviews_load.v0+json": "\nif ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n}\n\n\n function JupyterCommManager() {\n }\n\n JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n comm_manager.register_target(comm_id, function(comm) {\n comm.on_msg(msg_handler);\n });\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n comm.onMsg = msg_handler;\n });\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n console.log(message)\n var content = {data: message.data, comm_id};\n var buffers = []\n for (var buffer of message.buffers || []) {\n buffers.push(new DataView(buffer))\n }\n var metadata = message.metadata || {};\n var msg = {content, buffers, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n })\n }\n }\n\n JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n if (comm_id in window.PyViz.comms) {\n return window.PyViz.comms[comm_id];\n } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n if (msg_handler) {\n comm.on_msg(msg_handler);\n }\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n comm.open();\n if (msg_handler) {\n comm.onMsg = msg_handler;\n }\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n var comm_promise = google.colab.kernel.comms.open(comm_id)\n comm_promise.then((comm) => {\n window.PyViz.comms[comm_id] = comm;\n if (msg_handler) {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data};\n var metadata = message.metadata || {comm_id};\n var msg = {content, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n }\n }) \n var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n return comm_promise.then((comm) => {\n comm.send(data, metadata, buffers, disposeOnDone);\n });\n };\n var comm = {\n send: sendClosure\n };\n }\n window.PyViz.comms[comm_id] = comm;\n return comm;\n }\n window.PyViz.comm_manager = new JupyterCommManager();\n \n\n\nvar JS_MIME_TYPE = 'application/javascript';\nvar HTML_MIME_TYPE = 'text/html';\nvar EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\nvar CLASS_NAME = 'output';\n\n/**\n * Render data to the DOM node\n */\nfunction render(props, node) {\n var div = document.createElement(\"div\");\n var script = document.createElement(\"script\");\n node.appendChild(div);\n node.appendChild(script);\n}\n\n/**\n * Handle when a new output is added\n */\nfunction handle_add_output(event, handle) {\n var output_area = handle.output_area;\n var output = handle.output;\n if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n return\n }\n var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n if (id !== undefined) {\n var nchildren = toinsert.length;\n var html_node = toinsert[nchildren-1].children[0];\n html_node.innerHTML = output.data[HTML_MIME_TYPE];\n var scripts = [];\n var nodelist = html_node.querySelectorAll(\"script\");\n for (var i in nodelist) {\n if (nodelist.hasOwnProperty(i)) {\n scripts.push(nodelist[i])\n }\n }\n\n scripts.forEach( function (oldScript) {\n var newScript = document.createElement(\"script\");\n var attrs = [];\n var nodemap = oldScript.attributes;\n for (var j in nodemap) {\n if (nodemap.hasOwnProperty(j)) {\n attrs.push(nodemap[j])\n }\n }\n attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n oldScript.parentNode.replaceChild(newScript, oldScript);\n });\n if (JS_MIME_TYPE in output.data) {\n toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n }\n output_area._hv_plot_id = id;\n if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n window.PyViz.plot_index[id] = Bokeh.index[id];\n } else {\n window.PyViz.plot_index[id] = null;\n }\n } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n var bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n var script_attrs = bk_div.children[0].attributes;\n for (var i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\n }\n // store reference to server id on output_area\n output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n }\n}\n\n/**\n * Handle when an output is cleared or removed\n */\nfunction handle_clear_output(event, handle) {\n var id = handle.cell.output_area._hv_plot_id;\n var server_id = handle.cell.output_area._bokeh_server_id;\n if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n if (server_id !== null) {\n comm.send({event_type: 'server_delete', 'id': server_id});\n return;\n } else if (comm !== null) {\n comm.send({event_type: 'delete', 'id': id});\n }\n delete PyViz.plot_index[id];\n if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n var doc = window.Bokeh.index[id].model.document\n doc.clear();\n const i = window.Bokeh.documents.indexOf(doc);\n if (i > -1) {\n window.Bokeh.documents.splice(i, 1);\n }\n }\n}\n\n/**\n * Handle kernel restart event\n */\nfunction handle_kernel_cleanup(event, handle) {\n delete PyViz.comms[\"hv-extension-comm\"];\n window.PyViz.plot_index = {}\n}\n\n/**\n * Handle update_display_data messages\n */\nfunction handle_update_output(event, handle) {\n handle_clear_output(event, {cell: {output_area: handle.output_area}})\n handle_add_output(event, handle)\n}\n\nfunction register_renderer(events, OutputArea) {\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n var toinsert = this.create_output_subarea(\n metadata,\n CLASS_NAME,\n EXEC_MIME_TYPE\n );\n this.keyboard_manager.register_events(toinsert);\n // Render to node\n var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[0]);\n element.append(toinsert);\n return toinsert\n }\n\n events.on('output_added.OutputArea', handle_add_output);\n events.on('output_updated.OutputArea', handle_update_output);\n events.on('clear_output.CodeCell', handle_clear_output);\n events.on('delete.Cell', handle_clear_output);\n events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n safe: true,\n index: 0\n });\n}\n\nif (window.Jupyter !== undefined) {\n try {\n var events = require('base/js/events');\n var OutputArea = require('notebook/js/outputarea').OutputArea;\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n } catch(err) {\n }\n}\n" - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/javascript": [ - "(function(root) {\n", - " function now() {\n", - " return new Date();\n", - " }\n", - "\n", - " const force = false;\n", - " const py_version = '3.5.2'.replace('rc', '-rc.').replace('.dev', '-dev.');\n", - " const reloading = true;\n", - " const Bokeh = root.Bokeh;\n", - "\n", - " // Set a timeout for this load but only if we are not already initializing\n", - " if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n", - " root._bokeh_timeout = Date.now() + 5000;\n", - " root._bokeh_failed_load = false;\n", - " }\n", - "\n", - " function run_callbacks() {\n", - " try {\n", - " root._bokeh_onload_callbacks.forEach(function(callback) {\n", - " if (callback != null)\n", - " callback();\n", - " });\n", - " } finally {\n", - " delete root._bokeh_onload_callbacks;\n", - " }\n", - " console.debug(\"Bokeh: all callbacks have finished\");\n", - " }\n", - "\n", - " function load_libs(css_urls, js_urls, js_modules, js_exports, callback) {\n", - " if (css_urls == null) css_urls = [];\n", - " if (js_urls == null) js_urls = [];\n", - " if (js_modules == null) js_modules = [];\n", - " if (js_exports == null) js_exports = {};\n", - "\n", - " root._bokeh_onload_callbacks.push(callback);\n", - "\n", - " if (root._bokeh_is_loading > 0) {\n", - " // Don't load bokeh if it is still initializing\n", - " console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", - " return null;\n", - " } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n", - " // There is nothing to load\n", - " run_callbacks();\n", - " return null;\n", - " }\n", - "\n", - " function on_load() {\n", - " root._bokeh_is_loading--;\n", - " if (root._bokeh_is_loading === 0) {\n", - " console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n", - " run_callbacks()\n", - " }\n", - " }\n", - " window._bokeh_on_load = on_load\n", - "\n", - " function on_error(e) {\n", - " const src_el = e.srcElement\n", - " console.error(\"failed to load \" + (src_el.href || src_el.src));\n", - " }\n", - "\n", - " const skip = [];\n", - " if (window.requirejs) {\n", - " window.requirejs.config({'packages': {}, 'paths': {'h3': 'https://cdn.jsdelivr.net/npm/h3-js@4.1.0/dist/h3-js.umd', 'deck-gl': 'https://cdn.jsdelivr.net/npm/deck.gl@9.0.20/dist.min', 'deck-json': 'https://cdn.jsdelivr.net/npm/@deck.gl/json@9.0.20/dist.min', 'loader-csv': 'https://cdn.jsdelivr.net/npm/@loaders.gl/csv@4.2.2/dist/dist.min', 'loader-json': 'https://cdn.jsdelivr.net/npm/@loaders.gl/json@4.2.2/dist/dist.min', 'loader-tiles': 'https://cdn.jsdelivr.net/npm/@loaders.gl/3d-tiles@4.2.2/dist/dist.min', 'mapbox-gl': 'https://api.mapbox.com/mapbox-gl-js/v3.0.1/mapbox-gl', 'carto': 'https://cdn.jsdelivr.net/npm/@deck.gl/carto@^9.0.20/dist.min'}, 'shim': {'deck-json': {'deps': ['deck-gl']}, 'deck-gl': {'deps': ['h3']}}});\n", - " require([\"h3\"], function(h3) {\n", - " window.h3 = h3\n", - " on_load()\n", - " })\n", - " require([\"deck-gl\"], function(deck) {\n", - " window.deck = deck\n", - " on_load()\n", - " })\n", - " require([\"deck-json\"], function() {\n", - " on_load()\n", - " })\n", - " require([\"loader-csv\"], function() {\n", - " on_load()\n", - " })\n", - " require([\"loader-json\"], function() {\n", - " on_load()\n", - " })\n", - " require([\"loader-tiles\"], function() {\n", - " on_load()\n", - " })\n", - " require([\"mapbox-gl\"], function(mapboxgl) {\n", - " window.mapboxgl = mapboxgl\n", - " on_load()\n", - " })\n", - " require([\"carto\"], function() {\n", - " on_load()\n", - " })\n", - " root._bokeh_is_loading = css_urls.length + 8;\n", - " } else {\n", - " root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n", - " }\n", - "\n", - " const existing_stylesheets = []\n", - " const links = document.getElementsByTagName('link')\n", - " for (let i = 0; i < links.length; i++) {\n", - " const link = links[i]\n", - " if (link.href != null) {\n", - " existing_stylesheets.push(link.href)\n", - " }\n", - " }\n", - " for (let i = 0; i < css_urls.length; i++) {\n", - " const url = css_urls[i];\n", - " const escaped = encodeURI(url)\n", - " if (existing_stylesheets.indexOf(escaped) !== -1) {\n", - " on_load()\n", - " continue;\n", - " }\n", - " const element = document.createElement(\"link\");\n", - " element.onload = on_load;\n", - " element.onerror = on_error;\n", - " element.rel = \"stylesheet\";\n", - " element.type = \"text/css\";\n", - " element.href = url;\n", - " console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n", - " document.body.appendChild(element);\n", - " } if (((window.deck !== undefined) && (!(window.deck instanceof HTMLElement))) || window.requirejs) {\n", - " var urls = ['https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/h3-js@4.1.0/dist/h3-js.umd.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/deck.gl@9.0.20/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/json@9.0.20/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/csv@4.2.2/dist/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/json@4.2.2/dist/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/3d-tiles@4.2.2/dist/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/mapbox-gl-js/v3.0.1/mapbox-gl.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/maplibre-gl/dist/maplibre-gl.js'];\n", - " for (var i = 0; i < urls.length; i++) {\n", - " skip.push(encodeURI(urls[i]))\n", - " }\n", - " } if (((window.mapboxgl !== undefined) && (!(window.mapboxgl instanceof HTMLElement))) || window.requirejs) {\n", - " var urls = ['https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/carto@^9.0.20/dist.min.js'];\n", - " for (var i = 0; i < urls.length; i++) {\n", - " skip.push(encodeURI(urls[i]))\n", - " }\n", - " } var existing_scripts = []\n", - " const scripts = document.getElementsByTagName('script')\n", - " for (let i = 0; i < scripts.length; i++) {\n", - " var script = scripts[i]\n", - " if (script.src != null) {\n", - " existing_scripts.push(script.src)\n", - " }\n", - " }\n", - " for (let i = 0; i < js_urls.length; i++) {\n", - " const url = js_urls[i];\n", - " const escaped = encodeURI(url)\n", - " if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n", - " if (!window.requirejs) {\n", - " on_load();\n", - " }\n", - " continue;\n", - " }\n", - " const element = document.createElement('script');\n", - " element.onload = on_load;\n", - " element.onerror = on_error;\n", - " element.async = false;\n", - " element.src = url;\n", - " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", - " document.head.appendChild(element);\n", - " }\n", - " for (let i = 0; i < js_modules.length; i++) {\n", - " const url = js_modules[i];\n", - " const escaped = encodeURI(url)\n", - " if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n", - " if (!window.requirejs) {\n", - " on_load();\n", - " }\n", - " continue;\n", - " }\n", - " var element = document.createElement('script');\n", - " element.onload = on_load;\n", - " element.onerror = on_error;\n", - " element.async = false;\n", - " element.src = url;\n", - " element.type = \"module\";\n", - " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", - " document.head.appendChild(element);\n", - " }\n", - " for (const name in js_exports) {\n", - " const url = js_exports[name];\n", - " const escaped = encodeURI(url)\n", - " if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n", - " if (!window.requirejs) {\n", - " on_load();\n", - " }\n", - " continue;\n", - " }\n", - " var element = document.createElement('script');\n", - " element.onerror = on_error;\n", - " element.async = false;\n", - " element.type = \"module\";\n", - " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", - " element.textContent = `\n", - " import ${name} from \"${url}\"\n", - " window.${name} = ${name}\n", - " window._bokeh_on_load()\n", - " `\n", - " document.head.appendChild(element);\n", - " }\n", - " if (!js_urls.length && !js_modules.length) {\n", - " on_load()\n", - " }\n", - " };\n", - "\n", - " function inject_raw_css(css) {\n", - " const element = document.createElement(\"style\");\n", - " element.appendChild(document.createTextNode(css));\n", - " document.body.appendChild(element);\n", - " }\n", - "\n", - " const js_urls = [\"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/h3-js@4.1.0/dist/h3-js.umd.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/deck.gl@9.0.20/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/json@9.0.20/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/csv@4.2.2/dist/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/json@4.2.2/dist/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/3d-tiles@4.2.2/dist/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/mapbox-gl-js/v3.0.1/mapbox-gl.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/maplibre-gl/dist/maplibre-gl.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/carto@^9.0.20/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\"];\n", - " const js_modules = [];\n", - " const js_exports = {};\n", - " const css_urls = [\"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/mapbox-gl-js/v3.0.1/mapbox-gl.css?v=1.5.2\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/maplibre-gl@4.4.1/dist/maplibre-gl.css?v=1.5.2\"];\n", - " const inline_js = [ function(Bokeh) {\n", - " inject_raw_css(\"\\n.dataframe table{\\n border: none;\\n}\\n\\n.panel-df table{\\n width: 100%;\\n border-collapse: collapse;\\n border: none;\\n}\\n.panel-df td{\\n white-space: nowrap;\\n overflow: auto;\\n text-overflow: ellipsis;\\n}\\n\");\n", - " }, function(Bokeh) {\n", - " inject_raw_css(\"\\n.multi-select{\\n color: white;\\n z-index: 100;\\n background: rgba(44,43,43,0.5);\\n border-radius: 1px;\\n width: 120px !important;\\n height: 30px !important;\\n}\\n.multi-select > .bk {\\n padding: 5px;\\n width: 120px !important;\\n height: 30px !important;\\n}\\n\\n.deck-chart {\\n z-index: 10;\\n position: initial !important;\\n}\\n\");\n", - " }, function(Bokeh) {\n", - " inject_raw_css(\"\\n.center-header {\\n text-align: center\\n}\\n.bk-input-group {\\n padding: 10px;\\n}\\n#sidebar {\\n padding-top: 10px;\\n}\\n.custom-widget-box {\\n margin-top: 20px;\\n padding: 5px;\\n border: None !important;\\n}\\n.custom-widget-box > p {\\n margin: 0px;\\n}\\n.bk-input-group {\\n color: None !important;\\n}\\n.indicator {\\n text-align: center;\\n}\\n.widget-card {\\n margin: 5px 10px;\\n}\\n.number-card {\\n margin: 5px 10px;\\n text-align: center;\\n}\\n.number-card-value {\\n width: 100%;\\n margin: 0px;\\n}\\n\");\n", - " }, function(Bokeh) {\n", - " Bokeh.set_log_level(\"info\");\n", - " },\n", - " function(Bokeh) {\n", - " (function(root, factory) {\n", - " factory(root[\"Bokeh\"]);\n", - " })(this, function(Bokeh) {\n", - " let define;\n", - " return (function outer(modules, entry) {\n", - " if (Bokeh != null) {\n", - " return Bokeh.register_plugin(modules, entry);\n", - " } else {\n", - " throw new Error(\"Cannot find Bokeh. You have to load it prior to loading plugins.\");\n", - " }\n", - " })\n", - " ({\n", - " \"custom/main\": function(require, module, exports) {\n", - " const models = {\n", - " \"CustomInspectTool\": require(\"custom/cuxfilter.charts.datashader.custom_extensions.graph_inspect_widget.custom_inspect_tool\").CustomInspectTool\n", - " };\n", - " require(\"base\").register_models(models);\n", - " module.exports = models;\n", - " },\n", - " \"custom/cuxfilter.charts.datashader.custom_extensions.graph_inspect_widget.custom_inspect_tool\": function(require, module, exports) {\n", - " \"use strict\";\n", - " var _a;\n", - " Object.defineProperty(exports, \"__esModule\", { value: true });\n", - " exports.CustomInspectTool = exports.CustomInspectToolView = void 0;\n", - " const inspect_tool_1 = require(\"models/tools/inspectors/inspect_tool\");\n", - " class CustomInspectToolView extends inspect_tool_1.InspectToolView {\n", - " connect_signals() {\n", - " super.connect_signals();\n", - " this.on_change([this.model.properties.active], () => {\n", - " this.model._active = this.model.active;\n", - " });\n", - " }\n", - " }\n", - " exports.CustomInspectToolView = CustomInspectToolView;\n", - " CustomInspectToolView.__name__ = \"CustomInspectToolView\";\n", - " class CustomInspectTool extends inspect_tool_1.InspectTool {\n", - " constructor(attrs) {\n", - " super(attrs);\n", - " }\n", - " }\n", - " exports.CustomInspectTool = CustomInspectTool;\n", - " _a = CustomInspectTool;\n", - " CustomInspectTool.__name__ = \"CustomInspectTool\";\n", - " (() => {\n", - " _a.prototype.default_view = CustomInspectToolView;\n", - " _a.define(({ Boolean }) => ({\n", - " _active: [Boolean, true]\n", - " }));\n", - " _a.register_alias(\"customInspect\", () => new _a());\n", - " })();\n", - " //# sourceMappingURL=graph_inspect_widget.py:CustomInspectTool.js.map\n", - " }\n", - " }, \"custom/main\");\n", - " ;\n", - " });\n", - "\n", - " },\n", - "function(Bokeh) {} // ensure no trailing comma for IE\n", - " ];\n", - "\n", - " function run_inline_js() {\n", - " if ((root.Bokeh !== undefined) || (force === true)) {\n", - " for (let i = 0; i < inline_js.length; i++) {\n", - " try {\n", - " inline_js[i].call(root, root.Bokeh);\n", - " } catch(e) {\n", - " if (!reloading) {\n", - " throw e;\n", - " }\n", - " }\n", - " }\n", - " // Cache old bokeh versions\n", - " if (Bokeh != undefined && !reloading) {\n", - " var NewBokeh = root.Bokeh;\n", - " if (Bokeh.versions === undefined) {\n", - " Bokeh.versions = new Map();\n", - " }\n", - " if (NewBokeh.version !== Bokeh.version) {\n", - " Bokeh.versions.set(NewBokeh.version, NewBokeh)\n", - " }\n", - " root.Bokeh = Bokeh;\n", - " }\n", - " } else if (Date.now() < root._bokeh_timeout) {\n", - " setTimeout(run_inline_js, 100);\n", - " } else if (!root._bokeh_failed_load) {\n", - " console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n", - " root._bokeh_failed_load = true;\n", - " }\n", - " root._bokeh_is_initializing = false\n", - " }\n", - "\n", - " function load_or_wait() {\n", - " // Implement a backoff loop that tries to ensure we do not load multiple\n", - " // versions of Bokeh and its dependencies at the same time.\n", - " // In recent versions we use the root._bokeh_is_initializing flag\n", - " // to determine whether there is an ongoing attempt to initialize\n", - " // bokeh, however for backward compatibility we also try to ensure\n", - " // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n", - " // before older versions are fully initialized.\n", - " if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n", - " // If the timeout and bokeh was not successfully loaded we reset\n", - " // everything and try loading again\n", - " root._bokeh_timeout = Date.now() + 5000;\n", - " root._bokeh_is_initializing = false;\n", - " root._bokeh_onload_callbacks = undefined;\n", - " root._bokeh_is_loading = 0\n", - " console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n", - " load_or_wait();\n", - " } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n", - " setTimeout(load_or_wait, 100);\n", - " } else {\n", - " root._bokeh_is_initializing = true\n", - " root._bokeh_onload_callbacks = []\n", - " const bokeh_loaded = root.Bokeh != null && (root.Bokeh.version === py_version || (root.Bokeh.versions !== undefined && root.Bokeh.versions.has(py_version)));\n", - " if (!reloading && !bokeh_loaded) {\n", - " if (root.Bokeh) {\n", - " root.Bokeh = undefined;\n", - " }\n", - " console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", - " }\n", - " load_libs(css_urls, js_urls, js_modules, js_exports, function() {\n", - " console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n", - " run_inline_js();\n", - " });\n", - " }\n", - " }\n", - " // Give older versions of the autoload script a head-start to ensure\n", - " // they initialize before we start loading newer version.\n", - " setTimeout(load_or_wait, 100)\n", - "}(window));" - ], - "application/vnd.holoviews_load.v0+json": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = false;\n const py_version = '3.5.2'.replace('rc', '-rc.').replace('.dev', '-dev.');\n const reloading = true;\n const Bokeh = root.Bokeh;\n\n // Set a timeout for this load but only if we are not already initializing\n if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks;\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, js_modules, js_exports, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n if (js_modules == null) js_modules = [];\n if (js_exports == null) js_exports = {};\n\n root._bokeh_onload_callbacks.push(callback);\n\n if (root._bokeh_is_loading > 0) {\n // Don't load bokeh if it is still initializing\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n // There is nothing to load\n run_callbacks();\n return null;\n }\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n window._bokeh_on_load = on_load\n\n function on_error(e) {\n const src_el = e.srcElement\n console.error(\"failed to load \" + (src_el.href || src_el.src));\n }\n\n const skip = [];\n if (window.requirejs) {\n window.requirejs.config({'packages': {}, 'paths': {'h3': 'https://cdn.jsdelivr.net/npm/h3-js@4.1.0/dist/h3-js.umd', 'deck-gl': 'https://cdn.jsdelivr.net/npm/deck.gl@9.0.20/dist.min', 'deck-json': 'https://cdn.jsdelivr.net/npm/@deck.gl/json@9.0.20/dist.min', 'loader-csv': 'https://cdn.jsdelivr.net/npm/@loaders.gl/csv@4.2.2/dist/dist.min', 'loader-json': 'https://cdn.jsdelivr.net/npm/@loaders.gl/json@4.2.2/dist/dist.min', 'loader-tiles': 'https://cdn.jsdelivr.net/npm/@loaders.gl/3d-tiles@4.2.2/dist/dist.min', 'mapbox-gl': 'https://api.mapbox.com/mapbox-gl-js/v3.0.1/mapbox-gl', 'carto': 'https://cdn.jsdelivr.net/npm/@deck.gl/carto@^9.0.20/dist.min'}, 'shim': {'deck-json': {'deps': ['deck-gl']}, 'deck-gl': {'deps': ['h3']}}});\n require([\"h3\"], function(h3) {\n window.h3 = h3\n on_load()\n })\n require([\"deck-gl\"], function(deck) {\n window.deck = deck\n on_load()\n })\n require([\"deck-json\"], function() {\n on_load()\n })\n require([\"loader-csv\"], function() {\n on_load()\n })\n require([\"loader-json\"], function() {\n on_load()\n })\n require([\"loader-tiles\"], function() {\n on_load()\n })\n require([\"mapbox-gl\"], function(mapboxgl) {\n window.mapboxgl = mapboxgl\n on_load()\n })\n require([\"carto\"], function() {\n on_load()\n })\n root._bokeh_is_loading = css_urls.length + 8;\n } else {\n root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n }\n\n const existing_stylesheets = []\n const links = document.getElementsByTagName('link')\n for (let i = 0; i < links.length; i++) {\n const link = links[i]\n if (link.href != null) {\n existing_stylesheets.push(link.href)\n }\n }\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const escaped = encodeURI(url)\n if (existing_stylesheets.indexOf(escaped) !== -1) {\n on_load()\n continue;\n }\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n } if (((window.deck !== undefined) && (!(window.deck instanceof HTMLElement))) || window.requirejs) {\n var urls = ['https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/h3-js@4.1.0/dist/h3-js.umd.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/deck.gl@9.0.20/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/json@9.0.20/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/csv@4.2.2/dist/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/json@4.2.2/dist/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/3d-tiles@4.2.2/dist/dist.min.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/mapbox-gl-js/v3.0.1/mapbox-gl.js', 'https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/maplibre-gl/dist/maplibre-gl.js'];\n for (var i = 0; i < urls.length; i++) {\n skip.push(encodeURI(urls[i]))\n }\n } if (((window.mapboxgl !== undefined) && (!(window.mapboxgl instanceof HTMLElement))) || window.requirejs) {\n var urls = ['https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/carto@^9.0.20/dist.min.js'];\n for (var i = 0; i < urls.length; i++) {\n skip.push(encodeURI(urls[i]))\n }\n } var existing_scripts = []\n const scripts = document.getElementsByTagName('script')\n for (let i = 0; i < scripts.length; i++) {\n var script = scripts[i]\n if (script.src != null) {\n existing_scripts.push(script.src)\n }\n }\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (let i = 0; i < js_modules.length; i++) {\n const url = js_modules[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (const name in js_exports) {\n const url = js_exports[name];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onerror = on_error;\n element.async = false;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n element.textContent = `\n import ${name} from \"${url}\"\n window.${name} = ${name}\n window._bokeh_on_load()\n `\n document.head.appendChild(element);\n }\n if (!js_urls.length && !js_modules.length) {\n on_load()\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n const js_urls = [\"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/h3-js@4.1.0/dist/h3-js.umd.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/deck.gl@9.0.20/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/json@9.0.20/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/csv@4.2.2/dist/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/json@4.2.2/dist/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@loaders.gl/3d-tiles@4.2.2/dist/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/mapbox-gl-js/v3.0.1/mapbox-gl.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/maplibre-gl/dist/maplibre-gl.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/@deck.gl/carto@^9.0.20/dist.min.js\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\"];\n const js_modules = [];\n const js_exports = {};\n const css_urls = [\"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/mapbox-gl-js/v3.0.1/mapbox-gl.css?v=1.5.2\", \"https://cdn.holoviz.org/panel/1.5.2/dist/bundled/deckglplot/maplibre-gl@4.4.1/dist/maplibre-gl.css?v=1.5.2\"];\n const inline_js = [ function(Bokeh) {\n inject_raw_css(\"\\n.dataframe table{\\n border: none;\\n}\\n\\n.panel-df table{\\n width: 100%;\\n border-collapse: collapse;\\n border: none;\\n}\\n.panel-df td{\\n white-space: nowrap;\\n overflow: auto;\\n text-overflow: ellipsis;\\n}\\n\");\n }, function(Bokeh) {\n inject_raw_css(\"\\n.multi-select{\\n color: white;\\n z-index: 100;\\n background: rgba(44,43,43,0.5);\\n border-radius: 1px;\\n width: 120px !important;\\n height: 30px !important;\\n}\\n.multi-select > .bk {\\n padding: 5px;\\n width: 120px !important;\\n height: 30px !important;\\n}\\n\\n.deck-chart {\\n z-index: 10;\\n position: initial !important;\\n}\\n\");\n }, function(Bokeh) {\n inject_raw_css(\"\\n.center-header {\\n text-align: center\\n}\\n.bk-input-group {\\n padding: 10px;\\n}\\n#sidebar {\\n padding-top: 10px;\\n}\\n.custom-widget-box {\\n margin-top: 20px;\\n padding: 5px;\\n border: None !important;\\n}\\n.custom-widget-box > p {\\n margin: 0px;\\n}\\n.bk-input-group {\\n color: None !important;\\n}\\n.indicator {\\n text-align: center;\\n}\\n.widget-card {\\n margin: 5px 10px;\\n}\\n.number-card {\\n margin: 5px 10px;\\n text-align: center;\\n}\\n.number-card-value {\\n width: 100%;\\n margin: 0px;\\n}\\n\");\n }, function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\n function(Bokeh) {\n (function(root, factory) {\n factory(root[\"Bokeh\"]);\n })(this, function(Bokeh) {\n let define;\n return (function outer(modules, entry) {\n if (Bokeh != null) {\n return Bokeh.register_plugin(modules, entry);\n } else {\n throw new Error(\"Cannot find Bokeh. You have to load it prior to loading plugins.\");\n }\n })\n ({\n \"custom/main\": function(require, module, exports) {\n const models = {\n \"CustomInspectTool\": require(\"custom/cuxfilter.charts.datashader.custom_extensions.graph_inspect_widget.custom_inspect_tool\").CustomInspectTool\n };\n require(\"base\").register_models(models);\n module.exports = models;\n },\n \"custom/cuxfilter.charts.datashader.custom_extensions.graph_inspect_widget.custom_inspect_tool\": function(require, module, exports) {\n \"use strict\";\n var _a;\n Object.defineProperty(exports, \"__esModule\", { value: true });\n exports.CustomInspectTool = exports.CustomInspectToolView = void 0;\n const inspect_tool_1 = require(\"models/tools/inspectors/inspect_tool\");\n class CustomInspectToolView extends inspect_tool_1.InspectToolView {\n connect_signals() {\n super.connect_signals();\n this.on_change([this.model.properties.active], () => {\n this.model._active = this.model.active;\n });\n }\n }\n exports.CustomInspectToolView = CustomInspectToolView;\n CustomInspectToolView.__name__ = \"CustomInspectToolView\";\n class CustomInspectTool extends inspect_tool_1.InspectTool {\n constructor(attrs) {\n super(attrs);\n }\n }\n exports.CustomInspectTool = CustomInspectTool;\n _a = CustomInspectTool;\n CustomInspectTool.__name__ = \"CustomInspectTool\";\n (() => {\n _a.prototype.default_view = CustomInspectToolView;\n _a.define(({ Boolean }) => ({\n _active: [Boolean, true]\n }));\n _a.register_alias(\"customInspect\", () => new _a());\n })();\n //# sourceMappingURL=graph_inspect_widget.py:CustomInspectTool.js.map\n }\n }, \"custom/main\");\n ;\n });\n\n },\nfunction(Bokeh) {} // ensure no trailing comma for IE\n ];\n\n function run_inline_js() {\n if ((root.Bokeh !== undefined) || (force === true)) {\n for (let i = 0; i < inline_js.length; i++) {\n try {\n inline_js[i].call(root, root.Bokeh);\n } catch(e) {\n if (!reloading) {\n throw e;\n }\n }\n }\n // Cache old bokeh versions\n if (Bokeh != undefined && !reloading) {\n var NewBokeh = root.Bokeh;\n if (Bokeh.versions === undefined) {\n Bokeh.versions = new Map();\n }\n if (NewBokeh.version !== Bokeh.version) {\n Bokeh.versions.set(NewBokeh.version, NewBokeh)\n }\n root.Bokeh = Bokeh;\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n }\n root._bokeh_is_initializing = false\n }\n\n function load_or_wait() {\n // Implement a backoff loop that tries to ensure we do not load multiple\n // versions of Bokeh and its dependencies at the same time.\n // In recent versions we use the root._bokeh_is_initializing flag\n // to determine whether there is an ongoing attempt to initialize\n // bokeh, however for backward compatibility we also try to ensure\n // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n // before older versions are fully initialized.\n if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n // If the timeout and bokeh was not successfully loaded we reset\n // everything and try loading again\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_is_initializing = false;\n root._bokeh_onload_callbacks = undefined;\n root._bokeh_is_loading = 0\n console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n load_or_wait();\n } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n setTimeout(load_or_wait, 100);\n } else {\n root._bokeh_is_initializing = true\n root._bokeh_onload_callbacks = []\n const bokeh_loaded = root.Bokeh != null && (root.Bokeh.version === py_version || (root.Bokeh.versions !== undefined && root.Bokeh.versions.has(py_version)));\n if (!reloading && !bokeh_loaded) {\n if (root.Bokeh) {\n root.Bokeh = undefined;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n }\n load_libs(css_urls, js_urls, js_modules, js_exports, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n }\n // Give older versions of the autoload script a head-start to ensure\n // they initialize before we start loading newer version.\n setTimeout(load_or_wait, 100)\n}(window));" - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/javascript": [ - "\n", - "if ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n", - " window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n", - "}\n", - "\n", - "\n", - " function JupyterCommManager() {\n", - " }\n", - "\n", - " JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n", - " if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n", - " var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n", - " comm_manager.register_target(comm_id, function(comm) {\n", - " comm.on_msg(msg_handler);\n", - " });\n", - " } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n", - " window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n", - " comm.onMsg = msg_handler;\n", - " });\n", - " } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n", - " google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n", - " var messages = comm.messages[Symbol.asyncIterator]();\n", - " function processIteratorResult(result) {\n", - " var message = result.value;\n", - " console.log(message)\n", - " var content = {data: message.data, comm_id};\n", - " var buffers = []\n", - " for (var buffer of message.buffers || []) {\n", - " buffers.push(new DataView(buffer))\n", - " }\n", - " var metadata = message.metadata || {};\n", - " var msg = {content, buffers, metadata}\n", - " msg_handler(msg);\n", - " return messages.next().then(processIteratorResult);\n", - " }\n", - " return messages.next().then(processIteratorResult);\n", - " })\n", - " }\n", - " }\n", - "\n", - " JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n", - " if (comm_id in window.PyViz.comms) {\n", - " return window.PyViz.comms[comm_id];\n", - " } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n", - " var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n", - " var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n", - " if (msg_handler) {\n", - " comm.on_msg(msg_handler);\n", - " }\n", - " } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n", - " var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n", - " comm.open();\n", - " if (msg_handler) {\n", - " comm.onMsg = msg_handler;\n", - " }\n", - " } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n", - " var comm_promise = google.colab.kernel.comms.open(comm_id)\n", - " comm_promise.then((comm) => {\n", - " window.PyViz.comms[comm_id] = comm;\n", - " if (msg_handler) {\n", - " var messages = comm.messages[Symbol.asyncIterator]();\n", - " function processIteratorResult(result) {\n", - " var message = result.value;\n", - " var content = {data: message.data};\n", - " var metadata = message.metadata || {comm_id};\n", - " var msg = {content, metadata}\n", - " msg_handler(msg);\n", - " return messages.next().then(processIteratorResult);\n", - " }\n", - " return messages.next().then(processIteratorResult);\n", - " }\n", - " }) \n", - " var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n", - " return comm_promise.then((comm) => {\n", - " comm.send(data, metadata, buffers, disposeOnDone);\n", - " });\n", - " };\n", - " var comm = {\n", - " send: sendClosure\n", - " };\n", - " }\n", - " window.PyViz.comms[comm_id] = comm;\n", - " return comm;\n", - " }\n", - " window.PyViz.comm_manager = new JupyterCommManager();\n", - " \n", - "\n", - "\n", - "var JS_MIME_TYPE = 'application/javascript';\n", - "var HTML_MIME_TYPE = 'text/html';\n", - "var EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\n", - "var CLASS_NAME = 'output';\n", - "\n", - "/**\n", - " * Render data to the DOM node\n", - " */\n", - "function render(props, node) {\n", - " var div = document.createElement(\"div\");\n", - " var script = document.createElement(\"script\");\n", - " node.appendChild(div);\n", - " node.appendChild(script);\n", - "}\n", - "\n", - "/**\n", - " * Handle when a new output is added\n", - " */\n", - "function handle_add_output(event, handle) {\n", - " var output_area = handle.output_area;\n", - " var output = handle.output;\n", - " if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n", - " return\n", - " }\n", - " var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n", - " var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n", - " if (id !== undefined) {\n", - " var nchildren = toinsert.length;\n", - " var html_node = toinsert[nchildren-1].children[0];\n", - " html_node.innerHTML = output.data[HTML_MIME_TYPE];\n", - " var scripts = [];\n", - " var nodelist = html_node.querySelectorAll(\"script\");\n", - " for (var i in nodelist) {\n", - " if (nodelist.hasOwnProperty(i)) {\n", - " scripts.push(nodelist[i])\n", - " }\n", - " }\n", - "\n", - " scripts.forEach( function (oldScript) {\n", - " var newScript = document.createElement(\"script\");\n", - " var attrs = [];\n", - " var nodemap = oldScript.attributes;\n", - " for (var j in nodemap) {\n", - " if (nodemap.hasOwnProperty(j)) {\n", - " attrs.push(nodemap[j])\n", - " }\n", - " }\n", - " attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n", - " newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n", - " oldScript.parentNode.replaceChild(newScript, oldScript);\n", - " });\n", - " if (JS_MIME_TYPE in output.data) {\n", - " toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n", - " }\n", - " output_area._hv_plot_id = id;\n", - " if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n", - " window.PyViz.plot_index[id] = Bokeh.index[id];\n", - " } else {\n", - " window.PyViz.plot_index[id] = null;\n", - " }\n", - " } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n", - " var bk_div = document.createElement(\"div\");\n", - " bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n", - " var script_attrs = bk_div.children[0].attributes;\n", - " for (var i = 0; i < script_attrs.length; i++) {\n", - " toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\n", - " }\n", - " // store reference to server id on output_area\n", - " output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n", - " }\n", - "}\n", - "\n", - "/**\n", - " * Handle when an output is cleared or removed\n", - " */\n", - "function handle_clear_output(event, handle) {\n", - " var id = handle.cell.output_area._hv_plot_id;\n", - " var server_id = handle.cell.output_area._bokeh_server_id;\n", - " if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n", - " var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n", - " if (server_id !== null) {\n", - " comm.send({event_type: 'server_delete', 'id': server_id});\n", - " return;\n", - " } else if (comm !== null) {\n", - " comm.send({event_type: 'delete', 'id': id});\n", - " }\n", - " delete PyViz.plot_index[id];\n", - " if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n", - " var doc = window.Bokeh.index[id].model.document\n", - " doc.clear();\n", - " const i = window.Bokeh.documents.indexOf(doc);\n", - " if (i > -1) {\n", - " window.Bokeh.documents.splice(i, 1);\n", - " }\n", - " }\n", - "}\n", - "\n", - "/**\n", - " * Handle kernel restart event\n", - " */\n", - "function handle_kernel_cleanup(event, handle) {\n", - " delete PyViz.comms[\"hv-extension-comm\"];\n", - " window.PyViz.plot_index = {}\n", - "}\n", - "\n", - "/**\n", - " * Handle update_display_data messages\n", - " */\n", - "function handle_update_output(event, handle) {\n", - " handle_clear_output(event, {cell: {output_area: handle.output_area}})\n", - " handle_add_output(event, handle)\n", - "}\n", - "\n", - "function register_renderer(events, OutputArea) {\n", - " function append_mime(data, metadata, element) {\n", - " // create a DOM node to render to\n", - " var toinsert = this.create_output_subarea(\n", - " metadata,\n", - " CLASS_NAME,\n", - " EXEC_MIME_TYPE\n", - " );\n", - " this.keyboard_manager.register_events(toinsert);\n", - " // Render to node\n", - " var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n", - " render(props, toinsert[0]);\n", - " element.append(toinsert);\n", - " return toinsert\n", - " }\n", - "\n", - " events.on('output_added.OutputArea', handle_add_output);\n", - " events.on('output_updated.OutputArea', handle_update_output);\n", - " events.on('clear_output.CodeCell', handle_clear_output);\n", - " events.on('delete.Cell', handle_clear_output);\n", - " events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n", - "\n", - " OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n", - " safe: true,\n", - " index: 0\n", - " });\n", - "}\n", - "\n", - "if (window.Jupyter !== undefined) {\n", - " try {\n", - " var events = require('base/js/events');\n", - " var OutputArea = require('notebook/js/outputarea').OutputArea;\n", - " if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n", - " register_renderer(events, OutputArea);\n", - " }\n", - " } catch(err) {\n", - " }\n", - "}\n" - ], - "application/vnd.holoviews_load.v0+json": "\nif ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n}\n\n\n function JupyterCommManager() {\n }\n\n JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n comm_manager.register_target(comm_id, function(comm) {\n comm.on_msg(msg_handler);\n });\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n comm.onMsg = msg_handler;\n });\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n console.log(message)\n var content = {data: message.data, comm_id};\n var buffers = []\n for (var buffer of message.buffers || []) {\n buffers.push(new DataView(buffer))\n }\n var metadata = message.metadata || {};\n var msg = {content, buffers, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n })\n }\n }\n\n JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n if (comm_id in window.PyViz.comms) {\n return window.PyViz.comms[comm_id];\n } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n if (msg_handler) {\n comm.on_msg(msg_handler);\n }\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n comm.open();\n if (msg_handler) {\n comm.onMsg = msg_handler;\n }\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n var comm_promise = google.colab.kernel.comms.open(comm_id)\n comm_promise.then((comm) => {\n window.PyViz.comms[comm_id] = comm;\n if (msg_handler) {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data};\n var metadata = message.metadata || {comm_id};\n var msg = {content, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n }\n }) \n var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n return comm_promise.then((comm) => {\n comm.send(data, metadata, buffers, disposeOnDone);\n });\n };\n var comm = {\n send: sendClosure\n };\n }\n window.PyViz.comms[comm_id] = comm;\n return comm;\n }\n window.PyViz.comm_manager = new JupyterCommManager();\n \n\n\nvar JS_MIME_TYPE = 'application/javascript';\nvar HTML_MIME_TYPE = 'text/html';\nvar EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\nvar CLASS_NAME = 'output';\n\n/**\n * Render data to the DOM node\n */\nfunction render(props, node) {\n var div = document.createElement(\"div\");\n var script = document.createElement(\"script\");\n node.appendChild(div);\n node.appendChild(script);\n}\n\n/**\n * Handle when a new output is added\n */\nfunction handle_add_output(event, handle) {\n var output_area = handle.output_area;\n var output = handle.output;\n if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n return\n }\n var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n if (id !== undefined) {\n var nchildren = toinsert.length;\n var html_node = toinsert[nchildren-1].children[0];\n html_node.innerHTML = output.data[HTML_MIME_TYPE];\n var scripts = [];\n var nodelist = html_node.querySelectorAll(\"script\");\n for (var i in nodelist) {\n if (nodelist.hasOwnProperty(i)) {\n scripts.push(nodelist[i])\n }\n }\n\n scripts.forEach( function (oldScript) {\n var newScript = document.createElement(\"script\");\n var attrs = [];\n var nodemap = oldScript.attributes;\n for (var j in nodemap) {\n if (nodemap.hasOwnProperty(j)) {\n attrs.push(nodemap[j])\n }\n }\n attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n oldScript.parentNode.replaceChild(newScript, oldScript);\n });\n if (JS_MIME_TYPE in output.data) {\n toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n }\n output_area._hv_plot_id = id;\n if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n window.PyViz.plot_index[id] = Bokeh.index[id];\n } else {\n window.PyViz.plot_index[id] = null;\n }\n } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n var bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n var script_attrs = bk_div.children[0].attributes;\n for (var i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\n }\n // store reference to server id on output_area\n output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n }\n}\n\n/**\n * Handle when an output is cleared or removed\n */\nfunction handle_clear_output(event, handle) {\n var id = handle.cell.output_area._hv_plot_id;\n var server_id = handle.cell.output_area._bokeh_server_id;\n if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n if (server_id !== null) {\n comm.send({event_type: 'server_delete', 'id': server_id});\n return;\n } else if (comm !== null) {\n comm.send({event_type: 'delete', 'id': id});\n }\n delete PyViz.plot_index[id];\n if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n var doc = window.Bokeh.index[id].model.document\n doc.clear();\n const i = window.Bokeh.documents.indexOf(doc);\n if (i > -1) {\n window.Bokeh.documents.splice(i, 1);\n }\n }\n}\n\n/**\n * Handle kernel restart event\n */\nfunction handle_kernel_cleanup(event, handle) {\n delete PyViz.comms[\"hv-extension-comm\"];\n window.PyViz.plot_index = {}\n}\n\n/**\n * Handle update_display_data messages\n */\nfunction handle_update_output(event, handle) {\n handle_clear_output(event, {cell: {output_area: handle.output_area}})\n handle_add_output(event, handle)\n}\n\nfunction register_renderer(events, OutputArea) {\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n var toinsert = this.create_output_subarea(\n metadata,\n CLASS_NAME,\n EXEC_MIME_TYPE\n );\n this.keyboard_manager.register_events(toinsert);\n // Render to node\n var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[0]);\n element.append(toinsert);\n return toinsert\n }\n\n events.on('output_added.OutputArea', handle_add_output);\n events.on('output_updated.OutputArea', handle_update_output);\n events.on('clear_output.CodeCell', handle_clear_output);\n events.on('delete.Cell', handle_clear_output);\n events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n safe: true,\n index: 0\n });\n}\n\nif (window.Jupyter !== undefined) {\n try {\n var events = require('base/js/events');\n var OutputArea = require('notebook/js/outputarea').OutputArea;\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n } catch(err) {\n }\n}\n" - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.holoviews_exec.v0+json": "", - "text/html": [ - "
\n", - "
\n", - "
\n", - "" - ] - }, - "metadata": { - "application/vnd.holoviews_exec.v0+json": { - "id": "7362a503-e861-4c8c-b3f3-3e7e8fa81f09" - } - }, - "output_type": "display_data" - }, - { - "data": {}, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": {}, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.holoviews_exec.v0+json": "", - "text/html": [ - "
\n", - "
\n", - "
\n", - "" - ], - "text/plain": [ - "GridSpec(ncols=12, nrows=5)\n", - " [0] GridSpec(height=800, ncols=12, nrows=5, sizing_mode='fixed', width=1200)\n", - " [0] HoloViews(DynamicMap, height=800, sizing_mode='stretch_both', width=1200)\n", - " [1] WidgetBox(styles={'border-color': '...})\n", - " [0] Number(css_classes=['indicator'], default_color='#2B2B2B', font_size='18pt', format='{value:,}', name='Datapoints Selected', sizing_mode='stretch_width', title_size='14pt', value=58479894)\n", - " [1] Progress(sizing_mode='stretch_width', styles={'--success-bg-color': '...}, value=100)\n", - " [2] Column(min_height=500, sizing_mode='stretch_width')\n", - " [0] MultiChoice(name='cluster', options=[1, 0, 2, 4, 3], sizing_mode='scale_width', styles={'color': '#2B2B2B'}, stylesheets=['\\n .choic...])" - ] - }, - "execution_count": 54, - "metadata": { - "application/vnd.holoviews_exec.v0+json": { - "id": "41dc5a5d-172f-4935-a479-e2ca8aadaabc" - } - }, - "output_type": "execute_result" - } - ], - "source": [ - "dash = cxf_data.dashboard(\n", - " charts=[scatter_chart],\n", - " sidebar=[cluster_widget],\n", - " theme=cxf.themes.dark,\n", - " data_size_widget=True\n", - ")\n", - "\n", - "dash.app()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import IPython\n", - "app = IPython.Application.instance()\n", - "app.kernel.do_shutdown(True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.15" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} -- cgit v1.2.3