深入理解LinkedHashMap 源码分析

Blender几何节点倒角全解:程序化硬表面建模实战 程序化建模的核心理念是把固定操作变成可复用的生成规则,而几何节点正是这一理念在Blender中的具体承载。对于硬表面建模而言,倒角是表现零件加工感的关键细节,传统Bevel修改器存在边界控制难、参数不可驱动、难以嵌入复杂流程等痛点。Mesh Bevel Node的出现改变了这一局面:倒角不再是修改器栈末尾的静态处理,而是节点树中的数据流环节,可通过Selection精准限定范围、用命名属性驱动宽度、以Material Index控制新生成面的材质。这种基于属性驱动的方式,让倒角从一次性操作升级为可复用、可调 阅读详情

一、LinkedHashMap结构

  • 这是一个有序的,底层是继承于 HashMap 实现的,由一个双向链表所构成,具有和 HashMap 一样的快速查找特性。

  • LinkedHashMap 的排序方式有两种:

    • 根据写入顺序排序。
    • 根据访问顺序排序,每次 get 都会将访问的值移动到链表末尾,这样重复操作就能得到一个按照访问顺序排序的链表。
  • 数据结构,通过以下代码调试可以看到 map 的组成:
    @Test
    	public void test(){
    		Map<String, Integer> map = new LinkedHashMap<String, Integer>();
    		map.put("1",1) ;
    		map.put("2",2) ;
    		map.put("3",3) ;
    		map.put("4",4) ;
    		map.put("5",5) ;
    		System.out.println(map.toString());
    	}

 /**
     * The head of the doubly linked list.
     */
    private transient Entry<K,V> header;

    /**
     * The iteration ordering method for this linked hash map: <tt>true</tt>
     * for access-order, <tt>false</tt> for insertion-order.
     *
     * @serial
     */
    private final boolean accessOrder;
    
    private static class Entry<K,V> extends HashMap.Entry<K,V> {
        // These fields comprise the doubly linked list used for iteration.
        Entry<K,V> before, after;

        Entry(int hash, K key, V value, HashMap.Entry<K,V> next) {
            super(hash, key, value, next);
        }
    }  

其中 Entry 继承于 HashMap 的 Entry,并新增了上下节点的指针,也就形成了双向链表。还有一个 header 的成员变量,是这个双向链表的头结点。

第一个类似于 HashMap 的结构,利用 Entry 中的 next 指针进行关联。下边则是 LinkedHashMap 如何达到有序的关键。就是利用了头节点和其余的各个节点之间通过 Entry 中的 after 和 before 指针进行关联。其中还有一个 accessOrder 成员变量,默认是 false,默认按照插入顺序排序,为 true 时按照访问顺序排序,也可以调用:

这个构造方法可以显示的传入 accessOrder。

public LinkedHashMap(int initialCapacity,
                         float loadFactor,
                         boolean accessOrder) {
        super(initialCapacity, loadFactor);
        this.accessOrder = accessOrder;
    }

