大数据量的过滤 (用于爬虫,蜘蛛) Bloom Filter 布隆过滤器

FPGA 调试笔记:用 ILA 抓取 10G/25G Ethernet IP 关键状态信号,快速定位 PMA 回环问题 本文详细介绍了如何使用Vivado的ILA工具抓取10G/25G以太网IP核的关键状态信号,快速定位PMA回环问题。通过分析链路锁定信号、控制信号、状态寄存器等核心信号组,结合ILA配置的黄金法则和典型故障波形解析,帮助FPGA开发者高效解决高速串行链路调试中的常见问题。 阅读详情

来自:http://www.cnblogs.com/lovebanyi/archive/2007/07/06/808736.html

原文:Bloom Filters in C#
http://www.devsource.com/article2/0,1895,2113495,00.asp


想像一下.如果你有一个非常大的无序的数据(url连接) 并且你要保证同样的一条连接不会在其它地方再次出现
你实时的收集哪些数据,你没有办法来预防两个相同的url出现,再不断增加的数据当中.

当这些数据是少的时候你可以轻松的创建一个list(dictonary or hashtable 或者你自已的数据结构)然后遍历它们,看它是不是已经存在在这个list当中,
遍历所花的时间是非常多的,
但是 当这些数据的长度超过可用的内存的时候? hashtable可以帮我加快速度,但是存...

上面的比较多的费话..看起来累 呦口继续不下去了.

得出的方案是用 bit数组来节省空间
a hash table capable of holding M items will take m/8 bytes of memory
接下来是实际的解决方法
net 里面有一个类 BitArray它可以帮我们很容易的创建出一个hashtable

创建一个简单的 HashingTable

public   class  SimpleHashTable
    
{
        
private BitArray hashbits = null;

        
public SimpleHashTable(int tableSize)
        
{
            hashbits 
= new BitArray(tableSize, false);
        }


        
public bool Test(string str)
        
{
            
int hash = Math.Abs(str.GetHashCode()) % hashbits.Count;
            
return hashbits[hash];
        }


        
public bool Add(string str)
        
{
            
int hash = Math.Abs(str.GetHashCode()) % hashbits.Count;
            
bool rslt = hashbits[hash];
            
if (!rslt)
                hashbits[hash] 
= true;
            
return rslt;
        }

    }


Add 里面没有这个值的时候是返回 false ,
Test 里面有值的话是返回 true;

  class  Program
    
{
        
static void Main(string[] args)
        
{
            
int urlsRead = 0;
            
int collisions = 0;

            SimpleHashTable hashTable 
= new SimpleHashTable(1000000);
            
using (StreamReader sr = new StreamReader("urls.txt"))
            
{
                
string url;
                
while ((url = sr.ReadLine()) != null)
                
{
                    urlsRead
++;
                    
bool rslt = hashTable.Add(url);
                    
if (rslt)
                        collisions
++;
                    
if ((urlsRead % 10000) == 0)
                    
{
                        Console.WriteLine(
"{0}  {1}  {2}%", 
                            urlsRead, collisions, 
100*
                                (
double)collisions / urlsRead);
                    }

                }

            }

            Console.WriteLine(
"{0} urls read", urlsRead);
            Console.WriteLine(
"{0} collisions", collisions);
            Console.WriteLine(
"False positive rate = {0}%", 
                
100*(double)collisions / urlsRead);
        }

    }

The output from that program, run against the 100,000 unique URLs in my file, is:

10000  44  0.44%
20000  187  0.935%
30000  423  1.41%
40000  753  1.8825%
50000  1200  2.4%
60000  1753  2.92166666666667%
70000  2375  3.39285714285714%
80000  3123  3.90375%
90000  3946  4.38444444444444%
100000  4834  4.834%
100000 urls read
4834 collisions
False positive rate = 4.834%
然后写了一个简单的测试类,我们可以看到它的碰撞(冲突)还是比较明显的
接下来就是如何继续去解决这样的问题

创建一个新的 Hash算法函数 HashString

hi(x) = (f1(x) + if2(x)) mod m

然后提供了一个 防止碰撞的结构. hashkeys 保存这个hash的三个位置

  public   class  BloomFilter
    
