.net2.0中对config文件的操作方法总结

.NET App.Config配置文件说明 在项目中,为了使代码更加灵活,更加方便调整,我们都在config中添加许多配置信息,一般可以选 择.NET自带的配置文件形式app.config或者web项目中的web.config来完成配置工作。 立即下载
    在.net编程中,我们经常用到config文件来保存一些常用的应用程序配置信息,在WinForm中这个文件名字是app.config,在asp.net中叫web.config。这个.config文件其实就是一个xml文件,对它的读操作微软已经提供了一个类来实现了,这个类就是System.Configuration.ConfigurationManager,下面分别是例子:
  1. //读取config里名称为“conn”数据库连接信息
  2.      connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
  3. //读取config里名称为"Font_Size"的应用程序配置信息
  4. System.Configuration.ConfigurationManager.AppSettings["Font-Size"] = 9;

不过利用这个类却不能对config文件进行写操作。对于config文件的写操作,很多人通过xml的方式来进行,按照xml的方式进行写操作在WinForm下虽然繁琐点,但是毕竟能完成。以下是按照xml文件进行写的例子。

  1. #region 保存配置
  2.             XmlDocument document = LoadXml();
  3.             XmlNode root = document.DocumentElement;
  4.             XmlNodeList nodeList = root.FirstChild.ChildNodes;
  5.             for (int i = 0; i < nodeList.Count; i++)
  6.             {
  7.                 string key = nodeList[i].Attributes["key"].Value;
  8.                 if (key == "FilterOption")
  9.                 {
  10.                     nodeList[i].Attributes["value"].Value = ((int)container.FilterOption).ToString();
  11.                 }
  12.             }
  13.             document.Save(configPath);
  14.             #endregion


但是在WebForm下,往往会因为权限不足而报错。如下图:

本文提供了另外一种方式,利用.net2.0类库里面的Configuration来进行写操作。详细介绍请看下面的详细介绍。

 

Configuration 是允许进行编程访问以编辑配置文件的类。对于WebForm的config文件,可以用如下代码得到Configuration类的实例:

  1. Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(configPath);

对于WinForm的config文件,可以用如下代码得到Configuration类的实例:

 

  1. Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(configPath);