二、LinkedHashMap相关方法 

  • 构造方法就是调用HashMap 的构造方法:

    public LinkedHashMap() {
            super();
            accessOrder = false;
        }
    // HashMap实现:
     public HashMap(int initialCapacity, float loadFactor) {
            if (initialCapacity < 0)
                throw new IllegalArgumentException("Illegal initial capacity: " +
                                                   initialCapacity);
            if (initialCapacity > MAXIMUM_CAPACITY)
                initialCapacity = MAXIMUM_CAPACITY;
            if (loadFactor <= 0 || Float.isNaN(loadFactor))
                throw new IllegalArgumentException("Illegal load factor: " +
                                                   loadFactor);
    
            this.loadFactor = loadFactor;
            threshold = initialCapacity;
            //HashMap 只是定义了改方法,具体实现交给了 LinkedHashMap
            init();
        }
    

    可以看到里面有一个空的 init(),具体是由 LinkedHashMap 来实现的:

     @Override
        void init() {
            header = new Entry<>(-1, null, null, null);
            header.before = header.after = header;
        }

    其实也就是对 header 进行了初始化,从这个方法可以看出,实现了双向。

  • put() 方法:主体的实现都是借助于 HashMap 来完成的,只是对其中的 recordAccess(), addEntry(), createEntry() 进行了重写。如下是HashMap的put方法:

    public V put(K key, V value) {
            if (table == EMPTY_TABLE) {
                inflateTable(threshold);
            }
            if (key == null)
                return putForNullKey(value);
            int hash = hash(key);
            int i = indexFor(hash, table.length);
            for (Entry<K,V> e = table[i]; e != null; e = e.next) {
                Object k;
                if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {
                    V oldValue = e.value;
                    e.value = value;
                    //空实现,交给 LinkedHashMap 自己实现
                    e.recordAccess(this);
                    return oldValue;
                }
            }
    
            modCount++;
            // LinkedHashMap 对其重写
            addEntry(hash, key, value, i);
            return null;
        }
        
        // LinkedHashMap 对其重写
        void addEntry(int hash, K key, V value, int bucketIndex) {
            if ((size >= threshold) && (null != table[bucketIndex])) {
                resize(2 * table.length);
                hash = (null != key) ? hash(key) : 0;
                bucketIndex = indexFor(hash, table.length);
            }
    
            createEntry(hash, key, value, bucketIndex);
        }
        
        // LinkedHashMap 对其重写
        void createEntry(int hash, K key, V value, int bucketIndex) {
            Entry<K,V> e = table[bucketIndex];
            table[bucketIndex] = new Entry<>(hash, key, value, e);
            size++;
        }       
    //就是判断是否是根据访问顺序排序,如果是则需要将当前这个 Entry 移动到链表的末尾
            void recordAccess(HashMap<K,V> m) {
                LinkedHashMap<K,V> lm = (LinkedHashMap<K,V>)m;
                if (lm.accessOrder) {
                    lm.modCount++;
                    remove();
                    addBefore(lm.header);
                }
            }
            
            
        //调用了 HashMap 的实现,并判断是否需要删除最少使用的 Entry(默认不删除)    
        void addEntry(int hash, K key, V value, int bucketIndex) {
            super.addEntry(hash, key, value, bucketIndex);
    
            // Remove eldest entry if instructed
            Entry<K,V> eldest = header.after;
            if (removeEldestEntry(eldest)) {
                removeEntryForKey(eldest.key);
            }
        }
        
        void createEntry(int hash, K key, V value, int bucketIndex) {
            HashMap.Entry<K,V> old = table[bucketIndex];
            Entry<K,V> e = new Entry<>(hash, key, value, old);
            //就多了这一步,将新增的 Entry 加入到 header 双向链表中
            table[bucketIndex] = e;
            e.addBefore(header);
            size++;
        }
        
            //写入到双向链表中
            private void addBefore(Entry<K,V> existingEntry) {
                after  = existingEntry;
                before = existingEntry.before;
                before.after = this;
                after.before = this;
            }  

    以上是LinkedHashMap 的实现。

  • get 方法,LinkedHashMap 的 get() 方法也重写了:

    public V get(Object key) {
            Entry<K,V> e = (Entry<K,V>)getEntry(key);
            if (e == null)
                return null;
                
            //多了一个判断是否是按照访问顺序排序,是则将当前的 Entry 移动到链表头部。   
            e.recordAccess(this);
            return e.value;
        }
        
        void recordAccess(HashMap<K,V> m) {
            LinkedHashMap<K,V> lm = (LinkedHashMap<K,V>)m;
            if (lm.accessOrder) {
                lm.modCount++;
                
                //删除
                remove();
                //添加到头部
                addBefore(lm.header);
            }
        }

    clear()方法:

    //只需要把指针都指向自己即可,原本那些 Entry 没有引用之后就会被 JVM 自动回收。
        public void clear() {
            super.clear();
            header.before = header.after = header;
        }

    总的来说 LinkedHashMap 其实就是对 HashMap 进行了拓展,使用了双向链表来保证了顺序性。因为是继承与 HashMap 的,所以一些 HashMap 存在的问题 LinkedHashMap 也会存在,比如不支持并发等。

