11.Bean使用拾遗(一)

QGroundControl或者华科尔地面站安装完打不开问题解决 QGroundControl 华科尔 打不开 阅读详情

11.Bean使用拾遗(一)

1. 内部bean

<bean id="a" class="com.xxx">
	<properties name="car">
    	<bean class="com.xxx.car" p:name="BMW">
        </bean>
    </properties>
</bean>

2. null值

<bean id="a" class="com.xx">
	<property name="name"><null/></property>
</bean>

3.集合合并,允许子继承父同名集合属性合集

<bean id="parentBoss" class="com.xxx">
	<property name="favorites">
    	<set>
        	<value>看报</value>
            <value>高尔夫</value>
        </set>
    </property>
</bean>

<bean id="chidBoss" class="com.xxx" parent="parentBoss">
	<property name="favorites">
        <set merge="true">
        	<value>爬山</value>
            <value>游泳</value>
        </set>
    </property>
</bean>

4.lookup方法注入

package com.desmond.springlearning.lookup;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author presleyli
 * @date 2018/10/24 下午9:16
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Car {
    private String name;
}

package com.desmond.springlearning.lookup;

/**
 * @author presleyli
 * @date 2018/10/24 下午9:16
 */
public interface CarFactory {
    Car getCar();
}

package com.desmond.springlearning.lookup;

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

/**
 * @author presleyli
 * @date 2018/10/24 下午9:22
 */
public class Test {
    public static void main(String[] args) {
        Resource resource = new ClassPathResource("lookup/application.xml");
        XmlBeanFactory xmlBeanFactory = new XmlBeanFactory(resource);

        CarFactory carFactory = (CarFactory)xmlBeanFactory.getBean("carFactory");

        System.out.println(carFactory.getCar().getName());
    }
}

<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd "
       default-autowire="default">

    <bean id="car" class="com.desmond.springlearning.lookup.Car" p:name="BMW" scope="prototype" />

    <bean id="carFactory" class="com.desmond.springlearning.lookup.CarFactory">
        <lookup-method name="getCar" bean="car"/>
    </bean>

</beans>

5.replace-method(方法替换)

package com.desmond.springlearning.method_replace;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author presleyli
 * @date 2018/10/24 下午9:16
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Car {
    private String name;
}

package com.desmond.springlearning.method_replace;

/**
 * @author presleyli
 * @date 2018/10/24 下午9:33
 */
public class Boss1 {
    public Car getCar() {
        return new Car("BMW");
    }
}


package com.desmond.springlearning.method_replace;

import org.springframework.beans.factory.support.MethodReplacer;

import java.lang.reflect.Method;

/**
 * @author presleyli
 * @date 2018/10/24 下午9:33
 */
public class Boss2 implements MethodReplacer{

    public Object reimplement(Object o, Method method, Object[] objects) throws Throwable {
        System.out.println(o); // 目标对象,即boss1的代理对象
        System.out.println(method); // 目标方法,即boss1.getCar
        System.out.println(objects); // 目标方法的参数,即getCar的参数列表

        // 此行会抛出栈溢出错误
        // 原因:o 为 boss1 cglib的代理对象,代理了getCar方法,
        /*
            代理后的getCar 方法,方法体:
            boss2.reimplement(this, method, xxx);
            相当有自己调用自己,死循环.
         */
//        return method.invoke(o, objects);

        return new Car("LUHU.");
    }
}

package com.desmond.springlearning.method_replace;

import com.desmond.springlearning.lookup.CarFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.cglib.core.DebuggingClassWriter;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

/**
 * @author presleyli
 * @date 2018/10/24 下午9:22
 */
public class Test {
    public static void main(String[] args) {
        // 生成spring cglib 代理类文件
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "/Users/presleyli/java/desmond/codebase/spring-learning/src/main/java/com/desmond/springlearning/method_replace/clz");

        Resource resource = new ClassPathResource("method_replace/application.xml");
        XmlBeanFactory xmlBeanFactory = new XmlBeanFactory(resource);

