优秀代码记录

FOC控制必看:单/双/三电阻电流采样方案全对比(附NXP实战避坑指南) 本文深入对比了FOC控制中单电阻、双电阻和三电阻电流采样方案的优劣与适用场景,重点剖析了采样时序、窗口与ADC转换的工程挑战。针对NXP平台,提供了解决采样窗口过窄的实战方案与配置指南,帮助工程师根据成本与性能需求做出最优选择,并规避常见设计陷阱。 阅读详情

优秀代码都遵循的六大原则

Java六大设计原则(SOLID +1)是面向对象设计的核心准则:

  1. ‌单一职责原则 (SRP)‌

    • 一个类只负责一个功能领域
    • 示例:用户管理类不应同时处理登录和支付逻辑
  2. ‌开闭原则 (OCP)‌

    • 对扩展开放,对修改关闭
    • 通过抽象层(接口/抽象类)实现功能扩展
  3. ‌里氏替换原则 (LSP)‌

    • 子类必须能替换父类且不影响程序正确性
    • 典型违反:子类重写父类方法抛出更宽泛异常
  4. ‌接口隔离原则 (ISP)‌

    • 客户端不应依赖不需要的接口方法
    • 解决方案:将大接口拆分为多个小接口
  5. ‌依赖倒置原则 (DIP)‌

    • 高层模块不应依赖低层模块,二者都应依赖抽象
    • 通过依赖注入实现(如Spring IoC)
  6. ‌迪米特法则 (LoD)‌

    • 最少知识原则,对象只与直接朋友通信
    • 避免链式调用:a.getB().getC().doSomething()

‌扩展原则‌:组合优于继承(非SOLID但重要)

  • 优先使用对象组合而非类继承实现代码复用
  • 示例:策略模式通过组合不同算法对象实现行为变化

这些原则共同作用可提升代码的可维护性、扩展性和复用性,是设计模式的理论基础。实际开发中需根据场景灵活运用而非教条执行。

责任链


import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class AuditManagementFilterChain implements InitializingBean, ApplicationContextAware {

    private IAuditManagementFilter[] filters = new IAuditManagementFilter[0];

    private int pos = 0;

    private int n = 0;

    private ApplicationContext appContext;

    private void addFilter(IAuditManagementFilter newFilter) {
        IAuditManagementFilter[] newFilters = this.filters;

        for (IAuditManagementFilter filter : newFilters) {
            if (filter == newFilter) {
                return;
            }
        }

        if (this.n == this.filters.length) {
            newFilters = new IAuditManagementFilter[this.n + 10];
            System.arraycopy(this.filters, 0, newFilters, 0, this.n);
            this.filters = newFilters;
        }

        this.filters[this.n++] = newFilter;
    }

    public void doFilter(Object obj) {
        if (this.pos < this.n) {
            IAuditManagementFilter filter = this.filters[this.pos++];
            filter.doFilter(obj, this);
        }
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        this.appContext
                .getBeansOfType(IAuditManagementFilter.class)
                .values()
                .forEach(this::addFilter);
    }

    @Override
    public void setApplicationContext(@NotNull ApplicationContext applicationContext) throws BeansException {
        this.appContext = applicationContext;
    }
}

工厂


import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;


@Component
public class BankPayNotifyFactory implements InitializingBean, ApplicationContextAware {

    private static final Map<String, BankPayNotifyStrategy> NOTIFY_MAP = new HashMap<>(8);

    private ApplicationContext appContext;

    /**
     * 根据银行编码获取对应的处理器
     *
     * @param bankChannelCode 银行渠道编码
     * @return
     */
    public BankPayNotifyStrategy getHandler(String bankChannelCode) {
        return NOTIFY_MAP.get(bankChannelCode);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        this.appContext.getBeansOfType(BankPayNotifyStrategy.class)
                .values()
                .forEach(handler -> NOTIFY_MAP.put(handler.getBankChannelCode(), handler));
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.appContext = applicationContext;
    }
}

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
public class TagHandlerStrategyFactory {

    private static final Map<String, TagHandlerStrategy> strategyMap = new HashMap<>();

    public static TagHandlerStrategy addStrategy(TagHandlerStrategy strategy) {
        log.info("Register a policy class[{}]", strategy.getClass().getName());
        return strategyMap.put(strategy.getClass().getSimpleName(), strategy);
    }

    public static TagHandlerStrategy getStrategy(String name) {
        return strategyMap.get(name);
    }

}

门面

// 子系统
class CPU { void start() { /* ... */ } }
class Memory { void load() { /* ... */ } }