内部维护了一个双向链表,用来维护插入顺序或者 LRU 顺序。

/**
 * The head (eldest) of the doubly linked list.
 */
transient LinkedHashMap.Entry<K,V> head;

/**
 * The tail (youngest) of the doubly linked list.
 */
transient LinkedHashMap.Entry<K,V> tail;

accessOrder 决定了顺序,默认为 false,此时维护的是插入顺序。

final boolean accessOrder;

LinkedHashMap 最重要的是以下用于维护顺序的函数,它们会在 put、get 等方法中调用。

void afterNodeAccess(Node<K,V> p) { }
void afterNodeInsertion(boolean evict) { }

afterNodeAccess()

当一个节点被访问时,如果 accessOrder 为 true,则会将该节点移到链表尾部。也就是说指定为 LRU 顺序之后,在每次访问一个节点时,会将这个节点移到链表尾部,保证链表尾部是最近访问的节点,那么链表首部就是最近最久未使用的节点。

void afterNodeAccess(Node<K,V> e) { // move node to last
    LinkedHashMap.Entry<K,V> last;
    if (accessOrder && (last = tail) != e) {
        LinkedHashMap.Entry<K,V> p =
            (LinkedHashMap.Entry<K,V>)e, b = p.before, a = p.after;
        p.after = null;
        if (b == null)
            head = a;
        else
            b.after = a;
        if (a != null)
            a.before = b;
        else
            last = b;
        if (last == null)
            head = p;
        else {
            p.before = last;
            last.after = p;
        }
        tail = p;
        ++modCount;
    }
}

afterNodeInsertion()

在 put 等操作之后执行,当 removeEldestEntry() 方法返回 true 时会移除最晚的节点,也就是链表首部节点 first。

evict 只有在构建 Map 的时候才为 false,在这里为 true。

void afterNodeInsertion(boolean evict) { // possibly remove eldest
    LinkedHashMap.Entry<K,V> first;
    if (evict && (first = head) != null && removeEldestEntry(first)) {
        K key = first.key;
        removeNode(hash(key), key, null, false, true);
    }
}
removeEldestEntry() 默认为 false,如果需要让它为 true,需要继承 LinkedHashMap 并且覆盖这个方法的实现,这在实现 LRU 的缓存中特别有用,通过移除最近最久未使用的节点,从而保证缓存空间足够,并且缓存的数据都是热点数据。
protected boolean removeEldestEntry(Map.Entry<K,V> eldest) {
    return false;
}

 

分享一个不错的连接:https://www.imooc.com/article/22931

化工仿真软件:gPROMS二次开发_(1).gPROMS基础知识 在gPROMS中,模型是通过定义变量、参数和方程来创建的。模型可以是简单的单元操作,如换热器、反应器,也可以是复杂的系统,如整个化工流程。变量是模型中表示状态或输出的量。在gPROMS中,变量需要显式定义其类型和单位。# 定义变量VAR# 温度变量,单位为K# 压力变量,单位为Pa# 组分摩尔分数,数组变量参数是模型中表示常量或初始条件的量。参数同样需要定义其类型和单位。# 定义参数PAR# 理想气体常数,单位为J/(mol·K)# 反应器体积,单位为m^3# 初始摩尔数。 阅读详情

相关推荐

大麦网回流票监控实战:如何利用sign参数和cookie实现自动抢票(避坑指南)

本文详细介绍了如何利用sign参数和cookie构建大麦网回流票监控系统,实现自动化抢票。通过分析大麦网票务系统的核心机制、获取关键身份凭证、逆向分析sign签名算法,并构建完整的监控系统,帮助用户高效捕捉回流票机会。文章还提供了实战避坑指南和合法合规的注意事项,确保系统稳定运行且符合平台规则。

weixin_28568819的博客 412

LinkedHashMap源码分析

HashMap元素插入是无序的,为了让遍历顺序和插入顺序一致,我们可以使用LinkedHashMap,其内部维护了一个双向链表来存储元素顺序,并且可以通过accessOrder属性控制遍顺序为插入顺序或者为访问顺序。本节将记录LinkedHashMap的内部实现原理,基于JDK1.8,并且用LinkedHashMap实现一个简单的LRU。