需要注意的是,对文件进行写操作之后,需要调用Save()方法保存结果。整个程序的源代码如下,并附有详细代码注释。

  1. using System;
  2. using System.Configuration;
  3. using System.Web;
  4. using System.Windows.Forms;
  5. namespace NetSkycn.Common
  6. {
  7.     /// <summary>
  8.     /// 说明:Config文件类型枚举,
  9.    /// 分别为asp.net网站的config文件和WinForm的config文件
  10.     /// 作者:周公
  11.     /// 日期:2008-08-23
  12.     /// 首发地址:http://blog.youkuaiyun.com/zhoufoxcn/archive/2008/08/24/2823508.aspx
  13.     /// </summary>
  14.     public enum ConfigType
  15.     {
  16.         /// <summary>
  17.         /// asp.net网站的config文件
  18.         /// </summary>
  19.         WebConfig = 1,
  20.         /// <summary>
  21.         /// Windows应用程序的config文件
  22.         /// </summary>
  23.         ExeConfig = 2
  24.     }
  25.     /// <summary>
  26.     /// 说明:本类主要负责对程序配置文件(.config)进行修改的类,
  27.     /// 可以对网站和应用程序的配置文件进行修改
  28.     /// 作者:周公
  29.     /// 日期:2008-08-23
  30.     /// 首发地址:http://blog.youkuaiyun.com/zhoufoxcn/archive/2008/08/24/2823508.aspx
  31.     /// </summary>
  32.     public class ConfigurationOperator
  33.     {
  34.         private Configuration config;
  35.         private string configPath;
  36.         private ConfigType configType;
  37.         /// <summary>
  38.         /// 对应的配置文件
  39.         /// </summary>
  40.         public Configuration Configuration
  41.         {
  42.             get { return config; }
  43.             set { config = value; }
  44.         }
  45.         /// <summary>
  46.         /// 构造函数
  47.         /// </summary>
  48.         /// <param name="configType">.config文件的类型,只能是网站配置文件或者应用程序配置文件</param>
  49.         public ConfigurationOperator(ConfigType configType)
  50.         {
  51.             this.configType = configType;
  52.             if (configType == ConfigType.ExeConfig)
  53.             {
  54.                 configPath = Application.ExecutablePath; //AppDomain.CurrentDomain.BaseDirectory;
  55.             }
  56.             else
  57.             {
  58.                 configPath = HttpContext.Current.Request.ApplicationPath;
  59.             }
  60.             Initialize();
  61.         }
  62.         /// <summary>
  63.         /// 构造函数
  64.         /// </summary>
  65.         /// <param name="path">.config文件的位置</param>
  66.         /// <param name="type">.config文件的类型,只能是网站配置文件或者应用程序配置文件</param>
  67.         public ConfigurationOperator(string configPath, ConfigType configType)
  68.         {
  69.             this.configPath = configPath;
  70.             this.configType = configType;
  71.             Initialize();
  72.         }
  73.         //实例化configuration,根据配置文件类型的不同,分别采取了不同的实例化方法
  74.         private void Initialize()
  75.         {
  76.             //如果是WinForm应用程序的配置文件
  77.             if (configType == ConfigType.ExeConfig)
  78.             {
  79.                 config = System.Configuration.ConfigurationManager.OpenExeConfiguration(configPath);
  80.             }
  81.             else//WebForm的配置文件
  82.             {
  83.                 config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(configPath);
  84.             }
  85.         }
  86.         /// <summary>
  87.         /// 添加应用程序配置节点,如果已经存在此节点,则会修改该节点的值
  88.         /// </summary>
  89.         /// <param name="key">节点名称</param>
  90.         /// <param name="value">节点值</param>
  91.         public void AddAppSetting(string key, string value)
  92.         {
  93.             AppSettingsSection appSetting = (AppSettingsSection)config.GetSection("appSettings");
  94.             if (appSetting.Settings[key] == null)//如果不存在此节点,则添加
  95.             {
  96.                 appSetting.Settings.Add(key, value);
  97.             }
  98.             else//如果存在此节点,则修改
  99.             {
  100.                 ModifyAppSetting(key, value);
  101.             }
  102.         }
  103.         /// <summary>
  104.         /// 添加数据库连接字符串节点,如果已经存在此节点,则会修改该节点的值
  105.         /// </summary>
  106.         /// <param name="key">节点名称</param>
  107.         /// <param name="value">节点值</param>
  108.         public void AddConnectionString(string key, string connectionString)
  109.         {
  110.             ConnectionStringsSection connectionSetting = (ConnectionStringsSection)config.GetSection("connectionStrings");
  111.             if (connectionSetting.ConnectionStrings[key] == null)//如果不存在此节点,则添加
  112.             {
  113.                 ConnectionStringSettings connectionStringSettings = new ConnectionStringSettings(key, connectionString);
  114.                 connectionSetting.ConnectionStrings.Add(connectionStringSettings);
  115.             }
  116.             else//如果存在此节点,则修改
  117.             {
  118.                 ModifyConnectionString(key, connectionString);
  119.             }
  120.         }
  121.         /// <summary>
  122.         /// 修改应用程序配置节点,如果不存在此节点,则会添加此节点及对应的值
  123.         /// </summary>
  124.         /// <param name="key">节点名称</param>
  125.         /// <param name="value">节点值</param>
  126.         public void ModifyAppSetting(string key, string newValue)
  127.         {
  128.             AppSettingsSection appSetting = (AppSettingsSection)config.GetSection("appSettings");
  129.             if (appSetting.Settings[key] != null)//如果存在此节点,则修改
  130.             {
  131.                 appSetting.Settings[key].Value = newValue;
  132.             }
  133.             else//如果不存在此节点,则添加
  134.             {
  135.                 AddAppSetting(key, newValue);
  136.             }
  137.         }
  138.         /// <summary>
  139.         /// 修改数据库连接字符串节点,如果不存在此节点,则会添加此节点及对应的值
  140.         /// </summary>
  141.         /// <param name="key">节点名称</param>
  142.         /// <param name="value">节点值</param>
  143.         public void ModifyConnectionString(string key, string connectionString)
  144.         {
  145.             ConnectionStringsSection connectionSetting = (ConnectionStringsSection)config.GetSection("connectionStrings");
  146.             if (connectionSetting.ConnectionStrings[key] != null)//如果存在此节点,则修改
  147.             {
  148.                 connectionSetting.ConnectionStrings[key].ConnectionString = connectionString;
  149.             }
  150.             else//如果不存在此节点,则添加
  151.             {
  152.                 AddConnectionString(key, connectionString);
  153.             }
  154.         }
  155.         /// <summary>
  156.         /// 保存所作的修改
  157.         /// </summary>
  158.         public void Save()
  159.         {
  160.             config.Save();
  161.         }
  162.     }
  163. }

 

