hibernate 3.2.7 支持SQL SERVER 2005+的分页

Hibernate+sqlserver2000分页 不错的分页(Hibernate+sqlserver2000分页)值得大家一看。 立即下载

由于hibernate 3.2.7是用top处理mssql 查询分页,效率不高。由于在 3.6.x 版本中已经有改进的代码,因此从最近的版本hibernate-distribution-3.6.10.Final-dist.tar.gz中拷贝出SQLServer2005Dialect.java、SQLServer2008Dialect.java

具体目录是

hibernate-distribution-3.6.10.Final-dist.tar.gz\hibernate-distribution-3.6.10.Final\project\hibernate-core\src\main\java\org\hibernate\dialect


SQLServer2005Dialect.java 稍作修改:

/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.  All third-party contributions are
 * distributed under license by Red Hat Inc.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.hibernate.dialect;

import java.sql.Types;

import org.hibernate.Hibernate;
import org.hibernate.dialect.function.NoArgSQLFunction;
//import org.hibernate.type.StandardBasicTypes;

/**
 * A dialect for Microsoft SQL 2005. (HHH-3936 fix)
 * 
 * @author Yoryos Valotasios
 */
public class MySQLServer2005Dialect extends SQLServerDialect {
	private static final String SELECT = "select";
	private static final String FROM = "from";
	private static final String DISTINCT = "distinct";
	private static final int MAX_LENGTH = 8000;

	@SuppressWarnings("deprecation")
	public MySQLServer2005Dialect() {
		// HHH-3965 fix
		// As per http://www.sql-server-helper.com/faq/sql-server-2005-varchar-max-p01.aspx
		// use varchar(max) and varbinary(max) instead of TEXT and IMAGE types
		registerColumnType( Types.BLOB, "varbinary(MAX)" );
		registerColumnType( Types.VARBINARY, "varbinary(MAX)" );
		registerColumnType( Types.VARBINARY, MAX_LENGTH, "varbinary($l)" );
		registerColumnType( Types.LONGVARBINARY, "varbinary(MAX)" );
		
		registerColumnType( Types.CLOB, "varchar(MAX)" );
		registerColumnType( Types.LONGVARCHAR, "varchar(MAX)" );
		registerColumnType( Types.VARCHAR, "varchar(MAX)" );
		registerColumnType( Types.VARCHAR, MAX_LENGTH, "varchar($l)" );
		
		registerColumnType( Types.BIGINT, "bigint" );
		registerColumnType( Types.BIT, "bit" );
		registerColumnType( Types.BOOLEAN, "bit" );
		
		//registerFunction("row_number", new NoArgSQLFunction("row_number", StandardBasicTypes.INTEGER, true));
		registerFunction("row_number", new NoArgSQLFunction("row_number", Hibernate.INTEGER, true));

        registerHibernateType(Types.CHAR, Hibernate.STRING.getName());   
        registerHibernateType(Types.NVARCHAR, Hibernate.STRING.getName());   
        registerHibernateType(Types.LONGNVARCHAR, Hibernate.STRING.getName());   
        registerHibernateType(Types.DECIMAL, Hibernate.DOUBLE.getName()); 
	}

	@Override
	public boolean supportsLimitOffset() {
		return true;
	}

	@Override
	public boolean bindLimitParametersFirst() {
		return false;
	}

	@Override
	public boolean supportsVariableLimit() {
		return true;
	}
	
	//@Override
	public int convertToFirstRowValue(int zeroBasedFirstResult) {
		// Our dialect paginated results aren't zero based. The first row should get the number 1 and so on
		return zeroBasedFirstResult + 1;
	}
	
	@Override
	public String getLimitString(String query, int offset, int limit) {
		// We transform the query to one with an offset and limit if we have an offset and limit to bind
		if (offset > 1 || limit > 1)  {
			return getLimitString(query, true);
		}
		return query;
	}