Gaga246的博客 334

PWM调光原理详解:为什么你的LED灯会闪烁?从硬件到软件的避坑指南

本文深入解析PWM调光原理,揭示LED灯闪烁的根本原因,并提供从硬件设计到软件算法的全面解决方案。通过分析人眼视觉暂留机制和PWM参数设置,帮助开发者避免频闪问题,提升照明质量。特别适合电子工程师和智能家居开发者参考。

weixin_29189363的博客 293

java之LinkedHashMap源码详细解析

LinkedHashMap结合了hashmap和双向链表 LinkedHashMap是HashMap的子类,有着和HashMap的多数特性。 其特点大概有: key和value都允许为空 key可重复可覆盖,value可重复 有序的 非线程安全的 还可实现LRU (最近最少使用)算法

码农研究僧的博客 1797

打开.nc降水气象数据制作年降水量地图

图层的单位为度,在反距离插值中也是以度为单位,比较麻烦,还是想用以m为单位的投影,这里是个bug,后续调整一下。该彩色部分是以2021年1月、2月、3月的降水数据分别作为RGB得到。因为该栅格的分辨率还是太大了,一个栅格就能覆盖一个县,若想要进行降尺度,可以做插值处理。下载的数据集为2021-2022年,因此有12+12=24个月,24个波段。想要得到廊坊市周围的数据,需要裁剪范围,在降水数据图层上导出数据。打开数据管理工具-投影和变换-定义投影。在降水数据图层上右击属性,添加投影。得到了降尺度的插值图。

所有专家都曾始于新手 4520

YOLOv11旋转目标检测详解:从原理到实战的全面指南

本文介绍了YOLOv11旋转目标检测技术的核心概念、架构设计与应用场景。传统目标检测使用水平边界框(AABB)存在背景噪声大、定位精度低等问题,而旋转边界框(OBB)通过引入角度参数显著提升了检测精度,在遥感、OCR、工业质检等领域具有独特优势。YOLOv11-OBB采用改进的多尺度检测层、CSPDarknet53骨干网络和双通道角度输出机制,在保持实时性的同时实现精确的旋转目标检测。实验表明,该方法在DOTA数据集上达到81.3%的mAP,相比传统方法提升显著,特别适合处理具有旋转特性或高宽比悬殊的目标。

本博客聚焦 YOLOv11 全流程落地,涵盖架构优化、数据集处理、训练技巧与多场景部署,兼及国产数据库、Java 开发与 AI 模型应用,内容兼顾理论与工程实践,为开发者提供系统干货,助力高效提升技术能力。 302

LinkedHashMap源码解析

LinkedHashMap 直接继承自HashMap public class LinkedHashMap<K,V> extends HashMap<K,V> implements Map<K,V> 而LinkedHashMap比HashMap优于以下几点 LinkedHashMap 内部维护了一个双向链表,解决了 HashMap 不能随时保持遍历顺序和插入顺序一致的问题 LinkedHashMap 元素的访问顺序也提供了相关支持,也就是我们常说的 L

hequnwang10的博客 508

从统一入口到运营中枢:全面看懂 SAP for Me 的能力边界、使用方式与项目价值

SAP for Me 是 SAP 推出的统一工作平台,旨在整合原本分散在多个系统中的关键信息与操作。它将许可证管理、系统状态、支持工单、维护合同、产品路线图等核心功能集中到一个界面,为不同角色提供定制化视图。平台包含多个功能模块:Home 作为个性化工作台展示待办事项与风险;Calendar 整合各类维护事件与关键时间节点;Reporting 提供跨域分析与趋势洞察;Finance & Legal 管理订单、发票与合规事项;Portfolio & Products 则展示产品全景与路线图。该

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 121

LinkedHashMap 源码详细分析(JDK1.8)

