简单的单链表(2)

COMSOL中的动网格 首先我们先了解几个概念 (1)网格重划分(remesh):就是在某些特定的区域进行网格的重新划分,在Maxwell软件中的直线运动区域,当运动物体运动后,这个区域进行重新划分。 (2)morph:网格不重新划分,小范围的进行网格变形,针对运动物体运动位移较小,对变形区域不进行重划分,能够提高效率。 (3)网格滑移(sliding):针对圆形运动区域,运动与非运动区域进行网格滑移,当然边界上两侧网格不共节点,该方法不需要网格重新划分,大部分软件针对圆形运动区域采用该方法,比如maxwell的band,b 阅读详情
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h> 
typedef struct ElementData
{
	int index; 
} Item ; 

typedef struct node 
{
	Item item;
	struct node * nextNode;
} Node;

typedef Node * linkList ;

Node * CreateInsertNode(Item *item) ;


/*链表初始化   */ 
bool initList(linkList *plist)
{
	*plist = (linkList)malloc(sizeof(Node)); 
	if(*plist == NULL)
	{
		return false;
	}
	(*plist)->nextNode = NULL;
	return true;	
}

/*返回链表长度  */
int getListLength(linkList *plist)
{
	int length = 0;
	Node * node = (*plist)->nextNode;
	while(node != NULL)
	{
		length ++;
		node = node->nextNode;	
	}
	return length;
} 

/*返回在链表L中第一个与Item相同的元素的位序, 没有返回为0	*/
//两个结构体不能用 == 直接进行比较 
int locateElem(linkList  L, int item)
{
	int index = 0;
	while(L)
	{
		index ++; 
		if(L->nextNode->item.index == item)
		{
			return index; 
		}
		L = L->nextNode; 
	}	
	return index;
} 

/*返回在链表L的index-1个位置的元素	*/
//ndex-1个位置避免在index个位置插入的时候出错 
Node * getNode(linkList *L, int index)
{
	linkList p = (*L);
	
	int j = 1;
	while(p != NULL && j < index)
	{
		p = p->nextNode;
		j++; 
	}
		
	if(p == NULL || j > index)
	{
		fprintf(stderr, "要找的元素位置超出链表的长度.\n");
		exit(EXIT_FAILURE);
	}	

	return p;	
} 

/*在链表L的index个位置插入item	*/
void listInsert(linkList *L, int index, Item *item)
{	
	//得到index-1的元素 
	linkList currentNode;
	currentNode = getNode(L, index);
	
	//创建要插入的元素 
	linkList insertNode = CreateInsertNode(item) ;
	
	//插入到链表中 
	insertNode->nextNode = currentNode->nextNode;
	currentNode->nextNode = insertNode;		
}

/*把位于链表L的index个位置的元素删掉, 并用item返回其值		*/
void listDelect(linkList *L, int index, Item *item)
{
	//得到index-1的元素 
	linkList currentNode = getNode(L, index);
	
	//删掉元素 
	linkList delectNode = currentNode->nextNode;
	currentNode->nextNode = delectNode->nextNode;
	*item = delectNode->item;
	free(delectNode);
} 

/*头插入	*/
void CreateListHead(linkList *L, Item *item)
{	
	//创建要插入的元素并初始化 
	Node *insertNode = CreateInsertNode(item) ;
	
	//插入 
	linkList head = *L;
	insertNode->nextNode = head->nextNode;
	head->nextNode = insertNode; 		
}


/*尾插入	*/
void CreateListTail(linkList *L, Item *item)
{
	//创建初始化要插入的元素 
	linkList insertNode = CreateInsertNode(item) ;
	
	//找到最后一个元素 
	linkList list = (*L)->nextNode;
	while(list->nextNode != NULL)
	{ 
		list = list->nextNode; 
	} 
	
	//插入 
	list->nextNode = insertNode;
} 


/*删除	*/
void ClearList(linkList *L)
{
	linkList list = (*L)->nextNode ;
	linkList p ;
	while( list != NULL )
	{	
		p = list->nextNode;
		free(list);
		list = p;
	}
	(*L)->nextNode = NULL;
} 