        Boss1 boss1 = (Boss1) xmlBeanFactory.getBean("boss1");
        Boss2 boss2 = (Boss2) xmlBeanFactory.getBean("boss2");

        System.out.println(boss1.getCar().getName());
    }
}

<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd "
       default-autowire="default">

    <bean id="car" class="com.desmond.springlearning.method_replace.Car" p:name="BMW" scope="prototype" />

    <bean id="boss1" class="com.desmond.springlearning.method_replace.Boss1">
        <replaced-method name="getCar" replacer="boss2"/>
    </bean>

    <bean id="boss2" class="com.desmond.springlearning.method_replace.Boss2"/>

</beans>

6. rquest & session作用域

<?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:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"
       default-autowire="default">

    <bean id="car" class="com.desmond.springlearning.method_replace.Car" p:name="BMW" scope="request" >
        <aop:scoped-proxy/>
    </bean>

    <bean id="boss1" class="com.desmond.springlearning.method_replace.Boss1">
        <property name="car" ref="car"/>
    </bean>

</beans>

此例中,boss1为单例,car,每次http请求都会创建一个新的代理类car.动态代理的逻辑如下:判断当前boss1属于哪个线程下 -> 取出该线程对应的httpSevletRequest -> 从request域中取出car(不存在则先创建) -> 使用;如果作用域为session, 过程如下:判断当前boss1属于哪个线程下 -> 拿到该线程对应的httpSevletRequest -> request.getSession() -> 从session里获取car(不存在则先创建) -> 使用.

  1. FactoryBean

    package com.desmond.springlearning.factory_bean;
    
    import lombok.AllArgsConstructor;
    import lombok.Data;
    import lombok.NoArgsConstructor;
    
    /**
     * @author presleyli
     * @date 2018/10/24 下午9:16
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public class Car {
        private String name;
        private String slogon;
    }
    
    
    
    package com.desmond.springlearning.factory_bean;
    
    import org.springframework.beans.factory.FactoryBean;
    
    /**
     * @author presleyli
     * @date 2018/10/24 下午10:17
     */
    public class CarFactoryBean implements FactoryBean<Car>{
    
        private String carInfo;
    
        public Car getObject() throws Exception {
            String[] arr = this.getCarInfo().split(",");
    
            return new Car(arr[0], arr[1]);
        }
    
        public Class<?> getObjectType() {
            return Car.class;
        }
    
        public boolean isSingleton() {
            return true;
        }
    
        public String getCarInfo() {
            return carInfo;
        }
    
        public void setCarInfo(String carInfo) {
            this.carInfo = carInfo;
        }
    }
    
    
    
    package com.desmond.springlearning.factory_bean;
    
    import com.desmond.springlearning.lookup.CarFactory;
    import org.springframework.beans.factory.xml.XmlBeanFactory;
    import org.springframework.core.io.ClassPathResource;
    import org.springframework.core.io.Resource;
    
    /**
     * @author presleyli
     * @date 2018/10/24 下午9:22
     */
    public class Test {
        public static void main(String[] args) {
            Resource resource = new ClassPathResource("factory_bean/application.xml");
            XmlBeanFactory xmlBeanFactory = new XmlBeanFactory(resource);
    
            Car car = (Car)xmlBeanFactory.getBean("car");
            CarFactoryBean carFactory = (CarFactoryBean)xmlBeanFactory.getBean("&car");
    
            System.out.println(car);
            System.out.println(carFactory);
        }
    }
    
    
    <?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"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd "
           default-autowire="default">
        <bean id="car" class="com.desmond.springlearning.factory_bean.CarFactoryBean" p:carInfo="BMW,被摸我!"/>
    
    </beans>
    
    output:
    十月 24, 2018 10:22:58 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    信息: Loading XML bean definitions from class path resource [factory_bean/application.xml]
    
    Car(name=BMW, slogon=被摸我!)
    com.desmond.springlearning.factory_bean.CarFactoryBean@2133c8f8
    
    Process finished with exit code 0
    
