Flat Torus

[1]:
%matplotlib inline
[2]:
# Not really required
import sys
sys.path.insert(0, '../../..')
[3]:
from pyLDLE2 import datasets
from pyLDLE2 import buml_, util_
matplotlib.get_backend() =  module://matplotlib_inline.backend_inline
[4]:
save_dir_root = '../data/pyLDLE2/flattorus4d/'
[5]:
X, labelsMat, ddX = datasets.Datasets().flattorus4d()
X.shape =  (10000, 4)
[6]:
# The supplied options would override the default options
buml_obj = buml_.BUML(local_opts={'algo':'LPCA'},
                      intermed_opts={'eta_min': 15},
                  vis_opts={'c': labelsMat[:,0], 'save_dir': save_dir_root},
                  verbose=True, debug=True)
local_opts['k_nn0'] = 700 is created.
Options provided:
local_opts:
{
    "Atilde_method": "LDLE_1",
    "N": 100,
    "U_method": "k_nn",
    "algo": "LPCA",
    "alpha": 1,
    "debug": true,
    "delta": 0.9,
    "gl_type": "unnorm",
    "k": 28,
    "k_nn": 49,
    "k_nn0": 700,
    "k_tune": 7,
    "lambda1_decay": 0.75,
    "lambda1_init": 8,
    "lambda1_min": 0.001,
    "max_iter": 300,
    "max_sparsity": 0.9,
    "metric": "euclidean",
    "n_proc": 32,
    "p": 0.99,
    "power": 5,
    "pp_n_thresh": 32,
    "radius": 0.5,
    "reg": 0.0,
    "scale_by": "gamma",
    "tau": 50,
    "to_postprocess": true,
    "verbose": true
}
intermed_opts:
{
    "algo": "best",
    "debug": true,
    "eta_max": 25,
    "eta_min": 15,
    "len_S_thresh": 256,
    "local_algo": "LPCA",
    "metric": "euclidean",
    "n_proc": 32,
    "n_times": 4,
    "verbose": true
}
global_opts:
{
    "add_dim": false,
    "align_transform": "rigid",
    "align_w_parent_only": true,
    "alpha": 0.3,
    "beta": {
        "align": null,
        "repel": 1
    },
    "color_tear": true,
    "compute_error": false,
    "debug": true,
    "eps": 1e-08,
    "err_tol": 0.0001,
    "far_off_points_type": "reuse_fixed",
    "init_algo_name": "procrustes",
    "k": 28,
    "max_internal_iter": 100,
    "max_iter": 20,
    "metric": "euclidean",
    "n_proc": 32,
    "n_repel": 0,
    "nu": 3,
    "patience": 5,
    "refine_algo_name": "rgd",
    "repel_by": 0.0,
    "to_tear": true,
    "verbose": true,
    "vis_before_init": false
}
[7]:
buml_obj.fit(X=X)
Computing local views using LPCA
local_param: all 10000 points processed...
max distortion is 1.051459
Done.
##############################
Time elapsed from last time log: 1.3 seconds
Total time elapsed: 1.3 seconds
##############################
Posprocessing local parameterizations.
#Param replaced: 6111, max distortion: 1.051459
#Param replaced: 1033, max distortion: 1.051459
#Param replaced: 327, max distortion: 1.051459
#Param replaced: 48, max distortion: 1.051459
#Param replaced: 0, max distortion: 1.051459
Max local distortion after postprocessing: 1.0514588127278819
Done.
##############################
Time elapsed from last time log: 4.8 seconds
Total time elapsed: 6.1 seconds
##############################
Max local distortion = 1.0514588127278819
Constructing intermediate views.
eta = 2.
#non-empty views with sz < 2 = 10000
#nodes in views with sz < 2 = 10000
Costs computed when eta = 2.
##############################
Time elapsed from last time log: 9.1 seconds
Total time elapsed: 10.2 seconds
##############################
ctr=7936, total_len_S=48472, avg_len_S=6.108
Remaining #nodes in views with sz < 2 = 0
Done with eta = 2.
##############################
Time elapsed from last time log: 189.1 seconds
Total time elapsed: 199.2 seconds
##############################
eta = 3.
#non-empty views with sz < 3 = 481
#nodes in views with sz < 3 = 962
Costs computed when eta = 3.
##############################
Time elapsed from last time log: 1.4 seconds
Total time elapsed: 200.7 seconds
##############################
ctr=878, total_len_S=17371, avg_len_S=19.785
Remaining #nodes in views with sz < 3 = 0
Done with eta = 3.
##############################
Time elapsed from last time log: 10.9 seconds
Total time elapsed: 211.6 seconds
##############################
eta = 4.
#non-empty views with sz < 4 = 300
#nodes in views with sz < 4 = 900
Costs computed when eta = 4.
##############################
Time elapsed from last time log: 1.2 seconds
Total time elapsed: 212.8 seconds
##############################
ctr=816, total_len_S=23808, avg_len_S=29.176
Remaining #nodes in views with sz < 4 = 0
Done with eta = 4.
##############################
Time elapsed from last time log: 16.4 seconds
Total time elapsed: 229.2 seconds
##############################
eta = 5.
#non-empty views with sz < 5 = 205
#nodes in views with sz < 5 = 820
Costs computed when eta = 5.
##############################
Time elapsed from last time log: 1.3 seconds
Total time elapsed: 230.5 seconds
##############################
ctr=747, total_len_S=27080, avg_len_S=36.252
Remaining #nodes in views with sz < 5 = 0
Done with eta = 5.
##############################
Time elapsed from last time log: 17.6 seconds
Total time elapsed: 248.0 seconds
##############################
eta = 6.
#non-empty views with sz < 6 = 169
#nodes in views with sz < 6 = 845
Costs computed when eta = 6.
##############################
Time elapsed from last time log: 1.4 seconds
Total time elapsed: 249.4 seconds
##############################
ctr=756, total_len_S=32410, avg_len_S=42.870
Remaining #nodes in views with sz < 6 = 0
Done with eta = 6.
##############################
Time elapsed from last time log: 20.1 seconds
Total time elapsed: 269.5 seconds
##############################
eta = 7.
#non-empty views with sz < 7 = 138
#nodes in views with sz < 7 = 828
Costs computed when eta = 7.
##############################
Time elapsed from last time log: 1.1 seconds
Total time elapsed: 270.6 seconds
##############################
ctr=740, total_len_S=35653, avg_len_S=48.180
Remaining #nodes in views with sz < 7 = 0
Done with eta = 7.
##############################
Time elapsed from last time log: 24.7 seconds
Total time elapsed: 295.3 seconds
##############################
eta = 8.
#non-empty views with sz < 8 = 98
#nodes in views with sz < 8 = 686
Costs computed when eta = 8.
##############################
Time elapsed from last time log: 1.1 seconds
Total time elapsed: 296.4 seconds
##############################
ctr=597, total_len_S=32188, avg_len_S=53.916
Remaining #nodes in views with sz < 8 = 0
Done with eta = 8.
##############################
Time elapsed from last time log: 23.1 seconds
Total time elapsed: 319.4 seconds
##############################
eta = 9.
#non-empty views with sz < 9 = 85
#nodes in views with sz < 9 = 680
Costs computed when eta = 9.
##############################
Time elapsed from last time log: 1.1 seconds
Total time elapsed: 320.5 seconds
##############################
ctr=632, total_len_S=37272, avg_len_S=58.975
Remaining #nodes in views with sz < 9 = 0
Done with eta = 9.
##############################
Time elapsed from last time log: 28.4 seconds
Total time elapsed: 348.9 seconds
##############################
eta = 10.
#non-empty views with sz < 10 = 74
#nodes in views with sz < 10 = 666
Costs computed when eta = 10.
##############################
Time elapsed from last time log: 1.1 seconds
Total time elapsed: 350.0 seconds
##############################
ctr=576, total_len_S=36799, avg_len_S=63.887
Remaining #nodes in views with sz < 10 = 0
Done with eta = 10.
##############################
Time elapsed from last time log: 32.2 seconds
Total time elapsed: 382.2 seconds
##############################
eta = 11.
#non-empty views with sz < 11 = 56
#nodes in views with sz < 11 = 560
Costs computed when eta = 11.
##############################
Time elapsed from last time log: 0.9 seconds
Total time elapsed: 383.1 seconds
##############################
ctr=500, total_len_S=34059, avg_len_S=68.118
Remaining #nodes in views with sz < 11 = 0
Done with eta = 11.
##############################
Time elapsed from last time log: 27.5 seconds
Total time elapsed: 410.6 seconds
##############################
eta = 12.
#non-empty views with sz < 12 = 45
#nodes in views with sz < 12 = 495
Costs computed when eta = 12.
##############################
Time elapsed from last time log: 1.1 seconds
Total time elapsed: 411.7 seconds
##############################
ctr=440, total_len_S=31521, avg_len_S=71.639
Remaining #nodes in views with sz < 12 = 0
Done with eta = 12.
##############################
Time elapsed from last time log: 26.2 seconds
Total time elapsed: 437.9 seconds
##############################
eta = 13.
#non-empty views with sz < 13 = 49
#nodes in views with sz < 13 = 588
Costs computed when eta = 13.
##############################
Time elapsed from last time log: 1.0 seconds
Total time elapsed: 439.0 seconds
##############################
ctr=536, total_len_S=40874, avg_len_S=76.257
Remaining #nodes in views with sz < 13 = 0
Done with eta = 13.
##############################
Time elapsed from last time log: 46.2 seconds
Total time elapsed: 485.1 seconds
##############################
eta = 14.
#non-empty views with sz < 14 = 33
#nodes in views with sz < 14 = 429
Costs computed when eta = 14.
##############################
Time elapsed from last time log: 1.3 seconds
Total time elapsed: 486.4 seconds
##############################
ctr=429, total_len_S=34851, avg_len_S=81.238
Remaining #nodes in views with sz < 14 = 0
Done with eta = 14.
##############################
Time elapsed from last time log: 37.4 seconds
Total time elapsed: 523.8 seconds
##############################
eta = 15.
#non-empty views with sz < 15 = 32
#nodes in views with sz < 15 = 448
Costs computed when eta = 15.
##############################
Time elapsed from last time log: 1.2 seconds
Total time elapsed: 525.0 seconds
##############################
ctr=383, total_len_S=33317, avg_len_S=86.990
Remaining #nodes in views with sz < 15 = 0
Done with eta = 15.
##############################
Time elapsed from last time log: 25.6 seconds
Total time elapsed: 550.6 seconds
##############################
Pruning and cleaning up.
Done.
##############################
Time elapsed from last time log: 0.8 seconds
Total time elapsed: 551.4 seconds
##############################
After clustering, max distortion is 1.184359
Using rigid transforms for alignment.
Computing laterations scores for overlaps b/w intermed views
Done
##############################
Time elapsed from last time log: 1.0 seconds
Total time elapsed: 1.0 seconds
##############################
Computing a lateration.
Seq of intermediate views and their predecessors computed.
No. of connected components = 1
Done.
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 1.0 seconds
##############################
Computing initial embedding using: procrustes algorithm
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 1.0 seconds
##############################
Initial alignment of 120 views completed
Initial alignment of 240 views completed
Initial alignment of 360 views completed
Embedding initialized.
##############################
Time elapsed from last time log: 0.6 seconds
Total time elapsed: 1.7 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_1.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 0
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 13.6 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 4.2 seconds
Total time elapsed: 17.8 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_3.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 1
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 26.7 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 4.8 seconds
Total time elapsed: 31.5 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_5.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 2
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 41.0 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 5.3 seconds
Total time elapsed: 46.3 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_7.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 3
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 55.6 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 12.2 seconds
Total time elapsed: 67.9 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_9.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 4
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 78.5 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 5.9 seconds
Total time elapsed: 84.4 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_11.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 5
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 96.1 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 9.2 seconds
Total time elapsed: 105.2 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_13.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 6
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 116.2 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 6.4 seconds
Total time elapsed: 122.6 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_15.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 7
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 132.3 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 3.9 seconds
Total time elapsed: 136.2 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_17.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 8
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 148.0 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 3.8 seconds
Total time elapsed: 151.8 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_19.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 9
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 163.1 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 4.9 seconds
Total time elapsed: 168.0 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_21.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 10
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 178.2 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 6.5 seconds
Total time elapsed: 184.7 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_23.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 11
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 193.9 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 9.8 seconds
Total time elapsed: 203.7 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_25.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 12
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 215.3 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 5.2 seconds
Total time elapsed: 220.4 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_27.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 13
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 231.2 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 11.1 seconds
Total time elapsed: 242.3 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_29.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 14
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 255.0 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 6.1 seconds
Total time elapsed: 261.1 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_31.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 15
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 273.7 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 3.9 seconds
Total time elapsed: 277.6 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_33.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 16
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 291.7 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 4.0 seconds
Total time elapsed: 295.7 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_35.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 17
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 310.5 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 5.5 seconds
Total time elapsed: 316.0 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_37.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 18
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 329.0 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 14.3 seconds
Total time elapsed: 343.3 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_39.png
Refining with rgd algorithm for 100 iterations.
Refinement iteration: 19
##############################
Time elapsed from last time log: 0.0 seconds
Total time elapsed: 356.1 seconds
##############################
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Descent starts
Done.
##############################
Time elapsed from last time log: 4.8 seconds
Total time elapsed: 361.0 seconds
##############################
Computing error.
min and max weights: 1.0 1.0
Computing Pseudoinverse of a matrix of L of size 10000 + 480 multiplied with B
Computing svd
Done
Alignment error: 0.020676
##############################
Time elapsed from last time log: 4.4 seconds
Total time elapsed: 365.3 seconds
##############################
../../_images/lpca_nbks_closed_manifolds_flattorus4d_7_41.png
[7]:
array([[ 0.37526612, -0.02017774],
       [ 0.37521778, -0.01043941],
       [ 0.3751451 , -0.00060372],
       ...,
       [ 0.36557028, -0.04968134],
       [ 0.36551362, -0.03986399],
       [ 0.36560675, -0.03008007]])
[8]:
%matplotlib inline
buml_obj.GlobalViews.vis_embedding(buml_obj.GlobalViews.y_final, buml_obj.vis, buml_obj.vis_opts,
                                   buml_obj.GlobalViews.color_of_pts_on_tear_final,
                                   title='Final global embedding', )
../../_images/lpca_nbks_closed_manifolds_flattorus4d_8_0.png
[9]:
util_.save(save_dir_root, 'lpca.dat', [X, labelsMat, buml_obj])
[ ]: