如何进行高效的源码阅读:以Spring Cache扩展为例带你搞清楚

如何进行高效的SpringBoot源码阅读 摘要 日常开发中,需要用到各种各样的框架来实现API、系统的构建。作为程序员,除了会使用框架还必须要了解框架工作的原理。这样可以便于我们排查问题,和自定义的扩展。那么如何去学习框架呢。通常我们通过阅读文档、查看源码,然后又很快忘记。始终不能融汇贯通。本文主要基于Spring Cache扩展为例,介绍如何进行高效的源码阅读。 SpringCache的介绍 为什么以Spring Cache为例呢,原因... 阅读详情
13894260-d96523fa3c2b140f
如何进行高效的源码阅读:以Spring Cache扩展为例带你搞清楚

摘要

日常开发中,需要用到各种各样的框架来实现API、系统的构建。作为程序员,除了会使用框架还必须要了解框架工作的原理。这样可以便于我们排查问题,和自定义的扩展。那么如何去学习框架呢。通常我们通过阅读文档、查看源码,然后又很快忘记。始终不能融汇贯通。本文主要基于Spring Cache扩展为例,介绍如何进行高效的源码阅读。

SpringCache的介绍

为什么以Spring Cache为例呢,原因有两个

  1. Spring框架是web开发最常用的框架,值得开发者去阅读代码,吸收思想
  2. 缓存是企业级应用开发必不可少的,而随着系统的迭代,我们可能会需要用到内存缓存、分布式缓存。那么Spring Cache作为胶水层,能够屏蔽掉我们底层的缓存实现。

一句话解释Spring Cache: 通过注解的方式,利用AOP的思想来解放缓存的管理。

step1 查看文档

首先通过查看官方文档,概括了解Spring Cache

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-caching.html

重点两点

  1. 两个接口抽象 Cache,CacheManager,具体的实现都是基于这两个抽象实现。
  2. 典型的SPI机制,和eat your dog food。当需要提供接口给外部调用,首先自己内部的实现也必须基于同样一套抽象机制

The cache abstraction does not provide an actual store and relies on abstraction materialized by the org.springframework.cache.Cache and org.springframework.cache.CacheManager interfaces.

  1. Spring Cache提供了这些缓存的实现,如果没有一种CacheManage,或者CacheResolver,会按照指定的顺序去实现

If you have not defined a bean of type CacheManager or a CacheResolver named cacheResolver (see CachingConfigurer), Spring Boot tries to detect the following providers (in the indicated order):

1.Generic

2.JCache (JSR-107) (EhCache 3, Hazelcast, Infinispan, and others)

3.EhCache 2.x

4.Hazelcast

5.Infinispan

6.Couchbase

7.Redis

8.Caffeine

9.Simple

step2 run demo

对Spring Cache有了一个大概的了解后,我们首先使用起来,跑个demo。

定义一个用户查询方法

@Component
public class CacheSample {
 @Cacheable(cacheNames = "users")
 public Map<Long, User> getUser(final Collection<Long> userIds) {
 System.out.println("not cache");
 final Map<Long, User> mapUser = new HashMap<>();
 userIds.forEach(userId -> {
 mapUser.put(userId, User.builder().userId(userId).name("name").build());
 });
 return mapUser;
 }
</pre>

配置一个CacheManager

<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">@Configuration
public class CacheConfig {
 @Primary
 @Bean(name = { "cacheManager" })
 public CacheManager getCache() {
 return new ConcurrentMapCacheManager("users");
 }
</pre>

API调用

@RestController
@RequestMapping("/api/cache")
public class CacheController {
 @Autowired
 private CacheSample cacheSample;
 @GetMapping("/user/v1/1")
 public List<User> getUser() {
 return cacheSample.getUser(Arrays.asList(1L,2L)).values().stream().collect(Collectors.toList());
 }
 }
</pre>

step3 debug 查看实现

demo跑起来后,就是debug看看代码如何实现的了。

因为直接看源代码的,没有调用关系,看起来会一头雾水。通过debug能够使你更快了解一个实现。

13894260-9c11ab1f4df9474c
如何进行高效的源码阅读:以Spring Cache扩展为例带你搞清楚

通过debug我们会发现主要控制逻辑是在切面CacheAspectSupport

会先根据cache key找缓存数据,没有的话put进去。

step4 实现扩展

知道如何使用Spring Cache后,我们需要进一步思考,就是如何扩展。那么带着问题出发。

比如Spring Cache不支持批量key的缓存,像上文我们举的例子,我们希望缓存的key是userId,而不是Collection userIds。以userId为key,这样的缓存命中率更高,存储的成本更小。

