C# 编写 WinCE 下操作 INI 文件类库

C# WinCE开发实战 这里写自定义目录标题项目背景新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 项目背景 由于项目需要将程序对接设备,决定选择 新的改变 我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑 阅读详情

C# 编写 WinCE 下操作 INI 文件类库

自己留存,不做解释,如果需要可以复制代码进行学习或者使用。有三个下载链接,前两个使用的是List和HashTable集合的方式,不支持注释和空行,而另一个使用的则是ArrayList集合的方式,支持注释和空行,但由于过多的拆箱和装箱操作,所以相对于List集合的方式比较耗费资源。如果下载使用建议选择HashTable方式,简单粗暴。Microsoft Visual Studio 2008 版本,.NET Framework 2.0 下通过编译,不喜欢勿喷,可以讨论,谢谢!

List源文件下载
HashTable源文件下载
ArrayList源文下载

Field.cs

/*
 * 字段类
 */
using System;

using System.Collections.Generic;
using System.Text;

namespace IniFiles
{
    public class Field
    {
        public string Name { get; set; }    //字段名称
        public string Value { get; set; }   //字段信息
    }
}

Section.cs

/*
 * 节点类
 */
using System;

using System.Collections.Generic;
using System.Text;

namespace IniFiles
{
    public class Section
    {
        public string Name { get; set; }    //节点名称
        public List<Field> Field { get; set; }  //字段列表

        /// <summary>
        /// 构造函数
        /// </summary>
        public Section()
        {
            Field = new List<Field>();
        }
    }
}

IniFiles.cs

/*
 * IniFiles 配置文件 WinCE 类库 v1.0 版
 * 作者:派克鼠
 * QQ:53793494
 * E-Mail:53793494@qq.com
 * 完成时间:2020年6月23日
 */
using System;

using System.Collections.Generic;
using System.Text;

using System.IO;

