《thinking in c++》Volume 1知识点总结(二)

《thinking in c++》Volume 1知识点总结(一) 对于《thinking in c++》的知识点总结 阅读详情

Chapter9: Inline Function

1、C++中我们不会使用macro定义成员函数,因为macro没有权限访问数据成员;macro不属于任何类;对于类对象不能使用“.”运算符;且没有被封装,一但被定义就可以被任何类使用

相反,C++的inline function可以解决这个问题

2、Inline function

inline function确实是函数,且在调用时被扩展

在class里定义的函数默认为inline function,在class外定义的函数应在前面加上inline关键字,才为inline function

inline function常用于accessors和mutators

3、不能实现函数inline的情况

函数太复杂,具有循环或代码很长

函数的地址被引用

Recursive reference

class X{

        int i;

public:

       int f()const{ return g()+1; } //forward reference,inlining is ok

       int g()const{ return i; }

};

class X{

       int i;

public:

       int f()const{ return g()+1; } //recursive reference,inlining is impossible

       int g()const{ return f()+i; }

};

4、Hidden activities in constructors& destructors

class Member {

       int i, j, k;

public:

     Member(int x = 0) : i(x), j(x), k(x) {  }

     ~Member() { cout << "~Member" << endl; }

};

class WithMembers {

     Member q, r, s; 

     int i;

public:

     WithMembers(int ii) : i(ii) { }

    ~WithMembers() { cout << "~WithMembers" << endl; }

};

此时构造WithMembers还需调用3次Member的构造函数,因此将WithMembers的constructor定义为inline反而降低了效率

 

Chapter10: Name Control

1、Static objects inside functions

函数第一次被调用时,static objects才调用constructor进行构造,且只构造一次

当程序调用exit()退出时,才调用destructor析构static objects

如果函数没有被调用,则static objects不会被构造更不会析构

构造顺序:global—>static 析构顺序:static—>global

程序的对象析构顺序总是与构造顺序相反的

2、Namespace:在一个大项目中避免名字冲突的有效方法

可以内嵌,且结尾处没有分号

一个名字空间的定义可以出现在几个头文件中,这不会造成重定义

可以运用别名:namespace Bob=BobsSuperDuperLibrary;

3、Unnamed namespace和static具有相同的作用

namespace {

class Arm  { /* ... */ };

      class Robot {

            Arm arm[4];

            ...

      } xanthan;

     int i, j, k;

}

int main() { }

4、当声明某个函数f()为某一namespace中某一class的friend函数时,该函数f()会变为该名字空间的一员

5、Declare a namespace member:以cout为例

Scope resolution:

std::cout<<“num”<<num;

The using directive:

using namespace std;

cout<<“num”<<num;

The using declaration:

using std::cout;

cout<<“num”<<num;

6、当两个名字空间中具有相同名函数时,作用域内declare范围小的会被调用(范围scope resolution>the using directive>the using declaration),且与顺序无关

若同时出现两个declare范围相同,则会造成冲突出错

namespace U {

   inline void f() { }

}

namespace V {

   inline void f() { }

} 

void h() {

using V::f; 

   using namespace U; 

   f();   // V::f() will be called.

   U::f(); 

}

void g() {

using namespace V;

   using namespace U; 

   !f();   //wrong!

   U::f(); 

}

7、Using namespace

在头文件不要使用global using directive,在cpp文件使用global using directive

使用explicit qualification or declaration避免名字冲突

8、Static data members:a single piece of storage shared by all objects of a class

在类内进行声明,必须在类外部进行有且仅有一次的定义,可以更改

int x = 100;

class WithStatic {

   static int x;

   static int y;

};

int WithStatic::x = 1;

int WithStatic::y = x + 1; //x is WithStatic’s x

9、Static member functions:Essentially a global function which is scoped inside a class

static member function可以不通过类对象直接调用,即X::fun()

函数没有this指针,只能访问static data members

函数中不能调用non-static member function

10、Make a singleton:只有一个对象的类

class Egg {

int i;

    static Egg singleton; //must be static

    Egg(int ii) { i=ii; } //avoid calling constructor