{
        
private BitArray hashbits;
        
private int numKeys;
        
private int[] hashKeys;

        
public BloomFilter(int tableSize, int nKeys)
        
{
            numKeys 
= nKeys;
            hashKeys 
= new int[numKeys];
            hashbits 
= new BitArray(tableSize);
        }


        
private int HashString(string s)
        
{
            
int hash = 0;

            
for (int i = 0; i < s.Length; i++)
            
{
                hash 
+= s[i];
                hash 
+= (hash << 10);
                hash 
^= (hash >> 6);
            }

            hash 
+= (hash << 3);
            hash 
^= (hash >> 11);
            hash 
+= (hash << 15);
            
return hash;
        }


        
private void CreateHashes(string str)
        
{
            
int hash1 = str.GetHashCode();
            
int hash2 = HashString(str);

            hashKeys[
0] = Math.Abs(hash1 % hashbits.Count);
            
if (numKeys > 1)
            
{
                
for (int i = 1; i < numKeys; i++)
                
{
                    hashKeys[i] 
= Math.Abs((hash1 + (i * hash2))
                        
% hashbits.Count);
                }

            }

        }


        
public bool Test(string str)
        
{
            CreateHashes(str);
            
// Test each hash key.  Return false if any 
            
//  one of the bits is not set.
            foreach (int hash in hashKeys)
            
{
                
if (!hashbits[hash])
                    
return false;
            }

            
// All bits set.  The item is there.
            return true;
        }


        
public bool Add(string str)
        
{
            
// Initially assume that the item is in the table
            bool rslt = true;
            CreateHashes(str);
            
foreach (int hash in hashKeys)
            
{
                
if (!hashbits[hash])
                
{
                    
// One of the bits wasn't set, so show that
                    
// the item wasn't in the table, and set that bit.
                    rslt = false;
                    hashbits[hash] 
= true;
                }

            }

            
return rslt;
        }

    }

测试:

  class  Program
    
{
        
static void Main(string[] args)
        
{
            
int urlsRead = 0;
            
int hashCollisions = 0;
            
int bloomCollisions = 0;

            SimpleHashTable hashTable 
= new SimpleHashTable(1000000);
            BloomFilter bloom 
= new BloomFilter(480833, 3);

            
using (StreamReader sr = new StreamReader("urls.txt"))
            
{
                
string url;
                
while ((url = sr.ReadLine()) != null)
                
{
                    urlsRead
++;
                    
bool rslt = hashTable.Add(url);
                    
if (rslt)
                        hashCollisions
++;
                    rslt 
= bloom.Add(url);
                    
if (rslt)
                        bloomCollisions
++;

                    
if ((urlsRead % 10000) == 0)
                    
{
                        Console.WriteLine(
"{0}  {1}  {2}%  {3}  {4}%", urlsRead, 
                            hashCollisions, 
100*(double)hashCollisions / urlsRead,
                            bloomCollisions, 
100*(double)bloomCollisions / urlsRead);
                    }

                }

            }

            Console.WriteLine(
"{0} urls read", urlsRead);
            Console.WriteLine(
"{0} hash collisions", hashCollisions);
            Console.WriteLine(
"False positive rate (hash) = {0}%", 
                
100*(double)hashCollisions / urlsRead);
            Console.WriteLine(
"{0} Bloom collisions", bloomCollisions);
            Console.WriteLine(
"False positive rate (Bloom) = {0}%",
                
100*(double)bloomCollisions / urlsRead);
        }

    }

10000  44  0.44%  1  0.01%
20000  187  0.935%  10  0.05%
30000  423  1.41%  38  0.126666666666667%
40000  753  1.8825%  118  0.295%
50000  1200  2.4%  262  0.524%
60000  1753  2.92166666666667%  517  0.861666666666667%
70000  2375  3.39285714285714%  866  1.23714285714286%
80000  3123  3.90375%  1352  1.69%
90000  3946  4.38444444444444%  2118  2.35333333333333%
100000  4834  4.834%  2966  2.966%
100000 urls read
4834 hash collisions
False positive rate (hash) = 4.834%
2966 Bloom collisions
False positive rate (Bloom) = 2.966% 

