2019 Eagles training camp third operation

warm up

  1. VMware Workstation v15.5.1 official installation package .
    Attach activation key: YZ718-4REEQ-08DHQ-JNYQC-ZQRD0

  2. Ubuntu installation tutorial reference: https://blog.csdn.net/qq1326702940/article/details/82322079
    VMware prompted to install the Linux operating system does not support 64-bit operating system solution: https://www.jb51.net/softjc /494576.html

    And after that I operate the two approaches, or tips do not support, and finally found the reason, because my computer does not have antivirus software installed, use the built-in Windows Security Center, the need to isolate kernel memory protection options which complete of closed, can solve the problem. FIG follows:
    1.PNG
    adjusting the window size of the virtual machine, need to install VMware Tools. Tool installation and set up shared folders tutorial below: https://blog.csdn.net/love20165104027/article/details/83377758

  3. Open gedit editor output type "hello world" in the C language code, named "helloworld" and ".c" suffix to save the format.

    2.PNG

    In the host file "helloworld.c" folder to open the terminal

    Compile command

    gcc -o helloworld helloworld.c

    Run the program command

    ./helloworld

    The results are as follows:

    3.PNG

new technology

Learn about new technology

散列:英文为"Hash",又名"哈希"。通过哈希算法,把任意长度的输入转换成固定长度的输出,其输出值为散列值。因为不同的输入值有可能会散列成相同的输出值,所以根据散列值不能确定唯一的输入值。正是由于哈希算法不能逆运算,往往被用于密码加密场景中。

Sketch:一种基于散列的数据结构。设置哈希函数,将数据经过哈希算法运算后相同的输出值放在同一个桶中,达到减少空间开销的目的。

其将数据流投射在一个小的存储空间内作为整个数据流的概要, 这个小空间存储的概要数据称为概要图。相比存储数据流所有元素信息,用 Sketch 概要图来保留整个数据流所有元素的概要信息将占用更少的计算和存储资源, 因此它更适合于大数据时代的数据流计算模式。

——引自《基于 Sketch 数据结构的海量网络流量实时排名系统》

Count Min Sketch:基于Sketch的代表算法之一,是一个次线性空间的数据结构,由二维数组构成。用到分类的思想:将具有相同哈希值的数据流归为一类,并使用同一个计数器计数。因为相同的哈希值有可能对应不同的数据流,会存在一定的误差。利用多重散列等技术来减小误差。

算法过程

  1. 创建一个宽为w,深为d的二维数组,每个元素对应一个计数器,初始化值为0。

  2. 每行都有一个互不相同哈希函数(hashi)对新来的元素进行哈希映射,将其映射到该行的某一个计数器中。

  3. 当t时刻,新元素(jt,ct)到达时,表项被更新,二维数组中的每一行分别用哈希函数计算出结果,再将映射的计数器加上ct

  4. 当所有数据流全部通过此表完成更新后, 就得到了最终的二维数组。选取最小的计数器值作为频数值。

    4.PNG

实现新技术

  1. 找到搜索结果第一个基于Python的 Count Min Sketch 项目

    项目地址: https://github.com/rafacarrascosa/countminsketch

  2. 先在windows系统下试一下

    用pip命令安装 countminsketch

     pip install countminsketch

    5.PNG

    参考Usage,根据要求编写python代码如下:

    6.PNG

    运行结果如下:

    7.PNG

    遇到的问题:

    ​ 错误提示:

    NameError: name 'xrange' is not defined

    ​ 解决方法:把"countminsketch.py"里的 xrange( )函数全部换为range( ) ,共3处。
    ​ 原因: 在Python 3中,range( )与xrange( )合并为range( )

    ​ 错误提示:

     Unicode-objects must be encoded before hashing 

    ​ 解决方法:在update( )里加" .encode("utf-8") "后缀,需改两处:

    8.png

    ​ 原因: update( )必须指定要加密的字符串的字符编码

  3. 在Linux上运行代码

    由于Ubuntu16.04版本系统自带Python2和Python3,但是默认是Python2。为避免python2与python3代码不兼容的问题出现,需在终端上执行以下命令把默认版本为python3。

    echo alias python=python3 >> ~/.bashrc
    source ~/.bashrc

    查看结果
    13.PNG

    遇到的问题1:
    11.PNG
    解决方法:打开 'test.txt' 时后面追加 'rb' ,只读打开一个二进制文件。
    参考:https://blog.csdn.net/a6864657/article/details/84797090

    Problems encountered 2:
    10.PNG
    Solution: str type of transfer bytes Type
    Reference: https://www.fujieace.com/python/str-bytes.html

    The revised Code:
    12.PNG

    On Linux platforms are as follows:
    9.PNG

Guess you like

Origin www.cnblogs.com/HE11/p/11921150.html