    Egg(const Egg &); //avoid copy-constructor

public:

    static Egg * instance( ) {return & singleton; } //must be static to access singleton

    void print()  { cout << i << endl; }

};

Egg Egg::singleton(0); //define the only object

int main() {

    Egg::instance( )->print( ); 

}

11、Static initialization dependency

// is added to the project file first

#include <fstream>

extern std::ofstream  out;

class X{

public:

        X() { out << "hello" << std::endl;} //wrong, out hasn’t been defined!

} x;

 

// is added to the project file later

#include <fstream>

std::ofstream out("data.txt");

 

Solution1:Use an additional class

#ifndef INIT_H

#define INT_H

#include <fstream>

 

extern std::ofstream  * out;

class X{

public:

X() { *out << "hello" << std::endl;}

};

extern X *x;

class Initializer {

static int flag;

public:

    Initializer() {  

if (flag == 0) {

         out = new std::ofstream("data.txt");

          x= new X(); flag ++;

}

}

~Initializer() { if (flag != 0) {

           delete x; delete out; flag =0;

}

}

};

static Initializer init;

#endif

Solution2:Use static objects inside functions

// first file in the project

#include <fstream>

std::ofstream & get_out();

class X{

 public:

        X() { get_out() << "hello" << std::endl;}

} x;

// second file in the project

#include <fstream>

std::ofstream & get_out() {

      static std::ofstream out("data.txt");

      return out;

}

 

Chapter11: References & the Copy-Constructor

1、References in C++

引用必须与一块内存绑定且不可改变,并在定义时完成绑定,不存在NULL reference

当访问一个引用对象时,事实上是在访问它所指的那块内存,故可以借此改变对象的值

2、References in functions

在函数对引用对象的任何改变都会引起函数外该参数的改变

当一个函数return a reference的时候,必须确保引用指向的object在函数结束后依旧存在,即该object不是局部变量和临时变量

int& h() {

   int q;

!return q;  //wrong!

}

int & k(){

   static int x;

  return x;  //ok

}

3、Constant references

对于built-in types:意味着不改变形参的值

对于user-defined classes:意味着只调用const member function,且不改变public数据成员

形参以const Typename&形式模拟C中的按值传递参数,且由于没有复制过程,这种形式比按值传递效率高

4、Pointer references

void f( int * & p ) { p++; }

int * ip;  f(ip);

使用引用使得语句更加简洁,易阅读

5、Copy-constructor:实现class的pass-by-value

class X{

public:

       X(const X&);

};

可能会在“=”,“()”,按值传递函数参数或返回值被调用

int main() {

  HowMany h("h");

  HowMany h2 = f(h); //call copy-constructor twice

}

6、Default copy-constructor:

当class没有copy-constructor时,编译器会自动合成一个copy-constructor

对于普通类(no class composition and inheritance):default copy-constructor只是进行字节拷贝

对于classes with composition or inheritance:default copy-constructor会自动给每一个embedded object合成copy-constructor

7、Have your own copy-constructor

写自己的copy-constructor时,需要自己构建全部embedded object

default copy-constructor只能进行浅拷贝,自己写的copy-constructor才能实现深拷贝(针对class对象存在指针的情况)

如果不希望pass-by-value,则需将copy-constructor声明为private

8、Pointer to data members and member functions

Pointer to data members:

X d;

X *dp=&d;

int X::*p=&X::a;

dp—>*p=1; //the same as d.*p=1;

Pointer to member functions:

X d;

   X *dp = &d;

void (X::*pmem)(int) const;

pmem = &X::h;

(dp—>*pmem)(1); //the same as (d.*pmem)(1);

 

Chapter12: Operator Overloading

1、Operator overloading只对用户定义的类有用

Operator overloading为当前类的运算符赋予新的意义,增加程序的可读性

2、Syntax

Global functions:

    Unary operator —> one argument

    Binary operator —>two arguments

Member functions:

    Unary operator —> zero argument

    Binary operator —> one argument

3、Constraints

不能通过结合两个已存在的运算符创造新的运算符

运算符的优先级和结合顺序不会改变

4、Function arguments and return value