	/**
	 * Add a LIMIT clause to the given SQL SELECT (HHH-2655: ROW_NUMBER for Paging)
	 * 
	 * The LIMIT SQL will look like:
	 * 
	 * <pre>
	 * WITH query AS (
	 *   SELECT ROW_NUMBER() OVER (ORDER BY orderby) as __hibernate_row_nr__, 
	 *   original_query_without_orderby
	 * )
	 * SELECT * FROM query WHERE __hibernate_row_nr__ BEETWIN offset AND offset + last
	 * </pre>
	 * 
	 * 
	 * @param querySqlString
	 *            The SQL statement to base the limit query off of.
	 * @param offset
	 *            Offset of the first row to be returned by the query (zero-based)
	 * @param limit
	 *            Maximum number of rows to be returned by the query
	 * 
	 * @return A new SQL statement with the LIMIT clause applied.
	 */
	@Override
	public String getLimitString(String querySqlString, boolean hasOffset) {
		StringBuilder sb = new StringBuilder(querySqlString.trim().toLowerCase());

		int orderByIndex = sb.indexOf("order by");
		CharSequence orderby = orderByIndex > 0 ? sb.subSequence(orderByIndex, sb.length())
				: "ORDER BY CURRENT_TIMESTAMP";

		// Delete the order by clause at the end of the query
		if (orderByIndex > 0) {
			sb.delete(orderByIndex, orderByIndex + orderby.length());
		}

		// HHH-5715 bug fix
		replaceDistinctWithGroupBy(sb);

		insertRowNumberFunction(sb, orderby);

		// Wrap the query within a with statement:
		sb.insert(0, ";WITH query AS (").append(") SELECT * FROM query ");
		sb.append("WHERE __hibernate_row_nr__ BETWEEN ? AND ?");

		return sb.toString();
	}

	/**
	 * Utility method that checks if the given sql query is a select distinct one and if so replaces the distinct select
	 * with an equivalent simple select with a group by clause. See
	 * {@link SQLServer2005DialectTestCase#testReplaceDistinctWithGroupBy()}
	 * 
	 * @param sql an sql query
	 */
	protected static void replaceDistinctWithGroupBy(StringBuilder sql) {
		int distinctIndex = sql.indexOf(DISTINCT);
		if (distinctIndex > 0) {
			sql.delete(distinctIndex, distinctIndex + DISTINCT.length() + 1);
			sql.append(" group by").append(getSelectFieldsWithoutAliases(sql));
		}
	}

	/**
	 * This utility method searches the given sql query for the fields of the select statement and returns them without
	 * the aliases. See {@link SQLServer2005DialectTestCase#testGetSelectFieldsWithoutAliases()}
	 * 
	 * @param an
	 *            sql query
	 * @return the fields of the select statement without their alias
	 */
	protected static CharSequence getSelectFieldsWithoutAliases(StringBuilder sql) {
		String select = sql.substring(sql.indexOf(SELECT) + SELECT.length(), sql.indexOf(FROM));

		// Strip the as clauses
		return stripAliases(select);
	}

	/**
	 * Utility method that strips the aliases. See {@link SQLServer2005DialectTestCase#testStripAliases()}
	 * 
	 * @param a
	 *            string to replace the as statements
	 * @return a string without the as statements
	 */
	protected static String stripAliases(String str) {
		return str.replaceAll("\\sas[^,]+(,?)", "$1");
	}

	/**
	 * Right after the select statement of a given query we must place the row_number function
	 * 
	 * @param sql
	 *            the initial sql query without the order by clause
	 * @param orderby
	 *            the order by clause of the query
	 */
	protected static void insertRowNumberFunction(StringBuilder sql, CharSequence orderby) {
		// Find the end of the select statement
		int selectEndIndex = sql.indexOf(SELECT) + SELECT.length();

		// Insert after the select statement the row_number() function:
		sql.insert(selectEndIndex, " ROW_NUMBER() OVER (" + orderby + ") as __hibernate_row_nr__,");
	}
}


SQLServer2008Dialect.java 保留原样

/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.  All third-party contributions are
 * distributed under license by Red Hat Inc.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.hibernate.dialect;

import java.sql.Types;

import org.hibernate.Hibernate;
import org.hibernate.dialect.function.NoArgSQLFunction;

/**
 * A dialect for Microsoft SQL Server 2008 with JDBC Driver 3.0 and above
 *
 * @author Gavin King
 */