// 外观类
class ComputerFacade {
    private CPU cpu;
    private Memory memory;
    public void startComputer() {
        cpu.start();
        memory.load();
    }
}
// 客户端调用
facade.startComputer(); // 隐藏了CPU和Memory的细节


// 子系统:DVD播放器
class DvdPlayer {
    public void on() { System.out.println("DVD启动"); }
    public void play(String movie) { System.out.println("播放电影:" + movie); }
}

// 子系统:投影仪
class Projector {
    public void on() { System.out.println("投影仪开启"); }
}

// 外观类
class HomeTheaterFacade {
    private DvdPlayer dvd;
    private Projector projector;

    public HomeTheaterFacade() {
        this.dvd = new DvdPlayer();
        this.projector = new Projector();
    }

    public void watchMovie(String movie) {
        projector.on();
        dvd.on();
        dvd.play(movie);
    }
}

// 客户端调用
public class Client {
    public static void main(String[] args) {
        HomeTheaterFacade facade = new HomeTheaterFacade();
        facade.watchMovie("星际穿越");
    }
}

适配器


// 目标接口(客户端期望的接口)
interface MediaPlayer {
    void play(String audioType, String fileName);
}

// 被适配者:现有实现类(不兼容接口)
class AdvancedMediaPlayer {
    public void playMp4(String fileName) {
        System.out.println("Playing MP4 file: " + fileName);
    }
    
    public void playVlc(String fileName) {
        System.out.println("Playing VLC file: " + fileName);
    }
}

// 适配器类(实现目标接口并封装被适配者)
class MediaAdapter implements MediaPlayer {
    private AdvancedMediaPlayer advancedPlayer;

    public MediaAdapter(String audioType) {
        if(audioType.equalsIgnoreCase("vlc")) {
            advancedPlayer = new AdvancedMediaPlayer();
        } else if(audioType.equalsIgnoreCase("mp4")) {
            advancedPlayer = new AdvancedMediaPlayer();
        }
    }

    @Override
    public void play(String audioType, String fileName) {
        if(audioType.equalsIgnoreCase("vlc")) {
            advancedPlayer.playVlc(fileName);
        } else if(audioType.equalsIgnoreCase("mp4")) {
            advancedPlayer.playMp4(fileName);
        }
    }
}

// 客户端代码
public class AdapterDemo {
    public static void main(String[] args) {
        MediaPlayer player = new MediaAdapter("mp4");
        player.play("mp4", "movie.mp4");
        
        player = new MediaAdapter("vlc");
        player.play("vlc", "song.vlc");
    }
}

事件

@Component
public class BankWithholdRecordEventUtil {

    @Autowired
    private ApplicationEventPublisher publisher;

    /**
     * 发布监听
     *
     * @param bankWithholdRecord
     */
    public void publishBankWithholdRecordEvent(BankWithholdRecord bankWithholdRecord) {
        publisher.publishEvent(new BankWithholdRecordEvent(bankWithholdRecord));
    }
}

public class BankWithholdRecordEvent extends ApplicationEvent {

    /**
     * 事件
     *
     * @param source
     */
    public BankWithholdRecordEvent(BankWithholdRecord source) {
        super(source);
    }
}


@Component
@Slf4j
public class BankWithholdRecordListener {
    @Autowired
    private IBankWithholdRecordService bankWithholdRecordService;

    /**
     * 代扣流水监听
     *
     * @param event
     */
    @Async
    @EventListener({BankWithholdRecordEvent.class})
    public void saveWithholdRecord(BankWithholdRecordEvent event) {
        BankWithholdRecord bankWithholdRecord = (BankWithholdRecord) event.getSource();
        log.info("进入代扣流水监听方法:{}", bankWithholdRecord);
        bankWithholdRecordService.insertBankWithholdRecord(bankWithholdRecord);
    }
}

监听


import java.util.*;
public class Button {
    private List<ClickListener> listeners = new ArrayList<>();
    
    public void addListener(ClickListener listener) {
        listeners.add(listener);
    }
    
    public void click() {
        listeners.forEach(ClickListener::onClick);
    }
}


public interface ClickListener {
    void onClick();
}



public class Main {
    public static void main(String[] args) {
        Button button = new Button();
        button.addListener(() -> System.out.println("Button clicked!"));
        button.click();
    }
}

发布订阅


import java.util.*;
public class EventBroker {
    private Map<String, List<Subscriber>> topics = new HashMap<>();
    
    public void subscribe(String topic, Subscriber subscriber) {
        topics.computeIfAbsent(topic, k -> new ArrayList<>()).add(subscriber);
    }
    
