源代码就是设计 续篇

源代码就是设计,真的 源代码就是设计,讲述如何将代码设计的工整 优雅 很好的文章 立即下载

What Is Software Design: 13 Years Later
By Jack W. Reeves
Posted February 23, 2005

People have occasionally asked whether I did any follow-on writing to my "What Is Software Design" article. The answer has basically been "No, not really." I want to make it clear that that is not because I forgot about it or otherwise changed my mind. Allow me to offer a bit of explanation.

When the article appeared, I hoped–actually expected–that I would get some type of rebuttal from some sort of industry "expert." I was looking forward to this since part of my reason for writing the article had been hopes of stimulating discussion within the software industry about the overall software development process. Nothing happened.

There were no letters to the editor that I know about and nothing ever sent directly to me. C++ Journal became defunct shortly after that issue, and I figured my article had gone to that great land fill in the sky that swallows most publications. I went on to doing other things. It wasn’t until 1997 or 1998 that I got an email from Bob Martin (who had just taken over as editor of the C++ Report) letting me know there was a wiki page about my article on Ward Cunningham’s c2.com web site. This was–quite literally–the first time I knew anybody had read my article (other than the people I personally gave a copy to).

I started to follow the discussions on the wiki page and occasionally on some news groups, but deliberately stayed out of them myself for several reasons: a) I was focused on certain other things at the time, b) it was pretty obvious that other people who had accepted what I was trying to say were just as qualified–maybe more so–to argue the points as I would have been (I specifically remember Michael Feathers writing), and c) last but not least, it still looked to me like there was a lot of opposition to the concept. Unfortunately, most of the arguments sounded pretty much like the ones I had been dealing with for almost 15 years by that point (remember, I had had the idea almost 10 years before I wrote the article).

I had grown tired of trying to deal with people who were totally incapable of getting past their own pre-conceptions to even consider the idea rationally. It was like trying to explain that the French speak a different language to someone who is convinced that "different language" really just means "different dialect of English". No matter what you say, they will parse your arguments against their beliefs and either dismiss you out of hand, or patronize you with their counter arguments. I had seen a number of projects where "design it in the code" worked, but even the people on such projects often refused to accept the reality. My level of cynicism about being able to improve things was very high.

It still is, but I think it is time I made some attempt to actually defend myself, rather than let other people do it. Therefore, what I am going to do is address some of the most common criticisms I have seen about "What Is Software Design?".

A. Initially, the most common criticism I would see can be summarized as "If source code is the design, then programmers are designers; but obviously they are not, therefore source code cannot be the design." Nobody states it that baldly, but when you parse what they do say, it comes down to the same thing. These are circular arguments that start with the assumption that programming/coding is a manufacturing type of activity. In logic, this is known as a "Begging the Question" fallacy. In essence, these people say "your assumption (i.e. source code is the design) contradicts my assumption (i.e. programmers are assembly workers), therefore your assumption must be wrong."

Someone might suggest that I am doing the same thing, i.e. starting with the assumption that source code is a design. I accept that–up to a point. While I will admit that a lot of the article reads like an attempt to prove that "source code is the design", that was not really what I was trying to do. The following quote is from the beginning of the article:

"This article assumes that final source code is the real software design and then examines some of the consequences of that assumption. I may not be able to prove that this point of view is correct, but I hope to show that it does explain some of the observed facts of the software industry, ..."
I did not set out to prove that "source code is the design"; I will readily concede that what is a "design" is to some extent a matter of definition. The point of the article was to try to show how this assumption led to much better explanations of numerous observed facts. I am still waiting for anyone to offer better explanations based upon alternative assumptions.

B. These days, thanks in part to the rise of Extreme Programming and other Agile Methods, people are starting to accept (grudgingly) that programmers are not assembly line drones. Unfortunately, that doesn’t mean they are willing to accept the concept of "the source code is the design". The arguments can be summarized by the example that is still on the wiki page:

"As for throwing the whole design thing out, and just designing in code... Hahahahahahahahah no really Hahahahahahahahah :)"
This really makes me angry. For reasons that I do not understand, reasonably intelligent people insist upon confusing the concept of design as process versus design as product. You would think that anyone who passed high school would understand the difference between the process of writing a paper (for example) and the paper itself. Certainly, you would expect anyone with a college background to understand that there are often lots of different ways to arrive at the same solution.

Nevertheless, people keep insisting that my contention of "the source code is the design" means "don’t do design, just code." I never said anything of the sort. What I did say was:

"In software engineering, we desperately need good design at all levels. In particular, we need good top level design. The better the early design, the easier detailed design will be. Designers should use anything that helps. Structure charts, Booch diagrams, state tables, PDL, etc.—if it helps, then use it."
Today, I would phrase it differently. I would say we need good architectures (top level design), good abstractions (class design), and good implementations (low level design). I would also say something about using UML diagrams or CRC cards to explore alternatives. Nevertheless, I will not back away from the following statement:

"We must keep in mind, however, that these tools and notations are not a software design. Eventually, we have to create the real software design, and it will be in some programming language. Therefore, we should not be afraid to code our designs as we derive them."
This is fundamental. I am not arguing that we should not "do design." However you want to approach the process, I simply insist that you have not completed the process until you have written and tested the code.

Personally, I think a person with his feet on the desk staring at the ceiling can be "doing design" just as seriously as someone playing with UML diagrams in ROSE. I have always known that you are better off if you put some real thought into what you are trying to do before actually doing it. People differ widely in what helps them think, however. Some people use pencil and paper. Others like white boards or even computer tools. Some people like to bounce ideas off of other people, others like peace and quiet. Some people feel comfortable with diagrams like UML. Others prefer CRC cards.

What approach they choose doesn’t matter; until someone starts insisting that these intermediate designs should be products in their own right. It’s the code that matters. If you get good code, does it really matter how it came about? If you don’t get good code, does it really matter how much other garbage you made people do before they wrote the bad code?

Everybody that has been in this business any length of time has seen plenty of examples where someone obviously sat down and coded the first thing that popped into their mind. Later, when it became obvious that there were shortcomings with the approach, there was too much blood, sweat, and "skin" invested in the code to scrap it and do something better. Fine, we all know a little thought can go a long way.

On the other hand, any of us who has spent time on a traditional development project with its strict rules forbidding the writing of a single line of code until the "design" is completed and reviewed and approved, etc. knows you can waste a hell of a lot of time producing documents that are out of date literally days after the actual coding starts. Why bother?

You think we could find some happy medium of "enough" design effort, but not too much. There is no such thing. The only way we validate a software design is by building it and testing it. There is no silver bullet, and no "right way" to do design. Sometimes an hour, a day, or even a week spent thinking about a problem can make a big difference when the coding actually starts. Other times, 5 minutes of testing will reveal something you never would have thought about no matter how long you tried. We do the best we can under the circumstances, and then refine it.

One last comment: I also did not say that the only necessary documentation is the source code. I specifically pointed out in the article:

"...auxiliary documentation is as important for a software project as it is for a hardware project."
The source code may be the master design document, but it is seldom the only one necessary.

B’. I cannot resist making a remark about a side issue that often comes up in discussions about Extreme Programming and Agile methods that is related to the above. This is often phrased as a question: what about the Less Able Programmer? The issue seems to be that only the very best programmers can "design" and "code" at the same time. To offset this, we must have all those intermediate design steps and products mentioned above to make up for the lack of experience and talent of the average programmer.

To me, this is like asking "what do we do about the less able physician?" I know the practice of medicine and software development are not analogous, but bear with me for a moment. An awful lot of the practice of medicine is pretty much rote (we joke about "take two aspirin and call me tomorrow"). Nevertheless, the medical profession still insists upon some pretty high standards of intelligence, education, and experience before someone is allowed to call themselves an MD. In other words, we want our doctors to know what they are doing.

In software development, questions about the less able programmer really come down to trying to substitute a process for intelligence, aptitude, and experience. Apparently, a lot of people think that if we force people to create enough UML diagrams (or whatever), have enough reviews, and otherwise follow a detailed process, that eventually they will figure out what they are doing and code it correctly. There is no evidence that such approaches have worked in the past, and I see no reason to believe they will work in the future. In fact, my own experience says that properly using tools such as UML involves a considerable level of expertise and experience in its own right.

C. Another argument I have seen questions the contention that the goal of an engineering effort is some type of documentation. Some people argue that the goal of engineering is a "product" and that real engineers often "build" things and those "things" are as much a product of engineering as any documentation.

This argument tries to sidestep the question of "What is a Software Design?" by implying a parallel between the "things" that other engineers build and what software developers create. Frankly, this is nonsense. I will concede that there are engineers who build "things" with little or no formal design documentation, although I suspect that even in those cases there is probably some design documentation (even if it is on the back of an envelope). In any case, I think we can safely say that such projects produce only one-off products and are usually done by individuals.

