SGISTL源码探究-关联式容器:hash_set

细节增强卷积DEConv详解及代码复现 这种预训练模型能够捕捉图像的基本特征,为后续的端到端训练提供良好的初始参数。例如,在RESIDE和RESIDE-6K数据集上的实验结果表明,使用MSPLCK模块的MixDehazeNet-L模型在RESIDE-IN数据集上首次超过了42dB的PSNR指标,且在所有数据集上均优于先前的方法。例如,在RESIDE和RESIDE-6K数据集上的实验结果表明,使用MSPLCK模块的MixDehazeNet-L模型在RESIDE-IN数据集上首次超过了42dB的PSNR指标,且在所有数据集上均优于先前的方法。 阅读详情

前言

在上小节中,我们已经分析了hashtable的实现,它只是hash_set和hash_map的预备知识。在本小节中,我们将进入到关联式容器hash_set的源码中,一窥究竟。

hash_set的实现

由于hash_set并没有自己定义的迭代器,所以接下来我们先对它的定义部分以及数据结构进行分析,然后是它的构造函数以及常用操作等。

定义部分及数据结构
#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class Value, class HashFcn = hash<Value>,
          class EqualKey = equal_to<Value>,
          class Alloc = alloc>
#else
template <class Value, class HashFcn, class EqualKey, class Alloc = alloc>
#endif
class hash_set
{
private:
  //hash_set内部的hashtable成员变量rep
  typedef hashtable<Value, Value, HashFcn, identity<Value>,
                    EqualKey, Alloc> ht;
  ht rep;

public:
  //定义的别名部分
  typedef typename ht::key_type key_type;
  typedef typename ht::value_type value_type;
  typedef typename ht::hasher hasher;
  typedef typename ht::key_equal key_equal;

  typedef typename ht::size_type size_type;
  typedef typename ht::difference_type difference_type;
  typedef typename ht::const_pointer pointer;
  typedef typename ht::const_pointer const_pointer;
  typedef typename ht::const_reference reference;
  typedef typename ht::const_reference const_reference;

  //迭代器是const的,代表不能通过迭代器修改hash_set的值,这个和set类似
  typedef typename ht::const_iterator iterator;
  typedef typename ht::const_iterator const_iterator;