    public void publish(String topic, String message) {
        topics.getOrDefault(topic, Collections.emptyList())
              .forEach(sub -> sub.onEvent(message));
    }
}


public interface Subscriber {
    void onEvent(String message);
}


public class Main {
    public static void main(String[] args) {
        EventBroker broker = new EventBroker();
        broker.subscribe("news", message -> System.out.println("Sub1 received: " + message));
        broker.publish("news", "Java 21 released!");
    }
}

单例

最好的单例就是枚举!!!


public class Singleton {
    // 方式1:双重检查锁定(适用于JDK5+)
    private static volatile Singleton instance;
    
    private Singleton() {}
    
    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }

    // 方式2:枚举单例(推荐写法)
    public enum EnumSingleton {
        INSTANCE;
        public void doSomething() {
            System.out.println("Enum singleton working");
        }
    }
    
    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        System.out.println(s1 == s2); // true
        
        EnumSingleton.INSTANCE.doSomething();
    }
}

Android图形系统(三)系统篇:渲染/合成的底层原理浅析 众所周知,渲染工作是由GPU负责,那么在聊GPU之前首先得知道什么是“渲染”?我们来举个例子感受一下在系统中申请一块10*101、把图层背景这玩意染成绿的2、从左上(0,0)到右下(10,10)画一条宽度为1颜色为红色的直线3、以坐标点(5,5)为中心,画一个半径为3的实心圆,颜色要蓝色好了,接下来操作系统会把这些“绘图指令”同步给GPU去执行渲染任务图片来源:自己画的GPU完成渲染工作后,我们将会得到一个大小为10*10二维数组,数组中的每个元素都保存着坐标点的颜色信息、深度信息。 阅读详情

相关推荐

Syzkaller实战教程2:运行环境配置+实例运行

本文详细介绍了在linux系统上搭建Syzkaller内核模糊测试环境的完整流程。 1.环境配置:通过VMware创建Ubuntu20.04虚拟机A,配置QEMU/KVM虚拟化环境,安装Go语言工具链和Syzkaller; 2.内核编译:下载Linux内核源码并配置KCOV等调试选项,编译生成带覆盖率支持的bzImage内核镜像; 3.测试环境构建:使用debootstrap创建Debian虚拟机镜像,通过QEMU启动嵌套虚拟机B; 实例测试: 4.演示两种测试场景 - 提供完整上手教程

cuguanren的博客 1375

js优秀代码记录

<script>1当selection为null或者undefined,selection || []的值为[]; var selection=undefined;//selection=null; alert((selection || []).length);2 function isFavorite(id) { var byId ={"57bf4b85-...

dhdc93242的博客 194

Ubuntu22.04系统安装及配置