Function arguments通常为const,+=等operator例外

Return value:return a non-const value时(a+b).func()合法;return a const value时(a+b).func()非法

5、iostream类operator(<<,>>)

friend ostream& operator<<(ostream& os,const Typename & T);

friend istream& operator>>(ostream& is,Typename & T);

6、Necessary behavior of operator=

simple class:拷贝所有必要的信息

class with pointers:

为指针所指对象分配新的内存;引用计数(reference counting)

7、Automatic type conversion

constructor conversion: X(int i);

函数存在于目标类中

不能够进行user_type—>built-in type的转换

加入explicit关键字后,不能自动进行转换

operator conversion: operator X()const { return X; } 

函数存在于源类中

能够进行user_type—>built-in type的转换

 

Chapter14: Inheritance & Composition

1、Rules for access control

class B: public D{ //inheritance access control

public: //class access control

       int a;

};

继承access control并不影响派生类成员函数对数据成员的访问,只对外部函数有影响

protected概念上是指在被派生类中允许被访问

最终在派生类中的访问权是access path上范围最小的

默认继承access control为private

class B {

public: int pub;

protected:    int pro;

private:      int pri;

};

B—public>D1—protected>D2 D2可以访问pub,pro

B—protected>D1—protected>D2 D2可以访问pub,pro

B—private>D1—protected>D2 pub、pro、pri D2均不可访问

2、The initialization list

class C : public B {

A a;

public:

   C(int ii) : B(ii), a(ii) { }

};

当A或B存在default constructor,不需要在initialization list显式调用,即C(int ii){}

3、Order of constructor & destructors calls

constructor calls:

从继承树的根部开始构造;在每个水平上,基类的构造函数先被调用,然后根据声明顺序调用成员对象的构造函数

destructor calls:

与constructor的调用顺序相反

4、Name hiding

当在一个派生类中重定义一个基类的函数名时,基类中所有相同函数名的函数在派生类中都会丢失

class Base {

public:

   int f( ) const {   

     cout << "Base::f()\n"; 

     return 1; 

   }

   int f(string) const { return 1; }

   void g( ) {}

};

 

class Derived : public Base {

public:

   void g() const {}   

};   // both f are available, g() is unavailable

5、Special points

constructors、destructors和operator=不能继承

static member functions在继承上和non-static member function是相同的,但static member functions不能被声明为virtual函数

6、Choosing composition vs. inheritance

composition: has-a relationship

inheritance: Is-a relationship

private Inheritance可以用private composition代替

class A{

public:

void print(){}

};

class B{                                                                 class C: private A{

A a;                                                                        public:

public:                                                                         using A::print;

       void print(){ a.print(); }                                    };

};

以上B与C是等价的

7、Upcasting(Instrument—>Wind只发生在public继承和protected继承的派生类中)

由于Wind是一种Instrument,故Wind对象能调用Instrument的所有成员函数;任何以Instrument为argument的函数都可以接受一个Wind对象,当这个argument为指针或引用时,会导致upcasting;upcasted pointer or reference会丢失派生类的信息

enum note { middleC, Csharp, Cflat }; 

class Instrument {

public:

   void play(note) const  { }

};

class Wind : public Instrument { };

void tune(Instrument& i) {

   // ...

   i.play(middleC);

}

int main() {

   Wind flute;

   tune(flute); //call Instrument’s play()

}

upcasting对于派生类的copy-constructor的定义很有用

class Derived : public Base {

    A a;

public:

   Derived(const Derived& d): Base(d), a(d.a) {} //copy-constructor

}; 

 

Chapter15: Polymorphism & Virtual Functions:

(upcasting + virtual function—Late Binding>Polymorphism)

1、Early binding & Late binding

Early binding:compile binding (function name overloading)

编译器在编译阶段确定每个对象调用的函数的地址 (14.7例子为Early binding)

Late binding:dynamic binding,runtime binding

编译器在运行阶段根据每个对象的实际类型确定对象调用的函数的地址

enum note { middleC, Csharp, Cflat }; 

class Instrument {

public:

   virtual void play(note) const  { }

};

class Wind : public Instrument { };

