面试总结之算法题

面试中常考的数学题——截木棍、圆上取点、赛马、红蓝墨水,测试毒药、坐到正确座位问题 文章目录1.将一根木棒截成三段,问能够组成三角形的概率;2.在圆上任取三点,问能够组成锐角、直角、钝角三角形的概率;3.共有25匹马,找出最快的3匹,只有5个赛道,每次比赛只能得到5匹马的速度排序,最少需要多少次比赛;4 有两瓶红蓝墨水,体积一样,现在从红墨水中舀一勺加入蓝墨水中,搅拌均匀后,在从蓝墨水中舀一勺加到红墨水中,试问这两瓶墨水哪瓶纯度更高。 1.将一根木棒截成三段,问能够组成三角形的概率; 来源:https://blog.youkuaiyun.com/weixin_41245919/article/deta 阅读详情

在一个多月的面试过程中,有很多需要讲思路或实现的算法或其他题目,这里总结下作为复习。后面不断更新。

算法题

1. 翻转链表

题目描述:

给你一个链表,使用方法返回一个翻转的链表,如1->2->3->4->5,返回的结果为5->4->3->2->1。

思路

自己的思路:
先使用一个list存储链表的所有节点值,再倒序遍历,拼接一个链表即可。

/**
     * 先按自己想法实现一遍
     * 存到数组再从后往前遍历
     * @param head
     * @return
     */
    public ListNode ReverseList(ListNode head) {
   
   

        ArrayList<Integer> list = new ArrayList();

        while (head != null) {
   
   
            list.add(head.val);
            head = head.next;
        }

        System.out.println("list: " + list);

        int len = list.size();
        ListNode node = new ListNode(list.get(len - 1));
        for (int i = len - 2; i >= 0; i --) {
   
   
            // 再循环遍历出node的最后一个节点,并拼接进去

            ListNode tmp = node;
            while (true) {
   
   
                if (tmp.next == null) {
   
   
                    tmp.next = new ListNode(list.get(i));
                    break;
                }
                tmp = tmp.next;

            }
        }


        return node;
    }

其他思路:
如何让后一个节点指向前一个节点!在下面的代码中定义了一个 next 节点,该节点主要是保存要反转到头的那个节点,防止链表 “断裂”。

 // 反转链表
    public ListNode ReverseList(ListNode head) {
   
   

        ListNode next = null;
        ListNode pre = null;

        while (head != null) {
   
   
            // 保存要反转到头的那个节点
            next = head.next;
            // 要反转的那个节点指向已经反转的上一个节点(备注:第一次反转的时候会指向null)
            head.next = pre;
            // 上一个已经反转到头部的节点
            pre = head;
            // 一直向链表尾走
            head = next;
        }
        return pre;
    }

测试:

 public static void main(String[] args) {
   
   

        ListNode a = new ListNode(1);
        ListNode b = new ListNode(2);
        ListNode c = new ListNode(3);
        ListNode d = new ListNode(4);
        ListNode e = new ListNode(5);
        a.next = b;
        b.next = c;
        c.next = d;
        d.next = e;

        ListNode pre = new Demo().ReverseList(a);
//
//        while (e != null) {
   
   
//            System.out.println(e.val);
//            e = e.next;
//        }

		// ListNode{val=5, next=ListNode{val=4, next=ListNode{val=3, next=ListNode{val=2, next=ListNode{val=1, next=null}}}}}
        System.out.println(pre);
    }

2. 解析字符串中数学表达式

题目描述:

给你String,类似于“1 + 2 * (3 - 4 * 2) / 4” 这样的字符串,你怎么输出最后结果,说说你的思路。

思路

先将这个后缀表达式利用栈将其转化为后缀表达式(不包含括号):

从左到右遍历中缀表达式,遇到操作数,输出,遇到操作符,当前操作符的优先级大于栈顶操作符优先级,进栈,否则,弹出栈顶优先级大于等于当前操作符的操作符,当前操作符进栈。

这里还说下后缀表达式的好处,其中不包含括号,运算符是放在两个操作数之后,不用考虑运算符的优先级了。

接下来从左到右遍历后缀表达式,如果遇到操作数,则将其压入栈,遇到运算符,则将栈顶两个元素计算完后压入栈即可,直到遍历完后,栈中的最后数据即为结果。

3. 阻塞队列实现

题目描述:

利用Java编写一个阻塞队列,你的思路是怎么样的?

思路

生产者消费者模型就是当队列为空时消费者停止消费,当队列满时生产者停止生产。利用wait 和 notify 协调生产者线程和消费者线程的关系,再加上一个数组作为队列的容器,生产者的偏移量以及消费者的偏移量就可以完成一个简单的消费者生产者模型。

