再见,MybatisPlus!

解密 MyBatis 插件链:为什么你的自定义插件被分页插件 “堵“ 住了? 在 MyBatis 的分页插件设计中,通常会在 intercept 方法中对 SQL 语句进行修改,而不是直接调用 invocation.proceed()。这是因为分页插件的主要目的是修改 SQL 语句,使其包含分页逻辑(例如添加 LIMIT 和 OFFSET 子句),而不是简单地继续执行原生的 SQL 语句。拦截 SQL 语句:当 MyBatis 准备执行一个 SQL 语句时,分页插件会在 intercept 方法中拦截到这个 SQL 语句。 阅读详情

推荐关注

后端架构师

后端架构师

专注研究 Java 核心技术、架构,不限于分享算法、架构、高并发、多线程、JVM、Spring Boot、Maven、分布式、Spring Cloud +Docker+k8s、Dubbo、Zookeeper、Kafka、RocketMQ等。

公众号

顶级架构师后台回复 1024 有特别礼包

来源:juejin.cn/post/6886019929519177735

上一篇:深圳一普通中学老师工资单曝光,秒杀程序员,网友:敢问是哪个学校毕业的?

大家好,我是顶级架构师。

使用 fluent mybatis 可以不用写具体的 xml 文件,通过 java api 可以构造出比较复杂的业务 sql 语句,做到代码逻辑和 sql 逻辑的合一。

使用 fluent mybatis 可以不用写具体的 xml 文件,通过 java api 可以构造出比较复杂的业务 sql 语句,做到代码逻辑和 sql 逻辑的合一。不再需要在 Dao 中组装查询或更新操作,在 xml 或 mapper 中再组装参数。那对比原生 Mybatis, Mybatis Plus 或者其他框架,FluentMybatis 提供了哪些便利呢?

我们通过一个比较典型的业务需求来具体实现和对比下,假如有学生成绩表结构如下:

create table `student_score`
(
    id           bigint auto_increment comment '主键ID' primary key,
    student_id   bigint            not null comment '学号',
    gender_man   tinyint default 0 not null comment '性别, 0:女; 1:男',
    school_term  int               null comment '学期',
    subject      varchar(30)       null comment '学科',
    score        int               null comment '成绩',
    gmt_create   datetime          not null comment '记录创建时间',
    gmt_modified datetime          not null comment '记录最后修改时间',
    is_deleted   tinyint default 0 not null comment '逻辑删除标识'
) engine = InnoDB default charset=utf8;
复制代码

现在有需求:

统计 2000 年三门学科 ('英语', '数学', '语文') 及格分数按学期, 学科统计最低分,最高分和平均分, 且样本数需要大于 1 条, 统计结果按学期和学科排序

我们可以写 SQL 语句如下

select school_term,
       subject,
       count(score) as count,
       min(score)   as min_score,
       max(score)   as max_score,
       avg(score)   as max_score
from student_score
where school_term >= 2000
  and subject in ('英语', '数学', '语文')
  and score >= 60
  and is_deleted = 0
group by school_term, subject
having count(score) > 1
order by school_term, subject;
复制代码

那上面的需求,分别用 fluent mybatis, 原生 mybatis 和 Mybatis plus 来实现一番。

使用 fluent mybatis 来实现上面的功能

图片

具体代码

我们可以看到 fluent api 的能力,以及 IDE 对代码的渲染效果。

换成 mybatis 原生实现效果

  1. 定义 Mapper 接口

public interface MyStudentScoreMapper {
    List<Map<String, Object>> summaryScore(SummaryQuery paras);
}
复制代码

  1. 定义接口需要用到的参数实体 SummaryQuery

@Data
@Accessors(chain = true)
public class SummaryQuery {
    private Integer schoolTerm;

    private List<String> subjects;

    private Integer score;

    private Integer minCount;
}
复制代码

  1. 定义实现业务逻辑的 mapper xml 文件

<select resultType="map" parameterType="cn.org.fluent.mybatis.springboot.demo.mapper.SummaryQuery">
    select school_term,
    subject,
    count(score) as count,
    min(score) as min_score,
    max(score) as max_score,
    avg(score) as max_score
    from student_score
    where school_term >= #{schoolTerm}
    and subject in
    <foreach collection="subjects" item="item" open="(" close=")" separator=",">
        #{item}
    </foreach>
    and score >= #{score}
    and is_deleted = 0
    group by school_term, subject
    having count(score) > #{minCount}
    order by school_term, subject