void tune(Instrument& i) {

   // ...

   i.play(middleC); //Late binding

}

int main() {

   Wind flute;

   tune(flute); //call Wind’s play()

}

对于类对象,编译器只会使用Early binding;对于类对象的指针或引用,编译器才可能使用Late binding

2、Virtual function

只有成员函数能声明为virtual,函数定义不需要加virtual关键字

基类函数为virtual时,派生类中该函数都为virtual

virtual function是实现Late binding的前提

3、C++中是通过VTABLE和VPTR实现Late binding

对于每个包含virtual function的class,只有一个VTABLE会被构建

类对象并不包含VTABLE,但每个类对象用一个各自的VPTR

VPTR记录了类对象的类型信息,VPTR在constructor中初始化

函数的地址以相同的顺序保存在VTABLE中

4、Abstract base classes and pure virtual function

abstract base class:为派生类提供共同的接口;不能创建其类对象;至少含有一个pure virtual function

pure virtual function:形如virtual void print()=0;

类构建时,VTABLE中函数的顺序已经安排好,但没有任何pure virtual function的地址会被保存

基类pure virtual function在派送类中必须进行定义

派生类可以自主添加另外的virtual function或common function,派生类新定义的virtual function从当前派生类开始为virtual,原基类同名函数不为virtual

5、Object slicing

当将派生类对象按值传递给基类对象时,会得到一个真正的基类对象,此时会发生object silcing,VPTR会改变,故对于类对象,编译器只会使用Early binding

6、Name hiding for virtual functions

重载虚函数不能够改变返回值类型,但可以有不一样的参数

7、Constructor、destructor and virtual function

由于没有VPTR(VPTR在constructor中初始化),故不能够把constructor定义为virtual

应该将destructor定义为virtual,此时delelte an upcasted pointer才能正确析构

在任何constructor和destructor中,调用virtual function时为Early binding,这是由于派生类对象还未被构建或已被析构

8、Downcasting

Circle * pc = new Circle;

Shape *ps = pc;

pc =dynamic_cast<Circle*> ps;

只有当ps原本就指向一个Circle对象时,downcasting能成功

 

Chapter16: Introduction to Templates

1、Use template to construct general vector

template<class T> //parameterized type

class X{

       ...

};

X<int>, X<double> ...

2、Multiple parameters & Default parameters

template<class T, int size> //multiple parameters

class Stack{

       T stack[size];

       ...

};

Stack<int, 100> s, Stack<string, 20> ...

template<class T, int size=100> //default parameters

3、Container:a data structure whose length can vary automatically at runtime

容器有自动调节容量大小的函数

4、Introduction of iterators:a smart pointer

iterator提供了遍历container和访问container中元素的接口

所有的iterator有共同的接口:begin(), end(), ++, --, *, —>

各容器的iterator通常作为其nested class在container中声明实现

template<class T, int size=100>

class Stack{

T stack[size];

       int top;

public:

       class iterator;

       friend class iterator;

       class iterator{

              Stack& s;

              int dex;

       public:

              iterator(Stack& st): s(st), index(0){}

              iterator(Stack& st, bool): s(st), index(s.top){}

              ...

       };

...

};

5、The typename keyword

two condition:

Used for a name which depends on a template argument

template<typename T>

class X{

...

};

The type is nested within the template argument

template<class T>

class X{

typename T::iterator itr;

...

};

6、Function templates

一种可以处理多种数据类型的函数;函数第一次调用之前模板类型不会确定

template <typename T>

T array_sum(T * p, int n){

T sum=0;

for (int i=0; i<n; i++) 

        sum += *p++;

        return sum;

}

int main (){   

        int ia [3]={1, 2, 3};

        double da [4]={1, 2, 3, 4};

        cout<<array_sum<int>(ia,3);

        cout<<array_sum<double>(da,4);

}

7、Automatic type deduction:calling arguments—>template type

type和value都可以进行推断,推断出的type或value需与其他调用的参数一致

class templates不能进行type deduction

template <typename Dest, typename Src>

Dest implicit_cast (Src s) 

{ 

return s;

}