/*输出链表	*/
void listTraverse(linkList *L)
{
	linkList p = (*L)->nextNode;
	while(p)
	{
		printf("%d ,",p->item.index);
		p = p->nextNode;
	}
}

/*创建要插入的元素	返回创建的node指针	*/
Node * CreateInsertNode(Item *item)
{
	Node * insertNode = (linkList)malloc(sizeof(Node));
	if(insertNode == NULL)
	{
		fprintf(stderr,"尾插入错误");
		exit(EXIT_FAILURE);
	} 
	insertNode->item = *item ;
	insertNode->nextNode = NULL;
	return insertNode;
} 

/*单链表翻转/逆序	*/
//current始终保持在第一位,pnext与prev遍历并完成交换。
void ListReverse(linkList *L)
{
	linkList current; //当前节点 
	linkList next;	//下一节点 
	linkList prev;	//上一节点 
	
	current = (*L)->nextNode;
	next = current->nextNode;
	current->nextNode = NULL;
	
	while(next){
		prev = next->nextNode;
		next->nextNode = current;
		current = next;
		next = prev;
	}
	(*L)->nextNode = current;
} 

/*单链表翻转/逆序	*/
//current始终是原链表的第一个数,然后把pnext不断移动到首位。
void ListReverse1(linkList *L)
{
	linkList current; //当前节点 
	linkList next;	//下一节点 
	
	current = (*L)->nextNode;
	
	while(current->nextNode != NULL){
		next = current->nextNode;
		current->nextNode = next->nextNode;
		next->nextNode = (*L)->nextNode;
		(*L)->nextNode = next; 
	}
} 

/*单链表翻转/逆序	*/
//重新建立一个单链表newList,每次将L中的第一个结点放到newList后面
linkList  ListReverse2(linkList *L)
{
	linkList newlist = CreateInsertNode( &((*L)->item) ); 
	if( (*L)->nextNode == NULL)
	{
		return NULL;
	}
	linkList firstNode; 
	while( (*L)->nextNode )
	{
		firstNode = newlist->nextNode;
		newlist->nextNode = (*L)->nextNode;
		(*L)->nextNode = (*L)->nextNode->nextNode;
		newlist->nextNode->nextNode = firstNode;			
	}
	free(*L);
	return newlist;	
}

// 获取单链表倒数第N个结点值
//建立两个指针,第一个先走n步,然后第2个指针也开始走,
//两个指针步伐(前进速度)一致。当第一个结点走到链表末尾时,
//第二个节点的位置就是我们需要的倒数第n个节点的值。 
void GetNthNodeFromBack(linkList *L, int n, Item *item)
{
	linkList list = (*L)->nextNode;
	linkList last = (*L)->nextNode;
	int index = 1;
	
	while(list->nextNode != NULL && index < n)
	{
		index++;
		list = list->nextNode;
	}
	
	if(list->nextNode == NULL || index > n)
	{
		fprintf(stderr, "要找的元素位置超出链表的长度.\n");
		exit(EXIT_FAILURE);
	}
	
	while(list->nextNode != NULL)
	{
		list = list->nextNode;
		last = last->nextNode;	
	}
	*item = last->item;
}

//找到链表的中间节点 
void GetMidNode(linkList *L, Item *e) 
{
	linkList first = *L;
	linkList second = *L; 
	//first移动的速度是second的2倍 
	while(first->nextNode){
		if(first->nextNode->nextNode){
			first = first->nextNode->nextNode;
			second = second->nextNode;
		}else{
			first = first->nextNode;
		}	
	}
	
	*e = second->item;
}

//删除重复的节点
void RemoveDupNode(linkList *L)
{
	linkList first = *L; //用于遍历链表 
	linkList second ;
	linkList delNode ;
	
	while(first->nextNode){		
		second = first->nextNode;  //从first后面开始遍历 
		while(second->nextNode){
			//判断节点是否相等			
			if(second->nextNode->item.index == first->nextNode->item.index){
				//删除节点 
				delNode = second->nextNode;
				second->nextNode = delNode->nextNode;				
				free(delNode);
			}else{
				second = second->nextNode;
			}
		}		
		first = first->nextNode;
	}
} 