阻塞队列如下,使用的是ArrayList作为容器:

package top.hellolsy.offer;


import java.util.ArrayList;

/**
 * 自己动手实现一个有界阻塞队列
 * 可以使用synchronize及wait notify
 * 也可以使用Lock的condition
 *
 * 这里使用的是Arraylist作为阻塞队列
 *
 *
 * 生产者消费者模型就是当队列为空时消费者停止消费,当队列满时生产者停止生产。利用wait 和 notify 协调生产者线程和消费者线程的关系,
 * 再加上一个数组作为队列的容器,生产者的偏移量以及消费者的偏移量就可以完成一个简单的消费者生产者模型。
 * 阻塞队列原理就是如此
 *
 */
public class MyArrayBlockQuene {
   
   

    /**
     * 队列容器
     */
    private ArrayList<Integer> container = new ArrayList<>();

    /**
     * 元素个数
     * 且使用volatile保证可见性
     */
    private volatile int size;

    /**
     * 容量
     * 且使用volatile保证可见性
     */
    private volatile int capacity;

    /**
     * 锁的对象
     */
    private Object lock = new Object();

    /**
     * 传入容量
     * @param capacity
     */
    public MyArrayBlockQuene(int capacity) {
   
   
        this.capacity = capacity;
    }



    /**
     * 生产者生产
     * @param data
     */
    public void put(int data) {
   
   

        synchronized (lock) {
   
   
            // 队列满了
            while (size == capacity) {
   
   

                try {
   
   
                    System.out.println("队列已经满了,需要等消费者消费...");
                    // 这里等待同时会释放锁
                    // wait() 方法调用后会使得当前所在的线程暂停运行
                    lock.wait();
                } catch (InterruptedException e) {
   
   
                    e.printStackTrace();
                }


            }

            // 队列没满
            System.out.println("生产了:" + data);
            container.add(data);
            size ++;
            // 通知可以取数据
            lock.notifyAll();

        }


    }


    /**
     * 消费者消费
     * @return 返回消费的数据
     */
    public int take() {
   
   
        int result = 0;
        synchronized (lock) {
   
   
            // 队列空了
            while (size == 0) {
   
   

                try {
   
   
                    System.out.println("队列已经空了,需要等生产者生产...");
                    // 这里等待同时会释放锁
                    // wait() 方法调用后会使得当前所在的线程暂停运行
                    lock.wait();
                } catch (InterruptedException e) {
   
   
                    e.printStackTrace();
                }


            }

            // 队列没满 序号是从0开始,所以需要size - 1
            result = container.remove(size - 1);
            size --;
            // 通知可以生产数据
            lock.notifyAll();

        }



        return result;
    }






}

测试类:

package top.hellolsy.offer;


public class MyBlockQueueTest {
   
   
    public static void main(String[] args) {
   
   
        // 队列容量为5
        MyArrayBlockQuene queue = new MyArrayBlockQuene(5);

        Thread put_thread = new Thread(() -> {
   
   
            for (int i = 0; i < 40; i ++) {
   
   
                queue.put(i + 1);
                try {
   
   
                    Thread.sleep(500);
                }catch (InterruptedException e){
   
   
                    e.printStackTrace();
                }
            }
        });

        Thread take_thread = new Thread(() -> {
   
   
            for(;;){
   
   
                System.out.println("消费者开始工作,消费:" + queue.take());
                try {
   
   
                    Thread.sleep(800);
                }catch (InterruptedException e){
   
   
                    e.printStackTrace();
                }
            }
        });

        put_thread.start();
        take_thread.start();
    }
}

运行结果:
在这里插入图片描述
在这里插入图片描述

另外,还有可以使用lock中的Condition实现,由于很少使用lock,我按照我熟悉的synchronized 的等待,通知机制实现的。

4. 排序查找问题

这里包含了常见的选择、冒泡、插入、快速排序及二分查找。

package top.hellolsy.offer.others;


import java.util.Arrays;

/**
 * 手写排序还有查找的几个常见方法
 *
 * 稳定排序:冒泡 插入 归并 基数
 * 不稳定:选择 快速 希尔 堆
 */
public class Sort {
   
   