 @Cacheable(cacheNames = "users")
 public Map<Long, User> getUser(final Collection<Long> userIds) {}
</pre>

所以我们要实现对Spring Cache进行扩展。step3中我们已经大致了解了Spring Cache的实现。那么实现这个扩展的功能就是拆分Collection userIds,缓存命中的从缓存中获取,没有命中的,调用源方法。

@Aspect
@Component
public class CacheExtenionAspect {
 @Autowired
 private CacheExtensionManage cacheExtensionManage;
 /**
 * 返回的结果中缓存命中的从缓存中获取,没有命中的调用原来的方法获取
 * @param joinPoint
 * @return
 */
 @Around("@annotation(org.springframework.cache.annotation.Cacheable)")
 @SuppressWarnings("unchecked")
 public Object aroundCache(final ProceedingJoinPoint joinPoint) {

 // 修改掉Collection值,cacheResult需要重新构造一个
 args[0] = cacheResult.getMiss();
 try {
 final Map<Object, Object> notHit = CollectionUtils.isEmpty(cacheResult.getMiss()) ? null
 : (Map<Object, Object>) (method.invoke(target, args));
 final Map<Object, Object> hits = cacheResult.getHit();
 if (Objects.isNull(notHit)) {
 return hits;
 }
 // 设置缓存
 cacheResult.getCache().putAll(notHit);
 hits.putAll(notHit);
 return hits;
 }
}
然后扩展Cache,CacheManage
重写Cache的查找缓存方法,返回新的CacheResult
 public static Object lookup(final CacheExtension cache, final Object key) {
 if (key instanceof Collection) {
 final Collection<Object> originalKeys = ((Collection) key);
 if (originalKeys == null || originalKeys.isEmpty()) {
 return CacheResult.builder().cache(cache).miss(
 Collections.emptySet())
 .build();
 }
 final List<Object> keys = originalKeys.stream()
 .filter(Objects::nonNull).collect(Collectors.toList());
 final Map<Object, Object> hits = cache.getAll(keys);
 final Set<Object> miss = new HashSet(keys);
 miss.removeAll(hits.keySet());
 return CacheResult.builder().cache(cache).hit(hits).miss(miss).build();
 }
 return null;
 }
CacheResult就是新的缓存结果格式
 @Builder
 @Setter
 @Getter
 static class CacheResult {
 final CacheExtension cache;
 // 命中的缓存结果
 final Map<Object, Object> hit;
 // 需要重新调用源方法的keys
 private Set<Object> miss;
 }
</pre>

然后扩展CacheManager,没什么重写,就是自定义一种manager类型

为缓存指定新的CacheManager

@Primary @Bean public CacheManager getExtensionCache() { return new CacheExtensionManage("users2"); }
</pre>

觉得还不错的话记得转发转发+关注

觉得还不错的话记得转发转发+关注

由于篇幅过长哈,不能全部发出,需要完整代码可以点击链接获取:https://shimo.im/docs/QzafqtfKU4MoODI9/read

总结

本文主要介绍一种源码学习方法,纯属抛砖引玉,如果你有好的方法,欢迎留言分享。

计算机毕业设计源码高效利用指南:以Spring Boot音乐网站为例 在软件工程实践中,源码复用是提升开发效率、学习项目架构的重要手段,其核心原理在于对成熟代码逻辑和设计模式的理解与借鉴。对于计算机专业学生而言,毕业设计项目源码合集提供了宝贵的参考资源,其技术价值在于能快速搭建项目框架,理解Java、Python等主流技术栈在Web开发中的实际应用。然而,直接套用源码常伴随环境依赖、代码质量与安全漏洞等风险。以Spring Boot + MyBatis技术栈构建的儿童音乐分享网站为例,一个典型的应用场景是作为二次开发的基础。通过系统性地进行环境配置、源码解析、数据库优化及安全 阅读详情

相关推荐

Spring Cloud Alibaba Nacos与Sentinel源码深度解析:微服务治理核心原理与实战

在微服务架构中,服务注册发现与流量治理是保障系统稳定性的基石。其核心原理在于通过分布式协调与实时数据统计,实现服务实例的动态管理与异常流量的精准控制。从技术价值看,深入理解这些机制不仅能提升系统的高可用性与可扩展性,更是排查线上复杂问题的关键。具体到应用场景,例如在应对服务注册延迟或配置推送失败时,掌握客户端长轮询与心跳机制的工作原理至关重要;而在处理限流不准确或熔断失效问题时,则需要明晰滑动时间窗口算法与熔断状态机的底层实现。本文聚焦于Spring Cloud Alibaba生态下的Nacos与Senti

weixin_34258838的博客 384

Spring-Cache 源码解析

有了EnableCaching,才有了CacheInterceptor有了CacheInterceptor,CacheAutoConfiguration就会生效CacheAutoConfiguration会提供CacheProperties和CacheManagerCustomizers有了CacheProperties和CacheManagerCustomizers,ConcurrentMapCacheManager就会生效。

weixin_44175409的博客 432

仿番茄小说阅读器全栈项目实战:Spring Boot + Vue 前后端分离架构详解

在Web应用开发领域,前后端分离架构已成为主流模式,它通过清晰的职责划分实现了技术栈的灵活性与开发效率的提升。其核心原理是将用户界面与业务逻辑解耦,前端专注于视图渲染与交互,后端则提供标准化的API数据服务。这种架构的技术价值在于支持并行开发、便于维护扩展,并能适应多终端需求。在内容型应用如在线阅读平台中,该架构能有效管理书籍数据、用户状态及阅读进度。本文以仿番茄小说阅读器项目为例,深入探讨了如何运用Spring Boot构建RESTful API服务,并结合Vue实现响应式前端界面,其中重点解决了文本精确

weixin_33883104的博客 299

SpringCache源码解析(一)

SpringBoot 确实是通过 spring.factories 文件实现自动配置的。Spring Cache 也是遵循这一机制来实现自动装配的。具体来说,Spring Cache 的自动装配是通过 org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration 这个类来实现的。这个类位于 spring-boot-autoconfigure 包下。

moneywenxue的博客 1437

SpringCache框架加载/拦截原理详解

主要介绍了SpringCache框架加载/拦截原理详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

电机FOC控制实战:STM32 CubeMX配置六路互补PWM与死区优化

本文详细介绍了如何使用STM32 CubeMX配置六路互补PWM与死区优化,实现电机FOC控制。通过实战经验分享,包括时钟配置、定时器设置、死区时间计算及优化技巧,帮助开发者避免常见问题,提升电机控制性能。特别适用于STM32G4系列的无刷电机驱动应用。

weixin_29193259的博客 409

Spring cache源码分析

Spring cache是一个缓存API层,封装了对多种缓存的通用操作,可以借助注解方便地为程序添加缓存功能。 常见的注解有@Cacheable、@CachePut、@CacheEvict,有没有想过背后的原理是什么?楼主带着疑问,阅读完Spring cache的源码后,做一个简要总结。 先说结论,核心逻辑在CacheAspectSupport类,封装了所有的缓存操作的主体逻辑,下面详细介绍。 题外话:如何阅读开源代码? 有2种方法,可以结合起来使用: 静态代码阅读:查找关键类、方法的usage之处,熟练

Java烘焙师 1185

手把手教你用PLECS仿真BUCK数字电源(含DSP代码实现)

本文详细介绍了如何利用PLECS仿真软件与Visual Studio 2022搭建高保真数字电源开发环境,手把手指导从BUCK电路建模、编写硬件感知的C控制算法到参数调优的全过程。重点阐述了通过DLL接口实现软件在环仿真,模拟DSP的ADC/PWM时序,并将验证后的代码无缝迁移至TI C2000系列DSP,构建从仿真到固件的完整数字电源开发闭环,显著提升开发效率与一次成功率。

oo7890的博客 405

spring-cache 源码解析(无图)

spring-cache

ITket的博客 1037

SceneSplat

目标:训练一个网络,输入高斯参数 → 输出与自然语言空间对齐的特征。考虑到标注语义的 3DGS 数据有限,作者设计了。策略,让模型在无标签场景上学到有用表征。都有一个与自然语言对齐的语义特征。这是整个方法的第一步,目标是让。

weixin_61091146的博客 1288

HUMAnN 3.0 (alpha)安装及使用

文章目录简介安装数据库下载运行参考 简介 安装 conda install humann humann_test (~1 minute) 数据库下载 humann_databases --download chocophlan full /path/to/databases --update-config yes humann_databases --download uniref uniref90_diamond /path/to/databases --update-config yes humann_

dys的博客 9515

spring cache源码解析(四)——从@EnableCaching开始来阅读源码

@EnableCaching:开启缓存功能; @Cacheable:获取缓存; @CachePut:更新缓存; @CacheEvict:删除缓存;

moneywenxue的博客 1183

MATLAB R2022b 安装教程

1. 下载安装先放资源链接,百度网盘太贵了不想续了,换了夸克网盘。1. 下载安装。

qq_51654158的博客 2万+

扩展源_如何进行高效的源码阅读:以Spring Cache扩展为例带你搞清楚

摘要日常开发中,需要用到各种各样的框架来实现API、系统的构建。作为程序员,除了会使用框架还必须要了解框架工作的原理。这样可以便于我们排查问题,和自定义的扩展。那么如何去学习框架呢。通常我们通过阅读文档、查看源码,然后又很快忘记。始终不能融汇贯通。本文主要基于Spring Cache扩展为例,介绍如何进行高效的源码阅读。SpringCache的介绍为什么以Spring Cache为例呢,原因有两个...

weixin_29149709的博客 119

大数据领域数据产品的交通运输行业应用

您是否经历过早高峰被堵在桥上,看着导航显示“前方5公里缓行”却无能为力?是否见过货车司机绕远路导致成本飙升?这些“交通痛点”的背后,是传统交通管理依赖经验决策的局限。本文将聚焦“大数据数据产品”这一核心工具,从技术原理到实际应用,全面解析它如何为交通运输行业“开天眼”,解决从城市拥堵到物流效率的一系列难题。本文将按照“问题引入→概念拆解→技术原理→实战案例→应用场景→未来趋势”的逻辑展开,用生活化比喻降低理解门槛,用代码和数学模型提升专业性,最终帮您建立“大数据+交通”的完整认知框架。交通数据。

操作系统内核探秘的博客 242

网络系统管理专栏-配套练习+知识点详解

网络系统管理专栏-配套练习+知识点详解

bfq05234214的博客 688

以Spring Cache扩展为例介绍如何进行高效的源码的阅读

摘要 SpringCache的介绍 扩展点 功能的实现 扩展,如何实现metric监控 http://ylzheng.com/2018/01/24/use-prometheus-monitor-your-spring-boot-application/

方丈的寺院 1276

提示libfakeroot.so或libfakeroot-sysv.so出错处理方法

嵌入式Linux、Buildroot交叉编译出现fakeroot问题处理方法。

阿xin*的嵌入式AI 1451

高效阅读开源代码的黄金四步法与工具链配置

源码阅读是开发者深入理解技术原理的重要途径,其本质是通过逆向工程还原设计思想。掌握正确的源码分析方法能快速定位核心逻辑,常见技术包括依赖关系分析、动态调试和流程图解构。在Java生态中,Spring框架的IoC容器和MyBatis的SQL映射机制都是典型研究目标,通过单元测试切入和线程模型分析可以显著提升理解效率。现代IDE提供的调用链追踪和内存快照功能,配合PlantUML等可视化工具,能有效解决大型项目如Netty或Kafka的代码迷航问题。良好的源码阅读习惯应当包含知识沉淀体系,结合Git历史分析和性

weixin_34184158的博客 359

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

efm32 入门.pdf

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

高效拆解陌生GitHub仓库:从元数据到源码的完整指南

软件开发者常会遇到陌生的GitHub仓库,直接克隆运行往往因编译错误、版本不匹配而寸步难行。更高效的方式是先通过API读取仓库元数据,确认项目定位、技术栈与活跃度;再复制CI配置中的构建路径,复用团队已验证的环境。跑通测试后再阅读源码,让测试代码反推功能边界,同时借助构建文件识别依赖关系,从而减少盲目摸索。这套流程适用于任何未知代码库,既能降低上手门槛,也为后续二次开发与代码审查提供可靠基线。本文以unclebob/swarm-forge为案例,完整演示了从仓库名到可运行、可调试、可扩展的拆解步骤,帮助开发

weixin_34050005的博客 408

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

Spring Boot全栈实战:汽车4S店管理系统从部署到二次开发指南

在Java Web开发领域,Spring Boot作为构建企业级应用的主流框架,通过约定优于配置的理念简化了项目搭建过程。其核心原理在于自动配置和起步依赖,能够快速集成Web MVC、数据访问、安全控制等模块,显著提升开发效率。这一技术价值体现在能够帮助开发者聚焦业务逻辑而非基础设施,尤其适合构建管理后台、电商平台等数据驱动的系统。以汽车4S店管理系统为例,它典型地应用了Spring Boot整合MyBatis-Plus实现数据持久化,配合Thymeleaf模板引擎渲染前端页面,覆盖了从车辆信息管理、销售订

weixin_33798152的博客 341

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Spring面试高频题解析:从IoC到AOP的完整攻略

控制反转(IoC)和面向切面编程(AOP)是Spring框架的两大核心技术。IoC通过依赖注入(DI)实现组件解耦,其核心容器采用三级缓存机制解决循环依赖问题。AOP则基于动态代理实现,支持JDK动态代理和CGLIB两种方式,用于日志记录、事务管理等横切关注点。在Java后端开发中,Spring的事务管理尤为重要,涉及7种传播行为和4种隔离级别。理解这些核心机制不仅能应对90%的Spring面试问题,更能帮助开发者构建高可维护性的企业级应用。本文特别针对循环依赖和动态代理等高频考点进行深度解析,并给出实际工

weixin_34021089的博客 467
上一篇: 架构不容错过干货之分布式系统的负载均衡
下一篇: 三千字讲清TypeScript与React的实战技巧
普通网友
博客等级 码龄8年 342粉丝 68原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址