  //通过hashtable取得哈希函数对象还有比较key的函数对象
  hasher hash_funct() const { return rep.hash_funct(); }
  key_equal key_eq() const { return rep.key_eq(); }
构造函数
public:
  //默认大小为100个bucket,但是传进去后会被调整,所以实际上比100更大
  hash_set() : rep(100, hasher(), key_equal()) {}
  //禁止隐式转换,传入n,指定大小,其余的取默认值
  explicit hash_set(size_type n) : rep(n, hasher(), key_equal()) {}
  //指定大小n以及哈希函数,其余取默认值
  hash_set(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
  //指定大小n及哈希函数还有比较key的大小的函数
  hash_set(size_type n, const hasher& hf, const key_equal& eql)
    : rep(n, hf, eql) {}

  /* 下面传入迭代器进行构造
   * 重载了很多版本,这里就不一一细讲了
   * 因为里面的实现都是调用hashtable中的insert_unique函数进行插入
   */
#ifdef __STL_MEMBER_TEMPLATES
  template <class InputIterator>
  hash_set(InputIterator f, InputIterator l)
    : rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
  template <class InputIterator>
  hash_set(InputIterator f, InputIterator l, size_type n)
    : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
  template <class InputIterator>
  hash_set(InputIterator f, InputIterator l, size_type n,
           const hasher& hf)
    : rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
  template <class InputIterator>
  hash_set(InputIterator f, InputIterator l, size_type n,
           const hasher& hf, const key_equal& eql)
    : rep(n, hf, eql) { rep.insert_unique(f, l); }
#else

  hash_set(const value_type* f, const value_type* l)
    : rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
  hash_set(const value_type* f, const value_type* l, size_type n)
    : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
  hash_set(const value_type* f, const value_type* l, size_type n,
           const hasher& hf)
    : rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
  hash_set(const value_type* f, const value_type* l, size_type n,
           const hasher& hf, const key_equal& eql)
    : rep(n, hf, eql) { rep.insert_unique(f, l); }

  hash_set(const_iterator f, const_iterator l)
    : rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
  hash_set(const_iterator f, const_iterator l, size_type n)
    : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
  hash_set(const_iterator f, const_iterator l, size_type n,
           const hasher& hf)
    : rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
  hash_set(const_iterator f, const_iterator l, size_type n,
           const hasher& hf, const key_equal& eql)
    : rep(n, hf, eql) { rep.insert_unique(f, l); }
#endif /*__STL_MEMBER_TEMPLATES */
常用操作
public:
  //返回大小,调用hashtable提供的函数
  size_type size() const { return rep.size(); }
  size_type max_size() const { return rep.max_size(); }
  //判空,若为空返回true,还是调用的hashtable提供的函数
  bool empty() const { return rep.empty(); }
  //交换
  void swap(hash_set& hs) { rep.swap(hs.rep); }
  friend bool operator== __STL_NULL_TMPL_ARGS (const hash_set&,
                                               const hash_set&);

  //调用hashtable提供的begin和end
  iterator begin() const { return rep.begin(); }
  iterator end() const { return rep.end(); }

public:
  /* 插入元素
   * 调用hashtable提供的插入操作
   * 然后返回一个pair, 第一个元素指向插入的元素,第二个元素代表插入是否成功
   */
  pair<iterator, bool> insert(const value_type& obj)
    {
      pair<typename ht::iterator, bool> p = rep.insert_unique(obj);
      return pair<iterator, bool>(p.first, p.second);
    }
  /* 范围插入,转而调用hashtable提供的insert_unique */
#ifdef __STL_MEMBER_TEMPLATES
  template <class InputIterator>
  void insert(InputIterator f, InputIterator l) { rep.insert_unique(f,l); }
#else
  void insert(const value_type* f, const value_type* l) {
    rep.insert_unique(f,l);
  }
  void insert(const_iterator f, const_iterator l) {rep.insert_unique(f, l); }
#endif /*__STL_MEMBER_TEMPLATES */
  pair<iterator, bool> insert_noresize(const value_type& obj)
  {
    pair<typename ht::iterator, bool> p = rep.insert_unique_noresize(obj);
    return pair<iterator, bool>(p.first, p.second);
  }
  //查找为key的元素,并返回指向其的迭代器
  iterator find(const key_type& key) const { return rep.find(key); }

  //计算为key的元素个数
  size_type count(const key_type& key) const { return rep.count(key); }

  pair<iterator, iterator> equal_range(const key_type& key) const
    { return rep.equal_range(key); }

  /* 删除操作,也是调用的hashtable提供的函数 */
  size_type erase(const key_type& key) {return rep.erase(key); }
  void erase(iterator it) { rep.erase(it); }
  void erase(iterator f, iterator l) { rep.erase(f, l); }
  //清除函数
  void clear() { rep.clear(); }

public:
  //重建操作
  void resize(size_type hint) { rep.resize(hint); }
  //返回bucket的个数
  size_type bucket_count() const { return rep.bucket_count(); }
  size_type max_bucket_count() const { return rep.max_bucket_count(); }
  //返回对应bucket的节点个数
  size_type elems_in_bucket(size_type n) const
    { return rep.elems_in_bucket(n); }
};

//重载==操作符,其实也是调用的hashtable中重载的==操作符
template <class Value, class HashFcn, class EqualKey, class Alloc>
inline bool operator==(const hash_set<Value, HashFcn, EqualKey, Alloc>& hs1,
                       const hash_set<Value, HashFcn, EqualKey, Alloc>& hs2)
{
  return hs1.rep == hs2.rep;
}

#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER

template <class Val, class HashFcn, class EqualKey, class Alloc>
inline void swap(hash_set<Val, HashFcn, EqualKey, Alloc>& hs1,
                 hash_set<Val, HashFcn, EqualKey, Alloc>& hs2) {
  hs1.swap(hs2);
}

#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */

小结

本小节我们对hash_set容器的实现进行了分析,可以发现它和红黑树以及set之间的关系很类似,都是底层实现了之后,set或hash_set实现时,基本上都是转而调用底层提供的接口,并且都不能通过迭代器修改值。要说set和hash_set的区别,因为底层的实现不同,所以set支持自动排序,但是hash_set不支持自动排序。
在下一节中,我们将对hash_map的实现进行分析。

0.嵌入式控制器EC实战 Embedded Controller开发概述 文章目录前言1.嵌入式控制器EC概述2.EC芯片框图(IT8502为例)3.General Purpose I/O Port (GPIO)4.SMBus(System Management Bus,系统管理总线)5.PWM、TACH6.KBC(KeyBoard Controller)7.PS/28.ADC(模数转换)总结 前言 例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。 1.嵌入式控制器EC概述 嵌入式控制器EC是挂在CPU的L 阅读详情

相关推荐

微信小程序网关逆向分析:从协议、签名到会话管理的安全架构剖析

在现代Web与移动应用开发中,API网关作为客户端与后端服务之间的关键通信枢纽,承担着协议转换、流量调度、安全防护与性能优化等核心职责。其工作原理通常涉及统一的请求路由、身份认证、参数校验与响应聚合。从技术价值看,深入理解网关机制不仅能帮助开发者构建更健壮、可扩展的微服务架构,还能为安全评估、性能调优与故障排查提供基础。在移动生态如微信小程序中,网关设计尤为关键,它需要处理微信特有的登录态、数据加密与防重放攻击等安全需求。本文聚焦于微信小程序网关的逆向分析方法,通过结合网络抓包与代码反编译技术,深入解析其通

weixin_29323493的博客 442

SGISTL源码阅读 map与hash_map之间的区别

SGISTL源码阅读 map与hash_map之间的区别 前言 之前我们已经学习过了这两种关联式容器,他们可以用来存放键值对,并且不可存放重复键值(因为内部调用了insert_unique),他们所提供的很多插入删除方法也是非常类似的。现在我们来分析一下他们之间的区别。 我们知道map的底层容器是红黑树,hash_map的底层是hashtable,所以他们之间的区别主要是由他们底层的容器来带的,...

Lyn&Xx 385

一张图看懂中国民航适航审定体系:从适航司到审定中心,到底谁管谁?

本文深入解析中国民航适航审定体系,从立法层到执行层的完整链条,揭示适航管理的金字塔结构和核心流程。涵盖适航司、审定中心等关键机构职能,以及型号审定、生产许可审定等全生命周期管理,展现中国适航体系的特色实践与创新探索。

weixin_30896511的博客 475

SGISTL源码探究-STL中的hashtable(上)

前言关于哈希表部分,哈希函数以及解决哈希冲突的方法都有很多种,在本文中不会详细去讨论哈希表的大量知识,而是以SGISTL实现的hashtable为主,所以如果对hashtable不太了解,建议先去网上查阅相关的资料。这里只给出基本的概念。了解哈希表原理基本概念哈希表(hashtable,也称散列表):根据key来访问元素的一种数据结构。它可能先经过哈希函数计算出key,然后通过key访问表中对应ke

Move_now的博客 1483

SWIPT技术(无线通信携能技术)的简介与架构——(后续补充无人机SWIPT方向)

SWIPT一、SWIPT(无线通信携能)技术简介1.1、组成:1.2、与传统无线通信的区别:1.3、SWIPT 的集成接收器架构设计1、单独的接收器2、TS架构——时间开关(Time switching,TS)3、PS架构——功率分流(Power splitting,PS)4、天线开关接收器主要两种架构的区别参考文献SWIPT的发展 一、SWIPT(无线通信携能)技术简介 SWIPT(Simultaneous Wireless Information and Power Transfer )是各种WPT技术

Blue 1万+

Windows 11 IoT企业版LTSC 24H2/25H2中文版安装指南(含OEM激活教程)

本文详细介绍了Windows 11 IoT企业版LTSC 24H2/25H2中文版的安装与OEM激活全流程。从系统镜像准备、硬件兼容性检查到自动化安装配置,再到OEM激活方案(包括SLIC注入和数字许可证激活),为工业自动化、数字标牌等物联网设备提供稳定可靠的系统部署指南。

weixin_29198045的博客 8831

stl源码剖析 详细学习笔记 hashset hashmap

//---------------------------15/03/26---------------------------- //hash_set {     /*         hash_set概述:         1:这是一个hash版本的set,RB_tree版本的set有自动排序功能,         而hash_set没有这个功能。    

boydfd的专栏 1807

systrace分析 之 问题初步定位

如下surfaceflinger空缺点,上面对应的bufferTX 中有buffer,但VSYNC-SF 过来后,SurfaceFlinger却没有去取,检查测试app “android.settings”, 也没有GPU completion 时间长的问题,所以该部分可以请SurfaceFlinger的owner 进一步确认为何不取buffer。. GPU拿的是acquireFence HWC拿的是releaseFence, GPU是绘图,HWC是合成显示,这两个是互相等待的关系,

yangzex的专栏 3195

SGISTL源码阅读二十四 hash_set 关联式容器

SGISTL源码阅读二十四 hash_set 关联式容器 前言 前面我们已经分析了set和hashtable,set的底层容器是红黑树,而接下来我们要分析的hash_set,是底层为hashtable的集合。 深入源码 hash_set的定义部分 #ifndef __STL_LIMITED_DEFAULT_TEMPLATES template &lt;class Value, class Has...

Lyn&Xx 207

Python爬虫获取Shopee店铺的所有商品?

通过上述代码示例,我们可以轻松实现获取Shopee店铺所有商品信息的功能。Python爬虫不仅具有强大的功能和稳定性,还可以通过丰富的库支持实现高效的数据抓取和解析。希望这篇文章能为你提供一些启发和帮助。如果你对爬虫开发有更多兴趣,可以尝试探索更复杂的功能,如多线程爬取、数据可视化等。如果你在实践中遇到任何问题,欢迎随时交流和讨论。让我们一起用技术的力量,解锁更多可能!

2401_87195067的博客 1543

【无人机基站】基于K-mean算法实现无人机基站部署附matlab代码

【无人机基站】基于K-mean算法实现无人机基站部署附matlab代码

天天酷科研的博客 243

STL源码剖析 - 第5章 关联式容器 - hash_set

5.8 hash_set    hash_set以hashtable为底层机制。和set类似,hast_set的键值就是实值,实值就是键值,但是不同点是hash_set容器中的元素是没有排序的,因为hash table没有提供排序功能。hash_set的使用方式与set完全相同。本文源码出自SGISTL的文件。 hash_set容器源码剖析 #ifndef __SGI_STL_INTERNA

灯火阑珊处 532

使用 MATLAB/Simulink + Reinforcement Learning Toolbox 构建一个基于强化学习的永磁同步电机(PMSM)自适应控制仿真系统

随着人工智能(AI)技术的快速发展,强化学习(Reinforcement Learning, RL)在控制系统中的应用日益广泛。在电机控制领域,传统的PID控制虽然成熟稳定,但在面对非线性、时变、不确定负载等复杂工况时,其控制性能可能受限。而强化学习通过与环境的交互学习,能够实现在线自适应控制策略优化,显著提升系统的鲁棒性与响应速度。本教程将带你使用构建一个基于强化学习的永磁同步电机(PMSM)自适应控制仿真系统,实现从控制策略设计、环境建模、训练到仿真的全过程。当前转速(ω)

amy_mhd的博客 407

SGISTL源码探究-关联式容器:hash_multiset

前言在上几节中我们分析了hashtable以及hash_set还有hash_map的实现,hash_set以及hash_map都不允许有重复的key存在,而hashtable提供了允许插入重复元素的操作insert_equal,对应实现的则是hash_multiset以及hash_multimap。 接下来我们先看看hash_multiset的实现,它和hash_set的实现很类似。hash_mu

Move_now的博客 1090

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

SGISTL源码-容器 笔记

本文是在阅读SGI STL v3.3源码中,遇到的一些问题及有意思的点。本文建立在已经观看过侯捷老师STL源码剖析课程的基础上。是在阅读源码过程中,对其中的内容进行补充、修饰。

weixin_46065476的博客 596

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

SGISTL源码探究-关联式容器:hash_map

前言在上一小节,我们分析了hash_set的实现,本小节我们将针对hash_map进行分析。它大部分也是调用的hashtable,不过它与map的区别也是因为底层的实现不同,所以map具有自动排序功能,而hash_map没有。 接下来我们来看看hash_map是如何实现的。hash_map的实现还是分为定义部分及其数据结构、构造函数、常用操作这三部分。关于hash_map的迭代器,是使用的hash

Move_now的博客 835

深度学习工具包 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")

STL源码剖析 - 第5章 关联式容器 - RB-tree(红黑树)

5.1 树的导览      标准的STL关联式容器分为set(集合)和map(映射表)两大类,以及这两大类的衍生体multiset(多键集合)和multimap(多键映射表)。这些容器的底层机制均以RB-tree(红黑树)完成。RB-tree也是一个独立的容器,但并不开放给外界使用。 此外,SGI STL还提供了一个不在标准规格之列的关联式容器:hash table(散列表),以及以此hash

灯火阑珊处 758

《STL源码剖析》——第五、六章:关联容器与算法

第五章、关联容器 5.0、关联容器 标准的STL关联式容器分为set(集合)和map(映射表)两大类,以及这两大类的衍生体multiset(多键集合)和multimap(多键映射表)。这些容器的底层机制均以RB-tree(红黑树)完成。RB-tree也是一个独立容器,但并不开放给外界使用。 SGISTL还提供了一个不在标准规格之列的关联式容器:hash_table(散列表),以及以此has...

weixin_42637495的博客 350

STL源码分析之RB-tree结构简析

所谓关联容器:          每笔数据(每个元素)都有一个键值(key)和一个实值(value)。当元素被插入到关联式容器中时,容器内部结构(可能是RB-Tree 也可能是hash-table)便依照其键值大小,以某种特定规则将这个元素置放于适当的位置。          关联容器没有所谓的头尾(只有最大元素和最小元素),所以不会有所谓的push_back(), push_front(),

博客 795

SGISTL源码探究-STL中的红黑树(上)

前言本小节将进入到SGISTL的红黑树部分。关于红黑树,是一种比较复杂的数据结构,但是并不是特别难。如果对红黑树不太了解,可以去网上查阅相关的资料,因为本文的主要目的是分析STL中的红黑树的源码,和普通的红黑树略有不同,还要复杂一些,需要有一定的基础。基本概念首先什么是二叉搜索树,二叉搜索树即符合任何一个节点的值一定大于其左子树的任何一个节点的值并且小于其右子树的任何一个节点的值(节点的值不允许重复

Move_now的博客 1806

SGISTL源码探究-stl_algobase.h中的算法

前言在上一小节中,我们分析了stl_numeric.h中的算法部分。在本小节中,我们将分析stl_algobase.h文件中的算法,里面实现的都是一些比较基本的算法,比如equal、fill、max、swap等,可以从中学习到泛型的思想。stl_algobase.h中的算法iter_swap该函数的作用是交换迭代器指向的两个元素。注意迭代器的类型必须是ForwardIterator及其派生类。 并

Move_now的博客 1244

SGISTL源码探究-STL中的hashtable(下)

前言在上一小节中,我们介绍了hashtable的基本概念,以及分析了在STL中,hashtable的迭代器、采用的数据结构及它的构造/析构函数,还有部分成员函数。 在本小节中,我们讲继续分析剩下的一些操作,如插入、删除、复制等。插入操作关于插入操作,有大量的重载版本,我们只分析比较关键的函数,其他的可以随便看看。/* insert_unique,插入元素(不允许重复) * 首先先判断加上新增元素

Move_now的博客 1184

SGISTL源码探究-关联式容器:hash_multimap

前言本小节将介绍hash_multimap的源码实现,它与hash_map的不同与map和multimap的不同类似,所以我们可以一边分析它们的不同之处,一边顺便复习hash_map。hash_multimap的实现定义及数据结构#ifndef __STL_LIMITED_DEFAULT_TEMPLATES template <class Key, class T, class HashFcn =

Move_now的博客 1117

SGISTL源码探究-stl_algo.h中的排序算法

前言在本小节中,我们将分析STL中算法组件的最后一部分:排序算法。排序算法分为内部排序和外部排序。而内部排序中常见的有八种排序算法:直接插入排序、希尔排序、简单选择排序、堆排序、冒泡排序、快速排序、归并排序、桶排序。在SGISTL实现的sort算法中,并不是简单的使用快速排序作为排序算法,而是交叉使用了插入排序、堆排序以及快速排序,并且做了一定的优化,并且只接受迭代器类型为RandomAccessI

Move_now的博客 938

SGISTL源码探究-stl_algo.h中的排列算法

前言在本小节中,我们将分析stl_algo.h中的排列算法。可能你使用过STL中的next_permutation求过全排列。比如这样:#include <iostream> #include <algorithm> #include <string> using namespace std;int main() { string str; cin >> str; sort(

Move_now的博客 924

SGISTL源码探究-关联式容器:map

前言在本小节中,我们将分析map容器,它与set最大的不同就是,它是key-value型的,而set的key和value是同一个。map和set底层都由红黑树实现,map上存储的都是pair,即键值对,存储到红黑树中时,排序依据的就是pair的第一个元素。 之前提到在set中,不允许更改元素的值,而在map中,key值同样不允许修改,但是value可以修改,因为value不涉及到map整体内部结构

Move_now的博客 913
上一篇: SGISTL源码探究-STL中的hashtable(下)
下一篇: SGISTL源码探究-关联式容器:hash_map
UKey_
博客等级 码龄10年 258粉丝 186原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值