</select>
复制代码

  1. 实现业务接口 (这里是测试类, 实际应用中应该对应 Dao 类)

@RunWith(SpringRunner.class)
@SpringBootTest(classes = QuickStartApplication.class)
public class MybatisDemo {
    @Autowired
    private MyStudentScoreMapper mapper;

    @Test
    public void mybatis_demo() {
        
        SummaryQuery paras = new SummaryQuery()
            .setSchoolTerm(2000)
            .setSubjects(Arrays.asList("英语", "数学", "语文"))
            .setScore(60)
            .setMinCount(1);

        List<Map<String, Object>> summary = mapper.summaryScore(paras);
        System.out.println(summary);
    }
}
复制代码

总之,直接使用 mybatis,实现步骤还是相当的繁琐,效率太低。那换成 mybatis plus 的效果怎样呢?

搜索公众号Linux中文社区后台回复“私房菜”,获取一份惊喜礼包。

换成 mybatis plus 实现效果

mybatis plus 的实现比 mybatis 会简单比较多,实现效果如下

图片

如红框圈出的,写 mybatis plus 实现用到了比较多字符串的硬编码(可以用 Entity 的 get lambda 方法部分代替字符串编码)。字符串的硬编码,会给开发同学造成不小的使用门槛,个人觉的主要有 2 点:

  1. 字段名称的记忆和敲码困难

  2. Entity 属性跟随数据库字段发生变更后的运行时错误

其他框架,比如 TkMybatis 在封装和易用性上比 mybatis plus 要弱,就不再比较了。

fluent mybatis 生成代码设置

public class AppEntityGenerator {
    static final String url = "jdbc:mysql://localhost:3306/fluent_mybatis_demo?useSSL=false&useUnicode=true&characterEncoding=utf-8";

    public static void main(String[] args) {
        FileGenerator.build(Abc.class);
    }

    @Tables(
        /** 数据库连接信息 **/
        url = url, username = "root", password = "password",
        /** Entity类parent package路径 **/
        basePack = "cn.org.fluent.mybatis.springboot.demo",
        /** Entity代码源目录 **/
        srcDir = "spring-boot-demo/src/main/java",
        /** Dao代码源目录 **/
        daoDir = "spring-boot-demo/src/main/java",
        /** 如果表定义记录创建,记录修改,逻辑删除字段 **/
        gmtCreated = "gmt_create", gmtModified = "gmt_modified", logicDeleted = "is_deleted",
        /** 需要生成文件的表 ( 表名称:对应的Entity名称 ) **/
        tables = @Table(value = {"student_score"})
    )
    static class Abc {
    }
}
复制代码

mybatis plus 代码生成设置

public class CodeGenerator {

    static String dbUrl = "jdbc:mysql://localhost:3306/fluent_mybatis_demo?useSSL=false&useUnicode=true&characterEncoding=utf-8";

    @Test
    public void generateCode() {
        GlobalConfig config = new GlobalConfig();
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL)
            .setUrl(dbUrl)
            .setUsername("root")
            .setPassword("password")
            .setDriverName(Driver.class.getName());
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig
            .setCapitalMode(true)
            .setEntityLombokModel(false)
            .setNaming(NamingStrategy.underline_to_camel)
            .setColumnNaming(NamingStrategy.underline_to_camel)
            .setEntityTableFieldAnnotationEnable(true)
            .setFieldPrefix(new String[]{"test_"})
            .setInclude(new String[]{"student_score"})
            .setLogicDeleteFieldName("is_deleted")
            .setTableFillList(Arrays.asList(
                new TableFill("gmt_create", FieldFill.INSERT),
                new TableFill("gmt_modified", FieldFill.INSERT_UPDATE)));

        config
            .setActiveRecord(false)
            .setIdType(IdType.AUTO)
            .setOutputDir(System.getProperty("user.dir") + "/src/main/java/")
            .setFileOverride(true);

        new AutoGenerator().setGlobalConfig(config)
            .setDataSource(dataSourceConfig)
            .setStrategy(strategyConfig)
            .setPackageInfo(
                new PackageConfig()
                    .setParent("com.mp.demo")
                    .setController("controller")
                    .setEntity("entity")
            ).execute();
    }
}
复制代码