When an "engineering" effort starts involving more than a couple of people, or when it has a formal manufacturing phase, then documentation starts to loom larger and larger as the actual product of the engineering effort. You better believe that the engineers at Toyota or Motorola produce documentation, and we’ll not even think about the engineers at Boeing or Lockheed. So, while it might be true that a lot of engineers do things besides producing design documents, anyone who calls himself an engineer knows what a design document in his field looks like, and probably produces such more often than not. Can we say the same for "software engineers"?

Incidentally, this contention regarding engineers and documentation was not mine originally, but instead something I picked up from an article in Datamation back in 1979. I agree with it completely however.

D. One final but fairly minor argument I have seen is that source code is still too high level to be a design. At least one critic wanted to call source code the "specification." His (or her) take was that the real design is what comes out of the compiler. In some sense this is just a matter of definition, but I still disagree with it.

The generally accepted definition is that a "specification" states the what, which is followed by a design document that details the how. While there is a certain amount of flexibility allowed of the compiler in determining the how of object code, there is certainly no creativity involved. And that is where I draw the line. When the document is detailed enough, complete enough, and unambiguous enough that it can be interpreted mechanistically, whether by a computer or by an assembly line worker, then you have a design document. If it still requires creative human interpretation, then you don’t.

In software development, the design document is a source code listing.

永和大王门店管理系统 该代码内含多种jar包,包含二维码生成技术,数据库连接技术,El标签等。希望能帮助各位。 立即下载

相关推荐

What is software design

计算机敏捷开发中。非常经典的一篇文档。这个是英文的。有2005年的作者新的回顾和作者写给编辑的信件。学习开发和设计必读的文档。 PS:文档有点长,共24页。

源代码就是设计