int main(){

int i;

        !implicit_cast(i); //no have enough argument

        implicit_cast<double>(i);

        implicit_cast<char,double>(i);

        implicit_cast<char*, int> (i); //int can’t be cast to char*

}

8、The moment of instantiation

对于function template,在调用函数时instantiated

对于class template,每个成员函数都在调用时才instantiated

别再手动调格式了!用EndNote搞定中英文混排文献的保姆级教程(含‘等’与‘et al.’共存方案) 本文提供了一份EndNote中英文混排文献自动化管理的保姆级教程,详细介绍了如何利用EndNote的智能分类、输出样式定制和批量操作功能,彻底解决中英文文献格式混乱问题。特别包含‘等’与‘et al.’共存的实用方案,帮助科研人员高效管理文献,告别手动调格式的烦恼。 阅读详情

相关推荐

Ollama+Open WebUI本地AI部署全指南:离线可控、国产镜像加速

本地大模型部署正从概念走向工程实践,其核心在于实现模型推理、API服务与交互界面的全链路自主可控。Ollama作为轻量级模型运行时,提供统一的模型加载、硬件适配与OpenAI兼容API;Open WebUI则超越传统前端,构建起支持RAG、插件扩展与多源模型调度的AI工作流平台。二者组合解决了数据不出域、低依赖运维、中文场景优化等关键需求,广泛应用于企业知识库、会议纪要自动化、代码辅助等私有化AI场景。本文聚焦国内网络环境下的高效落地,深度整合OLLAMA_HOST镜像源配置与host.docker.int

dicha7140的博客 427

体积(volume)题解c++(dfs)

题目描述 给出n件物品,每件物品有一个体积Vi,求从中取若干件物品能够组成不同的体积和有多少种可能。例如,n=3,Vi=(1,3,4),那么输出6,6种不同的体积分别为1,3,4,5,7,8 输入格式 第一行一个正整数,表示n。 第二行n个正整数,表示Vi,每两个数间用一个空格隔开。 输出格式 一行一个数,表示有多少种可能 输入样例 3 ...

m0_61067261的博客 1955

think in c++ volume 1

think in c++ volume 1

C语言 预处理命令

预处理过程扫描源代码,对其进行初步的转换,产生新的源代码提供给编译器。可见预处理过程先于编译器对源代码进行处理。在C语言中,并没有任何内在的机制来完成如下一些功能:在编译时包含其他源文件、定义宏、根据条件决定编译时是否包含某些代码。要完成这些工作,就需要使用预处理程序。尽管在目前绝大多数编译器都包含了预处理程序,但通常认为它们是独立于编译器的。预处理过程读入源代码,检查包含预处理指令...

tuyerv的博客 818

GD32F4系列Keil工程模板搭建全攻略(手把手教学版)

本文提供了一份详细的GD32F4系列Keil工程模板搭建指南。从软件安装、固件库获取、目录规划,到Keil工程创建、文件添加、关键配置(如编译器选项、头文件路径、时钟设置),再到代码定制与常见问题排查,手把手教你构建一个标准化、模块化的开发基础。文章重点介绍了如何利用官方固件库和代码模板,快速建立稳定高效的开发环境,适用于GD32F407等Cortex-M4内核芯片的入门与项目开发。

weixin_29159995的博客 430

simulink调用C代码函数-C Caller模块

simulink中如何调用写好的C代码函数?使用C Caller模块调用C代码。

weixin_40531919的博客 5681

C++编程思想 第2卷 第9章 多重继承 虚基类

菱形继承 Left和Right值对象在一个完整的Bottom对象内部共享着一个Top对象 使Top成为Left和Right的一个虚基类 //: C09:VirtualBase.cpp // From "Thinking in C++, Volume 2", by Bruce Eckel &amp; Chuck Allison. // (c) 1995-2004 MindView, Inc. A...

eyetired的博客 179

Transformers 中的 Softmax 可以并行加速么?

通过融合前两个计算步骤,降低执行Reduce_max和Reduce_sum等操作的通信开销。利用共享内存来存储临时数据,以减少对全局内存的访问成本。

stephen147的博客 1239