图片

看完 3 个框架对同一个功能点的实现, 各位看官肯定会有自己的判断,笔者这里也总结了一份比较。

图片

图片

 

公众号后台回复 架构 或者 架构整洁 有惊喜礼包!

顶级架构师交流群

 「顶级架构师」建立了读者架构师交流群,大家可以添加小编微信进行加群。欢迎有想法、乐于分享的朋友们一起交流学习。

图片

扫描添加好友邀你进架构师群,加我时注明【姓名+公司+职位】

版权申明:内容来源网络,版权归原作者所有。如有侵权烦请告知,我们会立即删除并表示歉意。谢谢。

猜你还想看

一文搞懂四种同步工具类
单点登录系统用 8 张漫画就解释了
阿里技术专家:一文教你高效画出技术架构图
Sharding-Jdbc实现读写分离、分库分表

图片

nginx+keepalived高可用 两台服务器上的keepalive是靠相互通讯来判断的,如果一台服务器上keepalived挂掉了,keepalived就会把虚拟的ip就会转移到备用的nginx服务器上,实现服务转移。keepalive只能相互检查对方的进程是否还存活,所以对nginx没有任何一点监控作用,当nginx宕机后,keepalived进程还存活着就会导致web项目无法访问,所以后续需要编写一个shell脚本来完成对nginx进程的判断。在高可用架构中,Nginx 常用作前端的负载均衡器,将流量分发到多个后端服务器上。 阅读详情

相关推荐

详细推导波特图增益和相位曲线

文章来源:https://mp.weixin.qq.com/s/UCy9mRRok5Hc9qHq3qde5g 今天这篇文章想把近段时间关于波特图方面学习的内容整理一下。波特图将会是梳理闭环控制这个系列的开始。目前的计划是,以无源器件为基础,然后结合运放,再过渡到开关电源的环路控制方面。如果对这方面感兴趣的朋友,可以持续一起学习起来,目标就是掌握开关电源的闭环控制。 1. 什么是波特图? 波特图最常见的应用是在线性非时变的系统中,用于对传递函数的增益和相位进行分析,从而判断出系统随频率的响应是否稳定。因此,波

ltqdxl的博客 2万+

MyBatis过时了吗?

点击下方“JavaEdge”,选择“设为星标”第一时间关注技术干货!免责声明~任何文章不要过度深思!万事万物都经不起审视,因为世上没有同样的成长环境,也没有同样的认知水平,更「没有适用于所有人的解决方案」;不要急着评判文章列出的观点,只需代入其中,适度审视一番自己即可,能「跳脱出来从外人的角度看看现在的自己处在什么样的阶段」才不为俗人。怎么想、怎么做,全在乎自己「不断实践中寻找适合自己的大道」是...

JavaEdge全是干货的技术号 366

深入GSConv代码:逐行解析这个混合了标准卷积与深度可分离卷积的‘新算子’

本文深入解析GSConv代码,详细介绍了这个混合标准卷积与深度可分离卷积的‘新算子’的设计哲学与实现框架。通过PyTorch代码逐行分析,揭示GSConv如何在轻量级卷积神经网络中平衡计算效率与特征表达能力,特别适用于Slim-Neck架构,显著降低计算量同时保持高精度。

weixin_29860267的博客 323

再见 MyBatis-Plus !

一、Mybatis-Flex是什么?Mybatis-Flex 是一个优雅的 Mybatis 增强框架,它非常轻量、同时拥有极高的性能与灵活性。我们可以轻松的使用 Mybaits-Flex 链接任何数据库,其内置的 QueryWrapper^亮点 帮助我们极大的减少了 SQL 编写的工作的同时,减少出错的可能性。总而言之,MyBatis-Flex 能够极大地提高我们的开发效率和开发体验,让我们有更多...

公众号-老炮说Java 198

告别卡顿闪烁!在Cesium 1.134中集成SOG格式,让400万高斯秒级加载

本文详细介绍了如何在Cesium 1.134中集成SOG格式,实现400万高斯数据的秒级加载,解决传统加载方式导致的卡顿和闪烁问题。通过空间索引重构、属性量化编码和WebGPU原生支持等技术,SOG格式显著提升了三维地理空间可视化的性能。文章还提供了环境准备、模型转换和Cesium集成的实战指南,帮助开发者高效优化项目。