    public static void main(String[] args) {
   
   
        int[] arr = new int[]{
   
   6,4,2,8,6,0,9,1};
        int[] arr1 = new int[]{
   
   12,45,23,67,7,1,5,21};
        int[] arr2 = new int[]{
   
   12,45,23,7,7,1,5,21};
        int[] arr3 = new int[]{
   
   12,45,1,67,67,23,5,21};

        System.out.println("未排序之前arr : " + Arrays.toString(arr));
        System.out.println("未排序之前arr1 : " + Arrays.toString(arr1));
        System.out.println("未排序之前arr2 : " + Arrays.toString(arr2));
        System.out.println("未排序之前arr3 : " + Arrays.toString(arr3));
//        select_sort(arr);
//        bubble_sort(arr);
//        insert_sort(arr);
        quick_sort(arr,0, arr.length - 1);
        quick_sort(arr1,0, arr1.length - 1);
        quick_sort(arr2,0, arr2.length - 1);
        quick_sort(arr3,0, arr3.length - 1);

        System.out.println("排序之后arr : " + Arrays.toString(arr));
        System.out.println("排序之后arr1 : " + Arrays.toString(arr1));
        System.out.println("排序之后arr2 : " + Arrays.toString(arr2));
        System.out.println("排序之后arr3 : " + Arrays.toString(arr3));


        int result = binary_search(arr3, 67);

        System.out.println(result);
    }






    /**
     * 选择排序
     * 每次选择最小的放在前面
     * @param arr
     */
    public static void select_sort(int[] arr) {
   
   
        int len = arr.length;

        int min = 0;
        for (int i = 0; i < len; i ++) {
   
   
             min = i;

            for (int j = i + 1; j < len; j ++) {
   
   
                if (arr[j] < arr[min]) {
   
   
                    min = j;
                }
            }
            // 交换
            int tmp = arr[min];
            arr[min] = arr[i];
            arr[i] = tmp;

        }


    }


    /**
     * 冒泡
     * 两两比较
     * 每一趟选出一个最大值到后面
     * @param arr
     */
    public static void bubble_sort(int[] arr) {
   
   
        int len = arr.length;


        // 冒泡趟数
        for (int i = 0; i < len - 1; i ++) {
   
   

            // 也是从0开始
            for (int j = 0; j < len - i - 1; j ++) {
   
   
                if (arr[j + 1] < arr[j]) {
   
   
                    // 交换
                    int tmp = arr[j + 1];
                    arr[j + 1] = arr[j];
                    arr[j] = tmp;
                }
            }


        }


    }