//在单链表第n个位置建环
//找到环入口点first,把最后的指针curr指向first 
void BulidListLoop(linkList *L, int num)
{
	linkList first = *L;
	linkList curr ;
	
	if(!first || num < 0){
		fprintf(stderr,"建环失败.");
		exit(EXIT_FAILURE); 
	}
	
	for(int i = 0; i < num; i++){
		if(!first){
			fprintf(stderr,"建环失败,超出链表长度.");
			exit(EXIT_FAILURE); 
		}
		first = first->nextNode;
	}
	
	curr = first;
	
	while(curr->nextNode){
		curr = curr->nextNode;
	}

	curr->nextNode = first;	
}  

//判断链表是否有环
//设两个工作指针,一个快一个慢,如果有环的话,它们会必然在某点相遇。
int hasLoop(linkList *L)
{
	linkList first = *L;
	linkList second = *L;
	
	while(first && second && second->nextNode){
		first = first->nextNode;
		if(second->nextNode){
			second = second->nextNode->nextNode;	
		}
		if(first == second){
			return 1;	
		}
	}
	
	return 0;
} 

//判断链表是否有环
//设两个工作指针p、q,p总是向前走,但q每次都从头开始走,
//对于每个节点,看p走的步数是否和q一样
int hasLoop1(linkList *L)
{
	linkList first = *L;
	int setp = 0;
	
	while(first){
		setp ++;		
		linkList second = *L;
		int index = 0;		
		while(second){
			index ++;
			if(first == second){
				if(setp == index){ //步数相等说明没环 
					break;
				}else{
					return 1; 	
				}	
			}
			second = second->nextNode;
		}
		first = first->nextNode;
	}
	
	return 0;		
}

/*测试	*/
int main(void)
{
	linkList L;
	
	if(!initList(&L))
	{
		fprintf(stderr,"初始化错误");
		exit(EXIT_FAILURE);	
	}
	Item item1 = {
		item1.index = 5 
	};
	
	Item item2 = {
		item2.index = 6
	};
	
	Item item3 = {
		item3.index = 7
	};
	
	Item item4 = {
		item4.index = 6
	};
	
	Item item5 = {
		item5.index = 9
	};
	
	Item item6 = {
		item6.index = 4
	};
	
	listInsert(&L,1,&item1); 
	listInsert(&L,2,&item2); 
	listInsert(&L,3,&item3); 
	listInsert(&L,4,&item4);  
	CreateListHead(&L, &item5);
	CreateListTail(&L, &item6);	
	
	int length = getListLength(&L);	
//	printf("length=%d\n",length); 
	listTraverse(&L);  //显示 
/*	
	printf("\n");
	linkList n = ListReverse2(&L); //翻转 
	listTraverse(&n);  //显示 
	
	
	Item item5;
	listDelect(&L,1,&item5);
	int length1 = getListLength(&L);	
	printf("length1=%d\n",length1); 
	listTraverse(&L);	
*/
	Node * getnode ;
 	getnode = getNode(&L, 2); 
	printf("\n%d\n", getnode->nextNode->item.index);

	/*
	Item  i;
	GetNthNodeFromBack(&L, 2,&i) ; 测试单链表倒数第N个结点值
	printf("\n");
	printf("%i",i.index);
	*/
	
	/*
	Item i;
	GetMidNode(&L, &i); 测试中间节点 
	printf("\n");
	 printf("%i",i.index);
	 */
	 
	 /*
	 RemoveDupNode(&L); 测试删除重复节点 
	 printf("\n");
	  listTraverse(&L);
	  */
	  
	  /*
	  BulidListLoop(&L,2);
	  int i = hasLoop1(&L); 测试建环 检测是否有环 
      printf("\n%d",i)	;
	  */	
//	int index = locateElem(L,5);
//	printf("%d",index);	
	
	ClearList(&L);	
	return 0;
}

ubuntu下安装多版本cuda及版本切换教程 首先,从官网下载所需版本的cuda安装包,下载链接。选择对应版本后,会跳转到该版本的配置信息页面。比如我是ubuntu20.04系统,已经安装好了cuda10.0,但是现在还需要用到cuda9.0。那么,在选定版本后,配置信息如下图所示(由于Version选项中没有20.04,因此我们随便选一个即可,这里选的16.04,这一选项不会影响后面的安装),Installer Type选择为runfile(因为使用deb文件进行安装的话,可能会将已经安装的较新的显卡驱动给替换掉),选择好之后点击Base Insta 阅读详情