Thinking in Java [Java编程机制] 学习笔记 -- 初始化顺序Order of initialization

首先 初始化的顺序和变量声明的顺序有关,并且变量(包括primitive types and object reference)的初始化一定是在所有方法被调用之前,甚至constructor也要在此之后。 静态数据初始化 static data initialization 所有的静态数据都存储在一片存储区中,初始化也只会进行一次。初始化顺序是这样的:1.static(如果已经初始化

My World 1350

深入解析高通8155平台音频数据流:从HAL到DSP的完整链路

本文深入解析了高通8155平台音频数据从安卓HAL层到DSP的完整传输链路。以播放场景为例,详细阐述了音频数据如何通过ASoC DPCM框架进行路由、打包,并经由APR协议与DSP交互,最终驱动硬件发声的核心流程,为车载音频系统开发与调试提供了清晰的框架。

rust6ferris的博客 1181

Tesla V100 在 Windows 下的驱动选择与模式切换实战

本文详细解析了Tesla V100专业计算卡在Windows系统下的驱动安装与模式切换实战。针对设备管理器识别但任务管理器“隐身”的常见问题,文章指出其默认TCC模式为纯计算设计,并指导用户正确选择数据中心或GRID驱动。核心在于通过注册表修改或驱动选择,在高效的TCC模式与便于监控的WDDM模式间切换,同时提供了nvidia-smi命令行监控与AI框架测试等稳定使用方案。

weixin_29247219的博客 1823

Android之隐藏Activity界面的方法

moveTaskToBack(true);//activity 隐藏 清单文件 activity: android:configChanges="orientation|keyboardHidden|keyboard" android:launchMode="singleInstance" android:theme="@android:style/Theme.Black...

谁对谁错重要吗的博客 9684

FAST-LIO2实战:从零搭建香港大学火星实验室SLAM框架(附官方数据集测试指南)

本文提供了一份详细的FAST-LIO2实战指南,帮助读者从零开始搭建香港大学火星实验室开源的这一高效激光惯性里程计框架。内容涵盖系统环境配置、依赖安装、源码编译、官方数据集测试以及参数调优,旨在让开发者快速上手并应用于机器人SLAM项目。

ppp33的博客 691

《Thinking in C++, 2nd Edition》笔记-第十章(Name Control)

static关键字有时控制存储分配,而有时控制一个名字的可见性和连接。它的含义因此经常是相互冲突的: (1)在静态数据区上创建对象,而不是每次函数调用时在堆栈上产生。这也是静态存储的概念。 如果想在两次函数调用之间保留一个变量的值,我们可以通过定义一个全局变量来实现这点,但这样一来,这个变量就不仅仅受这个函数的控制,还受其它函数影响。C和C++都允许在函数内部创建一个static对象,这个对象

734

Python与CAD系列基础篇(十)图形复制、移动、删除

①通过pyautocad连接AutoCAD进行处理②通过ezdxf处理dxf格式文件。进行图形复制、移动、删除的方法。pyautocad方式。pyautocad方式。

weixin_43894929的博客 2211

各大厂薪资对比爬虫:Python采集OfferShow爆料数据

print(f"⚠️ API返回错误码: {data.get('code')}, msg: {data.get('msg')}")ax.set_title('各大厂薪资对比 (基于OfferShow爆料数据)', fontsize=16, fontweight='bold')stats.columns = ['人数', '平均年薪', '年薪中位数', '年薪标准差', '平均月薪', '平均月数']print(analyzer.get_position_stats('字节跳动').head(10))

2201_76125261的博客 611

c++书籍推荐(二)

《C++编程思想(两卷合订本)(第6届Jolt生产效率大奖获奖图书)(第1卷标准C++导引&第2卷实用编程技术)》 基本信息 原书名:Thinking in C++ Volume One:Introduction t...

163

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Jetson Orin Nano 8GB 离线大模型部署全记录:Ollama、Open WebUI、llama.cpp、vLLM、Whisper 与 Piper TTS

我按照 Seeed Studio 的“第五章:离线大模型开发”进行学习,在 Jetson Orin Nano 8GB 上依次实践了 Ollama、Open WebUI、llama.cpp、vLLM、jetson-examples、Whisper 和文本转语音。实际过程中遇到了 CPU 版 PyTorch、CUDA 版本错配、NumPy 2.x ABI、缺少。

weixin_57179621的博客 641

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

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

删除文件中重复的行

删除文件中重复的行                  实际上是一个很简单的操作,在这里写出来是因为最近在看Thinking in C++ Volume 2中关于iostream的章节,当作练习吧,所以写出来。J             先定义常量 

星光灿烂 2078

IEM模型,地表粗糙度模拟

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

C++编程思想

C++编程思想 基本信息 原书名:Thinking in C++ Volume One:Introduction to Standard C++, &Volume 2: Practical Programming (2nd Edition) 作者: (美)Bruce Eckel Chuck Allison 译者: 刘宗田 袁兆山 潘秋菱 刁成嘉 丛书名: 计...

weixin_30673611的博客 969

OpenClaw本地AI网关配置实战:Grsai+Gemini 3.1 Pro高效接入指南

OpenClaw本质上是一个轻量级API网关,而非本地大模型运行器,其核心功能是协议转换与服务适配。它依赖Node.js运行时构建HTTP客户端,将终端请求标准化转发至第三方AI服务(如Grsai),再解析响应返回结果。这种架构带来极低硬件开销,但也高度敏感于网络层、传输层和配置层的微小偏差——例如DNS污染导致API连通失败、keep-alive超时引发socket异常、User-Agent被风控拦截等。在Gemini 3.1 Pro等高性能模型成本持续下探的背景下,OpenClaw的价值正从‘能否运行’

chunchan1381的博客 449

Android12 U盘挂载流程学习(一)

这是开机流程的一个重要步骤,标志着user正式启动,而系统启动的第一个用户的id就是0,会走到这里。// /data/media/0/Android/data挂载到/mnt/user/0/emulated/0/Android/data。// /data/media/0/Android/obb挂载到/mnt/user/0/emulated/0/Android/obb。// 挂载/dev/fuse到/mnt/user/0/usb0,访问/mnt/user/0/usb0就会指向/dev/fuse。

c025200的博客 1660

计算机经典书籍之程序设计语言

【Java】 Java编程规范(第三版)---Java四大名著----JamesGosling(Java之父) 【原 书 名】The Java Language Specification (3rd Edition) 【原出版社】Addison-Wesley 【作  者】(美)James Gosling,Bill Joy,Guy St...

weixin_34226182的博客 184

Gemma 4本地多模态智能体部署与工具调用实战

多模态大模型正从‘能看图’迈向‘可执行’的工程化拐点。其核心在于统一语义空间下的跨模态对齐与原生工具调用能力,而非简单拼接视觉编码器。Gemma 4通过共享RoPE位置编码与轻量ViT-L/14视觉编码器,在单卡RTX 4090上实现低延迟、高精度的文本-图像联合推理,并原生支持OpenAPI Schema驱动的function calling。这种架构收敛性使其成为私有化部署智能体的理想底座,适用于工业文档解析、会议纪要生成、视频异常识别等需数据不出域、逻辑可编程的真实业务场景。

alexhill2009的博客 517

51c大模型~合集110

为了解决这一问题,在稠密化过程中,我们对容易引起退化和梯度集中的具有极端延展率的高斯面片进行了筛选,并对其增殖过程进行了限制,从而在不牺牲性能的情况下有效稳定了训练过程,保障了优化过程的顺利进行。大规模场景的重建往往还意味着显著的训练开销,要重建 1.97 平方千米的区域会产生接近两千万的高斯点,这意味着 4.6G 的存储以及 31.5G 的显存开销,以及超过三小时的训练时长。站在 AI 研究者的角度,得到了《苦涩的教训》,意味着在总结教训的过程中明确了什么是「更好」的。第二类则瞄准了相对复杂的问题。

whaosoft~aiotの开发板商城 2610
上一篇: 《thinking in c++》Volume 1知识点总结(一)
下一篇: 【转】Qt经典出错信息之undefined reference to `vtable for classname'
cly116
博客等级 码龄12年 291粉丝 33原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值