注:本文摘自《敏捷软件开发:原则、模式与实践》(清华大学出版社,2003年9月版。本人有幸翻译了该书,详见:http://www.china-pub.com/computers/common/info.asp?id=13569)中的附录D。这是一篇伟大的论文,该文撰写于1992年,作者在当时就能有这样的反思,实在是非常了不起。××××××××××××××××××××××××××××××××××

hoping的专栏 3338

ssm项目实战练习永和大王门店管理系统.docx

开发文档 这里利用之前学过的MySQL、JSP、JSTL、html、css等技术,以及目前市面上最流行的企业级Java开发框架SSM实现一个《永和大王门店管理系统》,其中包括门店管理模块和订单管理模块,两个模块中,实现了对门店和订单信息的增删改查功能。

什么是软件设计--Jack W.Reeves,1992 【抄录】

      面向对象技术,特别是C++,似乎给软件界带来了不小的震动。出现了大量的论文和书籍去描述如何应用这项新技术。总的来说,那些关于面向对象技术是否只是一个骗局的问题已经被那些关于如何付出最小努力即可获得收益的问题所代替。面向对象技术出现已经有一段时间了,但是这种爆炸式的流行却似乎有点不寻常。人们为何会突然关注它呢?对于这个问题,人们给出了各种各样的解释,事实上,很可能就没有单一的原因。也许,

superlee19的专栏 1256

店铺管理系统代码

店铺管理系统的源代码,桌面程序,开发文档已经上传

Matlab实现POD本征正交分解数据降维模型

近年来,随着大数据时代的到来,各种复杂的工程问题产生了海量的高维数据,如何有效降维、提取数据中的关键信息成为了众多领域中的重要问题。在传统的数据降维方法中,PCTFA(主成分分析)是一种典型的统计方法,然而对于流体动力学等非线性问题,PCTFA在处理时可能失去部分物理意义,难以捕捉到系统的复杂性。在降维过程中,POD提取的主要特征通常是一组复杂的正交基函数,如何将这些结果有效地转化为直观且易于理解的物理意义,特别是在实际应用中,对该特征的理解和分析,依然是一个重要的课题。本项目的扩展性也得到了有效体现。

优质创作者: 人工智能技术领域 对于有一定基础的 MATLAB和Python带具体需求都可以详谈 MATLAB和Python可以提供代码调试服务加油 谢谢 你的鼓励是我前行的动力 谢谢支持 加油 谢谢 1220

敏捷质疑: TDD

Q: 为什么通过单元测试发现的 Bug 很少 ?A: 单元测试不是用来发现 Bug 的, 而是用来预防 Bug 的. 如果采用 TDD, 测试用例完成之时, 产品代码尚未编写, Bug更无从谈起. Q: 那是否写单元测试就能提高代码质量了 ?A: 关于这一点, 似乎有人不这么看, TDD Opinion: Quality Is a Function of Thought and R

切尔斯基 9539

手把手教你用示波器实测LVDS/CML信号:从波形解读到故障排查(附实测图)

本文详细介绍了如何使用示波器实测LVDS和CML信号,从波形解读到故障排查的全过程。涵盖差分探头选择、示波器配置、标准波形特征解读、眼图分析技巧以及高速信号捕获要点,帮助硬件工程师快速诊断和解决信号完整性问题。附实测图和案例,提升高速数字电路设计效率。

weixin_27215337的博客 212

What is Software Design?

  http://www.developerdotstar.com/mag/articles/reeves_design.html  What Is Software Design?By Jack W. Reeves Published February 23, 2005Discussion  -  Printable  -  PDF

§为艺术而技术§ 2059

2.6 SST的核心性能指标体系

本文构建了固态变压器(SST)的核心性能指标体系,涵盖电气性能、可靠性、经济性和环境适配性四大类指标。电气性能指标包括运行效率(≥97%)、功率密度(≥900kVA/m³)、谐波畸变率(≤3%)等关键参数;可靠性指标设定MTBF≥43800h、年均故障率≤1.2次/年等标准;经济性指标对比分析了初始购置成本(45-55万元)和全生命周期成本(48-55万元);环境适配性指标则明确了温度、海拔等工况要求。该体系采用量化公式和国标限值,为SST的性能测试、选型和优化提供了统一标准。

技术工作者 613

变邻域搜索(VNS)原理梳理和应用细节-附求解VRPTW问题C++代码

文章目录1、简介-introduction2、VNS的基本机制2.1 变邻域下降方法-Variable Neighborhood Descent2.2基本变邻域搜索方法-Basic Variable Neighborhood Search2.3 终止准则3、VNS的拓展和混杂算法3.1 VNS的拓展3.2 变邻域分解搜索-Variable Neighborhood Decomposition Search3.3 偏变邻域搜索-Skewed VNS3.4 并行变邻域搜索-Parallel VNS4、VNS和其

dragon Fly的博客 6833

源程序就是设计 ---By Jack Reeves

http://www.bleading-edge.com/Publications/C++Journal/Cpjour2.htm这是一篇伟大的论文,该文撰写于1992年,作者在当时就能有这样的反思,实在是非常了不起。至 今,我仍能记起当我顿悟并最终产生下面文章时所在的地方。那是1986年的夏天,我在加利福尼亚中国湖海军武器中心担任临时顾问。在这期间,我有幸参加了 一个关于A...

weixin_33862993的博客 149

深度解析NXP AMCLIB状态观测器:PMSM无感FOC控制实战指南

状态观测器是现代电机控制中的核心算法,它基于电机数学模型,通过测量定子电压和电流,实时估算出转子的位置和速度,从而替代了传统的物理传感器。其原理遵循“预测-校正”的闭环结构,通过比较模型预测值与实际采样值的误差,不断修正内部状态估计。这项技术的核心价值在于实现了无传感器控制,显著降低了系统成本、提升了可靠性与紧凑性,广泛应用于伺服驱动、变频器、电动汽车和家电等领域。本文聚焦于NXP AMCLIB库中的角度跟踪观测器和反电动势观测器,深入剖析其设计思路、固定点运算实现以及参数整定方法,为工程师在永磁同步电机无

cumi7754的博客 2840

Should Job Security Trump Career Satisfaction?

问:我现在正在攻读会计学硕士,目前已经修完第一学期的课程。现在,我正在考虑转到精算系,因为我觉得会计很无聊。在目前的经济环境下,我到底是应该从事我所感兴趣的领域,还是追求稳定的职业呢?答:在当前的经济形势下,无论你从事何种职业,就业稳定都很难找到稳定的就业机会。专家们表示,光是追求预计能够带来稳定就业的领域是不够的。你希望追求的方向应该是你所热爱的能够借以维持生计的职业,并且能够运用到一些你可以轻...

shake863 118

EDKII环境配置完整版

参考博客【EDK2 UDK2018的环境搭建】:https://blog.csdn.net/qq_39155263/article/details/82965744下载EDK2 1.直接从https://github.com/tianocore/edk2/ 网站下载.zip压缩文件 2.运用svn 从http://svn.code.sf.net/p/edk2/code/trunk/edk2edk2下载 3.安装Visual Studio2017 安装其他Tool 1.IASL 从https..

tianpu2320959696的博客 1864

化工模拟与优化软件:Aspen HYSYS二次开发_(15).工业应用与项目管理

项目背景、目标和主要流程。

kkchenjj的博客 1135

【设计 = 编码】 VS 【设计 ≠ 编码】

在1992年,Jack W.Reeves发表了一篇名为:Code as Design的文章,这篇文章可以在《敏捷软件开发 原则、模式与实践》一书的附录中找到。这篇文章的核心观点是:编码也是设计,而软件开发中与建筑行业中的施工所对等的工作,已经被编译器代理了。这是几近20年前的文章,但时至今日,类似的争论仍未休止。好像是在《软件架构设计》里,在讨论架构设计时,作者就点了一句:这总不能说是设计就是编码

理想流 4398

基于强化学习的多无人机路径规划

我们使用了Dueling Double Deep Q-Network(DDDQN)算法来训练智能体,这个算法在深度Q学习算法的基础上进行了升级,具有更快的收敛速度和更好的性能。本文提出了一种基于强化学习的算法,实现了多无人机路径规划,并提供相应的MATLAB代码。通过基于强化学习的多无人机路径规划算法,我们能够高效地解决复杂环境下的任务需求,并在实际应用中取得了良好的效果。首先,我们定义了状态空间和动作空间。实验结果表明,我们的方法能够有效地解决多无人机路径规划问题,提高了任务完成的效率和准确率。

DjjPython的博客 824

主题:向大家推荐一文《源代码就是设计》

按]这是一篇伟大的论文,该文撰写于1992年,作者在当时就能有这样的反思,实在是非常了不起。至今,我仍能记起当我顿悟并最终产生下面文章时所在的地方。那是1986年的夏天,我在加利福尼亚中国湖海军武器中心担任临时顾问。在这期间,我有幸参加了一个关于Ada的研讨会。讨论当中,有一位听众提出了一个具有代表性的问题,“软件开发者是工程师吗?”我不记得当时的回答,但是我却记得当时并没有真