weixin_29313817的博客 499

vue-vben-admin 打包编译报错Failed to resolve entry for package “@vben-core/design“ 的解决方法

如果你在你是不是在 apps/子目录下执行了 build?# 项目根目录 pnpm build而不是在下面单独打包。这个问题本身不复杂,但非常容易被误导去“怀疑依赖、怀疑配置、怀疑人生”。实际上,只要理解vue-vben-admin 是 monorepo 架构,很多类似问题都会迎刃而解。如果你后面还遇到 vben-admin 的构建、部署、权限或性能相关问题,这一套思路都很有用。希望这篇记录,能帮你节省至少半小时的排坑时间。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 425

Mybatis-Plus详解

Mybatis-Plus是一个Mybatis(opens new window)的增强工具,在Mybatis的基础上只做增强不做改变,为简化开发。无侵入:只做增强不做改变,引入它不会对现有工程产生影响。 损耗小:启动即会自动注入基本CURD,性能基本无损耗,直接面向对象操作。 强大的CRUD操作:内置通用Mapper、通用Service,仅仅通过少量配置即可实现单表大部分CRUD操作,更有强大的条件构造器,满足各类使用需求。支持Lambda形式调用:通过 Lambda 表达式,方便的编写各类查询条件,无需

互联网底层民工的博客 7万+

【小白深度教程 1.32】手把手教你从多视角图像进行 3D 重建(SfM 算法)

重建的目标是从一组照片中推导场景的几何结构,假设摄像机位置和内部参数是已知的或可以从图像集中猜测。 这是通过使用多个照片,在其中应用运动结构法(Structure from Motion,SfM)来解决像素级对应问题,部分地恢复3D信息来实现的。

2401_87064292的博客 2160

mybatis-plus的使用

前言: mybatis在持久层框架中还是比较火的,一般项目都是基于ssm。虽然mybatis可以直接在xml中通过SQL语句操作数据库,很是灵活。但正其操作都要通过SQL语句进行,就必须写大量的xml文件,很是麻烦。mybatis-plus就很好的解决了这个问题。 一、mybatis-plus简介: Mybatis-Plus(简称MP)是一个 Mybatis 的增强工具,在 Mybatis 的基础...

weixin_44195615的博客 1600

Linux系统安装部署Redis完整教程(图文详解)

最近需要在Linux服务器安装部署Redis,参考了网上很多的文章,比较零碎,所以我自己写了一篇完整的Redis安装部署文档,在部署Redis之前重装了我的华为服务器,就是为了给大家一步步阐述我的操作过程,配合图文进行讲解更加通俗易懂!

黄团团的个人博客 6695

【推荐100个unity插件】unity易于使用模块化设计的天空、体积云和天气系统——Enviro 3

Enviro 3是一款功能强大的Unity天空与天气系统插件,提供动态天空、体积云、天气模拟等丰富功能。安装时需将预制体拖入场景并配置主相机,URP支持需激活深度纹理和添加渲染特性。模块化设计允许自由添加/移除时间、光照、雾效等模块,并通过API控制参数。推荐配合色调映射(如ACES模式)获得最佳视觉效果。插件支持季节、温湿度模拟及闪电风暴等特效,适用于需要逼真环境渲染的Unity项目。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 2096

再见MybatisPlus,阿里推出新ORM框架!

原文:https://juejin.cn/post/6886019929519177735使用 fluent mybatis 可以不用写具体的 xml 文件,通过 java api 可以构...

java思维导图 153

YOLOv9 损失函数解析

YOLOv9作为YOLO系列的最新成员,在损失函数设计上进行了多项创新,重点优化了动态任务对齐机制、多模态定位损失融合以及跨层级梯度协同,进一步提升了检测精度与训练效率。

浩瀚之水的专栏 1293

再见 MybatisPlus,阿里推出新 ORM 框架!

以下内容来自公众号逆锋起笔,关注每日干货及时送达来自:掘金,作者:稻草江南链接:https://juejin.cn/post/6886019929519177735使用fluent myb...

code小生 199

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

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

上一篇: Sharding-Jdbc实现读写分离、分库分表
下一篇: 分享一套开源的即时通讯 IM 聊天系统(附源码)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值