在添加数据的时候.他会判断前面这个位置是否有一个地址存了.如果有的话.它就存第二个. 如果都被存光了..哪就发生碰撞了
实际总的容量是有限的.
还有泛型和它的例子

public   abstract   class  BloomFilter
{
    
private BitArray hashbits;
    
private int numKeys;
    
protected int[] hashKeys;

    
public BloomFilter(int tableSize, int nKeys)
    
{
        numKeys 
= nKeys;
        hashKeys 
= new int[numKeys];
        hashbits 
= new BitArray(tableSize);
    }


    
public bool Test(TValue val)
    
{
        CreateHashes(val);
        
// Test each hash key.  Return false 
        
//  if any one of the bits is not set.
        foreach (int hash in hashKeys)
        
{
            
if (!hashbits[hash])
                
return false;
        }

        
// All bits set.  The item is there.
        return true;
    }


    
public bool Add(TValue val)
    
{
        
// Initially assume that the item is in the table
        bool rslt = true;
        CreateHashes(val);
        
foreach (int hash in hashKeys)
        
{
            
if (!hashbits[hash])
            
{
                
// One of the bits wasn't set, so show that
                
// the item wasn't in the table, and set that bit.
                rslt = false;
                hashbits[hash] 
= true;
            }

        }

        
return rslt;
    }


    
protected virtual void CreateHashes(TValue val)
    
{
        
int hash1 = CreateHash1(val);
        
int hash2 = CreateHash2(val);

        hashKeys[
0] = Math.Abs(hash1 % hashbits.Count);
        
if (numKeys > 1)
        
{
            
for (int i = 1; i < numKeys; i++)
            
{
                hashKeys[i] 
= Math.Abs((hash1 + (i * hash2)) %
                    hashbits.Count);
            }

        }

    }


    
protected abstract int CreateHash1(TValue val);

    
protected abstract int CreateHash2(TValue val);
}


 

class  StringBloomFilter : BloomFilter
{
    
public StringBloomFilter(int tableSize, int nKeys)
        : 
base(tableSize, nKeys)
    
{
    }


    
protected override int CreateHash1(string val)
    
{
        
return val.GetHashCode();
    }


    
protected override int CreateHash2(string val)
    
{
        
int hash = 0;

        
for (int i = 0; i < val.Length; i++)
        
{
            hash 
+= val[i];
            hash 
+= (hash << 10);
            hash 
^= (hash >> 6);
        }

        hash 
+= (hash << 3);
        hash 
^= (hash >> 11);
        hash 
+= (hash << 15);
        
return hash;
    }

}


让我们的蜘蛛跑得更快吧
Google 数学之美哪边也介绍到了.
http://googlechinablog.com/2007/07/bloom-filter.html


STM32H7的CAN1和CAN2的寄存器配置 首先,我们需要在STM32CubeMX中配置CAN1和CAN2接口。选择适当的STM32H7型号,然后在"Pinout & Configuration"选项卡中找到CAN1和CAN2接口引脚,并将它们分配给合适的GPIO引脚。本文将介绍如何配置STM32H7的CAN1和CAN2的寄存器,以实现CAN通信功能。通过以上步骤,您可以成功配置置STM32H7的CAN1和CAN2寄存器,以实现CAN通信功能。请根据您的具体需求修改代码中的参数和功能。函数中进行CAN1和CAN2的寄存器配置。 阅读详情

相关推荐

STM32H7,FDCAN与CAN兼容完整工程

工程由CUBEMX创建,具体的引脚配置等相关信息可以直接用CUBEMX打开查看。

STM32H7 FDCAN兼容普通CAN使用 基于CubeMX配置

STM32大多数型号均使用的是bxCAN这个IP核,该IP核工作非常稳定,以至于从STM32F1系列到STM32F7系列均使用此IP核。下列两张图分别为STM32F1C8Tx系列和STM32F767IITx的CAN配置界面。可以看到配置界面的选项完全相同。 bxCAN的配置例程非常多,应用广泛。FDCAN是2011年博世发布的改进版CAN,FDCAN的性能固然强悍,但是在实际项目中若是多个板之间通信的情况,难免需要让FDCAN兼容CAN通信。本文皆在介绍如何通过CubeMX配置FDCAN使之兼