相关推荐

【学一点英飞凌】AutoSar-MCAL-Gtm-TOM模块

本文基于英飞凌TC3X7芯片手册,GTM的TOM模块是产生并输出PWM的地方,想要彻底了解PWM,就必须知道它是怎么产生和如何被输出的。TOM通道还没有介绍的,详见下一篇;

qq_44688936的博客 6030

单链表

单链表 #include #include #include #include #define random(x) rand() % (x) //rand()的范围是在0与 ((unsigned int)-1 >> 1)...然后求余 //然后求余之后那么范围在 X之内了 typedef int Status; typedef int ElemType; //下面

xubuju的专栏 585

PID调参避坑指南:为什么你的电机总是震荡?从比例带积分到微分实战解析

本文针对电机控制中常见的震荡问题,提供了一份PID调参实战指南。文章深入解析了比例(P)、积分(I)、微分(D)三个参数对系统稳定性的影响,揭示了比例增益过大是导致震荡的关键原因之一,并给出了从纯比例调试到引入积分、微分的系统化调参流程与避坑要点,帮助工程师快速实现电机平稳、精准的控制。

weixin_28223453的博客 456

算法练习——在有序序列(r1,r2,...,rn)中,存在序号i(1<=i<=n),使得ri=i。请设计一个分治算法找到这个元素。 要求算法在最坏情况下的时间性能为O(logn))

算法练习题目答案注意 题目 答案 #include<iostream> using namespace std; int find(int a[],int left,int right) { if(left==right) { if(a[left]==left) return left; else return -1; } int mid=(left+right)/2; if(a[mid]==mid) return mid; else { if(a[mid]<

ljhsq的博客 3000

(Cascade extended state observer)级联ADRC的simulink仿真和程序---送给中国研究学者的精华版

(Cascade extended state observer)级联ADRC的simulink仿真和程序---送给中国研究学者的精华版

weixin_44312889的博客 3778

【论文学习】《Fully-Convolutional Siamese Networks for Object Tracking》2016年SiamFC 全卷积孪生网络用于目标跟踪

在这项工作中,我们脱离了跟踪中采用的传统在线学习方法,并展示了一种专注于在离线阶段学习强嵌入的替代方法。与在分类设置中的使用不同,我们证明,对于跟踪应用,孪生全卷积深度网络能够更有效地使用可用数据。这不仅反映在测试时,通过执行有效的空间搜索,也反映在训练时,其中每个子窗口都有效地代表一个有用的样本,而几乎没有额外的成本。实验表明,深度嵌入为在线跟踪器提供了自然丰富的特征来源,并使简单的测试时策略表现良好。我们相信这种方法是对更复杂的在线跟踪方法的补充,并期望未来的工作能够更彻底地探索这种关系。

SkyLeopard的博客 2418

计算机软件技术基础考前整理

第一章 1.什么是信息,信息和数据的区别和联系在何处? 信息是经过加工、具有一定含义的且对决策有价值的数据。 信息与数据的关系 信息是有一定含义的数据 信息是经过加工(处理)后的数据 信息是对决策有价值的数据 2.信息有哪些基本属性 事实性 等级性 可压缩性 可扩散性 可传输性 共享性 增值性与再生性 转换性 3.什么是计算机硬件,什么是计算机软件 计算机硬件(HardWare) 是...

qq_41262681的博客 5847

FLUENT Meshing Watertight Geometry工作流入门 - 9 生成体网格

总结一下我们学到的东西。讨论体积网格的重要性,并了解生成体积网格的不同方法。还了解体积网格质量的重要性,并学习如何改进它。

B_etter_Man的博客 1万+

【数据结构笔记】数据结构基础—排序

1.排序的原理 稳定排序和非稳定排序 设文件f=(R1……Ri……Rj……Rn)中记录Ri、Rj(i≠j,i、j=1……n)的key相等,即Ki=Kj。 若在排序前Ri领先于Rj,排序后Ri仍领先于Rj,则称这种排序是稳定的,其含义是它没有破坏原本已有序的次序。 内排序和外排序 若待排文件f在计算机的内存储器中,且排序过程也在内存中进行,称这种排序为内排序。 若排序中的文件存入外存储器,排序过程借助于内外存数据交换(或归并)来完成,...