stackelberg博弈_博弈论、多智能体、强化学习(随便记点东西) 多智能体应用场景:已实现:游戏AI。正在努力:UAV,物资运输,快递分发,交通系统。未来:社会学,预测群体行为,城市区域合作,国际关系。博弈论基本定义:玩家集合: 策略集合: 收益函数: 囚徒困境:两智能体矩阵博弈坦白抵赖坦白1,13,0抵赖0,32,2占优策略与最佳应对:上表中两者均具有占优策略,即无论如何都应该选坦白。那么构造下表。坦白抵赖坦白1,13,0抵赖0,12,2对于玩家一来说,坦白... 阅读详情

相关推荐

STM32L431电池供电项目实战:用STOP2模式把功耗降到5uA以下(CubeMX配置详解)

本文详细介绍了如何在STM32L431电池供电项目中利用STOP2模式实现5μA以下的超低功耗设计。通过CubeMX配置、硬件优化和软件策略,成功将农业温湿度监测节点的待机功耗控制在4.7μA,确保CR2032电池供电下3年以上的工作寿命。文章包含完整的低功耗实现路径和实测数据,特别适合物联网边缘设备开发者参考。

weixin_30345577的博客 393

Android WebView H5开发拾遗

上篇介绍了一些WebView的设置,本篇为一些补充项。 首先加载HTML5的页面时,会出现页面空白的现象,原因是需要开启 DOM storage API 功能: webSettings.setDomStorageEnabled(true); 其次,开发中需要注意的安全漏洞,详见《如何设计一个优雅健壮的Android WebView》: @TargetApi(1...

weixin_30879169的博客 129

FastAPI + Layui:打造企业级敏捷开发后台管理系统

本文详细介绍了如何使用FastAPI和Layui构建高效的企业级后台管理系统。FastAPI提供高性能的异步API支持,而Layui则简化了前端开发流程,两者结合可实现快速开发和部署。文章涵盖了从环境搭建、核心组件开发到性能优化的全流程,特别适合需要敏捷开发的企业项目。

weixin_29045585的博客 555

(新) Kotlin搞起来 —— 教程引言与目录

作为一个假的Android开发者,并没有通宵去看 Google I/O 2017开发者大会。早上和往常 一样起床坐地铁上班,习惯性掏出手机看看资讯,才知道 Kotlin 成为Android官方编程语言。 得知这一消息后,感到有些兴奋,使用Kotlin也有一年多了,期间写过一个完整项目,现在接手 别人的项目重构也直接上的Kotlin,习惯了Kotlin写代码的简洁,高效,酷炫,写回Java

Coder-Pig的猪栏 18万+

MATLAB2022b安装

图文并茂,手把手教会你怎么安装MATLAB2022b

1万+

用Multisim和AD2复刻经典:手把手教你搭建μA741三角波-方波发生器(附完整避坑指南)

本文详细介绍了如何使用Multisim和AD2搭建基于μA741运算放大器的三角波-方波发生器,包括电路原理、Multisim仿真流程、AD2硬件搭建及调试技巧。通过对比理论计算、仿真和实测数据,深入分析器件非理想特性的影响,并提供16个典型问题的解决方案,帮助读者掌握波形发生器的设计原理和工程调试经验。

weixin_28744423的博客 284

4.工厂模式

文章目录4.工厂模式简单工厂类图优缺点code输出工厂方法类图优缺点code输出抽象工厂类图优缺点code输出 4.工厂模式 简单工厂 类图 优缺点 优点 简单,解耦。 缺点 当需要扩充业务时,需要对BaoziFactory进行修改,当废弃某一产品时,也需要修改factory代码,产品过多,可能导致factory代码过长,冗余度高。 code package com.desmon...

desmond的专栏 530

bevformer详解(3): 逐行代码讲解

在这篇文章中,我们将从BEVFormer算法代码入手,深入探究BEV转换的流程。BEVFormer是一种基于Transformer的BEV转换模型,其核心思想是利用自注意力机制和交叉注意力机制,从,并通过Object Query与BEV特征的交互,完成3D目标检测和地图分割等任务。https://developer.baidu.com/article/details/3224715bevformer的网络结构由三部分组成, 模型结构所示,其中的是部分,对于的是的结构,对于部分,沿用的中的decoder部分,

@bangbang的博客 3700

15.观察者模式&发布/订阅模式

文章目录15.观察者模式&amp;发布/订阅模式1. 观察者模式1.概念&amp;优缺点2.类图3.代码2.发布-订阅模式1.概念2. 两个模式最重要的区别3. 差异总结 15.观察者模式&amp;发布/订阅模式 1. 观察者模式 1.概念&amp;优缺点 概念 观察者模式: 1. 在对象之间定义了一对多的依赖,这样一来,当一个对象改变状态,依赖它的对象会收到通知并自动更新。 2....

desmond的专栏 520

C#上位机性能优化全攻略:彻底解决界面卡顿+多线程死锁+PLC数据延迟,产线实测稳定运行2年

一开始我们用的是网上找的零散优化代码,根本满足不了要求,后来花了2个月的时间,把之前27条产线的代码整理、重构、优化,做了一套这套方案上线后,连续稳定运行2年零3个月:界面响应时间稳定在50ms以内,多线程死锁率持续为0,PLC数据延迟稳定在150ms以内,系统可用率≥99.99%,帮客户一年省下了超过480万的停线损失、罚款损失和人工成本,客户第二年就把剩下的22条产线也全部交给我们做了,还介绍了3家同行。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 293

使用SIMD思想进行memcpy的优化

arm64平台的memcpy的性能优化,相比C库提升30~40%,SIMD优化思路

zhaoxin1989的博客 1万+

2.知识点拾遗-轻量级容器和控制反转

POJO编程模型 原来的EJB编程模型存在的问题 POJO编程模型的优点 轻量级容器和控制反转 轻量级容器 控制反转 依赖注入 POJO编程模型 原来的EJB编程模型存在的问题 ​ 笨重,业务程序与EJB框架耦合严重,无法在JEE平台之外运行组件,开发-打包-部署-测试流程长且复杂。 POJO编程模型的优点 ​ 简单,轻量,无耦合 轻量级容器和...

desmond的专栏 479

【报错】ImportError: libpython3.10.so.1.0: cannot open shared object file: No such file or directory

ImportError: libpython3.10.so.1.0: cannot open shared object file: No such file or directory

静谧、淡雅 860

14.国际化信息

文章目录14.国际化信息1. 数字格式化2. 日期格式化3. 消息格式化4. 资源化文件5. 动态资源文件4. Spring MessageSource-without Application5. Spring MessageSource-with Application 14.国际化信息 1. 数字格式化 public static void formatNum () { Loc...

desmond的专栏 398

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

3.IOC容器

ioc容器 三种配置方式 依赖注入 自定义属性解析器 循环依赖(构造器) 描述 解决 重写Bean定义 配置元素 基于Java配置 基于XML配置 容器级别 ioc容器 三种配置方式 XML:最基本,最完整、强大 注解(Annotation),@Sine 2.5 疑问:基于注解,怎么读取&lt;context:component-scan base...

desmond的专栏 392

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

7.高级装配(一)

文章目录7.高级装配(一)1. 环境与Profile1.解决不同环境不同配置2.配置方式2. 条件化bean1. 概念2. 举例 7.高级装配(一) 1. 环境与Profile 1.解决不同环境不同配置 maven构建时,使用profiles来确定将哪一个配置编译到可部署的应用 缺点:不同环境重新构建,可能引入bug 使用Spring profile 2.配置方式 Java 可以...

desmond的专栏 365

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

6.装配Bean

文章目录6.装配Bean装配方案通过自动化装配通过Java代码装配通过XML装配导入和混合装配 6.装配Bean 装配方案 基于xml 基于java 基于隐式地bean发现与自动装配 通过自动化装配 优点 便利,自动化,可以解决大部分问题 Spring从两个角度来实现自动转配 组件扫描(component scan) xml &lt;context:component-sc...

desmond的专栏 362

10.设计模式&OO原则概览

文章目录10.设计模式&amp;amp;OO原则概览 10.设计模式&amp;amp;OO原则概览 OO基本概念 抽象 封装 继承 多态 OO原则 封装变化 多用组合,少用继承 针对接口编程,不针对实现编程 为交互对象之间的松耦合而努力 设计原则 找出可能变化的代码,把他独立封装,不要和那些不需要变化的代码混在一起 针对接口编程,而不是针对实现编程 良好的OO设计必须具备三个特性: ...

desmond的专栏 356

16.容器事件

文章目录16.容器事件1. 概念2. Spring事件类结构1. 事件类 `ApplicationEvent`2. 事件监听接口 `ApplicationListener`3. 事件广播 `ApplicationEventMulticaster`3. 实现示例 16.容器事件 1. 概念 Spring的ApplicationContext能够发布事件并且允许注册相应的事件监听器,因此,它拥有一套完...

desmond的专栏 353

21.配置文件读取以及验证(一)

文章目录Resource概述类图Bean加载获取Document类图寻找验证模式(DTD or XSD) Resource 概述 ​ Resource抽象了所有Spring内部使用到的底层资源:File、URL、Classpath等。这接口定义了三个判断短浅资源状态的方法:exists, isReadable, isOpen. 类图 Bean加载 获取Document 类图 ​ 加载docum...

desmond的专栏 348

25.Bean加载过程

文章目录1.BeanFactory v.s. FactoryBean1.BeanFactory2. Bean加载过程 1.BeanFactory v.s. FactoryBean 1.BeanFactory BeanFactory, 即bean工厂,通常用于访问spring容器. FactoryBean,工厂模式,本身为一个bean,用于创建bean,以下是描述 /** * Interface ...

desmond的专栏 330

22.配置文件读取以及验证(二)

文章目录获取Document寻找文档DTD的定义(EntityResolver) 获取Document 寻找文档DTD的定义(EntityResolver) ​ 在验证xml之前,需要找到这个xml的申明文件(DTD or XSD), 在 dtd/xsd + 验证模式的作用下,对xml进行验证. 此dtd/xsd, 通常声明为一网络地址,如果不指定EntityResolver, xml验证器会通过...

desmond的专栏 306

17.内部工作机制

文章目录17.内部工作机制1. 概览图2. 说明 17.内部工作机制 1. 概览图 2. 说明 InstantiationStrategy 负责创建对象,策略模式,参见18.策略模式 BeanWrapper ​ 相当于一个代理器,Spring委托BeanWrapper完成Bean属性的填充工作。在Bean实例被InstrantitationStrategy被创建出来之后,容器主控程序将B...

desmond的专栏 302

23.bean标签的解析及注册

文章目录1. Xml的解析概览1.1 xml解析1.2 xml解析(内)2. bean的解析2.1 默认标签2.2 自定义标签 1. Xml的解析概览 1.1 xml解析 1.2 xml解析(内) 2. bean的解析 2.1 默认标签 2.2 自定义标签 ...

desmond的专栏 280

5.Spring Bean生命周期.md

文章目录5.Spring Bean生命周期生命周期流程图说明总结 5.Spring Bean生命周期 生命周期流程图 说明 *调用InstantitationAwareBeanPostProcessor的postProcessBeforeInstantitation()方法 实例化:Class clazz, custructor或者 newInstance *调用用InstantitaonAw...

desmond的专栏 268

Spring AI + GPT-5.5 + Ollama 配置教程:Base URL、超时与流式调用

由于不同 Spring AI、Spring Boot 小版本之间仍可能存在差异,创建项目时应检查 Spring Initializr、Spring AI BOM 和官方兼容矩阵,不要直接复制旧教程中的 Starter 名称和版本号。多人项目最好隔离不同客户端,并在脱敏前提下记录最终 URL、状态码、请求耗时、请求 ID 和模型 ID。Spring AI 接入模型 API,至少要同时确认 Starter、Base URL、请求路径、API Key、模型 ID、连接超时、读取超时和流式客户端这 8 项。

2601_95893075的博客 232
上一篇: 10.设计模式&OO原则概览
下一篇: 12.Bean使用拾遗(二)
desmond_assis
博客等级 码龄14年 33粉丝 82原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值