springbatch入门练习(第一篇)

先搞懂几个概念

Job Respository: 作业仓库,负责Job、Step执行过程中的状态保存

Job launcher: 作业调度器,提供执行Job的入口

Job:作业,由多个step组成,封装整个批处理操作

Step:作业步,Job的一个执行环节,由多个或者一个step组装成Job

Tasklet:step中具体执行逻辑的操作,可以重复执行,可以设置具体的同步、异步操作等

Chunk: 给定数量Item的集合,可以定义对Chunk的读操作、处理操作、写操作、提交间隔等

Item:一条数据记录

ItemReader:从数据源中读取Item

ItemProcessor:在Item写入数据源之前,对数据进行处理

ItemWriter:将Item批量写入数据源

实战部分

使用maven创建的工程

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>core-batch</groupId>
  <artifactId>core-batch</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>core-batch</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
     <dependency>
         <groupId>org.springframework.batch</groupId>
         <artifactId>spring-batch-infrastructure</artifactId>
         <version>3.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.batch</groupId>
        <artifactId>spring-batch-core</artifactId>
        <version>3.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.batch</groupId>
        <artifactId>spring-batch-test</artifactId>
        <version>3.0.1.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

 

定义对象领域

package com.batman.core.batch;

//定义领域对象
public class CreditBill {
    private String accountID = "";
    private String name = "";
    private double amount = 0;
    private String date;
    private String address;
    