namespace IniFiles
{
    public class IniFiles
    {
        private string strFilename = null;  // 配置文件名称
        private List<Section> sections = new List<Section>();   // 配置信息

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="strFilename">文件名称</param>
        public IniFiles(string strFilename)
        {
            this.strFilename = strFilename;
            if (!File.Exists(strFilename))
            {
                try
                {
                    FileStream fs = new FileStream(this.strFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    fs.Close();
                }
                catch { }
            }
            LoadFile();
        }

        /// <summary>
        /// 销毁函数
        /// </summary>
        ~IniFiles()
        {
        }

        /// <summary>
        /// 加载配置信息
        /// </summary>
        private void LoadFile()
        {
            bool blSection = false; // 是否为节点
            string strTemp = null;  // 临时数据

            if (sections.Count > 0) { sections.Clear(); }

            try
            {
                StreamReader sr = new StreamReader(strFilename, Encoding.Default);  // 创建文件流用于读取配置文件

                while (!sr.EndOfStream) // 循环至流的底部
                {
                    // 如果临时数据不为空,则读取一行,一般情况下只在首次读取数据,或者上一次读取到数据为空,亦或者上一次读取数据为注释语句时才会读取数据                
                    if (string.IsNullOrEmpty(strTemp)) { strTemp = sr.ReadLine(); }

                    if (strTemp.IndexOf('[') == 0 && strTemp.LastIndexOf(']') == strTemp.Length - 1)    // 确认是否是节点
                    {
                        blSection = true;   // 标记本节点开始

                        Section section = new Section();    // 创建节点
                        section.Name = strTemp.Substring(strTemp.IndexOf('[') + 1, strTemp.LastIndexOf(']') - 1);   // 写入节点

                        while (!sr.EndOfStream && blSection)    // 节点内循环
                        {
                            strTemp = sr.ReadLine();    // 读取一行临时数据

                            if (strTemp.IndexOf('=') > 0)   // 确认是否为有效字段
                            {
                                Field field = new Field();  // 创建字段
                                field.Name = strTemp.Substring(0, strTemp.IndexOf('='));    // 写入字段名称
                                field.Value = strTemp.Substring(strTemp.IndexOf('=') + 1, strTemp.Length - strTemp.IndexOf('=') - 1);   // 写入字段值
                                section.Field.Add(field);   // 加入临时节点
                            }
                            else if (!string.IsNullOrEmpty(strTemp) && strTemp.IndexOf(';') != 0)   // 确认临时数据是否为为无效字段
                            {
                                blSection = false;  // 标记节点结束
                                break;  // 退出本层循环
                            }
                        }
                        sections.Add(section);  // 加入节点列表
                    }
                    else
                    {
                        strTemp = null; // 初始化临时数据
                    }
                }

                sr.Close(); // 关闭文件流
            }
            catch { }
        }

        /// <summary>
        /// 保存配置信息
        /// </summary>
        private void SaveFile()
        {
            try
            {
                StreamWriter sw = new StreamWriter(strFilename, false, Encoding.Default);   // 创建文件流用于写入配置文件

                foreach (Section section in sections)   // 循环进入各节点
                {
                    sw.WriteLine(string.Format("[{0}]", section.Name)); // 写入节点信息
                    foreach (Field field in section.Field)  // 循环进入各字段
                    {
                        sw.WriteLine(string.Format("{0}={1}", field.Name, field.Value)); // 写入字段信息
                    }
                }

                sw.Flush(); // 清理当前编写器的所有缓冲区,并使所有缓冲数据写入基础流。
                sw.Close(); // 关闭文件流
            }
            catch { }
        }

        /// <summary>
        /// 写入字符串值
        /// </summary>
        /// <param name="strSection">节名称</param>
        /// <param name="strField">字段名称</param>
        /// <param name="strValue">字符串值</param>
        public void WriteString(string strSection, string strField, string strValue)
        {
            bool blSection = false, blField = false;

            for (int y = 0; y < sections.Count; y++)    // 遍历各节点
            {
                if (strSection.Equals(sections[y].Name))    // 找到并修改节点
                {
                    blSection = true;
                    for (int x = 0; x < sections[y].Field.Count; x++)   // 遍历各字段
                    {
                        if (strField.Equals(sections[y].Field[x].Name)) // 找到并修改字段
                        {
                            blField = true;
                            sections[y].Field[x].Value = strValue;
                            break;
                        }
                    }
                    if (!blField)   // 未找到并添加字段
                    {
                        Field field = new Field();
                        field.Name = strField;
                        field.Value = strValue;
                        sections[y].Field.Add(field);
                    }
                    break;
                }
            }

            if (!blSection) // 未找到并添加节点
            {
                Section section = new Section();
                section.Name = strSection;

                Field field = new Field();
                field.Name = strField;
                field.Value = strValue;
                section.Field.Add(field);

                sections.Add(section);
            }

            SaveFile(); // 保存配置信息
        }

        /// <summary>
        /// 读取字符串值
        /// </summary>
        /// <param name="strSection">节名称</param>
        /// <param name="strField">字段名称</param>
        /// <param name="strDefault">默认值</param>
        /// <returns>字符串值</returns>
        public string ReadString(string strSection, string strField, string strDefault)
        {
            string result = null;

            try
            {
                foreach (Section section in sections)   // 遍历各节点
                {
                    if (strSection.Equals(section.Name))
                    {
                        foreach (Field field in section.Field)  // 遍历各字段
                        {
                            if (strField.Equals(field.Name))
                            {
                                result = field.Value;
                                break;
                            }
                        }
                        if (!string.IsNullOrEmpty(result)) { break; }
                    }
                }

                if (string.IsNullOrEmpty(result)) { result = strDefault; }
            }
            catch { }

            return result;
        }

        /// <summary>
        /// 写入整数值
        /// </summary>
        /// <param name="strSection">节名称</param>
        /// <param name="strField">字段名称</param>
        /// <param name="intValue">整数值</param>
        public void WriteInt(string strSection, string strField, int intValue)
        {
            WriteString(strSection, strField, intValue.ToString());
        }

        /// <summary>
        /// 读取整数值
        /// </summary>
        /// <param name="strSection">节名称</param>
        /// <param name="strField">字段名称</param>
        /// <param name="intDefault">默认值</param>
        /// <returns>整数值</returns>
        public int ReadInt(string strSection, string strField, int intDefault)
        {
            int result = 0;

            try
            {
                result = int.Parse(ReadString(strSection, strField, intDefault.ToString()));
            }
            catch { }


            return result;
        }

        /// <summary>
        /// 写入浮点值
        /// </summary>
        /// <param name="strSection">节名称</param>
        /// <param name="strField">字段名称</param>
        /// <param name="fltValue">浮点值</param>
        public void WriteFloat(string strSection, string strField, float fltValue)
        {
            WriteString(strSection, strField, fltValue.ToString());
        }

        /// <summary>
        /// 读取浮点值
        /// </summary>
        /// <param name="strSection">节名称</param>
        /// <param name="strField">字段名称</param>
        /// <param name="fltDefault">默认值</param>
        /// <returns>浮点值</returns>
        public float ReadFloat(string strSection, string strField, float fltDefault)
        {
            float result = 0;

            try
            {
                result = float.Parse(ReadString(strSection, strField, fltDefault.ToString()));
            }
            catch { }

            return result;
        }

        /// <summary>
        /// 写入布尔值
        /// </summary>
        /// <param name="strSection">节名称</param>
        /// <param name="strField">字段名称</param>
        /// <param name="blValue">布尔值</param>
        public void WriteBool(string strSection, string strField, bool blValue)
        {
            WriteString(strSection, strField, blValue.ToString());
        }

        /// <summary>
        /// 读取布尔值
        /// </summary>
        /// <param name="strSection">节名称</param>
        /// <param name="strField">字段名称</param>
        /// <param name="blDefault">默认值</param>
        /// <returns>布尔值</returns>
        public bool ReadBool(string strSection, string strField, bool blDefault)
        {
            bool result = false;

            try
            {
                result = bool.Parse(ReadString(strSection, strField, blDefault.ToString()));
            }
            catch { }

            return result;
        }
    }
}
C#在WinCE平台开发全屏应用程序的实践指南 Windows CE,也被称为Windows Embedded Compact,是微软推出的一种实时操作系统(RTOS),主要用于嵌入式设备。与传统的桌面操作系统不同,Windows CE设计轻量级和模块化,以适应资源有限的硬件环境。C# Compact Framework是微软推出的一款专门针对移动设备和嵌入式系统的开发框架。它具备了传统.NET Framework的核心功能,同时也针对移动设备进行了优化。Compact Framework的特点主要体现在以下几个方面:轻量级。 阅读详情

相关推荐

VS2008 C#开发WinCE系统程序开发详细步骤

使用VS2008+SQLite开发的WinCE系统下的PDA程序开发,自己写了一个小Deom,希望可以帮助到初次接触这个的人。文档中提到所需要的安装资源我也会放上去的。

C#开发wince应用程序

可参考http://www.arm9home.net/read.php?tid-9891.html

电力行业解决方案 电力系统砖家 电动汽车砖家 1185

C#开发WinCE实用技术文档(12篇)

这是我在从事WinCE&C#开发嵌入式应用程序学习时搜集的技术文档,共12篇,是否有你所需要的,解压后自己找吧。

使用VS2008(2005)编写windows CE程序

首先自行下载VS2008 2005与2008版本类似,都可以编写WINCE程序,找不到2008可以用2005代替 按照以下步骤建立工程 打开软件,选择新建项目 选择C#下面的智能设备项目 其他语言类似,建立智能设备项目即可,2005一样,不过2005在这个界面就可以看见建立WINCE项目的按键了 如下图进行选择设置 建立成功 建立成功,自带一个mainMenu控件,不想要可以删除 在Windows CE 下面运行工程 我这里知道两种方法, 第一种是把WINCE设备与电脑连接,然后点击运行的符号,选择部

liu_s_s_s的博客 1134

wince下的C#读取xml文件

wince下的C#读取xml文件,wince智能项目不支持相对路径,所以没有Setting.setting配置文件,所以需要读写xml,下载文件中有详细说明

C#开发wince

C#开发wince文档 ! PDA !

Wince 下C#使用INI文件(Bug修正版)

在网上找了N久,最终也没能找到合适用的,没办法,今天自己花了几个小时的时间写了个,留着自己以后用了,经过WINCE下调试,保证可以正常运行。为了方便其它网友,现在公布出来:  ///整个单元开始 using System; using System.Collections.Generic; using System.Text; using System.IO; using System

在键盘上飞舞的日子 2578

C#开发wince嵌入式应用程序入门

C#开发wince嵌入式应用程序入门

Wince 下C#使用INI文件

using System;using System.Collections.Generic;using System.Text;using System.IO;using System.Collections;namespace SJAnalyzer //我的空间命名,你可以需要改一下。   { class ceIniFiles { string IniFileName;char[] TrimC

S5PV210开发板-保定芯灵思 888

大模型蒸馏实战:让小模型获得大模型的知识

本文为初学者提供了一份大模型蒸馏实战指南,通过情感分析任务演示如何将 BERT 的知识迁移到轻量级 TextCNN。文章结合原理图解与 PyTorch 代码,详解软标签生成、温度调节和双损失设计等核心概念,并对比蒸馏前后的性能差异(准确率提升 4.6%,推理速度达 1200 句 / 秒)。内含可直接运行的代码片段、训练技巧及常见问题解答,助力开发者快速掌握模型压缩核心技术,实现工业级部署效率。适合 NLP 入门者学习实践。

1368

Altium Designer操作技巧(1)——原理图中如何批量替换元器件?

《AltiumDesigner批量替换元器件技巧分享》摘要:本文介绍了两种在AltiumDesigner中批量替换元器件的实用方法。方法一通过“查找相似对象”功能,可精准匹配并批量修改器件参数;方法二利用ActiveBOM功能,在BOM表中直观操作器件替换,推荐使用第二种方法可使BOM管理更高效。这些技巧能有效减少物料种类、降低贴装成本,特别适用于电阻电容等常用器件的批量替换。关注公众号获取更多电子设计技巧。

u012526819的博客 2578

WINCE C#读写INI文件

最近开发一个CE上的GPS程序,用到配置存储,由于数据比较少且数据结构简单,所以采用了INI格式,WINCE没有提供windows里读写ini的函数,就自己写了一个,代码如下(C#):     //////////////////////////////////////////////////////////////////////////    //ini文件的C#读写    //钟磊

8621

利用python爬取东方财富网股吧评论并进行情感分析(一)

利用python爬取东方财富网股吧评论(一) python-东方财富网贴吧文本数据爬取 分享一下写论文时爬数据用到的代码,有什么问题或者改善的建议的话小伙伴们一起评论区讨论。 新的改变 我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,帮助你用它写博客: 全新的界面设计 ,将会带来全新的写作体验; 在创作中心设置你喜爱的代码高亮样式,Markdown 将代码片显示选择的高亮样式 进行展示; 增加了 图片拖拽 功能,你可以将本地的图片直

YMG521000的博客 1万+

wince下ini文件操作

最近开发一个CE上的GPS程序,用到配置存储,由于数据比较少且数据结构简单,所以采用了INI格式,WINCE没有提供windows里读写ini的函数,就自己写了一个,代码如下(C#):       //////////////////////////////////////////////////////////////////////////     //ini文件的C#读写  

dragon_ton的专栏 1570

python123题目——个税计算器

类型:简单分支。

m0_62488776的博客 5802

Comsol超声空化气泡仿真:从基础理论到工业应用实践

本文详细介绍了Comsol超声空化气泡仿真的基础理论及工业应用实践。通过解析超声空化现象、Comsol模型搭建流程及求解器优化技巧,帮助工程师掌握气泡仿真技术,提升超声波清洗和乳液制备等工业应用的效率与质量。

weixin_27966471的博客 251

wince ini文件操作

<br />DWORD GetPrivateProfileString( LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName) { FILE *f = NULL; DWORD dwRet = 0; ASSERT(lpReturnedString != NULL);

105694832的专栏 1651

Qt之自定义带游标的QSlider

最近翻看6年前写了一篇关于QSlider的博客:Qt自定义带游标的slider,在滑块正上方显示当前值 发现存在很多问题,比如游标的坐标不准确;如果游标宽度稍大,滑到Slider最左或最右的时候会显示不全;游标不够美观。 PS:这里有个漂亮的Slider样式表https://blog.youkuaiyun.com/caoshangpa/article/details/53389517于是今天再实现了一遍,依然是子类化QSlider,效果如下,支持设置游标的尺寸:这一次的实现比之前简洁很多,只需要重新paintEvent

草上爬的博客 6279

.net精简框架集下的ini文件读取(C#)

无论是.net框架集还是.net精简框架集都能非常完美的支持XML文件,并且微软也强烈建议用xml文件取代ini文件,但是在工控领域大部分的工程都是采用ini文件配置的系统信息的。以前的隧道管理系统是采用ini文件配置信息的,为了实现兼容,只好在下位机也采用ini文件配置信息。由于WinCE平台不提供ini文件读取的api函数GetPrivateProfileString,所以需要自行编写,前一段

小铭专栏 584

2025年最新自动化/控制保研夏令营&预推免面试真题分享(东南大学苏州校区/华东理工/南航/天大)

笔者来2021级本科自动化专业,以下部分将介绍我在夏令营以及预推免期间发生经历和问题。

Control Everything 2583

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

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

wince中对ini文件的操作

下面是代码 class ZT_INI { /************************************************************************/ /*写操作 * strSection 节 * strKey 键 * strValue 需要写入的值 * st...

weixin_34128839的博客 166

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

WINCE 读取INI文件

using System; using System.IO; namespace DeviceApplication4 { public class IniFile { /************************************************************************/ /*写操作

#Define 1748

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

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

派克鼠
博客等级 码龄20年 43粉丝 1原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值