下载Ubuntu22.04系统镜像(下载地址:链接:https://caiyun.139.com/m/i?提取码:fLRJ),结合rufus和系统镜像制作USB启动盘,在物理机服务器上通过USB启动盘进行安装;或通过Esxi虚拟化平台创建虚拟机,然后在虚拟机中使用系统镜像进行安装。

cheagoun的博客 8万+

JS优秀代码记录

1当selection为null或者undefined,selection || []的值为[];   var selection=undefined;//selection=null;   alert((selection || []).length); 2  function isFavorite(id) {    var byId ={"57bf4b85-5ae6-45ac

268

浅谈python反序列化漏洞

0x01 python序列化与反序列化 Python 的序列化和反序列化是将一个类对象向字节流转化从而进行存储和传输,然后使用的时候再将字节流转化回原始的对象的一个过程。python中的序列化操作是通过pickle模块,而该模块主要包含l dumps将dict转化为str格式,loads将str格式转化为dict格式。 dump和load与文件操作结合起来, pickle.dump(obj, f...

Lethe's Blog 3220

android11.0 Launcher3 高端定制之循环滑动

待机界面可以向左、向右循环切换页面 效果图 修改清单 packages/apps/Launcher3/res/values-zh-rCN/strings.xml packages/apps/Launcher3/res/values/config.xml packages/apps/Launcher3/res/values/strings.xml packages/apps/Launcher3/res/xml/launcher_preferences.xml packages/apps/Launc

cczhengv 1548

优秀代码记录学习

router跳转 router.beforeEach((to, from, next) => { document.title = `${to.meta.title} | vue-manage-system`; const role = localStorage.getItem('ms_username'); if (!role && to.path !== '/login') { next('/login'); } else if.

君子不器 202

手把手教你学Simulink--电机控制架构与算法实现​场景示例:基于Simulink的电机速度环PID调节仿真

本文带你完成了电机速度环PID参数的科学整定,实现了:✅ 理解了速度环的级联系统特性与关键参数影响工程整定法(理论初值)系统辨识法(参数未知时)✅ PID Tuner自动调参(推荐!自动调参兼具快速性与鲁棒性✅ 学会了前馈补偿抗饱和等工程实用技巧。

MHD0815的博客 653

JS 优秀代码记录

1当selection为null或者undefined,selection || []的值为[];   var selection=undefined;//selection=null;   alert((selection || []).length); 2  function isFavorite(id) {    var byId ={"57bf4b85-5ae6-45ac

160

2026年1至9月武汉市房地产价格深度分析报告

本报告基于2026年1月至9月武汉市实际成交案例,从成交价格、区域分布、户型结构、价格走势等维度进行深度分析。数据来源包括武汉市住房保障和房屋管理局备案数据、主要中介机构成交记录及典型楼盘网签案例,覆盖全市15个行政区及主要功能板块。

王国平的博客 327

FPGA电路设计1——芯片原理图和封装制作流程

本文详细介绍了FPGA电路板设计的学习过程,以Xilinx Kintex-7系列FPGA为例。主要内容包括:1)从官网下载芯片引脚分配文件的方法;2)原理图库绘制流程,重点讲解Bank划分(配置Bank、HR/HP IO Bank、高速收发器Bank)及利用Excel预处理数据;3)使用Altium Designer的Symbol Wizard工具实现引脚自动化导入;4)原理图设计要点,包括电源系统设计(多电压需求与上电时序)、配置电路(JTAG/Flash接口)和时钟设计。

在读研究生,FPGA电路设计与功能开发。 1383

新增判断方式,优秀代码记录

public static boolean matches(String regex, CharSequence input) { Pattern p = Pattern.compile(regex); Matcher m = p.matcher(input); return m.matches(); }

u011254009的博客 93

【AI大模型:架构实战】31、工业级AI大模型系统全景解析:从架构设计到提示语引擎实践

本文系统解析了工业级AI大模型的核心架构与技术体系。整体采用分层解耦设计,包含数据工程、模型训练、模型部署、应用集成和监控运维五大核心模块,以及分布式计算、高速网络、异构硬件三大支撑体系。数据工程构建高质量数据处理流水线;模型训练实现从预训练到业务适配的全流程;模型部署优化服务性能与可用性;应用集成连接业务场景;监控运维保障系统持续优化。三大支撑能力专注于千亿参数管理、高并发低延迟处理和持续学习进化。该架构设计既满足当前需求,又为技术演进预留空间,为企业在数字化转型中提供AI工业化落地的完整解决方案。

2025博客之星Top81。专注AI工程化与架构实战。从分布式思维到模型部署,用工程化视角为你厘清AI落地的真实路径。 1989

记录一个优秀的图像二值化代码

#region 二值化02 public Bitmap binaryzation(Bitmap srcBitmap, Bitmap dstBitmap) { int threshold = 0; Byte[,] BinaryArray = ToBinaryArray(srcBitmap...

weixin_30562507的博客 192

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

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Termux 服务自启动:runit 与 Termux:Boot 实战

在 Android 中,后台进程会按优先级被回收,传统 Linux 的 init/systemd 服务管理方式无法直接照搬。要实现长期驻留,需要理解进程守护、服务生命周期与开机广播触发机制:守护进程负责异常退出后自动拉起,开机广播负责系统重启后的初始化,唤醒锁与电池优化白名单则影响后台存活率。对移动端运维、SSH 常驻、定时任务、Python 脚本托管等场景,稳定自启能显著降低人工干预。Termux 环境把这一套问题拆解为 termux-services 的 runit 守护、Termux:Boot 的开机

weixin_34186128的博客 361

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

写代码时需要改正的坏习惯

1、写代码时思想混乱,没有大局观,许多语法还不是很熟悉; 2、写代码时粗心大意,很多低级的错误出现过很多次; 3、写代码之前先构思,然后再敲代码; 4、精简代码量,多用系统函数; 5、对好的语句要做记录,向先进看齐;

yanyehe89的专栏 886

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Puppeteer记录操作过程及优秀的开源插件(五)

本节我们将介绍通过浏览器工具记录用户的实际操作,并且进行生成相应的 nodeJS 代码,然后能够进行对过程的重放。避免所有的脚本都需要用户进行编写,从而减轻代码编写的过程,而且增加代码的稳定性。接下来还会介绍一些常用的已经实现的比较优秀的插件库的列表集,可以根据自己的需求快速的使用到自己的项目中。

suwu150 2391

如何写出高质量的代码?优秀的程序员都是这样做的

编码是程序员最重要的工作,每个程序员都希望自己可以写出优雅,高性能,高质量的代码,对于大师级别的程序员,他们的写的代码就和艺术品一样,你会忍不住发出惊叹,他们怎么可以创造出如此惊艳的作品出来。 下面笔者就以自己的浅薄学识和一些经验来总结下优秀的程序应该具有的特点。 每个变量的命名都深思熟虑 普通程序员的变量命名很随便,以至于随便到abcd都会出来,而高质量的代码的命名则很规范,既不长,也不短,既可以读出它们的含义,又不至于显得啰嗦,总之,从变量命名你就能读出一个程序是否优雅。 从配置文件中读

Hsuesh的博客 1515

寻找、学习和收藏优秀的程序作品

     软件开发技术发展迅速,开发开发语言、开发方式不断的推陈出新。在一定的技术条件下,所产生的优秀的程序作品,不断涌现。这些优秀作品的价值,相当大。     首先,这些作品可以用来学习。程序开发的一些基本的理念是相同的。而程序设计的基本学习方法就是阅读前人的程序代码,研究前人的软件系统。所以,搜集、学习和收藏前人的程序设计优秀代码,可以提高个人的程序设计能力。     其次,搜集、学习和收藏前

Peisong Programming 796

【无标题】

记录开发过程中经常使用的代码块,或则优秀的代码案例代码如下(示例):

weixin_44885096的博客 178

优秀程序员编写可调试的代码

所有的程序都需要某种形式的日志记录建立在它们之上,以便我们可以观察到它正在做什么。这尤其在程序出错时就显得非常重要。一个优秀的程序员和一个糟糕的程序员之间的一个不同之处是一个优秀的程序员会增加日志或其他工具以便在程序失败时方便调试。 当程序如同预期的一样工作时,有日志和没日志往往没什么差异。然而,一旦程序失败,或你得到一个错误的结果的时候,你会立即明白...

weixin_33717298的博客 118

解锁优秀源代码的方法与技巧总结(上)

读码破万卷,敲键如有神。 概述 要成为作家, 需要阅读大量的文学作品;要成为一流的开发者,需要阅读大量的优秀代码。程序设计与开发,可视之为逻辑的武学;解锁优秀代码的能力,是开发者的内功心法之一。 优秀源代码就像一座宝库,里面藏着关于逻辑的奇珍异宝,非常值得一探哦! 解读设计思想,理解技术原理和实现,遇到类似问题时,能够应用到解决方案中; 积累好的代码,胜于重新造轮子。 怎样才...

weixin_30711917的博客 646

转:优秀程序员写可调试的代码

原文: http://blog.jobbole.com/61732/ 所有的程序都需要某种形式的日志记录建立在它们之上,以便我们可以观察到它正在做什么。这尤其在程序出错时就显得非常重要。一个优秀的程序员和一个糟糕的程序员之间的一个不同之处是一个优秀的程序员会增加日志或其他工具以便在程序失败时方便调试。 当程序如同预期的一样工作时,有日志和没日志往往没什么差异。然而,一旦程序失败,或你得...

weixin_34293246的博客 158

信息学奥赛一本通 2004:【20CSPJ普及组】优秀的拆分 | 洛谷 P7071 [CSP-J2020] 优秀的拆分

【题目链接】 ybt 2004:【20CSPJ普及组】优秀的拆分 洛谷 P7071 [CSP-J2020] 优秀的拆分 【题目考点】 数制 基数:即进制数。十进制的基数是10,二进制的基数是2。 按位权展开: 例:1234=1∗103+2∗102+3∗101+4∗1001234 = 1*10^3+2*10^2+3*10^1+4*10^01234=1∗103+2∗102+3∗101+4∗100 十进制转二进制方法:除基取余 10 / 2 = 5 … 0 5 / 2 = 2 … 1 2 / 2 = 1 …

君义NOIP的博客 2866

python学习记录201706070407

随便写写,只是为了克服自己的懒惰,所以写一下自己的python学习过程

u013422608的博客 353

最容易被优秀程序员看不起的三件事……

【优快云 编者按】开发人员们似乎患上了“银弹综合症”,面对技术难关,把太多的期望寄托在所谓的新技术中,却常常低估了一些最基本或许也是最有效的方法。原文链接:https://nvnh.io/index.php/2022/11/28/3-underrated-things-great-developers-do/本文为 优快云 编译整理,未经授权,禁止转载!作者 |Nick编译 | 杨紫艳出品...

优快云资讯 1735
上一篇: 向量化执行引擎是啥?
下一篇: Apache Doris学习记录
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值