public class SQLServer2008Dialect extends SQLServer2005Dialect {
	public SQLServer2008Dialect(){
		registerColumnType( Types.DATE, "date" );
		registerColumnType( Types.TIME, "time" );
		registerColumnType( Types.TIMESTAMP, "datetime2" );
		
		registerFunction( "current_timestamp", new NoArgSQLFunction("current_timestamp", Hibernate.TIMESTAMP,false) );
	}
}

默认的是SQL Server 2000

hibernate.dialect=org.hibernate.dialect.SQLServerDialect

对于SQL Server 2005 修改配置

hibernate.dialect=org.hibernate.dialect.SQLServer2005Dialect

对于 SQL Server 2008 修改配置

hibernate.dialect=org.hibernate.dialect.SQLServer2008Dialect


Hibernate 函数 ,子查询 和原生SQL查询 Hibernate 函数 ,子查询 和原生SQL查询。Hibernate 函数 ,子查询 和原生SQL查询 立即下载

相关推荐

hibernate 执行原生sql的几种方式

NULL 博文链接:https://ynp.iteye.com/blog/2007053

hibernate 各历史版本下载

有时候要查阅Hibernate 源码,记一下源码下载地址,当然可以直接用Maven 自动下载源码,但有时需要看doc文档 http://sourceforge.net/projects/hibernate/files/

jxchallenger的专栏 1840

hibernate-3.2.7.ga.zip

hibernate-3.2.7.ga.zip string struts hibernate 3.2.7

hibernate 方言org.hibernate.dialect.SQLServer2005Dialect导致字段分析不正确的问题

由于 org.hibernate.dialect.SQLServerDialect 方言中的分页不是真分页 所以用了org.hibernate.dialect.SQLServer2005Dialect作为方言 但是之后出现一个郁闷的问题。我的一个表里面有一个字段名称是distinct_code,因为某程序员设计表的时候,把单词写错了,本来应该是district_code的。写错的结果就是,hi...

meiweirenjian的专栏 1023

SQL2005利用ROW_NUMBER() OVER实现分页功能

SQL2005利用ROW_NUMBER() OVER实现分页功能,需要的朋友可以参考下

【文章阅读+代码复现】Point-GNN

Brief 在3D点云语义分割方法中,GNN已经做了很多可用的方案,但是在目标检测上依旧是采用比较传统的CNN和稀疏卷积的组合,这一篇文章是研究了图卷积在3D检测的中的用法。来自卡内基梅隆大学。已经被CVPR2020接收. 这里是 paper 这里是 code Abstruct 一个采用GNN设计的3D目标检测框架 过程是先将点云场景编码成图结构,随后设计了一个叫point-GNN的网络结构,在...

有所为,有所成长 1万+