mingxunzh的专栏 934

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

设计的最高境界----代码即是设计,设计即是代码;无设计亦有代码,无代码亦有设计...

最近,一直在思索达到什么程度才能达到架构和设计的巅峰;思索了写过的代码,在痛苦中不断总结,慢慢得到如下结论: 设计的最高境界,乃是心中有设计,不用写设计图,不用画设计图,一切尽在心中。 当然,这个不适合一般的项目过程,只适合极限编程和超级大牛。 达到这个程度,这个人需要极高的开发天赋,对于软件业的基础学科操作系统、编译器、语言以及设计有极深的理解,而且曾经研究和编写过很多代码...

java开发指南博客 【转载】 474

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

如何赚钱

第一节:成功一定是正确率大于60% 我做期货从2001年开始,至今6年,前面好几年都没有什么建树.零零碎碎地亏了不少钱,好在本来就没有什么钱,估计下来总共亏了4万多.从2005年开始,已经开始转败为胜,胜多败少, 2005年10月时,帐户上差几百元是2万,至目前为止帐面已达到32万多了. 我知道,这个战绩并不特别出色,但并非每个人都能办到.所以我想把我的一些操作写出来,让更多的人从中借鉴. 我的操

wanhahahahaha的专栏 599

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

究竟怎样写代码才算是好代码

今天让我们来谈谈代码吧。代码重要吗?当然,代码就是设计(Jack W.Reeves, 1992);代码是最有价值的交付物。我们需要好代码吗?在给“好代码”下个定义之前,这个问题无法回答。那么,究竟什么是好代码? 看下面这段英文解释: 'Good code' is code that works, is bu...

weixin_34192816的博客 461

网络学习之'独孤九剑'

在80386的电脑上有一个叫“笑傲江湖”的游戏,国产的;剑宗的风清扬使出9招剑式,威力无比,号称“独孤九剑”,令狐冲练了之后,武功迅速大增;气宗的岳不群练了数30年的“神功”,其武功确是十分地烂。这跟我们学习ccie和互联网技术是相通的,我们的学员,自从来了我们实验室,便逐渐抛弃了练神功的修炼方法,专心练起了“独孤九剑”。我想来实验室毕竟是一部分人而已,...

weixin_34375054的博客 278
上一篇: 软件思考系列之一
下一篇: 清晰性和可测试性的权衡
hoping
博客等级 码龄25年 229粉丝 28原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值