    public String getAccountID() {
        return accountID;
    }
    public void setAccountID(String accountID) {
        this.accountID = accountID;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public double getAmount() {
        return amount;
    }
    public void setAmount(double amount) {
        this.amount = amount;
    }
    public String getDate() {
        return date;
    }
    public void setDate(String date) {
        this.date = date;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    
}

定义数据处理类

package com.batman.core.batch;

import org.springframework.batch.item.ItemProcessor;

public class CreditBillProcessor implements ItemProcessor<CreditBill, CreditBill>{

    public CreditBill process(CreditBill bill) throws Exception {
        System.out.println(bill.toString());
        return bill;
    }
}

创建配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"    
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p"    
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:aop="http://www.springframework.org/schema/aop"    
    xmlns:context="http://www.springframework.org/schema/context"    
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
    http://www.springframework.org/schema/tx  
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
    http://www.springframework.org/schema/aop  
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context-2.5.xsd"    
    default-autowire="byName">
    <!-- 配置任务仓库 -->
    <bean id="jobRepository" 
        class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
    </bean>
    <!-- 配置任务调度器  用来启动Job-->
    <bean id="jobLauncher" 
        class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
        <property name="jobRepository" ref="jobRepository"/>
    </bean>
    <!-- 配置事务管理器 -->
    <bean id="transactionManager" 
        class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"/>
</beans>

创建job

<?xml version="1.0" encoding="UTF-8"?>
<bean:beans xmlns="http://www.springframework.org/schema/batch"    
    xmlns:bean="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:tx="http://www.springframework.org/schema/tx"    
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:context="http://www.springframework.org/schema/context"    
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/batch 
    http://www.springframework.org/schema/batch/spring-batch-2.2.xsd">
    <bean:import resource="classpath:job-context.xml"/>
    <!-- 定义一个批处理作业 -->
    <job id="billJob">
        <!-- 定义个billStep的作业步,有一个面向批的操作组成 -->
        <step id="billStep">
            <!-- 定义批处理操作采用定义的事务管理器,负责批处理中事务管理操作 -->
            <tasklet transaction-manager="transactionManager">
                <!-- 定义了面向批的操作,定义了读操作csvItemReader,处理操作 creditBillProcessor,写操作csvItemWriter
                 commit-interval表示提交间隔的大小,即每处理两条数据进行一次写操作-->
                <chunk reader="csvItemReader" writer="csvItemWriter" 
                    processor="creditBillProcessor" commit-interval="2">
                </chunk>
            </tasklet>
        </step>
    </job>
    <!-- 读取信用卡账单文件,CSV格式 -->
    <bean:bean id="csvItemReader"
        class="org.springframework.batch.item.file.FlatFileItemReader" 
        scope="step">
        <!-- 读取文件资源 -->
        <bean:property name="resource" value="classpath:credit-card-bill-201303.csv"/>
        <!-- 通过lineMapper可以把文本中的一行转换成领域对象CreditBill -->
        <bean:property name="lineMapper">
            <bean:bean 
                class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
                <!-- 定义文本中的分割符号 -->
                <bean:property name="lineTokenizer" ref="lineTokenizer"/>
                <!-- 根据lineTokenizer中定义的names属性映射到creditBill中,最终组装成信用卡账单对象 -->
                <bean:property name="fieldSetMapper">
                    <bean:bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
                        <bean:property name="prototypeBeanName" value="creditBill">
                        </bean:property>
                    </bean:bean>
                </bean:property>
            </bean:bean>
        </bean:property>
    </bean:bean>
    <!-- lineTokenizer -->
    <bean:bean id="lineTokenizer" 
        class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
        <bean:property name="delimiter" value=","/>
        <bean:property name="names">
            <bean:list>
                <bean:value>accountID</bean:value>
                <bean:value>name</bean:value>
                <bean:value>amount</bean:value>
                <bean:value>date</bean:value>
                <bean:value>address</bean:value>
            </bean:list>
        </bean:property>
    </bean:bean>
    
    <!-- 写信用卡账单文件,CSV格式 -->
    <bean:bean id="csvItemWriter" 
        class="org.springframework.batch.item.file.FlatFileItemWriter" 
        scope="step">
        <bean:property name="resource" value="file:target/outputFile.csv"/>
        <bean:property name="lineAggregator">
            <bean:bean 
                class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
                <bean:property name="delimiter" value=","></bean:property>
                <bean:property name="fieldExtractor">
                    <bean:bean 
                        class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
                        <bean:property name="names" 
                             value="accountID,name,amount,date,address">
                        </bean:property>
                    </bean:bean>
                </bean:property>
            </bean:bean>
        </bean:property>
    </bean:bean>
    
    <bean:bean id="creditBill" scope="prototype"
        class="com.batman.core.batch.CreditBill">
    </bean:bean>
    <!-- 负责处理读入的数据 -->
    <bean:bean id="creditBillProcessor" scope="step"
        class="com.batman.core.batch.CreditBillProcessor">
    </bean:bean>
</bean:beans>

创建main

package com.batman.core.batch;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class JobLaunch {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext(
                "job.xml");
        //获取作业调度器
        JobLauncher launcher = (JobLauncher) context.getBean("jobLauncher");
        //获取任务对象
        Job job = (Job) context.getBean("billJob");
        try {
            //通过JobLauncher的run方法执行billJob任务
            JobExecution result = launcher.run(job, new JobParameters());
            System.out.println(result.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

 

转载于:https://www.cnblogs.com/mutong1228/p/9048633.html

SpringBatch4升级SpringBatch5踩坑指南 springbatch4升级springbatch5指南,全面踩坑,报错,位置,参考,解决方案等 阅读详情

相关推荐

SpringBatch

根据Spring官网描述,Spring Batch是一个轻量级的、完善的批处理应用框架,旨在支持企业系统建立健壮、高效的批处理应用。然而Spring Batch不是一个调度框架,它只关注于任务的处理,如日志监控、事务、并发问题等,但是它可以与其它调度框架一起联合使用,完成相应的调度任务,如Quartz、Tivoli、Control-M等。Spring Batch提供了很多非常实用的组件,包括了日志/跟踪、事务管理、作业处理统计、作业重新启动、跳过和资源管理。它还提供了更先进的技术服务和功能,支持通过。

weixin_46228563的博客 1383

Spring-Batch学习总结(1)——重要概念,环境搭建,名词解释,第一个项目及异常处理...

Spring-batch框架学习总结(1)一.初识Spring-batch框架:1.核心名词解释:Job:是Spring-batch框架的核心概念,它包含了批处理的所有操作Step:每一个Job由一个或多个Step组成,每个Step中涉及到itemReader,itemProcessor,ItemWriter,这三个接口顾名思义,一个负责数据源,一个负责业务逻辑,一个负责处理后的数据输出;JobR...

weixin_33853794的博客 244

SpringBatch 事务详解

Spring Batch 是一个强大的批处理框架,它充分利用了 Spring 框架的事务管理机制,以确保批处理任务的数据一致性和完整性。在 Spring Batch 中,事务是一项关键概念,这里将详细解释 Spring Batch 中的事务管理。

境里婆娑 2038

spring batch

@Configuration public class InMemoryJobRepositoryConfig { @Bean public ResourcelessTransactionManager transactionManager() { return new ResourcelessTransactionManager(); } @B...

じ★vevan的专栏 380

SpringBatch批处理框架入门(二)

这篇文章接上一篇SpringBatch批处理框架入门(一),继续讲解SpringBatch基础知识。 SpringBatch 核心类介绍 下图是我们要讲解spring batch几个核心类: SpringBatch 核心类Job Job是封装整个批处理过程的一个概念。Job在spring batch的体系当中是一个最顶层的抽象概念。 一个job是我们运行的基本单位,它内部由step组成。job本质上可以看成step的一个容器。一个job可以按照指定的逻辑顺序组合step,并提供了我们给所有s.

境里婆娑 1661

史上最全的SpringBatch学习教程

写在前面: 我是「境里婆娑」。我还是从前那个少年,没有一丝丝改变,时间只不过是考验,种在心中信念丝毫未减,眼前这个少年,还是最初那张脸,面前再多艰险不退却。 写博客的目的就是分享给大家一起学习交流,如果您对 Java感兴趣,可以关注我,我们一起学习 相关文章: 今天我把写过的SpringB系列的文章全部整理在此,方便大家学习查看!博客里面都是基于 Spring Boot 2.2.2 版本的学习...

境里婆娑 4248

Spring Batch 批处理框架优化实践,效率嘎嘎高!

程序员的成长之路互联网/程序员/技术/资料共享关注阅读本文大概需要 12 分钟。来自:blog.csdn.net/u010349629/article/details/130673379一、Spring Batch简介1 框架概述2 核心概念和组件二、批处理优化实践4.1 使用Spring Boot Actuator进行监控4.2 使用管理控制台来监控3.1 批处理启动前校验3.2 读写校验2....

良月柒 540

ENSP:小型企业网络拓扑设计

包含的技术:ospf、dhcp中继、ac+ap、vrrp+mstp、acl、浮动路由、静态路由、vlan划分

weixin_45921302的博客 1万+

Spring Batch 构建企业级批处理应用

使用 Spring Batch 构建企业级批处理应用: 第 1 部分   Spring Batch 是一款基于 Spring 的批处理框架,通过它可以轻易构建出高内聚、低耦合的企业批处理应用。通过本文您可以一步步了解如何开发基于 Spring Batch 的批处理程序。同时,本文还介绍了 Spring Batch 的相关核心概念。 查看本系列更多内容 | 8 评论: ...

xls51314202005的博客 531

H3C-HCL模拟器-STP生成树协议实验

边缘接口的存在是为了提高网络的收敛速度和性能。由于边缘接口连接的是终端设备,这些设备通常不会产生环路,因此不需要参与生成树协议的计算和决策。边缘接口通常是指那些不会连接到其他交换机或生成树的冗余路径的接口。H3C交换机千兆口的cost默认是20,把SW2的g1/0/2接口的cost改为100;SW4是根网桥,根据STP计算,闭塞端口应该在SW1上;方法:使得SW2到SW1的cost比SW4到SW1更大;7)修改配置:把SW1连接PC的所有接口配置为边缘接口。协议的计算开销,提高网络的收敛速度。

网络工程 2997

零基础实战:YOLO检测头自定义替换全攻略

本文为零基础用户提供了YOLO检测头自定义替换的完整实战指南。通过将检测头比作汽车的“方向盘”,文章详细阐述了为何需要替换、如何寻找和集成新检测头模块、修改配置文件以及最终训练验证的全过程,旨在帮助用户针对特定任务(如小目标检测)提升模型性能。

perl8的博客 255

SpringBatch(1):SpringBatch入门

SpringBatch是什么?Spring Batch 是一个轻量级的、完善的批处理框架,旨在帮助企业建立健壮、高效的批处理应用。Spring Batch是Spring的一个子项目,使用Java语言并基于Spring框架为基础开发,使得已经使用Spring框架的开发者更容易访问和利用企业服务。Spring Batch 提供了大量可重复的组件,包括了日志、追踪、事务、任务作业统计、任务重启、跳过、重复、资源管理。

不积跬步,无以至千里 1541

基于YOLOv8的玉米病害监测系统

本研究的主要目标是设计并实现一个基于深度学习的玉米病害识别系统,通过采用YOLOv8算法进行玉米叶片病害的自动化识别。研究首先对玉米病害的种类和特点进行了分析,选择了具有代表性的病害类型,如玉米锈病、灰叶斑病、枯叶病和健康叶片,以构建一个多类别的分类问题。数据集的构建和处理是研究的关键部分,通过数据增强、图像标注等手段确保了数据的多样性和丰富性,从而提高了模型的泛化能力。

yupan__的博客 497

SpringBatch快速入门

SpringBatch是一个轻量级、高效的批处理框架,是Spring框架的一部分。它提供了一种简单而强大的方式来处理大量的数据处理任务,比如数据导入、转换、数据清洗、数据分析等。SpringBatch的核心概念是Job和Step。一个Job由一个或多个Step组成,每个Step包含了一个或多个Task。每个Task代表了一个具体的操作,比如读取文件、处理数据、写入数据库等。Step之间可以有依赖关系,可以串行执行,也可以并行执行。

Flying_Fish_roe的博客 1844

从开源到落地:SimpleBGC 三轴稳像平台全栈技术解析(上)

SimpleBGC是一款开源的稳定云台控制系统,相比专业设备具有显著的价格优势(仅为1/5-1/10),采用模块化设计支持全场景适配。系统包含硬件设计、软件代码和算法三大核心:硬件采用STM32主控和IMU传感器,支持6步换向和FOC电机驱动;软件采用三层架构(驱动层、算法层、应用层),实现姿态解算和PID控制;算法方面提供互补滤波(基础版)和卡尔曼滤波(高端版),可达到±0.5°至±0.1°的稳定精度。该系统适用于无人机航拍、工业检测等多种应用场景,特别适合DIY开发者和中小企业进行定制化开发。

bother3000的博客 3692

Copula函数实战:如何用MATLAB计算气象干旱与农业干旱的联合概率?

本文提供了一份基于MATLAB的Copula函数实战指南,详细阐述了如何利用该多变量联合分布函数计算气象干旱与农业干旱的联合概率及条件概率。通过从数据预处理、边缘分布拟合到Copula模型选择与检验的完整流程,帮助环境科学与农业气象研究者量化干旱事件的关联风险,为风险评估提供定量依据。

weixin_29213655的博客 434

SpringBatch配置与入门实例

通过对SpringBatch基础概念的了解,参考:SpringBatch使用介绍 任何技术用起来之后,再去探究内部细节的原理,才会事半功倍。下面记录一下笔者在SpringBoot项目中集成SpringBatch,并且通过一个小的实例展示如何简单使用它进行批处理。需要引入以下依赖 我这里用的SpringBoot版本是2.7.18,引入spring-boot-starter-batch时不需要再指定版本号,他会自动匹配对应版本,拉去maven依赖。需要新建配置类SpringBatchConfig,用于配置基础的

Alexon Xu的博客 760

【数据集】中国陆地生态系统通量观测网 ChinaFLUX

【数据集】中国陆地生态系统通量观测网 ChinaFLUX

WW、forever的博客 195

【SpringBatch】01简单入门

何为批处理,大白话:就是将数据分批次进行处理的过程。比如:银行对账逻辑,跨系统数据同步等。系统A从数据库中导出数据到文件,系统B读取文件数据并写入到数据库典型批处理特点:自动执行,根据系统设定的工作步骤自动完成数据量大,少则百万,多则上千万甚至上亿。(如果是10亿,100亿那只能上大数据了)定时执行,比如:每天,每周,每月执行。

qq_53433382的博客 2634

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

efm32 入门.pdf

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

00 SpringBatch 4.x.x版本:简单入门

00 SpringBatch 4.x.x版本:简单入门

Eyesmoon的博客 1525

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

SpringBatch入门

springbatch官方入门案例,非网络上最多的千峰视频资源的案例

Amazing66的博客 823

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

SpringBatch概述

1、SpringBatch简介 1.1、简介 根据Spring官网描述,Spring Batch是一个轻量级的、完善的批处理应用框架,旨在支持企业系统建立健壮、高效的批处理应用。然而Spring Batch不是一个调度框架,它只关注于任务的处理,如日志监控、事务、并发问题等,但是它可以与其它调度框架一起联合使用,完成相应的调度任务,如Quartz、Tivoli、Control-M等。 Sprin...

qq_36526036的博客 7962

01.SpringBatch小入门

1、基本语法 这包括static、final、transient等关键字的作用,foreach循环的原理等等。2、集合 非常重要,基本上就是List、Map、Set,各种实现类的底层实现原理,实现类的优缺点。 集合要掌握的是ArrayList、LinkedList、Hashtable、HashMap、ConcurrentHashMap、HashSet的实现原理, (1)ConcurrentHash...

勇敢牛牛 652

SpringBatch文档

第一章 SpringBatch 入门 第一节 SpringBatch概述 Spring Batch 是一个轻量级的、完善的批处理框架,旨在帮助企业建立健壮、高效的批处理应用。Spring Batch是Spring的一个子项目,使用Java语言并基于Spring框架为基础开发,使得已经使用 Spring 框架的开发者或者企业更容易访问和利用企业服务。 Spring Batch 提供了大量可重用的组件...

2108

SpringBatch从入门到精通-1

spring batch简介 Spring Batch架构介绍 Spring Batch核心概念介绍 chunk 处理流程 spring batch简介 spring batch是spring提供的一个数据处理框架。企业域中的许多应用程序需要批量处理才能在关键任务环境中执行业务操作。这些业务运营包括: 自动化、复杂地处理大量信息,无需用户交互即可最高效地处理这些信息。这些操作通常包括基于时间的事件(例如月末计算、通知或通信)。 定期应用..

jackssybin的专栏 676
上一篇: ubuntu 16.04lts 配置rabbitmq的记录
下一篇: https://b.tiles.mapbox.com/v4/mapbox.mapbox-terrain-v2,mapbox.mapbox-streets-v7/15/26919/13562.vecto...
weixin_30950607
博客等级 码龄11年 124粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值