相关推荐
海港综合能源系统物流-能量协同优化Matlab实现全解析
综合能源系统优化调度是当前能源与交通交叉领域的研究热点,其核心挑战在于多能互补与多系统耦合。其中,海港作为典型的高耗能物流枢纽,其物流作业与能量管理之间存在强耦合关系:泊位分配、岸桥调度直接影响负荷曲线与用能成本,而微电网内光伏、储能与购电策略又反向制约作业节奏。传统的顺序优化往往顾此失彼,协同优化则通过统一的混合整数线性规划模型,将物流决策与能量决策置于同一框架下联合求解,以港口综合运行成本最低为目标,挖掘削峰填谷与时间弹性潜力。这类问题在工程落地时常依赖Matlab结合Yalmip与Gurobi求解器实
将函数内联化
Inline Method(将函数内联化)Updated on Wednesday, November 10, 2004Summary: 将被内联化的函数,其本体(method body)与其名称(method name)同样清楚易懂,那么就在函数的调用点插入函数本体以消除该函数。 Tips: 如果你手上有一群组织不甚合理的函数,你可以试着把它们都i
embedding计算过程
文章目录embedding计算过程(错了跟我讲,我会改)参考示例个人理解过程图示总结(基于pytorch) embedding计算过程(错了跟我讲,我会改) 参考示例 https://www.jianshu.com/p/63e7acc5e890 个人理解过程图示 总结(基于pytorch) 总的来说,就是将独热向量的长度(对应嵌入层的num_embeddings)转变为嵌入层的emdedding_size(而独热向量的维数就是你的数据中一共产生了多少个不一样的词,至少是这么多)。 数据的变化,将二维
Inline Method 内联函数
一个函数的本体与名称同样清楚易懂 在函数调用点插入函数本体 ,然后移除该函数 int getRating() { return (moreThanFiveLateDeliveries()) ? 2 : 1 } boolean moreThanFiveLateDeliveries() { return _numberOfLateDeliveries > 5 } int...
基因树构建全流程:从OrthoFinder到iTOL的保姆级教程(附兰科植物案例)
本文提供了一份从OrthoFinder到iTOL的基因树构建全流程保姆级教程。详细解析了利用OrthoFinder构建物种树、IQ-TREE构建无根基因树、Notung进行树调和生根,以及最终在iTOL中实现专业可视化的每一步操作与实战经验,并以兰科植物NB-ARC基因家族为例进行演示,帮助研究者系统掌握基因树分析方法。
海康VM加密狗无法识别常见问题排查
海康VM加密狗无法识别常见问题排查
6.2 Inline Method 内联方法
在方法调用点插入方法本体,然后移除该方法 更多精彩 更多技术博客,请移步 asing1elife’s blog 动机 一系列组织不合理的方法相互调用,可以通过内联方法将其合并成一个大型方法,在通过 6.1 Extract Method 提炼方法 将这些代码重新提炼 过多的使用间接层,导致系统中大部分方法看上去都只是另一个方法的简单委托 案例 public int getRating()...
STM32 SPI驱动TFT LCD实战:时序配置与硬件协同
SPI(串行外设接口)是一种高速、全双工、同步串行通信协议,广泛应用于微控制器与显示模组等外设的数据交互。其核心依赖时钟极性(CPOL)与时钟相位(CPHA)组合定义的四种工作模式,直接影响数据采样可靠性;而片选(NSS)与MOSI/SCLK等信号的硬件映射,则决定了多设备共总线下的通信稳定性。在TFT LCD驱动场景中,SPI凭借低开销、高吞吐优势成为主流选择,尤其适配ST7789、ILI9341等集成显示控制器的模块。本文聚焦STM32L系列MCU通过SPI2驱动1.3寸LCD的完整链路,涵盖Mode
6.2Inline Method(内联函数)
【Photoshop JSX脚本】强大的事件监听器脚本 - event_listener.jsx
新手第一次了解的事件监听一定是ScriptingListener.8bi插件,如果你对此插件有了基本运用,那么现在了解一款更方便的时间监听脚本event_listener.jsx。不再像ScriptingListener.8bi插件那样晦涩难懂。 1、准备event_listener.jsx文件到 F:\Program Files\Adobe Photoshop 2020\Presets\...
[AI] 嵌入模型选择:bge / text-embedding-3 / Jina Embeddings 对比与选型指南
摘要: 本文对比了BGE-M3、OpenAI和Jina三种主流嵌入模型在语言覆盖、性能、延迟、维度和成本等维度的差异。BGE-M3适合中文场景,本地部署成本低;OpenAI API多语能力强但依赖网络;Jina在多语表现突出但需关注商用许可。测试显示BGE-M3本地延迟3-6ms,OpenAI API延迟200-600ms。选型建议:隐私场景选BGE本地部署,多语低维护选OpenAI,高精度选Jina。部署时需注意批处理优化、向量库压缩和商用许可等问题,建议建立评测指标并监控关键指标。
重新组织你的函数之二 :Inline Method(将函数内联化)
一个函数,其本体(method body)应该与其名称(method name)同样清楚易懂。 在函数调用点插入函数本体,然后移除该函数。 int getRating() { return (moreThanFiveLateDeliveries()) ? 2 : 1; } boolean moreThanFiveLateDeliveries() { ret
Codex 接入自定义大模型终极教程:插件解锁、会话管理、国产模型一键搞定
🚀 Codex 默认只能使用 OpenAI 官方模型?这篇文章带你从零接入 DeepSeek、通义千问、GLM 等国产大模型,并彻底解锁插件、会话删除、多模型切换等隐藏功能。配置原理、常见坑点、傻瓜式增强工具分享,小白也能轻松上手!🔥
2、重新组织函数
1、Extract Method(提炼函数) 1、无局部变量 2、有局部变量 1、被提炼代码段只是读取变量的值,并不修改他们。 简单传给目标函数 2、被提炼代码段对局部变量再赋值 1、如果发现源函数的参数被赋值,使用Remove Assignments to Para
基于YOLOv8的违规抽烟/打电话检测系统:从数据集构建到部署实战
模型优点缺点精度高速度慢(5 FPS)SSD速度快小目标检测差YOLOv5平衡性好官方支持停止YOLOv8最新、最快、最准需要PyTorch环境YOLOv8相比前代:骨干网络升级(C2f模块)无锚框检测(Anchor-Free)动态任务对齐分配(TaskAlignedAssigner)支持分类/检测/分割/姿态估计。
RU DOS版、EFI版32bit/64bit BIOS常用工具
DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。
【笔记】《重构:改善既有代码的设计》第6章-重新组织函数
第6章 重新组织函数 几乎所有时刻,问题都源于Long Methods(过长函数)。这很讨厌,因为它们往往包含太多信息,这些信息又被函数错综复杂的逻辑掩盖,不易鉴别。对付过长函数,一项重要的重构手法就是Extract Method,它把一段代码从原先函数中提取出来,放进一个单独函数中。Inline Method正好相反:将一个函数调用动作替换为该函数本体。如果在进行多次提炼之后,意识到提炼所得的某...
老版QQ原生表情gif动态
这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。
重构——2内联函数(Inline Method)
内联函数(Inline Method) 一个函数本体与名称同样清楚易懂,在函数调用点插入函数本体,然后移除该函数。 一、动机 1、非必要的间接性总让人不舒服 2、把组织不合理的一群函数重新组织 3、并不是所有的间接层都有价值,委托太多,会让人晕头转向 二、做法 1、检查函数,确定它不具多态性 2、找出这个函数所有的被调用点 3、将这个函数所有的调用点都替...
Statistics and Machine Learning Toolbox
Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具
深度学习工具包 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');```[](https://bitdeli.com/free "Bitdeli Badge")
《重构》-重新组织函数
重构 重新组织函数 1.Extract Method(提炼函数) a. 原因 如果有一个过长的函数或者需要一段注释才能让人理解用途的代码,那么就将这段代码放进一个独立函数中。 b. 好处 函数粒度小,被复用的机会大 使高层函数读起来像注释 函数都是细粒度,更易被复写 c. 步骤 1. 创建一个新函数,根据这个函数的意图来对他命名 2. 即使你想要提炼的代码非常简单,例如只是...
重新组织函数
重新组织函数 大多数问题都源于Long Methods,因为他们往往包含了大量的信息,而这些信息有被函数中错综复杂的逻辑所掩盖,不易甄别。所以重新组织函数中最主要的重构手法就是extract method。在使用extract method的手法时一般需要用到处理参数的一些手法,如:replace temp with query,split temporary varaibable和replac...
重构手法(一) —— 重新组织方法
重新组织方法 Extract Method 将一段可以被组织在一起的代码独立出来,并让函数名称解释该函数的用途。可以强化代码的清晰度。 Inline Method 某些函数的内部代码和函数名同样清晰易读,便可去除该函数,直接使用其中代码。 利用该方法还可以将多个小型函数inline到一个大型函数中,再对其重新提炼整理。 Inline Temp
139



被折叠的 条评论
为什么被折叠?