简单说明一下这个问题(水平有限,不保证完全正确),这里这么做确实会浪费空间,但与 TreeNode 通过继承获取的组成链表的能力相比,这点浪费是值得的。但在 HashMap 中,put 方法插入的是 HashMap 内部类 Node 类型的节点,该类型的节点并不具备与 LinkedHashMap 内部类 Entry 及其子类型节点组成链表的能力。链表的建立过程是在插入键值对节点时开始的,初始情况下,让 LinkedHashMap 的 head 和 tail 引用同时指向新节点,链表就算建立起来了。

Elvis Hu的博客 217

RNA-seq分析:Step4(比对)

预处理之后的fastq文件,可以使用HISAT2软件将reads比对至参考基因组上。HISAT2软件将reads比对至参考基因组上的步骤如下:1. 对参考基因组进行建索引。对参考基因组进行预处理,生成索引文件,包括基因组序列的FM索引和SA索引。2. 将原始的reads进行预处理。包括去除接头序列、去除低质量的碱基,以及进行过滤,得到质量较高的、可靠的reads。3. 利用建立的FM索引和SA索引,将处理后的reads与参考基因组进行比对。首先,通过FM索引,快速找到与reads匹配的可能位置;

沉香best的博客 2599

5、模糊风险评估

本文介绍了基于模糊逻辑的风险评估方法,探讨了如何在不确定、不完整信息环境下进行高效的风险分析。文章涵盖了模糊集合与隶属度函数的基本概念、模糊推理系统的流程,并结合犯罪风险、金融风险和医疗诊断等实际案例,展示了模糊风险评估的应用价值和技术细节。此外,还介绍了模糊贝叶斯网络、模糊综合评价等进阶工具与方法,为多领域风险管理提供了理论支持和实践指导。

mango的博客 180

【集合源码系列】LinkedHashMap源码解析

LinkedHashMap LinkedHashMap 继承自 HashMap 类,基本上没有重写 HashMap 的方法,只是把 HashMap 空实现的预留拓展点实现了。 数据结构 Map 拓展属性 /** * 头节点。 * * 越老的节点,放在越前面。所以头节点,指向链表的开头 */ transient LinkedHashMap.Entry<K,V> head; /** * 尾节点 * * 越新的节点,放在越后面。所以尾节点,指向链表的结尾 */ transi

菜鸡也有大佬梦 537

CONN工具箱分析fmri数据笔记1

前言一、安装二、预处理三、去噪 前言 CONN:functional connectivity toolbox,是基于MATLAB和SPM的一个对功能磁共振数据进行分析的一个工具箱。可以进行以下分析: Seed-based correlations (SBC), ROI-to-ROI correlations, graph analyses, Independent component analyses(group-ICA), Masked (ICA) Amplitude of Low-Frequency.

weixin_52073820的博客 6587

Map 四兄弟用法对比:HashMap、LinkedHashMap、TreeMap、Hashtable

脑图文字版]中央:Map 四兄弟├─HashMap:快、乱、null×1├─LinkedHashMap:快、稳、LRU├─TreeMap:排序、log n、null×0└─Hashtable:锁表、废弃、别用“Hash 为快 Linked 序,Tree 要排 null 除去;并发弃用 Hashtable,SkipList 来替。

持续输出Java相关知识 311

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

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

集合四课之四 Map接口下,HashTable、LinkedHashMap、HashMap和TreeMap介绍与区别 附带速记卡

先来看看组织图

null 202

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Java 集合

Java 集合(Collection) 文章目录Java 集合(Collection)@[toc]一,Java集合框架概述1.我们为什么要学习集合2.数组和集合的区别2.1长度的区别2.2元素的数据类型3.集合的由来4.集合框架大概体系结构二,Collection接口方法1.常用方法2.示例代码:三,Iterator迭代器接口1.Iterator接口概述2.Iterator接口的使用方法**Iterator接口中的方法:****Iterator接口如何使用?**四,Collection子接口:List接口1

Ther_123的博客 871

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

一文搞定java集合框架,四万字图文详解,深入分析源码,请带着耐心点进来!

