自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(31)
  • 资源 (17)
  • 收藏
  • 关注

原创 使用selenium打开网页并保存cookie至json文件

在编写爬虫,或者模拟浏览器进行一些操作时,如果每次都模拟用户输入账号密码登陆,实现步骤较为复杂,登陆后抓取cookies,在后续操作中使用cookies登陆是一种较为简便的方法。因此,本文使用python3 + chromedriver,帮助完成cookies的抓取。需要安装python3环境,安装selenium和json包,并下载对应版本的chromedriverfrom selenium import webdriverimport json options = webdriver.Chr

2021-05-18 00:14:44 1915

原创 Windows下载TS格式m3u8格式视频下载方法

下载ffmpeg,并配置到环境变量中(或者复制ffmpeg.exe到python等已经在环境变量中的文件夹中)在访问网页前打开F12(或打开F12后刷新网页),进入Network,找***.m3u8格式的资源,右键复制其链接在CMD中使用下述命令回车完成下载:其中https://example.com/linklink.m3u8对应m3u8的资源链接,output_name.mp4为下载合并后得到的mp4文件ffmpeg -i https://example.com/linklink.m3u8 .

2021-04-24 03:00:15 1416 2

原创 覆盖安装windows解决windows权限、文件异常等疑难杂症

最近不知道是因为安装了某些软件还是系统出了问题,在打开资源换利器、组策略等系统组件时,会报出用户账户控制错误:“为了对电脑进行保护,已经阻止此应用。管理员已阻止你运行此应用。有关详细信息,请于管理员联系。”同时观察到详情中的发布者为“未知”,故猜测可能是系统文件损坏或证书、权限出现问题首先尝试更改账户控制UAC,即使更改到最低也没有效果,虽然可以通过修改注册表等方式更彻底地关闭UAC,从而打开设备管理器等系统应用,但是关闭UAC对于系统安全来说也是个隐患,故放弃进而尝试DELL客服提供的方法:右

2020-12-26 14:25:28 1600

原创 python使用装饰器监控函数运行时间

