javascript函数库

js的常用封装函数库之Date操作 js的常用封装函数库之Date日期的操作 /* * 函数功能:Date */ class DateFn { /** * 格式化时间 * * @param {time} 时间 * @param {cFormat} 格式 * @return {String} 字符串 * * @example formatTime('2... 阅读详情
/*

-------------- 函数检索 --------------
trim函数: trim() lTrim() rTrim()
校验字符串是否为空: checkIsNotEmpty(str)
校验字符串是否为整型: checkIsInteger(str)
校验整型最小值: checkIntegerMinValue(str,val)
校验整型最大值: checkIntegerMaxValue(str,val)
校验整型是否为非负数: isNotNegativeInteger(str)
校验字符串是否为浮点型: checkIsDouble(str)
校验浮点型最小值: checkDoubleMinValue(str,val)
校验浮点型最大值: checkDoubleMaxValue(str,val)
校验浮点型是否为非负数: isNotNegativeDouble(str)
校验字符串是否为日期型: checkIsValidDate(str)
校验两个日期的先后: checkDateEarlier(strStart,strEnd)
校验字符串是否为email型: checkEmail(str)

校验字符串是否为中文: checkIsChinese(str)
计算字符串的长度,一个汉字两个字符: realLength()
校验字符串是否符合自定义正则表达式: checkMask(str,pat)
得到文件的后缀名: getFilePostfix(oFile)
-------------- 函数检索 --------------
*/

/**
* added by LxcJie 2004.6.25
* 去除多余空格函数
* trim:去除两边空格 lTrim:去除左空格 rTrim: 去除右空格
* 用法:
* var str = " hello ";
* str = str.trim();
*/
String.prototype.trim = function()
{
return this.replace(/(^[s]*)|([s]*$)/g, "");
}
String.prototype.lTrim = function()
{
return this.replace(/(^[s]*)/g, "");
}
String.prototype.rTrim = function()
{
return this.replace(/([s]*$)/g, "");
}
/********************************** Empty **************************************/
/**
*校验字符串是否为空
*返回值:
*如果不为空,定义校验通过,返回true
*如果为空,校验不通过,返回false 参考提示信息:输入域不能为空!
*/
function checkIsNotEmpty(str)
{
if(str.trim() == "")
return false;
else
return true;
}//~~~
/*--------------------------------- Empty --------------------------------------*/
/********************************** Integer *************************************/
/**
*校验字符串是否为整型
*返回值:
*如果为空,定义校验通过, 返回true
*如果字串全部为数字,校验通过,返回true
*如果校验不通过, 返回false 参考提示信息:输入域必须为数字!
*/
function checkIsInteger(str)
{
//如果为空,则通过校验
if(str == "")
return true;
if(/^(-?)(d+)$/.test(str))
return true;
else
return false;
}//~~~
/**
*校验整型最小值
*str:要校验的串。 val:比较的值
*
*返回值:
*如果为空,定义校验通过, 返回true
*如果满足条件,大于等于给定值,校验通过,返回true
*如果小于给定值, 返回false 参考提示信息:输入域不能小于给定值!
*/
function checkIntegerMinValue(str,val)
{
//如果为空,则通过校验
if(str == "")
return true;
if(typeof(val) != "string")
val = val + "";
if(checkIsInteger(str) == true)
{
if(parseInt(str,10)>=parseInt(val,10))
return true;
else
return false;
}
else
return false;
}//~~~
/**
*校验整型最大值
*str:要校验的串。 val:比较的值
*
*返回值:
*如果为空,定义校验通过, 返回true
*如果满足条件,小于等于给定值,校验通过,返回true
*如果大于给定值, 返回false 参考提示信息:输入值不能大于给定值!
*/
function checkIntegerMaxValue(str,val)
{
//如果为空,则通过校验
if(str == "")
return true;
if(typeof(val) != "string")
val = val + "";
if(checkIsInteger(str) == true)
{
if(parseInt(str,10)<=parseInt(val,10))
return true;
else
return false;
}
else
return false;
}//~~~
/**
*校验整型是否为非负数
*str:要校验的串。
*
*返回值:
*如果为空,定义校验通过,返回true
*如果非负数, 返回true
*如果是负数, 返回false 参考提示信息:输入值不能是负数!
*/
function isNotNegativeInteger(str)
{
//如果为空,则通过校验
if(str == "")
return true;
if(checkIsInteger(str) == true)
{
if(parseInt(str,10) < 0)
return false;
else
return true;
}
else
return false;
}//~~~
/*--------------------------------- Integer --------------------------------------*/
/********************************** Double ****************************************/
/**
*校验字符串是否为浮点型
*返回值:
*如果为空,定义校验通过, 返回true
*如果字串为浮点型,校验通过, 返回true
*如果校验不通过, 返回false 参考提示信息:输入域不是合法的浮点数!
*/
function checkIsDouble(str)
{
//如果为空,则通过校验
if(str == "")
return true;
//如果是整数,则校验整数的有效性
if(str.indexOf(".") == -1)
{
if(checkIsInteger(str) == true)
return true;
else
return false;
}
else
{
if(/^(-?)(d+)(.{1})(d+)$/g.test(str))
return true;
else
return false;
}
}//~~~
 

/**
*校验浮点型最小值
*str:要校验的串。 val:比较的值
*
*返回值:
*如果为空,定义校验通过, 返回true
*如果满足条件,大于等于给定值,校验通过,返回true
*如果小于给定值, 返回false 参考提示信息:输入域不能小于给定值!
*/
function checkDoubleMinValue(str,val)
{
//如果为空,则通过校验
if(str == "")
return true;
if(typeof(val) != "string")
val = val + "";
if(checkIsDouble(str) == true)
{
if(parseFloat(str)>=parseFloat(val))
return true;
else
return false;
}
else
return false;
}//~~~
/**
*校验浮点型最大值
*str:要校验的串。 val:比较的值
*
*返回值:
*如果为空,定义校验通过, 返回true
*如果满足条件,小于等于给定值,校验通过,返回true
*如果大于给定值, 返回false 参考提示信息:输入值不能大于给定值!
*/
function checkDoubleMaxValue(str,val)
{
//如果为空,则通过校验
if(str == "")
return true;
if(typeof(val) != "string")
val = val + "";
if(checkIsDouble(str) == true)
{
if(parseFloat(str)<=parseFloat(val))
return true;
else
return false;
}
else
return false;
}//~~~
/**
*校验浮点型是否为非负数
*str:要校验的串。
*
*返回值:
*如果为空,定义校验通过,返回true
*如果非负数, 返回true
*如果是负数, 返回false 参考提示信息:输入值不能是负数!
*/
function isNotNegativeDouble(str)
{
//如果为空,则通过校验
if(str == "")
return true;
if(checkIsDouble(str) == true)
{
if(parseFloat(str) < 0)
return false;
else
return true;
}
else
return false;
}//~~~
/*--------------------------------- Double ---------------------------------------*/
/********************************** date ******************************************/
/**
*校验字符串是否为日期型
*返回值:
*如果为空,定义校验通过, 返回true
*如果字串为日期型,校验通过, 返回true
*如果日期不合法, 返回false 参考提示信息:输入域的时间不合法!(yyyy-MM-dd)
*/
function checkIsValidDate(str)
{
//如果为空,则通过校验
if(str == "")
return true;
var pattern = /^((d{4})|(d{2}))-(d{1,2})-(d{1,2})$/g;
if(!pattern.test(str))
return false;
var arrDate = str.split("-");
if(parseInt(arrDate[0],10) < 100)
arrDate[0] = 2000 + parseInt(arrDate[0],10) + "";
var date = new Date(arrDate[0],(parseInt(arrDate[1],10) -1)+"",arrDate[2]);
if(date.getYear() == arrDate[0]
&& date.getMonth() == (parseInt(arrDate[1],10) -1)+""
&& date.getDate() == arrDate[2])
return true;
else
return false;
}//~~~
/**
*校验两个日期的先后
*返回值:
*如果其中有一个日期为空,校验通过, 返回true
*如果起始日期早于等于终止日期,校验通过, 返回true
*如果起始日期晚于终止日期, 返回false 参考提示信息: 起始日期不能晚于结束日期。
*/
function checkDateEarlier(strStart,strEnd)
{
if(checkIsValidDate(strStart) == false || checkIsValidDate(strEnd) == false)
return false;
//如果有一个输入为空,则通过检验
if (( strStart == "" ) || ( strEnd == "" ))
return true;
var arr1 = strStart.split("-");
var arr2 = strEnd.split("-");
var date1 = new Date(arr1[0],parseInt(arr1[1].replace(/^0/,""),10) - 1,arr1[2]);
var date2 = new Date(arr2[0],parseInt(arr2[1].replace(/^0/,""),10) - 1,arr2[2]);
if(arr1[1].length == 1)
arr1[1] = "0" + arr1[1];
if(arr1[2].length == 1)
arr1[2] = "0" + arr1[2];
if(arr2[1].length == 1)
arr2[1] = "0" + arr2[1];
if(arr2[2].length == 1)
arr2[2]="0" + arr2[2];
var d1 = arr1[0] + arr1[1] + arr1[2];
var d2 = arr2[0] + arr2[1] + arr2[2];
if(parseInt(d1,10) > parseInt(d2,10))
return false;
else
return true;
}//~~~
/*--------------------------------- date -----------------------------------------*/
/********************************** email *****************************************/
/**
*校验字符串是否为email型
*返回值:
*如果为空,定义校验通过, 返回true
*如果字串为email型,校验通过, 返回true
*如果email不合法, 返回false 参考提示信息:Email的格式不正確!
*/
function checkEmail(str)
{
//如果为空,则通过校验
if(str == "")
return true;
if (str.charAt(0) == "." || str.charAt(0) == "@" || str.indexOf('@', 0) == -1
|| str.indexOf('.', 0) == -1 || str.lastIndexOf("@") == str.length-1 || str.lastIndexOf(".") == str.length-1)
return false;
else
return true;
}//~~~
/*--------------------------------- email ----------------------------------------*/
/********************************** chinese ***************************************/
/**
*校验字符串是否为中文
*返回值:
*如果为空,定义校验通过, 返回true
*如果字串为中文,校验通过, 返回true
*如果字串为非中文, 返回false 参考提示信息:必须为中文!
*/
function checkIsChinese(str)
{
//如果值为空,通过校验
if (str == "")
return true;
var pattern = /^([u4E00-u9FA5]|[uFE30-uFFA0])*$/gi;
if (pattern.test(str))
return true;
else
return false;
}//~~~
/**
* 计算字符串的长度,一个汉字两个字符
*/
String.prototype.realLength = function()
{
return this.replace(/[^x00-xff]/g,"**").length;
}
/*--------------------------------- chinese --------------------------------------*/
/********************************** mask ***************************************/
/**
*校验字符串是否符合自定义正则表达式
*str 要校验的字串 pat 自定义的正则表达式
*返回值:
*如果为空,定义校验通过, 返回true
*如果字串符合,校验通过, 返回true
*如果字串不符合, 返回false 参考提示信息:必须满足***模式
*/
function checkMask(str,pat)
{
//如果值为空,通过校验
if (str == "")
return true;
var pattern = new RegExp(pat,"gi")
if (pattern.test(str))
return true;
else
return false;
}//~~~
/*--------------------------------- mask --------------------------------------*/
/********************************** file ***************************************/
/**
* added by LxcJie 2004.6.25
* 得到文件的后缀名
* oFile为file控件对象
*/
function getFilePostfix(oFile)
{
if(oFile == null)
return null;
var pattern = /(.*).(.*)$/gi;
if(typeof(oFile) == "object")
{
if(oFile.value == null || oFile.value == "")
return null;
var arr = pattern.exec(oFile.value);
return RegExp.$2;
}
else if(typeof(oFile) == "string")
{
var arr = pattern.exec(oFile);
return RegExp.$2;
}
else
return null;
}//~~~
/*--------------------------------- file --------------------------------------*/


转http://blog.chinaunix.net/u/23783/showart_219111.html
 
用TypeScript封装的一个JavaScript函数库 funclib.js (凡客杰斯) 简单介绍 目的:高效率完成前端业务代码! funclib.js 是一个简单、易用、贴进业务逻辑的JavaScript UMD函数库,类似于 underscore 和 lodash。 跟它们对比,funclib.js省去了很多js自带的或者不常用的方法。 funclib.js还根据一些实际业务的逻辑的规律封装了很多前后端都实用的新方法, ... 阅读详情

相关推荐

js的常用封装函数库之Dom操作

js的常用封装函数库之Dom操作: /* * 函数功能:Dom */ // getScrollTop /** * @desc 获取滚动条距顶部的距离 */ function getScrollTop() { return (document.documentElement && document.documentElement.scrollTop) || docume...

浮生离梦的博客 605

JS类库函数收集中....

实现string的substring方法   方法一:用charAt取出截取部分 String.prototype.mysubstring=function(beginIndex,endIndex){ var str=this, newArr=[]; if(!endIndex){ endIndex=str.length; ...

weixin_30610755的博客 113

数字化车间智能排产调度挑战赛(一)—— 数学模型

科大讯飞——数字化车间智能排产调度挑战赛。

Lyyyp的博客 5655

Pareto.js:超轻量级的JavaScript实用函数库

Pareto.js:超轻量级的JavaScript实用函数库 Pareto.js是一个精巧、直观且高效的JavaScript功能性工具库,它只包含14个核心函数,专注于提供最基础但实用的功能。这个库以纯函数为主,鼓励不可变数据处理,并且其大小甚至小于流行的lodash库。 技术分析 小巧玲珑:Pareto.js非常小,未压缩版本只有几KB,经过gzip压缩后更是微乎其微。 TypeScript...

gitblog_00015的博客 542

deepseek本地部署及应用部署指南

如果你找到的日志是[send] via NET/IB/0,则表示网络通信是通过IB网络的,但是没有开启GDRDMA技术,则会有大致5%的性能损耗(网传,未实测)。新增的环境变量配置,主要用于启用IB网络通信,而非使用以太网进行通信,详细的每一个参数的具体含义,可以在英伟达NCCL的官方网站上找到说明。下一步,我会对已经完成部署的模型进行压测,来探索系统的性能极限在哪里,以及如何在生产环境中何如进行进一步的性能优化,期待你的关注。

weixin_39797121的博客 2627

SAP ABAP ALV表格实战:5分钟搞定单元格下拉框配置(附完整代码)

本文详细介绍了在SAP ABAP开发中如何快速配置ALV表格的单元格下拉框功能,通过5分钟实战教程帮助开发者掌握关键步骤。文章包含完整的ABAP代码示例,涵盖下拉值定义、字段目录配置及ALV控件绑定等核心操作,特别适合需要实现财务系统费用类型选择或采购系统物料分类等场景的开发者参考。

weixin_28331555的博客 112

探索创新:Fn.js - 轻量级JavaScript函数库

探索创新:Fn.js - 轻量级JavaScript函数库 是一个开源的JavaScript函数库,专注于提供简单、高效的工具函数,为你的Web应用开发赋予更多的灵活性和便利性。在这个快速发展的Web世界中,Fn.js以其轻巧、模块化的设计理念,旨在简化开发者的工作流程,提高代码质量。 技术分析 Fn.js的核心是一个精心挑选的功能集,包括数组处理、对象操作、类型检查等常用功能。每个功能都是独立的...

gitblog_00004的博客 592

FreeRTOS-Plus-CLI在STM32F429上的高效移植与调试技巧

本文详细介绍了如何将FreeRTOS-Plus-CLI高效移植到STM32F429平台,并分享关键的调试技巧。内容涵盖使用HAL库进行底层驱动适配(特别是DMA+IDLE中断方案)、工程集成、自定义命令开发以及常见问题解决方案,旨在帮助开发者快速为嵌入式系统添加强大的命令行调试接口,提升开发与维护效率。

weixin_29224309的博客 336

自建JavaScript函数库

前段时间学JavaScript,最先学的就是如何建立自己的JavaScript函数库,在我看来,函数就是程序活的灵魂,在此简单介绍一下如何建立自己的JavaScript函数库。 原则:         不要版本检测:常用浏览器一般是IE、firefox、safari、opera、google,不能为了追求兼容而嗅探当前浏览器进而选择运行模式。         最好是能力检测:即在代码执行之前

李达 3111

Windows server 2012R2安装Oracle11g

打开 开始——所有程序——Oracle-OraDb11g_home1——配置和移植工具——Database Configuration Assistant。打开 开始——所有程序——Oracle-OraDb11g_home1——配置和移植工具——Net Configuration Assistant。首先打开Oracle的安装位置找到下面的位置找到tnsnames.ora文件右键编辑。打开Oracle的安装位置找到下面的位置找到tnsnames.ora文件右键编辑。选择仅安装数据库软件。

qq_74770105的博客 3597

Dify 本地插件安装失败?别慌,这篇教程手把手教你解决(解决 the plugin you want to install has a bad signature 报错的问题)

🤯dify安装本地插件报错 PluginDaemonBadRequestError: plugin verification has been enabled, and the plugin you want to install has a bad signature。的解决方案!

XiaoqiangClub的博客 3989

JavaScript函数库终极指南:Underscore.js与D3.js核心功能深度解析

JavaScript函数库在现代前端开发中扮演着至关重要的角色,它们为开发者提供了强大的工具和便捷的解决方案。在这篇完整指南中,我们将深入探讨两个业界知名的JavaScript函数库:**Underscore.js**和**D3.js**,帮助你快速掌握它们的使用技巧和实际应用场景。🚀 ## 为什么选择Underscore.js与D3.js? ### Underscore.js:函数式编程的

gitblog_00236的博客 885

【CASS精品教程】032:CASS11台阶画法案例大全

一、普通无边台阶 二、普通有边台阶 三、普通圆弧无边台阶 四、U型台阶 五、曲线U型台阶 六、L型台阶

智慧空间实验室 7474

Rambdax:JavaScript函数库的进化版

Rambdax:JavaScript函数库的进化版 项目介绍 Rambdax是一个基于Ramda理念扩展的JavaScript实用函数库,它旨在提供更加强大、灵活且高效的功能集合。不同于原生JavaScript提供的工具方法,Rambdax通过一系列精心设计的高阶函数,进一步提升了函数式编程在日常开发中的体验。这个项目特别适合那些寻求代码精简、可读性和模块化解决方案的开发者。 项目快速启动 要开始...

gitblog_00971的博客 413

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

【jQuery】初识JavaScript函数库:jQuery

一句话描述jQuery和JavaScript的关系:jQuery 是 JavaScript 的一个 函数库。就像STL是C++的一个函数库一样。

极客-多重人格递归 773

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

ChkInputs.js 客户端统一验证JavaScript函数库

ChkInputs.js 客户端统一验证JavaScript函数库 1、引言几乎所有的Web应用开发都需要用到客户端验证,客户端验证普遍使用JavaScript编写,JavaScript结合Html和CSS几乎占据了整个网页开发市场,不管采用什么技术,我们在最终在浏览器中看到的内容都是由这些代码组合而成。Web应用的交互中,用户通过客户端浏览器向服务端发送请求,在网络进行数据传输会耗费一定时间

chutao的专栏 1481

js的常用封装函数库之设置、获取和检测cookie

js的常用封装函数库之设置、获取和检测cookie /* * 函数功能:设置cookie * cname: cookie的名字 * cvalue: cookie的值 * exdays: cookie过期的天数 * 将访问者的名字存储在 cookie 变量中 */ function setCookie(cname, cvalue, exdays) { var d = new Date();...

浮生离梦的博客 299

Underscore——JS函数库

转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10826065.html underscore是什么——它是一个js函数库 jQuery统一了不同浏览器之间的DOM操作的差异,让我们可以简单地对DOM进行操作,而underscore则提供了一套完善的函数接口,让我们更方便地在JavaScript中实现函数式编程。 Un...

a631278993的博客 297

一个JavaScript函数库

最近写的一个JavaScript函数库,提供一些常用函数方法,有收集重写的,也有自写的。 github地址:https://github.com/seazeg/eg-utils 下面是库的函数列表 基础判断函数 isString (value) 判断字符串类型 isNumber (value) 判断数字类型 isBoolean (value) 判断布尔类型 isFunction (value)...

weixin_30343157的博客 206

javaScript 通用函数库

 /**//*       名字:Common.js       功能:通用JavaScript脚本函数库       包括:                     1.Trim(str)--去除字符串两边的空格                     2.XMLEncode(str)--对字符串进行XML编码            3.ShowLabel(str,str)--鼠标提示功

阿铮的箩筐 735

用js实现php里面的函数库 strtr()这个很好用

http://phpjs.org/functions/ 国外的一搓牛人,用js实现了php里面所有的函数。 这个函数库很好用,熟悉php的话,写js的时候可以看看,里面有没有要用的到的函数。

hzbigdog的专栏 1383

Typescript JavaScript类型判断函数库

是一个基于JavaScript语言开发的函数库,提供了一系列用于判断数据类型的函数,包括判断值是否为undefined、null、布尔值或数字等。在JavaScript中,由于动态类型的特性,开发者很难在编写代码时确保数据类型的正确性。该函数库的函数使用简单、明了,开发者只需传入要判断的值作为参数,函数会返回一个布尔值,表示该值是否为指定的数据类型。总之,JavaScript类型判断函数库是一个便捷、高效、可靠的工具,可以帮助开发者更好地处理JavaScript中的数据类型问题,提高代码质量和开发效率。

佚名程序员 360

JavaScript 自定义函数库

javascript function library相关信息 作者 moses.mo 邮箱 moses.mo@protegrity.com 版本信息如下: # redactor time comment 1 moses.mo 2016.6.12 create 2 moses.mo 2016.6.14 modify 函数库列表 # function

老莫小小朋友 1314

JavaScript 函数库 xe-utils 常见问题解决方案

xe-utils 是一个强大的 JavaScript 函数库,提供了丰富的工具方法,支持在浏览器和 Node.js 环境中使用。该项目主要使用 JavaScript 编程语言。 ## 新手常见问题及解决方案 ### 问题一:如何安装 xe-utils? **问题描述:** 新手在使用 xe-utils 之前,需要先安装这个库。 **解决步骤:** 1. 打开命令行工具。 2. 切换到你的项...

gitblog_00025的博客 906
上一篇: Javascript 技巧大全http://www.playes.net/Blog/450.asp
下一篇: 一些网页设计师面试试题及参考答案
oscar_java
博客等级 码龄22年 12粉丝 8原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值