Ubuntu 编译 Linux 内核并从新内核启动

本文在一个 VirtualBox 的 Ubuntu VM 里编译新的Linux Kernel, 然后安装新kernel和模块, 然后更改系统从新内核启动.

下载 Linux 内核

可以选择从各种发布版本下载, 也可以选择从 github.com 下载. 下面选择从 Ubuntu 下载

$ git clone --depth 1 -b master git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/jammy

编译

要编译内核, 先安装必要的工具:

$ sudo apt update 
$ sudo apt upgrade -y 
$ sudo apt install git fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex bison libelf-dev -y

然后编译

$ cd jammy # 进入文件夹
$ make help  # 查看 make 命令
$ make menuconfig # 更改配置, 并保存
$ ls -lah .config # 查看 .config 文件

$ make all -j 8

Kernel: arch/x86/boot/bzImage is ready  (#1)

$ ls arch/x86/boot/bzImage # 查看 bzImage
-rw-rw-r-- 1 supra supra 11M Jul  1 11:40 arch/x86/boot/bzImage

$ find . -name *.ko # 查看新生成的模块

安装模块前 查看 /lib/modules/ 文件夹

$ ls -lah /lib/modules/
drwxr-xr-x  3 root root 4.0K Jul  1 10:40 .
drwxr-xr-x 88 root root 4.0K Jul  1 11:07 ..
drwxr-xr-x  5 root root 4.0K Jul  1 10:40 5.15.0-76-generic

安装之前查看 /boot/ 目录

$ uname -r # 查看当前运行的 kernel 版本
5.15.0-76-generic

$ ls -lah /boot/
drwxr-xr-x  4 root root 4.0K Jul  1 11:07 .
drwxr-xr-x 19 root root 4.0K Jul  1 10:45 ..
-rw-------  1 root root 6.0M Jun 15 17:47 System.map-5.15.0-76-generic
-rw-r--r--  1 root root 256K Jun 15 17:47 config-5.15.0-76-generic
drwxr-xr-x  5 root root 4.0K Jul  1 10:40 grub
lrwxrwxrwx  1 root root   28 Jul  1 10:40 initrd.img -> initrd.img-5.15.0-76-generic
-rw-r--r--  1 root root 106M Jul  1 11:07 initrd.img-5.15.0-76-generic
lrwxrwxrwx  1 root root   28 Jul  1 10:40 initrd.img.old -> initrd.img-5.15.0-76-generic
drwx------  2 root root  16K Jul  1 10:37 lost+found
lrwxrwxrwx  1 root root   25 Jul  1 10:40 vmlinuz -> vmlinuz-5.15.0-76-generic
-rw-------  1 root root  12M Jun 15 18:21 vmlinuz-5.15.0-76-generic
lrwxrwxrwx  1 root root   25 Jul  1 10:40 vmlinuz.old -> vmlinuz-5.15.0-76-generic

安装 kernel 模块和 kernel image

安装 kernel 模块

$ sudo make INSTALL_MOD_STRIP=1 modules_install

$ ls -lah /lib/modules/ # 可以看到多了一个目录, 我们新编译安装的版本
drwxr-xr-x  4 root root 4.0K Jul  1 11:56 .
drwxr-xr-x 88 root root 4.0K Jul  1 11:07 ..
drwxr-xr-x  5 root root 4.0K Jul  1 10:40 5.15.0-76-generic
drwxr-xr-x  3 root root 4.0K Jul  1 11:58 5.15.92

安装新 kernel image

$ sudo make install

$ ls -lah /boot/ #查看 /boot/ 文件夹, 看到多了一个版本的一份: 5.15.92
drwxr-xr-x  4 root root 4.0K Jul  1 12:00 .
drwxr-xr-x 19 root root 4.0K Jul  1 10:45 ..
-rw-------  1 root root 6.0M Jun 15 17:47 System.map-5.15.0-76-generic
-rw-r--r--  1 root root 5.6M Jul  1 11:59 System.map-5.15.92
-rw-r--r--  1 root root 256K Jun 15 17:47 config-5.15.0-76-generic
-rw-r--r--  1 root root 184K Jul  1 11:59 config-5.15.92
drwxr-xr-x  5 root root 4.0K Jul  1 12:00 grub
lrwxrwxrwx  1 root root   18 Jul  1 12:00 initrd.img -> initrd.img-5.15.92
-rw-r--r--  1 root root 106M Jul  1 11:07 initrd.img-5.15.0-76-generic
-rw-r--r--  1 root root  99M Jul  1 12:00 initrd.img-5.15.92
lrwxrwxrwx  1 root root   28 Jul  1 10:40 initrd.img.old -> initrd.img-5.15.0-76-generic
drwx------  2 root root  16K Jul  1 10:37 lost+found
lrwxrwxrwx  1 root root   15 Jul  1 11:59 vmlinuz -> vmlinuz-5.15.92
-rw-------  1 root root  12M Jun 15 18:21 vmlinuz-5.15.0-76-generic
-rw-r--r--  1 root root  11M Jul  1 11:59 vmlinuz-5.15.92
lrwxrwxrwx  1 root root   25 Jul  1 10:40 vmlinuz.old -> vmlinuz-5.15.0-76-generic

更新 grub

系统启动整体步骤如下:
BIOS -> GRUB -> vmlinuz -> initrd -> rootfs.

grub 核心部分

安装新 Kernel 之后, 要更新 GRUB 的配置. GRUB 的文件都在 /boot/grub/ 目录, 配置文件: /boot/grub/grub.cfg, kernel 模块和GRUB的 image 都在 /boot/grub/i386-pc 目录.

$ find /boot/grub/ -name *.img
/boot/grub/i386-pc/core.img
/boot/grub/i386-pc/boot.img

$ find /boot/grub/ -name *.mod

grub 配置

查看 /boot/grub/grub.cfg 我们可以看到我们新安装的 kernel 版本 5.15.92 已经在里面某个 menuentry 了, 这是在上面 make install 更新的.

$ cat /boot/grub/grub.cfg
    menuentry 'Ubuntu, with Linux 5.15.92' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.92-advanced-84148117-53b4-4df1-bd78-8dd5d40c41da' {
        recordfail
        load_video
        gfxmode $linux_gfx_mode
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_gpt
        insmod ext2
        set root='hd0,gpt2'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  bea48426-830f-4bb9-9c08-f537663c02e6
        else
          search --no-floppy --fs-uuid --set=root bea48426-830f-4bb9-9c08-f537663c02e6
        fi
        echo    'Loading Linux 5.15.92 ...'
        linux    /vmlinuz-5.15.92 root=/dev/mapper/ubuntu--vg-ubuntu--lv ro
        echo    'Loading initial ramdisk ...'
        initrd    /initrd.img-5.15.92

修改 grub 启动项

稍后如果我们重启, 就能在启动的时候选择我们新版本的kernel 了, 但是重启之前, 需要修改配置文件/etc/default/grub. 把 GRUB_TIMEOUT_STYLE=hidden 注释掉, 把 GRUB_TIMEOUT改成50秒.

  GRUB_DEFAULT=0
  # GRUB_TIMEOUT_STYLE=hidden
  GRUB_TIMEOUT=50

更新上面的配置文件后, 需要运行下面的命令更新 GRUB:

$ sudo update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.92
Found initrd image: /boot/initrd.img-5.15.92
Found linux image: /boot/vmlinuz-5.15.0-76-generic
Found initrd image: /boot/initrd.img-5.15.0-76-generic
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
done

最后重启:

$ sudo reboot

验证新kernel 版本

回到 VirtualBox 界面, 我们可以看到启动的界面, 可以选择 Advanced 菜单, 然后可以看到选择 kernel 界面:
grub.png

其中每一项代表 /boot/grub/grub.cfg的一个 menuentry. 选择我们的新kernel 然后启动.

Mac 安装 VirtualBox, 创建 Ubuntu 虚拟机

为了学习 Linux Kernel 的准备工作, 要在本地安装 VirtualBox, 然后使用虚拟机. 即使把VM搞挂, 也不用担心.

MAC 安装 VirtualBox

  1. https://www.virtualbox.org/wiki/Downloads 下载合适的安装包.
  2. 双击下载的 dmg 文件, 按照步骤一步步安装.
  3. 启动 VirtualBox 程序.

VirtualBox 安装 Ubuntu

  1. https://ubuntu.com/download/server 下载 Ubuntu ISO image(我选的服务器版本, 不是桌面版).
  2. 在 VirtualBox 界面上面的菜单中 点击 New(新建), 填入名字, 选择ISO 文件, 下一步(next)
    portForward.png
  3. 设置 用户名/密码, 设置内存/CPU/虚拟磁盘, 查看设置, 完成. 过程中, MAC 可能问你要一些权限, 给.
  4. 然后安装 Ubuntu: 选择语言, 键盘, 一路next, 最后 安装完成. 选择 “reboot now”.
    在上面的步骤里, 其中有一步是 安装 ssh server, 注意要手动选上, 后面可以直接本地 ssh.
  5. 启动后, 输入刚才设置的 用户名/密码 就能登录了.

本地 ssh 连接

虽然上面是安装的服务器版本, 但是直接从 VirtualBox 的界面操作还是不方便, 最好是本地ssh 连接. 上面的安装步骤里 已经选择了安装 ssh 服务器, 如果你没有安装, 可以从 VirtualBox 的界面登录进入, 安装 ssh 服务.

要本地ssh进入, 必须设置本地 host 到 VM 的端口转发.
设置端口转发步骤如下:

  1. 如果虚拟机没有 power off, 先 power off shutdown now.
  2. 进入 VirtualBox 界面, 选择虚拟机, 右键, 点击设置(Settings), 然后选择 网络(network), 点开高级(Advanced), 点击 端口转发(Port Forwarding)
    portForward.png
  3. 点击 添加 按钮, 添加名字, 主机端口, Guest 端口, 其它留空. 点击 OK 保存.
    forwordDetail.png
  4. 双击 VM 启动VM.
  5. 然后本地 命令行 登录. 端口是刚才设置的, 用户名是VM的登录用户名.

     $ ssh -p 2222 supra@localhost

使用 ssh 登录 qemu 启动的 VM

在实验 https://github.com/int0x03/kernel-utils 的过程中, 我们最后通过 qemu 启动 img 文件, 然后通过我们预设的用户名/密码进入 shell. 但是这个shell 和启动VM 用的同一个tty, 所以系统的一些message 会源源不断的输出到这个tty, 如果你要在这个shell 改些东西, 会非常尴尬.

如何启动另外一个tty?

要启动另外一个tty, 我们可以通过 ssh 登录这个VM, 就需要安装 openssh-server, 所以我们更改 config/env.sh 在需要安装到软件那行, 加入 openssh-server.

改后:

packages_to_install="systemd-resolved bpftrace bpfcc-tools gdb iptables openssh-server"

另外需要本地端口做转换, 所以需要更改 qemu 的启动参数, 在 boot 文件改动如下:

netdev_args="user,id=network0,net=192.168.0.0/24 -device e1000,netdev=network0 -net nic -net user,hostfwd=tcp::2222-:22"

sshd server 默认是不让以 root 用户登录的, 所以要更改 /etc/ssh/sshd_config 运行root 访问:

PermitRootLogin yes

然后重启 sshd server

systemctl restart ssh

如何登录

在宿主机 ssh -p 2222 root@localhost

Linux 内核的编译, 启动和制作ISO镜像

(本文最初发布在掘金 https://juejin.cn/post/7242312269887914041)
学习 Linux 内核的第一步就是下载 Linux 内核代码, 然后进行编译与运行.

下载内核源代码

内核源码除了 Linus 的官方 https://github.com/torvalds/linux git, 还有各家发布版的 Linux 内核. 最好去发布版的内核去下载, 这样编译过程中不容易出错.

我的 Linux 机器是 Ubuntu 22.04 TLS, 所以根据官方文档: https://wiki.ubuntu.com/Kernel/SourceCode, 可以 clone git 下载:

$ git clone --depth 1 -b master git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/jammy

这里为了减少下载文件的数量和大小, 选择只下载最新的代码, 只选择了master分支. 下载到 jammy 文件夹.

编译配置

编译之前先要安装编译内核需要的各种安装包:

$ sudo apt update 
$ sudo apt upgrade -y
$ sudo apt install git fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex bison libelf-dev -y 

配置并编译

$ cd jammy
# 此时并没有 .config 文件, 执行下面的命令会让你选择配置, 然后保存.
$ make menuconfig
# 生成 .config 文件
$ ls -lah .config
-rw-rw-r-- 1 sre sre 256K Jun  2 20:58 .config

我们可以看到 .config 文件里面的各种配置项目, 比如:

CONFIG_VERSION_SIGNATURE="Ubuntu 5.15.0-72.79-generic 5.15.98"
CONFIG_HAVE_KERNEL_GZIP=y
CONFIG_TSL2583=m

有些配置项表示一个纯文本的配置, 比如上面的版本号. 另外一些后面是 =y, =m 或者=n.

  1. =y:当选项被设置为=y时,表示该选项将作为内核的一部分编译进内核映像(静态编译)。这意味着相关的功能将始终可用,并包含在生成的内核映像中。当系统启动时,这些功能将立即可用,无需加载额外的模块。选择=y是在构建内核时将特定功能编译到内核中的一种方式。
  2. =m:当选项被设置为=m时,表示该选项将作为可加载模块编译(动态编译)。这意味着相关的功能将编译为独立的模块文件(通常是以.ko为扩展名),并在需要时由内核加载。使用=m选项可以将特定功能作为模块构建,以便在运行时根据需要加载和卸载。

选择=y=m取决于您对系统需求的权衡。如果您确定某个功能始终需要在内核运行时可用,并且不希望依赖额外的模块加载过程,则选择=y。如果您希望能够根据需要加载和卸载某个功能,并且不会一直使用该功能,则选择=m。

请注意,对于某些选项,可能还有其他设置,例如=n,表示将完全排除该功能的编译。这意味着相关的功能将在内核映像和模块中都不可用。选择特定的设置取决于您的需求和系统配置。

文字界面配置如下, 最后选择 Save 到 .config 文件.
image.png

编译:

$ make all -j 4 # 使用 4个线程编译, 可能要等很久, 最后生成内核文件 arch/x86/boot/bzImage
...

$ ls -lah arch/x86/boot/bzImage
-rw-r--r-- 1 root root 11M Jun  5 08:59 arch/x86/boot/bzImage
Kernel: arch/x86/boot/bzImage is ready  (#1)
$ make help # 查看更多命令

如果遇到下面的出错:

sre@sre:~/work/exp/jammy$ make all -j 8
  ...
make[1]: *** No rule to make target 'debian/canonical-certs.pem', needed by 'certs/x509_certificate_list'.  Stop.
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1900: certs] Error 2

可以参看 https://askubuntu.com/questions/1329538/compiling-the-kernel-5-11-11 去掉里面证书的部分:

# 可以看到当前的配置, 改成=“”
sre@sre:~/work/exp/jammy$ cat .config | grep CONFIG_SYSTEM_TRUSTED_KEYS
CONFIG_SYSTEM_TRUSTED_KEYS="debian/canonical-certs.pem"

测试启动内核

首先安装 qemu, 然后启动内核:

$ sudo apt install qemu-system-x86 -y
$ qemu-system-x86_64 -kernel bzImage -append "console=tty0 console=ttyS0" -nographic
SeaBIOS (version 1.15.0-1)
iPXE (https://ipxe.org) 00:03.0 CA00 PCI2.10 PnP PMM+07F8B340+07ECB340 CA00
Booting from ROM...

Kernel Offset: disabled
---[ end Kernel panic - not syncing: No working init found.  Try passing init= option to kernel.

可以看到最后内核 panic, 因为没有任何 root 文件系统, 也没有 init 代码. 这时候, 我们可以通过 -initrd 来启动, 里面可以包含一个 busybox.

如何制作一个 initrd

使用 https://github.com/aweeraman/kernel-utils 提供的工具, 按照说明文档, 执行第一步 ./mk-initrd 就能生成 initramfs.cpio.gz, 里面包含了 initrc 和 busybox.

再次测试启动:

$ qemu-system-x86_64 -kernel bzImage -initrd initramfs.cpio.gz -append "console=tty0 console=ttyS0" -nographic

#这次成功启动

如何做一个最小的内核并启动进入命令行

制作最小内核

在 Linux 内核源代码根目录执行 make help, 你能看到各种有关配置的子命令, 比如:

  1. defconfig: New config with default from ARCH supplied defconfig.
  2. allnoconfig: New config where all options are answered with no.
  3. allyesconfig: New config where all options are accepted with yes.
  4. tinyconfig: Configure the tiniest possible kernel.

这里我们关注的是 tinyconfig, 于是我们先清理一下, 然后使用 tinyconfig 生成 .config 文件, 然后制作 image, 最后使用 qemu 去执行:

$ make mrproper
$ make tinyconfig
$ make all -j 8
    Kernel: arch/x86/boot/bzImage is ready

$ qemu-system-x86_64 -kernel bzImage  -append "console=tty0 console=ttyS0 init=/bin/sh" -nographic
SeaBIOS (version 1.15.0-1)
iPXE (https://ipxe.org) 00:03.0 CA00 PCI2.10 PnP PMM+07F8B340+07ECB340 CA00
Booting from ROM..

最后发现日志停在 Booting from ROM.. 就没有任何消息了.

这是因为 tinyconfig 包含的驱动或者配置太少, 导致没有后续输出, 我们需要在 tinyconfig 的基础上添加一些配置.

添加配置

添加配置使用 make menuconfig 来修改, 最后保存就好.

  1. 64-bit kernel
    image.png
  2. Device Drivers -> Character devices -> Enable TTY
    image.png
  3. Device Drivers -> Character devices -> Serial drivers -> 8250/16550 and compatible serial support -> Console on 8250/16550 and compatible serial port
    image.png
  4. General setup > Configure standard kernel features (expert users) -> Enable support for printk
    image.png

保存上面配置, 并且做一个新的image:

$ make all -j 8 
$ qemu-system-x86_64 -kernel bzImage  -append "console=tty0 console=ttyS0 init=/bin/sh" -nographic

SeaBIOS (version 1.15.0-1)
iPXE (https://ipxe.org) 00:03.0 CA00 PCI2.10 PnP PMM+07F8B340+07ECB340 CA00
Booting from ROM..
Run /bin/sh as init process
Kernel panic - not syncing: Requested init /bin/sh failed (error -2).
Kernel Offset: disabled
---[ end Kernel panic - not syncing: Requested init /bin/sh failed (error -2). ]---

可以看到 Kernel panic, 因为我们只是启动 kernel, 没有root 文件系统, 也没有使用 initrd 的ramdisk.

修改config 支持 initrd

使用 make menuconfig 继续修改

  1. General setup -> Initial RAM filesystem and RAM disk (initramfs/initrd) support
    image.png
  2. Executable file formats -> Kernel support for ELF binaries
    image.png

保存, 然后 make all -j 8 再次制作image, 然后运行:

$ qemu-system-x86_64 -kernel bzImage -initrd initramfs.cpio.gz -append "console=tty0 console=ttyS0 init=/bin/sh" -nographic

Run /init as init process
Failed to execute /init (error -8)
Run /bin/sh as init process
/bin/sh: can't access tty; job control turned off
/ # input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input2
clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x311fac54234, max_idle_ns: 440795352581 ns
clocksource: Switched to clocksource tsc
uname -a
Linux (none) 6.4.0-rc5+ #3 Wed Jun  7 08:19:32 PDT 2023 x86_64 GNU/Linux
/ # ls /bin/
...

/ # ps aux
PID   USER     TIME  COMMAND

可以看到 kernel 启动后执行了 /bin/sh, 我们使用 uname能看到 kernel 的版本号, 但是ps 没有任何输出. 那是因为我们没有挂载 proc 文件系统. 同时执行挂载 proc 文件系统的脚本在 initramfs.cpio.gz 内部的 init 文件里, 它是一个 shell, 所以要使 kernel 支持 shell 的 #!.

再次通过 make menuconfig 修改配置:

  1. Executable file formats -> Kernel support for scripts starting with #!
    image.png
    2. File systems > Pseudo filesystems -> (/proc file system support & sysfs file system support)
    image.png

修改完保存, 然后重新制作 image, 并且运行:

$ qemu-system-x86_64 -kernel bzImage -initrd initramfs.cpio.gz -append "console=tty0 console=ttyS0 init=/bin/sh" -nographic

ps
PID   USER     TIME  COMMAND
    1 0         0:00 {init} /bin/sh /init
    2 0         0:00 [kthreadd]
    3 0         0:00 [kworker/0:0-eve]
    4 0         0:00 [kworker/0:0H]
    5 0         0:00 [kworker/u2:0-ev]
    6 0         0:00 [mm_percpu_wq]
    7 0         0:00 [ksoftirqd/0]
    8 0         0:00 [oom_reaper]
    9 0         0:00 [writeback]
   10 0         0:00 [kswapd0]
   11 0         0:00 [kworker/u2:1-ev]
   12 0         0:00 [kworker/0:1-eve]
   13 0         0:00 [kworker/u2:2-ev]
   14 0         0:00 [kworker/0:2]
   19 0         0:00 sh
   20 0         0:00 ps

如何制作一个可运行的 ISO 文件

创建文件结构并且复制数据

$ mkdir -p iso/boot/grub
$ cp bzImage iso/boot/
$ cp initramfs.cpio.gz  iso/boot/

创建 grub.cfg 文件

 $ vim iso/boot/grub/grub.cfg
set default=0
set timeout=10# Load EFI video drivers. This device is EFI so keep the
# video mode while booting the linux kernel.
insmod efi_gop
insmod font
if loadfont /boot/grub/fonts/unicode.pf2
then
        insmod gfxterm
        set gfxmode=auto
        set gfxpayload=keep
        terminal_output gfxterm
fimenuentry 'myos' --class os {
    insmod gzio
    insmod part_msdos
    linux /boot/bzImage init=/bin/sh console=ttyS0 console=tty0
    initrd /boot/initramfs.cpio.gz
}

安装 xorriso, mtools 并且制作 ISO image:

$ sudo apt install xorriso mtools -y
$ grub-mkrescue -o myos.iso iso/

$ ls -lah myos.iso

使用 Qemu 测试新的 ISO image

$ qemu-system-x86_64 -boot d -cdrom myos.iso -nographic

image.png

时序数据相似性检测

看到一篇关于时序相似性检测的文章 How can we quantify similarity between time series?, 里面涉及了几种算法的对比, 非常有启发性. 于是问 ChatGPT 要了几个关于相似性的算法, 也做了相关的对比.

这里记录一下相关的代码和步骤. 这个内容是在 Jupyter Notebook 写的. 主要分为4部分.

定义几种算法

import numpy as np
import pywt

# 1. 欧拉距离 1.长度相同
def euclidean_similarity(actual, predic):
    return np.sqrt(np.sum((actual - predic) ** 2))

# 2. mean absolute percentage error (MAPE) 1.长度相同, 值不能为0
def mape_similarity(actual, predic):
    return np.mean(np.abs((actual - predic) / actual))

# 3. Pearson correlation coefficient 1.长度相同, 1.0 表示完全相同
def correlation_similarity(actual, predic):
    a_diff = actual - np.mean(actual)
    p_diff = predic - np.mean(predic)
    numerator = np.sum(a_diff * p_diff)
    denominator = np.sqrt(np.sum(a_diff ** 2)) * np.sqrt(np.sum(p_diff ** 2))
    return numerator / denominator

# 4. 余弦相似性, 1.长度相同, 1.0 表示完全相同
def cosine_similarity(x, y):
    numerator = sum([a * b for a,b in zip(x,y)])
    denominator = np.sqrt(sum([a**2 for a in x])) * np.sqrt(sum([b**2 for b in y]))
    return numerator / denominator

# 5. 基于傅立叶变换 再使用余弦相似
def fft_similarity(x, y):
    # 对两个时序数据进行傅里叶变换
    fft_x = np.fft.fft(x)
    fft_y = np.fft.fft(y)

    # 对频谱数据进行归一化处理
    norm_x = np.abs(fft_x) / len(x)
    norm_y = np.abs(fft_y) / len(y)

    # 计算余弦相似度
    numerator = np.dot(norm_x, norm_y)
    denominator = np.linalg.norm(norm_x) * np.linalg.norm(norm_y)
    similarity = numerator / denominator

    return similarity

# 6. 小波变换 -
def wavelet_similarity(x, y, wavelet='db4', level=3, threshold='soft', threshold_value=0.1):
    # 对两个时序数据进行小波变换
    coeffs_x = pywt.wavedec(x, wavelet=wavelet, level=level)
    coeffs_y = pywt.wavedec(y, wavelet=wavelet, level=level)

    # 对小波系数进行阈值处理
    if threshold == 'hard':
        thresh_coeffs_x = [pywt.threshold(c, threshold_value, mode='hard') for c in coeffs_x]
        thresh_coeffs_y = [pywt.threshold(c, threshold_value, mode='hard') for c in coeffs_y]
    elif threshold == 'soft':
        thresh_coeffs_x = [pywt.threshold(c, threshold_value, mode='soft') for c in coeffs_x]
        thresh_coeffs_y = [pywt.threshold(c, threshold_value, mode='soft') for c in coeffs_y]
    else:
        raise ValueError("Invalid threshold mode. Must be 'hard' or 'soft'.")

    # 计算余弦相似度
    flat_x = np.concatenate(thresh_coeffs_x)
    flat_y = np.concatenate(thresh_coeffs_y)
    numerator = np.dot(flat_x, flat_y)
    denominator = np.linalg.norm(flat_x) * np.linalg.norm(flat_y)
    similarity = numerator / denominator

    return similarity

定义一些辅助函数

# 一些辅助函数
def __normalize(vals):
    min_v = min(vals)
    max_v = max(vals)
    return [(x - min_v) / (max_v - min_v) * 100 for x in vals]

def __fill_0_for_empty_ts(x_values, y_values):
    """
    x_values & y_values are 2 dimension array, the 1st column is the millisecond, the 2nd
    column is the value of that time, ex: [[], [], []]
    """
    start_time = round(min(min(x_values)[0], min(y_values)[0]) / 60000)  # the min minute
    end_time = round(max(max(x_values)[0], max(y_values)[0]) / 60000)  # the max minute

    count = int(end_time - start_time) + 1
    x_vals = np.zeros(count)
    y_vals = np.zeros(count)

    for element in x_values:
        minute = round(element[0] / 60000)
        x_vals[minute - start_time] = float(element[1])

    for element in y_values:
        minute = round(element[0] / 60000)
        y_vals[minute - start_time] = float(element[1])

    return x_vals, y_vals

定义对比和测试函数

import matplotlib.pyplot as plt
import pandas as pd
from IPython.display import display

def __prepare(ts_x, ts_y):
    x = ts_x[:,1]
    y = ts_y[:,1]

    fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(30, 8))

    ax1.plot(np.array(ts_x[:,0], dtype='datetime64[ms]'), x, color='blue', label='ts_x')
    ax2.plot(np.array(ts_y[:,0], dtype='datetime64[ms]'), y, color='red', label='ts_y')


    nx = np.array(__normalize(x))
    ny = np.array(__normalize(y))
    ax3.plot(np.array(ts_y[:,0], dtype='datetime64[ms]'), nx, color='blue', label='normalized_x')
    ax3.plot(np.array(ts_y[:,0], dtype='datetime64[ms]'), ny, color='red', label='normalized_y')
    ax3.set_title('normalized')
    plt.tight_layout()
    
    return x, y, nx, ny

def test_similarity(x, y, similarity_func):
    return similarity_func(x, y)

# calc shift 
def test_similarity_with_move(ts_x, ts_y, similarity_func):
    steps = 8
    length = len(ts_x)
    best_score = similarity_func(ts_x, ts_y)
    best_shift = 0
    for move in range(1, steps):
        score = similarity_func(ts_x[move:], ts_y[:(length - move)])
        # print(f"{best_score} vs {score} with {similarity_func.__name__} shift: {move}")
        best_score, best_shift = (score, move) if score > best_score else (best_score, best_shift)
        
        score = similarity_func(ts_y[move:], ts_x[:(length - move)])
        # print(f"{best_score} vs {score} with {similarity_func.__name__} shift: {-move}")
        best_score, best_shift = (score, move) if score > best_score else (best_score, best_shift)
    
    return best_score, best_shift

def compare(ts_x, ts_y):
    algorithms = [correlation_similarity, cosine_similarity, fft_similarity, wavelet_similarity]
    x, y, nx, ny = __prepare(ts_x, ts_y)
    result = {"algorithm":[], "raw":[], "normalized":[], "rawWithShift":[], "normalizedWithShift":[]}
    for algorithm in algorithms:
        result["algorithm"].append(algorithm.__name__)
        result["raw"].append(test_similarity(x, y, algorithm))
        result["normalized"].append(test_similarity(nx, ny, algorithm))
        result["rawWithShift"].append(test_similarity_with_move(x, y, algorithm))
        result["normalizedWithShift"].append(test_similarity_with_move(nx, ny, algorithm))

    df = pd.DataFrame(result)
    display(df)
    

对比测试

明显区分度测试

# 测试1 明显区分度 原始数据
ts_x = np.array([[1682638320000,0.007328675730378209],[1682638380000,0.007166630970559917],[1682638440000,0.00677495505275072],[1682638500000,0.005878961713237096],[1682638560000,0.005011434857853048],[1682638620000,0.003964435698814772],[1682638680000,0.0032577727794710354],[1682638740000,0.0028030470165349985],[1682638800000,0.0022510571486542563],[1682638860000,0.0020857610336525445],[1682638920000,0.0019790581076671865],[1682638980000,0.0018066359030913803],[1682639040000,0.0016530616743632986],[1682639100000,0.001563973077646108],[1682639160000,0.0015774015801659491],[1682639220000,0.0016635560567977992],[1682639280000,0.001684409957195654],[1682639340000,0.0018186865396723206],[1682639400000,0.0020148695825893403],[1682639460000,0.002392657604525561],[1682639520000,0.002773864429062134],[1682639580000,0.002917356551485062],[1682639640000,0.0030241732893402373],[1682639700000,0.0033943180813809093],[1682639760000,0.0039351942403756945],[1682639820000,0.004199541581432875],[1682639880000,0.004468997813243392],[1682639940000,0.004762451107713561],[1682640000000,0.004873222007784839],[1682640060000,0.004694137046307945],[1682640120000,0.004133435929098428],[1682640180000,0.0038304855350106415],[1682640240000,0.0035566636212391867],[1682640300000,0.0034563444688856526],[1682640360000,0.003563236805129044],[1682640420000,0.003652322875815628],[1682640480000,0.003764329371771402],[1682640540000,0.003709763930659138],[1682640600000,0.003527470851182768],[1682640660000,0.0031720018560328356],[1682640720000,0.0028307219739353018],[1682640780000,0.002446958588156911],[1682640840000,0.002163249357725938],[1682640900000,0.0018491573754286783],[1682640960000,0.0016054880435072416],[1682641020000,0.0016268585353828025],[1682641080000,0.0017774368812232266],[1682641140000,0.002023414635800358],[1682641200000,0.002291366977382303],[1682641260000,0.0025414255987979972],[1682641320000,0.0027056666107684313],[1682641380000,0.002782190422505826],[1682641440000,0.0027145828288908103],[1682641500000,0.002552173457510687],[1682641560000,0.0022976245080648106],[1682641620000,0.002022121416229261],[1682641680000,0.0017429114162316184],[1682641740000,0.0015257355856960197],[1682641800000,0.0013625396060445993],[1682641860000,0.0013000981455664196],[1682641920000,0.0013037985329040769],[1682641980000,0.0013252149418385706],[1682642040000,0.0013912497725716566],[1682642100000,0.0014078215964332674],[1682642160000,0.0016080090965746585],[1682642220000,0.0021592147172232456],[1682642280000,0.0029726174960073015],[1682642340000,0.003957435247782359],[1682642400000,0.004996596076256021],[1682642460000,0.005771800735675292],[1682642520000,0.0062248419561224955],[1682642580000,0.006263563752554657],[1682642640000,0.005864433036227079],[1682642700000,0.0052890639934390915],[1682642760000,0.004523157041789183],[1682642820000,0.004078585455152717],[1682642880000,0.004032869476291778],[1682642940000,0.00407780073662134],[1682643000000,0.004438500566723458],[1682643060000,0.004868589334792062],[1682643120000,0.005580639406287835],[1682643180000,0.006204796843167548],[1682643240000,0.006540594322381965],[1682643300000,0.006978832012888847],[1682643360000,0.007070061231323588],[1682643420000,0.007230046190175199],[1682643480000,0.007431167185659282],[1682643540000,0.007635387459498766],[1682643600000,0.007941957234981256],[1682643660000,0.008266612596506961],[1682643720000,0.008703058343890735],[1682643780000,0.009008689964864591],[1682643840000,0.009035894501531638],[1682643900000,0.008945351893496656],[1682643960000,0.008824816546498138],[1682644020000,0.008335362088067955],[1682644080000,0.00781502222873287],[1682644140000,0.007239937679778152],[1682644200000,0.006518150563694758],[1682644260000,0.0058600028132203],[1682644320000,0.005184361913486701],[1682644380000,0.004682281031753832],[1682644440000,0.004348967564366868],[1682644500000,0.004163255024411616],[1682644560000,0.00419656113779332],[1682644620000,0.004241947741375651],[1682644680000,0.00428298333451127],[1682644740000,0.004339898919598184],[1682644800000,0.0043190309827773055],[1682644860000,0.004108698762247842],[1682644920000,0.0038160516541266842],[1682644980000,0.0035909966426352913],[1682645040000,0.0033678108960534248],[1682645100000,0.003232182040623477],[1682645160000,0.0031679864734261987],[1682645220000,0.00308763269254142],[1682645280000,0.0030224010354535924],[1682645340000,0.002893999790712143],[1682645400000,0.0027275119021520355],[1682645460000,0.002470835125129578],[1682645520000,0.002280509501738859],[1682645580000,0.002525232903371144],[1682645640000,0.0030782302258784977],[1682645700000,0.003811473746475169],[1682645760000,0.004666075560952443],[1682645820000,0.005272957055570848],[1682645880000,0.005605267487379217],[1682645940000,0.00549216535396746],[1682646000000,0.004993662245300956],[1682646060000,0.0043942169540098774],[1682646120000,0.0036102880556789785],[1682646180000,0.0031215733333150864],[1682646240000,0.0027843230768865856],[1682646300000,0.002473532317117999],[1682646360000,0.002327839192867165],[1682646420000,0.0021224560822837857],[1682646480000,0.001950708267869361],[1682646540000,0.00175140393765838],[1682646600000,0.0015800073810331439],[1682646660000,0.0015394708645942723],[1682646720000,0.0015687023906095776],[1682646780000,0.001708640903288039],[1682646840000,0.0020302216360987835],[1682646900000,0.0025163984632992076],[1682646960000,0.0029418072306420795],[1682647020000,0.003384975209639207],[1682647080000,0.0036272010302585977],[1682647140000,0.003623455966178857],[1682647200000,0.0034589918678064047],[1682647260000,0.003108060740452001],[1682647320000,0.002825394661602032],[1682647380000,0.002666588103194978],[1682647440000,0.002649715682851328],[1682647500000,0.0028823682055378885],[1682647560000,0.0032135645334064877],[1682647620000,0.003459947824070886],[1682647680000,0.0037663489961766716],[1682647740000,0.0037257364208496124],[1682647800000,0.0035998024353294245],[1682647860000,0.0033623823641214523],[1682647920000,0.003162295566296658],[1682647980000,0.003195775651740007],[1682648040000,0.0031361723464268243],[1682648100000,0.003242792107609249],[1682648160000,0.0031746102008726185],[1682648220000,0.003142860060609487],[1682648280000,0.0029911125004538075],[1682648340000,0.0027131293240030274],[1682648400000,0.0024885990084401177],[1682648460000,0.0021708754800804364],[1682648520000,0.0020740666130409924],[1682648580000,0.0019912220124088664],[1682648640000,0.0019405473558673503],[1682648700000,0.0019347275967319666],[1682648760000,0.0019458516662160807],[1682648820000,0.0020409561978713686],[1682648880000,0.0021301816917985716],[1682648940000,0.0022887430490345917],[1682649000000,0.002770562068244997],[1682649060000,0.0035850825855235913],[1682649120000,0.004619275480323259],[1682649180000,0.005768972400642336],[1682649240000,0.006633137430365976],[1682649300000,0.007155586552817561],[1682649360000,0.007161575246032448],[1682649420000,0.00672737257736622],[1682649480000,0.006016624766026268],[1682649540000,0.0051753086622016164],[1682649600000,0.004593801305652678],[1682649660000,0.004163198340509822],[1682649720000,0.0038325590526006037],[1682649780000,0.0036156221266722133],[1682649840000,0.0033222377599410047],[1682649900000,0.0031782268963684857],[1682649960000,0.003106968471933924],[1682650020000,0.003002687829276929],[1682650080000,0.0030282696101180395],[1682650140000,0.002954503977843359],[1682650200000,0.0029196119932183295],[1682650260000,0.0028110810196320113],[1682650320000,0.0027662178732079656],[1682650380000,0.0028514335000644486],[1682650440000,0.002886132007508868],[1682650500000,0.0030097880354288398],[1682650560000,0.003180530916290447],[1682650620000,0.003237196174907586],[1682650680000,0.0032029400644095762],[1682650740000,0.003381681294171046],[1682650800000,0.003462134537248973],[1682650860000,0.003540405580070405],[1682650920000,0.0036145002762770773],[1682650980000,0.0034996376238434213],[1682651040000,0.0033830123967277803],[1682651100000,0.0029777201901944883],[1682651160000,0.002634704500189766],[1682651220000,0.0022872867121803697],[1682651280000,0.0019755982712702513],[1682651340000,0.001977914513543788],[1682651400000,0.0019632992592498733],[1682651460000,0.0019895730560886005],[1682651520000,0.0020045462460269725],[1682651580000,0.001988533858144681],[1682651640000,0.0021221725321147744],[1682651700000,0.0023389076171003165],[1682651760000,0.0025029030080270243],[1682651820000,0.002712347402250681],[1682651880000,0.002934722834328829],[1682651940000,0.0030497812068259744],[1682652000000,0.0029902790024561865],[1682652060000,0.002727873719077234],[1682652120000,0.002392853116615301],[1682652180000,0.0021400685477295234],[1682652240000,0.0019624593344927943],[1682652300000,0.0019896328293226295],[1682652360000,0.002009000707588582],[1682652420000,0.0019710345093708614],[1682652480000,0.0020518220268753717],[1682652540000,0.002008597813535018],[1682652600000,0.0019351572418411234],[1682652660000,0.0018052122046056107],[1682652720000,0.0016644525621912765],[1682652780000,0.0016511399137405514],[1682652840000,0.001616071462890556],[1682652900000,0.0016209567438129069],[1682652960000,0.0016265177504325434],[1682653020000,0.0016007398012617413],[1682653080000,0.001634723746268163],[1682653140000,0.0016626151240427545],[1682653200000,0.0017584584630750966],[1682653260000,0.001893831719001371],[1682653320000,0.0019970695701683194],[1682653380000,0.00232765810444735],[1682653440000,0.002659990756185615],[1682653500000,0.0029111305458242587],[1682653560000,0.0032191634784118905],[1682653620000,0.003316524984117941],[1682653680000,0.0034123722446546267],[1682653740000,0.0033002312352797825],[1682653800000,0.0030223228060581864],[1682653860000,0.0027233283260920116],[1682653920000,0.0022124329819012134],[1682653980000,0.0019411218239093753],[1682654040000,0.0017181319806034434],[1682654100000,0.0015343285921756156],[1682654160000,0.0015095633924568919],[1682654220000,0.0015374033310443513],[1682654280000,0.0016713365986797957],[1682654340000,0.0017135039895874726],[1682654400000,0.001737500078526466],[1682654460000,0.0017783023895173722],[1682654520000,0.001836238317368899],[1682654580000,0.0019628669204051485],[1682654640000,0.0020511071595300523],[1682654700000,0.0020919509248067403],[1682654760000,0.0020802847578447192],[1682654820000,0.0020133898893013313],[1682654880000,0.0019487157433204505],[1682654940000,0.001805898411775364],[1682655000000,0.0016502545493773946],[1682655060000,0.0016221728607574981],[1682655120000,0.0016981000296136806],[1682655180000,0.0018296560039331444],[1682655240000,0.0019355113811716507],[1682655300000,0.0020158468465454327],[1682655360000,0.0020530949360129114],[1682655420000,0.0020180653355409417],[1682655480000,0.0019211640263269159],[1682655540000,0.001773363009312745],[1682655600000,0.0015853151349297656],[1682655660000,0.0014578640314741875],[1682655720000,0.001405827753802158],[1682655780000,0.0013930104535504473],[1682655840000,0.0014235676662394114],[1682655900000,0.0014888582722065724],[1682655960000,0.0015849292356276967],[1682656020000,0.0016564799291802768],[1682656080000,0.0017166160443695677],[1682656140000,0.001752875433222001],[1682656200000,0.0017569496266973683],[1682656260000,0.0017321556267200222],[1682656320000,0.001858476775846496],[1682656380000,0.0019992890151594445],[1682656440000,0.0021491873565406827],[1682656500000,0.002316572635042702],[1682656560000,0.0023472483849754644],[1682656620000,0.002481008715267463],[1682656680000,0.0024932616003254804],[1682656740000,0.0024815872975171294],[1682656800000,0.002438305748546088],[1682656860000,0.0022468354153518666],[1682656920000,0.002227421024070697],[1682656980000,0.0022351456581477525],[1682657040000,0.002212796542173767],[1682657100000,0.0022636703788108115],[1682657160000,0.0022842578693319515],[1682657220000,0.0023460665275277792],[1682657280000,0.002447716016601653],[1682657340000,0.002360426718802877],[1682657400000,0.002255584073876382],[1682657460000,0.0022849698279282515],[1682657520000,0.002357137323888314],[1682657580000,0.0026025740492461313],[1682657640000,0.002925715828579034],[1682657700000,0.0032799688856598452],[1682657760000,0.00357265637643589],[1682657820000,0.0036104373631341558],[1682657880000,0.0035843899201150053],[1682657940000,0.003377389430974098],[1682658000000,0.003075850252918455],[1682658060000,0.0028364656965261803],[1682658120000,0.002651271053682125],[1682658180000,0.0024537666189214935],[1682658240000,0.0022910827204858375],[1682658300000,0.002376228010664283],[1682658360000,0.0024121694859116083],[1682658420000,0.0025048976227134423],[1682658480000,0.002602719159143896],[1682658540000,0.0025982781005319255],[1682658600000,0.0026006775143946337],[1682658660000,0.0024407333284679478],[1682658720000,0.02883852003407894],[1682658780000,0.1492940034375545],[1682658840000,0.3176241592866017],[1682658900000,0.45541223987530366],[1682658960000,0.5575562726001705],[1682659020000,0.6180101775080709],[1682659080000,0.6482994706319214],[1682659140000,0.655331858934281],[1682659200000,0.6440218466775072],[1682659260000,0.6242940953343561],[1682659320000,0.5857011910622789],[1682659380000,0.544735358222797],[1682659440000,0.5064806297694842],[1682659500000,0.4511789805392241],[1682659560000,0.38312493430286465],[1682659620000,0.28317922112998983],[1682659680000,0.17975552116715965],[1682659740000,0.07697727298290669],[1682659800000,0.0045456785356436935],[1682659860000,0.0037271638293786546],[1682659920000,0.0035343425457551314]])
ts_y = np.array([[1682638320000,1.2999976391715666],[1682638380000,1.3445933616363022],[1682638440000,0.8513891645166145],[1682638500000,0.580030734376455],[1682638560000,0.5366737829361838],[1682638620000,0.29213584265117487],[1682638680000,0.06666666666666667],[1682638740000,0.016666666666666666],[1682638800000,0.016666666666666666],[1682638860000,0],[1682638920000,0.016666666666666666],[1682638980000,0.041666666666666664],[1682639040000,0.049999999999999996],[1682639100000,0.14999968754412588],[1682639160000,0.16110728963202783],[1682639220000,0.15000013889120378],[1682639280000,0.14438552780642439],[1682639340000,0.3352488269002545],[1682639400000,0.4791106494858955],[1682639460000,0.4670988185285921],[1682639520000,0.47477976942200895],[1682639580000,0.4166843529964785],[1682639640000,0.5047513306649607],[1682639700000,1.1145315261277136],[1682639760000,1.3657446685411132],[1682639820000,1.3118932804610217],[1682639880000,1.3502069581635667],[1682639940000,0.8249999312100912],[1682640000000,0.5749947576282455],[1682640060000,0.425062421275175],[1682640120000,0.39166635418185697],[1682640180000,0.5333356252965927],[1682640240000,0.5416674308240772],[1682640300000,0.5416659377744454],[1682640360000,0.5499998959440148],[1682640420000,0.46666524316478064],[1682640480000,0.6336589514654256],[1682640540000,0.6913314113839778],[1682640600000,0.5028315836111288],[1682640660000,0.38466392611255945],[1682640720000,0.19999944449045007],[1682640780000,0.10833336810662474],[1682640840000,0.03333333333333333],[1682640900000,0.0250005208514185],[1682640960000,0.2667035720031638],[1682641020000,0.40833451392505926],[1682641080000,0.5416680904110321],[1682641140000,0.6833330295489726],[1682641200000,0.45832292308947503],[1682641260000,0.5583323612227931],[1682641320000,0.46665854636552123],[1682641380000,0.34166541686573676],[1682641440000,0.33333107679551194],[1682641500000,0.08333326388946759],[1682641560000,0.05000010416796876],[1682641620000,0.024999999999999998],[1682641680000,0.016666666666666666],[1682641740000,0.024999999999999998],[1682641800000,0.041669619101209456],[1682641860000,0.049999999999999996],[1682641920000,0.05833302083926493],[1682641980000,0.15000000000000005],[1682642040000,0.1333332638938078],[1682642100000,0.2083326042501437],[1682642160000,0.6653442813240605],[1682642220000,1.0819944200907627],[1682642280000,1.3986757640109924],[1682642340000,1.6500266144000366],[1682642400000,1.4083953201740684],[1682642460000,1.1167151023096336],[1682642520000,0.9916681947057309],[1682642580000,0.7666733685670183],[1682642640000,0.7583336112326406],[1682642700000,0.59166618062355],[1682642760000,0.6583337847718469],[1682642820000,0.5999875460015153],[1682642880000,0.6166656945127288],[1682642940000,0.6166678820895601],[1682643000000,0.4499863662297911],[1682643060000,0.9416896769371015],[1682643120000,0.9832976874844609],[1682643180000,0.9333240658929527],[1682643240000,1.0750055964431735],[1682643300000,0.600000903022002],[1682643360000,0.39173132611068756],[1682643420000,0.40000562689957914],[1682643480000,0.4916728171698435],[1682643540000,0.5500227058301577],[1682643600000,0.9166703126734733],[1682643660000,1.0583296540822842],[1682643720000,0.8999965974380644],[1682643780000,1.1166663542753188],[1682643840000,0.7916661458777478],[1682643900000,0.76667354487317],[1682643960000,0.7722229090747322],[1682644020000,0.4666662500708899],[1682644080000,0.7416511215169792],[1682644140000,0.8249939602133775],[1682644200000,0.7083330903728287],[1682644260000,0.8083158526792605],[1682644320000,0.6416650001313566],[1682644380000,0.724999757219176],[1682644440000,0.8166649654408255],[1682644500000,0.7666740378807257],[1682644560000,0.6083323959263589],[1682644620000,0.37500145838802307],[1682644680000,0.4499981251539282],[1682644740000,0.48333923941052465],[1682644800000,0.5333367363136681],[1682644860000,0.4833325347750283],[1682644920000,0.37500076390596115],[1682644980000,0.400000000050347],[1682645040000,0.3833338194904531],[1682645100000,0.4333312848965507],[1682645160000,0.3416668750176507],[1682645220000,0.24166645841926884],[1682645280000,0.21666690978081724],[1682645340000,0.15833458338599746],[1682645400000,0.14166677085546953],[1682645460000,0.12500935008019612],[1682645520000,0.5833696574822261],[1682645580000,1.3166618058052564],[1682645640000,1.7416512586793633],[1682645700000,2.066650247736495],[1682645760000,1.791559029251039],[1682645820000,1.1082862688662387],[1682645880000,0.7999629530472216],[1682645940000,0.44166684035257686],[1682646000000,0.4416632989306695],[1682646060000,0.39166559063438255],[1682646120000,0.29166784727343953],[1682646180000,0.3500004167204877],[1682646240000,0.1333350349949652],[1682646300000,0.1416661805839104],[1682646360000,0.11666652778009254],[1682646420000,0.049999999999999996],[1682646480000,0.05000045141334044],[1682646540000,0.0583330208398436],[1682646600000,0.15833333336313743],[1682646660000,0.30833399308608334],[1682646720000,0.45000006944965304],[1682646780000,0.5250007986621833],[1682646840000,0.7166646195307386],[1682646900000,0.6583338195005793],[1682646960000,0.6250019098239343],[1682647020000,0.8083302093174858],[1682647080000,0.5666707306083691],[1682647140000,0.4916658333865731],[1682647200000,0.424999895839844],[1682647260000,0.18333333334056726],[1682647320000,0.2916672917005231],[1682647380000,0.4166673264631103],[1682647440000,0.5083314236809866],[1682647500000,0.6333356251163261],[1682647560000,0.5749980904075438],[1682647620000,0.5666662847822608],[1682647680000,0.49166823096313755],[1682647740000,0.44166791681800815],[1682647800000,0.40841168290966934],[1682647860000,0.5083278178490974],[1682647920000,0.8000021880580872],[1682647980000,0.808369177300842],[1682648040000,0.7416622920714273],[1682648100000,0.516662570484145],[1682648160000,0.23333343756351463],[1682648220000,0.29166312539721073],[1682648280000,0.3083327778530078],[1682648340000,0.30833281374917104],[1682648400000,0.2999658981003717],[1682648460000,0.2083337153126468],[1682648520000,0.22500013893257995],[1682648580000,0.24999954868908955],[1682648640000,0.2500330162625303],[1682648700000,0.21669553983142747],[1682648760000,0.2500018418379428],[1682648820000,0.28332830256066716],[1682648880000,0.25833923988846696],[1682648940000,0.8499995834230328],[1682649000000,1.4416584068732918],[1682649060000,1.8750083767517685],[1682649120000,2.349893261454968],[1682649180000,2.0333524758803745],[1682649240000,1.6416598511596454],[1682649300000,1.38332285358811],[1682649360000,1.0000722840169565],[1682649420000,0.8083225073860746],[1682649480000,0.8583610880767096],[1682649540000,0.7166698979418432],[1682649600000,0.8416634376934256],[1682649660000,0.7166375764127267],[1682649720000,0.5916603829802607],[1682649780000,0.5916649307245302],[1682649840000,0.44166791671354294],[1682649900000,0.8167755438018871],[1682649960000,0.6333245362349534],[1682650020000,0.5499907703759365],[1682650080000,0.6416585809075712],[1682650140000,0.333335034848538],[1682650200000,0.40833444452286255],[1682650260000,0.5750007291879341],[1682650320000,0.6500013195376172],[1682650380000,0.5916653826510151],[1682650440000,0.5249992361843148],[1682650500000,0.5333403839261278],[1682650560000,0.34165434904964276],[1682650620000,0.39167813100060345],[1682650680000,0.6833485843517212],[1682650740000,0.7333358681566876],[1682650800000,0.6916698978701316],[1682650860000,0.6250143504471447],[1682650920000,0.37500197947442404],[1682650980000,0.23333298612557826],[1682651040000,0.2416672569602147],[1682651100000,0.25000034729687937],[1682651160000,0.19166746537949567],[1682651220000,0.14999975695095477],[1682651280000,0.26666697919140725],[1682651340000,0.2583343403126462],[1682651400000,0.2583332639033565],[1682651460000,0.27499979170428196],[1682651520000,0.10833333333333332],[1682651580000,0.24166607643590646],[1682651640000,0.5249989583778916],[1682651700000,0.4666668402978886],[1682651760000,0.4666667014176795],[1682651820000,0.5333335416860536],[1682651880000,0.32500006945515053],[1682651940000,0.341666944520255],[1682652000000,0.3166639589581676],[1682652060000,0.1083228263925104],[1682652120000,0.11666899364960831],[1682652180000,0.19999947917838531],[1682652240000,0.23333618115900626],[1682652300000,0.24166677083723986],[1682652360000,0.16666739586444],[1682652420000,0.07500045145385299],[1682652480000,0.06666631945428209],[1682652540000,0.12499972223148115],[1682652600000,0.11666628474088458],[1682652660000,0.11666666668952506],[1682652720000,0.12499951390162019],[1682652780000,0.08333388890740802],[1682652840000,0.09166666666666666],[1682652900000,0.07499999999999998],[1682652960000,0.049999999999999996],[1682653020000,0.03333333333333333],[1682653080000,0.04166409801422338],[1682653140000,0.09166673611168981],[1682653200000,0.1916665277835648],[1682653260000,0.2083334722291669],[1682653320000,0.38333708460812416],[1682653380000,0.6833332291818573],[1682653440000,0.6083339584305589],[1682653500000,0.5999997222314811],[1682653560000,0.5083350699424805],[1682653620000,0.16666503480887837],[1682653680000,0.14999923616232383],[1682653740000,0.14166670139250584],[1682653800000,0.05000013889120374],[1682653860000,0.041666805557870404],[1682653920000,0.0499998958346354],[1682653980000,0.05833333333333333],[1682654040000,0.07499868076443451],[1682654100000,0.09999954870066341],[1682654160000,0.1583352084586321],[1682654220000,0.17499979166927093],[1682654280000,0.15000010418099005],[1682654340000,0.15000041668750105],[1682654400000,0.11666690972931151],[1682654460000,0.1666664583385416],[1682654520000,0.23333388896123028],[1682654580000,0.20833378475680067],[1682654640000,0.16666732654443522],[1682654700000,0.09166697917838586],[1682654760000,0.04166718753255411],[1682654820000,0.049999999999999996],[1682654880000,0.050000173614728076],[1682654940000,0.04999989583463539],[1682655000000,0.041666666666666664],[1682655060000,0.24166673613831038],[1682655120000,0.26666506957175207],[1682655180000,0.27500059032364066],[1682655240000,0.27499934037311685],[1682655300000,0.06666690973799248],[1682655360000,0.04166690972931155],[1682655420000,0.033333055560474445],[1682655480000,0.024999999999999998],[1682655540000,0.041666666666666664],[1682655600000,0.049999930556134255],[1682655660000,0.041666805557870404],[1682655720000,0.049999999999999996],[1682655780000,0.041666666666666664],[1682655840000,0.041666493059172374],[1682655900000,0.049999999999999996],[1682655960000,0.041666666666666664],[1682656020000,0.03333333333333333],[1682656080000,0.025000138890046302],[1682656140000,0.024999999999999998],[1682656200000,0.024999999999999998],[1682656260000,0.24166593753515497],[1682656320000,0.3000057354140598],[1682656380000,0.34173160451081036],[1682656440000,0.34166718767839527],[1682656500000,0.1583344445028963],[1682656560000,0.23333319452632917],[1682656620000,0.2833335764301233],[1682656680000,0.29166565987079957],[1682656740000,0.2750007986517668],[1682656800000,0.14166684028428822],[1682656860000,0.05833333333333333],[1682656920000,0.29999958334114585],[1682656980000,0.349997847455124],[1682657040000,0.3499976738858207],[1682657100000,0.33333291667447906],[1682657160000,0.09166663194806131],[1682657220000,0.1916660069813356],[1682657280000,0.19166652790336464],[1682657340000,0.20833354169560273],[1682657400000,0.35000000000000014],[1682657460000,0.3583314586865936],[1682657520000,0.36666715281626355],[1682657580000,0.5583319792058726],[1682657640000,0.591667534806571],[1682657700000,0.550002084140452],[1682657760000,0.5416671180802953],[1682657820000,0.3416666320065104],[1682657880000,0.2000009723428884],[1682657940000,0.2832766527714344],[1682658000000,0.32499826397742587],[1682658060000,0.3666660764633957],[1682658120000,0.33334533077339223],[1682658180000,0.10833333333333331],[1682658240000,0.2083331944467594],[1682658300000,0.2833334375039065],[1682658360000,0.3000001388900465],[1682658420000,0.30833322916796896],[1682658480000,0.1666662847310474],[1682658540000,0.049999999999999996],[1682658600000,0.06666795152012105],[1682658660000,8.084383797038834],[1682658720000,116.95480320305296],[1682658780000,308.0927477224179],[1682658840000,452.45974097212917],[1682658900000,533.7775135001857],[1682658960000,522.5950688415487],[1682659020000,386.2247646353648],[1682659080000,289.5582848044634],[1682659140000,255.093055326594],[1682659200000,301.72496990673505],[1682659260000,268.5137052894264],[1682659320000,209.62464021632255],[1682659380000,154.51662197559196],[1682659440000,35.74179090903667],[1682659500000,0.3750076441702283],[1682659560000,0.5749999654486423],[1682659620000,0.4833326389800263],[1682659680000,0.6000003473608198],[1682659740000,0.5583334722777776],[1682659800000,0.3583328125530955],[1682659860000,0.2833344792750411],[1682659920000,0.05000180594684404]])

compare(ts_x, ts_y)

结果:
verySimi.png

不明显区分度

# 测试2 一般区分度 
ts_x = np.array([[1684142400000,0.004900725958518537],[1684142460000,0.004922043937969356],[1684142520000,0.004960918232336575],[1684142580000,0.005058410123264467],[1684142640000,0.005087717397816105],[1684142700000,0.005098378421433125],[1684142760000,0.0051021828906732125],[1684142820000,0.005035437505554685],[1684142880000,0.004963174013978611],[1684142940000,0.00483528276649936],[1684143000000,0.004708003485498047],[1684143060000,0.004543258314430032],[1684143120000,0.004368802831260399],[1684143180000,0.004305170108534817],[1684143240000,0.004287760497175719],[1684143300000,0.0043482042270891474],[1684143360000,0.004482151259800338],[1684143420000,0.0046167343763307],[1684143480000,0.004711138277918581],[1684143540000,0.004750985329534552],[1684143600000,0.0047351068827742315],[1684143660000,0.004686357648869932],[1684143720000,0.004663931326356008],[1684143780000,0.004660938182642793],[1684143840000,0.0046965282287447785],[1684143900000,0.00471875900993779],[1684143960000,0.004738158949539217],[1684144020000,0.0047408641544123276],[1684144080000,0.004766727752865685],[1684144140000,0.004778480171527266],[1684144200000,0.004768583335906462],[1684144260000,0.004817506707413544],[1684144320000,0.0047861764326061484],[1684144380000,0.004730843568752752],[1684144440000,0.004611429969401337],[1684144500000,0.004432913245822623],[1684144560000,0.004270825535747869],[1684144620000,0.004102742665797687],[1684144680000,0.004010885265347652],[1684144740000,0.0039457635198355545],[1684144800000,0.003938814632315379],[1684144860000,0.00402447023409036],[1684144920000,0.004161124952854256],[1684144980000,0.004334077719926666],[1684145040000,0.004507412451460913],[1684145100000,0.004677871628420149],[1684145160000,0.004818979890345743],[1684145220000,0.004936731380548509],[1684145280000,0.0050676786824582765],[1684145340000,0.005183837895480603],[1684145400000,0.005331445744112595],[1684145460000,0.005564821424961397],[1684145520000,0.00581424632513694],[1684145580000,0.006040605034726809],[1684145640000,0.006188493090849789],[1684145700000,0.006229405608337957],[1684145760000,0.0061583659832329385],[1684145820000,0.0059970613062201306],[1684145880000,0.005821272653661391],[1684145940000,0.0056678714470347336],[1684146000000,0.005591212593976769],[1684146060000,0.005589058943621383],[1684146120000,0.005616710742501585],[1684146180000,0.005656091421112008],[1684146240000,0.005615309463859575],[1684146300000,0.005541904650563589],[1684146360000,0.005392406282064055],[1684146420000,0.005177109981011174],[1684146480000,0.00496743943659439],[1684146540000,0.004741248869148396],[1684146600000,0.004571229262100185],[1684146660000,0.0044086300790265875],[1684146720000,0.004316458710150739],[1684146780000,0.004325066636218788],[1684146840000,0.004422280130746636],[1684146900000,0.004556450881951335],[1684146960000,0.004713264448932608],[1684147020000,0.004898379094811278],[1684147080000,0.005011945922171912],[1684147140000,0.005065271932055859],[1684147200000,0.005055845801622549],[1684147260000,0.005016241993479276],[1684147320000,0.004984851231933485],[1684147380000,0.004979735052210943],[1684147440000,0.005048347584800439],[1684147500000,0.005379527477017754],[1684147560000,0.006204008447417975],[1684147620000,0.0076726748249121846],[1684147680000,0.009706967566859626],[1684147740000,0.012133665627228729],[1684147800000,0.014658914689141267],[1684147860000,0.01687547453258398],[1684147920000,0.01867503652833169],[1684147980000,0.01966851743170328],[1684148040000,0.01981319218573141],[1684148100000,0.019253974274728303],[1684148160000,0.017964479248980814],[1684148220000,0.01619733854130423],[1684148280000,0.013976311633307259],[1684148340000,0.011606482748249825],[1684148400000,0.009341245834860179],[1684148460000,0.007324841103537483],[1684148520000,0.00591308509136157],[1684148580000,0.005104288343400043],[1684148640000,0.0047482280968130786],[1684148700000,0.004742203502123954],[1684148760000,0.0048787873758558975],[1684148820000,0.0050448580703050805],[1684148880000,0.005145478753084021],[1684148940000,0.005221141206120494],[1684149000000,0.005262224532118109],[1684149060000,0.00529036945278194],[1684149120000,0.005406007766640686],[1684149180000,0.005516651335436662],[1684149240000,0.005631431858358571],[1684149300000,0.005634023987767245],[1684149360000,0.005552681260693748],[1684149420000,0.0054384789577012205],[1684149480000,0.005289232682911926],[1684149540000,0.00520388639590641],[1684149600000,0.0054246642403067424],[1684149660000,0.006101365801179703],[1684149720000,0.0071631157892110275],[1684149780000,0.008571493536081443],[1684149840000,0.00998938592149301],[1684149900000,0.01116592271478134],[1684149960000,0.011806378270403983],[1684150020000,0.011682275750362958],[1684150080000,0.010909319356845804],[1684150140000,0.009647314061871026],[1684150200000,0.008280465369472911],[1684150260000,0.007083689842197316],[1684150320000,0.00617849459862152],[1684150380000,0.0056255725107076104],[1684150440000,0.005431332727125371],[1684150500000,0.0055105099664952695],[1684150560000,0.005729650871231673],[1684150620000,0.006042658904532261],[1684150680000,0.006354792565037126],[1684150740000,0.006694559027382807],[1684150800000,0.006920070618845808],[1684150860000,0.006969247522631172],[1684150920000,0.0069533132146326615],[1684150980000,0.006823167473044123],[1684151040000,0.0066620359802506135],[1684151100000,0.006467744591853286],[1684151160000,0.0063120152681334085],[1684151220000,0.006212972513118364],[1684151280000,0.006083728624819984],[1684151340000,0.00602294665620684],[1684151400000,0.005936331490658864],[1684151460000,0.005886692323208043],[1684151520000,0.0059084034536996954],[1684151580000,0.005931338367169858],[1684151640000,0.005983735314181504],[1684151700000,0.005995602390790333],[1684151760000,0.006098013848438],[1684151820000,0.006246662991210017],[1684151880000,0.006335094680732567],[1684151940000,0.006402006654715464],[1684152000000,0.006423645672711031],[1684152060000,0.006435233912266636],[1684152120000,0.0064370473321964106],[1684152180000,0.006437567930868693],[1684152240000,0.006516134197741108],[1684152300000,0.006543931090588595],[1684152360000,0.006519391170320299],[1684152420000,0.006444641423330011],[1684152480000,0.006239126084405799],[1684152540000,0.006055880995463947],[1684152600000,0.005849839046426775],[1684152660000,0.005757052557358366],[1684152720000,0.0057643990269227174],[1684152780000,0.00581148372231155],[1684152840000,0.005971962001960041],[1684152900000,0.006039852252704869],[1684152960000,0.006041547197728425],[1684153020000,0.0060400757365882685],[1684153080000,0.006050846410437183],[1684153140000,0.00612769628775689],[1684153200000,0.0062630034070374485],[1684153260000,0.006422044199365984],[1684153320000,0.0065931891608087545],[1684153380000,0.006907772871802442],[1684153440000,0.007277280717838841],[1684153500000,0.007727677482719186],[1684153560000,0.008251349735820868],[1684153620000,0.00873551405350792],[1684153680000,0.009274831913904102],[1684153740000,0.009635221833645513],[1684153800000,0.009917049353421192],[1684153860000,0.010080813570639169],[1684153920000,0.010099795025296343],[1684153980000,0.010153127432371845],[1684154040000,0.010104937962375105],[1684154100000,0.009909535475216114],[1684154160000,0.009504824544695367],[1684154220000,0.008951031450574187],[1684154280000,0.008256817999294452],[1684154340000,0.007520080023022513],[1684154400000,0.006841318612577085],[1684154460000,0.006281354833203134],[1684154520000,0.005906080596233654],[1684154580000,0.005728374823714688],[1684154640000,0.0056780855341880265],[1684154700000,0.005694896805279792],[1684154760000,0.005704848383808359],[1684154820000,0.005680893116271624],[1684154880000,0.0056405637441486745],[1684154940000,0.005510728369661266],[1684155000000,0.005439625648742785],[1684155060000,0.005422400625782142],[1684155120000,0.005501881204916237],[1684155180000,0.005698754135975093],[1684155240000,0.005959938283791599],[1684155300000,0.0062347147372247],[1684155360000,0.006369448475332717],[1684155420000,0.006365691234406556],[1684155480000,0.0061783844806623245],[1684155540000,0.005857004855179482],[1684155600000,0.005479493150070569],[1684155660000,0.005113579296455839],[1684155720000,0.004959372425254904],[1684155780000,0.005285896011705371],[1684155840000,0.00612503078163118],[1684155900000,0.00741645368223165],[1684155960000,0.008956592447043166],[1684156020000,0.010503416750545114],[1684156080000,0.01195682148600552],[1684156140000,0.013002253751149384],[1684156200000,0.013485417578221082],[1684156260000,0.013324035465088757],[1684156320000,0.01261056122709392],[1684156380000,0.011630793144808083],[1684156440000,0.010514514064400182],[1684156500000,0.009335816385962925],[1684156560000,0.008318058711043408],[1684156620000,0.007521376286166226],[1684156680000,0.0070652746799847455],[1684156740000,0.006892903220606872],[1684156800000,0.006799647725499014],[1684156860000,0.0067489147204093936],[1684156920000,0.006679212667524359],[1684156980000,0.0066613523794141205],[1684157040000,0.006614134560942397],[1684157100000,0.006583207249137413],[1684157160000,0.006560217487604159],[1684157220000,0.006538120111478363],[1684157280000,0.006526205407157093],[1684157340000,0.0064675825540285725],[1684157400000,0.006374867296410347],[1684157460000,0.0062061284978827125],[1684157520000,0.006060134376397852],[1684157580000,0.006028494661051487],[1684157640000,0.006116852568801456],[1684157700000,0.0063272712283963806],[1684157760000,0.006598698780666767],[1684157820000,0.006899227825485799],[1684157880000,0.007144478876370375],[1684157940000,0.00728548164352727],[1684158000000,0.007306942551220219],[1684158060000,0.007156549582141514],[1684158120000,0.006927407909538275],[1684158180000,0.006603709933958979],[1684158240000,0.006237715217158435],[1684158300000,0.005864730570119825],[1684158360000,0.005469490640543806],[1684158420000,0.005170228584278402],[1684158480000,0.004950062499204044],[1684158540000,0.00483287606889915],[1684158600000,0.0048103772214559415],[1684158660000,0.0047994195262547334],[1684158720000,0.004875642163458482],[1684158780000,0.0049977929166298285],[1684158840000,0.0051556224806798],[1684158900000,0.00535209788887725],[1684158960000,0.0055280194077818035],[1684159020000,0.005670443076822518],[1684159080000,0.005738594111867834],[1684159140000,0.005754271426655966],[1684159200000,0.005708051498998001],[1684159260000,0.005608185938720811],[1684159320000,0.0055342977575295604],[1684159380000,0.005475714231980899],[1684159440000,0.0054726742105226656],[1684159500000,0.005507374587879754],[1684159560000,0.005527989545304868],[1684159620000,0.005578759626211016],[1684159680000,0.005590589295799586],[1684159740000,0.005617104929469763],[1684159800000,0.005626262034869378],[1684159860000,0.005626086084114412],[1684159920000,0.0056795181382848225],[1684159980000,0.005704257165727533],[1684160040000,0.005752690670505989],[1684160100000,0.005798847266721641],[1684160160000,0.005798242150982902],[1684160220000,0.005811288997978337],[1684160280000,0.005796814763512459],[1684160340000,0.005739454518698062],[1684160400000,0.0056746101563055484],[1684160460000,0.005638184120607459],[1684160520000,0.005629264069230033],[1684160580000,0.005662340997874327],[1684160640000,0.005672516345190282],[1684160700000,0.005703791049816775],[1684160760000,0.005716631312589038],[1684160820000,0.005658058651098363],[1684160880000,0.0055916986419501935],[1684160940000,0.005425730107664228],[1684161000000,0.005250313099537829],[1684161060000,0.005089807173061622],[1684161120000,0.0049866676632122076],[1684161180000,0.004977238995763855],[1684161240000,0.005017794637936501],[1684161300000,0.005072349429560363],[1684161360000,0.00507983703332382],[1684161420000,0.005049211358418959],[1684161480000,0.00490074724985301],[1684161540000,0.004704899133929352],[1684161600000,0.004494770012036464],[1684161660000,0.004331600316035411],[1684161720000,0.004276826108993714],[1684161780000,0.004318433768794039],[1684161840000,0.004508835722412674],[1684161900000,0.004710454384365681],[1684161960000,0.004837408599054238],[1684162020000,0.004858682879055998],[1684162080000,0.004712715209822971],[1684162140000,0.004431398026779276],[1684162200000,0.0040594615978865045],[1684162260000,0.003633154588922105],[1684162320000,0.0032455359907118675],[1684162380000,0.00293501854461653],[1684162440000,0.0027570636939490134],[1684162500000,0.002683449141863359],[1684162560000,0.0026204308046167135],[1684162620000,0.002542782961082901],[1684162680000,0.0024261474314206666],[1684162740000,0.0022349397552436923],[1684162800000,0.0019855184154030647],[1684162860000,0.0016994347677995458],[1684162920000,0.0014446817166258175],[1684162980000,0.0012675657087105607],[1684163040000,0.0011790078967945927],[1684163100000,0.001176921635328454],[1684163160000,0.0012145709837827479],[1684163220000,0.0012653855604025654],[1684163280000,0.0012770842127123316],[1684163340000,0.0012744240945110619],[1684163400000,0.0012027040559527968],[1684163460000,0.0010690795577407153],[1684163520000,0.0009055788764191774],[1684163580000,0.0006897956962939045],[1684163640000,0.0004968154670033087],[1684163700000,0.0003069139148185185],[1684163760000,0.0001612663719525731],[1684163820000,0.00006490532427516627],[1684163880000,0.000004861730410143927],[1684163940000,0],[1684164000000,0]])
ts_y = np.array([[1684142400000,1797.0786516853918],[1684142460000,1686.6019417475734],[1684142520000,1972.7792915531331],[1684142580000,1782.9787234042565],[1684142640000,1722.208955223878],[1684142700000,3437.383177570078],[1684142760000,1658.850574712641],[1684142820000,1818.2275711159741],[1684142880000,1685.0377833753155],[1684142940000,1609.390862944162],[1684143000000,1743.3333333333323],[1684143060000,1662.8296703296696],[1684143120000,1744.1406249999993],[1684143180000,1959.541284403666],[1684143240000,1994.4836272040338],[1684143300000,1778.4967320261435],[1684143360000,1962.14463840399],[1684143420000,1814.12915851272],[1684143480000,1921.0958904109561],[1684143540000,1957.1212121212145],[1684143600000,1800.288624787774],[1684143660000,1905.5582524271824],[1684143720000,1834.8765432098758],[1684143780000,1753.9754098360668],[1684143840000,1884.2463235294113],[1684143900000,1818.1395348837214],[1684143960000,1877.2262773722632],[1684144020000,1968.478260869565],[1684144080000,1756.6037735849036],[1684144140000,2250.2087682672136],[1684144200000,1695.3846153846148],[1684144260000,1893.2000000000005],[1684144320000,1598.3471074380177],[1684144380000,1716.5931863727424],[1684144440000,1858.9261744966461],[1684144500000,1541.7901234567896],[1684144560000,1651.0805500982324],[1684144620000,1757.881548974944],[1684144680000,1635.7142857142853],[1684144740000,1718.0492813141655],[1684144800000,1661.8140243902433],[1684144860000,2162.837837837848],[1684144920000,1654.3333333333355],[1684144980000,1711.3476263399684],[1684145040000,1800.2608695652182],[1684145100000,1730.000000000001],[1684145160000,1719.0640394088675],[1684145220000,1754.7311827956955],[1684145280000,1750.2204724409462],[1684145340000,1942.0747663551408],[1684145400000,2043.820224719097],[1684145460000,1918.2149046793766],[1684145520000,1969.9456521739116],[1684145580000,1879.3951612903236],[1684145640000,1845.779661016949],[1684145700000,1961.1287758346564],[1684145760000,1831.41935483871],[1684145820000,1937.051724137929],[1684145880000,2029.1666666666579],[1684145940000,1886.7105263157878],[1684146000000,1790.6170886075947],[1684146060000,1970.7772020725401],[1684146120000,2318.32298136645],[1684146180000,1978.3999999999992],[1684146240000,1907.1269487750533],[1684146300000,1984.1686746987975],[1684146360000,1784.9827586206893],[1684146420000,1913.1955484896648],[1684146480000,1777.328],[1684146540000,2161.376404494384],[1684146600000,1835.9857142857165],[1684146660000,1858.0026281208927],[1684146720000,1899.6861626248212],[1684146780000,1922.5937031484227],[1684146840000,1674.0189445196193],[1684146900000,1763.9108910891082],[1684146960000,1880.7045009784738],[1684147020000,1843.8477801268455],[1684147080000,1787.7198211624432],[1684147140000,1781.7499999999975],[1684147200000,1828.3412322274862],[1684147260000,1733.614457831325],[1684147320000,1569.3188854489183],[1684147380000,1965.9445407279038],[1684147440000,1861.6607773851586],[1684147500000,1840.4238410596026],[1684147560000,1934.9999999999995],[1684147620000,1957.677725118484],[1684147680000,2241.261498028909],[1684147740000,2275.777777777771],[1684147800000,1964.1326530612268],[1684147860000,2364.445828144457],[1684147920000,1998.0575539568342],[1684147980000,2044.5054945054815],[1684148040000,2847.7763659466277],[1684148100000,2915.9722222222126],[1684148160000,1990.8092485549146],[1684148220000,3380.909090909099],[1684148280000,4882.432432432441],[1684148340000,4996.987951807211],[1684148400000,4956.813819577734],[1684148460000,10114.634146341443],[1684148520000,4796.183206106857],[1684148580000,3757.4753173483796],[1684148640000,4576.7973856209155],[1684148700000,3492.4731182795776],[1684148760000,3652.1551724137885],[1684148820000,2122.093023255801],[1684148880000,1708.4313725490183],[1684148940000,1780.898876404496],[1684149000000,1804.5714285714323],[1684149060000,1679.088098918082],[1684149120000,1701.4716981132042],[1684149180000,1656.241379310345],[1684149240000,1985.7187017001534],[1684149300000,1754.7862068965533],[1684149360000,1749.6015936254985],[1684149420000,1883.0515759312323],[1684149480000,1803.284574468086],[1684149540000,1812.5547445255445],[1684149600000,1890.994764397906],[1684149660000,1859.4104560622893],[1684149720000,1903.95378690629],[1684149780000,2036.1969111968956],[1684149840000,1950.3270223752138],[1684149900000,1893.6933797909396],[1684149960000,1695.7081545064375],[1684150020000,1913.7693631669506],[1684150080000,1881.993006993006],[1684150140000,2070.9424083769736],[1684150200000,1782.3203592814366],[1684150260000,1838.3606557377057],[1684150320000,1763.9661016949144],[1684150380000,1859.8338368580057],[1684150440000,1910.320855614972],[1684150500000,1980.0975609756103],[1684150560000,1759.4331983805669],[1684150620000,1971.276595744681],[1684150680000,1773.5254237288134],[1684150740000,1815.0161290322571],[1684150800000,1820.1627486437599],[1684150860000,1903.3505154639142],[1684150920000,1965.4265734265723],[1684150980000,1756.9079754601198],[1684151040000,1840.8345752608034],[1684151100000,1983.273905996757],[1684151160000,1925.3092783505153],[1684151220000,1908.604651162793],[1684151280000,1843.6071887034655],[1684151340000,1787.6822633297056],[1684151400000,1805.785234899329],[1684151460000,1860.202312138729],[1684151520000,2870.871143375676],[1684151580000,3121.2742980561516],[1684151640000,3327.3218142548585],[1684151700000,2778.5851780558273],[1684151760000,2795.159728944824],[1684151820000,2697.834158415847],[1684151880000,2841.3716814159293],[1684151940000,3076.4394829612183],[1684152000000,1378.7657430730487],[1684152060000,1381.5567765567762],[1684152120000,3033.734939759021],[1684152180000,4347.3509933774785],[1684152240000,5051.801801801774],[1684152300000,4100.322580645134],[1684152360000,1976.1247973767386],[1684152420000,1979.6071428571424],[1684152480000,1910.9078404401644],[1684152540000,1766.2827225130877],[1684152600000,1657.899842364081],[1684152660000,1830.4106468583077],[1684152720000,1784.2769230769213],[1684152780000,1779.3984962406014],[1684152840000,1953.583690987126],[1684152900000,1898.2544727070926],[1684152960000,2008.4889987064257],[1684153020000,2814.2079048843243],[1684153080000,2602.889148417723],[1684153140000,3180.644479432188],[1684153200000,3018.7361979204934],[1684153260000,2150.263975558962],[1684153320000,2077.1640144295625],[1684153380000,2187.7926836734514],[1684153440000,1952.181818181819],[1684153500000,1906.5979381443306],[1684153560000,1854.477611940299],[1684153620000,1982.8368794326248],[1684153680000,1936.9152542372883],[1684153740000,1842.6644182124787],[1684153800000,2057.1721311475285],[1684153860000,1930.3302509907521],[1684153920000,1991.5546218487402],[1684153980000,1874.9499545040942],[1684154040000,1841.875693673695],[1684154100000,1860.85889570552],[1684154160000,1827.5929752066118],[1684154220000,2642.58241758242],[1684154280000,1949.168704156479],[1684154340000,1885.8257713248631],[1684154400000,1936.5283018867901],[1684154460000,1841.707080504364],[1684154520000,1734.3518518518513],[1684154580000,1845.531914893616],[1684154640000,1856.636125654449],[1684154700000,1932.822429906544],[1684154760000,1802.0820189274452],[1684154820000,1744.559999999998],[1684154880000,1981.5044247787612],[1684154940000,1802.052980132451],[1684155000000,1963.751668891856],[1684155060000,2221.3963963963934],[1684155120000,1964.985955056179],[1684155180000,1814.299065420561],[1684155240000,1869.838709677419],[1684155300000,1827.6271186440674],[1684155360000,1905.6666666666677],[1684155420000,1746.677524429968],[1684155480000,1962.8813559322034],[1684155540000,1930.1845018450167],[1684155600000,1763.603034134007],[1684155660000,1806.207701283544],[1684155720000,1776.0456730769229],[1684155780000,1907.9721030042922],[1684155840000,1979.4346289752639],[1684155900000,1850],[1684155960000,2596.3251670378627],[1684156020000,1868.6101694915246],[1684156080000,1855.7101024890203],[1684156140000,2233.4886817576485],[1684156200000,1940.7702702702693],[1684156260000,3068.7763713080158],[1684156320000,2209.5444685466427],[1684156380000,2401.148851148847],[1684156440000,2110.0112485939153],[1684156500000,1801.420047732697],[1684156560000,1830.608365019011],[1684156620000,1864.3550624133138],[1684156680000,1779.4650205761318],[1684156740000,1791.6706161137427],[1684156800000,1854.9466192170814],[1684156860000,1687.9656160458464],[1684156920000,1968.3253588516736],[1684156980000,1764.858611825193],[1684157040000,1919.6932515337428],[1684157100000,1769.2094861660073],[1684157160000,1735.2030735455528],[1684157220000,1948.9361702127685],[1684157280000,1750.2443609022566],[1684157340000,1806.5100671140956],[1684157400000,1971.58463385354],[1684157460000,1795.0704225352108],[1684157520000,1764.2024965325922],[1684157580000,1874.3540183112905],[1684157640000,1890.6065088757414],[1684157700000,1919.3067590987848],[1684157760000,1740.9292502639917],[1684157820000,1883.8912133891235],[1684157880000,2247.024952015375],[1684157940000,1971.0535117056843],[1684158000000,1963.0633284241503],[1684158060000,2375.0000000000045],[1684158120000,2281.8991097922817],[1684158180000,2307.380952380962],[1684158240000,1841.62303664921],[1684158300000,1886.4006514657979],[1684158360000,1734.5123384253804],[1684158420000,1708.4269662921329],[1684158480000,1613.0898203592806],[1684158540000,1864.0845070422502],[1684158600000,1591.999999999999],[1684158660000,1826.4131994261124],[1684158720000,1605.6120826709066],[1684158780000,1669.6625421822282],[1684158840000,1731.3366336633708],[1684158900000,1797.1879483500682],[1684158960000,1825.505780346819],[1684159020000,1899.3865030674842],[1684159080000,1680.6249999999973],[1684159140000,1782.9172932330816],[1684159200000,1858.8267148014422],[1684159260000,1713.2421874999995],[1684159320000,1607.3873873873856],[1684159380000,1720.858725761773],[1684159440000,1588.7537993920976],[1684159500000,1650.7012195121938],[1684159560000,1662.8129205921946],[1684159620000,1708.826151560177],[1684159680000,1568.4615384615377],[1684159740000,1528.090322580645],[1684159800000,1731.8490967056314],[1684159860000,1601.6613418530362],[1684159920000,1518.2207578253679],[1684159980000,1396.5697674418586],[1684160040000,1623.604651162791],[1684160100000,1489.7496522948554],[1684160160000,1554.8637015781924],[1684160220000,1435.7885906040292],[1684160280000,1685.1741293532332],[1684160340000,1813.4756097560953],[1684160400000,1533.5937499999984],[1684160460000,1818.8415446071901],[1684160520000,1838.0295566502443],[1684160580000,1591.733021077283],[1684160640000,1396.7315175097287],[1684160700000,1357.4918918918893],[1684160760000,1597.197452229298],[1684160820000,1482.3979591836726],[1684160880000,1510.6538461538405],[1684160940000,1391.6493313521544],[1684161000000,1266.3421828908554],[1684161060000,1354.928848641655],[1684161120000,1388.2812499999955],[1684161180000,1549.1381668946628],[1684161240000,1552.0574162679409],[1684161300000,1196.1259079903136],[1684161360000,1234.6196660482337],[1684161420000,1315.2928647497326],[1684161480000,1396.98113207547],[1684161540000,1521.6216216216205],[1684161600000,1478.810289389074],[1684161660000,1438.6451612903177],[1684161720000,994.4959677419364],[1684161780000,978.4968684759922],[1684161840000,1606.6513056835638],[1684161900000,1597.032457496134],[1684161960000,1623.5437589670014],[1684162020000,1430.3545051698657],[1684162080000,869.6445497630334],[1684162140000,956.458885941644],[1684162200000,904.5634920634895],[1684162260000,836.3212435233139],[1684162320000,828.5777777777766],[1684162380000,783.8252340615243],[1684162440000,766.3223300970867],[1684162500000,3009.6874999999286],[1684162560000,1632.5087924970692],[1684162620000,1585.9181685338517],[1684162680000,1502.2391559202813],[1684162740000,1617.2050340849498],[1684162800000,1569.0939977349924],[1684162860000,1510.1306818181818],[1684162920000,1493.2784726793925],[1684162980000,1425.8500323206197],[1684163040000,584.0601503759393],[1684163100000,398.3973655323814],[1684163160000,389.6801346801341],[1684163220000,491.54566744730516],[1684163280000,371.4275256222553],[1684163340000,383.01547678482285],[1684163400000,436.19512195121996],[1684163460000,663.1407942238234],[1684163520000,855.6786366402918],[1684163580000,868.0652818991098],[1684163640000,830.8698777857647],[1684163700000,190.87328767123273],[1684163760000,177.98598130841094],[1684163820000,176.26115041525668],[1684163880000,158.09655396618976],[1684163940000,163.54401228249736],[1684164000000,154.67682363804215]])

compare(ts_x, ts_y)

结果:
lowSimi.png