From 4d9e89c0afb0071fca9a018a65fe2472fccdb5c6 Mon Sep 17 00:00:00 2001 From: ashawkey Date: Fri, 29 Dec 2023 14:17:28 +0800 Subject: [PATCH] update --- docs/algorithm/advanced/final_exam_prep.md | 28 ----- ...16\347\274\200\346\225\260\347\273\204.md" | 26 ++--- ...04\350\277\236\351\200\232\346\200\247.md" | 2 - .../\345\271\266\346\237\245\351\233\206.md" | 1 - ...55\350\267\257\347\256\227\346\263\225.md" | 7 +- ...21\347\212\266\346\225\260\347\273\204.md" | 4 +- .../\347\272\277\346\256\265\346\240\221.md" | 4 + .../\347\272\277\346\256\265\346\240\2212.md" | 4 - ...65\346\240\221\346\200\273\347\273\223.md" | 8 -- .../\347\275\221\347\273\234\346\265\201.md" | 2 - .../\347\275\221\347\273\234\346\265\2012.md" | 5 - ...41\347\256\227\345\207\240\344\275\225.md" | 3 - docs/algorithm/algoanalysis/Approximation.md | 2 - docs/algorithm/algoanalysis/NP.md | 7 -- docs/algorithm/basic/DA01_Intro.md | 12 ++- docs/algorithm/basic/DA02_LinearTable.md | 11 +- docs/algorithm/basic/DA03_StackAndQueue.md | 5 +- docs/algorithm/basic/DA04_String.md | 2 - docs/algorithm/basic/DA05_BinaryTree.md | 24 +++++ docs/algorithm/basic/DA07_Graph.md | 5 +- docs/algorithm/basic/DA08_InnerSorting.md | 12 +-- docs/algorithm/basic/DA09_OuterSorting.md | 6 +- docs/algorithm/basic/DA10_Search.md | 49 ++++++--- docs/algorithm/basic/DA11_Index.md | 37 +++---- docs/algorithm/basic/DA12_Advanced.md | 22 ++-- docs/algorithm/review/ACM_IO.md | 8 -- docs/algorithm/review/Python.md | 6 -- docs/algorithm/review/Trie.md | 2 - ...04\345\210\222\351\242\230\347\233\256.md" | 19 ---- .../review/old/\345\233\276\350\256\272.md" | 3 - .../\345\244\215\346\235\202\345\272\246.md" | 18 ---- .../\345\255\227\347\254\246\344\270\262.md" | 5 - .../best_time_to_buy_and_sell_stock.md | 8 +- .../review/problem_series/digit_simulation.md | 1 - .../review/problem_series/jump_game.md | 1 - .../problem_series/median_of_data_stream.md | 2 - ...2x\347\232\204\346\246\202\347\216\207.md" | 4 + .../review/problem_series/palindrome.md | 3 - .../review/problem_series/search_2d_matrix.md | 1 - ...343\200\220math\343\200\221joseph_loop.md" | 5 +- ...32\345\221\230\345\267\245\346\225\260.md" | 2 - ...26\345\231\250\345\215\212\345\276\204.md" | 5 - ...00\347\232\204\346\225\260\345\255\227.md" | 7 -- ...04\345\222\214\343\200\201\347\247\257.md" | 4 - ...72\345\212\233\351\227\256\351\242\230.md" | 5 +- ...22\345\210\227\344\270\252\346\225\260.md" | 18 +++- ...02\351\276\204\346\234\213\345\217\213.md" | 3 - ...06\345\217\221\351\245\274\345\271\262.md" | 4 - ...40\346\225\260\345\210\206\346\225\260.md" | 5 - ...46\344\270\262\345\214\271\351\205\215.md" | 7 -- ...11\344\270\216\345\220\265\351\227\271.md" | 2 - ...17\351\253\230\345\272\246\346\240\221.md" | 1 - ...27\347\254\246\345\255\220\344\270\262.md" | 1 - ...15\345\244\215\345\255\220\344\270\262.md" | 12 ++- ...44\344\270\252\345\205\203\347\264\240.md" | 1 - ...36\344\270\211\345\205\203\347\273\204.md" | 3 - ...36\350\264\237\346\225\264\346\225\260.md" | 7 ++ ...51\345\260\224\346\212\225\347\245\250.md" | 2 - ...2\344\270\2722\347\232\204\345\271\202.md" | 1 - .../\344\272\214\345\210\206\346\263\225.md" | 4 + .../\345\207\270\344\274\230\345\214\226.md" | 4 + ...50\346\200\201\350\247\204\345\210\222.md" | 23 ++-- ...72\351\227\264\351\227\256\351\242\230.md" | 14 --- ...25\350\260\203\351\230\237\345\210\227.md" | 7 -- .../\345\217\214\346\214\207\351\222\210.md" | 12 --- .../review/\345\223\210\345\270\214.md" | 1 - .../review/\345\233\236\346\272\257.md" | 4 - "docs/algorithm/review/\345\233\276.md" | 3 - ...72\351\227\264\351\227\256\351\242\230.md" | 3 - .../review/\345\237\272\347\241\200.md" | 1 - .../review/\346\220\234\347\264\242.md" | 9 -- .../review/\350\264\252\345\277\203.md" | 2 - docs/c/basic_compile.md | 8 -- docs/c/c.md | 13 --- docs/c/cpp.md | 16 --- docs/c/csapp/01_Roaming.md | 4 - docs/c/csapp/02_Information_Storage.md | 5 - docs/c/csapp/03_Machine_Language.md | 5 - docs/c/csapp/07_Linking.md | 5 - docs/c/ctricks.md | 2 - docs/c/magic/rvalue_universal_ref.md | 4 - docs/c/modern_cpp.md | 10 -- docs/c/template.md | 1 - docs/crypto/asymmetric_cryptography.md | 2 - docs/crypto/base64.md | 5 - docs/crypto/blockchain.md | 5 - docs/cuda/atomic_utils.md | 6 -- docs/cuda/basics.md | 28 ----- docs/cuda/gpu_to_arch.md | 1 - docs/cuda/nsight-sys.md | 1 - docs/cuda/project_layout.md | 8 -- docs/cuda/runtime.md | 3 - docs/cuda/thrust.md | 3 - docs/cuda/triton.md | 3 - docs/cuda/utils.md | 6 -- docs/cuda/vector_utils.md | 3 - docs/deeplearning/autodiff_understand.md | 8 -- docs/deeplearning/background_removal.md | 8 -- docs/deeplearning/diffusion_models.md | 46 ++++++-- docs/deeplearning/einops_tutorial.md | 1 - docs/deeplearning/flax_tutorial.md | 3 - docs/deeplearning/jax_tutorial.md | 14 --- docs/deeplearning/mAP_understand.md | 3 - docs/deeplearning/old/CVXPY_tutorial.md | 5 - docs/deeplearning/old/Convex_optimization.md | 37 +++---- docs/deeplearning/old/RAPIDS_tutorial.md | 3 - docs/deeplearning/old/datatable_tutorial.md | 10 +- docs/deeplearning/old/feature_engineering.md | 3 - docs/deeplearning/old/k_means_tutorial.md | 12 ++- docs/deeplearning/old/keras_tutorial.md | 8 -- docs/deeplearning/old/meshlab_tutorial.md | 1 - docs/deeplearning/old/pytorch_API.md | 1 - docs/deeplearning/old/pytorch_tutorial.md | 9 +- docs/deeplearning/old/scipy.sparse_API.md | 1 - docs/deeplearning/old/sklearn_API.md | 3 - docs/deeplearning/old/sklearn_tutorial.md | 8 +- docs/deeplearning/old/sklearn_user_guide.md | 12 +++ docs/deeplearning/old/tensorflow_API.md | 20 ++-- docs/deeplearning/pandas_tutorial.md | 16 --- docs/deeplearning/pytorch_cpp_extension.md | 10 -- docs/deeplearning/pytorch_grad.md | 8 -- docs/deeplearning/pytorch_internals.md | 2 - docs/deeplearning/roc_auc_understand.md | 7 +- docs/deeplearning/spark/dataframe.md | 1 - docs/deeplearning/wordcloud.md | 3 - docs/docker/compose.md | 1 - docs/docker/cuda.md | 1 - docs/docker/display.md | 1 - docs/docker/docker.md | 3 - docs/graphics/101_rasterization.md | 1 - docs/graphics/102_shading.md | 28 ++--- docs/graphics/103_geometry.md | 21 ++-- docs/graphics/104_raytracing.md | 13 +-- docs/graphics/105_material.md | 4 - docs/graphics/opengl_advanced.md | 11 +- docs/graphics/opengl_basics.md | 5 - docs/graphics/opengl_lighting.md | 1 - docs/graphics/pbr.md | 4 + docs/graphics/prt.md | 15 ++- docs/graphics/python_moderngl.md | 11 -- docs/index.md | 40 +++---- docs/latex/tutorial.md | 14 --- docs/linux/advanced_bash.md | 1 - docs/linux/alternatives.md | 1 - docs/linux/apt_dpkg.md | 11 -- docs/linux/awscli.md | 3 - docs/linux/bash.md | 1 - docs/linux/cadaver.md | 1 - docs/linux/conda.md | 4 - docs/linux/cron.md | 4 - docs/linux/disk.md | 13 --- docs/linux/env.md | 5 - docs/linux/find.md | 2 - docs/linux/gdb.md | 2 - docs/linux/git.md | 13 --- docs/linux/git_lfs.md | 2 - docs/linux/git_tricks.md | 15 --- docs/linux/htop.md | 1 - docs/linux/locate.md | 1 - docs/linux/lscolor.md | 4 - docs/linux/modern_cmd.md | 18 ---- docs/linux/network_utils.md | 10 -- docs/linux/nps.md | 5 - docs/linux/nvidia_cuda.md | 7 -- docs/linux/qt.md | 10 -- docs/linux/rclone.md | 3 - docs/linux/rm_mv.md | 2 - docs/linux/rsync.md | 3 - docs/linux/runlevel.md | 4 - docs/linux/security/auth.md | 6 -- docs/linux/security/fail2ban.md | 1 - docs/linux/security/file-permission.md | 5 - docs/linux/security/netstat.md | 3 - docs/linux/security/ps-kill.md | 3 - docs/linux/security/ssh.md | 2 - docs/linux/slurm.md | 9 +- docs/linux/swap.md | 6 -- docs/linux/sysrq.md | 3 - docs/linux/trash.md | 2 - docs/linux/ubuntu_install_list.md | 4 - docs/linux/ufw.md | 1 - docs/linux/ulimit.md | 2 - docs/linux/vim.md | 2 - docs/linux/wget.md | 4 - docs/linux/wsl/simulate_systemd.md | 1 - docs/linux/xorg.md | 8 -- docs/linux/zip.md | 1 - docs/math/ddpm.md | 4 + docs/math/graph/graph_clustering.md | 17 ++- docs/math/graph/graph_spectral_theory.md | 57 +++++++++- docs/math/quaternion.md | 102 ++++++++++++++++-- docs/math/statistics/Rstatistics.md | 6 -- docs/math/statistics/test.md | 4 - docs/model/blender_tutorial.md | 7 -- docs/nas/router/router.md | 3 - docs/nas/synology/frp_nginx_config.md | 2 - docs/nas/unraid/CA_proxy.md | 7 -- docs/nas/unraid/filebrowser.md | 3 - docs/nas/unraid/frp_example.md | 1 - docs/nas/unraid/remote_access.md | 5 - docs/nas/unraid/webdav_raidrive.md | 1 - docs/onnx/basics.md | 1 - docs/onnx/web.md | 1 - docs/others/chebnet_understanding.md | 22 ++-- docs/others/chrom_custom_search.md | 4 - docs/others/code_duplicate_check.md | 1 - docs/others/ffmpeg_tutorial.md | 1 - docs/others/google_protobuff.md | 8 -- docs/others/nerf_gradient.md | 28 +++++ docs/others/programming_language_type.md | 1 - docs/others/recommenders.md | 26 ++--- docs/others/vs_code_hotkey.md | 7 -- docs/python/config.md | 10 +- docs/python/cython.md | 6 -- docs/python/dearpygui.md | 1 - docs/python/gradio.md | 12 --- docs/python/hash.md | 1 - docs/python/introspection.md | 2 - docs/python/mkdocs.md | 5 - docs/python/monky_patch.md | 2 - docs/python/numpy_pitfalls.md | 13 --- docs/python/open3d_ASH.md | 2 - docs/python/pybind.md | 6 -- docs/python/pymeshlab.md | 6 -- docs/python/pypi_publish.md | 10 -- docs/python/pytorch_pitfalls.md | 1 - docs/python/re_tutorial.md | 3 - docs/python/threading_multiprocessing.md | 10 -- docs/python/tyro.md | 5 - docs/python/unittest.md | 1 - docs/python/walk.md | 1 - .../3d reconstruction and generation.md | 40 ------- docs/readings/paper recommendation 2022.md | 5 - docs/speakings/conversation.md | 4 - docs/speakings/daily.md | 3 - docs/speakings/meetings.md | 4 - docs/speakings/travel.md | 1 - docs/vision/camera_combined.md | 11 +- docs/vision/camera_intrinsics_exintrics.md | 40 +++++-- docs/vision/camera_view_projection.md | 34 ++++-- docs/vision/colmap.md | 6 -- docs/vision/eigen.md | 18 ---- docs/vision/image_interpolation.md | 4 - docs/vision/image_processing.md | 39 ++++--- docs/vision/opencv.md | 1 - docs/vision/transformation.md | 19 +++- docs/web/backend/golang_basics.md | 21 ---- docs/web/backend/golang_gin.md | 1 - docs/web/backend/python_fastapi.md | 5 - docs/web/backend/python_flask.md | 10 -- docs/web/backend/sql_mysql.md | 15 --- docs/web/backend/sql_sqlite.md | 7 -- docs/web/deploy/gh-pages.md | 1 - docs/web/deploy/manifest.md | 1 - docs/web/deploy/nginx.md | 8 -- docs/web/deploy/pm2.md | 1 - docs/web/deploy/ssl_acmesh.md | 4 - docs/web/deploy/uwsgi.md | 5 - docs/web/dns.md | 2 - docs/web/frontend/chrome_debugger.md | 1 - docs/web/frontend/html/css.md | 1 - docs/web/frontend/html/html.md | 8 -- docs/web/frontend/html/html_js_interaction.md | 1 - docs/web/frontend/html/http.md | 2 - docs/web/frontend/html/web_api.md | 3 - docs/web/frontend/i18n.md | 2 - docs/web/frontend/javascript_advanced.md | 7 -- docs/web/frontend/javascript_async.md | 6 -- docs/web/frontend/javascript_basics.md | 12 --- docs/web/frontend/lodash.md | 1 - docs/web/frontend/nodejs_basics.md | 7 -- docs/web/frontend/pyodide.md | 7 -- docs/web/frontend/react-basics.md | 23 ---- docs/web/frontend/react-formik.md | 5 - docs/web/frontend/three/basic.md | 1 - docs/web/frontend/three/plyloader.md | 2 - docs/web/frontend/webpack.md | 6 -- docs/web/ip.md | 6 -- docs/web/proxy/concepts.md | 7 -- docs/web/proxy/frp_reverse_proxy.md | 1 - docs/web/proxy/set_usual_apps_proxy.md | 4 - docs/web/proxy/ss.md | 13 --- docs/web/proxy/trojan-go.md | 8 -- docs/web/proxy/trojan.md | 1 - docs/web/rss/rsshub.md | 3 - docs/web/rss/ttrss.md | 7 -- docs/web/scrape/grab.md | 6 -- docs/web/scrape/xpath.md | 4 - docs/web/web_overview.md | 4 - docs/windows/cuda.md | 5 - docs/writings/examples.md | 10 -- docs/writings/pitfalls.md | 9 -- docs/writings/rebuttals.md | 4 - docs/writings/review.md | 2 - docs/writings/societal_impact.md | 3 - fix_mathblock.py | 52 +++++++++ sync.ps1 | 1 + 297 files changed, 755 insertions(+), 1560 deletions(-) create mode 100644 fix_mathblock.py diff --git a/docs/algorithm/advanced/final_exam_prep.md b/docs/algorithm/advanced/final_exam_prep.md index c770822ec..2b31d14c8 100644 --- a/docs/algorithm/advanced/final_exam_prep.md +++ b/docs/algorithm/advanced/final_exam_prep.md @@ -181,7 +181,6 @@ int main() { ``` - ### BIT ##### apple tree @@ -275,7 +274,6 @@ int main() { ``` - ### Segment Tree ##### Balanced Lineup @@ -352,7 +350,6 @@ int main() { ``` - ##### integers ```c++ @@ -458,7 +455,6 @@ int main() { ``` - ##### kth-Number ```c++ @@ -544,7 +540,6 @@ int main() { ``` - ##### Mayor's Poster ```c++ @@ -640,9 +635,6 @@ int main() { ``` - - - ### Trie ##### Proto @@ -736,7 +728,6 @@ int main() { ``` - ### Directed Tarjan ##### popular cows @@ -840,7 +831,6 @@ int main() { ``` - ### Shortest Path ###### candies @@ -929,7 +919,6 @@ int main() { ``` - ##### currency exchange ```c++ @@ -1000,7 +989,6 @@ int main() { ``` - ##### Warmholes ```c++ @@ -1075,7 +1063,6 @@ int main() { ``` - ##### cow contest ```c++ @@ -1153,9 +1140,6 @@ int main() { ``` - - - ---- ### Undirected Tarjan @@ -1163,7 +1147,6 @@ int main() { ··· - ### Maximum Flow ##### Alice's Chance @@ -1425,9 +1408,6 @@ int main() { ``` - - - ### Geometry ##### TOYS @@ -1987,11 +1967,6 @@ int main() { ``` - - - - - ### Suffix Array ##### Substrings @@ -2112,6 +2087,3 @@ int main() { ``` - - - diff --git "a/docs/algorithm/advanced/\345\220\216\347\274\200\346\225\260\347\273\204.md" "b/docs/algorithm/advanced/\345\220\216\347\274\200\346\225\260\347\273\204.md" index 710a5edb8..5c5e24d10 100644 --- "a/docs/algorithm/advanced/\345\220\216\347\274\200\346\225\260\347\273\204.md" +++ "b/docs/algorithm/advanced/\345\220\216\347\274\200\346\225\260\347\273\204.md" @@ -15,7 +15,6 @@ sa[5] = 2 nana ``` - ### $O(n \log n)$ Method to find SA * **j-suffix** @@ -68,7 +67,6 @@ sa[5] = 2 nana ``` - ### RMQ (Sparse Table) Range Maximum/Minimum Query. `RMQ(arr, i, j)` @@ -165,9 +163,6 @@ int main() { ``` - - - ### 最长公共前缀数组 任给两个后缀,O(1)求其最长公共前缀(LCP)的长度。 @@ -196,20 +191,26 @@ LCPL(i, j) = min{height[i+1, ..., j]} // RMQ O(1) * LCP引理1 + $$ +\displaylines{ LCPL(i, j) = min\{LCPL(k, k+1)| k=i, ..., j-1\} +} $$ * LCP引理2 + $$ +\displaylines{ \forall i \le k \lt j \\ LCPL(k, j) \ge LCPL(i, j) +} $$ @@ -221,19 +222,16 @@ $$ `i>0 && Rank[i]>0`时: + $$ +\displaylines{ H[i] \ge H[i-1] -1 +} $$ - - - - - - ```c++ int Rank[maxn], height[maxn]; void buildHeight(char* str, int n, int* sa){ @@ -252,11 +250,9 @@ buildHeight("abcd", 5, sa); ``` - ### Applications - ###### POJ2774 Long Long Message 求两个字符串的最长公共子串。 @@ -345,7 +341,6 @@ int main() { ``` - ###### 最长公共子串(多序列) [ref](https://www.xuebuyuan.com/3226411.html) @@ -357,7 +352,6 @@ int main() { * 最坏复杂度$O(l L\log L)$,在所有字符串都只含有同一个字符时达到。 - ###### POJ3450 Corporate Identity ```c++ @@ -487,7 +481,6 @@ int main() { ``` - ###### Musical Theme POJ 不重叠的最长重复子串。 @@ -589,7 +582,6 @@ int main() { ``` - ##### Milk Pattern 可重叠的至少k次的最长重复子序列。 diff --git "a/docs/algorithm/advanced/\345\233\276\347\232\204\350\277\236\351\200\232\346\200\247.md" "b/docs/algorithm/advanced/\345\233\276\347\232\204\350\277\236\351\200\232\346\200\247.md" index 1993631f3..e4a455e8f 100644 --- "a/docs/algorithm/advanced/\345\233\276\347\232\204\350\277\236\351\200\232\346\200\247.md" +++ "b/docs/algorithm/advanced/\345\233\276\347\232\204\350\277\236\351\200\232\346\200\247.md" @@ -245,7 +245,6 @@ ``` - ### 无向连通图 * 割点&桥 @@ -759,4 +758,3 @@ ``` - diff --git "a/docs/algorithm/advanced/\345\271\266\346\237\245\351\233\206.md" "b/docs/algorithm/advanced/\345\271\266\346\237\245\351\233\206.md" index c0ec788bb..341f4b8b2 100644 --- "a/docs/algorithm/advanced/\345\271\266\346\237\245\351\233\206.md" +++ "b/docs/algorithm/advanced/\345\271\266\346\237\245\351\233\206.md" @@ -366,4 +366,3 @@ ``` - diff --git "a/docs/algorithm/advanced/\346\234\200\347\237\255\350\267\257\347\256\227\346\263\225.md" "b/docs/algorithm/advanced/\346\234\200\347\237\255\350\267\257\347\256\227\346\263\225.md" index a8c5b4d98..f7becc185 100644 --- "a/docs/algorithm/advanced/\346\234\200\347\237\255\350\267\257\347\256\227\346\263\225.md" +++ "b/docs/algorithm/advanced/\346\234\200\347\237\255\350\267\257\347\256\227\346\263\225.md" @@ -14,11 +14,15 @@ 时间复杂度分析: + $$ +\displaylines{ T(n) = O(E)*dk_Q + O(V)*em_Q +} $$ + $dk_Q$ means **Decrease Key**, we need to sort all edges once in the whole algo. $em_Q$ means Extract Min, for each vertex, we calculate the next shortest edge once. @@ -170,9 +174,6 @@ int main() { ``` - - - ### Examples * Currency Exchange diff --git "a/docs/algorithm/advanced/\346\240\221\347\212\266\346\225\260\347\273\204.md" "b/docs/algorithm/advanced/\346\240\221\347\212\266\346\225\260\347\273\204.md" index 469affb8e..930cce3cf 100644 --- "a/docs/algorithm/advanced/\346\240\221\347\212\266\346\225\260\347\273\204.md" +++ "b/docs/algorithm/advanced/\346\240\221\347\212\266\346\225\260\347\273\204.md" @@ -42,8 +42,11 @@ $O(N)$: build time complexity + $$ +\displaylines{ C[k] = sum(k)-sum(k-lowbit(k)) +} $$ @@ -215,7 +218,6 @@ int query(int i, int j) { ``` - * Examples * 最长上升子序列 diff --git "a/docs/algorithm/advanced/\347\272\277\346\256\265\346\240\221.md" "b/docs/algorithm/advanced/\347\272\277\346\256\265\346\240\221.md" index 0dbdcef59..5d737c2bf 100644 --- "a/docs/algorithm/advanced/\347\272\277\346\256\265\346\240\221.md" +++ "b/docs/algorithm/advanced/\347\272\277\346\256\265\346\240\221.md" @@ -26,12 +26,16 @@ struct node{ Not a complete tree, but nearly. + $$ +\displaylines{ 2*2^{ceil(log_2(n))}-1 \le 4n-1 +} $$ + so it is safe if we assign `[4 * maxn]` nodes, then we can use $2*i+1, 2*i+2$ instead of `node*` ### Operations diff --git "a/docs/algorithm/advanced/\347\272\277\346\256\265\346\240\2212.md" "b/docs/algorithm/advanced/\347\272\277\346\256\265\346\240\2212.md" index 0da62502e..729c80001 100644 --- "a/docs/algorithm/advanced/\347\272\277\346\256\265\346\240\2212.md" +++ "b/docs/algorithm/advanced/\347\272\277\346\256\265\346\240\2212.md" @@ -291,7 +291,6 @@ 保证边重合的情况,两边不都算。 - ```c++ #include #include @@ -419,9 +418,6 @@ ``` - - - #### 二维线段树 * Matrix diff --git "a/docs/algorithm/advanced/\347\272\277\346\256\265\346\240\221\346\200\273\347\273\223.md" "b/docs/algorithm/advanced/\347\272\277\346\256\265\346\240\221\346\200\273\347\273\223.md" index f61368589..b43a120b5 100644 --- "a/docs/algorithm/advanced/\347\272\277\346\256\265\346\240\221\346\200\273\347\273\223.md" +++ "b/docs/algorithm/advanced/\347\272\277\346\256\265\346\240\221\346\200\273\347\273\223.md" @@ -75,9 +75,6 @@ int main() { ``` - - - ### 动态线段树:区间最值替换 **替换**某个区间的最值为某个数。而非增加到某个数(见下)。也不是取当前值与目标值的最大值(无法实现)。 @@ -153,7 +150,6 @@ void modify(int rt, int l, int r, int v) { ``` - ###### LeetCode 699 Falling Squares ```c++ @@ -251,9 +247,6 @@ public: ``` - - - ### 动态线段树:区间加减 支持区间求和、求最值。 @@ -363,4 +356,3 @@ int main() { ``` - diff --git "a/docs/algorithm/advanced/\347\275\221\347\273\234\346\265\201.md" "b/docs/algorithm/advanced/\347\275\221\347\273\234\346\265\201.md" index f78ee03e8..05371622f 100644 --- "a/docs/algorithm/advanced/\347\275\221\347\273\234\346\265\201.md" +++ "b/docs/algorithm/advanced/\347\275\221\347\273\234\346\265\201.md" @@ -197,7 +197,6 @@ ``` - * Merge Vertex ![1543198763129](C:\Users\hawke\AppData\Roaming\Typora\typora-user-images\1543198763129.png) @@ -386,7 +385,6 @@ int main() { ``` - * Optimal Milking ```c++ diff --git "a/docs/algorithm/advanced/\347\275\221\347\273\234\346\265\2012.md" "b/docs/algorithm/advanced/\347\275\221\347\273\234\346\265\2012.md" index 88f9e0285..b824b5247 100644 --- "a/docs/algorithm/advanced/\347\275\221\347\273\234\346\265\2012.md" +++ "b/docs/algorithm/advanced/\347\275\221\347\273\234\346\265\2012.md" @@ -5,21 +5,17 @@ 把每一条有下界的边分为**必要边+不必要边。** - * Budget - ### 最小费用最大流 每条边有一个单位流量所需的费用,求所有最大流中费用最小的。 - * Farm Tour - ### 二部图最大匹配 左半部分无限边(1边也可以)连接对应的右半部分,超源点用1边连向所有左半部分,超汇点用1出边连接所有右半部分。调用最大流即可得到最大匹配数。 @@ -139,7 +135,6 @@ ``` - ### 最小割 最大流==最小割。 diff --git "a/docs/algorithm/advanced/\350\256\241\347\256\227\345\207\240\344\275\225.md" "b/docs/algorithm/advanced/\350\256\241\347\256\227\345\207\240\344\275\225.md" index d964f4e58..194f8c25e 100644 --- "a/docs/algorithm/advanced/\350\256\241\347\256\227\345\207\240\344\275\225.md" +++ "b/docs/algorithm/advanced/\350\256\241\347\256\227\345\207\240\344\275\225.md" @@ -66,7 +66,6 @@ int graham(vector& ps, vector& stk) { ``` - ##### Grandpa's Estate ```c++ @@ -260,7 +259,6 @@ int main() { ``` - ##### Most Distant Point from the Sea ```c++ @@ -445,7 +443,6 @@ int main() { ``` - ##### Pipe ```c++ diff --git a/docs/algorithm/algoanalysis/Approximation.md b/docs/algorithm/algoanalysis/Approximation.md index 196e0b5c4..4686b898a 100644 --- a/docs/algorithm/algoanalysis/Approximation.md +++ b/docs/algorithm/algoanalysis/Approximation.md @@ -3,7 +3,6 @@ 近似算法针对**组合优化问题**! - ### 最小顶点覆盖问题 贪心算法:任取一条边,将两个顶点加入V',并删去其关联的边,直到所有边都被删除。 @@ -13,7 +12,6 @@ > 顶点覆盖的判定问题是NPC的! - ### 最大团问题 & 最大独立集问题 这两个问题目前认为**不存在常数近似比的近似算法**。 \ No newline at end of file diff --git a/docs/algorithm/algoanalysis/NP.md b/docs/algorithm/algoanalysis/NP.md index 0d79eb0da..64551ae63 100644 --- a/docs/algorithm/algoanalysis/NP.md +++ b/docs/algorithm/algoanalysis/NP.md @@ -6,7 +6,6 @@ To prove a problem is NPC, we need to: * show it is NP-hard, by reducing from a known NP-hard problem (e.g., SAT, 3-SAT, ...). - ### Known NPC problems ![image-20220608155144578](NP.assets/image-20220608155144578.png) @@ -16,7 +15,6 @@ To prove a problem is NPC, we need to: Can be reduced from Subset-sum, and is a limited case of 0-1 knapsack. - ### Undirected Hamiltonian Cycle > https://www.ics.uci.edu/~goodrich/teach/cs162/hw/HW8Sols.pdf @@ -47,7 +45,6 @@ To prove a problem is NPC, we need to: ![image-20220608144438533](NP.assets/image-20220608144438533.png) - ### Strongly Independent Set > https://www.cse.iitd.ac.in/~amitk/SemI-2015/tut11.pdf @@ -71,9 +68,6 @@ The following is a version of the Independent Set problem. You are given a graph Conversely, let S be a strongly independent set in G0 . First observe that k > 1 (otherwise, the reduction is trivially correct). Now S cannot contain any of the new vertices ve (because any other vertex in G0 is reachable from ve by a path of length 2). Therefore, S contains vertices which correspond to those in G. Now check that these vertices form an independent set in S. - - - ### Minimum Sum of Squares > http://cmcstuff.esyr.org/vmkbotva-r15/5%20%D0%BA%D1%83%D1%80%D1%81/9%20%D0%A1%D0%B5%D0%BC%D0%B5%D1%81%D1%82%D1%80/%D0%A2%D0%B8%D0%B3%D1%80%D1%8B/%D0%A2%D0%B5%D0%BE%D1%80%D0%B8%D1%8F%20%D1%81%D0%BB%D0%BE%D0%B6%D0%BD%D0%BE%D1%81%D1%82%D0%B8%20%D0%BD%D0%B0%20%D0%B0%D0%BD%D0%B3%D0%BB%D0%B8%D0%B9%D1%81%D0%BA%D0%BE%D0%BC.pdf, 17 @@ -81,4 +75,3 @@ The following is a version of the Independent Set problem. You are given a graph ![image-20220608161307474](NP.assets/image-20220608161307474.png) - diff --git a/docs/algorithm/basic/DA01_Intro.md b/docs/algorithm/basic/DA01_Intro.md index 197123480..54fdf09df 100644 --- a/docs/algorithm/basic/DA01_Intro.md +++ b/docs/algorithm/basic/DA01_Intro.md @@ -72,41 +72,51 @@ * $O()$ expression + $$ +\displaylines{ \exist C,N_0 \gt 0 \ \ s.t. \ \forall n \ge N_0:\\ f(n) \le C \cdot g(n) \\ \Rightarrow f(n) \in O(g(n)) +} $$ + We should choose the **tightest** $g(n)$ . eg. $f(x) = n^2 + 2n$ is $O(n^2)$, but we can also say it's $O(n^3)$ or larger. * $\Omega()$ expression + $$ +\displaylines{ \exist C,N_0 \gt 0 \ \ s.t. \ \forall n \ge N_0:\\ f(n) \ge C \cdot g(n) \\ \Rightarrow f(n) \in \Omega(g(n)) +} $$ + Choose the tightest. * $\Theta()$ expression + $$ +\displaylines{ f(n) \in O(g(n)) \ and \ f(n) \in \Omega(g(n)) \\ \Rightarrow f(n) \in \Theta(g(n)) +} $$ - Best, Worst and Average Complexity analysis: For most Algorithms, the difference is only in the constants and coefficients. Trade-off between Time and Space. diff --git a/docs/algorithm/basic/DA02_LinearTable.md b/docs/algorithm/basic/DA02_LinearTable.md index f073c349d..b72055323 100644 --- a/docs/algorithm/basic/DA02_LinearTable.md +++ b/docs/algorithm/basic/DA02_LinearTable.md @@ -31,9 +31,6 @@ More space for less time. Link the head and tail. - - - # Exercise * Floyd Cycle detection (& Variations) @@ -95,12 +92,15 @@ Link the head and tail. (m奇数时均走m步,f第一圈不经过相遇点,m偶数时f走两圈,每圈m/2) + $$ +\displaylines{ 2t - t = km \\ 2t'-t' = (k+1)m \\ \therefore t'-t = m +} $$ @@ -108,15 +108,19 @@ $$ 设s入环后又走了x步,则: + $$ +\displaylines{ t = n + x \\ t = km \\ \therefore km = n +x \\ (k-1)m + (m-x) = n \\ +} $$ + 即,外部路径长度为当前位置走到入口点的距离加上k个环。 @@ -128,7 +132,6 @@ $$ * (更简单直白)先分别遍历两个链表,如果终点相同,则他们相交。记录他们的长度,再次遍历,先让长链表指针移动长度的差值次,再同步移动两个指针,相等处即交点。 - ### Others - dancing links algorithm (Knuth) diff --git a/docs/algorithm/basic/DA03_StackAndQueue.md b/docs/algorithm/basic/DA03_StackAndQueue.md index 4c1dc7d80..a9cbf55c6 100644 --- a/docs/algorithm/basic/DA03_StackAndQueue.md +++ b/docs/algorithm/basic/DA03_StackAndQueue.md @@ -17,9 +17,12 @@ * **性质**: + $$ +\displaylines{ C_0 = 1 \ \ and \ \ C_{n+1} = \sum_{i=0}^nC_iC_{n-i} \\ or\ \ C_{n+1} = \frac{2(2n+1)}{n+2} C_n +} $$ @@ -134,7 +137,6 @@ $$ ``` - ### Queue (FIFO) * Implement @@ -192,7 +194,6 @@ $$ * buffer - # Simulation * 2 stacks --> queue diff --git a/docs/algorithm/basic/DA04_String.md b/docs/algorithm/basic/DA04_String.md index caad8ea23..1d6c3d8b4 100644 --- a/docs/algorithm/basic/DA04_String.md +++ b/docs/algorithm/basic/DA04_String.md @@ -43,7 +43,6 @@ ``` - ### Pattern Matching * Classification @@ -162,7 +161,6 @@ | next2 | -1 | 0 | 0 | 0 | -1 | 1 | 0 | 0 | 3 | 0 | - ### Boyer-Moore 算法 实际上Ctrl+F,GNU grep使用的算法,预处理O(m),平均查找O(n/m),最坏O(n),NB! diff --git a/docs/algorithm/basic/DA05_BinaryTree.md b/docs/algorithm/basic/DA05_BinaryTree.md index 0c0c8ec25..bbb74b1c5 100644 --- a/docs/algorithm/basic/DA05_BinaryTree.md +++ b/docs/algorithm/basic/DA05_BinaryTree.md @@ -14,7 +14,9 @@ Yet another deduction of Catalan Number: + $$ +\displaylines{ f(0) = 1 \\ f(1) = 1 \\ f(2) = f(1)f(0) + f(0)f(1) = 2 \\ @@ -23,6 +25,7 @@ $$ f(n) = f(n-1)f(0) + f(n-2)f(1) + ... + f(1)f(n-2) + f(n-1)f(0) \\ the\ solution\ is \ f(n) = \frac{C_{2n}^n}{n+1} +} $$ @@ -82,13 +85,16 @@ $$ 归纳法证明: + $$ +\displaylines{ E_n = I_n + 2n \\ assume\ add \ a\ node\ of\ length= k \\ I_{n+1} = I_n + k \\ E_{n+1} = E_n -k+2(k+1) = E_n+k+2 \\ E_{n+1} = I_{n+1}+2(n+1) +} $$ @@ -100,19 +106,25 @@ $$ $N(N>0)$个节点的$K$叉树的空指针数: + $$ +\displaylines{ P=NK - (N-1) = N(K-1)+1 +} $$ * 实际上,任意二叉树$N_0 = N_2 + 1$ + $$ +\displaylines{ N = N_0 + N_1 + N_2 = E +1\\ E = N_1 + 2N_2 \\ \Rightarrow N_0 = N_2 + 1 +} $$ @@ -493,7 +505,9 @@ $$ 定理:**随机构造$n$个不同节点的二叉搜索树的平均深度为$O(log\ n)$,期望内部路径总和为$O(nlog\ n)$** + $$ +\displaylines{ D(N)\ is \ inner \ path \ summation.\\ D(N) = D(i) + D(N-1-i) + N-1 \\ D(N) = 2*\frac 1 N\sum_{i=0}^{N-1}D(i) + N-1 \\ @@ -502,19 +516,25 @@ $$ f(n) = f(n-1)+O(1/n) \\ f(n) \in \sum_{i=1}^nO(1/n) = O(log\ n) +} $$ + $f(n)$相当于平均高度,从而期望内部路径总长$D(N)=O(NlogN)$ **Harmonic Series:** + $$ +\displaylines{ \sum_{i=1}^{N}\frac 1 i \in O(logN) \\ this \ follows \ continuous \ condition: \\ \int \frac 1 xdx = lnx +} $$ + Another version of proof: ![img](https://i.stack.imgur.com/xHenH.png) @@ -603,11 +623,15 @@ $$ 用到了**错位相减法**求数列和。 + $$ +\displaylines{ \sum_{i=0}^{logn}2^i(logn - i) = \sum_{j=0}^{logn}n\frac j {2^j} \lt 2n +} $$ + 有趣的题目: ![1541493860686](DA05_BinaryTree.assets\1541493860686.png) diff --git a/docs/algorithm/basic/DA07_Graph.md b/docs/algorithm/basic/DA07_Graph.md index 88e4cf224..58dfe1698 100644 --- a/docs/algorithm/basic/DA07_Graph.md +++ b/docs/algorithm/basic/DA07_Graph.md @@ -2,10 +2,14 @@ ### Definition + $$ +\displaylines{ G = (V, E) +} $$ + We only considers **simple graphs** that have **No self-Connection, No parallel edge.** * Complete graph: contains all possible edges, $E = \frac {V(V-1)}{2}$ @@ -413,7 +417,6 @@ int main() { ``` - ### Examples * ウサギと桜 diff --git a/docs/algorithm/basic/DA08_InnerSorting.md b/docs/algorithm/basic/DA08_InnerSorting.md index d75a548ab..e4e67465e 100644 --- a/docs/algorithm/basic/DA08_InnerSorting.md +++ b/docs/algorithm/basic/DA08_InnerSorting.md @@ -102,7 +102,6 @@ Time2: $O(n) \sim O(n^2) \sim O(n^2)$ Space: $O(1)$ - #### Selection sort ```c++ @@ -128,7 +127,6 @@ Time: $O(n^2) \sim O(n^2) \sim O(n^2)$ (stably) Improvement is the **Heap sort**. Instead of using O(n) to find the smallest element, we can put the records in a heap and only use O(logn). - ### Shell sort (缩小增量排序) Based on Insert sort's good property when the sequence is short and almostly ordered. @@ -164,7 +162,6 @@ Space: $O(1)$ ​ 交换次数计算:(1+1+1)+(1+1)+(4) = 9 - ### Divide-and-conquer #### quick sort (by Hoare) @@ -221,17 +218,19 @@ When pivot is selected such that it always in nearly middle, the height of corre When the sequence is already ordered, it reaches the worst Time complexity of n^2. Analysis of average time complexity: (Similar to that of Random BST) + $$ +\displaylines{ T(n) = T(i) + T(n-i-1) + cn\\ T(n) = \frac 2 n \sum_{i=0}^{n-1} T(i) + cn \\ nT(n) - (n-1)T(n-1) = 2T(n-1) + cn \\ \frac {T(n)} {n+1} = \frac {T(n-1)} {n} + \frac c n \\ \frac {T(n)} {n+1} \sim O(logn) \\ T(n) \sim O(nlogn) +} $$ - * Variant: **Find the first k smallest elements, or Find the k-th smallest element.** They are the same question, and quicksort variant can give the best **Average Time Complexity**: $O( n )$ @@ -288,7 +287,6 @@ $$ ``` - #### merge sort quick sort focus on how to divide, merge sort focus on how to merge. @@ -358,7 +356,6 @@ MergeSort(array, count) ``` - ### Heap sort Advanced version of Selection sort. @@ -377,7 +374,6 @@ Time: $O(nlogn)$ (stably) Space: $O(1 )$ - ### Bin sort 需要对排序序列进行一定的假设限制。 @@ -604,11 +600,9 @@ void adjust(record arr[], int idx[], int n){ 关键在于adjust仅使用O(1)额外空间。 - ## Summary - **排序算法的下界分析:判定树。** 有n个记录,生成的判定树有n!个叶节点,树深为$O(lg(n!)) \sim O(nlogn)$。 diff --git a/docs/algorithm/basic/DA09_OuterSorting.md b/docs/algorithm/basic/DA09_OuterSorting.md index ceabb3a2f..d9410a2fc 100644 --- a/docs/algorithm/basic/DA09_OuterSorting.md +++ b/docs/algorithm/basic/DA09_OuterSorting.md @@ -62,7 +62,9 @@ void ReplacementSelection(elem *a, int n){ ![1543030801537](C:\Users\hawke\AppData\Roaming\Typora\typora-user-images\1543030801537.png) 内部节点树深度s,最底层外部节点个数`LowExt`(篮框),`LowExt`以外的节点数`offset`(红框,满完全二叉树)。则L[i]与对应的父节点B[p]的关系为: + $$ +\displaylines{ s = ceil(log_2n)-1\\ LowExt = 2(n-2^s)\\ offset = 2^{s+1}-1 \\ @@ -72,6 +74,7 @@ p = \left\{ (i-LowExt+n-1)/2, & i>LowExt \end{array} \right. +} $$ @@ -82,7 +85,6 @@ $$ 只需要`siftdown`根节点即可,每次与兄弟比较,更改父节点。 - #### 败者树 胜者树的变体,简化重构。 @@ -154,7 +156,6 @@ struct LoserTree{ ``` - ##### 复杂度分析: 初始化$O(k)$,每次操作$O(logk)$. @@ -164,4 +165,3 @@ struct LoserTree{ (naive需要$O(nk)$) - diff --git a/docs/algorithm/basic/DA10_Search.md b/docs/algorithm/basic/DA10_Search.md index 68f47b96b..459597a5f 100644 --- a/docs/algorithm/basic/DA10_Search.md +++ b/docs/algorithm/basic/DA10_Search.md @@ -18,16 +18,23 @@ #### 顺序检索 设置下标0处为哨岗,从尾部检索到此处仍未发现目标元素,意味着检索失败。 + $$ +\displaylines{ \frac {n+1} 2 < ASL < n+1 +} $$ + * 检索成功: 假设 $p_i$ is $\frac 1 n$: + $$ +\displaylines{ \sum_{i=1}^n\frac 1 n(n-i+1) = \frac {n+1} 2 +} $$ @@ -36,11 +43,15 @@ $$ #### 二分检索 + $$ +\displaylines{ ASL = \frac 1 n (\sum_{i=1}^{lg\ n}i\cdot 2^{i-1}) \\ \sim O(lg\ n) +} $$ + * Need Sorting first * Success or fail: $\sim O(lg\ n)$ @@ -57,10 +68,13 @@ $$ 分块有序,先检索在哪一块中(二分检索),后在块内检索(顺序检索)。 ![1543372011178](C:\Users\hawke\AppData\Roaming\Typora\typora-user-images\1543372011178.png) + $$ +\displaylines{ ASL_{succ} = ASL_b + ASL_s \\ \approx lg\ b + s/2 \\ \approx lg(\frac n s + 1) + s/2 +} $$ @@ -116,12 +130,16 @@ $$ * 基数转换法 + $$ +\displaylines{ x_{(a)} \rightarrow x_{(b)} = y_{(a)} +} $$ + 其中a,b为两个互素的基数,一般选择b大于a。 选取 y 的几位作为address。 @@ -198,43 +216,48 @@ $$ 下一条记录被放到7中的概率:9/13 (0~7,12) + $$ +\displaylines{ ASL_{succ} = \frac 1 {11} (1+5+1+2+2+1+1+1+1+2+3) = 20/11 \\ ASL_{fail} = \frac 1 {13} (8+7+6+5+4+3+2+1+1+1+2+1+11) = 4 +} $$ - - - - - - ​ 改进:`p(K, i)=i*c`(仍然会纠缠) ​ * 二次探查 + $$ +\displaylines{ p(K, 2i-1) = i^2 \\ p(K, 2i) = -i^2 +} $$ + 基本消除聚集。 * 伪随机数序列探查 + $$ +\displaylines{ p(K, i) = perm[i-1] +} $$ + perm为[1, M-1]的伪随机序列。 **基本消除聚集。** @@ -251,10 +274,13 @@ $$ $h2(key)$必须与M互素。 + $$ +\displaylines{ d = h_1(key) \\ d_i = (d + p(key, i)) \% M \\ p(key, i) = i*h_2(key) +} $$ @@ -332,26 +358,23 @@ $$ ``` - - - ### 效率分析 ![1543980144853](C:\Users\hawke\AppData\Roaming\Typora\typora-user-images\1543980144853.png) - 经验表明,负载因子alpha小于0.5时,大部分操作预期代价均小于2,远比二分检索优秀,但是alpha大于0.5时性能急剧下降。 插入与删除频繁的散列表效率会降低(负载因子增大,同义词表变长,墓碑变多),可以通过定期重新散列来解决(清除墓碑,把访问最频繁的记录向前移动到基地址) - - - #### Exercises ![1544104068419](C:\Users\hawke\AppData\Roaming\Typora\typora-user-images\1544104068419.png) + $$ +\displaylines{ ASL = 0.6*1 + 0.4*(0.6*2+0.4*(0.6*3+...)) = (1-a)\sum_i^{N}(i*a^i) +} $$ + diff --git a/docs/algorithm/basic/DA11_Index.md b/docs/algorithm/basic/DA11_Index.md index 704e83dc6..5065b6903 100644 --- a/docs/algorithm/basic/DA11_Index.md +++ b/docs/algorithm/basic/DA11_Index.md @@ -25,7 +25,6 @@ 一个主文件可能有多个相关索引文件,每个索引文件支持一个索引字段。 - ### 线性检索 按照索引码值的顺序进行排序的文件。 @@ -59,7 +58,6 @@ > 4096/8 (二级索引个数) * 4096/8 (每个二级索引指向一个存一级索引的块,每个块中一级索引的个数) * 4096/68 (每个一级索引指向一个块,每个块存放记录的个数) = 2^18 * 60 = 15M - ### 静态检索(Deprecated) 文件创建完成时索引就不能再被修改了。 @@ -67,7 +65,6 @@ 几乎没有插入/删除,或者允许定期重新组织结构的话,效率还是很高的。 - ### 倒排检索 由属性值来确定记录的位置,称为倒排检索(基于属性/基于正文)。 @@ -105,7 +102,6 @@ 缺点:支持的检索类型有限,检索词有限,空间代价极高。 - ### 动态检索 动态更新删除,并保持最佳检索性能。 @@ -202,7 +198,6 @@ ``` - * 非叶节点 把此关键码与后继交换位置,成为叶节点再删除。 @@ -213,33 +208,42 @@ 证明:设有l个空指针,n个节点,第i节点有x_i个关键码,x总和即关键码总数N,则边的总数m为: + $$ +\displaylines{ m = l + m' = l + n - 1 = \sum_{i=1}^n(x_i + 1) = N + n +} $$ - - - - 设树**m阶k层**(根节点在第0层),则通过另一种方法计算最后一层的节点数, **最大高度公式:**(也是最大检索次数) + $$ +\displaylines{ N+1 \ge 2*\lceil \frac m 2 \rceil^{k-1} \\ k \le 1 + log_{\lceil m/2 \rceil}(\frac {N+1} 2) \\ +} $$ + 最小高度公式: + $$ +\displaylines{ N+1 \le m^k \\ k\ge log_m(N+1) +} $$ 设p为内部节点数,s为每插入一个关键码的平均分裂节点数: + $$ +\displaylines{ s = \frac{p-1}{N-1} \le \frac 1 {\lceil m/2 \rceil - 1} +} $$ @@ -256,8 +260,6 @@ $$ > 若考虑叶节点也是一层,则最高12层。 - - #### B+树 B树变体,**只在叶节点存储信息。** @@ -311,7 +313,6 @@ MySQL索引采用的就是B+树。 * 兄弟也借不了,和兄弟合并。删除一个父节点关键码,递归向上检查父节点关键码数量。 - ### 红黑树 #### 定义 @@ -339,21 +340,17 @@ MySQL索引采用的就是B+树。 设阶为k,树高为h。 + $$ +\displaylines{ h \le 2k+1 \\ n \ge 2^k - 1 \\ \Rightarrow h\le 2log_2(n+1)+1 +} $$ - - - - - - - #### 红黑树之插入 ```bash @@ -494,7 +491,6 @@ $$ 否则,由于此时G变为红色,需要**递归向上**继续进行红红检查。 - #### 红黑树之删除 ```bash @@ -740,7 +736,6 @@ $$ ``` - #### 红黑树性能 平均和**最差**检索$O(lgn)$。 diff --git a/docs/algorithm/basic/DA12_Advanced.md b/docs/algorithm/basic/DA12_Advanced.md index 166169859..6df227e53 100644 --- a/docs/algorithm/basic/DA12_Advanced.md +++ b/docs/algorithm/basic/DA12_Advanced.md @@ -8,11 +8,14 @@ 下标计算 : + $$ +\displaylines{ loc(A[j_0, ..., j_{n-1}]) = loc(A[0,...,0])\\ + size*[\sum_{i=0}^{n-2}(j_i\prod_{k=i+1}^{n-1}d_k)+j_{n-1}] +} $$ @@ -24,7 +27,6 @@ $$ * 稀疏矩阵:三元组表,十字链表 - ### Generalized Lists (广义表,Multi-list) 线性表的拓展,线性表内的元素均为同一类型。 @@ -68,7 +70,6 @@ TAIL: 广义表中**第一个元素以外的元素构成的(!)广义表(!)**。 ``` - ### 字典树 Trie * 英文字母Trie树 @@ -80,7 +81,6 @@ TAIL: 广义表中**第一个元素以外的元素构成的(!)广义表(!)**。 * 二叉Trie树(PAT-Tree, Patricia) - ### 二叉排序树变体 BST Variants #### 最佳BST @@ -96,28 +96,25 @@ TAIL: 广义表中**第一个元素以外的元素构成的(!)广义表(!)**。 **最佳BST**:根据用户历史访问频率,可以计算ASL最小的BST。 - ##### 构造最佳BST的方法 * 节点检索等概率 p为内部节点,共n个;q为外部节点,共n+1个。 + $$ +\displaylines{ \frac {p_i} W = \frac {q_j} W = \frac 1 {2n+1} \\ ASL(n) = \frac 1 {2n+1} (\sum_{i=1}^n(H(p_i)+1)+\sum_{j=0}^nH(q_j)) \\ = \frac 1 {2n+1} (I+n+E)\\ = \frac {2I+3n} {2n+1} +} $$ - - - - - ​ 故在n已知时,构造I最短的BST即可,即类似完全二叉树的形状。 * **节点检索不等概率** @@ -135,11 +132,9 @@ $$ `C(i, j) = W(i, j) + min{C(i, k-1) + C(k, j)}, for k in [i, j]` - ![图片1](DA12_Advanced.assets\图片1.png) - #### 平衡BST(AVL) ##### 平衡因子 @@ -239,7 +234,6 @@ $ASL = O(lg n)$. * RL:A的R的L导致失衡,`bf(A)=2` - ##### AVL删除 ```bash @@ -409,7 +403,6 @@ $ASL = O(lg n)$. ``` - #### 伸展树(Splay) 动态自组织的数据结构,检索频繁的记录离根节点更近。 @@ -501,6 +494,3 @@ Splay规则保证访问代价较低,不保证平衡。 * m次访问操作的总代价:$O(mlgn)$,**每次操作平均代价$O(lgn)$**,保证多个操作平均高效。 - - - diff --git a/docs/algorithm/review/ACM_IO.md b/docs/algorithm/review/ACM_IO.md index 8707f7964..84ec514e3 100644 --- a/docs/algorithm/review/ACM_IO.md +++ b/docs/algorithm/review/ACM_IO.md @@ -1,7 +1,6 @@ ### ACM style I/O - ### scanf/printf Not recommended to use... @@ -37,9 +36,6 @@ int main() { ``` - - - ### iostream Acceleration: @@ -56,7 +52,6 @@ int main() { ``` - `cin >> x` are separated by spaces or line breaks. types are auto-casted. ```cpp @@ -90,7 +85,6 @@ int main() { ``` - If you want to get **a whole input line (may contain spaces)** to string: ```cpp @@ -106,7 +100,6 @@ int main() { ``` - `cout` precision: ```cpp @@ -126,4 +119,3 @@ int main() { ``` - diff --git a/docs/algorithm/review/Python.md b/docs/algorithm/review/Python.md index f9c18598e..92a39bb00 100644 --- a/docs/algorithm/review/Python.md +++ b/docs/algorithm/review/Python.md @@ -35,7 +35,6 @@ print(x, end='') # do not append \n ``` - ### list ```python @@ -66,7 +65,6 @@ l = [x in l if x != val] ``` - * remove in for loop: Not well supported. Use list comprehension or filter. @@ -88,7 +86,6 @@ s.discard(x) # pass if not found. ``` - ### dict ```python @@ -109,9 +106,6 @@ if k in d: ``` - - - ### tricks * automatic memorizing recursion: diff --git a/docs/algorithm/review/Trie.md b/docs/algorithm/review/Trie.md index 447000354..66f93a00c 100644 --- a/docs/algorithm/review/Trie.md +++ b/docs/algorithm/review/Trie.md @@ -77,7 +77,6 @@ struct trie { ``` - # Trie图 AC自动机(Trie树上的KMP)。输入一个词典,用于检查任意字符串是否包含词典中的单词。 @@ -93,7 +92,6 @@ AC自动机(Trie树上的KMP)。输入一个词典,用于检查任意字 Trie图可以实现$O(\sum_i^N|P_i| +L)$的复杂度。 - ```cpp const int letters = 26; diff --git "a/docs/algorithm/review/old/\345\212\250\346\200\201\350\247\204\345\210\222\351\242\230\347\233\256.md" "b/docs/algorithm/review/old/\345\212\250\346\200\201\350\247\204\345\210\222\351\242\230\347\233\256.md" index 73a451896..4207db681 100644 --- "a/docs/algorithm/review/old/\345\212\250\346\200\201\350\247\204\345\210\222\351\242\230\347\233\256.md" +++ "b/docs/algorithm/review/old/\345\212\250\346\200\201\350\247\204\345\210\222\351\242\230\347\233\256.md" @@ -97,7 +97,6 @@ public: ``` - $O(lg N)$ exponentiation by sequaring (矩阵快速幂) ```python @@ -123,9 +122,6 @@ def knightDialer(self, N): ``` - - - ###### Remove Boxes (leetcode 546) 输入一维数组。简单的二维端点DP缺失信息,故拓展维度到三维DP,记录区间[i, j]以及i**左侧(区间外)**与i同色的方块数k。k值并非固定,而在消除方块的过程中会变化,所以可以作为一个维度。 @@ -158,7 +154,6 @@ public: ``` - ###### Burst Balloons (leetcode 312) 输入一维数组。`dp[i][j]`代表`[i, j]`气球爆炸到只剩i与j时的最高得分。 @@ -218,7 +213,6 @@ public: ``` - ###### Stickers to Spell Word (691) minimum string coverage problem, the following is a slow silly version. Converting string to vector\ caused the map to be very slow. 状态压缩DP。 @@ -276,7 +270,6 @@ public: ``` - ###### Partition Equal Subset Sum 416 判断一维数组是否能被划分为两个子集,使两个子集各自的和相等。只是判断,故只需要二维动归。 @@ -372,7 +365,6 @@ public: ``` - ###### Ones and Zeros 474 some what like a knapsack problem, but i failed to figure it out again. @@ -410,7 +402,6 @@ public: ``` - ###### Non-negative integers without Consecutive Ones 600 ```c++ @@ -446,7 +437,6 @@ public: ``` - ###### Running 贝茜的晨练计划 一言难尽的转移方程,目前还是超过了我的能力啊。。。 @@ -484,7 +474,6 @@ int main() { ``` - ###### Longest Palindromic SubSequence 516 子问题虽然看上去很显然,但是递推公式不好想,总之又跪了。 @@ -520,7 +509,6 @@ public: ``` - ###### Nearby cows DP in a tree. @@ -577,7 +565,6 @@ int main() { ``` - ###### Tallest BillBoard 956 与【是否存在和为某个值的子集】类似,但思路很不同,相当于是找【是否存在两个和为某个值的子集,只需求这个最大值】。这样题目就复杂了起来。 @@ -617,7 +604,6 @@ public: ``` - ###### Delete to make sorted 960 Clear! @@ -653,7 +639,6 @@ public: ``` - ###### Distinct SubSequences 115 find all subseqs equal to `t` in `s`. SIMPLE ! @@ -682,7 +667,6 @@ public: ``` - ###### Distince SubSequences II 940 dp[i] means distinct subseqs in the first i characters. Transfer formula is incredible. @@ -714,7 +698,6 @@ public: ``` - ###### Length of Longest Fibo Subsequence 873 map accelerated DP. 用Map查找唯一的特定值,而不是循环检验,始终是降低复杂度的重要技巧。 @@ -746,7 +729,6 @@ public: ``` - ###### Coin Change 322 Infinite knapsack. Very Orthodox and Effective DP Problem! @@ -772,7 +754,6 @@ public: ``` - ###### Count bits 338 Interesting DP formula, just for fun! diff --git "a/docs/algorithm/review/old/\345\233\276\350\256\272.md" "b/docs/algorithm/review/old/\345\233\276\350\256\272.md" index 9de201df6..258135629 100644 --- "a/docs/algorithm/review/old/\345\233\276\350\256\272.md" +++ "b/docs/algorithm/review/old/\345\233\276\350\256\272.md" @@ -106,7 +106,6 @@ int main() { ``` - ### Full Tank ? 太难了,本质DP,Dijkstra可以操作二维数组。 @@ -176,7 +175,6 @@ int main() { ``` - ### 道路 类似上题。 @@ -255,7 +253,6 @@ int main() { ``` - ### Window Pains Topo sort to find Directed Loops. **有向图判圈,就用拓扑排序!**此外此题如何构图也比较困难。 diff --git "a/docs/algorithm/review/old/\345\244\215\346\235\202\345\272\246.md" "b/docs/algorithm/review/old/\345\244\215\346\235\202\345\272\246.md" index 87d595846..fb4e65961 100644 --- "a/docs/algorithm/review/old/\345\244\215\346\235\202\345\272\246.md" +++ "b/docs/algorithm/review/old/\345\244\215\346\235\202\345\272\246.md" @@ -192,9 +192,6 @@ ``` - - - ### Interval Scheduling Maximization Problem **given a set of intervals, find the maximum numbers of intervals that are non-overlapping.** @@ -240,8 +237,6 @@ ``` - - #### Variants * GISDP: Grouped Interval Scheduling decision problem @@ -252,7 +247,6 @@ * more than 2 intervals: NP-hard. - ### Monotonic Queue 单调队列,push元素时先把队尾小于x的元素pop掉,保证队首始终为最大元素。适合于滑动区间取最值问题。 @@ -296,7 +290,6 @@ $O(1)$ for pop() and **getmax()** ! ( but in worst cases $O( n)$ for push(). ) ``` - ### Maximum & Minimum Integer Sequence **Greedy**. But the comparator is hard to come about. @@ -343,9 +336,6 @@ public: ``` - - - ### Palindrome Manacher is the golden key. @@ -379,7 +369,6 @@ public: ``` - ### Cumulative Sum **子序列(Subarray, continuous)求和**问题,枚举子序列O(n^2),每个子序列的计算O(n),Naive算法O(n^3)。 @@ -409,8 +398,6 @@ Cumsum预处理O(n),枚举子序列O(n^2),每个子序列的计算O(1),总 ``` - - ### O(1) Space Cults * find the unique number @@ -445,9 +432,6 @@ Cumsum预处理O(n),枚举子序列O(n^2),每个子序列的计算O(1),总 ``` - - - ### Range Maximum * Segment tree @@ -463,7 +447,6 @@ Cumsum预处理O(n),枚举子序列O(n^2),每个子序列的计算O(1),总 不支持更新,预处理O(nlgn),区间查询O(1) - ###### Longest Valid Parenthesis substring 32 DP is complicated, use stack and think reversely. @@ -498,7 +481,6 @@ public: ``` - ###### 排序的代价 求通过交换任意两个数字(代价为两个数字之和)使得数组有序所要花费的最小代价。 diff --git "a/docs/algorithm/review/old/\345\255\227\347\254\246\344\270\262.md" "b/docs/algorithm/review/old/\345\255\227\347\254\246\344\270\262.md" index cd4609f62..e4635d5cb 100644 --- "a/docs/algorithm/review/old/\345\255\227\347\254\246\344\270\262.md" +++ "b/docs/algorithm/review/old/\345\255\227\347\254\246\344\270\262.md" @@ -81,8 +81,6 @@ ``` - - ### 最小重复子串 判断是否存在最小重复子串。 @@ -184,7 +182,6 @@ * Suffix Array + Binary Search,$O(lgL*N^2)$ - ### 最长公共子序列 求2个字符串的最长公共子序列。 @@ -192,13 +189,11 @@ * DP - ### 最长上升子序列 * DP - ### Distinct Subsequences 求一个字符串的Unique的子序列的个数。 diff --git a/docs/algorithm/review/problem_series/best_time_to_buy_and_sell_stock.md b/docs/algorithm/review/problem_series/best_time_to_buy_and_sell_stock.md index 0c8f2a893..73ea1e08e 100644 --- a/docs/algorithm/review/problem_series/best_time_to_buy_and_sell_stock.md +++ b/docs/algorithm/review/problem_series/best_time_to_buy_and_sell_stock.md @@ -5,10 +5,13 @@ 只允许完成一笔交易(买一次,卖一次)并且一天只能完成一次买或者卖,求最大利益。 贪心法,求最低点与最高点相减即可。 + $$ +\displaylines{ \text{profit}[i] = \max(\text{profit}[i-1], \text{prices}[i]-\min_{1\le j\le i}\{\text{prices}[j]\}) \\ \text{profit}[1] = 0 \\ \text{ans} = \text{profit}[n] +} $$ @@ -17,10 +20,13 @@ $$ 允许完成多笔交易,但同时只能参与一笔交易(买入前必须全部卖出)。 贪心法,只要价格升高就卖出。 + $$ +\displaylines{ \text{profit}[i] = \text{profit}[i-1] + \max\{0, \text{prices}[i] - \text{prices}[i-1]\}\\ \text{profit}[1] = 0 \\ \text{ans} = \text{profit}[n] +} $$ @@ -31,7 +37,6 @@ $$ 遍历分界点,调用两次问题Ⅰ。 - #### [买卖股票的最佳时机Ⅳ](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/) 最多完成K笔交易。 @@ -39,5 +44,4 @@ $$ 动态规划。 - ![image-20210705130203572](best_time_to_buy_and_sell_stock.assets/image-20210705130203572.png) \ No newline at end of file diff --git a/docs/algorithm/review/problem_series/digit_simulation.md b/docs/algorithm/review/problem_series/digit_simulation.md index d4ba339d5..79ce769d9 100644 --- a/docs/algorithm/review/problem_series/digit_simulation.md +++ b/docs/algorithm/review/problem_series/digit_simulation.md @@ -21,7 +21,6 @@ public: ``` - ### [整数序列中第N位数字](https://leetcode-cn.com/problems/nth-digit/) 在无限的整数序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...中找到第 `n` 位数字。 diff --git a/docs/algorithm/review/problem_series/jump_game.md b/docs/algorithm/review/problem_series/jump_game.md index 6961781c8..d7529fea0 100644 --- a/docs/algorithm/review/problem_series/jump_game.md +++ b/docs/algorithm/review/problem_series/jump_game.md @@ -1,5 +1,4 @@ #### [jump game](https://leetcode.com/problems/jump-game/) - #### [jump game 2](https://leetcode.com/problems/jump-game-ii/) \ No newline at end of file diff --git a/docs/algorithm/review/problem_series/median_of_data_stream.md b/docs/algorithm/review/problem_series/median_of_data_stream.md index 2c158df08..3676492c0 100644 --- a/docs/algorithm/review/problem_series/median_of_data_stream.md +++ b/docs/algorithm/review/problem_series/median_of_data_stream.md @@ -46,7 +46,6 @@ public: ``` - #### multiset维护中点迭代器 `multiset`本身就是红黑树,具有$O(\log N)$的插入耗时,关键在于如何实现$O(1)$的查询耗时。 @@ -81,4 +80,3 @@ public: ``` - diff --git "a/docs/algorithm/review/problem_series/n\344\270\252\351\252\260\345\255\220\346\212\225\345\207\272x\347\232\204\346\246\202\347\216\207.md" "b/docs/algorithm/review/problem_series/n\344\270\252\351\252\260\345\255\220\346\212\225\345\207\272x\347\232\204\346\246\202\347\216\207.md" index 2de94ea75..28a1115b8 100644 --- "a/docs/algorithm/review/problem_series/n\344\270\252\351\252\260\345\255\220\346\212\225\345\207\272x\347\232\204\346\246\202\347\216\207.md" +++ "b/docs/algorithm/review/problem_series/n\344\270\252\351\252\260\345\255\220\346\212\225\345\207\272x\347\232\204\346\246\202\347\216\207.md" @@ -27,9 +27,13 @@ public: 数学公式: 出现$k$的概率为$x^k$的系数。 + $$ +\displaylines{ (x+x^2+x^3+x^4+x^5+x^6)^n / 6^n +} $$ + 可以通过扩展二项式定理展开: ![](https://wikimedia.org/api/rest_v1/media/math/render/svg/7e4dd69e04f849cc627775308fffd170e9472024) diff --git a/docs/algorithm/review/problem_series/palindrome.md b/docs/algorithm/review/problem_series/palindrome.md index 04a114424..56cec33c4 100644 --- a/docs/algorithm/review/problem_series/palindrome.md +++ b/docs/algorithm/review/problem_series/palindrome.md @@ -50,7 +50,6 @@ public: ``` - ### [回文子串数量](https://leetcode-cn.com/problems/palindromic-substrings/) 计算字符串中有多少个回文子串。 @@ -78,7 +77,6 @@ class Solution(object): ``` - ### [最长回文子序列](https://leetcode-cn.com/problems/longest-palindromic-subsequence/) 计算这个字符串中最长的回文子序列的长度(Subsequence,可以不连续)。 @@ -115,6 +113,5 @@ public: ``` - ### [不同回文子序列的数量](https://leetcode-cn.com/problems/count-different-palindromic-subsequences/) diff --git a/docs/algorithm/review/problem_series/search_2d_matrix.md b/docs/algorithm/review/problem_series/search_2d_matrix.md index a38c7f70f..4cdd9baf8 100644 --- a/docs/algorithm/review/problem_series/search_2d_matrix.md +++ b/docs/algorithm/review/problem_series/search_2d_matrix.md @@ -16,7 +16,6 @@ both row-col and col-row binary search for 13 will fail! ``` - 奇妙遍历法,从右上角开始。 ```cpp diff --git "a/docs/algorithm/review/problem_series/\343\200\220math\343\200\221joseph_loop.md" "b/docs/algorithm/review/problem_series/\343\200\220math\343\200\221joseph_loop.md" index a3e8a3405..967c8d09f 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220math\343\200\221joseph_loop.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220math\343\200\221joseph_loop.md" @@ -5,10 +5,14 @@ 并不用模拟,是有递推公式的。 $f(n, m)$ 代表此问题最后剩下的人的编号。 + $$ +\displaylines{ f(n, m) = f(n-1, m) + m \mod n +} $$ + ```cpp class Solution { public: @@ -36,7 +40,6 @@ public: ``` - ### [消除游戏](https://leetcode-cn.com/problems/elimination-game/) > 列表 arr 由在范围 [1, n] 中的所有整数组成,并按严格递增排序。请你对 arr 应用下述算法: diff --git "a/docs/algorithm/review/problem_series/\343\200\220toposort\343\200\221\343\200\220\345\237\272\347\216\257\346\240\221\343\200\221\345\217\202\344\270\216\344\274\232\350\256\256\347\232\204\346\234\200\345\244\232\345\221\230\345\267\245\346\225\260.md" "b/docs/algorithm/review/problem_series/\343\200\220toposort\343\200\221\343\200\220\345\237\272\347\216\257\346\240\221\343\200\221\345\217\202\344\270\216\344\274\232\350\256\256\347\232\204\346\234\200\345\244\232\345\221\230\345\267\245\346\225\260.md" index 863fadb0d..bd670db6d 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220toposort\343\200\221\343\200\220\345\237\272\347\216\257\346\240\221\343\200\221\345\217\202\344\270\216\344\274\232\350\256\256\347\232\204\346\234\200\345\244\232\345\221\230\345\267\245\346\225\260.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220toposort\343\200\221\343\200\220\345\237\272\347\216\257\346\240\221\343\200\221\345\217\202\344\270\216\344\274\232\350\256\256\347\232\204\346\234\200\345\244\232\345\221\230\345\267\245\346\225\260.md" @@ -79,7 +79,6 @@ public: ``` - ### 拓展 **基环树/环套树(pseudo-tree)**:**具有N个节点,N条边的连通图。**若不连通,则成为**基环树森林(pseudo-forest)**。 @@ -176,4 +175,3 @@ public: ``` - diff --git "a/docs/algorithm/review/problem_series/\343\200\220\344\272\214\345\210\206\343\200\221\344\276\233\346\232\226\345\231\250\345\215\212\345\276\204.md" "b/docs/algorithm/review/problem_series/\343\200\220\344\272\214\345\210\206\343\200\221\344\276\233\346\232\226\345\231\250\345\215\212\345\276\204.md" index cc38d3719..74c453f61 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\344\272\214\345\210\206\343\200\221\344\276\233\346\232\226\345\231\250\345\215\212\345\276\204.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\344\272\214\345\210\206\343\200\221\344\276\233\346\232\226\345\231\250\345\215\212\345\276\204.md" @@ -1,7 +1,6 @@ ## [供暖器](https://leetcode-cn.com/problems/heaters/) - 冬季已经来临。 你的任务是设计一个有固定加热半径的供暖器向所有房屋供暖。 在加热器的加热半径范围内的每个房屋都可以获得供暖。 @@ -11,7 +10,6 @@ 说明:所有供暖器都遵循你的半径标准,加热的半径也一样。 - ### 二分搜索半径 最开始的想法,能否覆盖随半径是单调的,但这样在每次循环中仍需要搜索下一个没被覆盖的房子,所以最终时间复杂度是$O(n\log^2n)$。 @@ -48,9 +46,6 @@ public: ``` - - - ### 贪心,记录每个房子的最近供暖器 更直接的做法,直接遍历房子,同时记录最近的供暖器即可,时间复杂度$O(n\log n)$(排序) diff --git "a/docs/algorithm/review/problem_series/\343\200\220\344\275\215\350\277\220\347\256\227\343\200\221\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260\344\270\272\344\270\200\347\232\204\346\225\260\345\255\227.md" "b/docs/algorithm/review/problem_series/\343\200\220\344\275\215\350\277\220\347\256\227\343\200\221\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260\344\270\272\344\270\200\347\232\204\346\225\260\345\255\227.md" index 79eb3b601..f3d0dc817 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\344\275\215\350\277\220\347\256\227\343\200\221\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260\344\270\272\344\270\200\347\232\204\346\225\260\345\255\227.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\344\275\215\350\277\220\347\256\227\343\200\221\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260\344\270\272\344\270\200\347\232\204\346\225\260\345\255\227.md" @@ -7,9 +7,6 @@ 全部**异或**一遍即可。 - - - ### [有两个数字只出现了一次](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/) 其余数字都出现了两次,找到这个数,要求$O(1)$空间复杂度。 @@ -34,7 +31,6 @@ public: ``` - ### [有一个数字只出现了一次,其余数字都出现了三次](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof/) 要求$O(1)$空间复杂度。 @@ -77,9 +73,6 @@ public: ``` - - - ### 有一个数字只出现了一次,其余数字都出现了m次 要求$O(1)$空间复杂度。 diff --git "a/docs/algorithm/review/problem_series/\343\200\220\345\212\250\350\247\204\343\200\221\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\345\222\214\343\200\201\347\247\257.md" "b/docs/algorithm/review/problem_series/\343\200\220\345\212\250\350\247\204\343\200\221\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\345\222\214\343\200\201\347\247\257.md" index 5a5668f4c..6496c84fd 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\345\212\250\350\247\204\343\200\221\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\345\222\214\343\200\201\347\247\257.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\345\212\250\350\247\204\343\200\221\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\345\222\214\343\200\201\347\247\257.md" @@ -20,7 +20,6 @@ public: ``` - ## [最大子矩阵](https://leetcode-cn.com/problems/max-submatrix-lcci/) > 给定一个正整数、负整数和 0 组成的 N × M 矩阵,编写代码找出元素总和最大的子矩阵。 @@ -73,9 +72,6 @@ public: ``` - - - ## [乘积最大子数组](https://leetcode-cn.com/problems/maximum-product-subarray/) > 给你一个整数数组 nums ,请你找出数组中乘积最大的非空连续子数组(该子数组中至少包含一个数字),并返回该子数组所对应的乘积。 diff --git "a/docs/algorithm/review/problem_series/\343\200\220\345\212\250\350\247\204\343\200\221\350\247\243\345\206\263\346\231\272\345\212\233\351\227\256\351\242\230.md" "b/docs/algorithm/review/problem_series/\343\200\220\345\212\250\350\247\204\343\200\221\350\247\243\345\206\263\346\231\272\345\212\233\351\227\256\351\242\230.md" index 4fbe2cacb..123a181ad 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\345\212\250\350\247\204\343\200\221\350\247\243\345\206\263\346\231\272\345\212\233\351\227\256\351\242\230.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\345\212\250\350\247\204\343\200\221\350\247\243\345\206\263\346\231\272\345\212\233\351\227\256\351\242\230.md" @@ -34,10 +34,14 @@ public: ### 倒序DP $f(i)$为从第$i$题开始做的最高得分。由于用到之后的信息,需要倒序计算。 + $$ +\displaylines{ f(i) = \max\{f(i+1), \text{points}(i)+f(i+1+\text{brainpower}(i))\} +} $$ + ```cpp class Solution { public: @@ -53,7 +57,6 @@ public: ``` - ### 正序DP $f(i)$为前$i$题的最高得分。每次循环不只更新当前下标,还要更新未来的下标。 diff --git "a/docs/algorithm/review/problem_series/\343\200\220\345\212\250\350\247\204\343\200\221\351\200\206\345\272\217\345\257\271\344\270\272k\347\232\204\346\216\222\345\210\227\344\270\252\346\225\260.md" "b/docs/algorithm/review/problem_series/\343\200\220\345\212\250\350\247\204\343\200\221\351\200\206\345\272\217\345\257\271\344\270\272k\347\232\204\346\216\222\345\210\227\344\270\252\346\225\260.md" index a75c32ea0..4e8ac97c5 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\345\212\250\350\247\204\343\200\221\351\200\206\345\272\217\345\257\271\344\270\272k\347\232\204\346\216\222\345\210\227\344\270\252\346\225\260.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\345\212\250\350\247\204\343\200\221\351\200\206\345\272\217\345\257\271\344\270\272k\347\232\204\346\216\222\345\210\227\344\270\252\346\225\260.md" @@ -1,32 +1,47 @@ ### [k inverse pairs array](https://leetcode-cn.com/problems/k-inverse-pairs-array/) - > 给出两个整数 `n` 和 `k`,找出所有包含从 `1` 到 `n` 的数字,且恰好拥有 `k` 个逆序对的不同的数组的个数。 令$f(i, j)$代表前$i$个数组成的序列中含有$j$个逆序对的个数。 假设我们知道$f(i-1, *)$, 考虑将$i$插入到$k=0 \rightarrow i-1$的位置处**新**得到的逆序对数量为$i-1-k$,从而: + $$ +\displaylines{ f(i, j) = \sum_{k=0}^{i-1}f(i-1, j-(i-1-k))=\sum_{k=0}^{i-1}f(i-1, j-k) +} $$ + 展开可发现: + $$ +\displaylines{ \begin{align} f(i,j) &= f(i-1,j) + &f(i-1, j-1) + \cdots + &f(i-1, j-i+1) \\ f(i, j-1) &= &f(i-1, j-1) + \cdots + &f(i-1, j-i+1) + f(i-1, j-i) \\ \end{align} +} $$ + 从而: + $$ +\displaylines{ f(i,j) = f(i-1,j) + f(i, j-1)-f(i-1,j-i) +} $$ + 边界条件: + $$ +\displaylines{ f(*, 0) = 1 \quad \text{specifically, } f(1, 0) = 1\\ f(1, j) = 0 \quad \text{if} ~ j > 0\\ f(*, j) = 0 \quad \text{if} ~ j < 0 \\ +} $$ + 动态规划: ```cpp @@ -79,4 +94,3 @@ public: ``` - diff --git "a/docs/algorithm/review/problem_series/\343\200\220\345\217\214\346\214\207\351\222\210\343\200\221\351\200\202\351\276\204\346\234\213\345\217\213.md" "b/docs/algorithm/review/problem_series/\343\200\220\345\217\214\346\214\207\351\222\210\343\200\221\351\200\202\351\276\204\346\234\213\345\217\213.md" index 71b9b5f06..c14b3ed31 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\345\217\214\346\214\207\351\222\210\343\200\221\351\200\202\351\276\204\346\234\213\345\217\213.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\345\217\214\346\214\207\351\222\210\343\200\221\351\200\202\351\276\204\346\234\213\345\217\213.md" @@ -17,7 +17,6 @@ 返回在该社交媒体网站上产生的好友请求总数。 - ### 二分 最初的想法。条件三是条件二的充分条件,所以只用判断两种边界。 @@ -45,7 +44,6 @@ public: ``` - ### 双指针 $O(n\log n)$,常数更低。 @@ -69,7 +67,6 @@ public: ``` - ### 前缀和 由于年龄限制在120以内,更快的做法是暴力统计。 diff --git "a/docs/algorithm/review/problem_series/\343\200\220\345\233\236\346\272\257\343\200\221\345\205\254\345\271\263\345\210\206\345\217\221\351\245\274\345\271\262.md" "b/docs/algorithm/review/problem_series/\343\200\220\345\233\236\346\272\257\343\200\221\345\205\254\345\271\263\345\210\206\345\217\221\351\245\274\345\271\262.md" index 3ecc2b212..19d280e87 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\345\233\236\346\272\257\343\200\221\345\205\254\345\271\263\345\210\206\345\217\221\351\245\274\345\271\262.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\345\233\236\346\272\257\343\200\221\345\205\254\345\271\263\345\210\206\345\217\221\351\245\274\345\271\262.md" @@ -11,7 +11,6 @@ - `2 <= k <= cookies.length` - ### 回溯 “**把一个集合划分成K组,使得每组的和的最大值最小**”应该只能用回溯才能得到正确答案!贪心一定是错的! @@ -47,9 +46,6 @@ public: ``` - - - ### 二分加速回溯 注意到这个题目的答案也具有单调性,故可以用二分法寻找边界。然而判断函数还是需要回溯才能得到正确答案。 diff --git "a/docs/algorithm/review/problem_series/\343\200\220\345\240\206\343\200\221\343\200\220\344\272\214\345\210\206\343\200\221\347\254\254 K \344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260.md" "b/docs/algorithm/review/problem_series/\343\200\220\345\240\206\343\200\221\343\200\220\344\272\214\345\210\206\343\200\221\347\254\254 K \344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260.md" index b55daa8ca..799394c3e 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\345\240\206\343\200\221\343\200\220\344\272\214\345\210\206\343\200\221\347\254\254 K \344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\345\240\206\343\200\221\343\200\220\344\272\214\345\210\206\343\200\221\347\254\254 K \344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260.md" @@ -7,7 +7,6 @@ 那么第 k 个最小的分数是多少呢? 以长度为 2 的整数数组返回你的答案, 这里 answer[0] == arr[i] 且 answer[1] == arr[j] 。 - ### 暴力 扫描k次,手动管理大小关系只能做到每次$O(N)$。 @@ -15,7 +14,6 @@ $O(kN)=O(N^3)$,TLE。 - ### 堆 类似的想法,扫描k次,但通过堆管理排序。本质是**多路归并**问题。 @@ -48,7 +46,6 @@ public: ``` - ### 二分 小于$x$的分数数量关于$x$是单调递增的,所以可以二分$x$,计数小于$x$的分数数量来求解。 @@ -94,7 +91,6 @@ public: ``` - ### 类似题目:[查找和最小的K对数字](https://leetcode-cn.com/problems/find-k-pairs-with-smallest-sums/) 给定两个以升序排列的整数数组 nums1 和 nums2 , 以及一个整数 k 。 @@ -104,7 +100,6 @@ public: 请找到和最小的 k 个数对 (u1,v1), (u2,v2) ... (uk,vk) 。 - #### 堆 类似的,虽然两组数可复用时没有明显的单调性,但如果固定其中一个数,求和对另一个数一定是单调的,所以也可以用堆解决。 diff --git "a/docs/algorithm/review/problem_series/\343\200\220\345\276\252\347\216\257KMP\343\200\221\351\207\215\345\217\240\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215.md" "b/docs/algorithm/review/problem_series/\343\200\220\345\276\252\347\216\257KMP\343\200\221\351\207\215\345\217\240\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215.md" index 0ad54abb4..4b4ce0ccc 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\345\276\252\347\216\257KMP\343\200\221\351\207\215\345\217\240\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\345\276\252\347\216\257KMP\343\200\221\351\207\215\345\217\240\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215.md" @@ -5,7 +5,6 @@ 注意:字符串 "abc" 重复叠加 0 次是 "",重复叠加 1 次是 "abc",重复叠加 2 次是 "abcabc"。 - ### 二分 + find 也不是不行,但仔细想想就知道这是很傻的做法了。$O(2n\log\frac{n}{m} )$。 @@ -34,7 +33,6 @@ public: ``` - ### find 因为其实一次find加贪心就可以得到答案:$O(2n)$ @@ -55,7 +53,6 @@ public: ``` - ### 循环KMP 手写KMP并修改,使其可以循环匹配母串。$O(n+m)$ @@ -94,7 +91,6 @@ public: ``` - ### 循环Rabin-Karp 滚动哈希。$O(n+m)$ @@ -144,6 +140,3 @@ public: ``` - - - diff --git "a/docs/algorithm/review/problem_series/\343\200\220\346\213\223\346\211\221\346\216\222\345\272\217\343\200\221\345\257\214\346\234\211\344\270\216\345\220\265\351\227\271.md" "b/docs/algorithm/review/problem_series/\343\200\220\346\213\223\346\211\221\346\216\222\345\272\217\343\200\221\345\257\214\346\234\211\344\270\216\345\220\265\351\227\271.md" index 3f5298c0f..973fbc43e 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\346\213\223\346\211\221\346\216\222\345\272\217\343\200\221\345\257\214\346\234\211\344\270\216\345\220\265\351\227\271.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\346\213\223\346\211\221\346\216\222\345\272\217\343\200\221\345\257\214\346\234\211\344\270\216\345\220\265\351\227\271.md" @@ -1,7 +1,6 @@ ## [喧闹与富有](https://leetcode-cn.com/problems/loud-and-rich/) - 有一组 n 个人作为实验对象,从 0 到 n - 1 编号,其中每个人都有不同数目的钱,以及不同程度的安静值(quietness)。为了方便起见,我们将编号为 x 的人简称为 "person x "。 给你一个数组 richer ,其中 richer[i] = [ai, bi] 表示 person ai 比 person bi 更有钱。另给你一个整数数组 quiet ,其中 quiet[i] 是 person i 的安静值。richer 中所给出的数据 逻辑自恰(也就是说,在 person x 比 person y 更有钱的同时,不会出现 person y 比 person x 更有钱的情况 )。 @@ -44,7 +43,6 @@ public: ``` - ### 拓扑排序 ```cpp diff --git "a/docs/algorithm/review/problem_series/\343\200\220\346\240\221\344\270\255\346\234\200\351\225\277\350\267\257\345\276\204\343\200\221\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221.md" "b/docs/algorithm/review/problem_series/\343\200\220\346\240\221\344\270\255\346\234\200\351\225\277\350\267\257\345\276\204\343\200\221\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221.md" index 2ec11e658..f0d0c0606 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\346\240\221\344\270\255\346\234\200\351\225\277\350\267\257\345\276\204\343\200\221\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\346\240\221\344\270\255\346\234\200\351\225\277\350\267\257\345\276\204\343\200\221\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221.md" @@ -11,7 +11,6 @@ 树的 高度 是指根节点和叶子节点之间最长向下路径上边的数量。 - ### 搜索树中最长路径,返回中点即可 但搜索最长路径是有技巧的:只需要**先以任意节点为根,搜索最远的点x,再以x为根,搜索最远的点y,最长路径即x-y**。搜索过程中记录parent数组,即可找回这条路径的中点。 diff --git "a/docs/algorithm/review/problem_series/\343\200\220\346\273\221\345\212\250\347\252\227\345\217\243\343\200\221\345\217\257\344\277\256\346\224\271k\346\254\241\347\232\204\346\234\200\351\225\277\345\220\214\345\255\227\347\254\246\345\255\220\344\270\262.md" "b/docs/algorithm/review/problem_series/\343\200\220\346\273\221\345\212\250\347\252\227\345\217\243\343\200\221\345\217\257\344\277\256\346\224\271k\346\254\241\347\232\204\346\234\200\351\225\277\345\220\214\345\255\227\347\254\246\345\255\220\344\270\262.md" index 0ec591f95..9fe961916 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\346\273\221\345\212\250\347\252\227\345\217\243\343\200\221\345\217\257\344\277\256\346\224\271k\346\254\241\347\232\204\346\234\200\351\225\277\345\220\214\345\255\227\347\254\246\345\255\220\344\270\262.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\346\273\221\345\212\250\347\252\227\345\217\243\343\200\221\345\217\257\344\277\256\346\224\271k\346\254\241\347\232\204\346\234\200\351\225\277\345\220\214\345\255\227\347\254\246\345\255\220\344\270\262.md" @@ -6,7 +6,6 @@ > 请你返回在不超过 k 次操作的情况下,最大 连续 'T' 或者 'F' 的数目。 - 贪心,只需要控制滑动窗口内的相异字符数量不超过k即可。 ```cpp diff --git "a/docs/algorithm/review/problem_series/\343\200\220\346\273\221\347\252\227\345\223\210\345\270\214\343\200\221\351\207\215\345\244\215\345\255\220\344\270\262.md" "b/docs/algorithm/review/problem_series/\343\200\220\346\273\221\347\252\227\345\223\210\345\270\214\343\200\221\351\207\215\345\244\215\345\255\220\344\270\262.md" index 5df55161f..47e50e53b 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\346\273\221\347\252\227\345\223\210\345\270\214\343\200\221\351\207\215\345\244\215\345\255\220\344\270\262.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\346\273\221\347\252\227\345\223\210\345\270\214\343\200\221\351\207\215\345\244\215\345\255\220\344\270\262.md" @@ -1,7 +1,6 @@ ## [repeated substring](https://leetcode-cn.com/problems/repeated-dna-sequences/) - > 所有 DNA 都由一系列缩写为 'A','C','G' 和 'T' 的核苷酸组成,例如:"ACGAATTCCG"。在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮助。 > > 编写一个函数来找出所有目标子串,目标子串的长度为 10,且在 DNA 字符串 s 中出现次数超过一次。 @@ -31,7 +30,6 @@ public: ``` - ### 位运算优化 注意到只有四个字母,因此可以用2bit表示。又注意到固定串长为10,每个子串可用20bit表示,小于一个int的长度。因此可以预处理每个滑动窗口为一个int。 @@ -66,15 +64,16 @@ public: ``` - - - ### Polynomial rolling Hash + 前缀和 [polynomial rolling hash](https://en.wikipedia.org/wiki/Rolling_hash): + $$ +\displaylines{ hash(s) = \sum_{i = 0}^Ns[L-i-1]\cdot P^i \mod M +} $$ + where: * $L$ is the length of $s$. @@ -86,10 +85,13 @@ properties: * since it is in the form of a prefix-sum, it is easy to calculate the hash of substrings. + $$ +\displaylines{ hash(s[i:j+1]) = hash(s[:j]) - hash(s[:i-1])\cdot P^{j-i+1} +} $$ diff --git "a/docs/algorithm/review/problem_series/\343\200\220\350\256\241\346\225\260\343\200\221\345\207\272\347\216\260\346\254\241\346\225\260\346\234\200\345\244\232\347\232\204\345\211\215\344\270\244\344\270\252\345\205\203\347\264\240.md" "b/docs/algorithm/review/problem_series/\343\200\220\350\256\241\346\225\260\343\200\221\345\207\272\347\216\260\346\254\241\346\225\260\346\234\200\345\244\232\347\232\204\345\211\215\344\270\244\344\270\252\345\205\203\347\264\240.md" index e56e32bef..bf66fb24f 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\350\256\241\346\225\260\343\200\221\345\207\272\347\216\260\346\254\241\346\225\260\346\234\200\345\244\232\347\232\204\345\211\215\344\270\244\344\270\252\345\205\203\347\264\240.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\350\256\241\346\225\260\343\200\221\345\207\272\347\216\260\346\254\241\346\225\260\346\234\200\345\244\232\347\232\204\345\211\215\344\270\244\344\270\252\345\205\203\347\264\240.md" @@ -42,4 +42,3 @@ public: ``` - diff --git "a/docs/algorithm/review/problem_series/\343\200\220\350\264\252\345\277\203\343\200\221\351\200\222\345\242\236\344\270\211\345\205\203\347\273\204.md" "b/docs/algorithm/review/problem_series/\343\200\220\350\264\252\345\277\203\343\200\221\351\200\222\345\242\236\344\270\211\345\205\203\347\273\204.md" index 4647f7b39..d715979f6 100644 --- "a/docs/algorithm/review/problem_series/\343\200\220\350\264\252\345\277\203\343\200\221\351\200\222\345\242\236\344\270\211\345\205\203\347\273\204.md" +++ "b/docs/algorithm/review/problem_series/\343\200\220\350\264\252\345\277\203\343\200\221\351\200\222\345\242\236\344\270\211\345\205\203\347\273\204.md" @@ -5,7 +5,6 @@ 如果存在这样的三元组下标 (i, j, k) 且满足 i < j < k ,使得 nums[i] < nums[j] < nums[k] ,返回 true ;否则,返回 false 。 - ### 最长递增子序列的子问题 只需找到LIS,在判断是否长于3即可。 @@ -29,7 +28,6 @@ public: ``` - ### 更简单的想法 和上面的贪心做法思路一致,只不过只记录第一小和第二小的值,这样一旦出现更大的值,就说明有三元组了。 @@ -52,4 +50,3 @@ public: ``` - diff --git "a/docs/algorithm/review/problem_series/\344\270\215\345\220\253\350\277\236\347\273\255\344\270\200\347\232\204\351\235\236\350\264\237\346\225\264\346\225\260.md" "b/docs/algorithm/review/problem_series/\344\270\215\345\220\253\350\277\236\347\273\255\344\270\200\347\232\204\351\235\236\350\264\237\346\225\264\346\225\260.md" index 065162ebd..7a2e9213b 100644 --- "a/docs/algorithm/review/problem_series/\344\270\215\345\220\253\350\277\236\347\273\255\344\270\200\347\232\204\351\235\236\350\264\237\346\225\264\346\225\260.md" +++ "b/docs/algorithm/review/problem_series/\344\270\215\345\220\253\350\277\236\347\273\255\344\270\200\347\232\204\351\235\236\350\264\237\346\225\264\346\225\260.md" @@ -3,15 +3,22 @@ > 给定一个正整数 n,找出小于或等于 n 的非负整数中,其二进制表示不包含 **连续的1** 的个数。 先考虑$n=2^k$,在排除0的情况下,可以发现这个结果就是斐波那契数列。 + $$ +\displaylines{ f(2^k) = f(2^{k-1}) + f(2^{k-2}) \\ f(1) = 1;f(2) = 2. +} $$ + 在考虑任意$n$,从第一个bit开始循环,如果遇到连续的一,则可以终止循环。 + $$ +\displaylines{ f(b1100100) = f(b1011111)=f(b1010101) \\ = f(b1000000) + f(b10000) + f(b100) + f(b1)\\ = f(b1000000) + f(b100000) - 1 +} $$ diff --git "a/docs/algorithm/review/problem_series/\346\221\251\345\260\224\346\212\225\347\245\250.md" "b/docs/algorithm/review/problem_series/\346\221\251\345\260\224\346\212\225\347\245\250.md" index e5307153b..b75b6e0a2 100644 --- "a/docs/algorithm/review/problem_series/\346\221\251\345\260\224\346\212\225\347\245\250.md" +++ "b/docs/algorithm/review/problem_series/\346\221\251\345\260\224\346\212\225\347\245\250.md" @@ -5,7 +5,6 @@ 当然现在存储空间往往不是平静,Hash算法的时间常数更低。 - ### [寻找数组中出现概率超过1/2的数](https://leetcode-cn.com/problems/majority-element/) ```cpp @@ -31,7 +30,6 @@ public: ``` - ### [寻找数组中出现概率超过1/3的数](https://leetcode-cn.com/problems/majority-element-ii) ```cpp diff --git "a/docs/algorithm/review/problem_series/\351\207\215\346\216\222\344\270\2722\347\232\204\345\271\202.md" "b/docs/algorithm/review/problem_series/\351\207\215\346\216\222\344\270\2722\347\232\204\345\271\202.md" index 8f7d46a6c..ad8db8134 100644 --- "a/docs/algorithm/review/problem_series/\351\207\215\346\216\222\344\270\2722\347\232\204\345\271\202.md" +++ "b/docs/algorithm/review/problem_series/\351\207\215\346\216\222\344\270\2722\347\232\204\345\271\202.md" @@ -34,7 +34,6 @@ public: ``` - ### 排列组合 按照题意对所有排列依次检查。 diff --git "a/docs/algorithm/review/\344\272\214\345\210\206\346\263\225.md" "b/docs/algorithm/review/\344\272\214\345\210\206\346\263\225.md" index e0876b054..b46bdf246 100644 --- "a/docs/algorithm/review/\344\272\214\345\210\206\346\263\225.md" +++ "b/docs/algorithm/review/\344\272\214\345\210\206\346\263\225.md" @@ -4,10 +4,14 @@ **搜索空间单调!** + $$ +\displaylines{ i < j \Rightarrow test(i) \rightarrow test(j) +} $$ + ### 分类(根据搜索目标) * 单值 diff --git "a/docs/algorithm/review/\345\207\270\344\274\230\345\214\226.md" "b/docs/algorithm/review/\345\207\270\344\274\230\345\214\226.md" index d2d5e3c95..5b685b673 100644 --- "a/docs/algorithm/review/\345\207\270\344\274\230\345\214\226.md" +++ "b/docs/algorithm/review/\345\207\270\344\274\230\345\214\226.md" @@ -1,9 +1,13 @@ #### [几何中心](https://leetcode-cn.com/problems/best-position-for-a-service-centre/) 给定一些二维平面上的点,求一个目标点使得其到所有给定点的欧氏距离之和最小。 + $$ +\displaylines{ \min_{x,y}\sum_{i}\sqrt{(x-x_i)^2 + (y-y_i)^2} +} $$ + **没有解析解**,但目标函数为凸函数,故使用梯度下降法求解: ```c++ diff --git "a/docs/algorithm/review/\345\212\250\346\200\201\350\247\204\345\210\222.md" "b/docs/algorithm/review/\345\212\250\346\200\201\350\247\204\345\210\222.md" index 344e8b361..27217b3e3 100644 --- "a/docs/algorithm/review/\345\212\250\346\200\201\350\247\204\345\210\222.md" +++ "b/docs/algorithm/review/\345\212\250\346\200\201\350\247\204\345\210\222.md" @@ -16,11 +16,15 @@ 状态方程:$f[i][j]$表示使用前$i$个物品,最大容量为$j$时可以获得的最大价值。 + $$ +\displaylines{ f[i][j] = \max(f[i-1][j], f[i-1][j-w[j]]+v[j]) \\ , 0 \le i \le M, 0 \le j \le N \\ +} $$ + 边界条件: * $f[0][j] = 0$ @@ -94,11 +98,15 @@ int main() { 最大容量N,共M个物品,每个物品可以选任意次。 + $$ +\displaylines{ f[i][j] = \max_{0 \le k \le K}(f[i-1][j-kw[i]] + kv[i]) \\ f[i][j] = \max(f[i-1][j], f[i][j-w[i]]+v[i]) +} $$ + ```c++ const int M = 100 + 1; const int N = 1000 + 1; @@ -216,10 +224,6 @@ public: ``` - - - - ### [最长公共子序列](https://leetcode-cn.com/problems/longest-common-subsequence/) LCS **子序列(Subsequence)可以不连续!**(与最长公共子串不同) @@ -247,7 +251,6 @@ public: ``` - ### [最长上升子序列](https://leetcode-cn.com/problems/longest-increasing-subsequence/) LIS DP solution $O(n^2)$: @@ -394,11 +397,6 @@ public: ``` - - - - - ### [最长公共子串](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) **子串(Substring)必须连续!** @@ -432,7 +430,6 @@ public: ``` - ### [最长公共子串(多序列)](https://leetcode-cn.com/problems/longest-common-subpath) (POJ Corporate Identity) @@ -568,9 +565,6 @@ public: Effective, but not always easy to write, anyway. - - - ### 状态压缩 通常题目中会有一个序列(10~30长度),这个序列可以用二进制表示,即使用一个`int`表示这个序列的状态。 @@ -616,4 +610,3 @@ public: ``` - diff --git "a/docs/algorithm/review/\345\214\272\351\227\264\351\227\256\351\242\230.md" "b/docs/algorithm/review/\345\214\272\351\227\264\351\227\256\351\242\230.md" index 68171b6ac..50d35d9b1 100644 --- "a/docs/algorithm/review/\345\214\272\351\227\264\351\227\256\351\242\230.md" +++ "b/docs/algorithm/review/\345\214\272\351\227\264\351\227\256\351\242\230.md" @@ -13,7 +13,6 @@ * 线段树为最通用的方案(区间修改,区间查询),但对于更限定的场景,前缀和、差分等方法更简单。 - #### 前缀和 支持$O(1)$时间的区间查询。 @@ -92,7 +91,6 @@ arr[i] = diff[i] + arr[i-1] ``` - * [1D array](https://leetcode-cn.com/problems/corporate-flight-bookings/) ```cpp @@ -172,7 +170,6 @@ arr[i] = diff[i] + arr[i-1] - #### 树状数组 支持$O(\log n)$时间的单点更新与区间求和。 @@ -180,7 +177,6 @@ arr[i] = diff[i] + arr[i-1] **默认下标从1开始!!!** - * [1D array](https://leetcode-cn.com/problems/range-sum-query-mutable/) ```cpp @@ -225,7 +221,6 @@ arr[i] = diff[i] + arr[i-1] - #### 线段树 支持$O(\log n)$时间的区间更新与区间求和,但常数较大。 @@ -314,10 +309,6 @@ arr[i] = diff[i] + arr[i-1] ``` - - - - ### 区间最值 | 数组修改 | 算法 | @@ -328,16 +319,12 @@ arr[i] = diff[i] + arr[i-1] | 单点替换 | 线段树,树状数组 | - #### ST表 ```cpp ``` - - - #### 扩展树状数组 支持单点替换,区间查询 @@ -382,7 +369,6 @@ int query(int i, int j) { ``` - #### 线段树 * 替换 diff --git "a/docs/algorithm/review/\345\215\225\350\260\203\351\230\237\345\210\227.md" "b/docs/algorithm/review/\345\215\225\350\260\203\351\230\237\345\210\227.md" index 222b81805..90d053d21 100644 --- "a/docs/algorithm/review/\345\215\225\350\260\203\351\230\237\345\210\227.md" +++ "b/docs/algorithm/review/\345\215\225\350\260\203\351\230\237\345\210\227.md" @@ -46,7 +46,6 @@ for (int i = 0; i < n; i++) { ``` - ### [滑动窗口极值](https://leetcode-cn.com/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/) 裸模板$O(N)$: @@ -106,7 +105,6 @@ public: 使用Sparse Table的RMQ算法也可以$O(N)$。 - ### [Maximum value in queue](https://leetcode-cn.com/problems/dui-lie-de-zui-da-zhi-lcof/) deque直接记录当前窗口的最值。 @@ -141,9 +139,6 @@ public: ``` - - - ### [Maximum Sum Circular Subarray](https://leetcode-cn.com/problems/maximum-sum-circular-subarray/) 前缀和&滑动窗口: @@ -221,7 +216,6 @@ public: ``` - ### [The next larger element (monotone stack)](https://leetcode-cn.com/problems/next-greater-element-i/) > 给你两个 没有重复元素 的数组 nums1 和 nums2 ,其中nums1 是 nums2 的子集。请你找出 nums1 中每个元素在 nums2 中的下一个比其大的值。 @@ -256,4 +250,3 @@ public: ``` - diff --git "a/docs/algorithm/review/\345\217\214\346\214\207\351\222\210.md" "b/docs/algorithm/review/\345\217\214\346\214\207\351\222\210.md" index 9d0ce14f6..4b7d24426 100644 --- "a/docs/algorithm/review/\345\217\214\346\214\207\351\222\210.md" +++ "b/docs/algorithm/review/\345\217\214\346\214\207\351\222\210.md" @@ -17,7 +17,6 @@ - ### 有序数组中的搜索 ##### 两数之和 @@ -65,7 +64,6 @@ vector twoSum(vector& nums, int target) { ``` - ##### 三数之和 给定一个数组,求其中所有不重复的三个数,使其和为0。 @@ -113,9 +111,6 @@ public: ``` - - - ### [合法三角形个数](https://leetcode-cn.com/problems/valid-triangle-number/) 给定一个边长数组,求其中可以组成合法三角形的三元组个数。 @@ -144,9 +139,6 @@ public: ``` - - - ### [链表相交点](https://leetcode-cn.com/problems/liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof/) 双指针换家。证明很简单,但是方法想不到啊。 @@ -175,7 +167,6 @@ public: ``` - ### [救生艇的最少数量](https://leetcode-cn.com/problems/boats-to-save-people/) 并不是动规,问的是袋子的最少数量。 @@ -234,9 +225,6 @@ public: ``` - - - ### [和为s的连续正整数序列](https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof/) 输入一个正整数 target ,输出所有和为 target 的连续正整数序列(至少含有两个数)。序列内的数字由小到大排列,不同序列按照首个数字从小到大排列。 diff --git "a/docs/algorithm/review/\345\223\210\345\270\214.md" "b/docs/algorithm/review/\345\223\210\345\270\214.md" index d72fa8f53..e6f9bc9f7 100644 --- "a/docs/algorithm/review/\345\223\210\345\270\214.md" +++ "b/docs/algorithm/review/\345\223\210\345\270\214.md" @@ -1,7 +1,6 @@ # hash - #### [和为K的子数组](https://leetcode-cn.com/problems/subarray-sum-equals-k/) 求数组中和为K的连续子数组。前缀和将问题转换为类似于两数之和的问题,再使用哈希。 diff --git "a/docs/algorithm/review/\345\233\236\346\272\257.md" "b/docs/algorithm/review/\345\233\236\346\272\257.md" index d822b6c6e..19c4146bd 100644 --- "a/docs/algorithm/review/\345\233\236\346\272\257.md" +++ "b/docs/algorithm/review/\345\233\236\346\272\257.md" @@ -32,7 +32,6 @@ public: ``` - ### 全组合 回溯: @@ -72,9 +71,6 @@ for (int m = 0; m <= maxm; m++) { ``` - - - ### N皇后 ```c++ diff --git "a/docs/algorithm/review/\345\233\276.md" "b/docs/algorithm/review/\345\233\276.md" index 038d0d248..3c3262cf0 100644 --- "a/docs/algorithm/review/\345\233\276.md" +++ "b/docs/algorithm/review/\345\233\276.md" @@ -66,9 +66,6 @@ public: ``` - - - ### [遍历所有节点的最短路](https://leetcode-cn.com/problems/shortest-path-visiting-all-nodes/) 求一个无向图**可从任意节点出发、可重复经过节点的**遍历所有节点的路径的最短长度。 diff --git "a/docs/algorithm/review/\345\234\250\347\272\277\345\214\272\351\227\264\351\227\256\351\242\230.md" "b/docs/algorithm/review/\345\234\250\347\272\277\345\214\272\351\227\264\351\227\256\351\242\230.md" index 719ed2f50..e0c687743 100644 --- "a/docs/algorithm/review/\345\234\250\347\272\277\345\214\272\351\227\264\351\227\256\351\242\230.md" +++ "b/docs/algorithm/review/\345\234\250\347\272\277\345\214\272\351\227\264\351\227\256\351\242\230.md" @@ -63,9 +63,6 @@ public: ``` - - - ### [Range模块](https://leetcode-cn.com/problems/range-module/) 每次修改一个区间(添加或删除),随时查询某个区间是否被完全填充。 diff --git "a/docs/algorithm/review/\345\237\272\347\241\200.md" "b/docs/algorithm/review/\345\237\272\347\241\200.md" index f97d5de34..8889fc401 100644 --- "a/docs/algorithm/review/\345\237\272\347\241\200.md" +++ "b/docs/algorithm/review/\345\237\272\347\241\200.md" @@ -282,7 +282,6 @@ ``` - * is prime ```c++ diff --git "a/docs/algorithm/review/\346\220\234\347\264\242.md" "b/docs/algorithm/review/\346\220\234\347\264\242.md" index d5ea3fa6a..2ef619baf 100644 --- "a/docs/algorithm/review/\346\220\234\347\264\242.md" +++ "b/docs/algorithm/review/\346\220\234\347\264\242.md" @@ -7,7 +7,6 @@ Uninformed (Blind) Search: 对要搜索的节点一无所知。 Informed (Heuristic) Search: 对要搜索的节点有一些启发性的知识,可以用来加速搜索。 - ### BFS ```python @@ -55,13 +54,11 @@ dfs(s0) ``` - * **Space **: $O(|V|)$ if for a graph (the vis list), but $O(D)$ for a tree (no need for vis list). * **Time**: $O(|V|)$ - #### DFS与BFS的区别 * 搜索**满足条件的节点**:都可以,时间复杂度都是$O(|V|)$​. @@ -127,9 +124,6 @@ dfs(s0) 时间复杂度为$O(3^LMN)$,最坏需要遍历所有长度L的路径,每步有三个方向(不能回头),最多有$MN$个起点。 - - - ### IDS DFS在特定数据下具有优势,但也有一个重大缺陷,即**树的深度有可能是无限的**。 @@ -139,7 +133,6 @@ DFS在特定数据下具有优势,但也有一个重大缺陷,即**树的深 每次增大搜索深度上限都会导致DFS的重新调用,但在完全多叉树的情况下,新的节点总是远多于重复搜索的结点的。 - ### Best-FS 对节点的已知信息可以用两个函数来表示: @@ -186,7 +179,6 @@ A* is complete and optimal. 但是这样的$h(s)$不一定好找。 - ### IDA* A* use BFS as the backbone. @@ -196,7 +188,6 @@ To reduce the Space Complexity of BFS, we can use IDS to replace BFS. This is called IDA*. - ### alpha-beta pruning 对于双方、零和、确定性的游戏(TicTacToe,五子棋,围棋),其搜索树的搜索目标每层都会反转,即MIN层-MAX层结构。 diff --git "a/docs/algorithm/review/\350\264\252\345\277\203.md" "b/docs/algorithm/review/\350\264\252\345\277\203.md" index 03d0fe9f0..d9a7e8d2c 100644 --- "a/docs/algorithm/review/\350\264\252\345\277\203.md" +++ "b/docs/algorithm/review/\350\264\252\345\277\203.md" @@ -28,7 +28,6 @@ public: ``` - ### [接雨水](https://leetcode-cn.com/problems/trapping-rain-water/) > 给定 `n` 个非负整数表示每个宽度为 `1` 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。 @@ -102,7 +101,6 @@ public: ``` - ### [接雨水2D](https://leetcode-cn.com/problems/trapping-rain-water-ii/) 仍然是贪心,1D中只求每个位置的左右最高点,在2D中变成了求每个位置到任意边界的**所有路径**中的最高点!(而不仅仅是四个方向的最高点) diff --git a/docs/c/basic_compile.md b/docs/c/basic_compile.md index a4522beea..1948dbcd0 100644 --- a/docs/c/basic_compile.md +++ b/docs/c/basic_compile.md @@ -1,7 +1,6 @@ # Compile - ### Header `(.h/hpp)` vs Implementation `(.c/cpp)` ##### Concepts @@ -42,7 +41,6 @@ A collection of resources to provide **re-usable** code. Generally, any code you include can be viewed as a library. - ##### Using at Compiling This is the case when you **have the source code of the library**. @@ -120,7 +118,6 @@ You only have `libxxx.h` , and a compiled library file. (static or dynamic) ``` - Both kind of library should be compiled & linked by: ```bash @@ -135,7 +132,6 @@ g++ main.cpp -I /path/to/include -L /path/to/lib -lunuseful ``` - ##### use`pkg-config` to auto-find `-l` ```bash @@ -147,7 +143,6 @@ g++ main.cpp `pkg-config --cflags --libs` `pkg-config --cflags ` outputs the include arguments and any other needed compile flags. - ### gcc / g++ Used to compile **Single** source code. @@ -206,7 +201,6 @@ g++ -std=c++11 main.cpp ``` - ### make Batch-compile for **multiple** source files. @@ -222,7 +216,6 @@ make install # install to where ? ``` - ### makefile ##### example @@ -287,7 +280,6 @@ clean : ``` - ### compilers * **Visual C++**: GUI compiler, mainly used in Windows. diff --git a/docs/c/c.md b/docs/c/c.md index 41da5561c..7acad4027 100644 --- a/docs/c/c.md +++ b/docs/c/c.md @@ -1,7 +1,6 @@ # C - ## Concepts * ANSI C / ISO C / Standard C @@ -42,7 +41,6 @@ gcc -o hello.out hello.c ``` - ## Tutorial ### Operator Precedence @@ -109,7 +107,6 @@ long long -> float -> double -> long double ``` - ### Pointer ```c @@ -128,7 +125,6 @@ Some concepts: * dangling pointer (悬垂指针): pointint to a **deleted** address. - ### Array ```c @@ -265,7 +261,6 @@ int main() { ``` - ### Chars ```c @@ -289,7 +284,6 @@ int i = atoi(s); // 12 ``` - ### pass-by-reference in function args ```c @@ -303,7 +297,6 @@ void int(int *px) { *px += 1; } ``` - ### CMD args ```c @@ -318,7 +311,6 @@ int main(int argc, char **argv) ``` - ### Struct ```c @@ -348,7 +340,6 @@ struct { ``` - ### typedef ```c @@ -357,7 +348,6 @@ BYTE b; ``` - ### Macro ```c @@ -372,7 +362,6 @@ BYTE b; ``` - ### IO ```c @@ -392,7 +381,6 @@ int main() { ``` - ### C Library #### #include @@ -465,7 +453,6 @@ int main() { ``` - #### #include ```c diff --git a/docs/c/cpp.md b/docs/c/cpp.md index 650a0a30d..ec7f0a20e 100644 --- a/docs/c/cpp.md +++ b/docs/c/cpp.md @@ -26,7 +26,6 @@ Contains 4 parts, each designed with different philosophy. ``` - ### C++ Library #### #include \ @@ -593,9 +592,6 @@ unsigned long x = bs.to_ulo ``` - - - ### Class ```c++ @@ -647,7 +643,6 @@ struct A { ``` - #### Inheritance ```c++ @@ -738,11 +733,6 @@ public: ``` - - - - - ### Template #### Function @@ -767,7 +757,6 @@ public: ``` - ### new & delete ```c++ @@ -780,7 +769,6 @@ delete [] s; ``` - ### shared_ptr a smart pointer class, that manages reference count of the object and automatically deconstruct the object if reference count is 0. @@ -795,9 +783,6 @@ p.reset(new ClassName()); // the first object is deconstructed. ``` - - - ### Reference less powerful but safer than pointer. it works like an alias. @@ -840,7 +825,6 @@ void swap(int& x, int& y) { ``` - ### Memory Layout ![img](cpp.assets/memoryLayoutC.jpg) diff --git a/docs/c/csapp/01_Roaming.md b/docs/c/csapp/01_Roaming.md index 91bd9280f..0144bbc43 100644 --- a/docs/c/csapp/01_Roaming.md +++ b/docs/c/csapp/01_Roaming.md @@ -15,7 +15,6 @@ What happened: * linker (ld): `hello.o, printf.o, ... --> hello` - ### Hardware Organization of a System Hardwares: @@ -45,13 +44,11 @@ Memory hierarchy: Balance between **Access Speed** and **Storage Size**! * Disk: 1~1000 TB - Memory Organization: ![image-20221202103252080](roaming.assets/image-20221202103252080.png) - ### Concurrency and Parallelism Amdahl's Law: How much can a program be accelerated. @@ -59,7 +56,6 @@ Amdahl's Law: How much can a program be accelerated. ![image-20221202103648538](roaming.assets/image-20221202103648538.png) - Different methods: * Thread-level Concurrency diff --git a/docs/c/csapp/02_Information_Storage.md b/docs/c/csapp/02_Information_Storage.md index f204071e4..fc4cc665b 100644 --- a/docs/c/csapp/02_Information_Storage.md +++ b/docs/c/csapp/02_Information_Storage.md @@ -1,7 +1,6 @@ ## Information Storage - ### Integer ![image-20221202105118312](02_Information_Storage.assets/image-20221202105118312.png) @@ -27,7 +26,6 @@ assert(a > b); // true, signed -1 --> unsigned 2^{32}-1 > 0 ``` - ### Integer Arithmetic Overflow: @@ -41,9 +39,6 @@ Overflow: ![image-20221202110308769](02_Information_Storage.assets/image-20221202110308769.png) - - - ### Floating Point ![image-20221202113856519](02_Information_Storage.assets/image-20221202113856519.png) diff --git a/docs/c/csapp/03_Machine_Language.md b/docs/c/csapp/03_Machine_Language.md index ee12f8381..87f6d4583 100644 --- a/docs/c/csapp/03_Machine_Language.md +++ b/docs/c/csapp/03_Machine_Language.md @@ -10,7 +10,6 @@ gcc -Og -c test.c # test.o, binary machine code ``` - #### Registers * **Caller-saved / Callee-saved** Register: different strategies to save register context at calling functions. @@ -43,9 +42,6 @@ gcc -Og -c test.c # test.o, binary machine code ![image-20221203193139631](03_Machine_Language.assets/image-20221203193139631.png) - - - ### Instructions * Operation Code: `movq, addq, subq, xorq, ret` @@ -148,5 +144,4 @@ gcc -Og -c test.c # test.o, binary machine code * - > TODO: 3-6 diff --git a/docs/c/csapp/07_Linking.md b/docs/c/csapp/07_Linking.md index e081f9493..eb94ac745 100644 --- a/docs/c/csapp/07_Linking.md +++ b/docs/c/csapp/07_Linking.md @@ -111,7 +111,6 @@ These parts are **linked** together later. ``` - ### Handling Symbols #### Undefined symbols @@ -179,7 +178,6 @@ gcc -static -o main main.o lib.a # append the lib archive ``` - ### Static Linking ```bash @@ -212,7 +210,6 @@ gcc -static -o foo foo.c libx.a liby.a libx.a # must duplicate libx.a twice here ``` - ### Relocation After determining the set **E**xecutable, linker performs relocation to merge all the `*.o` files into one. @@ -232,7 +229,6 @@ Two steps are performed: ![image-20221219203503532](07_Linking.assets/image-20221219203503532.png) - ### Executable Files Similar to ELF files: @@ -254,7 +250,6 @@ What happens when we run an executable file: ![image-20221219204229506](07_Linking.assets/image-20221219204229506.png) - ### Dynamic Linking Static linking (static libraries, `*.o`) has various disadvantages: diff --git a/docs/c/ctricks.md b/docs/c/ctricks.md index c31fadabb..327c8039a 100644 --- a/docs/c/ctricks.md +++ b/docs/c/ctricks.md @@ -30,7 +30,6 @@ else ...; ``` - ### Playing with #define ```cpp @@ -68,7 +67,6 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { ``` - ### static General meaning: **only initialized once**. diff --git a/docs/c/magic/rvalue_universal_ref.md b/docs/c/magic/rvalue_universal_ref.md index 101a43876..722274fc2 100644 --- a/docs/c/magic/rvalue_universal_ref.md +++ b/docs/c/magic/rvalue_universal_ref.md @@ -122,7 +122,6 @@ int main() { ``` - ### Applications 右值引用主要在函数传参时**用移动代替拷贝**,即**需要拷贝但被拷贝者之后又不再需要**的场景,例如临时变量。因为`std::move`只改变地址指向,而不会物理上的移动(即拷贝)数据。 @@ -210,7 +209,6 @@ v.push_back(A(1)); // A(1) is still copied. ``` - > 其它语言中的类似情况: > > c++默认的对象传值方式是拷贝,例如`vec.push_back(obj); auto vec2 = vec1;`等都会触发拷贝行为。引用传值必须通过`&`显式显式实现,例如`vec.push_back(move(obj)); auto vec2 = &vec1;` @@ -218,7 +216,6 @@ v.push_back(A(1)); // A(1) is still copied. > python默认的对象传值方式就是引用,例如`l.append(obj), obj2 = obj1`均为引用。相反,如果需要拷贝,则要通过`deepcopy`显式实现。 - ### 通用引用 Universal Reference 表现形式为**T && (模板+右值引用)**,利用编译器对模板的推导多义性,可以同时绑定左值与右值。 @@ -248,7 +245,6 @@ typename remove_reference::type&& move(T&& t) { ``` - ### 完美转发问题 完美转发指的是在函数内部将参数**包括类型原封不动**的传递给内部的另一函数。但由于右值引用传入函数后会变成左值,简单的参数转发是错误的! diff --git a/docs/c/modern_cpp.md b/docs/c/modern_cpp.md index 6774f37c4..e7643899c 100644 --- a/docs/c/modern_cpp.md +++ b/docs/c/modern_cpp.md @@ -20,7 +20,6 @@ To replace `NULL`'s use as a pointer. > ``` - ### value initialization (c++11) ```cpp @@ -28,7 +27,6 @@ int x{}; // default initialization, equals to `int x = 0;` ``` - ### string_view (c++17) make a view of a string without copying it. @@ -144,7 +142,6 @@ static_cast(sv); - ### constexpr constant expression is different from constant value. @@ -166,7 +163,6 @@ char a[fibonacci(5)]; // OK ``` - ### declare variable inside if (c++17) ```cpp @@ -180,7 +176,6 @@ if (n := len(v)) > 10: ``` - ### initializer list ```cpp @@ -197,9 +192,6 @@ A f() { return {1,2,3}; } ``` - - - ### tuple (c++17) ```cpp @@ -264,7 +256,6 @@ cout << s.a << endl; ``` - ### std::optional (c++17) Any instance of `optional` at any given point in time either *contains a value* or *does not contain a value*. @@ -321,7 +312,6 @@ modifying it changed it to Mothra ``` - ### lambda function (c++11) Lambdas can be used as an anonymous in-place function, or a nested function. diff --git a/docs/c/template.md b/docs/c/template.md index 51a935596..c7a72806c 100644 --- a/docs/c/template.md +++ b/docs/c/template.md @@ -55,7 +55,6 @@ ``` - ### meta/generic programming 功能类似于C中的MACRO,各种动态语言的duck typing,其目的是实现静态类型的抽象。 diff --git a/docs/crypto/asymmetric_cryptography.md b/docs/crypto/asymmetric_cryptography.md index c357197b0..2927aa907 100644 --- a/docs/crypto/asymmetric_cryptography.md +++ b/docs/crypto/asymmetric_cryptography.md @@ -29,7 +29,6 @@ Secure Hash Algorithms. A large series of well known hash functions. e.g., SHA-256 - # asymmetric cryptography also called public-key cryptography. @@ -54,7 +53,6 @@ Some widely used asymmetric cryptosystem: * ECDSA (Elliptic Curve Digital Signature Algorithm) - ### digital signature asymmetric cryptosystem guarantees that **only you can read the messages sent to you**. (加密) diff --git a/docs/crypto/base64.md b/docs/crypto/base64.md index abff4cde9..6e7d18763 100644 --- a/docs/crypto/base64.md +++ b/docs/crypto/base64.md @@ -8,7 +8,6 @@ padding character: = ``` - It encodes every 3 byte binary string to 4 byte base64 string. ```python @@ -38,9 +37,6 @@ def base64_decode(s): ``` - - - ### python API ```python @@ -53,7 +49,6 @@ bs == base64.b64decode(bs64) # True ``` - Note the difference between bytes and strings. ```python diff --git a/docs/crypto/blockchain.md b/docs/crypto/blockchain.md index 0872daad7..4c49197ba 100644 --- a/docs/crypto/blockchain.md +++ b/docs/crypto/blockchain.md @@ -7,7 +7,6 @@ blockchain is a center-less distributed database. * once the data are written into the database, they cannot be modified (unless one has control over more than 51% nodes). - ### Algorithm blockchain is a single-direction linked list (chain) of blocks. @@ -50,7 +49,6 @@ And this computation progress is called **mining**. In fact, it is very expensive to maintain a blockchain, and maybe the only practical application of blockchain is bitcoin. - ### Bitcoin Bitcoin protocol requires each block to be at most 1MB. (around 2000 transactions) @@ -96,9 +94,6 @@ There are 2 ways for miners to get profits: Digital Signature technology is used here. - - - ### Problems of cryptocurrency * Not real time. (10~60 minutes) diff --git a/docs/cuda/atomic_utils.md b/docs/cuda/atomic_utils.md index 020a774c1..798d73976 100644 --- a/docs/cuda/atomic_utils.md +++ b/docs/cuda/atomic_utils.md @@ -63,9 +63,6 @@ TODO: how much will it improve performance??? ``` - - - ### `atomicAdd` for `at::Half` ```cpp @@ -78,9 +75,6 @@ static inline __device__ at::Half atomicAdd(at::Half *address, at::Half val) { ``` - - - ### `atomicMax` for `at::Half, float, double` ```cpp diff --git a/docs/cuda/basics.md b/docs/cuda/basics.md index 6583f5a80..68341ee6f 100644 --- a/docs/cuda/basics.md +++ b/docs/cuda/basics.md @@ -3,11 +3,9 @@ https://nanohub.org/resources/7225/share?sharewith=pinterest - ## Examples - ### Compile ```bash @@ -21,11 +19,9 @@ nvprof ./hello.out ``` - ## Tutorials - ### Compute Capability (SM version) indicates the features supported by the GPU **hardware** (not to be confused with CUDA **software** version). @@ -37,7 +33,6 @@ indicates the features supported by the GPU **hardware** (not to be confused wit > 8 = Ampere - ### Call kernel with <<> **(num_blocks, num_threads can be 1d/2d/3d)** @@ -69,7 +64,6 @@ About how to decide the `N_THREAD` or `block_size` [here](https://stackoverflow. * usually, tune it from `[128, 1024]` with a stride of 32. - ### Built-ins ```c @@ -84,7 +78,6 @@ dim3 Dim3(x=1, y=1, z=1); ``` - ### One-dimensional example ```c @@ -143,7 +136,6 @@ vector_add<<>>(d_out, d_a, d_b, N); ``` - ### Two-dimensional example ```c @@ -162,7 +154,6 @@ MatAdd<<>>(A, B, C); ``` - ### [Function prefix](https://stackoverflow.com/questions/12373940/difference-between-global-and-device-functions) Concepts: host (cpu), device (gpu, ...) @@ -180,7 +171,6 @@ global & device function cannot: * variable number of arguments. - ### Memory Location ```c @@ -203,7 +193,6 @@ int RegArr[10]; // local memory ``` - ### MatMul Example with shared memory ```c @@ -335,7 +324,6 @@ void MatMul(const Matrix A, const Matrix B, Matrix C) { ``` - ### Optimize Pointer Aliasing ```c @@ -364,7 +352,6 @@ __global__ void example3b(const float* __restrict__ a, float* __restrict__ b, co ``` - ### Stream The default stream (0) : No concurrency. @@ -411,7 +398,6 @@ nvcc --default-stream per-thread ./stream_test.cu -o stream_per_thread ``` - ### Array unfold In cuda, tensors are usually flattened for parallel. @@ -431,9 +417,6 @@ farr = arr.view(-1) [3n,] Usually, to access `arr[i, j, k]`, we need `farr[i*(J+K) + j*K + k]` - - - ### Atomic Operators these functions are guaranteed to be performed without interference from other threads. @@ -452,7 +435,6 @@ int atomicXor(int* address, int val); ``` - ### Pragma unroll ```c++ @@ -471,7 +453,6 @@ a[2] = 2; ``` - ### compute capability > 实际架构代码必须兼容于虚拟架构代码。在运行时,若二进制代码可直接运行在所在显卡上,则直接运行二进制代码;否则,若文件中包含虚拟架构代码,显卡驱动会尝试将虚拟架构代码在编译时动态编译为二进制代码进行执行。 @@ -500,15 +481,11 @@ Some abbreviations: ``` - ### compilation in detail ![img](basics.assets/cuda-compilation-from-cu-to-executable.png) - - - ### [Print from kernel](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#formatted-output) First, use `--gpu-architecture > 20` (this is default to `compute_10`) @@ -537,7 +514,6 @@ __global__ void helloCUDA(float f) { ``` - ### [CUDA memory check](https://stackoverflow.com/questions/27277365/unspecified-launch-failure-on-memcpy/27278218#27278218) Useful tool to debug `cuda illegal memory access`. @@ -582,9 +558,6 @@ const float density = grid[index]; ``` - - - ### template cuda provides `AT_DISPATCH_FLOATING_TYPES` to automatically dispatch & cast type for every input. @@ -662,7 +635,6 @@ static inline __device__ at::Half gpuAtomicAdd(at::Half *address, at::Half val) However, `__half` atomicAdd is extremely slow compared to `float` or `__half2`. Usually a better choice is to not use it at all. - ### Cuda example: find max value & index in an array https://www.apriorit.com/dev-blog/614-cpp-cuda-accelerate-algorithm-cpu-gpu diff --git a/docs/cuda/gpu_to_arch.md b/docs/cuda/gpu_to_arch.md index d07c2a00f..cff1ba25c 100644 --- a/docs/cuda/gpu_to_arch.md +++ b/docs/cuda/gpu_to_arch.md @@ -13,7 +13,6 @@ reference: https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-vario ** Hopper is NVIDIA’s rumored “tesla-next” series, with a 5nm process. - ### Fermi cards (CUDA 3.2 until CUDA 8) Deprecated from CUDA 9, support completely dropped from CUDA 10. diff --git a/docs/cuda/nsight-sys.md b/docs/cuda/nsight-sys.md index 5e4013651..ce5b079c6 100644 --- a/docs/cuda/nsight-sys.md +++ b/docs/cuda/nsight-sys.md @@ -26,7 +26,6 @@ sudo sh -c 'echo 1 >/proc/sys/kernel/perf_event_paranoid' ``` - ### Usage Pretty simple, just start the GUI, choose new project, and enter the **command line** that starts your program. diff --git a/docs/cuda/project_layout.md b/docs/cuda/project_layout.md index 3b3471ad5..730307fa4 100644 --- a/docs/cuda/project_layout.md +++ b/docs/cuda/project_layout.md @@ -21,7 +21,6 @@ setup.py # build C side and install python side ``` - ### Implement Function in CPP This is much easier. @@ -35,7 +34,6 @@ We can handle memory allocation in python side, and only pass data pointer to C * write `setup.py` to build everything. - ### Implement Class in CPP We need to let C side hold data structures and maybe allocate memory! This becomes harder... @@ -43,14 +41,8 @@ We need to let C side hold data structures and maybe allocate memory! This becom For example, we'll need to convert data pointer to custom `struct` or `class`. - - - ### Header Source Separation - - - ### Example diff --git a/docs/cuda/runtime.md b/docs/cuda/runtime.md index 3c09d3cb6..87dfbf195 100644 --- a/docs/cuda/runtime.md +++ b/docs/cuda/runtime.md @@ -82,6 +82,3 @@ int main() { ``` - - - diff --git a/docs/cuda/thrust.md b/docs/cuda/thrust.md index 4db0d3929..cffe1bdb2 100644 --- a/docs/cuda/thrust.md +++ b/docs/cuda/thrust.md @@ -44,7 +44,6 @@ int main(void) { ``` - ### Algorithms Thrust algorithms will auto detect host/device and run the correct version. @@ -146,7 +145,6 @@ float norm = std::sqrt(thrust::transform_reduce(d_x.begin(), d_x.end(), square>()); // return ``` - diff --git a/docs/cuda/triton.md b/docs/cuda/triton.md index dacac8f6e..6191df22a 100644 --- a/docs/cuda/triton.md +++ b/docs/cuda/triton.md @@ -11,7 +11,6 @@ pip install -e . ``` - ### Questions * **how to debug, e.g., print from kernel?** @@ -98,7 +97,6 @@ Some differences from writing CUDA : * We don't use `N_THREAD`, instead, we use `BLOCK_SIZE = N / N_THREAD`. - parallel-on-batch-dim example (softmax): ```python @@ -178,7 +176,6 @@ benchmark.run(show_plots=False, print_data=True) ``` - > TODO: Matrix-multiplication example: diff --git a/docs/cuda/utils.md b/docs/cuda/utils.md index bfa599e35..cc83511bd 100644 --- a/docs/cuda/utils.md +++ b/docs/cuda/utils.md @@ -276,9 +276,6 @@ static inline __device__ void atomMin(double *address, double val) { ``` - - - ### `atomicAdd` for `at::Half` ```cpp @@ -290,9 +287,6 @@ static inline __device__ at::Half atomicAdd(at::Half *address, at::Half val) { ``` - - - ### `atomicMax` for `at::Half, float, double` ```cpp diff --git a/docs/cuda/vector_utils.md b/docs/cuda/vector_utils.md index f516aa37c..615303208 100644 --- a/docs/cuda/vector_utils.md +++ b/docs/cuda/vector_utils.md @@ -213,6 +213,3 @@ template static __device__ __forceinline__ void swap(T& a, T& b) ``` - - - diff --git a/docs/deeplearning/autodiff_understand.md b/docs/deeplearning/autodiff_understand.md index 3d6ce9394..bd5765895 100644 --- a/docs/deeplearning/autodiff_understand.md +++ b/docs/deeplearning/autodiff_understand.md @@ -1,7 +1,6 @@ # autodiff - ### Concepts ![autodiff](autodiff_understand.assets/torch_autodiff.png) @@ -9,7 +8,6 @@ ![image-20211218131323609](autodiff_understand.assets/image-20211218131323609.png) - * `x.is_leaf` whether tensor `x` is a leaf node, i.e., `x.grad_fn == None` (is not created via a `Function` operation / is the leaf nodes in the DAG). @@ -93,14 +91,12 @@ ``` - * `x.detach()` create a new tensor (but not copy data) from `x`, and set `requires_grad = False`. (which also means `is_leaf == True`). note that `x.clone()` will copy data but remains the gradient to the original tensor (thus `is_leaf == False`). - * `with torch.no_grad():` temporarily disable all DAG recording (and thus cannot call `backward()`), i.e., behave as if no inputs requires grad. @@ -136,7 +132,6 @@ similar to `with torch.no_grad()/enable_grad():`. - * `x.retain_grad()` `x` must be a non-leaf tensor to call this before `backward()`, so `x` will keep its `grad` (as the leaf tensors that requires grad). @@ -144,8 +139,6 @@ the state can be checked by `x.retains_grad`, which is a boolean flag. - - * `torch.autograd.grad(outputs, inputs, grad_outputs=None, retain_graph=None, create_graph=False)` a way to manually compute and get the gradients. @@ -167,7 +160,6 @@ ``` - Full Examples: ```python diff --git a/docs/deeplearning/background_removal.md b/docs/deeplearning/background_removal.md index e837eb95d..52bfb0d56 100644 --- a/docs/deeplearning/background_removal.md +++ b/docs/deeplearning/background_removal.md @@ -19,9 +19,6 @@ remove_folder(input_folder, output_folder, return_mask=True) ``` - - - ### [Carvekit](https://github.com/OPHoperHPO/image-background-remove-tool) ```bash @@ -99,7 +96,6 @@ for img_path in tqdm.tqdm(img_paths): ``` - ### [Rembg](https://github.com/danielgatis/rembg) best quality. @@ -113,7 +109,6 @@ rembg p input_folder output_folder ``` - ```python from rembg import remove import cv2 @@ -128,9 +123,6 @@ cv2.imwrite('output.png', output) ``` - - - ### [BackgroundRemover](https://github.com/nadermx/backgroundremover) better than carvekit, but slightly worse than rembg. diff --git a/docs/deeplearning/diffusion_models.md b/docs/deeplearning/diffusion_models.md index 348635212..512885baf 100644 --- a/docs/deeplearning/diffusion_models.md +++ b/docs/deeplearning/diffusion_models.md @@ -4,15 +4,21 @@ The forward process can be described with a sequence of gaussian distributions: + $$ +\displaylines{ q(x_t|x_{t-1})=\mathcal N(x_t; \sqrt{1 - \beta_t}x_{t-1}, \beta_tI) +} $$ + Assume $$\beta_t$$ is the weight for gaussian noise (variance) at step $$t$$, and $$\alpha_t = 1 - \beta_t,~ \bar\alpha_t= \prod_{i=1}^t\alpha_i$$. The forward step gradually adds **a sequence of gaussian noise** $\{\epsilon_t\} \sim \mathcal N(0, I)$ to the **real image** $x_0$, so the corrupted image at step $t$ is: + $$ +\displaylines{ \begin{aligned} x_t &= \sqrt{\alpha_t}x_{t-1}+ \sqrt{1-\alpha_t}\epsilon_{1} \\ &= \sqrt{\alpha_t}(\sqrt{\alpha_{t-1}}x_{t-2}+ \sqrt{1-\alpha_{t-1}}\epsilon_{2})+ \sqrt{1-\alpha_t}\epsilon_{1} \\ @@ -21,16 +27,21 @@ x_t &= \sqrt{\alpha_t}x_{t-1}+ \sqrt{1-\alpha_t}\epsilon_{1} \\ &= \cdots \\ &= \sqrt{\bar \alpha_{t}}x_{0}+\sqrt{1-\bar \alpha_{t}} \epsilon_{t} \\ \end{aligned} +} $$ + Note that two independent gaussian noise $\epsilon_{1}, \epsilon_{2}$ can be merged into one: + $$ +\displaylines{ \mathcal N(0, {\alpha_t(1-\alpha_{t-1})})+\mathcal N(0, {1-\alpha_{t}}) \rightarrow \mathcal N(0, {1-\alpha_t\alpha_{t-1}}) +} $$ -**This means we can express any $x_t$ with $x_0$, $\{\beta_1, \beta_2, \cdots, \beta_t\}$, and a random noise $\epsilon_{t}$.** +**This means we can express any $x_t$ with $x_0$, $\{\beta_1, \beta_2, \cdots, \beta_t\}$, and a random noise $\epsilon_{t}$.** ### The backward pass (noise to image) @@ -39,35 +50,50 @@ Given $$x_{t}$$, we want to get $$x_{t-1}$$, and eventually restore the real ima **It's proven that if $\beta_t$ is small enough, the backward process is also a sequence of gaussian.** + $$ +\displaylines{ q(x_{t-1}|x_t) = \mathcal N(x_{t-1}; \tilde\mu_t(x_t, t), \tilde\beta_tI) +} $$ + which gives the denoising step with **another sequence of gaussian noise** $\{z_t\} \sim \mathcal N(0, I)$: + $$ +\displaylines{ x_{t-1} = \tilde\mu_t(x_t, t)+\tilde \beta_t z_t +} $$ + Through some math we could get: + $$ +\displaylines{ \tilde\beta_t = \frac {1 - \bar \alpha_{t-1}} {1 - \bar \alpha_{t}} \beta_t\\ \tilde\mu_t(x_t, t)=\frac {1} {\sqrt{\alpha_t}} (x_t-\frac{1-\alpha_t}{\sqrt{1-\bar \alpha_t}}\epsilon_t) +} $$ + Note that here **$\epsilon_t$ is the exact noise added in the forward step!** And **all we need is a neural network that predicts this noise $\epsilon_t$ given $x_t(x_0, t) = \sqrt{\bar \alpha_{t}}x_{0}+\sqrt{1-\bar \alpha_{t}}\epsilon_t$**. Assume the predicted noise is $\epsilon_\theta$, we need to minimize the following loss: + $$ +\displaylines{ \mathcal L=\mathbb E_{t,x_0,\epsilon_t}||\epsilon_t -\epsilon_\theta(x_0, t)||^2 +} $$ -The neural network is usually an **U-Net with attention** since we need same-size output as input. +The neural network is usually an **U-Net with attention** since we need same-size output as input. ### DDPM (Denoising Diffusion Probabilistic Model) @@ -79,26 +105,33 @@ Note that DDPM use $\tilde \beta_t = \beta_t$ as an approximation. ![image-20221212213705784](diffusion_models.assets/image-20221212213705784.png) - ### DDIM (Denoising Diffusion Implicit Model) DDIM use a different formula for the backward step: + $$ +\displaylines{ \begin{aligned} x_{t-1} &= \sqrt{\bar \alpha_{t-1}}x_{0}+\sqrt{1-\bar \alpha_{t-1}} \epsilon_{t-1} \\ &= \sqrt{\bar \alpha_{t-1}}x_{0}+\sqrt{1-\bar \alpha_{t-1} -\sigma_t^2} \epsilon_{t} +\sigma_t z_t \\ &= \sqrt{\bar \alpha_{t-1}}x_{0}+\sqrt{1-\bar \alpha_{t-1} -\sigma_t^2} \frac {x_t-\sqrt{\alpha_t}x_0}{\sqrt{1-\alpha_t}} +\sigma_t z_t \\ \end{aligned} +} $$ + According to $x_{t-1} = \tilde\mu_t(x_t, t)+\tilde \beta_t z_t$, we have + $$ +\displaylines{ \tilde\mu_t(x_t, t)=\sqrt{\bar \alpha_{t-1}}x_{0}+\sqrt{1-\bar \alpha_{t-1} -\sigma_t^2} \frac {x_t-\sqrt{\alpha_t}x_0}{\sqrt{1-\alpha_t}} \\ \tilde\beta_t = \sigma_t^2= \frac {1 - \bar \alpha_{t-1}} {1 - \bar \alpha_{t}} \beta_t +} $$ + Another hyper-parameter $\eta \ge 0$ is introduced as $\eta \tilde \beta_t = \sigma_t^2$. DDPM usually requires $T=1000$ steps for both training and inference ($S = T = 1000$), which makes generation (inference) too slow. @@ -106,7 +139,6 @@ DDPM usually requires $T=1000$ steps for both training and inference ($S = T = 1 To speed up inference, DDIM use strided sampling where $S 0$ scales regularization. * all lead to convex fitting problems. - # Constructive Convex Analysis & DCP ### Convex Optimization ##### Conic form + $$ +\displaylines{ minimize\ c^Tx \\ subject\ to\ Ax=b,\ x\in K +} $$ + - $x \in R^n$ - $K$ is convex cone. - linear objective, equality constraints. @@ -116,7 +121,6 @@ $$ - has the form $f(x) = a^Tx+b$ - ##### Basic convex functions - $x^p,\ p\ge1\ or\ p\le 0$ @@ -137,7 +141,6 @@ Less basic ones: - $\lambda_{max}(X), X=X^T$ - ##### Basic concave functions - $x^p,\ 0 \le p\le 1$ @@ -151,7 +154,6 @@ Less basic ones: - $\lambda_{min}(X), X=X^T$ - ##### Calculus rules that keeps convexity - nonnegative scaling @@ -171,12 +173,15 @@ Less basic ones: - $f_i$ is affine - eg. show the following function is convex: + $$ +\displaylines{ f(u, v) = (u+1)log(\frac {u+1}{min(u,v)}) +} $$ + ##### Constructive Convexity verification view the function as an expression tree, and use the general composition rule to determine the convexity. @@ -186,7 +191,6 @@ sufficient, but not necessary for convexity. - $f(x)=\sqrt{1+x^2}$ is convex, but can't be proved by Constructive Convexity verification. - ### Disciplined Convex Program (DCP) framework for describing convex optimization problems based on constructive convex analysis. @@ -212,6 +216,3 @@ DCP is very easy to build a parser/analyzer, and be transformed to cone form, th CVXPY will raise error if the constraints not obey the DCP rules. - - - diff --git a/docs/deeplearning/old/RAPIDS_tutorial.md b/docs/deeplearning/old/RAPIDS_tutorial.md index c8f461897..f4464b2c7 100644 --- a/docs/deeplearning/old/RAPIDS_tutorial.md +++ b/docs/deeplearning/old/RAPIDS_tutorial.md @@ -5,7 +5,6 @@ GPU DataFrame. - ### cuml Machine Learning Algorithms. @@ -27,7 +26,6 @@ Machine Learning Algorithms. ``` - ##### k-Means ```python @@ -40,7 +38,6 @@ train.head() ``` - ##### T-SNE ```python diff --git a/docs/deeplearning/old/datatable_tutorial.md b/docs/deeplearning/old/datatable_tutorial.md index 905b5deb5..eff14599b 100644 --- a/docs/deeplearning/old/datatable_tutorial.md +++ b/docs/deeplearning/old/datatable_tutorial.md @@ -5,7 +5,6 @@ import datatable as dt ``` - ### Load ```python @@ -20,7 +19,6 @@ dt.fread(data, sep=None, header=None, fill=False, skip_blank_lines=False, column ``` - ### Properties ```python @@ -30,17 +28,16 @@ DT.stypes # column types ``` - - - ### Data Manipulation + $$ +\displaylines{ DT[i, j, by(), sort(), join()] +} $$ - ```python # selector DT[i, j] = 1 # [row, col, ...] @@ -99,7 +96,6 @@ DT[:, :, sort(f.A)] ``` - ### Save ```python diff --git a/docs/deeplearning/old/feature_engineering.md b/docs/deeplearning/old/feature_engineering.md index 58600c77a..7b866900b 100644 --- a/docs/deeplearning/old/feature_engineering.md +++ b/docs/deeplearning/old/feature_engineering.md @@ -1,9 +1,6 @@ # Feature Engineering - - - ```python ### Label Encoding from sklearn import preprocessing diff --git a/docs/deeplearning/old/k_means_tutorial.md b/docs/deeplearning/old/k_means_tutorial.md index 351aba1ec..b9c165d2f 100644 --- a/docs/deeplearning/old/k_means_tutorial.md +++ b/docs/deeplearning/old/k_means_tutorial.md @@ -97,7 +97,6 @@ other uses: ``` - ### k-means++ select the initial centroids as far as possible: @@ -116,7 +115,6 @@ def ppCent(data, k, dist=squareEucliDist): ``` - #### (Weighted) Kernel k-means One limit for k-means is that it always cluster by a hyperplane. @@ -124,22 +122,26 @@ One limit for k-means is that it always cluster by a hyperplane. So we can use a transfer function $\phi()$ to transfer each data vector into a higher dimension, then apply traditional k-means. Besides, we can also add weight for each data vector. + $$ +\displaylines{ \sum_{c=1}^{k}\sum_{a_i \in \pi_c} w_i||\phi(a_i) - m_c||^2 +} $$ + Further more, if we simply expand the $l2$ norm, we notice that we even needn't knowing the explicit form of $\phi()$ to compute this norm. All we need is a Kernel Matrix $K$, where $K_{ij} = \phi(a_i)\phi(a_j)$ for example, a polynomial $K$ can be defined as: + $$ +\displaylines{ K_{ij} = (a_i \cdot a_j + c)^d +} $$ - - - #### Spherical k-means Used in document clustering, replace Euclidean Distance with Cosine Distance. diff --git a/docs/deeplearning/old/keras_tutorial.md b/docs/deeplearning/old/keras_tutorial.md index b5f0d385b..e752bb2d6 100644 --- a/docs/deeplearning/old/keras_tutorial.md +++ b/docs/deeplearning/old/keras_tutorial.md @@ -11,7 +11,6 @@ > In Tensorflow 2.0 `tf.keras` will be the default and I highly recommend to start working using `tf.keras` - ### Model ##### Sequential @@ -86,7 +85,6 @@ def build_densenet(): ``` - ### Data Loaders ```python @@ -147,7 +145,6 @@ class DataGenerator(keras.utils.Sequence): ``` - ### Preprocess ```python @@ -184,7 +181,6 @@ for e in range(epochs): ``` - ### Callbacks ##### Built-ins @@ -223,7 +219,6 @@ class MyCallback(keras.callbacks.Callback): ``` - ### Custom Metrics ```python @@ -242,7 +237,6 @@ model.compile(optimizer='rmsprop', ``` - ### Custom Losses ```python @@ -265,7 +259,6 @@ model.compile(loss=dice_loss(smooth=0.001)) ``` - ### Custom Layers ```python @@ -309,7 +302,6 @@ class MyLayer(Layer): ``` - ### Examples ```python diff --git a/docs/deeplearning/old/meshlab_tutorial.md b/docs/deeplearning/old/meshlab_tutorial.md index 7e453ee88..732dca1ca 100644 --- a/docs/deeplearning/old/meshlab_tutorial.md +++ b/docs/deeplearning/old/meshlab_tutorial.md @@ -17,7 +17,6 @@ can only use the RGB to color. - ### Codelet ```python diff --git a/docs/deeplearning/old/pytorch_API.md b/docs/deeplearning/old/pytorch_API.md index d25e9cbb7..71cc76043 100644 --- a/docs/deeplearning/old/pytorch_API.md +++ b/docs/deeplearning/old/pytorch_API.md @@ -335,7 +335,6 @@ interpolate(input, size=None, scale_factor=None, mode="nearest", align_corners=N ``` - ### torch.optim ```python diff --git a/docs/deeplearning/old/pytorch_tutorial.md b/docs/deeplearning/old/pytorch_tutorial.md index 314df7a67..9dd0b8ddc 100644 --- a/docs/deeplearning/old/pytorch_tutorial.md +++ b/docs/deeplearning/old/pytorch_tutorial.md @@ -42,7 +42,6 @@ torch.cat((A, B), dim=1) ``` - ### autograd ```python @@ -68,13 +67,15 @@ print(x.grad) # 4.5 ``` + $$ +\displaylines{ out = \frac {3}{4} \sum (x + 2)^2 \\ \frac {\partial out}{\partial x_i} = \frac{3}{2}(x+2) = 4.5 +} $$ - ### Neural Network Affine Layer: Fully connected layer. @@ -235,7 +236,6 @@ def weights_init(m): ``` - #### Low level functional ```python @@ -260,7 +260,6 @@ F.cross_entropy(input, target, weight=None, size_average=True) ``` - ### dataset & torchvision ```python @@ -390,7 +389,6 @@ print('Accuracy of the network on the 10000 test images: %d %%' % ( ``` - ### Save Model ```python @@ -426,5 +424,4 @@ model.eval() ``` - ### torchvision transforms diff --git a/docs/deeplearning/old/scipy.sparse_API.md b/docs/deeplearning/old/scipy.sparse_API.md index 774d2b1b1..bcfb0146a 100644 --- a/docs/deeplearning/old/scipy.sparse_API.md +++ b/docs/deeplearning/old/scipy.sparse_API.md @@ -80,4 +80,3 @@ eigsh(A[, k]) # fast for real sym mat ``` - diff --git a/docs/deeplearning/old/sklearn_API.md b/docs/deeplearning/old/sklearn_API.md index a7b1fef69..bebfb801a 100644 --- a/docs/deeplearning/old/sklearn_API.md +++ b/docs/deeplearning/old/sklearn_API.md @@ -44,7 +44,6 @@ RandomForestClassifier() ``` - #### feature_extraction #### linear_model @@ -57,7 +56,6 @@ RandomForestClassifier() ``` - #### metrics * classification metrics @@ -157,7 +155,6 @@ df[col+"_scaled"] = scaler.fit_transform(df[col].values.reshape(-1,1)) ``` - #### svm #### tree diff --git a/docs/deeplearning/old/sklearn_tutorial.md b/docs/deeplearning/old/sklearn_tutorial.md index 962b904a2..308d4e4df 100644 --- a/docs/deeplearning/old/sklearn_tutorial.md +++ b/docs/deeplearning/old/sklearn_tutorial.md @@ -72,7 +72,9 @@ * Linear regression model: + $$ +\displaylines{ y = Xw + \epsilon \\ J(w) = min_w||Xw-y||^2 \\ @@ -81,6 +83,7 @@ $$ in \ fact \ we \ can \ solve \ it: \\ w = (X'X)^{-1}X'y +} $$ @@ -98,12 +101,16 @@ $$ LR is very **sensitive to noise**, so RR is designed to improve this. + $$ +\displaylines{ J(W) = min_w\{||Xw-y||^2 + \alpha||w||^2\} +} $$ + so we can set an $\alpha$ to avoid $w$ being so big and thus too sensitive. $\alpha||w||^2$ is called the regularization. @@ -232,4 +239,3 @@ $$ separate a multivariate signal into additive subcomponents that are maximally independent. - diff --git a/docs/deeplearning/old/sklearn_user_guide.md b/docs/deeplearning/old/sklearn_user_guide.md index d9ceaffa7..1548ad989 100644 --- a/docs/deeplearning/old/sklearn_user_guide.md +++ b/docs/deeplearning/old/sklearn_user_guide.md @@ -4,10 +4,13 @@ * Ordinary Least Squares + $$ +\displaylines{ argmin_w\{||Xw+b-y||_2^2\} +} $$ @@ -20,10 +23,13 @@ $$ * Ridge Regression + $$ +\displaylines{ argmin_w\{||Xw+b-y||_2^2+\alpha||w||_2^2\} +} $$ @@ -36,10 +42,13 @@ $$ * Lasso Regression + $$ +\displaylines{ argmin_w\{\frac{1}{2N}||Xw+b-y||_2^2 + \alpha||w||_1\} +} $$ @@ -57,10 +66,13 @@ $$ we can use L1 or L2 norm for regularization. + $$ +\displaylines{ argmin_{w,b}\{\frac 1 2 ||w||_2 + C\sum_{i=1}^nlog(exp(-y_i(X_i^Tw+b))+1)\} +} $$ diff --git a/docs/deeplearning/old/tensorflow_API.md b/docs/deeplearning/old/tensorflow_API.md index 103a16e70..980d6aada 100644 --- a/docs/deeplearning/old/tensorflow_API.md +++ b/docs/deeplearning/old/tensorflow_API.md @@ -46,10 +46,13 @@ * MAPE (percentage error) + $$ +\displaylines{ MAPE = \frac{1}{n}\sum_{i=1}^n|\frac{\hat y - y_i}{y_i}| +} $$ @@ -57,10 +60,13 @@ $$ binary classification with sigmoid. + $$ +\displaylines{ L = -\sum_{i=1}^n(y_ilog(\hat y) + (1-y_i)log(1-\hat y)) +} $$ @@ -68,16 +74,16 @@ $$ multiple classification with one_hot + softmax. + $$ +\displaylines{ L = -\sum_{i=1}^n\sum_{t=1}^c(y_{i,t}log\hat y_t) +} $$ - - - #### tensorflow ```python @@ -189,7 +195,6 @@ GradientDescentOptimizer(learning_rate) ``` - #### layers An encapsulation of `tf.nn `. @@ -252,7 +257,6 @@ average_pooling2d() ``` - #### nn ```python @@ -402,12 +406,6 @@ model.save("full_model.h5") ``` - #### summary - - - - - diff --git a/docs/deeplearning/pandas_tutorial.md b/docs/deeplearning/pandas_tutorial.md index 43ac6f5ef..103bcd204 100644 --- a/docs/deeplearning/pandas_tutorial.md +++ b/docs/deeplearning/pandas_tutorial.md @@ -8,7 +8,6 @@ import pandas as pd ``` - ### IO ```python @@ -20,9 +19,6 @@ df.to_csv(path, header=False, index=False) # do not write row and column names ( ``` - - - ### Data Structure ##### Series (Ordered, Indexed, Homogenous, One-Dimensional) @@ -80,7 +76,6 @@ df = pd.read_excel(io, sheetname=0, header=0) ``` - ### Manipulate Data ##### Series @@ -123,7 +118,6 @@ s.unique() ``` - ##### DataFrame ```python @@ -185,7 +179,6 @@ df[df['list'].str.len() > 0] ``` - ### Conditioned Query ```python @@ -196,7 +189,6 @@ df.loc[df.price.notnull()] # or isnull() ``` - ### Grouping and Sorting ```python @@ -221,9 +213,6 @@ Parrot 25.0 ``` - - - ### Missing values ```python @@ -259,7 +248,6 @@ def impute(train, columns, test=None): ``` - ### Melting ```python @@ -332,7 +320,6 @@ two 4 5 6 ``` - ### Merging ```python @@ -341,7 +328,6 @@ pd.merge(left, right, how='inner', on=None) ``` - ### Options ```python @@ -357,7 +343,6 @@ pd.reset_option(key) ``` - ### Others ```python @@ -374,4 +359,3 @@ df.pipe(func, *args, **kwargs) ``` - diff --git a/docs/deeplearning/pytorch_cpp_extension.md b/docs/deeplearning/pytorch_cpp_extension.md index b1f404e14..cf7d9d073 100644 --- a/docs/deeplearning/pytorch_cpp_extension.md +++ b/docs/deeplearning/pytorch_cpp_extension.md @@ -1,7 +1,6 @@ # Custom C++ & CUDA extensions - ## Pitfalls * always check the input tensor is `contiguous` !!! @@ -11,7 +10,6 @@ * - ## Bindings ### Ahead of Time (setup) @@ -106,9 +104,6 @@ print(add(one, one)) ``` - - - ### Just in Time (load) Better use this. @@ -166,9 +161,6 @@ class Add(nn.Module): ``` - - - ## Torch C++ API ### Header @@ -179,7 +171,6 @@ class Add(nn.Module): ``` - ### ATen A Tensor Library for CPU & GPU. Not differentiable. @@ -211,7 +202,6 @@ at::device(a.device()).dtype(at::ScalarType::Int)); ``` - ### C++ Frontend high level library providing CPU & GPU tensor support with automatic differentiation. diff --git a/docs/deeplearning/pytorch_grad.md b/docs/deeplearning/pytorch_grad.md index 0a1bec78b..163e47259 100644 --- a/docs/deeplearning/pytorch_grad.md +++ b/docs/deeplearning/pytorch_grad.md @@ -28,7 +28,6 @@ print(x.is_leaf) # True. see below. ``` - ### leaf A node is leaf if: @@ -40,7 +39,6 @@ A node is leaf if: Gradients are only populated to tensors with both `required_grad` and `is_leaf` are `True`. - ### backward backward will calculate the target tensor's gradients w.r.t all is_leaf and requires_grad tensors. @@ -54,9 +52,6 @@ z.backward(torch.Tensor([1.0 ,1.0 ,1.0])) ``` - - - ### dynamic computation graph A DAG to track gradient flow. @@ -77,12 +72,9 @@ print(x.grad.data) ``` - ![](https://miro.medium.com/max/589/1*viCEZbSODfA8ZA4ECPwHxQ.png) - ### [Implement a simple `autograd`](https://github.com/mattjj/autodidact) - diff --git a/docs/deeplearning/pytorch_internals.md b/docs/deeplearning/pytorch_internals.md index b3be4906b..ffcd9ae6b 100644 --- a/docs/deeplearning/pytorch_internals.md +++ b/docs/deeplearning/pytorch_internals.md @@ -66,7 +66,6 @@ def is_contiguous(stride): * dtype: int, float, ... - ### Source Structure ```bash @@ -94,7 +93,6 @@ Then you should write kernels as the real implementation. You'll need to `dispatch` based on `dtype`, and implement each (or use template). - ### Workflow efficiency * Editing headers sparingly, since it may cause re-compilation of lots of files... diff --git a/docs/deeplearning/roc_auc_understand.md b/docs/deeplearning/roc_auc_understand.md index e71bfff8f..2b88d6f8b 100644 --- a/docs/deeplearning/roc_auc_understand.md +++ b/docs/deeplearning/roc_auc_understand.md @@ -3,7 +3,6 @@ A metric traditionally used for binary classification task. - ### sklearn API ```python @@ -18,23 +17,23 @@ auc = metrics.auc(fpr, tpr) ``` - ### Great Illustration ![image-20200717212241528](roc_auc_understand.assets/image-20200717212241528.png) - ### Receiver Operation Curve A graphic plot metric for binary classifier. $$ +\displaylines{ \begin{eqnarray} TPR = \frac{TP}{P}=\frac {TP}{TP+FN} \\ FPR = \frac{FP}{N}=\frac {FP}{FP+TN} \\ \end{eqnarray} +} $$ @@ -45,13 +44,11 @@ We need a threshold $T$ to determine whether the prediction is positive or negat ROC curve plots parametrically $TPR(T)$ vs. $FPR(T)$. - ### Area Under the Curve Use $TPR$ as y axis and $FPR$ as x axis. - ### Self Implementations ```python diff --git a/docs/deeplearning/spark/dataframe.md b/docs/deeplearning/spark/dataframe.md index 908ab4d9b..76cd8a4ca 100644 --- a/docs/deeplearning/spark/dataframe.md +++ b/docs/deeplearning/spark/dataframe.md @@ -1,7 +1,6 @@ # Spark SQL - ```python from pyspark.sql import SparkSession diff --git a/docs/deeplearning/wordcloud.md b/docs/deeplearning/wordcloud.md index 54e3a90bf..9598e641f 100644 --- a/docs/deeplearning/wordcloud.md +++ b/docs/deeplearning/wordcloud.md @@ -5,7 +5,6 @@ pip install wordcloud ``` - ### CLI ``` @@ -13,7 +12,6 @@ wordcloud_cli --text mytext.txt --imagefile wordcloud.png ``` - ### API ```python @@ -30,7 +28,6 @@ plt.show() ``` - ``` Parameters ---------- diff --git a/docs/docker/compose.md b/docs/docker/compose.md index 114d71f6b..dfddff56f 100644 --- a/docs/docker/compose.md +++ b/docs/docker/compose.md @@ -10,7 +10,6 @@ sudo chmod +x /usr/local/bin/docker-compose ``` - ### usage Run multiple containers (service) within one config (project). diff --git a/docs/docker/cuda.md b/docs/docker/cuda.md index f0b6aee5b..46512848b 100644 --- a/docs/docker/cuda.md +++ b/docs/docker/cuda.md @@ -24,7 +24,6 @@ docker run --rm --gpus all nvidia/cuda:10.2-base nvidia-smi ``` - Note: * Always monitor in host by `nvidia-smi`. In container it will not display correctly. diff --git a/docs/docker/display.md b/docs/docker/display.md index 32ef412dd..ab79cde39 100644 --- a/docs/docker/display.md +++ b/docs/docker/display.md @@ -24,5 +24,4 @@ CMD glmark2 ``` - > NO success yet, to be continued... \ No newline at end of file diff --git a/docs/docker/docker.md b/docs/docker/docker.md index 74fc3f730..17a3e1d12 100644 --- a/docs/docker/docker.md +++ b/docs/docker/docker.md @@ -38,7 +38,6 @@ sudo usermod -aG docker $USER ``` - ### mirrors Add in `/etc/docker/daemon.json`: @@ -58,7 +57,6 @@ sudo systemctl restart docker ``` - ### command line * get image from docker hub: @@ -241,7 +239,6 @@ sudo systemctl restart docker - ### Dockerfile To build an image, we should first create an empty folder and create a `Dockerfile`: diff --git a/docs/graphics/101_rasterization.md b/docs/graphics/101_rasterization.md index aa69e429e..39587895d 100644 --- a/docs/graphics/101_rasterization.md +++ b/docs/graphics/101_rasterization.md @@ -9,7 +9,6 @@ When rasterize triangles, we need to solve the visibility/occlusion problem. store an extra z-value for each pixel to represent the depth. (convention: positive, the larger the further, in fact it can be viewed as the depth.) - ```c++ static bool insideTriangle(int x, int y, const Vector4f* _v){ Vector3f v[3]; diff --git a/docs/graphics/102_shading.md b/docs/graphics/102_shading.md index 80e0c32fd..842e0e68f 100644 --- a/docs/graphics/102_shading.md +++ b/docs/graphics/102_shading.md @@ -7,23 +7,28 @@ ![image-20210314200305193](shading.assets/image-20210314200305193.png) - ##### Ambient Term Not depend on anything. Just a constant environment light. + $$ +\displaylines{ L_a = k_aI_a +} $$ ##### Diffuse Term (Lambertian) depend on light direction, independent of view direction. + $$ +\displaylines{ L_d = k_d\frac I {r^2} \max(0, \mathbf n\cdot \mathbf l) +} $$ -where $k_d$ is a coefficient, $\frac I {r^2}$ is the energy received at radius $r$. $\mathbf n\cdot \mathbf l = \cos \alpha$ (assume unit vector.) +where $k_d$ is a coefficient, $\frac I {r^2}$ is the energy received at radius $r$. $\mathbf n\cdot \mathbf l = \cos \alpha$ (assume unit vector.) ##### Specular Term (Blinn-Phong, the highlight) @@ -31,16 +36,19 @@ where $k_d$ is a coefficient, $\frac I {r^2}$ is the energy received at radius $ depends on both light direction and view direction. Brighter near Mirror reflection direction (defined as $r$) + $$ +\displaylines{ \mathbf h = \frac {\mathbf v + \mathbf l} {||\mathbf v + \mathbf l||} \\ L_s = k_s \frac I {r^2} \max(0, \mathbf n\cdot \mathbf h)^p +} $$ + where $p$ is a coefficient to control the highlight's area (the larger $p$, the smaller highlight region). note we have $2 = $. - ```c++ // example of blinn-phong shading with texture mapping. Eigen::Vector3f texture_fragment_shader(const fragment_shader_payload& payload) @@ -93,15 +101,9 @@ Eigen::Vector3f texture_fragment_shader(const fragment_shader_payload& payload) ``` - - - ![image-20210314200203442](shading.assets/image-20210314200203442.png) - - - ### Shading Frequency ![image-20210314200644548](shading.assets/image-20210314200644548.png) @@ -125,15 +127,18 @@ DEF: **vertex normal** is defined as the average of surrounding face normals. * compute color for each pixel. - ##### Barycentric Interpolation Interpolate by area. suppose $X = (x, y)$: + $$ +\displaylines{ \alpha = \frac {S_{XBC}} {S_{ABC}}\\ \beta = \frac {S_{XAC}} {S_{ABC}} \\ \gamma = \frac {S_{XAB}} {S_{ABC}} +} $$ + A practical version: ![image-20210314201950596](shading.assets/image-20210314201950596.png) @@ -143,7 +148,6 @@ Properties: * $(x,y)$ is inside $\Delta ABC$ if and only if $\alpha, \beta, \gamma$ are all non-negative. - ### Texture Mapping Each triangle copies a piece of texture image (2d, uv-space) to the surface (3d). @@ -153,13 +157,11 @@ Each triangle copies a piece of texture image (2d, uv-space) to the surface (3d) * Interpolate color at UV, and assign it to the pixel. (nearest, bilinear, bicubic) - ##### Texture can affect shading: (bump / displacement shading) ![image-20210314203342299](shading.assets/image-20210314203342299.png) - ```c++ // example code of bump & displacement shading. diff --git a/docs/graphics/103_geometry.md b/docs/graphics/103_geometry.md index 34d4b678d..698b33d28 100644 --- a/docs/graphics/103_geometry.md +++ b/docs/graphics/103_geometry.md @@ -5,15 +5,18 @@ ##### Implicit abstract functions. (Signed Distance Function, SDF) + $$ +\displaylines{ f(x, y, z) = \begin{cases} \le0, \text{inside} \\ >0, \text{outside} \end{cases} +} $$ -easy to test inside/outside, but hard to sample. +easy to test inside/outside, but hard to sample. ##### Explicit @@ -25,7 +28,6 @@ Or 2d parameter maps ($f(u,v)\rightarrow (x,y,z)$) easy to sample, but hard to test inside/outside. - ### Bezier Curves ![image-20210519161328028](geometry.assets/image-20210519161328028.png) @@ -37,13 +39,20 @@ Given 4 control points, an interpolation parameter $t$, and order $n$, **recursi ![image-20210314210904500](geometry.assets/image-20210314210904500.png) This algorithm has a explicit algebra solution (the Bernstein form): + $$ +\displaylines{ \mathbf b^n(t) = \sum_{j=0}^n\mathbf b_j B^n_j(t) \\ B_i^n(t) = C_n^it^i(1-t)^{n-i} +} $$ + In particular, for a $n=4 $ Bezier curve: + $$ +\displaylines{ \mathbf b^n(t) = \mathbf b_0(1-t)^3 + \mathbf b_13t(1-t)^2 + \mathbf b_23t^2(1-t) + \mathbf b_3 t^3 +} $$ @@ -54,7 +63,6 @@ B-Splines (Basis Splines) is superset of Bezier Curves. Bezier Curve can be extended to Bezier Surface in 3D, and use separable 1D de Casteljau to solve. - ```c++ // explicit solution for Bezier curve of n = 4. void algebra_bezier(const std::vector &points, cv::Mat &window) @@ -98,9 +106,6 @@ cv::Point2f recursive_bezier_func(const std::vector &points, float ``` - - - ### Mesh Operations ##### Subdivision (Magnification) @@ -116,9 +121,6 @@ Collapse edges and minimize quadric error. ![image-20210314212536499](geometry.assets/image-20210314212536499.png) - - - ### Shadow A pixel NOT in shadow must be seen both by the light and camera. @@ -132,5 +134,4 @@ A pixel NOT in shadow must be seen both by the light and camera. ![image-20210318190725656](geometry.assets/image-20210318190725656.png) - problem: soft-shadow (penumbra) vs hard-shadow (umbra) \ No newline at end of file diff --git a/docs/graphics/104_raytracing.md b/docs/graphics/104_raytracing.md index b12776d4c..fa4d3d18b 100644 --- a/docs/graphics/104_raytracing.md +++ b/docs/graphics/104_raytracing.md @@ -7,7 +7,6 @@ Rasterization Shading cannot handle global effect (e.g., soft shadow, multiple l Ray-tracing is slow, but can generate high quality shades. - ### Whitted-Style Ray Tracing Cast ray and trace the route recursively. @@ -15,9 +14,13 @@ Cast ray and trace the route recursively. ![image-20210314220007542](raytracing.assets/image-20210314220007542.png) A ray is defined by origin $\mathbf o$ and direction $\mathbf d$ as a function of time $t \ge 0$: + $$ +\displaylines{ \mathbf r(t) = \mathbf o + t\mathbf d +} $$ + Ray-Surface intersection algorithm: * Naïve: Check intersection with each triangles. (slow!) @@ -29,8 +32,6 @@ Ray-Surface intersection algorithm: Need to pre-compute bounding boxes by spatial partitioning (uniform grid, KD-tree) / object partitioning (bounding volume hierarchy). - - ```c++ // Moller Trumbore Algorithm: detect ray-triangle intersection bool rayTriangleIntersect(const Vector3f& v0, const Vector3f& v1, const Vector3f& v2, const Vector3f& orig, @@ -59,7 +60,6 @@ bool rayTriangleIntersect(const Vector3f& v0, const Vector3f& v1, const Vector3f ``` - #### BVH (Bounding Volume Hierarchy) BVH partitions **object** directly, compared to KD-Tree/Oct-Tree/BSP-Tree that partitions **space**. @@ -69,9 +69,6 @@ BVH's bounding boxes **may overlap in space, but each object is uniquely contain ![image-20210521223715017](104_raytracing.assets/image-20210521223715017.png) - - - ### Basic Radiometry ![image-20210314222140206](raytracing.assets/image-20210314222140206.png) @@ -96,7 +93,6 @@ Irradiance (辐射照度) vs radiance (辐射亮度): ![image-20210314221805847](raytracing.assets/image-20210314221805847.png) - **Bidirectional Reflectance Distribution Function (BRDF)**: how much light is reflected into each outgoing direction from each incoming direction. ![image-20210314223820806](raytracing.assets/image-20210314223820806.png) @@ -110,7 +106,6 @@ The Rendering Equation: ![image-20210314224100205](raytracing.assets/image-20210314224100205.png) - ### Path Tracing Whitted-Style Ray Tracing's assumptions are too simple (in fact wrong). diff --git a/docs/graphics/105_material.md b/docs/graphics/105_material.md index 3ffecbdb0..e191dd276 100644 --- a/docs/graphics/105_material.md +++ b/docs/graphics/105_material.md @@ -15,9 +15,6 @@ Material == BRDF ![image-20210318190942601](material.assets/image-20210318190942601.png) - - - ### Microfacet Theory ### Anisotropic Materials @@ -25,7 +22,6 @@ Material == BRDF ![image-20210318191307366](material.assets/image-20210318191307366.png) - ### Properties of BRDF * Non-negativity diff --git a/docs/graphics/opengl_advanced.md b/docs/graphics/opengl_advanced.md index 618c7fd54..9675cb31f 100644 --- a/docs/graphics/opengl_advanced.md +++ b/docs/graphics/opengl_advanced.md @@ -41,12 +41,16 @@ This mapping is NON-linear, because we want more precision in nearer distance, while less precision in further distance. + $$ +\displaylines{ z' = \frac {1/z - 1/near} {1/far - 1/near} +} $$ + To visualize z buffer, just set it as the `FragColor`: ```glsl @@ -71,7 +75,6 @@ $$ There is no real solution for this (maybe set 32-bit depth buffer), so never place two triangles too close! - ### Stencil test (模板测试) * Stencil can be viewed as a **mask**, so we have more control on where to draw. For example, we can use it to highlight the edge of an object. @@ -150,7 +153,6 @@ $$ ``` - ### Blending * alpha blending allows drawing (full or partial) transparent objects. @@ -236,7 +238,6 @@ $$ ``` - ### Face Culling * A way to discard occluded faces (back facing), so we can save computation time. @@ -606,7 +607,6 @@ $$ To achieve **dynamic** environment mapping, we need to frame buffer all reflective faces and then render it to the object! - ### Advanced GLSL * set the point size. @@ -758,7 +758,6 @@ $$ ``` - ### Geometry Shader * `Vertex Shader --> [Geometry Shader] --> Fragment Shader` @@ -961,7 +960,6 @@ $$ ``` - ### Instancing * Instancing aims to **draw multiple instances of the same object within one GPU call**, instead of use a for loop, so we can save CPU/GPU communication cost. @@ -1100,7 +1098,6 @@ $$ ``` - ### Anti-aliasing (AA) * SSAA: super-resolution, render at a larger resolution and then resize. Very expensive, do not use. diff --git a/docs/graphics/opengl_basics.md b/docs/graphics/opengl_basics.md index f3bec41de..0d2b154e0 100644 --- a/docs/graphics/opengl_basics.md +++ b/docs/graphics/opengl_basics.md @@ -5,7 +5,6 @@ A definition of a set of APIs to call GPU to render images. Kudos to [learnopengl](https://learnopengl-cn.github.io/) ! - ### Versions * **OpenGL < 3.3**: Legacy, not used now. Use fixed pipeline. @@ -15,7 +14,6 @@ Kudos to [learnopengl](https://learnopengl-cn.github.io/) ! * **DirectX** (Not OpenGL, Windows's graphic library.) - ### APIs The way OpenGL works is like a **state machine**. We always call it **Sequentially**. @@ -688,9 +686,6 @@ GLSL (OpenGL Shading Language): Small c-like programs to describe Vertex & Fragm ![img](opengl.assets/camera_pitch_yaw_roll.png) - - - ### [A complete program example in C++](https://github.com/JoeyDeVries/LearnOpenGL/tree/master/src/1.getting_started/6.2.coordinate_systems_depth) ```glsl diff --git a/docs/graphics/opengl_lighting.md b/docs/graphics/opengl_lighting.md index bb6650519..37a8aa30a 100644 --- a/docs/graphics/opengl_lighting.md +++ b/docs/graphics/opengl_lighting.md @@ -30,6 +30,5 @@ - ### gamma correction diff --git a/docs/graphics/pbr.md b/docs/graphics/pbr.md index 2c553aeee..8f6f6edf9 100644 --- a/docs/graphics/pbr.md +++ b/docs/graphics/pbr.md @@ -13,10 +13,14 @@ * $s(\omega_i)$ is the occlusion probability from the shading point to light. * rendering Equation: + $$ +\displaylines{ \mathbf c(\mathbf \omega_o) = \int_\Omega L(\omega_i)f(\omega_i, \omega_o)(\omega_i \cdot \mathbf n)d \omega_i +} $$ + * micro-facet BRDF (Cook-Torrance 1982): $$ f(\omega_i, \omega_o) = (1 - m) \frac {\mathbf a} {\pi} + \frac {DFG} {4(\omega_i \cdot \mathbf n)(\omega_o \cdot \mathbf n)} diff --git a/docs/graphics/prt.md b/docs/graphics/prt.md index c230c12a4..bdbbeb396 100644 --- a/docs/graphics/prt.md +++ b/docs/graphics/prt.md @@ -19,24 +19,35 @@ * For any function $f$ defined on the sphere, we can represent it with a linear combination of SHs (usually truncated): + $$ +\displaylines{ f(\omega) = \sum_ic_iB_i(\omega) +} $$ + **SH property (orthonormal)**: + $$ +\displaylines{ \int_\Omega B_i(\omega)B_j(\omega) = 0, i\ne j \\ \int_\Omega B_i(\omega)B_j(\omega) = 1, i= j \\ +} $$ + **SH property (projection)**: the coefficient can be obtained with: + $$ +\displaylines{ c_i = \int_\Omega f(\omega)B_i(\omega)d\omega +} $$ @@ -56,9 +67,12 @@ $$ * view the rendering function as lighting and **light transport (or bounce, in fact the visibility & BRDF)**. + $$ +\displaylines{ L(o) = \int_\Omega \underbrace{L(i)}_{\text{lighting}}\underbrace{V(i)\rho(i, o)\max(0, n \cdot i)}_{\text{light transport}}di +} $$ @@ -90,7 +104,6 @@ $$ Now we need to save a matrix for each point. - * **SH property (rotation)**: any rotated SH basis function, can be represented with a linear combination of basis functions of the same level. So to rotate the lighting, we don't need to re-compute $T_j$, but apply the rotation on $T_j$. diff --git a/docs/graphics/python_moderngl.md b/docs/graphics/python_moderngl.md index 1729e3d8d..80e1619fc 100644 --- a/docs/graphics/python_moderngl.md +++ b/docs/graphics/python_moderngl.md @@ -3,7 +3,6 @@ `moderngl ` supports OpenGL >= 3.3. - ### install ```bash @@ -12,9 +11,6 @@ pip install moderngl-window # for window creation ``` - - - ### troubles version `5.6` just fails: (maybe caused by the new `glcontext`) @@ -39,7 +35,6 @@ SystemError: returned NULL without setting an however, version`5.5` is OK. - ### example ```python @@ -87,7 +82,6 @@ for i in range(0, 20, 2): ``` - #### Context the GL Context, all the operations are called in this context. @@ -109,7 +103,6 @@ ctx.version_code ``` - ### Primitive Modes ```python @@ -122,7 +115,6 @@ Context.TRIANGLES ``` - #### program `shader` programs. @@ -145,7 +137,6 @@ program = ctx.program( ``` - #### buffer (vbo) OpenGL objects that stores an array in GPU allocated by the context. @@ -164,7 +155,6 @@ vbo.ctx ``` - #### vertex_array (vao) describes how `buffer` is read by `shader`. @@ -182,7 +172,6 @@ vao.extra ``` - ### Texture texture contains one or more images of the same format, can be the source access from a shader, or a render target. diff --git a/docs/index.md b/docs/index.md index 6f5e5c119..59561ebf9 100644 --- a/docs/index.md +++ b/docs/index.md @@ -4,23 +4,23 @@ [kiui](https://kiui.moe/)'s notebook. ## Recent Updates -- [tyro.md](python\tyro/)
2023-12-15 16:03:52.529119
-- [camera_intrinsics_exintrics.md](vision\camera_intrinsics_exintrics/)
2023-12-13 20:07:38.526265
-- [monky_patch.md](python\monky_patch/)
2023-12-12 18:58:16.041742
-- [set_usual_apps_proxy.md](web\proxy\set_usual_apps_proxy/)
2023-12-08 16:21:56.252977
-- [slurm.md](linux\slurm/)
2023-12-07 15:20:34.127883
-- [zip.md](linux\zip/)
2023-12-06 14:44:52.320809
-- [huggingface.md](python\huggingface/)
2023-12-06 14:44:52.316494
-- [awscli.md](linux\awscli/)
2023-12-06 14:44:52.315493
-- [vs_code_hotkey.md](others\vs_code_hotkey/)
2023-12-06 14:44:52.315493
-- [powershell.md](windows\powershell/)
2023-12-06 14:44:52.279341
-- [blender_tutorial.md](model\blender_tutorial/)
2023-12-06 14:44:52.277337
-- [git.md](linux\git/)
2023-11-28 20:33:56.409179
-- [env.md](linux\env/)
2023-11-27 19:54:33.115214
-- [disk.md](linux\disk/)
2023-11-23 11:12:45.079090
-- [ddpm.md](math\ddpm/)
2023-11-21 14:17:26.240711
-- [quaternion.md](math\quaternion/)
2023-11-20 15:05:44.199565
-- [rebuttals.md](writings\rebuttals/)
2023-11-18 11:39:03.764987
-- [git_tricks.md](linux\git_tricks/)
2023-11-18 11:04:41.502742
-- [trojan.md](web\proxy\trojan/)
2023-11-17 09:55:15.367723
-- [bash.md](linux\bash/)
2023-11-17 09:19:57.540734
+- [societal_impact.md](writings\societal_impact/)
2023-12-29 14:16:08.915191
+- [review.md](writings\review/)
2023-12-29 14:16:08.914190
+- [rebuttals.md](writings\rebuttals/)
2023-12-29 14:16:08.912181
+- [pitfalls.md](writings\pitfalls/)
2023-12-29 14:16:08.909348
+- [examples.md](writings\examples/)
2023-12-29 14:16:08.907343
+- [cuda.md](windows\cuda/)
2023-12-29 14:16:08.899009
+- [xpath.md](web\scrape\xpath/)
2023-12-29 14:16:08.897680
+- [grab.md](web\scrape\grab/)
2023-12-29 14:16:08.895679
+- [ttrss.md](web\rss\ttrss/)
2023-12-29 14:16:08.894582
+- [rsshub.md](web\rss\rsshub/)
2023-12-29 14:16:08.893581
+- [trojan.md](web\proxy\trojan/)
2023-12-29 14:16:08.892491
+- [trojan-go.md](web\proxy\trojan-go/)
2023-12-29 14:16:08.884487
+- [ss.md](web\proxy\ss/)
2023-12-29 14:16:08.876081
+- [set_usual_apps_proxy.md](web\proxy\set_usual_apps_proxy/)
2023-12-29 14:16:08.875081
+- [frp_reverse_proxy.md](web\proxy\frp_reverse_proxy/)
2023-12-29 14:16:08.873938
+- [concepts.md](web\proxy\concepts/)
2023-12-29 14:16:08.871939
+- [plyloader.md](web\frontend\three\plyloader/)
2023-12-29 14:16:08.870939
+- [basic.md](web\frontend\three\basic/)
2023-12-29 14:16:08.862816
+- [web_api.md](web\frontend\html\web_api/)
2023-12-29 14:16:08.860812
+- [http.md](web\frontend\html\http/)
2023-12-29 14:16:08.850490
diff --git a/docs/latex/tutorial.md b/docs/latex/tutorial.md index b7d415a8e..2986bab67 100644 --- a/docs/latex/tutorial.md +++ b/docs/latex/tutorial.md @@ -23,7 +23,6 @@ XeLaTeX supports `pstricks`(draw images with code), but LuaLaTeX doesn't. - ### Misc. * document class @@ -197,7 +196,6 @@ ``` - ##### parentheses ```latex @@ -221,7 +219,6 @@ s & = \left\{ x \middle| x < 10 \notag \right. \\ ``` - ##### Align (package amsmath) ```latex @@ -245,7 +242,6 @@ p(x) = 3x^6 + 14x^5y + 590x^4y^2 + 19x^3y^3\\ ``` - ##### Matrices ```latex @@ -280,7 +276,6 @@ $\big(\begin{smallmatrix} ``` - ##### spacings ```latex @@ -295,7 +290,6 @@ $\big(\begin{smallmatrix} ``` - ##### fonts ```latex @@ -311,7 +305,6 @@ RQSZ \\ ``` - ### Bibliography ```latex @@ -334,7 +327,6 @@ YEAR="3200", Bibliography style file. - ### Figures ```latex @@ -391,7 +383,6 @@ Bibliography style file. ``` - ### Tables ```latex @@ -433,9 +424,6 @@ Bibliography style file. ``` - - - ### Errors * `undefined control sequence` @@ -445,7 +433,6 @@ Bibliography style file. - ### Lengths ##### Units @@ -498,4 +485,3 @@ Bibliography style file. ``` - diff --git a/docs/linux/advanced_bash.md b/docs/linux/advanced_bash.md index 719e6c949..7d9df4e26 100644 --- a/docs/linux/advanced_bash.md +++ b/docs/linux/advanced_bash.md @@ -11,7 +11,6 @@ mkdir tmp/{a,b}/c ``` - ### run & interrupt parallel commands https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script diff --git a/docs/linux/alternatives.md b/docs/linux/alternatives.md index e76db995f..cb61e5237 100644 --- a/docs/linux/alternatives.md +++ b/docs/linux/alternatives.md @@ -1,7 +1,6 @@ # update-alternatives - ### gcc example ```bash diff --git a/docs/linux/apt_dpkg.md b/docs/linux/apt_dpkg.md index e984c36c9..d453dbdfa 100644 --- a/docs/linux/apt_dpkg.md +++ b/docs/linux/apt_dpkg.md @@ -26,9 +26,6 @@ apt will read & download sources from `/etc/apt/sources.list` We recommend to use the [TUNA mirror](https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/). - - - ### build from source ```bash @@ -45,7 +42,6 @@ sudo make install This will install to `/usr/local/bin` - ### PPA Personal Package Achieve. To install **unofficial** softwires by `apt`. @@ -73,9 +69,6 @@ sudo rm /etc/atp/sources.list.d/xxx.list* ``` - - - Remove trusted GPG keys: ```bash @@ -114,7 +107,6 @@ $ sudo apt-key del BE1229CF ``` - ### unmet dependencies Sometimes we meet errors like: @@ -171,6 +163,3 @@ sudo apt install xorg # ok! Or, `aptitude` will suggest you how to repair, just type `n` to select the preferred solution and type `Y`. - - - diff --git a/docs/linux/awscli.md b/docs/linux/awscli.md index 652facfa1..e95c51625 100644 --- a/docs/linux/awscli.md +++ b/docs/linux/awscli.md @@ -5,7 +5,6 @@ pip install awscli ``` - ### Setup First configure it using your AK & SK: @@ -29,7 +28,6 @@ alias aws="aws --endpoint-url=http://:" ``` - ### Usage ```bash @@ -60,7 +58,6 @@ aws s3 rm s3://myBucket/remote_file ``` - ### Megfile A management tool for both S3 and normal dataset. diff --git a/docs/linux/bash.md b/docs/linux/bash.md index dd9c7b519..9639893a4 100644 --- a/docs/linux/bash.md +++ b/docs/linux/bash.md @@ -1,7 +1,6 @@ # bash - * options * `--`: disable further option processing. * `-i`: interactive diff --git a/docs/linux/cadaver.md b/docs/linux/cadaver.md index 4e7737673..e9131e066 100644 --- a/docs/linux/cadaver.md +++ b/docs/linux/cadaver.md @@ -5,7 +5,6 @@ an extension of the [Hypertext Transfer Protocol](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) (HTTP) that allows [clients](https://en.wikipedia.org/wiki/Web_client) to perform remote [Web](https://en.wikipedia.org/wiki/World_Wide_Web) content authoring operations. - ### cadaver A command-line WebDAV client for Unix. diff --git a/docs/linux/conda.md b/docs/linux/conda.md index 42d849699..26e9dfc90 100644 --- a/docs/linux/conda.md +++ b/docs/linux/conda.md @@ -1,7 +1,6 @@ # conda - ### install download the runfile from [here](https://www.anaconda.com/products/individual), then simply run it with bash. @@ -10,7 +9,6 @@ download the runfile from [here](https://www.anaconda.com/products/individual), * uninstall: `rm -rf ~/anaconda` - ### envs ```bash @@ -36,7 +34,6 @@ conda env remove -n ``` - ### conda file locations In `.bashrc`: @@ -78,7 +75,6 @@ The directory structures: ``` - ### package management ```bash diff --git a/docs/linux/cron.md b/docs/linux/cron.md index 229aac119..0f950ae89 100644 --- a/docs/linux/cron.md +++ b/docs/linux/cron.md @@ -39,7 +39,6 @@ Config formats: ``` - ### cron deamon ```bash @@ -49,7 +48,6 @@ systemctl restart cron ``` - ### cron command ```bash @@ -60,7 +58,6 @@ crontab -l -u ``` - ### log files ```bash @@ -72,7 +69,6 @@ crontab -l -u ``` - ### anacron 设想这样一个场景,Linux 服务器会在周末关机两天,但是设定的定时任务大多在周日早上进行,但在这个时间点,服务器又处于关机状态,导致系统很多定时任务无法运行。 diff --git a/docs/linux/disk.md b/docs/linux/disk.md index 5ff2a71d6..282c7a663 100644 --- a/docs/linux/disk.md +++ b/docs/linux/disk.md @@ -9,7 +9,6 @@ ref: https://stackoverflow.com/questions/24429949/device-vs-partition-vs-file-sy ``` - ### Partition Table Type A data structure that provides basic information for the OS about the partition of the hard disk. @@ -55,7 +54,6 @@ A way of storing data inside the partitions. support both Windows and Linux, usually for swap and recovery. - ### check disk state and mount point * `fdisk`: check all physically loaded disks @@ -240,12 +238,6 @@ A way of storing data inside the partitions. ``` - - - - - - ### Add a new disk * Plug in the hardware @@ -300,9 +292,6 @@ A way of storing data inside the partitions. - - - ### testdisk TestDisk can undelete @@ -314,7 +303,6 @@ TestDisk can undelete If it doesn't work or for other filesystem! (which means the most used ext4 cannot use it.) - ### extundelete Need to unmount the device. @@ -322,7 +310,6 @@ Need to unmount the device. Usually we need a live-USB boot. (very difficult, not recommended) - ### if the process is not killed (the only practical way) > ref: https://www.jianshu.com/p/662293f12a47 diff --git a/docs/linux/env.md b/docs/linux/env.md index 1e2c3e842..f7614ae3a 100644 --- a/docs/linux/env.md +++ b/docs/linux/env.md @@ -3,7 +3,6 @@ For loading different environments from system for local user... - ### gcc ```bash @@ -12,7 +11,6 @@ export LD_LIBRARY_PATH="/path/to/mpfr-4.1.0/lib:/path/to/gcc-11.2.0/lib64:${LD_L ``` - ### cuda ```bash @@ -21,6 +19,3 @@ export LD_LIBRARY_PATH="/path/to/cuda-11.8/lib64:${LD_LIBRARY_PATH}" ``` - - - diff --git a/docs/linux/find.md b/docs/linux/find.md index 60f7526e6..17fc3617b 100644 --- a/docs/linux/find.md +++ b/docs/linux/find.md @@ -25,8 +25,6 @@ ``` - - * Replace string in all files under a folder ```bash diff --git a/docs/linux/gdb.md b/docs/linux/gdb.md index b14aab073..eb78790c6 100644 --- a/docs/linux/gdb.md +++ b/docs/linux/gdb.md @@ -5,7 +5,6 @@ https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/gdb.html - ## Deal with Segmentation Fault Set `-g` flag for compiler, @@ -38,7 +37,6 @@ $gdb info stack # show traceback ``` - ### seg fault in python that calls c ```bash diff --git a/docs/linux/git.md b/docs/linux/git.md index fa2b28d7b..9fa8c43e4 100644 --- a/docs/linux/git.md +++ b/docs/linux/git.md @@ -11,7 +11,6 @@ git config --global credential.helper cache ``` - ### Start Projects & Make Changes ##### file status lifespan @@ -65,7 +64,6 @@ git commit -a -m "message" # auto add all modified (tracked) files and commit (o ``` - ### History ```bash @@ -82,7 +80,6 @@ git log --grep="keyword" ``` - ### Undo ```bash @@ -101,7 +98,6 @@ git checkout -- [file] # dangerous operation. all changes to [file] will be lost ``` - ### Remote ```bash @@ -184,7 +180,6 @@ git push origin master ``` - ### Tag ```bash @@ -192,7 +187,6 @@ git tag ``` - ### Alias ```bash @@ -201,7 +195,6 @@ git config --global alias.st status # git st == git status ``` - ### Branching **Branch is a pointer** pointing to a commit object. @@ -243,7 +236,6 @@ git branch -D dev # forcely delete unmerged "dev" ``` - ### Remote Branching ```bash @@ -273,7 +265,6 @@ git push origin/exp exp ``` - ### Rebase Branch Another method to merge branches. @@ -295,13 +286,11 @@ git merge experiment ![master 分支的快进合并。](https://git-scm.com/book/en/v2/images/basic-rebase-4.png) - While normal merge will generate: ![通过合并操作来整合分叉了的历史。](https://git-scm.com/book/en/v2/images/basic-rebase-2.png) - ### Ignore `.gitignore` @@ -319,7 +308,6 @@ git rm -r --cached ``` - ### Submodule Add a repo (at `url`) to the current repo's `dest_path` as a submodule: @@ -331,7 +319,6 @@ git submodule add This will automatically track the submodule's version by creating a `.gitmodules` file. - ### Stash Use situation: You want to switch to another branch, but there are uncommitted modifications in the current branch. diff --git a/docs/linux/git_lfs.md b/docs/linux/git_lfs.md index 894ce484c..9ed0f9eb6 100644 --- a/docs/linux/git_lfs.md +++ b/docs/linux/git_lfs.md @@ -3,13 +3,11 @@ Ref: [tutorial](https://zzz.buzz/zh/2016/04/19/the-guide-to-git-lfs/#%E5%B8%B8%E7%94%A8-git-lfs-%E5%91%BD%E4%BB%A4) - ### install Download the [releases](https://github.com/git-lfs/git-lfs/releases) and follow platform specific instructions. - ### usage ```bash diff --git a/docs/linux/git_tricks.md b/docs/linux/git_tricks.md index 62a162237..f30b749a7 100644 --- a/docs/linux/git_tricks.md +++ b/docs/linux/git_tricks.md @@ -5,7 +5,6 @@ git submodule update --init --recursive ``` - ### add more things to the last commit (amend) ```bash @@ -19,7 +18,6 @@ git commit --amend ``` - ### command line diff If you cannot use VS Code or Github. @@ -32,7 +30,6 @@ git diff --staged ``` - ### modify the last commit ```bash @@ -46,7 +43,6 @@ git commit -c ORIG_HEAD ``` - ### revert a commit ```bash @@ -57,7 +53,6 @@ git revert ``` - ### checkout a history commit, and also update all submodules to the corresponding commits ```bash @@ -69,7 +64,6 @@ git submodule update --recursive # checkout all submodules too. ``` - ### undo `git pull` **git pull** performs two operations: @@ -110,7 +104,6 @@ Improvement: **use `git pull --rebase` instead of `git pull`!** [It also syncs server change](https://gitolite.com/git-pull--rebase). - ### [force `git pull`](https://stackoverflow.com/questions/1125968/git-how-do-i-force-git-pull-to-overwrite-local-files) ```bash @@ -126,7 +119,6 @@ git pull ``` - ### remove a large file wrongly committed and left in git history large file, even if removed in current branch, will be left in history and every clone suffers from it. @@ -148,7 +140,6 @@ git push --all --force ``` - ### embed mp4 in readme.md (github only) You just edit the markdown file in github webpage, drag and drop your mp4 video to it, and it will work. @@ -162,7 +153,6 @@ https://user-images.githubusercontent.com/25863658/155265815-c608254f-2f00-4664- ``` - ### reset to a history commit say you would like to reset to a previous commit. @@ -183,7 +173,6 @@ git reset --hard HEAD@{y} ``` - ### change remote repo url ```bash @@ -194,7 +183,6 @@ git remote set-url origin [new_repo_url] ``` - ### push a new branch to remote ```bash @@ -210,7 +198,6 @@ git push -u origin ``` - ### gitignore un-ignore specific files say you want to exclude everything in `datasets/` except `datasets/splits/*`.` @@ -223,7 +210,6 @@ datasets/* # the /* matters! ``` - ### use ssh for git command (avoid permission denied error) You need to generate a SSH key for your machine and add it to github. @@ -240,7 +226,6 @@ Then copy the public key and add it in https://github.com/settings/keys Now you should be able to clone through ssh! - ### fetch branch from a forked repo without clone ```bash diff --git a/docs/linux/htop.md b/docs/linux/htop.md index 5783f9d39..f80c3fa50 100644 --- a/docs/linux/htop.md +++ b/docs/linux/htop.md @@ -1,7 +1,6 @@ # htop - ### rank by press `F6` and select. diff --git a/docs/linux/locate.md b/docs/linux/locate.md index 12ba63d37..2ca2d64b7 100644 --- a/docs/linux/locate.md +++ b/docs/linux/locate.md @@ -10,7 +10,6 @@ This command is paired with `updatedb`, which creates a database for `locate` fo `updatedb` is run by `cron` everyday. - This command is usually used to locate libraries. ```bash diff --git a/docs/linux/lscolor.md b/docs/linux/lscolor.md index 8ed93d34b..a8d2ec759 100644 --- a/docs/linux/lscolor.md +++ b/docs/linux/lscolor.md @@ -51,19 +51,16 @@ echo ``` - ### default output ![gnome-terminal screenshot - default](lscolor.assets/6kknG.png) - ### other-writable (o+w) can be write by users other than owner. - ### sticky bit Sticky means ONLY root or owner can delete/move this file/directory. @@ -83,7 +80,6 @@ chmod 0777 ``` - ### change ls color the environment variable `LS_COLORS` takes charge of this. diff --git a/docs/linux/modern_cmd.md b/docs/linux/modern_cmd.md index 25a025aa4..2b38df994 100644 --- a/docs/linux/modern_cmd.md +++ b/docs/linux/modern_cmd.md @@ -3,7 +3,6 @@ A note on https://github.com/ibraheemdev/modern-unix - ### `zoxide` (recommend!) To replace `cd` @@ -29,9 +28,6 @@ zi ``` - - - ### `mcfly` (recommend!) To replace `Ctrl + R`. @@ -61,9 +57,6 @@ mcfly # it takes about one minute to read in history ``` - - - ### `ag` (recommend!) To replace `grep -rnw -e "pattern"` @@ -83,9 +76,6 @@ ag -w "pattern" # whole word ``` - - - ### `duf` (recommend!) To replace `df` @@ -103,9 +93,6 @@ duf ``` - - - ### `dust` (recommend!) To replace `du` @@ -133,9 +120,6 @@ dust -d 1 ``` - - - ### `exa` To replace `ls` @@ -162,7 +146,6 @@ exa -lT # ls directory trees. ``` - ### `bat` To replace `cat` @@ -187,7 +170,6 @@ bat ``` - ### `gdown` https://github.com/wkentaro/gdown diff --git a/docs/linux/network_utils.md b/docs/linux/network_utils.md index e804d5aa3..f272bb72e 100644 --- a/docs/linux/network_utils.md +++ b/docs/linux/network_utils.md @@ -72,7 +72,6 @@ Explain: * `RX Bytes, TX Bytes`: total amount of data received, transmitted. - ### arp command to show the ARP (Address Resolution Protocol) cache. @@ -87,7 +86,6 @@ arp -v ``` - ### route, ip, netstat * show routing table @@ -145,9 +143,6 @@ arp -v - - - ### subnet mask Each host is configured with a unique IP address and subnet mask. @@ -166,7 +161,6 @@ inet addr:222.29.2.44 Mask:255.255.255.0 ``` - ### what router does ? When presented with a packet bound for an IP address @@ -174,7 +168,6 @@ When presented with a packet bound for an IP address the router needs to determine which of its network interfaces will best get that packet closer to its destination. - ### default gateway The node that serves as the default router when no other route specification matches the destination IP address. @@ -192,7 +185,6 @@ Destination Gateway Genmask Flags Metric Ref Use Iface ``` - ### traceroute install by `sudo apt install traceroute`. @@ -208,7 +200,6 @@ traceroute 8.8.8.8 # google DNS ``` - ### iptables firewall. @@ -219,4 +210,3 @@ iptables -L ``` - diff --git a/docs/linux/nps.md b/docs/linux/nps.md index 22ed9a8e2..4f417e1bf 100644 --- a/docs/linux/nps.md +++ b/docs/linux/nps.md @@ -6,7 +6,6 @@ * `ufw allow 8080` - ### Server ```bash @@ -16,7 +15,6 @@ nps start ##### TCP tunnel - ### Client ```bash @@ -24,6 +22,3 @@ npc ``` - - - diff --git a/docs/linux/nvidia_cuda.md b/docs/linux/nvidia_cuda.md index 721b18a3a..cd0fefbc9 100644 --- a/docs/linux/nvidia_cuda.md +++ b/docs/linux/nvidia_cuda.md @@ -7,7 +7,6 @@ Usually, we install nvidia-driver first since it is necessary for GUI. CUDA is only used for high-performance computation. - ### install nvidia-driver Always use the package manager!!! @@ -66,7 +65,6 @@ nvidia-smi -> /etc/alternatives/x86_64-linux-gnu_nvidia_smi ``` - ### switch between intel and nvidia driver ```bash @@ -82,7 +80,6 @@ sudo prime-select intel ``` - ### uninstall nvidia-driver ```bash @@ -91,7 +88,6 @@ sudo apt purge nvidia* ``` - ### install CUDA Recommend to use Runfile install. @@ -116,7 +112,6 @@ nvcc -V ``` - ### switch between multiple CUDA versions Globally: change the `/usr/local/cuda` soft link. @@ -136,7 +131,6 @@ export LD_LIBRARY_PATH="/usr/local/cuda-10.1/lib64:$:LD_LIBRARY_PATH" ``` - ### uninstall CUDA Just REMOVE it. @@ -152,7 +146,6 @@ sudo apt purge cuda* ``` - ### pitfalls * for CUDA 10.1, install the update `10.1.243` directly, instead of the general release `10.1.105` !!! Or you can update from `105` to `243`, just run the new `runfile` and it will prompt. diff --git a/docs/linux/qt.md b/docs/linux/qt.md index 8ee3667b1..965747828 100644 --- a/docs/linux/qt.md +++ b/docs/linux/qt.md @@ -3,7 +3,6 @@ Qt is a fucking commercial software, and all its free releases are to disgust you. - You must register to download even the free version. Docs at: https://doc.qt.io/qt-5/gettingstarted.html @@ -13,11 +12,9 @@ TUNA mirror (always god!): https://mirrors.tuna.tsinghua.edu.cn/qt/ Official (slow): https://www.qt.io/offline-installers - To manage different Qt versions, use `PATH` and `LD_LIBRARY_PATH`. - ### Qt 5.5.1 ~ 5.9.7 The default version, in `/usr/libx86_64-linux-gnu/`. @@ -27,7 +24,6 @@ what `sudo apt install qt-default` will install. However, this is terribly outdated, e.g., `PyQt5, PySide2` do not support it. - ### Qt 5.12.11 The last version that supports a GUI installer. @@ -42,7 +38,6 @@ sudo ./qt-opensource-linux-x64-5.12.11.run ``` - Install the following `[Yes]`, which takes ~ 1.5G: ``` @@ -72,7 +67,6 @@ qmake -v ``` - ##### PyQt5 support ```bash @@ -81,9 +75,6 @@ pip install PyQt5==5.12.11 ``` - - - ### Qt 5.15 You must build it from source. @@ -93,4 +84,3 @@ download at: https://mirrors.tuna.tsinghua.edu.cn/qt/official_releases/qt/5.15/5 docs at: https://doc.qt.io/qt-5/build-sources.html - diff --git a/docs/linux/rclone.md b/docs/linux/rclone.md index 2729e421e..acbf6df6e 100644 --- a/docs/linux/rclone.md +++ b/docs/linux/rclone.md @@ -1,7 +1,6 @@ # rclone - ### install ```bash @@ -9,7 +8,6 @@ curl https://rclone.org/install.sh | sudo bash ``` - ### set up remotes follow the instructions: @@ -47,7 +45,6 @@ rclone about nuts: ``` - ### usage * list diff --git a/docs/linux/rm_mv.md b/docs/linux/rm_mv.md index 9bb124891..55168b529 100644 --- a/docs/linux/rm_mv.md +++ b/docs/linux/rm_mv.md @@ -11,7 +11,6 @@ mv !(dir1|dir2) dir1 ``` - ### remove with exclusion ```bash @@ -25,4 +24,3 @@ rm -vi * ``` - diff --git a/docs/linux/rsync.md b/docs/linux/rsync.md index 51d68c670..e2697a58b 100644 --- a/docs/linux/rsync.md +++ b/docs/linux/rsync.md @@ -24,8 +24,6 @@ ``` - - * alternative of `scp` ```bash @@ -38,7 +36,6 @@ - * Super fast remove (for large and recursive directories) ```bash diff --git a/docs/linux/runlevel.md b/docs/linux/runlevel.md index 92cc7d87b..55690968a 100644 --- a/docs/linux/runlevel.md +++ b/docs/linux/runlevel.md @@ -17,7 +17,6 @@ ``` - ### check runlevel ```bash @@ -29,7 +28,6 @@ sudo systemctl get-default ``` - ### change current runlevel ```bash @@ -43,7 +41,6 @@ sudo telinit 5 ``` - ### set default runlevel ```bash @@ -60,7 +57,6 @@ sudo reboot ``` - However, if lightdm failed to start, your runlevel will still be 3 even if the default is 5. check lightdm status and xorg log. \ No newline at end of file diff --git a/docs/linux/security/auth.md b/docs/linux/security/auth.md index 828496f70..8343a2158 100644 --- a/docs/linux/security/auth.md +++ b/docs/linux/security/auth.md @@ -1,7 +1,6 @@ # authorization - ### last logins ```bash @@ -23,7 +22,6 @@ who ``` - ### auth.log `/var/log/auth.log` @@ -41,7 +39,6 @@ sudo cat /var/log/auth.log | grep "Failed password" ``` - If `rsyslog` is working but `auth.log` still failed to show any logs, this maybe caused by ownership of `auth.log` (must not be `root` but `syslog:adm`). Try: ```bash @@ -49,9 +46,6 @@ sudo chown syslog:adm /var/log/auth.log ``` - - - ### syslog `/var/log/syslog` diff --git a/docs/linux/security/fail2ban.md b/docs/linux/security/fail2ban.md index 27ce89d0c..4d9403d97 100644 --- a/docs/linux/security/fail2ban.md +++ b/docs/linux/security/fail2ban.md @@ -1,7 +1,6 @@ # fail2ban - ```bash ### install sudo apt install fail2ban diff --git a/docs/linux/security/file-permission.md b/docs/linux/security/file-permission.md index 472015aee..9e932c03b 100644 --- a/docs/linux/security/file-permission.md +++ b/docs/linux/security/file-permission.md @@ -22,7 +22,6 @@ https://www.computerhope.com/unix/chattr.htm#list-of-attributes change the attributes of file or directory. - ### chown change ownership of file or directory. @@ -38,7 +37,6 @@ sudo chown -R ``` - ### umask set/check default user permission mask for new files. @@ -53,7 +51,6 @@ umask u+x # rwxr--r-- ``` - ### chmod set user permission mask for a specific file. @@ -66,7 +63,6 @@ chmod -R 777 ``` - ### note the escaped space! ```bash @@ -75,4 +71,3 @@ but `ls --escape` will reveal it! ``` - diff --git a/docs/linux/security/netstat.md b/docs/linux/security/netstat.md index ec1acf7f2..b8a0025cb 100644 --- a/docs/linux/security/netstat.md +++ b/docs/linux/security/netstat.md @@ -1,7 +1,6 @@ # port - ### netstat check for network communications on every port. @@ -12,7 +11,6 @@ sudo netstat -anup # ... udp ... ``` - ### fuser identify processes using files or sockets. @@ -29,7 +27,6 @@ fuser -i -k . ``` - ### ufw https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-18-04 diff --git a/docs/linux/security/ps-kill.md b/docs/linux/security/ps-kill.md index 8db56a734..809c60d0d 100644 --- a/docs/linux/security/ps-kill.md +++ b/docs/linux/security/ps-kill.md @@ -9,7 +9,6 @@ ps aux | grep ``` - ### kill kill by pid. single wrapper to kill system call. @@ -30,7 +29,6 @@ kill -SIGKILL ``` - ### killall kill by name. @@ -46,7 +44,6 @@ killall -I ``` - ### pkill kill by name, use `pgrep` for matching. diff --git a/docs/linux/security/ssh.md b/docs/linux/security/ssh.md index 4bc2987ee..de99c4176 100644 --- a/docs/linux/security/ssh.md +++ b/docs/linux/security/ssh.md @@ -14,7 +14,6 @@ ssh-copy-id user@remote_host ``` - ### sshd_config located in `/etc/ssh/sshd_config`. @@ -32,4 +31,3 @@ DenyUsers user3 user4 ``` - diff --git a/docs/linux/slurm.md b/docs/linux/slurm.md index 0a6462de2..94b3d5603 100644 --- a/docs/linux/slurm.md +++ b/docs/linux/slurm.md @@ -3,7 +3,6 @@ Simple Linux Utility for Resource Management. - ### sinfo check information of the system. @@ -22,7 +21,6 @@ cinfo -p occupy-reserved # only show reserved quota ``` - ### squeue check the current running (R) and pending (PD) jobs. @@ -33,7 +31,6 @@ squeue -l # list all info ``` - ### srun/sbatch launch/submit a job. @@ -64,7 +61,6 @@ QUOTA mode [phoenix-feature]: * auto: try to allocate reserved quota first, if not successful, turn to spot mode. - `srun` will start the job in foreground, suitable for single-node training: ```bash @@ -81,7 +77,6 @@ sr1gpu python test.py ``` - `sbatch` will submit jobs in background, and can perform multi-node training. For example, we launch 4 * 8 = 32 GPUs to train: @@ -150,6 +145,7 @@ srun --jobid $SLURM_JOBID bash -c "$CMD" 2>&1 | tee -a $LOG_PATH echo "END TIME: $(date)" ``` +**make sure the --output and --err log directory (`logs` here) exists!** Else the task will fail immediately without any information! ### scontrol @@ -165,7 +161,6 @@ scontrol release JOBID # release ``` - ### scancel stop/cancel a job. @@ -175,7 +170,6 @@ scancel ``` - ### sacct show status of running and (recently) finished jobs. @@ -192,7 +186,6 @@ sacct ``` - ### swatch identify why my job is pending. diff --git a/docs/linux/swap.md b/docs/linux/swap.md index 4f5a89c15..49ddbe822 100644 --- a/docs/linux/swap.md +++ b/docs/linux/swap.md @@ -5,7 +5,6 @@ use `htop`. - ### create swap ```bash @@ -16,7 +15,6 @@ sudo swapon /swapfile ``` - ### delete swap ```bash @@ -25,7 +23,6 @@ sudo rm /swapfile ``` - ### check swap file location ```bash @@ -36,9 +33,6 @@ sudo cat /proc/swaps ``` - - - ### `kswapd0` high CPU usage. This is usually caused by unmounted Swap if there is not enough memory. diff --git a/docs/linux/sysrq.md b/docs/linux/sysrq.md index 27a9b6b03..b0f859c38 100644 --- a/docs/linux/sysrq.md +++ b/docs/linux/sysrq.md @@ -1,17 +1,14 @@ # Magic SysRq - `SysRq` is usually `Print Screen` in keyboard. - - `Ctrl+Z`: pause a process (plus `bg` to resume in the background, `fg` to raise to foreground) - `Ctrl+C`: politely ask the process to shut down now - `Ctrl+\`: mercilessly kill the process that is currently in the foreground - Push each key sequentially. - `Alt+SysRq+s`: Write data to disk (always do this before killing anything important) diff --git a/docs/linux/trash.md b/docs/linux/trash.md index 14c4fd7b9..5614ad024 100644 --- a/docs/linux/trash.md +++ b/docs/linux/trash.md @@ -3,7 +3,6 @@ Cut my fingers if I `rm` a file accidentally again!!! - ### Usage ```bash @@ -28,7 +27,6 @@ restore-trash # will show a list and let you choose id to restore ``` - ### Details `trash` literally moves the file to `/files`, and create an info file at `/infos`. diff --git a/docs/linux/ubuntu_install_list.md b/docs/linux/ubuntu_install_list.md index 93b381cf4..860e8308d 100644 --- a/docs/linux/ubuntu_install_list.md +++ b/docs/linux/ubuntu_install_list.md @@ -9,7 +9,6 @@ https://rufus.ie/ Use the default settings are OK. - ### Restart the machine, enter boot manager. Zlab servers: @@ -21,7 +20,6 @@ Select your USB as the starter, and choose `try or install ubuntu`. To change the default boot order (e.g., if you installed new system on a different disk), you should check `Hard Disk Drive BBS Priorities` in BIOS config. - ### Installing... Wait until you see graphics. @@ -31,7 +29,6 @@ Choose language, how to install (alongside or erase old OS), enter your name and Then another long wait... - ### Setting up * Network connection @@ -306,7 +303,6 @@ Then another long wait... download the deb file to install. - ### Misc * I cannot open firefox or any other snap applications in nomachine virtual desktop... diff --git a/docs/linux/ufw.md b/docs/linux/ufw.md index d2c9cba2f..2bfdc13f8 100644 --- a/docs/linux/ufw.md +++ b/docs/linux/ufw.md @@ -1,7 +1,6 @@ # ufw - ### enable ```bash diff --git a/docs/linux/ulimit.md b/docs/linux/ulimit.md index 1be8cb586..51a179c68 100644 --- a/docs/linux/ulimit.md +++ b/docs/linux/ulimit.md @@ -18,7 +18,6 @@ ulimit -n 100000 ``` - ### permanent fix Modify `/etc/security/limits.conf`, and add: @@ -29,4 +28,3 @@ Modify `/etc/security/limits.conf`, and add: ``` - diff --git a/docs/linux/vim.md b/docs/linux/vim.md index c2f0e1cc4..654310496 100644 --- a/docs/linux/vim.md +++ b/docs/linux/vim.md @@ -1,7 +1,6 @@ # vim - ### remove ^M at line ending (dos to unix format) ``` @@ -9,7 +8,6 @@ ``` - ### slow startup First, try `vim -X`. diff --git a/docs/linux/wget.md b/docs/linux/wget.md index afe7c980e..e9423933c 100644 --- a/docs/linux/wget.md +++ b/docs/linux/wget.md @@ -9,7 +9,6 @@ wget -c https://example.com/test.txt ``` - ### cURL (client URL) ```bash @@ -25,8 +24,5 @@ curl ip.sb # ipv6 ``` - - - ### aria2 diff --git a/docs/linux/wsl/simulate_systemd.md b/docs/linux/wsl/simulate_systemd.md index c378d4c87..913cc8c42 100644 --- a/docs/linux/wsl/simulate_systemd.md +++ b/docs/linux/wsl/simulate_systemd.md @@ -8,4 +8,3 @@ fi ``` - diff --git a/docs/linux/xorg.md b/docs/linux/xorg.md index 2f3b1014d..a8a38dfba 100644 --- a/docs/linux/xorg.md +++ b/docs/linux/xorg.md @@ -11,7 +11,6 @@ sudo apt install ubuntu-desktop ``` - ### ubuntu 18.04 issues since ubuntu 18.04 changes from `lightdm` to `gdm3`, there are somethings to do if it fails to start. @@ -33,9 +32,6 @@ since ubuntu 18.04 changes from `lightdm` to `gdm3`, there are somethings to do * reconfigure `xorg.conf` and restart `gdm3` - - - ### basics log files: @@ -211,9 +207,6 @@ sudo systemctl status display-manager log files:`/var/log/lightdm/lightdm.log` - - - ### nomachine related ``` @@ -233,7 +226,6 @@ sudo /etc/NX/nxserver --restart ``` - ### reinstall ubuntu-desktop ```bash diff --git a/docs/linux/zip.md b/docs/linux/zip.md index 25c4d829b..8828f08dc 100644 --- a/docs/linux/zip.md +++ b/docs/linux/zip.md @@ -29,7 +29,6 @@ - # 7z ```bash diff --git a/docs/math/ddpm.md b/docs/math/ddpm.md index 09951c9c0..4124c32a2 100644 --- a/docs/math/ddpm.md +++ b/docs/math/ddpm.md @@ -2,7 +2,11 @@ ### forward + $$ +\displaylines{ x_t = \sqrt \alpha_tx_{t-1} +} $$ + diff --git a/docs/math/graph/graph_clustering.md b/docs/math/graph/graph_clustering.md index cf7c81f3d..9ad21f1f0 100644 --- a/docs/math/graph/graph_clustering.md +++ b/docs/math/graph/graph_clustering.md @@ -3,40 +3,53 @@ there are different objective for a partition of a graph. denotations: + $$ +\displaylines{ links(A, B) = \sum_{i \in A, j \in B}A_{ij} \\ degree(A) = links(A, V)\\ +} $$ + * Ratio association + $$ +\displaylines{ RAssoc(G) = max_{V_1,...,V_k }\sum_{c=1}^k \frac {links(V_c, V_c)}{|V_c|} +} $$ * Ratio cut + $$ +\displaylines{ RCut(G) = min_{V_1,...,V_k }\sum_{c=1}^k \frac {links(V_c, V \setminus V_c)}{|V_c|} \\ +} $$ + if $V_1, ..., V_k$ are all of the same size, we call it the Kernighan-Lin objective. * Normalized cut + $$ +\displaylines{ NCut(G) = min_{V_1,...,V_k }\sum_{c=1}^k \frac {links(V_c, V \setminus V_c)}{degree(V_c)} \\ +} $$ - * General Weighted graph cut/association denote $w(V_c) = \sum_{i \in V_c}w_i$ , use this to replace $|V_c|$ in $RAssoc$ and $RCut$. @@ -44,11 +57,9 @@ $$ we use $WCut, WAssoc$ to denote them. - #### Spectral clustering - #### Graclus multilevel clustering Metis is another multilevel clustering algorithm. diff --git a/docs/math/graph/graph_spectral_theory.md b/docs/math/graph/graph_spectral_theory.md index b3c42e9f4..6a62bfdc4 100644 --- a/docs/math/graph/graph_spectral_theory.md +++ b/docs/math/graph/graph_spectral_theory.md @@ -21,24 +21,30 @@ $\mathcal{L}$ works as a difference operator for any signal $f$ . + $$ +\displaylines{ Lf(i) = \sum_{j}w_{ij}(f(i)-f(j)) +} $$ + Since $\mathcal{L}$ is a real symmetric matrix for an undirected graph, it has $N$ eigenvalues denoted as $\{\lambda_\iota\}_{\iota=0,1,...,N-1}​$. Also, since the graph has at least one connected component, there is at least one eigenvalue that is equal to zero. * **Normalized Graph Laplacian**: + $$ +\displaylines{ \hat{\mathcal{L}} = D^{-1/2}\mathcal{L}D^{-1/2} = I - D^{-1/2}WD^{-1/2} +} $$ - the eigenvalues of $\hat{\mathcal{L}}$ belongs to $[0, 2]$ , with $\hat\lambda = 2$ if and only if $\mathcal{G}$ is bipartite. * **Random Walk Matrix**: $P = D^{-1}W$ @@ -52,29 +58,45 @@ The classical Fourier transform works in **the time domain and the frequency dom For any signal $f$ in the vertex domain, we have its corresponding signal (kernel) $\hat{f}$ in the graph spectral domain. In matrix form, we have $U$ ($n * n$) as the Fourier basis of the graph Laplacian (eigenvectors as columns), $F$ ($n * m$) as a list of $m$ signals on $n$ vertices (each signal is a column). + $$ +\displaylines{ \hat{f}(\lambda_\iota) = \sum_{i=1}^{N}f(i)\mathcal{u}_\iota^*(i) \\ \hat{F} = U'F +} $$ + and the inverse graph Fourier transform: + $$ +\displaylines{ f(i) = \sum_{\iota=0}^{N-1}\hat{f}(\lambda_\iota)u_\iota(i) \\ F = U\hat{F} +} $$ + The eigenvalues and eigenvectors in graph spectral domain provide a similar **notation of frequency**: the eigenvectors with larger eigenvalues contains more zero crossings. ### Discrete Calculus and Signal Smoothness The edge derivative of a signal $f$ with respect to edge $e_{ij}$ at vertex $i$ is defined as : + $$ +\displaylines{ \frac {\partial f} {\partial e} |_i = \sqrt{W_{i,j}}|f(j)-f(i)| +} $$ + The gradient of $f$ at vertex $i$ ($\nabla_if$) is therefore the vector of all derivatives with edges starting from $i$ in the graph. The discrete $p$-Dirichlet form of $f$ is defined as: + $$ +\displaylines{ S_p(f) = \frac {1} {p} \sum_{i \in V}\parallel \nabla_if\parallel_2^p +} $$ + When $p=2$ , it is known as the **graph Laplacian quadratic form**. Seminorm of $f$ is defined as $\parallel f\parallel _\mathcal{L} = \sqrt{S_2(f)}$ . @@ -82,9 +104,13 @@ Seminorm of $f$ is defined as $\parallel f\parallel _\mathcal{L} = \sqrt{S_2(f)} **The smoother the graph, the smaller the $S_2(f)$ .** The discrete regularization framework: + $$ +\displaylines{ {argmin}_f\{\parallel f-y\parallel_2^2 + \gamma S_p(f)\} +} $$ + When $p=2$ ,it is called Tikhonov Regularization and can be used for image denoising. ### Generalized Graph Signal Operators @@ -95,28 +121,37 @@ When $p=2$ ,it is called Tikhonov Regularization and can be used for image denoi let $\hat{h}(1*n)$ be the transfer function in spectral domain. let $H = diag(\hat{h})$ . + $$ +\displaylines{ \hat f_{out}(\lambda_\iota) = \hat f_{in}(\lambda_\iota)\hat h(\lambda_\iota) \\ \hat{F}_{out} = H \hat{F}_{in} +} $$ + $ f_{out} $ can then be calculated through an inverse graph Fourier transform. + $$ +\displaylines{ U' * F_{out} = H U' F_{in} \\ F_{out} = U H U' F_{in} +} $$ + * vertex domain: linear combination within K-hop neighborhoods + $$ +\displaylines{ f_{out}(i) = b_{i,i}f_{in}(i) + \sum_{j \in \mathcal{N}(i,K)}b_{i,j}f_{in}(j) +} $$ - - When the transfer function in graph spectral domain is an **order K polynomial**, the two forms of filtering can be related. ##### Convolution @@ -124,33 +159,49 @@ When the transfer function in graph spectral domain is an **order K polynomial** **Convolution in the vertex domain (the time domain) is equivalent to multiplication in the graph spectral domain (the frequency domain).** Since in the graph setting there is no $h(t-\tau)$, we use multiplication in the graph spectral domain to generalize the definition of convolution: + $$ +\displaylines{ (f *_g h)(i) = \sum_{\iota = 0}^{N-1}\hat f(\lambda_\iota)\hat h(\lambda_\iota)u_\iota(i) \\ f *_g h = U((U'f) \odot (U'g)\\ F *_g h = UHU'F +} $$ + **so convolution with $h$ is just filter with $h$.** ##### Translation It's not clear what it means to translate a graph signal, but we can generalize translation as a convolution with a delta centered at $n$: + $$ +\displaylines{ (T_ng)(i) = \sqrt{N}(g*\delta_n)(i) +} $$ + ##### Modulation + $$ +\displaylines{ (M_kg)(i) = \sqrt{N}u_k(i)g(i) +} $$ + ##### Dilation + $$ +\displaylines{ (\hat{\mathcal{D}_sg)}(\lambda) = \hat g(s\lambda) +} $$ + ##### Coarsening this operation can be separated in to two subtasks: diff --git a/docs/math/quaternion.md b/docs/math/quaternion.md index a03d89dd8..c6445a032 100644 --- a/docs/math/quaternion.md +++ b/docs/math/quaternion.md @@ -3,27 +3,29 @@ > Ref & Credits: https://github.com/Krasjet/quaternion - ### Basics about complex number $\mathbb C$ $$ +\displaylines{ i^2 = -1 \\ - z = a + bi = \begin{bmatrix}a &-b \\ b & a\end{bmatrix} \\ - z_1z_2=z_2z_1 \\ - ||z|| = \sqrt{a^2 + b^2} = \sqrt{z \bar z} +} $$ - - ### 2D Rotation 2D rotation (counter-clockwise by $\theta$) can be represented by: + + $$ +\displaylines{ \mathbf{v'} = \begin{bmatrix}\cos\theta &-\sin\theta \\ \sin\theta & \cos\theta\end{bmatrix} \mathbf{v} +} $$ + + A complex number can represents a 2D vector. Multiply it with a complex number equals **scaling and rotating** in the 2D plane: @@ -32,20 +34,24 @@ let $\theta = \arccos \frac{b}{\sqrt{a^2+b^2}}, r=||z||=\sqrt{a^2+b^2}$: $$ +\displaylines{ z = \begin{bmatrix}a &-b \\ b & a\end{bmatrix} = \sqrt{a^2+b^2} \begin{bmatrix} \frac {a} {\sqrt{a^2+b^2}} & \frac {-b} {\sqrt{a^2+b^2}} \\ \frac{b}{\sqrt{a^2+b^2}} & \frac{a} {\sqrt{a^2+b^2}}\end{bmatrix} = r \begin{bmatrix}\cos \theta & - \sin \theta \\ \sin \theta & \cos \theta\end{bmatrix} \\ = r(\cos\theta + i\sin\theta) \\ = re^{i\theta} +} $$ -Therefore, we also have $v' = zv$ if the scaling factor $r=||z||=1$. +Therefore, we also have $v' = zv$ if the scaling factor $r=||z||=1$. ### 3D Rotation 3D rotation can be represented by three **Euler angles** $(\theta, \phi, \gamma)$, but it relies on the axes system and can lead to Gimbal Lock. + $$ +\displaylines{ \mathbf R_x(\theta) = \begin{bmatrix} @@ -70,7 +76,9 @@ $$ 0&0&1&0 \\ 0&0&0&1\\ \end{bmatrix} \\ +} $$ + Another representation is **axis-angle**: rotation $\theta$ degree along axis $\textbf {u} = (x, y, z)^T$, where $||\mathbf u|| = 1$. (There are still only 3 Degree of Freedom) @@ -78,43 +86,71 @@ Another representation is **axis-angle**: rotation $\theta$ degree along axis $\ ![image-20231120100645841](quaternion.assets/image-20231120100645841.png) which leads to the **Rodrigues' Rotation Formula**: + $$ +\displaylines{ \mathbf v' = \cos\theta\mathbf v + (1 - \cos\theta)(\mathbf u \cdot \mathbf v)\mathbf u + \sin\theta(\mathbf u\times\mathbf v) +} $$ - ### Basics about Quaternion $\mathbb H$ + $$ +\displaylines{ q = a + bi + cj + dk = \begin{bmatrix}a,b,c,d\end{bmatrix}^T \quad (a, b, c, d \in \mathbb R) \\ ||q||=\sqrt{a^2 + b^2 + c^2 + d^2} +} $$ + where + $$ +\displaylines{ i^2=j^2=k^2=ijk=-1 +} $$ + by left-multiplying $i$ or right-multiplying $k$ to $ijk$, we have: + $$ +\displaylines{ ij=k, jk=i +} $$ + further left-multiplying $i$ or right-multiplying $j$ to $ij$ and similar to $jk$, we have: + $$ +\displaylines{ kj=-i, ik=-j,ji=-k +} $$ + lastly right-multiplying $i$ to $ji$, we have: + $$ +\displaylines{ ki=j +} $$ + which leads to an important difference with Complex number: + $$ +\displaylines{ q_1q_2 \neq q_2q_1 +} $$ + ![image-20231120102716151](quaternion.assets/image-20231120102716151.png) The matrix formulation of multiplication: + $$ +\displaylines{ q_1 = a + bi + cj + dk, q_2=e+fi+gj+hk \\ q_1q_2=\begin{bmatrix} a & -b & -c & -d \\ @@ -134,46 +170,71 @@ d & c & -b & a \begin{bmatrix} e \\ f \\ g \\ h \end{bmatrix} +} $$ + A more concise form can be represented by hybrid scalar-vector form (Grafman Product): + $$ +\displaylines{ q_1 = [a, \mathbf v], q_2=[e, \mathbf{u}] \\ \mathbf v = [b, c, d]^T, \mathbf{u}=[f,g,h]^T \\ q_1q_2=[ae-\mathbf v \cdot \mathbf u,a\mathbf u+e\mathbf v+\mathbf v \times \mathbf u] +} $$ + #### Pure quaternion the real part equals 0. + $$ +\displaylines{ v = [0, \mathbf v], u=[0, \mathbf u] \\ vu=[-\mathbf v\cdot\mathbf u, \mathbf v\times\mathbf u] +} $$ + #### Inverse + $$ +\displaylines{ qq^{-1} = q^{-1}q = 1 +} $$ + #### Conjugate + $$ +\displaylines{ q=[s, \mathbf u] \rightarrow q^* = [s, -\mathbf u] \\ (q^*)^* = q \\ qq^*=q^*q=||q||^2=[s^2 + \mathbf u \cdot \mathbf u, 0] \\ ||q||=||q^*|| \\ q_1^*q_2^*=(q_2q_1)^* +} $$ + And we get a method to calculate the inverse: + $$ +\displaylines{ q^{-1} = \frac {q^*} {||q||^2} = [\frac s {s^2 + \mathbf u \cdot \mathbf u}, \frac {-\mathbf{u}} {s^2 + \mathbf u \cdot \mathbf u} ]\\ +} $$ + which also indicates: + $$ +\displaylines{ ||q^{-1}|| = \frac 1 {||q||} \\ (q^{-1})^{-1} = q +} $$ @@ -188,14 +249,22 @@ And we can rewrite the Rodrigues' Rotation Formula in a new form! To rotate $\mathbf{v}$ for $\theta$ degree along axis $\textbf {u} = (x, y, z)^T$, where $||\mathbf u|| = 1$, define + $$ +\displaylines{ v = [0, \mathbf v], q=[\cos\frac\theta 2, \sin\frac\theta 2 \mathbf u] \\ +} $$ + note that $$||q||=1$$, we have: + $$ +\displaylines{ v'=qvq^*=qvq^{-1} +} $$ + > To understand it, we still need to decompose it: > $$ > v'=q(v_{||}+v_{\perp})q^* = qv_{||}q^*+qv_{\perp}q^*=qq^*v_{||}+qqv_\perp = v_{||}+qqv_\perp @@ -207,11 +276,15 @@ $$ > (rotate $\frac \theta 2$ twice equals rotate $\theta$) Inversely, given a unit quaternion $q=[a, \mathbf b]$, we can get the rotation angle and axis by: + $$ +\displaylines{ \theta = 2 \arccos a\\ \mathbf u = \frac {\mathbf {b}} {\sin\theta} +} $$ + #### Matrix form Very complicated form... @@ -221,21 +294,27 @@ Very complicated form... #### Composition of rotation Just do it sequentially, + $$ +\displaylines{ v' = q_2(q_1vq_1^*)q_2^* = (q_2q_1)v(q_2q_1)^* +} $$ + First apply $q_1$ then apply $q_2$ leads to equal rotation of $q_2q_1$. Note that the order matters! $q_1q_2 \ne q_2q_1$. - #### Double cover One 3D rotation can be represented with TWO quaternions: $q$ and $-q$. + $$ +\displaylines{ (-q)v(-q)^*=qvq^* \\ -q = [-\cos\frac\theta 2, -\sin\frac\theta 2 \mathbf u] = [\cos(\pi - \frac\theta 2), \sin(\pi-\frac\theta 2) (-\mathbf u)] +} $$ @@ -244,16 +323,17 @@ $$ Notice that the matrix form is exactly the same for $-q$ and $q$, since all of the elements are multiplication of two coefficients! - #### Euler power form + $$ +\displaylines{ e^{\mathbf u \theta}=\cos \theta + \mathbf u\sin\theta \\ v' = e^{\mathbf u \frac\theta 2} v e^{-\mathbf u \frac \theta 2} +} $$ - ### Implementation ```python diff --git a/docs/math/statistics/Rstatistics.md b/docs/math/statistics/Rstatistics.md index dd72076bb..ff10b8d72 100644 --- a/docs/math/statistics/Rstatistics.md +++ b/docs/math/statistics/Rstatistics.md @@ -14,7 +14,6 @@ cov(x, y) // covariance ``` - ### Distributions ```R @@ -22,7 +21,6 @@ pnorm(x, mean, sd) ``` - ### Quantiles 默认计算$P[x \le z_p] = p$,即下分位数。 @@ -39,7 +37,6 @@ qf(p, df1, df2) ``` - #### Confidence Interval 居然没有原生函数( @@ -64,8 +61,5 @@ confint <- function(x, y, alpha, ratio){ ``` - - - ### test diff --git a/docs/math/statistics/test.md b/docs/math/statistics/test.md index 9ba945400..d26d0125e 100644 --- a/docs/math/statistics/test.md +++ b/docs/math/statistics/test.md @@ -41,10 +41,6 @@ else: print("Significant difference.") - - - ``` - diff --git a/docs/model/blender_tutorial.md b/docs/model/blender_tutorial.md index fe2341daf..f9748ef2d 100644 --- a/docs/model/blender_tutorial.md +++ b/docs/model/blender_tutorial.md @@ -15,7 +15,6 @@ Then open compositing window, and set use nodes, then add an "alpha over" layer ![image-20230817121909364](D:\aa\Notebooks\docs\model\blender_tutorial.assets\image-20230817121909364.png) - ### Add-on `Edit --> Preferences --> Add-ons` @@ -65,7 +64,6 @@ in the same folder, and a name keyword is necessary. * Then go to pose mode, and you can move your bones to visualize the deformed poses! - ### How to render transparent background ![image-20230914130930948](blender_tutorial.assets/image-20230914130930948.png) @@ -124,15 +122,11 @@ In the world properties: ![image-20230305191716034](blender_tutorial.assets/image-20230305191716034.png) - ### Move object origin to mesh center (instead of global center 0,0,0) ![image-20230521220540588](blender_tutorial.assets/image-20230521220540588.png) - - - ### UI and shortcut key * Middle Button (view control) @@ -169,6 +163,5 @@ In the world properties: * Ctrl + Shift + Z: redo - * Ctrl + Alt + 0: **move camera to current view (very useful!)** diff --git a/docs/nas/router/router.md b/docs/nas/router/router.md index 4a7686de7..a35b1c5b8 100644 --- a/docs/nas/router/router.md +++ b/docs/nas/router/router.md @@ -56,6 +56,3 @@ * 静态路由:http://blog.sina.com.cn/s/blog_86d75993010109cr.html - - - diff --git a/docs/nas/synology/frp_nginx_config.md b/docs/nas/synology/frp_nginx_config.md index cdb3f836b..ebe52df00 100644 --- a/docs/nas/synology/frp_nginx_config.md +++ b/docs/nas/synology/frp_nginx_config.md @@ -24,7 +24,6 @@ nohup /root/frp/frpc -c /root/frp/frpc.ini /root/frp/log.txt 2>&1 & ``` - ### `frps.ini` ```ini @@ -39,7 +38,6 @@ dashboard_pwd = ``` - ### `nginx.conf` ```nginx diff --git a/docs/nas/unraid/CA_proxy.md b/docs/nas/unraid/CA_proxy.md index bf7bfee48..7d69e1064 100644 --- a/docs/nas/unraid/CA_proxy.md +++ b/docs/nas/unraid/CA_proxy.md @@ -1,13 +1,11 @@ # Community Applications: The Ultra Proxy Guide. - ### Problems Unraid plugins rely on GitHub. Specifically, it needs to access `github.com` and `raw.githubusercontent.com` to fetch data. - ### manually Install CA * download the plugin in your PC: @@ -23,11 +21,9 @@ Unraid plugins rely on GitHub. Specifically, it needs to access `github.com` and * go to Plugin Tab and install from the local file. - > Ref: https://post.smzdm.com/p/ad2dngvn/ - ### Use docker to setup proxy Since the terminal of unraid do not support package manager (and the alternative `nerdpack` is also a plugin), we would like to use docker to setup `trojan` proxy. @@ -126,7 +122,6 @@ Since the terminal of unraid do not support package manager (and the alternative * Turn on auto-restart of this container. - ### Configure proxy settings for CA * Apps Tab: use `curl` to fetch. @@ -161,5 +156,3 @@ Since the terminal of unraid do not support package manager (and the alternative * Reboot and you are free to load Apps and install Plugins! - - diff --git a/docs/nas/unraid/filebrowser.md b/docs/nas/unraid/filebrowser.md index 7f9135b1f..2b4131c6f 100644 --- a/docs/nas/unraid/filebrowser.md +++ b/docs/nas/unraid/filebrowser.md @@ -3,7 +3,6 @@ [website](https://filebrowser.org/) - ### install * official repo: @@ -27,13 +26,11 @@ (However it is close-sourced, and cannot play `flv` still.) - ### usage Default account/password is `admin/admin`. - ### video it use the browser's video player, so mostly only `.mp4` will work. diff --git a/docs/nas/unraid/frp_example.md b/docs/nas/unraid/frp_example.md index 787d2c77f..b07b368b5 100644 --- a/docs/nas/unraid/frp_example.md +++ b/docs/nas/unraid/frp_example.md @@ -1,7 +1,6 @@ # frp docker - ### client side by docker * create `/boot/config/frp/frpc.ini` and write: diff --git a/docs/nas/unraid/remote_access.md b/docs/nas/unraid/remote_access.md index 3530bd183..450d91f6c 100644 --- a/docs/nas/unraid/remote_access.md +++ b/docs/nas/unraid/remote_access.md @@ -1,7 +1,6 @@ # remote access - ### 路由器端口映射 将路由器LAN的端口映射到WAN的端口。 @@ -51,10 +50,6 @@ > 比较麻烦,但校园网不支持... - - - ![image-20211117222714270](remote_access.assets/image-20211117222714270.png) - diff --git a/docs/nas/unraid/webdav_raidrive.md b/docs/nas/unraid/webdav_raidrive.md index a2b9f0207..fd628505c 100644 --- a/docs/nas/unraid/webdav_raidrive.md +++ b/docs/nas/unraid/webdav_raidrive.md @@ -7,7 +7,6 @@ just search `webdav` and install it. default port maybe `8384`. - ### install RaiDrive search from google and download it. diff --git a/docs/onnx/basics.md b/docs/onnx/basics.md index 6ad49f3a5..12f879d04 100644 --- a/docs/onnx/basics.md +++ b/docs/onnx/basics.md @@ -5,7 +5,6 @@ ONNX: An open standard format for ML models. ONNX Runtime: a multi-platform and hardware performance-focused engine for ONNX models. - ## Python API Install: diff --git a/docs/onnx/web.md b/docs/onnx/web.md index 95b9d04c2..3ac2c4c5d 100644 --- a/docs/onnx/web.md +++ b/docs/onnx/web.md @@ -7,6 +7,5 @@ npm install -S onnxruntime-web ``` - ### example diff --git a/docs/others/chebnet_understanding.md b/docs/others/chebnet_understanding.md index 074dd7487..e422c5a6d 100644 --- a/docs/others/chebnet_understanding.md +++ b/docs/others/chebnet_understanding.md @@ -3,9 +3,13 @@ convolution in spectral domain is just a frequency filter. let the graph Laplacian is $n * n$. + $$ +\displaylines{ y = UHU'x = Ug_\theta(\lambda)U'x = g_\theta(L)x +} $$ + but to learn a filter's complicity is $O(n)$. (there are $n$ free parameters) the problem is how to make it faster. @@ -13,25 +17,32 @@ the problem is how to make it faster. we need parametrization of the filter. we use Chebyshev polynomial to approximate it. + $$ +\displaylines{ g_\theta(\lambda) = diag(\theta) \rightarrow \sum_{k=0}^{K-1}\theta_k\Lambda^k \rightarrow \sum_{k=0}^{K-1}\theta_kT_k(\tilde\Lambda) \\ \Lambda = diag(\lambda)\\ g_\theta(L) \rightarrow Ug_\theta(\lambda)U' = \sum_{k=0}^{K-1}\theta_kT_k(\tilde L) \\ then \ \ \ y = g_\theta(L)x \\ let \ \ \bar{x_k} = T_k(\tilde L)x \\ y = \bar{X}\theta \\ +} $$ + due to the property of Chebyshev: + $$ +\displaylines{ \bar{x_k} = 2\tilde L \bar{x_{k-1}} - \bar{x_{k-2}} \\ \tilde L = 2L/\lambda_{max} - I +} $$ + so we avoided computing eigenvalues and Fourier basis $U$ , and just use $L$ and $\lambda_{max}$ to recursively calculate $y$ from $x$. time complexity is from $O(n^2)$ to $O(K|\mathcal E|)$ - #### Pooling pooling is clustering or cutting for a graph. @@ -50,7 +61,6 @@ Then we pool it by adding fake nodes to build a balanced binary tree. Finally, we feed it to a Fully connected Layer for Output. - #### Codes * graph @@ -378,14 +388,6 @@ class model_perf: ``` - #### Example - - - - - - - diff --git a/docs/others/chrom_custom_search.md b/docs/others/chrom_custom_search.md index 98ecee342..0338b143b 100644 --- a/docs/others/chrom_custom_search.md +++ b/docs/others/chrom_custom_search.md @@ -1,9 +1,6 @@ ## custom search keyword - - - Chrome: 设置-搜索引擎-管理搜索引擎和网站搜索-网站搜索-添加 * google scholar: https://scholar.google.com/scholar?q=%s @@ -14,7 +11,6 @@ Chrome: 设置-搜索引擎-管理搜索引擎和网站搜索-网站搜索-添 * twitter: https://twitter.com/search?q=%s - ### Reference https://gist.github.com/siboehm/53d2b498e1470d32f0af13b2c39a9520 \ No newline at end of file diff --git a/docs/others/code_duplicate_check.md b/docs/others/code_duplicate_check.md index e8fc52b17..e5b815248 100644 --- a/docs/others/code_duplicate_check.md +++ b/docs/others/code_duplicate_check.md @@ -27,7 +27,6 @@ compare similarity of vectors. - ### example ```python diff --git a/docs/others/ffmpeg_tutorial.md b/docs/others/ffmpeg_tutorial.md index c18e12bc9..cc6c6ad09 100644 --- a/docs/others/ffmpeg_tutorial.md +++ b/docs/others/ffmpeg_tutorial.md @@ -59,7 +59,6 @@ ffmpeg -i in.mp4 -vf reverse -af reverse out.mp4 ``` - ## ffplay ```bash diff --git a/docs/others/google_protobuff.md b/docs/others/google_protobuff.md index 65a7053d6..e245d61f2 100644 --- a/docs/others/google_protobuff.md +++ b/docs/others/google_protobuff.md @@ -55,7 +55,6 @@ message AddressBook { this generate `*_pb2.py` files in the python_out directory. - * API ```python @@ -71,7 +70,6 @@ message AddressBook { ``` - ### Proto3 ##### Message @@ -129,14 +127,11 @@ can be viewed as class in python. ``` - - ##### comments same as C/C++. - ##### reserved field ```protobuf @@ -149,7 +144,6 @@ message Foo { you should reserve the field number or name for your deleted fields, in case of later modifications reuse these fields and cause bugs. - ##### import ```protobuf @@ -169,7 +163,6 @@ when `old.proto` is imported by another proto file saying `client.proto,` python will ignore package declarations, since python modules are organized according to locations in file system. - ##### oneof oneof is a type that means the message will only record one of its fields or subclasses. @@ -192,4 +185,3 @@ CHECK(!message.has_name()); ``` - diff --git a/docs/others/nerf_gradient.md b/docs/others/nerf_gradient.md index dfd861a61..c2995a70d 100644 --- a/docs/others/nerf_gradient.md +++ b/docs/others/nerf_gradient.md @@ -2,7 +2,9 @@ Basic notations: (assume single color channel denoted as $R$) + $$ +\displaylines{ \begin{align} \alpha_i &= 1 - e^{- \sigma_i \delta_i} \\ @@ -18,32 +20,44 @@ R_i &= \sum_{j=1}^i w_j r_j \\ R &= R_N \end{align} +} $$ + Gradient towards color: + $$ +\displaylines{ \begin{align} \frac {\partial L} {\partial r_i} &= \frac {\partial L} {\partial R} \frac {\partial R} {\partial r_i} \\ &= \frac {\partial L} {\partial R} w_i \\ &= \frac {\partial L} {\partial R} \alpha_iT_i \end{align} +} $$ + Gradient towards sigma: + $$ +\displaylines{ \begin{align} \frac {\partial L} {\partial \sigma_i} &= \frac {\partial L} {\partial R} \frac {\partial R} {\partial \sigma_i} \\ &= \frac {\partial L} {\partial R} \frac {\partial R} {\partial \alpha_i} \frac {\partial \alpha_i} {\partial \sigma_i} \\ \end{align} +} $$ + We have: + $$ +\displaylines{ \begin{align} \frac {\partial R} {\partial \alpha_i} &= \frac {\partial \sum_{j=1}^N \alpha_jT_jr_j } {\partial \alpha_i} \\ @@ -58,30 +72,42 @@ $$ &= \frac {1} {1-\alpha_i} (T_{i+1}r_i - \sum_{j=i+1}^N\alpha_jT_jr_j) \\ &= \frac {1} {1-\alpha_i} (T_{i+1}r_i -(R - R_i)) \end{align} +} $$ + And since: + $$ +\displaylines{ \frac {\partial \alpha_i} {\partial \sigma_i} = \delta_ie^{-\sigma_i\delta_i}=\delta_i(1-\alpha_i) +} $$ + We finally have: + $$ +\displaylines{ \begin{align} \frac {\partial L} {\partial \sigma_i} &= \frac {\partial L} {\partial R} \frac {\partial R} {\partial \alpha_i} \frac {\partial \alpha_i} {\partial \sigma_i} \\ &= \frac {\partial L} {\partial R} \delta_i (1-\alpha_i) \frac {1} {1-\alpha_i} (T_{i+1}r_i -(R - R_i)) \\ &= \frac {\partial L} {\partial R} \delta_i (T_{i+1}r_i -(R - R_i)) \end{align} +} $$ + And this is the form used in `instant-ngp`. A more beautiful form: + $$ +\displaylines{ \begin{align} T_{i+1}r_i - \sum_{j=i+1}^N\alpha_jT_jr_j &= (1-\alpha_i)T_ir_i - \sum_{j=i+1}^N\alpha_jT_jr_j \\ @@ -89,4 +115,6 @@ T_{i+1}r_i - \sum_{j=i+1}^N\alpha_jT_jr_j &= T_ir_i - \sum_{j=i}^N\alpha_jT_jr_j \\ &= T_ir_i - (R-R_{i-1}) \end{align} +} $$ + diff --git a/docs/others/programming_language_type.md b/docs/others/programming_language_type.md index ca5f586c4..07a4a2b5d 100644 --- a/docs/others/programming_language_type.md +++ b/docs/others/programming_language_type.md @@ -3,7 +3,6 @@ ![img](programming_language_type.assets/b0aeb7ffd1667b9162e5329154d43777_1440w.jpg) - * Dynamic Language: type of variables are determined at runtime. * Static Language: type of variables are determined at compilation. diff --git a/docs/others/recommenders.md b/docs/others/recommenders.md index ec95c656b..b25e188a8 100644 --- a/docs/others/recommenders.md +++ b/docs/others/recommenders.md @@ -5,7 +5,6 @@ * https://developers.google.com/machine-learning/recommendation - ### Problem Definition Recommender algorithm can be defined as a matrix completion problem. @@ -21,9 +20,6 @@ an application of recsys. (e.g., in app store) Each user/item may have additional features to use. - - - ### Large scale Recommendation System pipeline #### Candidate Generation @@ -56,11 +52,6 @@ A precise & slower model is used. post processing, such as remove explicitly disliked items. - - - - - ### Alternating Least Square (ALS) Main idea: Matrix factorization. @@ -71,10 +62,14 @@ Assume $R \approx X^TY$. Optimize: + $$ +\displaylines{ \min_{X,Y} \sum_{r_{ui}}^{\text{observed}} (r_{ui} - x_u^Ty_i)^2 + \lambda (\sum_u||x_u||^2+\sum_i||y_i||^2) +} $$ + This is nonconvex, but we can make a 2-step iterative optimization to separately optimize X and Y: * Repeat until Converge: (**WHY???**) @@ -82,37 +77,42 @@ This is nonconvex, but we can make a 2-step iterative optimization to separately * Fix Y, update X + $$ +\displaylines{ x_u = (\sum_{r_{ui} \in r_{u*}}y_iy_i^T+\lambda I_k)^{-1} \sum_{r_{ui} \in r_{u*}}r_{ui}y_i +} $$ * Fix X, update Y + $$ +\displaylines{ y_i = (\sum_{r_{ui} \in r_{*i}}x_ux_u^T+\lambda I_k)^{-1} \sum_{r_{ui} \in r_{*i}}r_{ui}x_u +} $$ * Inference: + $$ +\displaylines{ r_{ui} = x_u^Ty_i +} $$ - - - - ### Wide & Deep (2016, Google) wide = Linear Regression (Memorization) diff --git a/docs/others/vs_code_hotkey.md b/docs/others/vs_code_hotkey.md index 92ffd89fd..46c2a33c5 100644 --- a/docs/others/vs_code_hotkey.md +++ b/docs/others/vs_code_hotkey.md @@ -13,7 +13,6 @@ 选中代码块, `shift+tab` 或 `tab` - ### 多光标模式 * `Alt+click` @@ -24,13 +23,11 @@ * `Esc` 退出多光标模式 - ### 块选中 **`shift+alt`+鼠标拖拽** - ### 跳转定义 `F12` 跳转至定义 @@ -38,7 +35,6 @@ `Alt+Left` 后退 - ### 重复当前行 * 复制当前行到上/下行 `Shift+Alt+Up/Down` @@ -47,19 +43,16 @@ * 剪切当前行(无选中时)`Ctrl+X` - ### 移动当前行 `Alt+Up/Down` - ### 查找光标下的单词 `Ctrl+D` - ### 自动分屏 `Ctrl+Alt+ -> ` 新窗口自动在右边分屏 diff --git a/docs/python/config.md b/docs/python/config.md index af363e7f4..e240ab4cf 100644 --- a/docs/python/config.md +++ b/docs/python/config.md @@ -1,5 +1,3 @@ -## ultimate config - ### argparse when you just have a simple project, and don't want to write `yaml` config files. @@ -13,7 +11,6 @@ opt = parser.parse_args() ``` - ### omega conf for large projects, when you need different configs (`yaml`) for different running. @@ -93,4 +90,9 @@ use it in command line: python main.py --config configs/base.yaml --train --gpu 0 # override config python main.py --config configs/base.yaml --train --gpu 0 x=2 # now x is 2 -``` \ No newline at end of file +``` + + +### tyro + +An even better library, satisfying all the need, check the separate note [here](./tyro.md). \ No newline at end of file diff --git a/docs/python/cython.md b/docs/python/cython.md index 514330fa1..b417bf699 100644 --- a/docs/python/cython.md +++ b/docs/python/cython.md @@ -5,11 +5,9 @@ > Cython: C-extension of Python, allows to compile python code for speeding up. - The extension of Cython file is `.pyx` - ### Example `primes.pyx`: @@ -65,7 +63,6 @@ primes.primes(10) ``` - ### C library ```python @@ -83,9 +80,6 @@ cdef double f(double x): ``` - - - ### C++ library ```python diff --git a/docs/python/dearpygui.md b/docs/python/dearpygui.md index 4e7ce13ae..d87593f39 100644 --- a/docs/python/dearpygui.md +++ b/docs/python/dearpygui.md @@ -7,7 +7,6 @@ pip install dearpygui ``` - ### Pipeline Context --> Viewport --> DearPyGUI diff --git a/docs/python/gradio.md b/docs/python/gradio.md index eaeb56753..b9b6f3ed8 100644 --- a/docs/python/gradio.md +++ b/docs/python/gradio.md @@ -9,7 +9,6 @@ pip install gradio ``` - ### example ```python @@ -93,9 +92,6 @@ gr.Interface(fn=predict, ``` - - - ### Components ```python @@ -104,7 +100,6 @@ name = gr.Textbox(label="Name") ``` - ### Event Listener ```python @@ -124,9 +119,6 @@ inp.change(greet, inp, out) ``` - - - ### Iterative Outputs ```python @@ -156,9 +148,6 @@ demo.launch() ``` - - - ### Queuing Control the concurrency rate. Should be used if the core function takes > 1min to process. @@ -169,7 +158,6 @@ demo.launch() ``` - ### State To preserve information between multiple submits. diff --git a/docs/python/hash.md b/docs/python/hash.md index 76ec078ae..668bbba7a 100644 --- a/docs/python/hash.md +++ b/docs/python/hash.md @@ -20,7 +20,6 @@ hash(10.1) == hash(230584300921368586) # True ``` - ### The exact algorithms in `cpython` source, e.g., diff --git a/docs/python/introspection.md b/docs/python/introspection.md index 693a349e8..eb89ad5cd 100644 --- a/docs/python/introspection.md +++ b/docs/python/introspection.md @@ -30,7 +30,6 @@ vars(foo) ``` - ### `dir()` `dir(x)` returns the names of attributes & methods of all levels (both current class and base class). @@ -101,7 +100,6 @@ dir(foo) ``` - ### inspect ```python diff --git a/docs/python/mkdocs.md b/docs/python/mkdocs.md index 6db8e517a..369880eb0 100644 --- a/docs/python/mkdocs.md +++ b/docs/python/mkdocs.md @@ -7,7 +7,6 @@ pip install mkdocs-material ``` - ### setup Init a workspace: @@ -19,7 +18,6 @@ mkdocs new . Then add your markdowns to `docs`. Folder structure will be preserved in the navigation. - ### configuration edit `mkdocs.yml`, an example: @@ -79,7 +77,6 @@ window.MathJax = { ``` - ### serve At the root of workspace: @@ -91,7 +88,6 @@ mkdocs serve by default it serves at `localhost:8000` - ### deploy Use github workflows to automatically deploy to github pages: @@ -119,7 +115,6 @@ jobs: It is invoked at each push to master branch. - ### problems * The math plugin seems to have more strict rules compared to typora. Most math blocks are not rendered correctly... \ No newline at end of file diff --git a/docs/python/monky_patch.md b/docs/python/monky_patch.md index 687b58bb5..c4c261735 100644 --- a/docs/python/monky_patch.md +++ b/docs/python/monky_patch.md @@ -1,7 +1,6 @@ ## Monkey patch a method - To patch the `forward` of a `nn.Module`, **define a closure** that keeps temporary variables and returns your new `forward`: ```python @@ -41,7 +40,6 @@ patched forward of b ``` - However, you cannot patch magic methods like `__call__` by this: ```python diff --git a/docs/python/numpy_pitfalls.md b/docs/python/numpy_pitfalls.md index 2596f5195..6d71dc42e 100644 --- a/docs/python/numpy_pitfalls.md +++ b/docs/python/numpy_pitfalls.md @@ -37,7 +37,6 @@ print(a[:, None] + b) ``` - ### View Without touching underlying data, a `view` is the datatype and shape of the data. @@ -66,7 +65,6 @@ Cons: * [space] even if only a small slice is used, the pointed data maybe large and cannot be released. Use `.copy()` if you are sure the old data will not be used and should be garbage-collected! - ### indexing & Slicing (IMPORTANT!) We discuss the behavior of `x[obj]`, which can be classified as: @@ -206,7 +204,6 @@ Tips: - ### assign value by a list of coordinates ```python @@ -233,7 +230,6 @@ tuple(coords.T) is: (array([0, 1, 2, 3]), array([1, 2, 3, 4])) ``` - ### slice ```python @@ -249,7 +245,6 @@ print(a[s_odd]) # equals a[1::2] ``` - ### meshgrid ```python @@ -290,9 +285,6 @@ torch.meshgrid(torch.arange(3), torch.arange(4)) ``` - - - ### numpy add by index, with duplicated indices In numpy >= 1.8, you can also use the `at` method of the addition 'universal function' ('ufunc'). As the [docs note](http://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc.at.html): @@ -323,7 +315,6 @@ np.negative.at(np.array([1,2,3]), [0,2]) # [-1,2,-3] ``` - Torch's equivalent: ```python @@ -347,7 +338,6 @@ torch_scatter.scatter_add(c, b, out=a) # ([0, 0, 2, 1, 0, 1]), correctly accumul Note: the name `index_put_` is tricky, `index_add_` is another different thing in torch, which is less flexible to achieve what we are doing. - ### numpy add by 2D (or nD) index The desired operation: @@ -383,9 +373,6 @@ a.index_put_(tuple(b.T), c, accumulate=True) # as expected. ``` - - - ### take v.s. take_along_axis `np.take` is in fact simple indexing. diff --git a/docs/python/open3d_ASH.md b/docs/python/open3d_ASH.md index 333657e78..a51306eb4 100644 --- a/docs/python/open3d_ASH.md +++ b/docs/python/open3d_ASH.md @@ -19,7 +19,6 @@ th_a = torch.utils.dlpack.from_dlpack(o3_a.to_dlpack()) ``` - ### Hash API ```python @@ -152,4 +151,3 @@ active_keys = hashset.key_tensor()[active_buf_indices] ``` - diff --git a/docs/python/pybind.md b/docs/python/pybind.md index a2b0fcda9..c21b23793 100644 --- a/docs/python/pybind.md +++ b/docs/python/pybind.md @@ -7,7 +7,6 @@ pip install pybind11 ``` - ### example `example.cpp`: @@ -42,7 +41,6 @@ example.add(1, 2) ``` - ### binding basics * functions @@ -342,10 +340,6 @@ TODO: https://github.com/pybind/pybind11/blob/master/tests/test_eigen.cpp ##### Eigen Matrix --> numpy ndarray - - - - ### Building * `Setuptools` diff --git a/docs/python/pymeshlab.md b/docs/python/pymeshlab.md index 41e92f1ad..fef3dd42b 100644 --- a/docs/python/pymeshlab.md +++ b/docs/python/pymeshlab.md @@ -1,7 +1,6 @@ ## PyMeshLab - ### install ```bash @@ -9,7 +8,6 @@ pip install pymeshlab ``` - ### usage Basics: @@ -54,7 +52,6 @@ ms.clear() ``` - Numpy interaction: ```python @@ -79,7 +76,6 @@ faces = m.face_matrix() ``` - Filter script (automatic processing) ```python @@ -106,7 +102,6 @@ ms.apply_filter_script() ``` - ### Useful Filters ```python @@ -136,7 +131,6 @@ ms.meshing_repair_non_manifold_vertices(vertdispratio=0) ``` - [T-vertices](): Vertices in the mid of an edge. Could be fixed by tessellation. ![image-20221201134302514](pymeshlab.assets/image-20221201134302514.png) diff --git a/docs/python/pypi_publish.md b/docs/python/pypi_publish.md index 06ed8559b..94263cc40 100644 --- a/docs/python/pypi_publish.md +++ b/docs/python/pypi_publish.md @@ -1,7 +1,6 @@ # PyPi publish - ### Prepare `setup.py` A simple example: @@ -36,7 +35,6 @@ if __name__ == '__main__': `setup.cfg` is a static alternative of `setup.py`. Usually we don't need it. (although `setuptools` aims to transfer to the static one.) - ### `pytest` for unit test ```python @@ -95,7 +93,6 @@ pytest -k Class.method ``` - ### `.gitignore` ``` @@ -112,7 +109,6 @@ dist/ ``` - `LICENSE` ``` @@ -140,9 +136,6 @@ THE SOFTWARE. ``` - - - ### Publishing First, build the distributions by: @@ -167,7 +160,6 @@ twine upload dist/numpytorch-0.1.2.tar.gz Note: you cannot delete or replace published versions! To update the code, you must change the version code and rebuild the package, then upload a different version (e.g., 0.1.3). - ### Add static files By default `sdist` only bundle code files, if you have some data, like the `onnx` models, you should use `MANIFEST.in` to add them. @@ -192,7 +184,6 @@ setup( Now you can run `python setup.py sdist` to check whether it copies your static files. - ### Automatic publishing with github actions create workflows at `.github/workflows/pypi-publish.yml`: @@ -238,7 +229,6 @@ When you want to publish a new version, navigate to **release** and release a ve Then github actions will build and publish current repository state automatically! - ### the setup script ```python diff --git a/docs/python/pytorch_pitfalls.md b/docs/python/pytorch_pitfalls.md index e0b7554ec..93c2981d3 100644 --- a/docs/python/pytorch_pitfalls.md +++ b/docs/python/pytorch_pitfalls.md @@ -75,7 +75,6 @@ ``` - ### ``torch.scatter(input, dim, index, src)`` For the input specifications, it is very similar to `gather`. diff --git a/docs/python/re_tutorial.md b/docs/python/re_tutorial.md index 2f7e82aa9..ba12d6269 100644 --- a/docs/python/re_tutorial.md +++ b/docs/python/re_tutorial.md @@ -11,7 +11,6 @@ r'\s*' ``` - ### Special Characters * `.` @@ -41,7 +40,6 @@ r'\s*' * `\W`: [ ^a-zA-Z0-9_] - ### API ```python @@ -70,7 +68,6 @@ m.endpos ``` - ### Examples ```python diff --git a/docs/python/threading_multiprocessing.md b/docs/python/threading_multiprocessing.md index c2cc1406a..09d7483ae 100644 --- a/docs/python/threading_multiprocessing.md +++ b/docs/python/threading_multiprocessing.md @@ -1,14 +1,12 @@ # threading and multiprocessing - ### difference between threading and multiprocessing * threading is limited by the GIL (for CPython), so only one python process can run at the same time. * object can be shared between threads (memory sharing), but **must be copied** per process. - ### GIL (Global Interpreter Lock) * What: a mutex that only allows one thread to access python objects at any time. @@ -62,7 +60,6 @@ - ### multiprocessing thread start method @@ -77,7 +74,6 @@ mp.set_start_method('spawn') ``` - simple data-parallel: ```python @@ -109,7 +105,6 @@ with Pool(8) as p: ``` - sender-receiver model with Queue: ```python @@ -175,13 +170,9 @@ a.run() ``` - - - ### threading - sender-receiver model ```python @@ -227,4 +218,3 @@ a.run() ``` - diff --git a/docs/python/tyro.md b/docs/python/tyro.md index 0f06116f3..ea986d583 100644 --- a/docs/python/tyro.md +++ b/docs/python/tyro.md @@ -5,7 +5,6 @@ Although `omegaconf`+`argparse` is great for a research project, it's not suitab With `tyro`, we can write a package CLI elegantly! - ### Function The simplest use case, turn a function into a CLI. @@ -30,7 +29,6 @@ python main.py --x 1 --path wow ``` - ### Dataclass For more complex configs. @@ -139,7 +137,6 @@ usage: main.py [-h] --x INT --flag1 {True,False} [--path STR] [--shape INT [INT ``` - ### Hierarchical Configs For nesting configs. @@ -190,7 +187,6 @@ usage: main.py [-h] [--optimizer.type {adam,sgd}] [--optimizer.lr FLOAT] [--seed ``` - ### Subcommands ```python @@ -247,7 +243,6 @@ usage: main.py train [-h] [--type {adam,sgd}] [--lr FLOAT] [--seed INT] [--itera ``` - ### Subcommands for overriding default configs This can reach the same effect as using multiple config files with `omegaconf`, but it's a little tricky... diff --git a/docs/python/unittest.md b/docs/python/unittest.md index fa3ed6433..b1f48b424 100644 --- a/docs/python/unittest.md +++ b/docs/python/unittest.md @@ -24,7 +24,6 @@ if __name__ == '__main__': ``` - ```bash python -m unittest tests/test_something.py diff --git a/docs/python/walk.md b/docs/python/walk.md index 19d178709..7cee66cf3 100644 --- a/docs/python/walk.md +++ b/docs/python/walk.md @@ -12,7 +12,6 @@ os.path.dirname(path) # a/b/c --> a/b ``` - ### os.walk ```python diff --git a/docs/readings/3d reconstruction and generation.md b/docs/readings/3d reconstruction and generation.md index 3a9a45681..23ce20a32 100644 --- a/docs/readings/3d reconstruction and generation.md +++ b/docs/readings/3d reconstruction and generation.md @@ -1,13 +1,11 @@ # Single-/Multi- view 3D Reconstruction and Generation - We focus on the problem of 3D reconstruction / generation from single or multiple (but not too many) RGB (D)s. The problem is usually ill-posed (ambiguous), and needs to guess / generate some content. - ## Object Level > Category: @@ -41,9 +39,6 @@ The problem is usually ill-posed (ambiguous), and needs to guess / generate some > * Output: Voxels --> Point Cloud / Implicit Function / Mesh - - - #### [ECCV 2016] 3D-R2N2: 3D Recurrent Reconstruction Neural Network ``` @@ -71,7 +66,6 @@ The problem is usually ill-posed (ambiguous), and needs to guess / generate some ![image-20210401215040718](3d reconstruction and generation.assets/image-20210401215040718.png) - #### [3DV 2017] Hierarchical Surface Prediction for 3D Object Reconstruction [paper](https://arxiv.org/abs/1704.00710) @@ -84,19 +78,16 @@ The problem is usually ill-posed (ambiguous), and needs to guess / generate some ![image-20210401215558646](3d reconstruction and generation.assets/image-20210401215558646.png) - #### [ICCVW 2017] 3D Object Reconstruction from a Single Depth View with Adversarial Learning [paper](https://arxiv.org/abs/1708.07969) - #### [ICCV 2017] Octree Generating Networks: Efficient Convolutional Architectures for High-resolution 3D Outputs [paper](https://arxiv.org/abs/1703.09438) | [code](https://github.com/lmb-freiburg/ogn) - #### [NIPS 2017] MarrNet: 3D Shape Reconstruction via 2.5D Sketches [paper](https://arxiv.org/abs/1711.03129) @@ -104,7 +95,6 @@ The problem is usually ill-posed (ambiguous), and needs to guess / generate some ![image-20210401220252010](3d reconstruction and generation.assets/image-20210401220252010.png) - #### [CVPR 2017] A point set generation network for 3d object reconstruction from a single image. [paper](https://arxiv.org/pdf/1612.00603.pdf) @@ -115,7 +105,6 @@ The problem is usually ill-posed (ambiguous), and needs to guess / generate some * Output: Point Cloud - #### [ECCV 2018] Pixel2Mesh: Generating 3D Mesh Models from Single RGB Images [paper](https://arxiv.org/pdf/1804.01654.pdf) | [code](https://github.com/nywang16/Pixel2Mesh) @@ -128,7 +117,6 @@ The problem is usually ill-posed (ambiguous), and needs to guess / generate some ![image-20210401222806763](3d reconstruction and generation.assets/image-20210401222806763.png) - #### [ECCV 2018] Learning Category-Specific Mesh Reconstruction from Image Collections. ``` @@ -156,7 +144,6 @@ The problem is usually ill-posed (ambiguous), and needs to guess / generate some ![image-20210401212228981](3d reconstruction and generation.assets/image-20210401212228981.png) - #### [ECCV 2014] OpenDR: An approximate differentiable renderer. [paper](https://files.is.tue.mpg.de/black/papers/OpenDR.pdf) @@ -189,7 +176,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima * we propose an approximate gradient for rasterization that enables the integration of rendering into neural networks. - #### [ICCV 2019] Soft Rasterizer: A differentiable renderer for image-based 3d reasoning. [paper](https://arxiv.org/abs/1904.01786) | [code](https://github.com/ShichenLiu/SoftRas) @@ -223,7 +209,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima ![image-20210402101531055](3d reconstruction and generation.assets/image-20210402101531055.png) - #### [NIPS 2019] DISN: Deep Implicit Surface Network for High-quality Single-view 3D Reconstruction [paper](https://arxiv.org/pdf/1905.10711.pdf) | [code](https://github.com/laughtervv/DISN) @@ -234,7 +219,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima * Output: Implicit Function - #### [ECCV 2020] Shape and viewpoint without keypoints. [paper](https://arxiv.org/abs/2007.10982) | [code](https://github.com/shubham-goel/ucmr) @@ -253,7 +237,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima ![image-20210402103514003](3d reconstruction and generation.assets/image-20210402103514003.png) - #### [ECCV 2020] Self-supervised single-view 3d reconstruction via semantic consistency [paper](https://arxiv.org/pdf/2003.06473.pdf) @@ -271,7 +254,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima ![image-20210402102613777](3d reconstruction and generation.assets/image-20210402102613777.png) - #### [CVPR 2020] From Image Collections to Point Clouds with Self-supervised Shape and Pose Networks ``` @@ -293,7 +275,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima ![image-20210401221826288](3d reconstruction and generation.assets/image-20210401221826288.png) - #### [NIPS 2020] Convolutional Generation of Textured 3D Meshes ``` @@ -324,9 +305,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima ![image-20210401213317770](3d reconstruction and generation.assets/image-20210401213317770.png) - - - #### [Arxiv 2021] Learning Generative Models of Textured 3D Meshes from Real-World Images ``` @@ -354,7 +332,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima ![image-20210402101126321](3d reconstruction and generation.assets/image-20210402101126321.png) - #### [Arxiv 2021] NeuTex: Neural Texture Mapping for Volumetric Neural Rendering ``` @@ -383,7 +360,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima ![image-20210402105216141](3d reconstruction and generation.assets/image-20210402105216141.png) - #### [Arxiv 2021] Putting NeRF on a Diet: Semantically Consistent Few-Shot View Synthesis [paper](https://arxiv.org/pdf/2104.00677.pdf) @@ -395,9 +371,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima image-20210402142103260 - - - > Remaining Problems: > > * Avoid using topologically fixed Mesh Template @@ -408,11 +381,9 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima > * How to extract mesh from NeRF? (view-dependent to independent) - ## Scene Level - #### [CVPR 2018] ScanComplete: Large-Scale Scene Completion and Semantic Segmentation for 3D Scans ``` @@ -439,7 +410,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima ![img](https://github.com/angeladai/ScanComplete/raw/master/images/teaser_mesh.jpg) - #### [CVPR 2020] SynSin: End-to-end View Synthesis from a Single Image [paper](https://arxiv.org/abs/1912.08804) | [code](https://github.com/facebookresearch/synsin) @@ -456,7 +426,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima ![image-20210402151112751](3d reconstruction and generation.assets/image-20210402151112751.png) - #### [CVPR 2020] SG-NN: Sparse Generative Neural Networks for Self-Supervised Scene Completion of RGB-D Scans ``` @@ -483,7 +452,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima ![img](https://github.com/angeladai/sgnn/raw/master/sgnn.jpg) - #### [TPAMI 2020] Semantic Scene Completion using Local Deep Implicit Functions on LiDAR Data [paper](https://arxiv.org/abs/2011.09141) @@ -494,7 +462,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima * Output: Implicit Function with semantics. - #### [Arxiv 2021] SPSG: Self-Supervised Photometric Scene Generation from RGB-D Scans ``` @@ -525,9 +492,6 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima ![image-20210402133455770](3d reconstruction and generation.assets/image-20210402133455770.png) - - - > Remaining Problems: > > * Self-supervised SSC @@ -547,13 +511,9 @@ Inverse graphics: reverse-engineer the physical process that produced a real ima > * Hard. It's better to divide and conquer, by first detecting objects and layout. - - - ------- - #### [] `` diff --git a/docs/readings/paper recommendation 2022.md b/docs/readings/paper recommendation 2022.md index c564a586c..f066cf6e5 100644 --- a/docs/readings/paper recommendation 2022.md +++ b/docs/readings/paper recommendation 2022.md @@ -1,7 +1,6 @@ # Paper Recommendation 2022 - ### Tips: * Check **[Project]/[Blog]** first for a brief understanding of the paper, and watch their introduction video if available. @@ -9,7 +8,6 @@ * Only about 2 papers are chosen for each area. If you find a paper interesting, please use [[Connected Papers]](https://www.connectedpapers.com/) to find related works! - ### Backbone * [2015] **Deep Residual Learning for Image Recognition** [[Paper]](https://arxiv.org/abs/1512.03385) @@ -25,7 +23,6 @@ * [2021] **CLIP: Connecting Text and Images** [[Blog]](https://openai.com/blog/clip/) [[Code]](https://github.com/openai/CLIP) [[Paper]](https://arxiv.org/abs/2103.00020) - ### Perception (Classification, Segmentation, Detection) #### 2D @@ -55,7 +52,6 @@ Different from 2D images, 3D data have many representations (voxel volumes, poin * [2020] **Searching Efficient 3D Architectures with Sparse Point-Voxel Convolution** [[Paper]](https://arxiv.org/abs/2007.16100) [[Code]](https://github.com/mit-han-lab/torchsparse) - ### Generation * [2014] **Generative Adversarial Networks** [[Paper]](https://arxiv.org/abs/1406.2661) @@ -73,7 +69,6 @@ Different from 2D images, 3D data have many representations (voxel volumes, poin Further readings: DALL-E 2, Imagen, Parti... - ### 3D Reconstruction * [2016] **COLMAP** [[Doc]](https://colmap.github.io/) [[Code]](https://github.com/colmap/colmap) diff --git a/docs/speakings/conversation.md b/docs/speakings/conversation.md index 462e6e781..0ad3fcede 100644 --- a/docs/speakings/conversation.md +++ b/docs/speakings/conversation.md @@ -52,7 +52,6 @@ * Are you used to the life here? - ### Daily topics * family @@ -74,9 +73,6 @@ * [response] I like pop / rock / classical / jazz music. - - - ### End a topic * goodbye diff --git a/docs/speakings/daily.md b/docs/speakings/daily.md index dab687b91..2821bff23 100644 --- a/docs/speakings/daily.md +++ b/docs/speakings/daily.md @@ -34,8 +34,5 @@ * - - - > P50 diff --git a/docs/speakings/meetings.md b/docs/speakings/meetings.md index 82c300b1d..d72731bd2 100644 --- a/docs/speakings/meetings.md +++ b/docs/speakings/meetings.md @@ -13,7 +13,6 @@ I'm looking forward to our discussion today. I'm thrilled to be here. - ### Asking questions I have a question. @@ -27,7 +26,6 @@ Can you elaborate on... ? I didn't get the main idea. Excuse me, I didn't hear you. Could you please say that again? - ### Refusing I'm afraid I can't... @@ -37,7 +35,6 @@ I'm sorry, but I don't think I can... Unfortunately, I won't be able to - ### environment / unexpected problems I'm so sorry, you'll have to forgive the noise in the background. @@ -49,7 +46,6 @@ you are breaking up (cutting out) 卡了 Sorry my audio is not working. I will be right back. - ### end We got a lot done today. Thanks for your time and patience. diff --git a/docs/speakings/travel.md b/docs/speakings/travel.md index 0e53ae171..dba0f64b2 100644 --- a/docs/speakings/travel.md +++ b/docs/speakings/travel.md @@ -41,7 +41,6 @@ * I'm here to see friends. - ### Hotel * No appointment diff --git a/docs/vision/camera_combined.md b/docs/vision/camera_combined.md index 6ab5dd308..24dda8b74 100644 --- a/docs/vision/camera_combined.md +++ b/docs/vision/camera_combined.md @@ -8,26 +8,33 @@ * The Intrinsic Matrix use pixel height / width / focal, e.g. `H ~ [0, 1024), W ~ [0, 1024), focal = 1236 `, and face at `+z`. + $$ +\displaylines{ K = \begin{bmatrix} f_x & s & x_0 & 0 \\ 0 & f_y & y_0 & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix} +} $$ * The Projection Matrix use NDC, e.g., `H ~ [-1, 1], W ~ [-1, 1], near = 0.1`, and face at `-z`: + $$ +\displaylines{ Persp = Ortho\cdot P = Ortho \cdot \begin{bmatrix} near & 0 & 0 & 0 \\ 0 & near & 0 & 0 \\ 0 & 0 & near+far & near * far \\ 0 & 0 & -1 & 0 \end{bmatrix} +} $$ + And here the $P$ can be seen as a modified $K$: * if we use the near plane as the focal plane, then $near = f_x = f_y$ @@ -41,7 +48,6 @@ However, in most cases, the focal plane is not the near plane: ![enter image description here](camera_combined.assets/6wEgR.png) - ### implementation ```python @@ -172,9 +178,6 @@ class Camera: ``` - - - ### references * http://ksimek.github.io/2013/06/03/calibrated_cameras_in_opengl/ diff --git a/docs/vision/camera_intrinsics_exintrics.md b/docs/vision/camera_intrinsics_exintrics.md index 53197e400..50e5f3022 100644 --- a/docs/vision/camera_intrinsics_exintrics.md +++ b/docs/vision/camera_intrinsics_exintrics.md @@ -1,19 +1,19 @@ ## Camera Pose - Very good reference: https://ksimek.github.io/2012/08/22/extrinsic/ Good demo of look-at camera: https://learnwebgl.brown37.net/07_cameras/camera_lookat/camera_lookat.html - ### Homogeneous Coordinates $$ +\displaylines{ \text{2D:} \quad [u, v, 1]^T \\ \text{3D:} \quad [x, y, z, 1]^T \\ +} $$ @@ -21,7 +21,9 @@ $$ We usually first transform the 3D points to the camera coordinate system by the camera pose, then project the 3D points to 2D image plane by the camera matrix: + $$ +\displaylines{ z_c\begin{bmatrix} u \\ v \\ 1 \\ \end{bmatrix} @@ -36,8 +38,10 @@ x_c \\ y_c \\ z_c \\ 1 \\ \begin{bmatrix} x_w \\ y_w \\ z_w \\ 1 \\ \end{bmatrix} +} $$ + 3D Point in the world coordinate system: $[x_w, y_w,z_w]^T$ (relative to a defined origin position.) 3D Point in the camera coordinate system: $[x_c, y_c, z_c]^T$ (relative to the camera center position.) @@ -49,12 +53,13 @@ Camera Intrinsic (determined only by the camera itself): $\mathbf K \in \mathbb Camera Extrinsic (describes the transformation from **world to camera**, inversion of camera pose): $\begin{bmatrix}\mathbf R& \mathbf T \\ 0& 1 \end{bmatrix} \in \mathbb R ^ {4 \times 4}$. - ### Intrinsic A $3 \times 4$ matrix used to **project** 3D points to 2D coordinates: + $$ +\displaylines{ z_c\begin{bmatrix} u \\ v \\ 1 \\ \end{bmatrix} @@ -73,8 +78,10 @@ f_x & \gamma & u_0 & 0 \\ \begin{bmatrix} x_c \\ y_c \\ z_c \\ 1 \\ \end{bmatrix} +} $$ + $f_x, f_y$ are the **focal length in pixels**, usually $f_x =f_y$. $\gamma$ is the skew coefficient, usually 0. @@ -85,22 +92,25 @@ Inversely, we can use the intrinsic to project pixel coordinates to 3D points in Since a pixel can be projected to multiple depth planes, so we need to know the depth value $z_c$ in advance. + $$ +\displaylines{ \begin{cases} x_c = \frac {(u - u_0)} {f_x} z_c \\ y_c = \frac {(v - v_0)} {f_y} z_c \\ z_c \end{cases} +} $$ - - ### Extrinsic (w2c) A $4 \times 4$ matrix, a regular **3D transformation from world coordinate system to camera coordinate system**. + $$ +\displaylines{ \begin{bmatrix}\mathbf R_{3\times3}& \mathbf T_{3\times1} \\ 0_{1\times3}& 1 \end{bmatrix} = \begin{bmatrix}\mathbf I& \mathbf T \\ 0& 1 \end{bmatrix} @@ -108,8 +118,10 @@ $$ = \begin{bmatrix}\mathbf R& 0 \\ 0& 1 \end{bmatrix} \begin{bmatrix}\mathbf I& -\mathbf C \\ 0& 1 \end{bmatrix} +} $$ + It can be decomposed as: * first rotate with $\mathbf R$, then translate with $\mathbf T$, or @@ -123,7 +135,9 @@ $\mathbf T$ is the position of **the world origin in the camera coordinate syste instead, the position of the camera center in the world coordinate system, $\mathbf C=[x_0, y_0, z_0]$ should be calculated as: + $$ +\displaylines{ \begin{bmatrix} 0 \\ 0 \\ 0 \\ 1 \end{bmatrix} @@ -133,27 +147,31 @@ $$ \begin{bmatrix} x_0 \\ y_0 \\ z_0 \\ 1 \end{bmatrix} +} $$ + thus, $\mathbf C = -\mathbf R^{-1}\mathbf T$ this also gives a way to calculate $\mathbf{T} = -\mathbf{RC}$. - ### Pose (c2w) Also a $4 \times 4$ matrix, but it describes the **3D transformation from camera to world**. Obviously, **camera pose (c2w) is the inversion of extrinsic (w2c)**. + $$ +\displaylines{ \begin{bmatrix}\mathbf R_{3\times3}^T& \mathbf C_{3\times1} \\ 0_{1\times3}& 1 \end{bmatrix} = \begin{bmatrix}\mathbf R_{3\times3}& \mathbf T_{3\times1} \\ 0_{1\times3}& 1 \end{bmatrix}^{-1} +} $$ -Note that now the translation vector $\mathbf{C}$ is the camera's position in the world coordinate system now. +Note that now the translation vector $\mathbf{C}$ is the camera's position in the world coordinate system now. ### Construct by `LookAt` @@ -166,7 +184,9 @@ Assuming you know the camera position $\mathbf{C}$, and target position $\mathbf To construct the **camera pose matrix**, you can calculate the normalized **right, up, and forward vector**, then simply concatenate them: + $$ +\displaylines{ \begin{bmatrix} x_w \\ y_w \\ z_w \\ 1 \end{bmatrix} @@ -181,11 +201,15 @@ x_w \\ y_w \\ z_w \\ 1 \begin{bmatrix} x_c \\ y_c \\ z_c \\ 1 \end{bmatrix} +} $$ + Or the **camera extrinsic/view matrix** similarly: + $$ +\displaylines{ \begin{bmatrix} x_c \\ y_c \\ z_c \\ 1 \end{bmatrix} @@ -207,10 +231,10 @@ x_c \\ y_c \\ z_c \\ 1 \begin{bmatrix} x_w \\ y_w \\ z_w \\ 1 \end{bmatrix} +} $$ - There are different world/camera coordinate conventions, which are really confusing: ``` diff --git a/docs/vision/camera_view_projection.md b/docs/vision/camera_view_projection.md index 03994ef1d..994749f01 100644 --- a/docs/vision/camera_view_projection.md +++ b/docs/vision/camera_view_projection.md @@ -1,7 +1,6 @@ ## View & Projection - ### Right-handed system It is a convention. @@ -14,13 +13,11 @@ It is a convention. >- Now bend your middle finger downwards 90 degrees. - ### Global Picture of transformations ![img](transformations.assets/coordinate_systems.png) - ### Model Transformation It transform the object from its local coordinate system to the world coordinate system. @@ -33,26 +30,31 @@ It transform both the camera and objects, until **the camera is at the origin, u We should first apply this view transformation before we further apply projection transformation. + $$ +\displaylines{ V_{camera} = \mathbf M_{view} \cdot V_{world} \\ +} $$ - ### Projection Transformation It projects 3D objects into a Clip space, such that we can transform it to the final 2D plane. + $$ +\displaylines{ V_{clip} = \mathbf M_{projection} \cdot V_{camera} \\ +} $$ + First, we project the objects (from camera coordinate system) into a canonical cuboid $[-1,1]^3$ (the normalized device coordinate system, NDC). Coordinates outside $[-1, 1]$ will be clipped, so the space is called Clip space. Second, we perform viewport transform, i.e., simply look at -Z direction and get the 2D projection plane. - #### Orthographic projection ![](transformations.assets/gl_projectionmatrix02.png) @@ -62,7 +64,9 @@ Second, we perform viewport transform, i.e., simply look at -Z direction and get In implementation, we simply **linear** translate & scale the object's bounding box **from $[l,r]\times[b,t]\times[-n,-f]$ into $[-1, 1]^3$**: + $$ +\displaylines{ \mathbf M_{ortho} = \begin{bmatrix} \frac 2 {r-l} & 0 & 0 & -\frac{r+l}{r-l} \\ @@ -70,10 +74,11 @@ $$ 0 & 0 & \frac {-2} {f-n} & -\frac{f+n}{f-n} \\ 0 & 0 & 0 & 1 \end{bmatrix} +} $$ -(Note: since we look at -Z, we use $-n$ and $-f$ for near and far plane, so that $0 Troubleshooting: `Eigen::all, Eigen::seq` is not a member of Eigen. > > These operations belong to `dev` branch of Eigen, as you can see from the documentation: @@ -24,7 +22,6 @@ or simply symbol link it to `\usr\local\include`. > To use the `dev` branch, download the source at https://eigen.tuxfamily.org/dox/ - ### Examples simple matrix @@ -67,7 +64,6 @@ int main() ``` - ### Matrix all matrices and vectors are instances of the `Matrix` class: @@ -100,7 +96,6 @@ Built-in typedefs for `N in [2,3,4,X]` and `t in [i, f, d, cf, cd]`: * `RowVectorNt` == `Matrix` - #### dynamic matrix Eigen also supports **dynamic** matrix size: `typedef Matrix MatrixXd;` @@ -118,7 +113,6 @@ using Triangles = Matrix; ``` - #### Access coefficients Coefficient accessors: `m(i, j)` @@ -133,7 +127,6 @@ m << 1, 2, 3, ``` - #### Size Size and resize: `rows(), cols(), size()` @@ -157,7 +150,6 @@ a = b; // a is now 3x3 ``` - ### Arithmetic #### Add/Sub: @@ -286,7 +278,6 @@ int main() { ``` - #### Basic reductions ```c++ @@ -329,7 +320,6 @@ a.cwiseProduct(b); ``` - ### Array `Array` provides general-purposed arrays, while `Matrix` provides linear-algebra purposed arrays. @@ -416,9 +406,6 @@ int main() ``` - - - ### Block Operations use `.block(i,j,p,q)` for dynamic-size block or `.block(i,j)` for a fixed-size block, starting at `(i,j)` with size `(p,q)`. @@ -479,7 +466,6 @@ v.segment(i, n) == v.segment(i) ``` - ### Advanced Initializations #### joined comma @@ -497,7 +483,6 @@ std::cout << "joined = " << joined << std::endl; ``` - ### Special matrices ```c++ @@ -548,7 +533,6 @@ mat = (MatrixXf(2,2) << 0, 1, 1, 0).finished() * mat; // .finished() is a must! ``` - ### Reductions #### norm @@ -687,7 +671,6 @@ int main() ``` - ### Map: from raw data to eigen ```cpp @@ -696,7 +679,6 @@ Map pos(data, 3); // (pointer, size) ``` - ### Ref: generic type without template ```cpp diff --git a/docs/vision/image_interpolation.md b/docs/vision/image_interpolation.md index f3cef69f3..08e1ca039 100644 --- a/docs/vision/image_interpolation.md +++ b/docs/vision/image_interpolation.md @@ -5,17 +5,14 @@ ![image-20210310122314387](interpolation.assets/image-20210310122314387.png) - ### Align Corners https://zhuanlan.zhihu.com/p/87572724 - ### Up-sampling - ### Down-sampling ```bash @@ -72,7 +69,6 @@ https://zhuanlan.zhihu.com/p/87572724 ``` - ### PIL resize problem `PIL.resize` behaves differently compared to `cv2.resize`. diff --git a/docs/vision/image_processing.md b/docs/vision/image_processing.md index 8dee8e0bb..44f555562 100644 --- a/docs/vision/image_processing.md +++ b/docs/vision/image_processing.md @@ -71,7 +71,6 @@ def HSV2BGR(_img, hsv): ``` - ### Histogram ```python @@ -79,13 +78,16 @@ plt.hist(img.ravel(), bins=255, rwidth=0.8, range=(0, 255)) ``` - ### Gamma Correction + $$ +\displaylines{ I_{out} ={\frac{1}{c}\ I_{in}} ^ {\frac{1}{g}} +} $$ + 校正照相机等电子设备传感器的非线性光电转换特征,主要是增大RGB值。 ```python @@ -101,7 +103,6 @@ def gamma_correction(img, c=1, g=2.2): ``` - ### Interpolation * Nearest Neighbor @@ -238,10 +239,11 @@ def gamma_correction(img, c=1, g=2.2): ``` - ### Affine Transform + $$ +\displaylines{ \left( \begin{matrix} x'\\ @@ -289,8 +291,10 @@ t_x\\ t_y \end{matrix} \right) +} $$ + ```python def affine(img, a, b, c, d, tx, ty): H, W, C = img.shape @@ -327,7 +331,9 @@ def affine(img, a, b, c, d, tx, ty): * Shift + $$ +\displaylines{ \left( \begin{matrix} @@ -351,12 +357,15 @@ $$ \end{matrix} \right) +} $$ * Resize + $$ +\displaylines{ \left( \begin{matrix} @@ -380,12 +389,16 @@ $$ \end{matrix} \right) +} $$ + * Rotate + $$ +\displaylines{ \left( \begin{matrix} @@ -409,12 +422,16 @@ $$ \end{matrix} \right) +} $$ + * Sharing + $$ +\displaylines{ a=\frac{t_x}{h}\\ \left[ @@ -460,20 +477,21 @@ $$ \end{matrix} \right] +} $$ - - ### Fourier Transform + $$ +\displaylines{ G(k,l)=\frac{1}{H\ W}\ \sum\limits_{y=0}^{H-1}\ \sum\limits_{x=0}^{W-1}\ I(x,y)\ e^{-2\ \pi\ j\ (\frac{k\ x}{W}+\frac{l\ y}{H})} \\ I(x,y)=\frac{1}{H\ W}\ \sum\limits_{l=0}^{H-1}\ \sum\limits_{k=0}^{W-1}\ G(l,k)\ e^{2\ \pi\ j\ (\frac{k\ x}{W}+\frac{l\ y}{H})} +} $$ - ```python # DFT hyper-parameters K, L = 128, 128 @@ -652,7 +670,6 @@ def idft(G): 5. IDCT之后从YCbCr色彩空间变换到RGB色彩空间。 - ```python T = 8 K = 8 @@ -768,9 +785,6 @@ def JPEG(img): ``` - - - ### Canny Edge Detector ```python @@ -972,7 +986,6 @@ def Canny(img): ``` - ### Hough Transform (Line detection) ```python @@ -1076,7 +1089,6 @@ def Hough_Line(edge, img): ``` - ### Dilate ```python @@ -1128,7 +1140,6 @@ def Morphology_Erode(img, Dil_time=1): ``` - ### Opening Operation Dilate N times, Erode N times. ==> Remove isolated pixels. diff --git a/docs/vision/opencv.md b/docs/vision/opencv.md index 448fa49ae..3aa39debf 100644 --- a/docs/vision/opencv.md +++ b/docs/vision/opencv.md @@ -10,7 +10,6 @@ pkg-config --libs opencv ``` - ### install opencv2 Although opencv2 has been outdated, lots of packages still use it... diff --git a/docs/vision/transformation.md b/docs/vision/transformation.md index c56813298..13b73d4f1 100644 --- a/docs/vision/transformation.md +++ b/docs/vision/transformation.md @@ -3,7 +3,9 @@ #### 2D The transformation matrix is **Rotate THEN Translate (and scale)** + $$ +\displaylines{ \begin{bmatrix} \cos\theta & -\sin\theta & t_x \\ \sin\theta & \cos\theta & t_y \\ @@ -20,21 +22,28 @@ $$ \sin\theta & \cos\theta & 0 \\ 0&0&1 \\ \end{bmatrix} +} $$ + Note: We always use $\mathbf T \mathbf R$ because in this form the translation is applied later and is explicit. + $$ +\displaylines{ \mathbf T \mathbf R = \begin{bmatrix}1 & \mathbf t \\ 0 & 1\end{bmatrix} \begin{bmatrix}\mathbf r & 0 \\ 0 & 1\end{bmatrix} = \begin{bmatrix}\mathbf r & \mathbf t \\ 0 & 1\end{bmatrix} \ne \begin{bmatrix}\mathbf r & \mathbf {rt} \\ 0 & 1\end{bmatrix} = \begin{bmatrix}\mathbf r & 0 \\ 0 & 1\end{bmatrix}\begin{bmatrix}1 & \mathbf t \\ 0 & 1\end{bmatrix} = \mathbf R \mathbf T +} $$ #### 3D Main difference from 2D is the three rotation matrices **along three axes**: + $$ +\displaylines{ \mathbf R_x(\alpha) = \begin{bmatrix} 1&0&0&0\\ @@ -59,23 +68,31 @@ $$ 0&0&1&0 \\ 0&0&0&1\\ \end{bmatrix} \\ +} $$ + With the final form: + $$ +\displaylines{ \mathbf R_{xyz}(\alpha) = \mathbf R_x(\alpha)\mathbf R_y(\alpha)\mathbf R_z(\alpha) +} $$ + Rodrigues' Rotation Formula for rotation along any axis $\mathbf n$: + $$ +\displaylines{ \mathbf R(\mathbf n, \alpha) = \cos\alpha\mathbf I + (1 - \cos\alpha)\mathbf n\mathbf n^T + \sin\alpha \begin{bmatrix} 0 & -n_x &n_y \\ n_z & 0 & -n_x \\ -n_y & n_x & 0 \end{bmatrix} +} $$ - ### Decompose 3D transformation > ref: https://math.stackexchange.com/questions/237369/given-this-transformation-matrix-how-do-i-decompose-it-into-translation-rotati/417813 diff --git a/docs/web/backend/golang_basics.md b/docs/web/backend/golang_basics.md index e021b686d..9eadb2441 100644 --- a/docs/web/backend/golang_basics.md +++ b/docs/web/backend/golang_basics.md @@ -9,7 +9,6 @@ go run test.go # build and run ``` - ### Go Proxy Correct way to download modules. @@ -23,7 +22,6 @@ go get ``` - ### Go Modules ```bash @@ -49,7 +47,6 @@ require github.com/gin-gonic/gin v1.6.3 ``` - ### Defer ```go @@ -72,9 +69,6 @@ defer func() { fmt.Println("3") }() ``` - - - ### The empty Interface `interface{}` can hold values of any type. @@ -100,7 +94,6 @@ func main() { ``` - ### Overview ```go @@ -120,7 +113,6 @@ go run test.go ``` - ### Types * Pass-by-Value @@ -170,7 +162,6 @@ const ( * Global variable may not be used. - ### Control * `select` @@ -196,7 +187,6 @@ const ( - ### Function ```go @@ -204,7 +194,6 @@ func name([param [type1], param2 [type2]]) [return type] {} ``` - ### Array ```go @@ -217,7 +206,6 @@ func foo(arr [] int, size int) int {} ``` - ### Pointer ```go @@ -235,9 +223,6 @@ func swap (x* int, y* int) { ``` - - - ### OOP * `struct` @@ -288,9 +273,6 @@ func swap (x* int, y* int) { ``` - - - ### Slice (dynamic array) ```go @@ -303,7 +285,6 @@ slc = append(slc, d, e) ``` - ### Map ```go @@ -323,7 +304,6 @@ delete(m, key) ``` - ### Go Routine In-born multi-threading support. @@ -375,4 +355,3 @@ In-born multi-threading support. * `select` - diff --git a/docs/web/backend/golang_gin.md b/docs/web/backend/golang_gin.md index 6efaecb8b..0943e7900 100644 --- a/docs/web/backend/golang_gin.md +++ b/docs/web/backend/golang_gin.md @@ -142,7 +142,6 @@ func main() { - ### CORS ```go diff --git a/docs/web/backend/python_fastapi.md b/docs/web/backend/python_fastapi.md index df34d27ca..ad9f4092f 100644 --- a/docs/web/backend/python_fastapi.md +++ b/docs/web/backend/python_fastapi.md @@ -8,7 +8,6 @@ pip install fastapi[all] ``` - ### basic usage ```python @@ -106,7 +105,6 @@ def getitem(id: int): ``` - ### debug the `main.py`: @@ -132,9 +130,6 @@ python main.py ``` - - - ### deploy assume the APIs are in `main.py`, and the backend is called `app`: diff --git a/docs/web/backend/python_flask.md b/docs/web/backend/python_flask.md index 9a117cb97..8ebd8dd0b 100644 --- a/docs/web/backend/python_flask.md +++ b/docs/web/backend/python_flask.md @@ -15,7 +15,6 @@ flask run # python -m flask run ``` - ### Views A function to respond to requests. @@ -86,7 +85,6 @@ def login_required(view): ``` - ### Context **How flask handle request: ** @@ -104,7 +102,6 @@ APP context is cheap, and can be created without a request, for accessing `curre Request context is expensive. - ### URL arguments * simple arguments @@ -202,7 +199,6 @@ session.clear() ``` - ### flask.g Store data **in the same request**. @@ -234,9 +230,6 @@ def teardown_db(): ``` - - - ### Jinja A template library. @@ -247,6 +240,3 @@ A template library. - `# ... ##` for [Line Statements](https://jinja.palletsprojects.com/en/2.11.x/templates/#line-statements) - - - diff --git a/docs/web/backend/sql_mysql.md b/docs/web/backend/sql_mysql.md index 7e2cb77fe..a548f1ecf 100644 --- a/docs/web/backend/sql_mysql.md +++ b/docs/web/backend/sql_mysql.md @@ -13,7 +13,6 @@ vim /etc/mysql/mysql.conf.d/mysqld.cnf ``` - ### CLI ```bash @@ -43,7 +42,6 @@ show full columns from ; ``` - ### backup & recovery ```bash @@ -59,7 +57,6 @@ mysql $ source backup.sql; ``` - ### Char set > ref: https://mathiasbynens.be/notes/mysql-utf8mb4#character-sets @@ -141,9 +138,6 @@ To set the default charset to `utf8mb4`: - - - ### Set password ```mysql @@ -156,7 +150,6 @@ exit; the default password is ''. - ### Data types * TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT @@ -181,7 +174,6 @@ the default password is ''. * DATE, TIME, DATETIME, TIMESTAMP - ### Create database You must create database first, then select database, then create table. @@ -195,7 +187,6 @@ USE database_name; ``` - ### Create table ```mysql @@ -211,13 +202,11 @@ column_name data_type(length) [NOT NULL] [DEFAULT value] [AUTO_INCREMENT] column ``` - ### Operations Nearly the same as SQLite. - ### Full text search * Create index by `FULLTEXT (columns) WITH PARSER ngram` @@ -253,7 +242,6 @@ Nearly the same as SQLite. ``` - ### Python API ```python @@ -290,6 +278,3 @@ res = cursor.fetchall() # list of list ``` - - - diff --git a/docs/web/backend/sql_sqlite.md b/docs/web/backend/sql_sqlite.md index 32f1c4ef0..8b79ea23b 100644 --- a/docs/web/backend/sql_sqlite.md +++ b/docs/web/backend/sql_sqlite.md @@ -9,8 +9,6 @@ contains a series of `sql` script. - - ### Data Types * NULL @@ -20,7 +18,6 @@ * BLOB: binary large object, can store any time of data. unlimited size. - ### Create Table ```sqlite @@ -155,7 +152,6 @@ CREATE TABLE [IF NOT EXISTS] [schema_name].table_name ( - * UPDATE used to change value of inserted row. @@ -173,7 +169,6 @@ CREATE TABLE [IF NOT EXISTS] [schema_name].table_name ( - ### PRAGMA Set default behavior. @@ -183,7 +178,6 @@ PRAGMA case_sensitive_like = true; ``` - ### Full text search We must use FTS5 virtual table to achieve full text search in SQLite. @@ -220,7 +214,6 @@ ORDER BY rank; ``` - ### Python API ```python diff --git a/docs/web/deploy/gh-pages.md b/docs/web/deploy/gh-pages.md index a62689953..7e78002f8 100644 --- a/docs/web/deploy/gh-pages.md +++ b/docs/web/deploy/gh-pages.md @@ -1,7 +1,6 @@ # gh-pages - ##### `package.json` ```json diff --git a/docs/web/deploy/manifest.md b/docs/web/deploy/manifest.md index bbbf15054..b796db9cd 100644 --- a/docs/web/deploy/manifest.md +++ b/docs/web/deploy/manifest.md @@ -18,7 +18,6 @@ Assume file directory as: ``` - ``` ``` diff --git a/docs/web/deploy/nginx.md b/docs/web/deploy/nginx.md index 5f174aa27..ef0ea8a4d 100644 --- a/docs/web/deploy/nginx.md +++ b/docs/web/deploy/nginx.md @@ -6,9 +6,6 @@ * Reverse Proxy (Server): An intermediary for responses from servers. - - - ### Systemd `Systemd` is a series of commands, it replaces `initd` and has `pid=1`. @@ -40,9 +37,6 @@ systemctl cat apache.service # cat config file ``` - - - ### CLI ```bash @@ -57,7 +51,6 @@ nginx -t # test, check config files. ``` - ### Logs default: @@ -68,7 +61,6 @@ default: ``` - ### Configs Location: `/etc/nginx/nginx.conf` diff --git a/docs/web/deploy/pm2.md b/docs/web/deploy/pm2.md index 1605d84d0..e3a6d244f 100644 --- a/docs/web/deploy/pm2.md +++ b/docs/web/deploy/pm2.md @@ -9,7 +9,6 @@ npm install -g pm2 ``` - ### usage ```bash diff --git a/docs/web/deploy/ssl_acmesh.md b/docs/web/deploy/ssl_acmesh.md index 97d4c3cc8..d6ca3e677 100644 --- a/docs/web/deploy/ssl_acmesh.md +++ b/docs/web/deploy/ssl_acmesh.md @@ -1,7 +1,6 @@ # SSL - ### SSL: secure sockets layer Protocols for establishing authenticated and encrypted links between networked computers. @@ -9,13 +8,11 @@ Protocols for establishing authenticated and encrypted links between networked c The protocol is deprecated in 1999 with TLS release, but still used to refer to this technique. - ### TLS: transport layer security Successor of SSL. - ### HTTPS Tunnel HTTP over TSL/SSL which encrypts the HTTP payload. @@ -25,7 +22,6 @@ Tunnel HTTP over TSL/SSL which encrypts the HTTP payload. Or use free license by `acme.sh` ! - ### acme.sh https://github.com/acmesh-official/acme.sh/wiki/%E8%AF%B4%E6%98%8E diff --git a/docs/web/deploy/uwsgi.md b/docs/web/deploy/uwsgi.md index 756f2f06c..ff3cf3dd3 100644 --- a/docs/web/deploy/uwsgi.md +++ b/docs/web/deploy/uwsgi.md @@ -17,7 +17,6 @@ ln -s /root/anaconda3/lib/libpcre.so.1 /lib ``` - ### Config uwsgi.ini @@ -43,7 +42,6 @@ pidfile = uwsgi.pid ``` - ### Setup Nginx ``` @@ -68,9 +66,6 @@ server { ``` - - - ### CLI ```bash diff --git a/docs/web/dns.md b/docs/web/dns.md index 0d5a89897..9c208fbda 100644 --- a/docs/web/dns.md +++ b/docs/web/dns.md @@ -11,7 +11,6 @@ * `www`:著名的www子域名 - ### 域名解析服务 DNS服务商提供域名解析服务。 @@ -19,7 +18,6 @@ DNS服务商提供域名解析服务。 每条记录包括**记录类型,主机记录**,解析线路ISP,**记录值**,TTL,MX优先级。 - * **A记录**:IP指向(Alias),即把域名指向IP地址。 把整个二级域名指向服务器IP diff --git a/docs/web/frontend/chrome_debugger.md b/docs/web/frontend/chrome_debugger.md index cbfafa87a..b7ac1e169 100644 --- a/docs/web/frontend/chrome_debugger.md +++ b/docs/web/frontend/chrome_debugger.md @@ -15,7 +15,6 @@ It is just so helpful QwQ. ![image-20210912155345390](chrome_debugger.assets/image-20210912155345390.png) - ### Pitfalls * JS caching: chrome will cache the `javascript` code by default, use `Ctrl + F5` FULL refresh to make sure the code is up to date. diff --git a/docs/web/frontend/html/css.md b/docs/web/frontend/html/css.md index 86f8f13c8..534a028e4 100644 --- a/docs/web/frontend/html/css.md +++ b/docs/web/frontend/html/css.md @@ -82,7 +82,6 @@ a[attr*=value] {} /* a with value in attr */ ``` - ### Cascading and Inheriting * Cascading diff --git a/docs/web/frontend/html/html.md b/docs/web/frontend/html/html.md index 40c6b9607..13b1d7325 100644 --- a/docs/web/frontend/html/html.md +++ b/docs/web/frontend/html/html.md @@ -3,7 +3,6 @@ > We prefer not to write HTML directly. Instead, use code to generate HTML automatically. - ### Elements * ` Website ` @@ -34,11 +33,6 @@ * `
` declare header, no factual effect. - - - - - ### Example * Simple Document @@ -61,7 +55,6 @@ - ### Script basics: @@ -82,4 +75,3 @@ basics: ``` - diff --git a/docs/web/frontend/html/html_js_interaction.md b/docs/web/frontend/html/html_js_interaction.md index d64deb208..3eb928eb7 100644 --- a/docs/web/frontend/html/html_js_interaction.md +++ b/docs/web/frontend/html/html_js_interaction.md @@ -18,7 +18,6 @@ ``` - ```js function custom_func () { // use global object `document` to access the DOM diff --git a/docs/web/frontend/html/http.md b/docs/web/frontend/html/http.md index 5a7d3ceee..f09f13e20 100644 --- a/docs/web/frontend/html/http.md +++ b/docs/web/frontend/html/http.md @@ -64,7 +64,6 @@ A technique that stores a copy of a given resource, and serves it back when requ It eases the load of server, and improves performance. - ### Cookies A small piece of data that a server sends to the user's web browser. @@ -107,7 +106,6 @@ Usually used to tell if two requests came from the same browser. (keeping logged - ### CORS: Cross-Origin Resource Sharing A Mechanism that uses additional HTTP Headers, to tell browsers to give a web App access to resources from a different origin. diff --git a/docs/web/frontend/html/web_api.md b/docs/web/frontend/html/web_api.md index e1a31fce9..8424cb3ee 100644 --- a/docs/web/frontend/html/web_api.md +++ b/docs/web/frontend/html/web_api.md @@ -65,7 +65,6 @@ else { ``` - ### URL Parameters `https://example.com/?product=shirt&color=blue&newuser&size=m` @@ -82,7 +81,6 @@ size=m This allows to pass simple data to the server in `GET` and `POST`. - ### Fetch ```javascript @@ -125,4 +123,3 @@ fetch(url+"?"+query).then(...) ``` - diff --git a/docs/web/frontend/i18n.md b/docs/web/frontend/i18n.md index 6a809ea25..de971609e 100644 --- a/docs/web/frontend/i18n.md +++ b/docs/web/frontend/i18n.md @@ -3,7 +3,6 @@ stands for **Internationalization**, `i-18 letters-n`. - ### [i18next](https://react.i18next.com/latest/using-with-hooks) Install: @@ -134,7 +133,6 @@ t('common:a.b'); ``` - translation files: `public/locales//translation.json` diff --git a/docs/web/frontend/javascript_advanced.md b/docs/web/frontend/javascript_advanced.md index 5918d51c8..0c1d03845 100644 --- a/docs/web/frontend/javascript_advanced.md +++ b/docs/web/frontend/javascript_advanced.md @@ -11,7 +11,6 @@ function foo(){ ``` - ### [`globalThis`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis) A standard way to access the global environment in different js environments. @@ -31,7 +30,6 @@ var globals = getGlobal(); ``` - ### Prototype Chain * All the reference types are Objects. @@ -41,7 +39,6 @@ var globals = getGlobal(); * If an attribute cannot be found in an object, then find it in the object's `_proto_`. - ### Hoisting (声明提前) Function and Variable declarations will be hoisted at runtime (in their domains, i.e., global or local function). @@ -76,7 +73,6 @@ undefined ``` - ### Class (ES6) ##### basics @@ -338,9 +334,6 @@ l.speak(); ``` - - - ### Tips * `var` is deprecated. Use `const` and `let`. diff --git a/docs/web/frontend/javascript_async.md b/docs/web/frontend/javascript_async.md index cf8e55d26..d6ce94681 100644 --- a/docs/web/frontend/javascript_async.md +++ b/docs/web/frontend/javascript_async.md @@ -1,7 +1,6 @@ # asynchronous programming - ### Promise A `Promise` is an object representing the eventual completion or failure of an asynchronous operation. @@ -13,7 +12,6 @@ It is always in one of these states: `pending, fufilled, rejected.` Use `then()` to add callbacks to `fufilled` promises, and `catch()` for `rejected` promises. - Some guarantees: * Callbacks added with `then()/catch()` will never be invoked before the [completion of the current run](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#run-to-completion) of the JavaScript event loop @@ -21,7 +19,6 @@ Some guarantees: * (Chaining) Multiple callbacks may be added by calling `then()` several times. They will be invoked one after another, in the order in which they were inserted. - Chaining: ```js @@ -35,7 +32,6 @@ doAnotherthing(); // this will not wait until doSomething() finish ! ``` - Catching errors: ```js @@ -56,7 +52,6 @@ new Promise((resolve, reject) => { ``` - ### Create promises manually ```js @@ -89,7 +84,6 @@ console.log(1); // not in task queue ``` - ### async / await `async` can be put in front of a function to make it async, i.e., return a Promise. diff --git a/docs/web/frontend/javascript_basics.md b/docs/web/frontend/javascript_basics.md index b960b64fe..49c1b2b37 100644 --- a/docs/web/frontend/javascript_basics.md +++ b/docs/web/frontend/javascript_basics.md @@ -9,7 +9,6 @@ var a = 1; // use ; ``` - ### Types * `Number` @@ -105,7 +104,6 @@ var a = 1; // use ; * `undefined`: uninitialized variable - ### Variables Pass by value. @@ -145,7 +143,6 @@ Pass by value. Maybe Global or Local, depending on where we declare it. - ### Operators ```javascript @@ -162,7 +159,6 @@ Pass by value. ``` - ### Controls ```javascript @@ -182,7 +178,6 @@ switch (action) { ``` - ### Objects Objects in JavaScript are like Dictionaries in Python. @@ -211,7 +206,6 @@ Pass by Reference. ``` - ### Arrays A special type of Object. (Not a list, still a dictionary!) @@ -240,7 +234,6 @@ a.splice(a.indexOf('x'), 1) // delete 'x' ``` - ### Functions * If no `return`, return `undefined`. @@ -315,8 +308,6 @@ a.splice(a.indexOf('x'), 1) // delete 'x' ``` - - ### Exports & Imports Export by: @@ -357,9 +348,6 @@ import(".App.js").then( ``` - - - ### Closures ```javascript diff --git a/docs/web/frontend/lodash.md b/docs/web/frontend/lodash.md index af9bc1b5a..b77a8aad7 100644 --- a/docs/web/frontend/lodash.md +++ b/docs/web/frontend/lodash.md @@ -11,7 +11,6 @@ npm install -S lodash ``` - ### usage ```js diff --git a/docs/web/frontend/nodejs_basics.md b/docs/web/frontend/nodejs_basics.md index c5299b7e7..54f895868 100644 --- a/docs/web/frontend/nodejs_basics.md +++ b/docs/web/frontend/nodejs_basics.md @@ -19,7 +19,6 @@ sudo npm install -g npm need to restart shell to use new version! - ### `node` Node.js is a **JavaScript run-time environment.** @@ -105,7 +104,6 @@ It allows developers to write JavaScript outside of a browser. - ### `npm`: Node Package Manager ```bash @@ -172,7 +170,6 @@ this will create a `package.json`. ``` - React provides a better init setup by: `npx create-react-app ` @@ -180,9 +177,6 @@ React provides a better init setup by: It installs lots of default packages. - - - ### `npx`: Node Package Runner ```bash @@ -199,7 +193,6 @@ npx https://xxx # run code from web ``` - ### `package.json` ```json diff --git a/docs/web/frontend/pyodide.md b/docs/web/frontend/pyodide.md index 9d71c6565..77c1e4863 100644 --- a/docs/web/frontend/pyodide.md +++ b/docs/web/frontend/pyodide.md @@ -35,7 +35,6 @@ run python in javascript! ``` - ### example in nodejs Install: @@ -57,7 +56,6 @@ await pyodide.runPythonAsync("1+1"); ``` - ### JS API (`namedLikeThis`) * `globals`: `PyProxy`, alias to the global python environment. @@ -83,7 +81,6 @@ await pyodide.runPythonAsync("1+1"); * `toJs(options)`: convert to a native js object. - ### Python API (`named_like_this`) * `js`: alias to the global js environment (`window`). @@ -95,13 +92,11 @@ await pyodide.runPythonAsync("1+1"); Most time we just use `PyProxy.toJs()` in js. - ### Micropip API * `install(requirements)`: install given packages and dependencies. - ### access python from js ```js @@ -170,7 +165,6 @@ let sys = pyodide.globals.get("sys"); ``` - ### access js from python ```python @@ -220,7 +214,6 @@ reload_page() ``` - ### load python packages ```js diff --git a/docs/web/frontend/react-basics.md b/docs/web/frontend/react-basics.md index 1b79d633c..f71c5c5fe 100644 --- a/docs/web/frontend/react-basics.md +++ b/docs/web/frontend/react-basics.md @@ -7,7 +7,6 @@ npx create-react-app ``` - ### JSX Use in code. Place expressions inside {}. @@ -60,9 +59,6 @@ const element = React.createElement( - - - ### Render ```javascript @@ -85,7 +81,6 @@ setInterval(tick, 1000); ``` - ### Component & Prop[ertie]s ```javascript @@ -138,7 +133,6 @@ class Welcome extends React.Component { * **Props are Read-Only** - ### States & Lifecycle Methods We use class component to implement dynamic states. @@ -335,7 +329,6 @@ ReactDOM.render( ``` - ### Dynamic Rendering ```javascript @@ -397,9 +390,6 @@ function DynamicForm(){ ``` - - - ### Refs To access Child node in Parent node. @@ -463,7 +453,6 @@ To access Child node in Parent node. ``` - ### Context provide Global `props` (themes, login-status) used by many components. @@ -572,9 +561,6 @@ function Content() { ``` - - - ### Render Props pass in a `render` attributes to dynamically render component inside component. @@ -629,11 +615,6 @@ class MouseTracker extends React.Component { ``` - - - - - ### Hook It allows **functional components** to use `states`. (Avoid annoying `this` in class components!) @@ -873,9 +854,6 @@ class Columns extends React.Component { ``` - - - ### Other API * `React.PureComponent` @@ -903,4 +881,3 @@ class Columns extends React.Component { - diff --git a/docs/web/frontend/react-formik.md b/docs/web/frontend/react-formik.md index d0339990c..655e1cd03 100644 --- a/docs/web/frontend/react-formik.md +++ b/docs/web/frontend/react-formik.md @@ -45,7 +45,6 @@ function SelectForm() { ``` - ### Uncontrolled Form: File Input ```javascript @@ -83,9 +82,6 @@ ReactDOM.render( ``` - - - ### Formik & Yup ```javascript @@ -134,7 +130,6 @@ const SignupForm = () => { ``` - ### Dynamic Form ```javascript diff --git a/docs/web/frontend/three/basic.md b/docs/web/frontend/three/basic.md index 06ac84c5a..e48e810d2 100644 --- a/docs/web/frontend/three/basic.md +++ b/docs/web/frontend/three/basic.md @@ -110,7 +110,6 @@ function animate2(time) { ``` - ### app structure ![](https://threejsfundamentals.org/threejs/lessons/resources/images/threejs-structure.svg) diff --git a/docs/web/frontend/three/plyloader.md b/docs/web/frontend/three/plyloader.md index 60091b413..c1454ee85 100644 --- a/docs/web/frontend/three/plyloader.md +++ b/docs/web/frontend/three/plyloader.md @@ -19,7 +19,6 @@ ``` - `renderer.js` ```js @@ -208,7 +207,6 @@ function add_plane(h, w, z) { } - // bind to window window.load_input = load_input; window.change_k = change_k; diff --git a/docs/web/frontend/webpack.md b/docs/web/frontend/webpack.md index c81aa9357..4ca1c918f 100644 --- a/docs/web/frontend/webpack.md +++ b/docs/web/frontend/webpack.md @@ -3,7 +3,6 @@ Another solution except for `react`. - ### init project ```bash @@ -33,7 +32,6 @@ this creates `package.json` ``` - ### files organization we can install any package by `npm`: @@ -43,7 +41,6 @@ npm install -S lodash ``` - `webpack.config.js` ```js @@ -60,7 +57,6 @@ module.exports = { ``` - `dist/index.html` ```html @@ -78,7 +74,6 @@ module.exports = { ``` - `src/index.js` ```js @@ -97,7 +92,6 @@ document.body.appendChild(component()); ``` - ### build * directly use `npx` diff --git a/docs/web/ip.md b/docs/web/ip.md index 06089d588..fcecfafa6 100644 --- a/docs/web/ip.md +++ b/docs/web/ip.md @@ -28,17 +28,11 @@ Special IPs: ``` - - - ### IPv6 128bit - - - ### NAT (Network Address Translation) 用于缓解IPv4不足,指的是路由器自动修改IP报文实现LAN/WAN之间转换的过程。 diff --git a/docs/web/proxy/concepts.md b/docs/web/proxy/concepts.md index 8d6d5fe41..69a30e3d0 100644 --- a/docs/web/proxy/concepts.md +++ b/docs/web/proxy/concepts.md @@ -6,7 +6,6 @@ Protocol that exchanges packets through a proxy server. * socks5: - ### [ShadowSocks](https://github.com/shadowsocks/shadowsocks) A client software that connects to a third-party socks5 proxy server, similar to an SSH tunnel. @@ -18,7 +17,6 @@ First written in python. Most usual client in Windows. - ### [trojan](https://github.com/trojan-gfw) A lightweight **idea** that imitating HTTPS to bypass GFW. @@ -30,9 +28,6 @@ in C++. Easy to use, best client to use in Linux. - - - ### [v2ray (Project V) ](https://github.com/v2ray/v2ray-core) A network toolset to build own computer network. @@ -42,10 +37,8 @@ in Golang. Support nearly all platforms. - ### proxychains A Linux command line tool to use proxy in the followed command. - diff --git a/docs/web/proxy/frp_reverse_proxy.md b/docs/web/proxy/frp_reverse_proxy.md index 01e67866b..6b4b6569f 100644 --- a/docs/web/proxy/frp_reverse_proxy.md +++ b/docs/web/proxy/frp_reverse_proxy.md @@ -8,7 +8,6 @@ download from [releases](https://github.com/fatedier/frp/releases). * `frpc`: client - ### deploy * `frps`: diff --git a/docs/web/proxy/set_usual_apps_proxy.md b/docs/web/proxy/set_usual_apps_proxy.md index 941f3adf3..64f70a7a1 100644 --- a/docs/web/proxy/set_usual_apps_proxy.md +++ b/docs/web/proxy/set_usual_apps_proxy.md @@ -9,8 +9,6 @@ clash defaults to `http://127.0.0.1:7890` and `socks5://127.0.0.1:7890` trojan-qt5 local client's socks port is in "入站设置", not "出站设置". the default is `socks5://127.0.0.1:51837`. - - ### powershell ```powershell @@ -97,7 +95,6 @@ pip install pysocks ``` - ### docker * `docker build` @@ -121,7 +118,6 @@ pip install pysocks * `docker run` - ### Authorization ```bash diff --git a/docs/web/proxy/ss.md b/docs/web/proxy/ss.md index 324a80132..47962e9c6 100644 --- a/docs/web/proxy/ss.md +++ b/docs/web/proxy/ss.md @@ -3,7 +3,6 @@ Server is CentOS 7 (Digital Oceans).. - ### Shadowsocks edit `/etc/shadowsocks.json` @@ -33,7 +32,6 @@ edit `/etc/shadowsocks.json` ``` - edit `/etc/systemd/system/shadowsocks.service` ``` @@ -51,7 +49,6 @@ WantedBy=multi-user.target (note the `ssserver`'s location may be different) - run `systemctl` to enable shadowsocks daemon. ```bash @@ -66,7 +63,6 @@ systemctl status shadowsocks -l # list all ``` - Always remember to check the `logs` if something is wrong! ```bash @@ -75,7 +71,6 @@ Always remember to check the `logs` if something is wrong! ``` - ### Fail2ban fail2ban is used to secure the server from brute-force ssh attack. @@ -86,7 +81,6 @@ lastb -20 # check last 20 failed logins ``` - ```bash #! /bin/bash set -euxo pipefail @@ -107,13 +101,11 @@ systemctl status fail2ban -l ``` - > sshd > > sshd is the daemon of ssh. - remember to check the `log`. ```bash @@ -121,7 +113,6 @@ remember to check the `log`. ``` - check banned IPs & unban IP. ```bash @@ -130,7 +121,6 @@ fail2ban-client set sshd unbanip xxx.xxx.xxx.xxx # unban ``` - ### set up FirewallD ```bash @@ -142,7 +132,6 @@ firewall-cmd --reload ``` - ### change SSH default port first add a new port, and test on it (make sure you can log in on that port). @@ -156,7 +145,6 @@ Port 6666 ``` - ```bash systemctl restart sshd systemctl status sshd @@ -167,7 +155,6 @@ firewall-cmd --reload ``` - ### Else * add user diff --git a/docs/web/proxy/trojan-go.md b/docs/web/proxy/trojan-go.md index 98dfa211b..1472009f4 100644 --- a/docs/web/proxy/trojan-go.md +++ b/docs/web/proxy/trojan-go.md @@ -3,7 +3,6 @@ Support CDN like Cloudflare to hide your server's IP, or use it even if it's blocked. - ### download https://github.com/p4gefau1t/trojan-go/releases @@ -15,7 +14,6 @@ unzip trojan-go-linux-amd64.zip ``` - ### Cloudflare settings Go to `SSL/TLS`: @@ -27,14 +25,12 @@ Go to `SSL/TLS`: Copy and paste your `cert.pem & private.key`! Put them on your server, like under `/root/cert/`. - Go to `DNS`: * add a new A record that parse your domain name to your server IP. * make sure to use `Proxied`. - ### server A [config](https://p4gefau1t.github.io/trojan-go/basic/config/) example: @@ -124,7 +120,6 @@ server { ``` - To reuse 443 via NGINX streaming, first change trojan config: ```json @@ -248,7 +243,6 @@ systemctl status nginx ``` - ### Client #### trojan-go client @@ -327,7 +321,6 @@ systemctl statue trojan-go ``` - #### Clash client (recommended) get clash: @@ -387,4 +380,3 @@ systemctl start clash finally, set up system proxy to manual and enter your http/socks5 port. - diff --git a/docs/web/proxy/trojan.md b/docs/web/proxy/trojan.md index d1e73f044..5198804e2 100644 --- a/docs/web/proxy/trojan.md +++ b/docs/web/proxy/trojan.md @@ -229,7 +229,6 @@ server { ![image-20210305154420993](trojan_nginx_server.assets/image-20210305154420993.png) - ### Client * Get trojan diff --git a/docs/web/rss/rsshub.md b/docs/web/rss/rsshub.md index bbecbf030..e85c4d415 100644 --- a/docs/web/rss/rsshub.md +++ b/docs/web/rss/rsshub.md @@ -19,7 +19,6 @@ npm start ``` - ### configs create `.env` file to write configs. @@ -33,7 +32,6 @@ PORT=1888 ``` - ### [Nginx forward](https://gist.github.com/soheilhy/8b94347ff8336d971ad0) ```nginx @@ -50,4 +48,3 @@ server { ``` - diff --git a/docs/web/rss/ttrss.md b/docs/web/rss/ttrss.md index a6fdecb3d..a39968e82 100644 --- a/docs/web/rss/ttrss.md +++ b/docs/web/rss/ttrss.md @@ -1,7 +1,6 @@ # TTRSS - ### install ```bash @@ -24,7 +23,6 @@ docker-compose up ``` - ### Nginx As sub-domain mode: @@ -68,7 +66,6 @@ server { ``` - As sub-directory mode: [DO NOT RECOMMEND!] * If use this mode, all the APIs in the web frontend needs to be modified. e.g., the fever API should be `https://kiui.moe/ttrss/plugins/fever`, but the web frontend shows `https://kiui.moe/plugins/fever/`. This will also lead to several bugs. @@ -103,9 +100,6 @@ server { ``` - - - ### access web frontend At `kiui.moe/ttrss/` or `ttrss.kiui.moe`. @@ -113,7 +107,6 @@ At `kiui.moe/ttrss/` or `ttrss.kiui.moe`. Default account is `admin`. Remember to change password at once. - ### fever api for 3rd applications * activate in prefs. diff --git a/docs/web/scrape/grab.md b/docs/web/scrape/grab.md index bb3bfa7a6..db438c931 100644 --- a/docs/web/scrape/grab.md +++ b/docs/web/scrape/grab.md @@ -3,7 +3,6 @@ ## Simple API - ### Get ```python @@ -53,7 +52,6 @@ selector.text() ``` - ### Example crawl videos in `yhdm.so` . @@ -86,9 +84,6 @@ def crawl(keyword): ``` - - - ## Spider API ```python @@ -110,4 +105,3 @@ bot.run() ``` - diff --git a/docs/web/scrape/xpath.md b/docs/web/scrape/xpath.md index 99981e708..fdd94ff85 100644 --- a/docs/web/scrape/xpath.md +++ b/docs/web/scrape/xpath.md @@ -30,7 +30,6 @@ count //ul[count(li) > 2] ``` - ### Selectors ``` @@ -58,7 +57,6 @@ node() ``` - ### Built-in functions ``` @@ -76,7 +74,6 @@ substring(str, start, end) ``` - ### Operators ``` @@ -89,7 +86,6 @@ mod ``` - ### Axis ``` diff --git a/docs/web/web_overview.md b/docs/web/web_overview.md index 5e65c9a82..0858ec550 100644 --- a/docs/web/web_overview.md +++ b/docs/web/web_overview.md @@ -40,7 +40,6 @@ HTML + CSS + JavaScript > Should I write all JavaScript? - ### Dynamic Websites (Server-side programming) Application Server + Database @@ -54,8 +53,5 @@ Application Server + Database * `React`:一个用于动态构建用户界面的JS库。 - - - ### Deploy diff --git a/docs/windows/cuda.md b/docs/windows/cuda.md index af520fc8d..697ddae5e 100644 --- a/docs/windows/cuda.md +++ b/docs/windows/cuda.md @@ -1,7 +1,6 @@ ## CUDA on Windows - ### [install](https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html) Very easy, just follow the [link](https://developer.nvidia.com/cuda-downloads?target_os=Windows) and get a installer. @@ -19,7 +18,6 @@ nvcc --version ``` - ### CUDA_VISIBLE_DEVICES ```powershell @@ -27,7 +25,6 @@ set CUDA_VISIBLE_DEVICES=2,3 & python my_script.py ``` - ### Where is the damn `cl.exe` ? For the error `Command '['where', 'cl']' returned non-zero exit status 1`. @@ -45,7 +42,6 @@ For the error `Command '['where', 'cl']' returned non-zero exit status 1`. > also mentioned a script to do this at `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat`, but I didn't find it useful... - Another brilliant solution is from `tiny-cuda-nn`, auto-find `cl` in `setup.py/backend.py`: ```python @@ -71,5 +67,4 @@ elif os.name == "nt": ``` - \ No newline at end of file diff --git a/docs/writings/examples.md b/docs/writings/examples.md index 692f4dbf9..ff22c2620 100644 --- a/docs/writings/examples.md +++ b/docs/writings/examples.md @@ -5,7 +5,6 @@ * ... be prohibitively computational expensive ... - ### Abstract * It is of increasing importance for ... and draws increasing attention. @@ -13,7 +12,6 @@ * Experiments on the ... dataset show that xxx outperforms the state-of-the-arts in xxx, especially for ... - ### Intro * ... remains an important open challenge in ... @@ -41,7 +39,6 @@ * In contrast, ... - ### Contributions * We present a new approach capable of ... from ... @@ -49,9 +46,6 @@ * We demonstrate significant performance improvements of our approach compared to prior work. - - - ### Related work * We briefly describe related work in major lines of research: ... @@ -65,7 +59,6 @@ * Compared to the xxx approaches, wherein the ... is often suboptimal, yyy approaches are more straightforward and have achieved promising performance. - ### Methods * (directly describe methods) In this section, we briefly summarize A, and then describe how we extend it to B. @@ -74,14 +67,12 @@ * Our goal is .... In the following, we discuss the main components of our method. First, ... (See Sec~\ref{}). Next, ... Finally, .... - ### Experiments * The improvements potentially come from the design of ... in our method, which can act as a ... * - ### Appendix * The proof is given in the Appendix. @@ -89,7 +80,6 @@ * The detailed derivation of this formula is given in the Appendix. - ### junction * In this section we investigate the relationship between ... diff --git a/docs/writings/pitfalls.md b/docs/writings/pitfalls.md index a862ede1c..22c4418b4 100644 --- a/docs/writings/pitfalls.md +++ b/docs/writings/pitfalls.md @@ -1,7 +1,6 @@ # Writing Issues - ### Avoid Ambiguity * since --> because @@ -10,7 +9,6 @@ * if --> whether - ### Avoid Strong Words * always --> often @@ -18,7 +16,6 @@ * - ### Avoid Informal Words * though --> although @@ -52,13 +49,11 @@ * note ... --> note that ... - ### Avoid Complicated Words * utilize --> use - ### Which vs That * restrictive clause: that (without preceding comma) @@ -86,7 +81,6 @@ > ABC, that is the best method, ... [WRONG] - ### Misc * No need to add "the" before Figure/Table 1. @@ -104,7 +98,6 @@ e.g., "Tools proposed in [2]" --> "Tools proposed by AAA et al. [2]" - ### Uncountable * work: use several pieces of work. @@ -112,13 +105,11 @@ * software: use several software programs. - ### Abbreviation * ABC (Aaa Bbb Ccc) --> Aaa Bbb Ccc (ABC) - ### As follows * The paper makes the following contributions. diff --git a/docs/writings/rebuttals.md b/docs/writings/rebuttals.md index d063d0907..3efb86bea 100644 --- a/docs/writings/rebuttals.md +++ b/docs/writings/rebuttals.md @@ -1,7 +1,6 @@ ### Openreview markdown - Thank you for your valuable time and insightful comments! We have tried to address your concerns in the updated manuscript and our rebuttal text: **Q1: questions** @@ -13,9 +12,6 @@ replies. We hope our responses satisfactorily address your queries. Please let us know to address any further concerns impacting your review. - - - ### CMT pdf ```latex diff --git a/docs/writings/review.md b/docs/writings/review.md index 1855fb1b0..bb34b0b3f 100644 --- a/docs/writings/review.md +++ b/docs/writings/review.md @@ -6,14 +6,12 @@ * The paper addresses an important research topic on ... - ### weaknesses * Some parts of the paper are difficult to understand, ... * - ### post rebuttal After reading the other reviews and the rebuttal, I still remain at a reject rating. diff --git a/docs/writings/societal_impact.md b/docs/writings/societal_impact.md index c1e57aca2..b26e39a4d 100644 --- a/docs/writings/societal_impact.md +++ b/docs/writings/societal_impact.md @@ -1,7 +1,4 @@ * This project aims to provide users with an effective tool for synthesizing personal subjects (animals, objects) in different contexts. While general text-to-image models might be biased towards specific attributes when synthesizing images from text, our approach enables the user to get a better reconstruction of their desirable subjects. **On contrary, malicious parties might try to use such images to mislead viewers**. This is a common issue, existing in other generative models approaches or content manipulation techniques. Future research in generative modeling, and specifically of personalized generative priors, must continue investigating and revalidating these concerns. - - - * Our method has the potential for negative impact if used to create deepfakes. Using voice cloning, a malicious actor can create videos enabling identity theft or dissemination of fake news. However, in controlled settings, SPACEx can be used for positive creative purposes. \ No newline at end of file diff --git a/fix_mathblock.py b/fix_mathblock.py new file mode 100644 index 000000000..67f9c5031 --- /dev/null +++ b/fix_mathblock.py @@ -0,0 +1,52 @@ +import os +import re +import glob + +files = glob.glob('docs/**/*.md', recursive=True) + +# fix math blocks to be correctly rendered by mathjax: +# 1. $$..$$ will always be preceded and followed by an empty line, and there is no blank line following the left $$. +# 2. always wrap all content within \displaylines{} + +for file in files: + with open(file, 'r') as f: + lines = f.readlines() + + # naive matching $$...$$ + is_left = True + modified = False + for i, line in enumerate(lines): + if re.match('^\$\$', line) is not None: + if is_left: + if lines[i+1] != '\displaylines{\n': + lines[i] = '\n$$\n\displaylines{\n' + modified = True + is_left = False + else: + if lines[i-1] != '}\n': + lines[i] = '}\n$$\n\n' + modified = True + is_left = True + + # remove excessive blank lines + cnt = 0 + for i, line in enumerate(lines): + if line == '\n': + cnt += 1 + if cnt >= 3: + lines[i] = '' + modified = True + else: + cnt = 0 + + if modified: + lines = [line for line in lines if line != ''] + + if not is_left: + print(f'[WARN] {file} unmatched $$, no modification is done.') + else: + if modified: + with open(file, 'w') as f: + f.writelines(lines) + print(f'[INFO] {file} fixed.') + diff --git a/sync.ps1 b/sync.ps1 index b5eeedfc3..5a95bcf04 100644 --- a/sync.ps1 +++ b/sync.ps1 @@ -1,6 +1,7 @@ "==============================================================" "Update" "==============================================================" +python fix_mathblock.py python update_recent.py "=============================================================="