用法实例:
(一)WebForm中的用法

 

  1. ConfigurationOperator co = new ConfigurationOperator(ConfigType.WebConfig);
  2.         string key = txtConnectionStringKey.Text;
  3.         string value = txtConnectionStringValue.Text;
  4.         co.AddConnectionString(key, value);
  5.         co.Save();

(二)WinForm中的用法

  1. ConfigurationOperator co = new ConfigurationOperator(ConfigType.ExeConfig);
  2.             co.AddAppSetting("Font-Size", "9");
  3.             co.AddAppSetting("WebSite", "http://blog.youkuaiyun.com/zhoufoxcn");
  4.             co.AddConnectionString("Connection", "test");
  5.             co.Save();//保存写入结果

我在WinForm里加入了一个空白的app.config文件,经过上面的操作得到如下结果(这个文件是和最后生成的exe文件在同一个目录下,而不是和源代码在同一文件夹下的那个config文件):

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3.     <appSettings>
  4.         <add key="Font-Size" value="9" />
  5.         <add key="WebSite" value="http://blog.youkuaiyun.com/zhoufoxcn" />
  6.     </appSettings>
  7.     <connectionStrings>
  8.         <add name="Connection" connectionString="test" />
  9.     </connectionStrings>
  10. </configuration>

经过这个封装类可以简化对config配置文件的操作,仅仅是需要在实例化Configuration类的实例时指明打开的是网站还是应用程序的config文件,并且在进行了所有修改和增加操作之后调用Save()方法保存所做的修改即可。

 

转自:http://blog.youkuaiyun.com/zhoufoxcn/archive/2008/08/24/2823508.aspx

net2.0中对config文件的操作方法.cs 立即下载

相关推荐

SAP中成本估算没有找到工艺路线消息处理实例

在针对成品的标准成本核算处理过程中,系统中会经由设定好的策略来收集成品相关成本组成,最终计算出产成品的标准成本。关于成本组成,可以归纳为三个基本要素,料,工,费。即标准成本就是要知道,生产一件成品,需要消耗多少钱的原材料?消耗多少钱的人工?以及其它的间接消耗? 某日,接到CO同事的反馈,在用CK11N做产成品标准价格核算时,提示没有工艺路线确定,但该消息为绿灯,可以通过。基于业务上的谨慎,提出分析。 从提示可以看出问题与工艺路线有关。因为,成品工艺路线中设定有成品生产所耗工时,所以,在计算产成品标准

专注SAP应用技术文章写作,致力于拉近用户与系统间的距离; 6279

.NET程序配置文件

配置文件是标准的XML文件,可以用来更改应用程序的设置和设置策略。.NET框架的配置模式由元素组成,你可以在配置文件中使用这些元素来控制应用程序的行为表现。本节的内容表将反映了启动、运行时、网络和其它类型配置设置项的架构层次结构。那什么是配置文件的架构呢?说一说我的理解,首先.NET平台下可以开发各种类型的程序(Web的、桌面的、移动端的等等)。在这些不同类型程序的工程中,用到的配置文件在内容和组织形式上有所不同。那每种工程更适合怎样的内容/形式的配置文件呢?............

三千幻想乡 2584

手把手教你用Silvaco Atlas复现GaN蓝光LED仿真:从网格划分到光谱分析全流程避坑

本文详细介绍了如何使用Silvaco Atlas进行GaN蓝光LED仿真,从网格划分到光谱分析的全流程避坑指南。重点讲解了网格划分技巧、材料参数设置、极化效应处理以及结果分析方法,帮助用户快速掌握半导体器件仿真技术,提升研发效率。

weixin_42552716的博客 224

.net 程序Config文件解读

暂时link官方文档至此处,稍后更新自己的理解 http://msdn.microsoft.com/en-us/library/1fk1t1t0(v=vs.100).aspx

guotieyun的专栏 1034

NVIDIA vGPU三种授权方式(个人玩家版)

NVIDIA vGPU三种方式搭建授权服务器(个人玩家版)

wstc2689784536的博客 8436

从零到一:AnythingLLM与Ollama的本地知识库搭建实战

本文详细介绍了如何使用AnythingLLM与Ollama从零开始搭建本地知识库,涵盖技术选型、环境部署、系统配置及优化策略。通过RAG技术架构,实现安全高效的文档管理与智能问答,特别适合企业及个人构建私有化知识管理系统。