Hibernate5+sqlserver2008 分页问题

 Hibernate 发布了最新版本 5.2,恰好公司要做个新项目,我是比较喜欢冒险的,所有决定采用 spring4+Hibernate5,各种搜索,各种配置之后,框架终于跑起来了,当测试到分页的时候出现了一个很意外的错误,下面详细描述下错误的过程 1、分页代码 public  List> findByPageMap(final String hql, final Object[] pa

jackwang1的博客 1951

Ubuntu22.04安装搜狗输入法踩坑实录:从依赖报错到完美解决的完整指南

本文详细解析了在Ubuntu 22.04系统上安装搜狗拼音输入法的完整流程,从解决依赖报错到配置fcitx框架,再到最终优化使用体验。针对常见的dpkg安装错误和fcitx冲突问题,提供了实用的解决方案和命令,帮助用户顺利完成安装并享受流畅的中文输入体验。

palm99的专栏 971

Hibernate 自定义dialect(SQLServer)

    参考: 1.http://dingren.blog.51cto.com/4586729/1093242 2.http://tech.ccidnet.com/art/3539/20070717/1146833_1.html        hibernate 在查询一些大数据类型如:varchar(max)时,会报“ No Dialect mapping for JDBC t...

dampce32的专栏 1775

浮点数运算的陷阱与启示:FP16加法器/乘法器开发中的常见误区

本文深入探讨FP16加法器和乘法器开发中的常见误区,包括FP16格式解析、阶码对齐陷阱、尾数运算风险及规格化处理。通过Verilog实战代码展示防御性编程技巧,帮助开发者避免边界条件处理和异常状态管理中的错误,提升硬件设计的可靠性和效率。

dell8的博客 249

【Halcon】双目立体视觉引导机械手有序抓取,案例分享

本文介绍了一个基于双目视觉的工件定位与抓取系统。该系统使用两个工业相机组成双目视觉系统,通过标定获取相机参数,采用模板匹配算法识别任意摆放且可能交叠的工件。重点阐述了三维坐标获取方法,特别是通过Z方向高度实现有序抓取的策略。文章详细说明了系统搭建、双目标定、模板创建等关键步骤,并展示了特征点匹配和定位结果。该案例为初学者和开发者提供了双目视觉系统的基本实现参考,展示了机器视觉与机械手协同工作的典型应用场景。

机器视觉从业者 2489

Hibernate3.2对sqlserver2005查询分页的处理

对Hibernate的查询分页,想必大家都比较熟悉了。setFirstResult()和setMaxResults()就可以搞定。但是使用sqlserver的朋友发现了吗,hibernate发送的分页语句中总是会有令人心烦的"select top 数字" 这样的字符串。比如你一页显示50条记录,现在要查询第100页的数据,则会出现"select top 50000"这样的语句,它是先把前5000条

远 823

1.14、基于NARX神经网络的磁悬浮建模(matlab)

数据准备:首先,需要准备用于训练和测试的磁悬浮系统的输入和输出数据,包括磁力、电流、位置、速度等信息。数据可以被保存在MATLAB的数据文件中,并加载到工作空间中。使用MATLAB的神经网络工具箱,创建一个NARX神经网络。需要定义网络的层次结构、节点数、激活函数等参数。通常,NARX网络包括自回归层和外部输入层。数据预处理:对加载的数据进行预处理,包括去除噪声、归一化处理等操作,以确保数据质量和网络训练的稳定性。使用MATLAB的训练函数,如trainlm或者trainbr,对NARX神经网络进行训练。

XU157303764的博客 1997

hibernate 对 sql server 2005 分页改进

Hibernate 可以实现分页查询 如下 Query q = session.createQuery("from Cat as c"); q.setFirstResult(10000); q.setMaxResults(20); List l = q.list(); 生成的sql 语句为 select top 10000 .... from Cat as c 分析:Hiberna

ye1992的专栏 2569

VisionPro 机器视觉案例 之 彩色保险丝个数统计

CogColorSegmenterTool CogColorMatchTool

机器视觉李小白的博客 2352

YOLOv9改进,YOLOv9添加CBAM注意力机制

CBAM是一个简单而有效的注意力模块,用于前馈卷积神经网络。给定一个中间特征图,我们的模块按顺序推断两个独立维度(通道和空间)的注意力图,然后将注意力图乘以输入特征图以进行自适应特征细化。由于 CBAM 是一个轻量级的通用模块,因此它可以无缝集成到任何 CNN 架构中,开销可以忽略不计,并且可以与基础 CNN 一起进行端到端训练。论文链接:(CBAM论文)

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 856

Hibernate5.1+Sqlserver2000分页查询

前几天改到一个bug:从MS SQLserver上面同步表结构并且采集数据写入其他库。然后用的核心技术是用的Hibernate。 其中bug出在SQLServer2000版本上。排查下来发现2000版本真的是一个让人头疼的数据库。 驱动jar包不兼容;hibernate5.1分页查询也不能用。系统表也与其他版本的天差地别。 一、驱动问题 一开始上网查询,发现大家都推荐用JTDS驱动。...

weixin_30480651的博客 209

UWB:FiRa Consortium UCI Generic Technical Specification v1.1.0(1)- UCI架构和通用数据包头

如果大家学习过WiFi的SPEC,比如从我的资源里面下载 IEEE 802.11-2007,应该很容易发现,FiRa的spec定义实在是太差了。有现成的好例子不学,非得自己来一套,搞一堆新的名词,其实都是一个意思。比如GID,OID等,而且GID、OID是最先出现的,但是对应表格 还得去附件的最后一项去找。 FiRa是UWB联盟,希望跟WIFi联盟学习一下,把UWB做大做强,而不是自成一派,自命不凡。

Ankie资深技术项目经理 2434

Hibernate3.2 中使用视图 查询记录重复

这次在优化系统中,由于客户使用的SQL server 2005的标准版,此版本不支持分区功能,但如果不分区,系统优化的效果就不会很明显。后来使用了分区视图。  在系统中,没有使用对象关联,发现很多地方为查询信息,多次读取数据库。后来也用视图进行封装。       本文就讨论在Hibernate3.2如何配合使用数据库视图技术。      1, 使用分区视图      2, 使用视图

学习园地 1820

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

在MyEclipse下如何添加hibernate支持 (全)【转】

在网络资源中有很多S2HS整合的文档和教程,但是真正适合初学者的少之又少,初学者在整合的时候经常会遇到这样活着那样的错误,今天我就把自己在实践中的详细过程都记录下来,希望对自己,对学习S2HS的初学者都有些帮助。 MyEclipse创建一个Hibernate应用的开发步骤: Ø 创建工程 Ø 切换到MyEclipse Database Explorer透视图 Ø 在MyEcl...

houchangxi的专栏 274

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

3.2javaEE_ssh_SQL Server 2005学生信息管理系统(源码+数据库sql+lun文)————源码私信博主

JAVA学生信息管理系统 摘 要 随着科学技术的不断提高,尤其是计算机科学技术的日渐成熟,其强大的功能和高速的运行速度已为人们深刻认识,它已进入人类社会的各个领域并发挥着越来越重要的作用。使用计算机对学生档案信息进行管理,具有手工管理无法比拟的优点。如:检索快速、便于查找、规范管理、科学化的统计、处理速度快、可靠性很高、存储量很大、保密性好、寿命长、成本低等,这些优点能够极大地提高学生档案管理的效率。学生管理系统对于学校的决策者和管理者来说起着至关重要的作用,是一所学校必不可少的管理工具,能够为用户提供充足

fshao123的博客 381

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

面试题:如何对查询结果进行分页显示

原文在论坛:http://topic.csdn.net/u/20090811/18/b3507163-995c-44c9-a92f-5f0807f6b29a.html 引用169楼的回复吧!    分页有真分页和假分页,假分页就是把数据全部取出,在显示出来之前处理要显示多少记录,而真分页是在数据库拿出一页数据的数据直接显示。假分页效率低下,占用服务器和客户端资源大,如果数据

老紫竹的专栏 6824

Hibernate 4.3.7 可编程方式+注解

1.复制jar文件到lib antlr-2.7.7.jardbmysql.jardboracle.jardbsqljdbc2005.jardom4j-1.6.1.jarhibernate-commons-annotations-4.0.5.Final.jarhibernate-core-4.3.7.Final.jarhibernate-jpa-2.1-api-1.0.0.Final.j...

badaoxu7493的博客 177

四种 Sql Server分页查询

给初学者分享四种 Sql Server分页查询使用示例   当我们显示列表信息的时候,我们常常以分页形式显示,当然在ASP.NET中的ListView和GridView控件等都自带了分页功能,但是效率很低,无法适用大量数据,并且灵活性不高。因而我们一般都使用第三方分页控件或者自己编写分页程序。那么在基于ADO.NET中实现自定义分页的第一步也就是最关键一步必然是要写分页SQL语句,而且语句效

491

分页~~

1.分页有真分页和假分页,假分页就是把数据全部取出,在显示出来之前处理要显示多少记录,而真分页是在数据库拿出一页数据的数据直接显示。假分页效率低下,占用服务器和客户端资源大,如果数据量很大,会造成成服务器内存不足而使程序异常,所以不推荐使用。而真分页依赖数据库支持,核心思想就是从行号 为startRow 的记录开始拿数据,拿一个pageSize 的数据。 SQL Server2005...

weixin_34352449的博客 81
上一篇: sql server 2005 还原备份数据库
下一篇: apue.2e 源码在 Freebsd 9.0 下编译
rootcn
博客等级 码龄23年 27粉丝 91原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值