Fairchild_1947的博客 2万+

极空间NAS零基础部署Wiki.js:Docker+PostgreSQL全流程避坑指南

本文提供了一份在极空间NAS上从零部署Wiki.js私有知识库的详细指南。通过Docker容器化技术,结合PostgreSQL数据库,手把手讲解环境准备、核心组件配置、性能优化及安全加固等全流程,并特别针对极空间平台特性提供了避坑要点,帮助用户打造安全、高效、自主可控的知识管理系统。

3a9bq4r8t2y的博客 483

STM32H743 FDCAN 发送管理分析(HAL库)

MCU:H743野火挑战者 其他文章: STM32H743 FDCAN通信 接收中断如何实现 如何计算并设置CAN外设的波特率(基于STM32H7和HAL库) STM32H743 FDCAN FIFO发送管理分析 前言 在CAN专属的消息RAM中,存在32个TX缓冲区,32个TX事件FIFO。每个里面都存在1个元素,一共有64个元素,对应64个报文。 TX缓冲区 每一个TX缓冲区可以配置一个ID,即对应一个报文。缓冲区内不仅仅只有报文的内容,还有报文的类型、ID等相关信息,官方定义这样一个整体叫ele.

wuwenbin12的博客 1万+

基于QT的华为网络摄像头二次开发

第一次使用华为的网络摄像头并进行二次开发,网上关于QT对华为网络摄像头的二次开发的文章很少,基于项目的需求做了一些工作,特此记录。 目标: 1、实时预览 2、手动控制录制视频 3、监听告警型号 4、实时获取元数据中的划定区域内的人数 摄像头型号如下: 准备工作: 在购买摄像头后,应当在官网下载对应的开发资料,如果需要权限,则联系华为的技术支持人员。下载资料如下: SDC Development Kit Demo 8.0.T9 SDK DEMO下载地址:https://bbs.hua

xumingyifrend的博客 3168

30分钟搭建AI科研写作工作台:基于WorkBuddy的论文全流程加速实践

在人工智能技术日益普及的今天,如何利用智能工具提升专业领域工作效率成为关键课题。其核心原理在于通过模块化设计,将复杂的任务流程拆解为可复用、可编排的标准化技能单元,并结合精准的指令控制,实现从通用对话到深度任务执行的转变。这一技术价值在于显著降低重复性劳动强度,将人的创造力聚焦于核心决策与创新环节。在科研写作、数据分析、代码开发等场景中,这类智能工作台能有效辅助完成文献调研、内容生成、格式校验等繁琐步骤。本文以科研论文写作为具体应用场景,深入探讨如何利用WorkBuddy这一智能工作台,通过配置核心科研技能

weixin_29032489的博客 1442

Bloom-Filter算法

<br />一、 Bloom-Filter算法简介。<br /> Bloom-Filter,即布隆过滤 器,1970年由Bloom中提出。它可以用于检索一个元素是否在一个集合中,其优点是空间效率和查询时间都远远超过其他算法,其不足在于Bloom- Filter存在着误判。<br /><br />二、 Bloom-Filter的基本思想。<br /> Bloom-Filter算法的核心思想就是利用 多个不同的Hash函数来解决“冲突”。<br /> 计算某元素x是否在一个集合中,首先能想到的方法就

tattarrattat的专栏 2656

大模型部署之二--vllm+docker部署

本文介绍了在openEuler系统上快速本地部署Qwen3-8B、DeepSeek-R1、Qwen2.5deng 大模型的完整流程。通过modelscope管理模型,采用vllm+docker模式实现部署。主要步骤包括:1)安装conda环境;2)配置docker;3)下载模型;4)编写docker compose配置文件;5)启动服务。特别针对2卡4090服务器提供了参数配置建议,并给出常用命令和参考资料。文档还提示不同系统和平台可能存在差异,为开发者提供了本地部署大型语言模型的实用指南。

weixin_39279863的博客 1133