weixin_29079643的博客 562

dotnet常用命令详解

NET CLI 使用 NuGet 来查找项目需要的依赖,如果本地缓存中没找到,则下载它们放到本地缓存中,还原过程中会检测相关依赖的兼容性。nuget locals:命令清除或列出 http 请求缓存、临时缓存或计算机范围的全局包文件夹中的本地 NuGet 资源。所以此命令的场景一般用于在自动化部署的流程中控制执行流程中使用,先在其他命令中使用。run 命令会使用依赖的缓存,所以不建议在生产环境使用此命令运行应用。watch:运行项目在热重载模式下,即监听文件的变更会自动重启项目。

tangPHP的博客 2941

SAP中错记虚拟利润中心的调整,冲销处理实例

我非CO专业顾问。工作中遇到的问题,也会找资料,分析,测试。有时这个过程会拿到结果,解决问题。遂将过程记录下来备查。读者请谨慎参考!EC-PCA: 利润中心记账流程_9ke0-优快云博客。

专注SAP应用技术文章写作,致力于拉近用户与系统间的距离; 1796

.NET中对config文件的操作方法总结

在.net 编程中,我们经常用到config文件来保存一些常用的应用程序配置信息,在WinForm中这个文件名字是app.config,在asp.net中叫 web.config。这个.config文件其实就是一个xml文件,对它的读操作微软已经提供了一个类来实现了,这个类就是 System.Configuration.ConfigurationManager,下面分别是例子: ...

weixin_30462049的博客 269

数字图像处理:直方图匹配或规定化Histogram Matching (Specification)原理及感悟

本文介绍了连续图像和数字图像直方图匹配(直方图规定化)的原理、处理过程,并提供了案例进行了讲解。可以看到,直方图均衡处理是直方图匹配的一个重要桥梁。 最后,对于直方图规定化这个翻译个人觉得很low,个人感觉叫指定直方图更好理解,但Histogram Specification怎么翻译确实不太好把握,因此还是叫Histogram Matching直方图匹配最好。

老猿Python 2880

【unity实战】Spline 插件让物体沿路径 “丝滑” 走位,实现火车沿轨道移动——Spline 插件的使用

Unity Spline系统教程:实现火车轨道移动 摘要:本文介绍了Unity Spline系统的核心功能与实战应用,通过火车轨道移动案例演示了完整开发流程。内容包括:1)安装Spline包并绘制样条线轨道;2)调整样条节点和曲线弧度;3)使用Spline Instantiate组件实例化轨道模型;4)通过Spline Animate组件实现小车自动沿轨移动;5)补充讲解了轨道闭合、分支节点、循环模式等进阶技巧。该系统可用于创建河流、摄像机路径等多种曲线应用,文中提供了官方文档链接和详细操作步骤,适合Uni

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 1828

.Net 应用程序config的配置

文件的目录(若要对config配置文件进行操作,需要添加对的引用)     调用方式  //获取配置节数据   var obj= System.Configuration.ConfigurationManager.GetSection("myConfigSection");   1.App.config 文件 &lt;?xml version="1.0" encoding="ut...

qq_18298653的博客 883

对角两对双差速轮AGV的平移、直行、转弯和原地旋转之PID控制

本示例将展示如何使用PID控制算法,控制具有对角线布置的两对双差速轮(左前和右后)的AGV,实现平移、直行、转弯和原地旋转等运动。通过对车辆的运动学和PID控制器的设计,我们可以精确地控制AGV的运动

xiaoc100200的博客 1510

net2.0中对config文件的操作方法总结

标签:asp.net config 操作方法 dotnet 转载自: http://zhoufoxcn.blog.51cto.com/792419/166844         在.net编程中,我们经常用到config文件来保存一些常用的应用程序配置信息,在WinForm中这个

Miracle_Lee 605

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

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

在.net2.0中对config文件的操作方法总结

<br />在.net程序开发中,我们经常会在config文件来保存一些常用的应用程序配置信息,在WinForm中这个文件名字是app.config,在asp.net中叫web.config。这个.config文件其实就是一个xml文件,对它的读操作微软已经提供了一个类来实现了,这个类就是System.Configuration.ConfigurationManager,下面分别是例子: <br />//读取config里名称为“conn”数据库连接信息 <br />     connectionStrin

winddai的专栏 363

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

上一篇: vss的安装配置
下一篇: 用emacs做为CC++集成开发环境
evilmojo
博客等级 码龄18年 16粉丝 23原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值