from functools import wrapsimport timedef func_timer(function): @wraps(function) def function_timer(*args, **kwargs): start = time.time() result = function(*args, **kwargs) end = time.time() print ("函数%s总运行时间: %s s" %(function.__nam

2020-12-13 11:10:00 599

原创 JAVA生成特定位数特定内容的随机字符串

public class Utils {public static String j(int length) { int a = 16; String KeyString = "123456789abcdefghijklmnopqrstuvwxyz"; int len = KeyString.length(); StringBuffer sb = new StringBuffer(); for(int i=0;i<a;i++){ sb.appen

2020-12-10 19:24:49 895

原创 Python根据URL地址下载文件并保存至对应目录

Python根据URL地址下载文件并保存至对应目录引言在编程中经常会遇到图片等数据集将图片等数据以URL形式存储在txt文档中,为便于后续的分析,需要将其下载下来,并按照文件夹分类存储。本文以Github中Alexander Kim提供的图片分类数据集为例,下载其提供的图片样本并分类保存Python 3.6.5,Anaconda, VSCode1. 下载数据集文件建立项目文件夹,下载上述...

2020-09-19 16:01:52 69458 5

原创 Photoshop 添加ico图标格式支持

Photoshop原生缺乏对ico图标格式的支持,但是我们可以通过添加组件的形式,导出ico文件,下面介绍方法。首先,打开下述网址下载8bi组件:http://www.telegraphics.com.au/sw/product/ICOFormat根据系统版本选择对应版本的插件,插件支持Mac/Win平台下巨虎所有Photoshop版本下载完成后,解压下载得到的zip压缩包得到.8bi格式(系统不同可能扩展名会有所差异)的文件。进入软件安装目录下的\Required\Plug-ins\File F

2020-08-26 00:23:53 1221

原创 windows 下使用命令快速在cmd或powershell中以管理员权限执行命令

本文通过使用scoop安装sudo实现在windows下实现类似linux系统下的sudo的效果安装Scoop若已安装请跳过此步骤Scoop为windows下非常方便的包管理程序,可以通过类似linux下yum/apt的命令实现软件安装和软件管理。打开powershell并执行下述命令保证本地脚本的执行:set-executionpolicy remotesigned -scope currentuser安装:iex (new-object net.webclient).downl

2020-08-15 15:31:24 3664

原创 Python3随爬虫启动代理池(引用外部Python代码项目并实现多进程并行执行)

最近在写某网站爬虫的过程中,遇到了异常访问封禁IP的问题。而且不只是爬虫访问会触发封禁,网页端一次浏览太多页面也会触发反爬保护。为了解决这个问题,在Github上找到了一个不错的免费IP代理池程序,这个作者通过爬虫爬取了几个免费的IP代理源,并且定期循环对节点进行监测,删除失效代理,将有效代理存储于redis库中。而且,通过向本地特定端口发送请求,即可获取和操作本地IP代理池的代理,配置完成后非常方便。然而,在使用过程中也发现,每次手动启动代理非常麻烦,所以就想在主爬虫进程启动前,先调用该代理池程序,在

2020-08-10 13:09:37 230

原创 Python3使用pipreqs生成requirements.txt

当一个Python完成后,若要在新环境下运行,往往需要重新安装各种包依赖,这就需要记录当前环境下所用到的包、包的版本等,非常麻烦,这里介绍一种方法,可以较为快速便捷地生成requirements.txt文件,在新环境下部署运行时,执行下述命令,即可自动安装所需的对应版本的包依赖。pip install -r requirements.txtrequirements.txt中的内容格式类似:APScheduler==3.2.0werkzeug==0.15.3Flask==1.0requests&

2020-07-24 09:25:59 1891

原创 基于人口普查数据的收入预测模型构建及比较分析(Python数据分析分类器模型实践)

收入是反映人民生活水平和国家经济发展状况的重要指标,改善收入水平,提高生活质量是各国政府和人民共同的奋斗目标。探索收入的影响因素,不仅对国家具有重要意义,对个人提升自我,企业识别目标消费群体也具有重要的参考价值。为了研究年龄、受教育程度、职业等诸多因素对个体收入的影响,本文以UCI Machine Learning Repository网站提供的人口普查数据作为数据样本,遵循CRISP-DM的数据挖掘流程,对数据中可能存在的规律进行探索和分析,构建决策树、Logistic回归、K近邻、线性支持向量机、随机森

2020-07-09 20:40:25 18813 16

原创 Python 比较日期字符串与当前日期的日期差

在Python中经常会需要用到时间比较的情况,如爬取特定一段时间的数据,或比较某一时间值和当前时间的差import datetimedate_str = "2020-07-06" # 以此时间为例interval = datetime.datetime.today() - datetime.datetime.strptime(date_str,"%Y-%m-%d")print('目标日期与当前日期的日期差为:{}天'.format(interval.days))若要比较两个给定日期字符串的日

2020-07-07 10:04:17 2876

原创 Python 8行代码实现input询问键盘输入超时自动跳过选择默认值

在编写Python程序时,经常需要设置临时选择项,如出现异常时询问后续操作,或程序开始执行时询问必要参数等,这时候往往需要用到input或弹窗等方式向用户询问。然而,当程序并不是自己用,或者需要分享给他人的时候,出于稳健性的考虑,我们可能需要为此类输入命令设置超时时间,如询问选择后若5秒内未得到返回值,就选择默认参数,并继续执行后续进程。然而,通过一段时间的搜索,网上提供了不少超时终止的方法,如采取多线程的方法,或使用包eventlet,或者使用signal。经过测试,发现其各自都有一些问题。对于使用

2020-07-06 11:33:22 4482 13

原创 Python3通过简单进程池multiprocessing.Pool实现多进程(学习笔记)

在编写Python程序时,经常需要同时执行多个运算任务或多项工作以实现某些功能和使用计算机的多核提高执行效率,这里介绍一种非常简单的方法实现多进程。这里使用的是multiprocessing提供的Pool方法来实现多进程以下述代码为例:from multiprocessing import Pool # 导入线程池import os, time, random # 导入其他包def long_time_task(name): print('Run task %s (%s)...'

2020-07-04 17:59:16 1223

原创 Macbook Pro Bootcamp 安装触控板驱动mac-precision-touchpad在Windows系统下实现更好的触控板操作

由于很多软件的限制,所以不得不在Windows和MacOS之间进行切换,然而,Windows下虽然Bootcamp提供了触控板的驱动,然而只能实现简单的上下滑动和点击等操作,而且在滑动页面的时候滑动非常不流畅,体验极差。今天无意间发现了一款第三方撰写的驱动,可以较为完美地实现Macbook笔记本在Windows系统下的触控板操作支持,通过在我的2015款Macbook Pro(A1502)进行安装测试,感觉体验很不错,在这里分享给大家。驱动来自于Github上的imbushu,他的项目地址如下:htt

2020-07-02 19:57:05 14053 3

原创 Windows下Anaconda配置conda和pip镜像源,实现快速包安装

配置pip源在用户路径下创建pip文件夹,在pip文件夹中创建pip.ini,文件编码使用默认或(GB2312),输入[global]trusted-host=pypi.doubanio.com #豆瓣源,可以换成其他的源index-url=https://pypi.doubanio.com/simple/ #添加豆瓣源为可信主机,要不然可能报错保存后,下期进行包安装即可自动应用。配置好后的文件路径为%HOME%\pip\pip.ini下面三个pip源速度都还不错,可

2020-07-02 16:14:38 4126

原创 Windows Terminal 使用管理员身份创建标签页

在Windows Terminal里运行指令,经常容易遇到某些操作需要使用管理员权限,但是Terminal却忘记使用管理员权限打开的情况。不仅如此,以管理员权限打开Windows Terminal步骤也比较繁琐(有比较便捷的方法欢迎评论哈),而且打开后所有的标签页都会拥有管理员权限,有一定的安全风险。但是在MacOS或Linux的Terminal中,我们却可以简单使用sudo命令实现从用户身份向管理员身份的转变。那么,Windows下能否实现sudo一样的命令,来快速地对某一个标签页开启管理者权限呢?这里

2020-06-29 18:59:39 14755 17

原创 windows cmd执行命令时卡死 假死,按空格回车方向键等进行键盘操作后恢复

今天在使用you-get下载视频的时候发现,cmd经常动不动就没有反应了,视频下载进度没有变化,速度没有变化,仿佛是凝固了一般,但是在窗口敲击键盘任意按键,按按Enter,按按方向键,cmd命令又会醒过来继续执行,甚至跳出来一堆东西,重启、重新执行依然无法解决问题,遂上网查找解决方案。经过一番测试,也受到http://m.lanhusoft.com/Article/697.html这篇文章的启发,问题出在cmd的设置里面:cmd默认开启了“快速编辑模式”,只要当鼠标点击cmd任何区域时,就自动进入了编

2020-06-24 00:52:49 15335 3

原创 使用MATLAB求解线性规划问题,并输出单纯形表,识别无界解和无穷多最优解情况

本文构建SimplexMax函数,通过构建单纯型表和循环迭代,求解线性规划问题的最优解clc;clear;%% 设置变量,调用函数% 题目参数A = [0 5 1 0 0; 6 2 0 1 0; 1 1 0 0 1];b = [15; 24; 5];c = [2 1 0 0 0];ind = [3 4 5]% 无界解% A = [-2 1 1 0;% ...

2020-03-31 16:44:04 4863

原创 使用MATLAB的solve函数求解线性方程组

使用MATLAB的solve函数求解线性方程组示例定义变量定义方程组使用solve函数进行求解输出求解结果syms a b p k e w; % 定义变量eqns = [b*p - e*k - a == 0, e + k*p + k*w == 0, 2*b*p == a + e*k + b*w]; % 定义规则res = solve(eqns,w,e,p); % 求解re...

2020-03-31 16:29:18 14774

原创 MATLAB 2019 设置自定义字体

老版本的MATLAB安装字体到Windows即可在MATLAB的预设-字体中进行设置,但MATLAB 2019b等较新的版本安装好字体后有时却在MATLAB中找不到对应的字体解决方法:将字体的ttf文件放置到MATLAB安装目录的jre中的font文件夹内,路径如下:C:\Program Files\MATLAB\R2019b\sys\java\jre\win64\jre\lib\fonts...

2019-11-11 21:46:29 4361 2

转载 在windows中把文件上传到远程Linux服务器

1.下载可以从http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html下载pscp,并将其放入windows的system32 文件夹下,这样在dos命令窗口中就能直接调用使用了。2、使用(一)Windows—Linux上传文件:1)、开始→运行→cmd进入到dos模式,输入以下命令:pscp E:\javaWP\ne...

2019-04-24 17:15:51 5561

原创 Python3 Pandas DataFrame 对某一列求和

Pandas DataFrame 对某一列求和在操作pandas的DataFrame的时候,常常会遇到某些列是字符串,某一些列是数值的情况,如果直接使用df_obj.apply(sum)往往会出错使用如下方式即可对其中某一列进行求和dataf_test1['diff'].sum() // diff为要求和的列...

2019-04-24 11:50:05 107423 1

转载 statsmodels.regression.linear_model.RegressionResults

statsmodels.regression.linear_model.RegressionResults*class statsmodels.regression.linear_model.RegressionResults(model, params, normalized_cov_params=None, scale=1.0, cov_type=‘nonrobust’, cov_kwds=...

2019-04-24 10:56:24 3381

原创 利用油猴脚本实现知网搜索自动选择核心期刊

利用知网查询学术期刊默认选择全部期刊,而很多时候我们只希望找到SCI、SSCI等核心期刊,每次都要手动勾选太麻烦,这里利用油猴写一个脚本自动点选想要查询的期刊,省去每次选择的麻烦首先在浏览器中安装油猴插件右键插件按钮选择“选项”打开油猴设置面板点选右上角加号创建新脚本删除原有代码,将下述代码黏贴进去,保存即可// ==UserScript==// @name CNK...

2019-03-18 10:59:46 2907 3

原创 python递归遍历目录和子目录下的所有文件,并将文件目录存入列表

python递归遍历目录和子目录下的所有文件,并将文件目录存入列表本文编写了一个函数,实现递归查找目标目录path和目标目录下的多层子目录下的所有文件,并将所有文件的path 存放于一个list列表中。import osdef get_file(root_path,all_files=[]): ''' 递归函数,遍历该文档目录和子目录下的所有文件,获取其path '...

2019-01-18 17:24:18 10180 2

原创 Servlet实现查询返回json数据

使用Servlet响应浏览器的请求,实现Ajax查询等功能 package servlet;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http...

2019-01-04 15:57:16 11403

原创 测试不同浏览器对HTML5音频视频的支持

使用不同音频视频样本,测试浏览器对不同格式的支持程度。音视频样本下载:https://download.csdn.net/download/weixin_39858881/10306563网页源码:&lt;!doctype html&gt;&lt;html&gt;&lt;head&gt;&lt;meta charset="utf-8"&gt;&lt;title&gt;音视...

2019-01-04 14:54:54 933

原创 Mysql 8.0 创建DBCP连接池

DBCP连接池简介     DBCP(DataBase connection pool)数据库连接池是 apache 上的一个Java连接池项目。DBCP通过连接池预先同数据库建立一些连接放在内存中(即连接池中),应用程序需要建立数据库连接时直接到从接池中申请一个连接使用,用完后由连接池回收该连接,从而达到连接复用,减少资源消耗的目的。MySQL 8.0MySQL 8.0以后,对jav...

2019-01-04 14:53:44 3850 1

原创 TOMCAT访问文件目录返回资源列表

尝试访问一个不存在index的文件目录,如localhost:8080/example/,如果返回目录列表,则证明开启,若报错,则需要进入Tomcat的conf目录,对web.xml进行如下编辑:原始代码:    &lt;servlet&gt;        &lt;servlet-name&gt;default&lt;/servlet-name&gt;        &lt;ser...

2018-12-29 12:05:16 1233

原创 JAVA-编写循环将一个数组的值赋值给另一数组

package com.Javapractice;// 循环给新数组赋值public class practice3 { public static void main(String args[]){ int a[]={10,20,30,40,50}; //int b[(a.length)]; // 不可以这样声明 //int b[]=

2017-09-24 10:45:35 17918

代码及相关资料—基于人口普查数据的收入预测模型构建及比较分析(Python数据分析分类器模型实践)

此压缩包为该文章相关资料,包含代码等,建议使用jupyter打开 https://blog.csdn.net/weixin_39858881/article/details/107235037

2022-07-19

Macbook Bootcamp 触控板Trackpad 驱动 mac-precision-touchpad

用于Macbook、Trackpad等的触控板优化,实现更多操作 使用方法参考:https://blog.csdn.net/weixin_39858881/article/details/107091728

2020-07-02

mysimpleMax2.m

使用MATLAB求解线性规划问题,并将结果和单纯形表导出到Excel,包含简单线性规划问题、无界解的线性规划问题和无穷多解的线性规划问题

2020-03-31

eql_solve.m

本代码为MATLAB solve函数的示例,通过一个线性方程组的求解演示该函数的用法,希望对您有所帮助!!!

2020-03-31

mysql8 DBCP连接池jar依赖

用于实现DBCP连接池所用的JAR依赖文件,包括数据库驱动及创建连接池所需的其他依赖: * commons-collections  * commons-dbcp2  * commons-logging  * commons-pool2  * mysql-connector

2019-01-04

lcx.exe原版 端口转发

windows下实现端口转发的工具

2018-12-19

validator jQuery表单验证插件

插件描述:Validator是一个jQuery验证插件,可以验证文本,文本区,密码复选框并选择元素。验证器支持:需要依赖复选框,最小/最大长度、电子邮件、数量、数字和一些定位的错误消息

2018-07-12

commons-logging-1.2

When writing a library it is very useful to log information. However there are many logging implementations out there, and a library cannot impose the use of a particular one on the overall application that the library is a part of. The Logging package is an ultra-thin bridge between different logging implementations. A library that uses the commons-logging API can be used with any logging implementation at runtime. Commons-logging comes with support for a number of popular logging implementations, and writing adapters for others is a reasonably simple task. Applications (rather than libraries) may also choose to use commons-logging. While logging-implementation independence is not as important for applications as it is for libraries, using commons-logging does allow the application to change to a different logging implementation without recompiling code. Note that commons-logging does not attempt to initialise or terminate the underlying logging implementation that is used at runtime; that is the responsibility of the application. However many popular logging implementations do automatically initialise themselves; in this case an application may be able to avoid containing any code that is specific to the logging implementation used.

2018-07-12

commons-collections4-4.1

Commons-Collections seek to build upon the JDK classes by providing new interfaces, implementations and utilities. There are many features, including: Bag interface for collections that have a number of copies of each object BidiMap interface for maps that can be looked up from value to key as well and key to value MapIterator interface to provide simple and quick iteration over maps Transforming decorators that alter each object as it is added to the collection Composite collections that make multiple collections look like one Ordered maps and sets that retain the order elements are added in, including an LRU based map Reference map that allows keys and/or values to be garbage collected under close control Many comparator implementations Many iterator implementations Adapter classes from array and enumerations to collections Utilities to test or create typical set-theory properties of collections such as union, intersection, and closure

2018-07-12

Apache commons-pool2-2.5.0

The Apache Commons Pool open source software library provides an object-pooling API and a number of object pool implementations. Version 2 of Apache Commons Pool contains a completely re-written pooling implementation compared to the 1.x series. In addition to performance and scalability improvements, version 2 includes robust instance tracking and pool monitoring.

2018-07-12

Flat-UI CSS样式 HTML模板

非常好看而又实用的HTML页面模板,包括按钮、表单、单选按钮、复选按钮、提示框等

2018-07-12

jQuery Validate

基于jQuery的Validate表单输入验证插件,附带使用示例页面

2018-07-12

Crypto 1.4.30 加解密软件

CryptoTool安装包 CryptoTool安装文件 支持私钥公钥加解密,MD5等操作

2018-04-16

音频视频格式测试包

压缩包包含wav,mp3,ogg,flac,m4r,mmf,mp2,amr,ape,aac,wma,wv共12种格式的音频样本和mkv,ogg,mp4,3gp,avi,flv,mov,mpg,rmvb,swf,vob,wmv共12种格式的视频样本,供浏览器、播放器等的测试使用

2018-03-24

Apache POI 3.17

是用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程式对Microsoft Office格式档案读和写的功能。POI为“Poor Obfuscation Implementation”的首字母缩写,意为“简洁版的模糊实现”。

2017-12-24

深度学习工具包 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 com Directories 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 working For references on each library check REFS.md Setup ----- 1. Download. 2. addpath(genpath('DeepLearnToolbox')); Example: Deep Belief Network --------------------- ```matlab function test_example_DBN load 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 weights rand('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 NN rand('state',0) %train dbn dbn.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 nn nn = dbnunfoldtonn(dbn, 10); nn.activation_function = 'sigm'; %train nn opts.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 --------------------- ```matlab function test_example_SAE load 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 FFNN nn = nnsetup([784 100 10]); nn.activation_function = 'sigm'; nn.learningRate = 1; nn.W{1} = sae.ae{1}.W{1}; % Train the FFNN opts.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 --------------------- ```matlab function test_example_CNN load 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% error rand('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 error figure; plot(cnn.rL); assert(er<0.12, 'Too big error'); ``` Example: Neural Networks --------------------- ```matlab function test_example_NN load 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 net rand('state',0) nn = nnsetup([784 100 10]); opts.numepochs = 1; % Number of full sweeps through data opts.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 decay rand('state',0) nn = nnsetup([784 100 10]); nn.weightPenaltyL2 = 1e-4; % L2 weight decay opts.numepochs = 1; % Number of full sweeps through data opts.batchsize = 100; % Take a mean gradient step over this many samples nn = 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 dropout rand('state',0) nn = nnsetup([784 100 10]); nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through data opts.batchsize = 100; % Take a mean gradient step over this many samples nn = 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 function rand('state',0) nn = nnsetup([784 100 10]); nn.activation_function = 'sigm'; % Sigmoid activation function nn.learningRate = 1; % Sigm require a lower learning rate opts.numepochs = 1; % Number of full sweeps through data opts.batchsize = 100; % Take a mean gradient step over this many samples nn = nntrain(nn, train_x, train_y, opts); [er, bad] = nntest(nn, test_x, test_y); assert(er < 0.1, 'Too big error'); %% ex5 plotting functionality rand('state',0) nn = nnsetup([784 20 10]); opts.numepochs = 5; % Number of full sweeps through data nn.output = 'softmax'; % use softmax output opts.batchsize = 1000; % Take a mean gradient step over this many samples opts.plot = 1; % enable plotting nn = 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 data vx = 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 output opts.numepochs = 5; % Number of full sweeps through data opts.batchsize = 1000; % Take a mean gradient step over this many samples opts.plot = 1; % enable plotting nn = 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")

2017-10-15

数学建模国赛2014B源程序 折叠桌

数学建模国赛2014B 优秀论文附件 MATLAB源代码程序 折叠桌问题

2017-10-08

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除