    /**
     * 插入排序
     * 假设数组前部分是已经排序好的
     * @param arr
     */
    public static void insert_sort(int[] arr) {
   
   
        int len = arr.length;


        // 从第二个元素开始,因为默认第一个元素已排序
        for (int i = 1; i < len; i ++) {
   
   

            // 一步步与已排序好的数组的最后一个元素进行比较
            // 注意 是arr[j]与arr[j - 1]进行比较
            for (int j =  i; j > 0; j --) {
   
   
                if (arr[j] < arr[j - 1]
快手面试算法题合集 1.力扣原题:最长不重复序列 import java.util.*; public class kuaishou { public static void main(String[] args){ Scanner in=new Scanner(System.in); String s=in.nextLine(); System.out.println(longestPalindrome(s)); } public static String longest 阅读详情

相关推荐

社招面试总结——算法题篇

面试结果 总结下最近的面试: 头条后端:3面技术面挂 蚂蚁支付宝营销-机器学习平台开发: 技术面通过,年后被通知只有P7的hc 蚂蚁中台-机器学习平台开发: 技术面通过, 被蚂蚁HR挂掉(脉脉上好多人遇到这种情况,一个是今年大环境不好,另一个,面试尽量不要赶上阿里财年年底,这算是一点tips吧) 快手后端: 拿到offer 百度后端: 拿到offer 最终拒了百度,去快手了, 一心想去阿里, ...

码蹄疾 3064

微软面试算法题总结

Leecode 84 第一题是数字三角形找最大和路径 (容易题) 第二题是二叉树中找两个节点的最近公共祖先节点 (最近公共祖先) 给定二叉树中的特定节点中序遍历后的下一个节点 (剑指offer) Leetcode 124 最大路径和 做题 (并查集) 有n个二维平面上的点和距离d,将它们分成k组。 若两点间的距离小于等于d,则这两个点在一组;如果点A和点B在一组,点B和点C在一组,则点A和点C...

wwxy1995的博客 3919

华为外包l两道面试算法题。

今日下午刚结束面试。一共两技术人员面的,一人出了一道算法题,记录下,并为以后做些准备,由于远程面试,所以没有代码测试,不知道行不行的通,且行且看吧。 1、输入为String 字母卡片(可以重复)和一个单词,问利用字母卡片是否能拼出单词。 事例:字母卡片“Zoos”,单词“Zoo” 答案是可以的输出true 如果单词是“Zoom” 输出为FALSE /*我一...

可及的小屋 1988

华为面试算法题

华为面试算法题

touchingnotyet的博客 5212

CVTE 面试的两道算法题

下了班立马赶往深圳北站,下着大雨又坐过了站,着急地跑向对面的站牌,匆忙间搞得满头大汗。好不容易坐上了高铁,休息片刻,终于有时间整理一下前两天面试CVTE 时遇到的两道算法题。 1. 在数组中寻找和为固定值的两个数字 这道题目是一面的时候一个女面试给出的最后一个面试问题。题目的大概意思如上,数据不一定有序,而且要求是在O(n) 的时间内找到答案。对于常年混迹LeetCode 的人来说,这是一道再...

少东的博客 1199

研究生课程笔记:软件包在流行病学中的应用(三)——STATA软件

关键词:STATA软件基本操作、STATA对于流行病学研究的实现、STATA对复杂抽样设计样本量计算的实现 一、STATA软件基本操作 这部分网上教程有很多,也可以直接根据stata自带的help功能进行自学,在此只记录课程中提及的功能项。 1. 变量编辑 1.1 赋值:label type(按精度区分) 1) 整型:int(32), short(16), long(32) 2) 实型:flo...

weixin_45463530的博客 2432

雷电模拟器+Auto.js避坑指南:用桥接模式解决PC与模拟器连接超时问题

本文详细解析了雷电模拟器与Auto.js联调中的桥接模式应用,解决PC与模拟器连接超时问题。通过桥接模式配置、高频故障排查及多开环境下的高阶配置,提升开发效率与稳定性,特别适合需要稳定网络连接的Auto.js开发者。

weixin_28836989的博客 631

电子数据取证实战:从“平航杯”竞赛看计算机检材分析的关键技术与案例解析

本文通过'平航杯'电子数据取证竞赛案例,深入解析计算机检材分析的关键技术,包括USB设备追踪、浏览器历史分析、AI换脸取证、虚拟货币交易追踪等实战技巧。重点探讨了数字痕迹的发现与关联,以及电子取证工具链的应用,为从业人员提供实用的技术参考和案例分析。

www00的博客 533

智能座舱-语音交互系统

从什么是智能座舱、智能座舱的发展驱动因素、智能座舱的构成要素三个方面梳理我对智能座舱的基础认识之后,为了加深“智能座舱产品入门”课程中语音交互部分知识的理解,我从什么是语音交互、语音交互的底层技术、智能座舱的语音交互等方面,对智能座舱语音交互系统相关的知识进行了梳理与总结。

GUOSA0928的博客 1440

DDR为什么需要DQS信号?

本文根据相关书籍和个人经验,谈了一下对DDR中DQS信号作用的理解

weixin_41155581的博客 2万+

【CAN总线测试】——使用VH6501 进行Busoff快慢恢复测试

即在IDBase中填标准帧11位二进制ID,如果不满11位,高位补零,凑齐11位,并将下方CurrTriggerField设置干扰前一位AckSlot位,Triggeroffset设置为0。首先确认环境支持VN6501,6501硬件连接成功后,工程的小闪电是正常黄色状态,若是灰色证明缺少License,或者软件安装环境不正确。填写干扰报文ID、干扰位置 注意这里的干扰位置是实际干扰的前一位,TriggerOffset表示偏移量,可以干扰某个字节的具体位.找到并打开Panel后,开启工程,并且配置面板。

LOVE135149的博客 5628

29、高速低功耗采样保持放大器设计

本文详细介绍了适用于低功耗模数转换器的高速低电压采样保持放大器(SHA)的设计技术,包括传统SHA的局限性、采样技术分类以及全NPN型和BiCMOS型SHA的具体设计实现。同时,文章深入探讨了优化输入电容、采样开关驱动及低功耗设计等具体措施,并提供了10位ADC前端和无线通信应用中的实例分析,为相关领域的工程师提供有价值的参考。

weixin_30600615的博客 424

【AI产品思路】用户旅程图与用户全生命周期:到底是什么关系?

用户旅程图(User Journey Map)和用户全生命周期(User Lifecycle)是两种不同的分析框架。用户旅程聚焦单次交易体验的完整过程(如浏览→下单→售后),关注触点、情绪和优化点;而用户生命周期则关注用户与平台的长期关系(从认知到流失),着重提升留存和LTV。两者互为补充:生命周期是时间维度的关系框架,旅程图是行为维度的体验路径。电商运营中,旅程优化改善单次体验,生命周期优化解决长期增长问题,二者结合才能实现体验提升与商业效率的双赢。

qq_25438419的博客 216

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

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

efm32 入门.pdf

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

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

上一篇: Java一个对象占用多少字节
下一篇: 日常问题归纳
思维态度行动
博客等级 码龄7年 31粉丝 60原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值