段昊东的博客 270

Oracle EBS Tax 四国实现详解:印度、巴西、美国、阿根廷

印度:务必启用India Localization模块,不要尝试用标准EBTax模拟GST逻辑 巴西:必须配置NF-e接口,建议聘请本地税务顾问设置CFOP和NCM代码映射 美国:跨州业务强烈建议购买Vertex或Avalara服务,自建税率表维护成本极高 阿根廷:注意1:1:1架构限制,提前规划Legal Entity和OU结构

金牌架构师 260

核心面试聚焦:业务问题+系统问题+设计题---字节、阿里、美团等整理统计

业务系统及其他相关面试问题整理:线上相关问题排查+高并发系统的限流+高并发秒杀系统设计+负载均衡+一个网站有 20 亿 url 存在一个黑名单中,这个黑名单要怎么存?若此时随便输入一个 url,你如何快速判断该 url 是否在这个黑名单中?并且需在给定内存空间(比如:500M)内快速判断出?

曾经“等你生日那天”都遥远得像未来,如今却可欢愉的挥手说“下个十年见” 172万+

冲突解决策略是定义一个序列F(i)=ri,其中r0=0且r1,r2……rN是前N个整数的随机排列(每个整数恰好出现一次)

数据结构与算法分析——c语言描述 练习5.5e  答案 hashQuad.c #include"hashQuad.h" #include"fatal.h" #include #include #define MinTableSize 5 enum KindOfEntry { Legitimate, Empty, Deleted }; struct HashEntry {

wwj_bupt 1398

IEC 104电力规约详细解读(五) - 遥控

主站下发遥控选择命令,子站进行遥控选择返校,若成功则回答遥控选择成功报文,若失败则回答失败报文。主站下发取消遥控命令或者遥控执行命令行。子站皆以报文的镜像确认。遥控命令用来实现对一个可操作设备状态的改变。在配电自动化中,包括单点命令和双点命令。通常,单点命令用于控制单点信息对象;双点命令用于控制双点信息对象。

张二狗的博客 7350

【单链表】21 单链表ADT模板简单应用算法设计:2个单链表的交叉归并