Java Collections Framework Internals Authors Introduction 关于*C++标准模板库(Standard Template Library, STL)的书籍和资料有很多,关于Java集合框架(Java Collections Framework, JCF)*的资料却很少,甚至很难找到一本专门介绍它的书籍,这给Java学习者们带来不小的麻烦。我深深的不解其中的原因。虽然JCF设计参考了STL,但其定位不是Java版的STL,而是要实现一个精简紧凑的容器框架,

Viper的程序员修炼手册 658

Java集合类源码分析:LinkedHashMap如何维护插入顺序

继承自HashMap,在保留HashMap所有特性的基础上,通过维护一个双向链表来记录元素的插入顺序或访问顺序。这使得它既具有HashMap的O(1)时间复杂度的查询性能,又能提供可预测的迭代顺序。java// 基本使用示例// 迭代顺序保证为A->B->C通过巧妙的双向链表设计,在继承HashMap高效查找的基础上,完美解决了哈希表无序的问题。通过扩展节点类添加前后指针插入时自动维护链表顺序支持可选的访问顺序模式迭代器基于链表实现保证顺序通过组合而非修改来扩展功能。

2501_93833736的博客 1785

Java Collection系列之HashMap、ConcurrentHashMap、LinkedHashMap的使用及源码分析

文章目录HashMapHashMap的存储结构初始化put & getput元素get元素扩容遍历Mapjdk1.8中的优化ConcurrentHashMapjdk1.7版本jdk1.8版本put元素get元素1.8中的变化LinkedHashMap内部结构put元素get元素移除最近最少使用元素TreeMap使用元素自然排序使用自定义排序参考 HashMap、ConcurrentHash...

小马快跑的博客 798

java基础:深入理解LinkedHashMap:从底层原理到大厂实战与面试解析

LinkedHashMap继承自HashMap,在HashMap“数组+链表/红黑树”的基础上,通过双向链表维护所有节点的访问/插入顺序,实现“有序存储”。

weixin_43290370的博客 1127

Java集合系列[4]----LinkedHashMap源码分析

这篇文章我们开始分析LinkedHashMap的源码,LinkedHashMap继承了HashMap,也就是说LinkedHashMap是在HashMap的基础上扩展而来的,因此在看LinkedHashMap源码之前,读者有必要先去了解HashMap的源码,可以查看我上一篇文章的介绍《Java集合系列[3]----HashMap源码分析》。只要深入理解了HashMap的实现原理,回过头来...

anwupeng2413的博客 211

java基础之集合框架--LinkedHashMap深入理解

java基础之集合框架–LinkedHashMap深入理解在看LinkedHashMap时还是建议先回顾下HashMap–LinkedHashMap的父亲,是不是感觉HashMap很重要,哈哈~~,它就是很重要,可以把它比作一个美轮美奂的精美建筑,一切设计都那么恰到好处! java基础之集合框架–HashMap深入理解及应用LinkedHashMap底层结构图LinkedHashMap底层为数组

wmj765的博客 350

Java集合LinkedHashMap源码分析

作者:劳夫子 (Java知音)这篇文章我们开始分析LinkedHashMap的源码,LinkedHashMap继承了HashMap,也就是说LinkedHashMap是在HashMap的基础上扩展而来的。因此在看LinkedHashMap源码之前,读者有必要先去了解HashMap的源码,可以查看我上一篇文章的介绍《集合系列—HashMap源码分析》。只要深入理解了HashMap的实现原理,回过头来...

化名三爷 259

JDK1.8之LinkedHashMap简单了解

一、前言   前面我们已经分析了HashMap的源码,已经知道了HashMap可以用在哪种场合,如果这样一种情形,我们需要按照元素插入的顺序来访问元素,此时,LinkedHashMap就派上用场了,它保存着元素插入的顺序,并且可以按照我们插入的顺序进行访问。 二、LinkedHashMap用法 import java.util.Map; import java.uti

mmoren的博客 460
上一篇: 深入理解HashMap 的工作原理及代码实现,什么时候用到红黑树
下一篇: springboot启动报错:Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException:
striveb
博客等级 码龄10年 242粉丝 117原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值