bloom filter 的Java 版

转载文章 感谢原作者的无私奉献 一、 Bloom-Filter算法简介。         Bloom-Filter,即布隆过滤器,1970年由Bloom中提出。它可以用于检索一个元素是否在一个集合中,其优点是空间效率和查询时间都远远超过其他算法,其不足在于Bloom- Filter存在着误判。  二、 Bloom-Filter的基本思想。        Bloom-Filter

曲线救己的fighter 921

ROC-RK3588S-PC 刷机 安装Android系统

rk3588刷机,装系统

Wjz_www的博客 4826

FANUC机器人RSR与PNS功能深度解析及实战应用指南

本文深度解析了FANUC机器人RSR(远程程序启动)与PNS(程序号选择)两大核心功能。文章详细阐述了RSR的队列执行机制与PNS的二进制编码原理,提供了从硬件连接到参数配置的完整实战指南,并分享了混合使用策略与常见故障排除方法,旨在帮助工程师实现高效、稳定的生产线自动化程序调度。

neovim7hacker的博客 307

关于布隆过滤器(Bloom-Filter)的理解

简介: Bloom-Filter,即布隆过滤器,1970年由Bloom中提出。它可以用于检索一个元素是否在一个集合中,其优点是空间效率和查询时间都远远超过其他算法,其不足在于Bloom- Filter存在着误判。 因此, Bloom Filter 不适合那些“零错误”的应用场合。而在能容忍低错误率的应用场合下, Bloom Filter 通过极少的错误换取了存储空间的极大节省。 

zjm750617105的专栏 1371

【AHE数据集】历史/未来全球网格热排放数据 PF-AHF

AHE数据集

WW、forever的博客 127

Bloom Filter 布隆算法;

一、 Bloom-Filter算法简介。 Bloom-Filter,即布隆过滤器,1970年由Bloom中提出。它可以用于检索一个元素是否在一个集合中,其优点是空间效率和查询时间都远远超过其他算法,其不足在于Bloom- Filter存在着误判。 二、 Bloom-Filter的基本思想。 Bloom-Filter算法的核心思想就是利用多个不同的Hash函数来解决“冲突”。 计算某

面朝阳光,心向大海 的专栏 1325

NVIDIA Isaac ROS - 入门教程(一)

欢迎访问 Isaac ROS,这是一套硬件加速、高性能、低延迟的 ROS 2 软件包,用于制造自主机器人,充分利用 Jetson 和其他英伟达平台的强大功能。英伟达 Jetson 平台运行在基于 Ubuntu Linux 的 JetPack 操作系统上。JetPack 5.x 是在 Ubuntu 20.04 Focal 的基础上构建的,这意味着由 ROS 2 Buildfarm 为 Ubuntu 22.04 Jammy 构建的 ROS 2 Humble 的 Debian 包不受支持。由于官方 ROS 2 B

机器人控制与仿真应用 5721

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Bloom Filter算法

<?php /*Bloom Filter算法来去重过滤。 介绍下Bloom Filter的基本处理思路:申请一批空间用于保存0 1信息,再根据一批哈希函数确定元素对应的位置,如果每个哈希函数对应位置的值为全部1,说明此元素存在。相反,如果为0,则要把对应位置的值设置为1。由于不同的元素可能会有相同的哈希值,即同一个位置有可能保存了多个元素的信息,从而导致存在一定的误判率。 如果申请空间太小

576

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Java版本bloom filter<转>

属于转贴 一、 Bloom-Filter算法简介。         Bloom-Filter,即布隆过滤器,1970年由Bloom中提出。它可以用于检索一个元素是否在一个集合中,其优点是空间效率和查询时间都远远超过其他算法,其不足在于Bloom- Filter存在着误判。  二、 Bloom-Filter的基本思想。        Bloom-Filter算法的核心思想就是利用多个

yongjian_luo的专栏 673

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

上一篇: C#多线程参数传递
下一篇: 创建触发器时提示错误信息:不能在 'inserted' 表和 'deleted' 表中使用 text、ntext 或 image 列
ArvinStudy
博客等级 码龄15年 83粉丝 193原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值