问题描述 : 目的:使用C++模板设计单链表的抽象数据类型(ADT)。并在此基础上,使用单链表ADT的基本操作,设计并实现单链表的简单算法设计。 内容: (1)请使用模板设计单链表的抽象数据类型。(由于该环境目前仅支持单文件的编译,故将所有内容都集中在一个源文件内。在实际的设计中,推荐将抽象类及对应的派生类分别放在单独的头文件中。参考网盘中的ADT原型文件。) (2)ADT的简单应用:使用该ADT设计并实现单链表应用场合的一些简单算法设计。 应用3:假设线性表A=(a1,a2,...,..

windyuan~ 780

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

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

单链表ADT模板简单应用算法设计:2个单链表的交叉归并(手画图片讲解)

问题描述 目的:使用C++模板设计单链表的抽象数据类型(ADT)。并在此基础上,使用单链表ADT的基本操作,设计并实现单链表的简单算法设计。 内容:(1)请使用模板设计单链表的抽象数据类型。(由于该环境目前仅支持单文件的编译,故将所有内容都集中在一个源文件内。在实际的设计中,推荐将抽象类及对应的派生类分别放在单独的头文件中。参考网盘中的ADT原型文件。) (2)ADT的简单应用:使用该ADT设计并实现单链表应用场合的一些简单算法设计。 应用3:假设线性表A=(a1,a2,…,am),线性表B=(b1,b2,

Blackoutdragon的博客 1360

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

程序2:用单链表实现简单的栈

<br />这是对10.22题的实现<br /> <br />此栈的通用性还是不强,只能应对内置类型的数据,增强通用性即数据类型可以为结构体,对某些函数必须增加一个函数对象参数用来执行赋值操作以及销毁操作。 栈的根通用实现方式是在C++中用模板的方式实现,当然在C++中已经很好的给我们实现了。<br /> <br />//头文件<br />/* 文件名: stack.h 功能: 单链表实现简单的栈 作者: shaofeng5000 时间: 2011/4/3 */ #ifndef _STA

shaofeng5000的专栏 603

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

链表基础2(超简单)--单链表的插入和删除

这篇文章是基于链表基础1(超简单)–创建一个长度为n的单链表所写的,需要看基础的可以跳过去,链表的基础知识这里就不在讲了。 我们首先来看一下链表的删除,话不多说直接上图。 如图,比如我们要删除B这个节点。我们先来看一下删除后的图。一对比你就明白啦! 两个图一对比你就发现,如果我们要删除B节点,我们首先要将B节点的前后两个节点A,C连起来,这样B不就孤立了嘛,我们就可以给他free掉了!是不是灰常简单呀! 我们来看一下具体代码实现。 先看一下这个链表的结构 typedef struct lianbiao

玫瑰花店的博客 3283

数据结构2:简单实现单链表

代码不全只是自己记录,借鉴:https://blog.youkuaiyun.com/javazejian/article/details/52953190;强烈推荐此人博客。。。package com.zejian.structures.LinkedList.MyLinked; /** * 单链表的进化版本 * @param &lt;T&gt; */ public class SingleLinked...

qq_38788128的博客 249

「数据结构与算法 2」| 单链表其实真的很简单。

写在之前 在程序设计里,我们经常需要将同为某个类型的一组数据元素作为一个整体来使用,需要创建这种元素组,用变量来记录它们或者传入函数等等等等,「线性表」就是这样一组元素的抽象,它是某类元素的集合并且记录着元素之间一种顺序关系,是最基本的数据结构之一,在实际程序中运用非常广泛,比如 Python 中的 list 和 tuple 都可以看作是线性表的实现。 基于各种实际操作等方面的综合考虑,我们提出了...

Rocky0429 1819

栈的简单实现(2)-单链表实现

引言 栈(stack)是一种被广泛使用的线性数据结构,它只允许在表的一端进行插入或删除操作,因而栈也可以被称作为操作受限的线性表 。在栈中,允许插入或删除的一端称作栈顶(top)不允许插入和删除的另一端称作栈底(bottom); 示意图如下: 此文借助单链表简单地实现栈及其基本操作。 代码如下: typedef struct stack{ int da...

weixin_30629977的博客 154

C语言简单的数据结构:单链表的有关算法题(2)

接着我们介绍后面的三道题,虽然代码变多了但我们的思路更加通顺了。 题目: 4. 单链表相关经典算法OJ题3:合并两个有序链表 5. 循环链表经典应⽤-环形链表的约瑟夫问题 6. 单链表相关经典算法OJ题5:分割链表

2302_82004664的博客 1238

第四周项目三-单链表的应用(2)

问题描述:已知L1和L2分别指向两个单链表的头结点,且已知其长度分别为m、n,请设计算法将L2连接到L1的后面。实现这个算法,完成测试,并分析这个算法的复杂度。 代码: #include #include #include "linklist.h" void Link(LinkList *&L1, LinkList *&L2) { LinkList *p = L1;

yanghuijuan12138的博客 480

单链表应用(2)

问题描述:2、已知L1和L2分别指向两个单链表的头结点,且已知其长度分 别为m、n,请设计算法将L2连接到L1的后面。实现这个算法,完成测试, 并分析这个算法的复杂度。

西红柿的博客 712

第四周 项目3-单链表的应用(2)

/*        *    Copyright (c)2015,烟台大学计算机与控制工程学院        *    All rights reserved.        *    文件名称:单链表应用(2).cpp        *    作        者:林颖    *    完成日期:2016年9月19日                *    问题描述:已知L1和L2分

linying3121的博客 326

第四周项目3 - 单链表应用(2)

/* * Copyright (c)2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名称:项目3.cpp * 作 者:高金艳 * 完成日期:2016年9月19日 * 版 本 号:v1.0 *问题描述:已知L1和L2分别指向两个单链表的头结点,且已知其长度分别为m、n, 请设计算法将L2连接到L1的后

gaojinyangaojia的博客 603
上一篇: 计算机组成原理(1)
下一篇: 博客搬家了
chapter_lin
博客等级 码龄14年 1粉丝 8原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值