如何画一个漂亮的功能连接矩阵图

AI摘要

本文将介绍如何利用MATLAB程序绘制功能连接矩阵热力图,常见于神经科学领域的顶级期刊。程序简单易用,能生成清晰的脑网络矩阵图。详细步骤包括下载代码和示例数据,组织文件,以及在MATLAB中运行代码生成图片。

下面将介绍一种画功能连接矩阵热力图的程序。该程序使用简单,有了改代码再也不用担心类似下图的矩阵热力图。

以下几幅图都是来自一些神经、精神、心理学的顶级期刊,包括nature medicine,nature communications、brain等。这些图是以矩热力图的形式展示的功能连接或者统计学结果图。我们可以看到属于不同的网络的节点的连接被一些网格线分割开,很容易让别人识别脑网络。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

那么这种图是怎么做出来的呢?本期我们将给大家介绍一个专门用于做这种矩阵热力图的程序,并教大家如何使用改程序做出高清的用于直接投稿用的图片。

以下图片是使用笔者改程序做出来的矩阵热力图,这个图反映的是sub001的功能连接。

在这里插入图片描述

这个功能连接是一个114114的矩阵,表示有114个节点。另外我们有一个叫做netIndex.mat的文件,里面储存的是114个节点的网络标签,即每一个节点属于第几个网络。netIndex.mat是一个1114的向量,比如第1个位置的元素值表示第1个节点属于哪个脑网络。

进入具体操作正题:

  • 第1步,下载代码和例子数据:

代码下载地址(进入github项目后可以下载我的整个项目,也可以只下载该代码,最简单的方式就是直接把代码复制到matlab新建的函数里面):

可视化代码

The codes in this folder are used to visualization.

lc_circleplot is used to plot network in circle format.

lc_netplot is used to plot network in square format.

lc_plot_mean_tvalue is used to plot mean tvalues within or between networks.

数据下载地址(将其中的netIndex.mat和sub001.mat下载下来):

数据下载地址

  • 第2步,整理下载的文件:

将下载的两个.mat文件(netIndex.mat 和sub001.mat)放在一个叫做toy_data的文件夹下。并将下载的代码(lc_netplot.m)放在与toy_data同级的文件下。

  • 第3步,运行代码:

代码setpath到matlab路径后,在matlab命令窗口输入”lc_netplot”后,程序会在窗口打印出两个使用的例子,分别是EXAMPLE1和EXAMPLE 2.复制其中一个例子,到窗口,回车即可运行代码。运行结束后,图片会保存到toy_data文件夹下。

注:转载于公众号——脑之说。

function lc_netplot(varargin)
% LC_NETPLOT
% PURPOSE: plot functional connectivity network using grid format. 
% NOTO: This function will automatically sort network according to net_index.
% Parameters:
% -----------
%   REQUIRED:
%       [--net, -n]: path str | .mat matrix
%           Functional connectivity network that needs to be plotted.
%       [--net_index, -ni]: path str | .mat vector
%           network index, each node has a net_index indicating its network index
%   OPTIONAL:
%      [--if_add_mask, -iam]: int, 0 or 1
%           If add mask to net for filtering.
%      [--mask, -m]: path str | .mat matrix
%           Mask that used to filter the net.
%      [--how_disp, -hd]: str:: 'only_neg', 'only_pos' or 'all'
%           how display the network
%      [--if_binary, -ib]: int, 0 or 1
%           If binary the network.
%      [--which_group, -wg]: int
%           If the network .mat file has multiple 2D matrix, then choose which one to display.
%      [--linewidth, -lw]: float 
%           separation line width
%      [--linecolor, -lc]: color string 
%           separation line color
%      [--is_legend, -il]: int
%          If show legend.
%      [--legends, -lg]: cell
%          legends of each network.
%      [--legend_fontsize, -lgf]: float
%          fontsize of the legends
%   
% EXAMPLE:
% lc_netplot('-n', 'tvalue_medication.mat', '-ni', 'netIndex.mat')
% AUTHOR: Li Chao
% EMAIL: lichao19870617@gmail.com, lichao19870617@163.com
% If you used this code, please cite the code

if nargin == 0
    help lc_netplot
    return;
end

[net, if_add_mask, mask, how_disp, if_binary, which_group, net_index, linewidth, linecolor, is_legend, legends, legend_fontsize] = ...
            parseInputs(varargin{:});

% net
if isa(net, 'char')
    net=importdata(net);
else
    net=net;
end

% show postive and/or negative
if strcmp(how_disp,'only_pos')
    net(net<0)=0;
elseif strcmp(how_disp,'only_neg')
    net(net>0)=0;
elseif strcmp(how_disp,'all')
    disp('show both postive and negative')
else
    disp('Did not specify show positive or negative!')
    return
end

% when matrix is 3D, show which (the 3ith dimension)
if numel(size(net))==3
    %     net=squeeze(net(which_group,:,:));
    net=squeeze(net(:,:,which_group));
end

% transfer the weighted matrix to binary
if if_binary
    net(net<0)=-1;
    net(net>0)=1;
end

% mask
if if_add_mask
    if isa(mask, 'char')
        mask=importdata(mask);
    else
        mask=mask;
    end
    
    % when mask is 3D, show which (the 3ith dimension)
    if numel(size(mask))==3
        mask=squeeze(mask(which_group,:,:));
    end
    
    % extract data in mask
    net=net.*mask;
end

% sort the matrix according to network index
if ischar(net_index)
    net_index=importdata(net_index);
elseif ismatrix(net_index)
end
[index,re_net_index,re_net]=lc_ReorganizeNetForYeo17NetAtlas(net,net_index);

% plot: insert separate line between each network
lc_InsertSepLineToNet(re_net, re_net_index, linewidth, linecolor, is_legend, legends, legend_fontsize);
end


function [net, if_add_mask, mask, how_disp, if_binary, which_group, net_index, linewidth, linecolor, is_legend, legends, legend_fontsize] = ...
            parseInputs(varargin)
% Varargin parser

% Initialize
if_add_mask = 0;
mask = '';
how_disp='all';
if_binary=0;
which_group=1;
linewidth = 0.5;
linecolor = 'k';
is_legend = 0;
legends = '';
legend_fontsize = 10;

if( sum(or(strcmpi(varargin,'--net'),strcmpi(varargin,'-n')))==1)
    net = varargin{find(or(strcmpi(varargin,'--net'),strcmp(varargin,'-n')))+1};
else
    error('Please specify net!');
end

if( sum(or(strcmpi(varargin,'--if_add_mask'),strcmpi(varargin,'-iam')))==1)
    if_add_mask = varargin{find(or(strcmpi(varargin,'--if_add_mask'),strcmp(varargin,'-iam')))+1};
end

if( sum(or(strcmpi(varargin,'--mask'),strcmpi(varargin,'-m')))==1)
    mask = varargin{find(or(strcmpi(varargin,'--mask'),strcmp(varargin,'-m')))+1};
end

if( sum(or(strcmpi(varargin,'--how_disp'),strcmpi(varargin,'-hd')))==1)
    how_disp = varargin{find(or(strcmpi(varargin,'--how_disp'),strcmp(varargin,'-hd')))+1};
end

if( sum(or(strcmpi(varargin,'--if_binary'),strcmpi(varargin,'-ib')))==1)
    if_binary = varargin{find(or(strcmpi(varargin,'--if_binary'),strcmp(varargin,'-ib')))+1};
end

if( sum(or(strcmpi(varargin,'--which_group'),strcmpi(varargin,'-wg')))==1)
    which_group = varargin{find(or(strcmpi(varargin,'--which_group'),strcmp(varargin,'-wg')))+1};
end

if( sum(or(strcmpi(varargin,'--net_index'),strcmpi(varargin,'-ni')))==1)
    net_index = varargin{find(or(strcmpi(varargin,'--net_index'),strcmp(varargin,'-ni')))+1};
end

if( sum(or(strcmpi(varargin,'--linewidth'),strcmpi(varargin,'-lw')))==1)
    linewidth = varargin{find(or(strcmpi(varargin,'--linewidth'),strcmp(varargin,'-lw')))+1};
end

if( sum(or(strcmpi(varargin,'--linecolor'),strcmpi(varargin,'-lc')))==1)
    linecolor = varargin{find(or(strcmpi(varargin,'--linecolor'),strcmp(varargin,'-lc')))+1};
end

if( sum(or(strcmpi(varargin,'--is_legend'),strcmpi(varargin,'-il')))==1)
    is_legend = varargin{find(or(strcmpi(varargin,'--is_legend'),strcmp(varargin,'-il')))+1};
end

if( sum(or(strcmpi(varargin,'--legends'),strcmpi(varargin,'-lg')))==1)
   legends = varargin{find(or(strcmpi(varargin,'--legends'),strcmp(varargin,'-lg')))+1};
end

if( sum(or(strcmpi(varargin,'--legend_fontsize'),strcmpi(varargin,'-lgf')))==1)
   legend_fontsize = varargin{find(or(strcmpi(varargin,'--legend_fontsize'),strcmp(varargin,'-lgf')))+1};
end

end

function lc_InsertSepLineToNet(net, re_net_index, linewidth, linecolor, is_legend, legends, legend_fontsize)
% 此代码的功能:在一个网络矩阵种插入网络分割线,以及bar
% 此分割线将不同的脑网络分开
% 不同颜色的区域,代表一个不同的网络
% input
%   net:一个网络矩阵,N*N,N为节点个数,必须为对称矩阵
%   network_index: network index of each node.
%   location_of_sep:分割线的index,为一个向量,比如[3,9]表示网络分割线分别位于3和9后面
%% input
% if not given location_of_sep, then generate it using network_index;
uni_id = unique(re_net_index);
location_of_sep = [0; cell2mat(arrayfun( @(id) max(find(re_net_index == id)), uni_id, 'UniformOutput',false))];

if size(net,1)~=size(net,2)
    error('Not a symmetric matrix!\n');
end

%%

%% Gen new sep line and new network
n_node = length(net);
% New sep
num_sep = numel(location_of_sep);
location_of_sep_new = location_of_sep;
for i =  2 : num_sep
    location_of_sep_new(i:end) = location_of_sep_new(i:end) + 1;
end
% New network
net_insert_line = zeros(n_node + num_sep, n_node + num_sep);
for i = 1:num_sep-1
    % Rows iteration
    start_point =  location_of_sep_new(i) + 1;
    end_point = location_of_sep_new(i+1) - 1;
    start_point_old =  location_of_sep(i) + 1;
    end_point_old = location_of_sep(i+1);
    % Columns iteration
    for j = 1 : num_sep - 1
        start_point_j =  location_of_sep_new(j) + 1;
        end_point_j = location_of_sep_new(j+1) - 1;
        start_point_old_j =  location_of_sep(j) + 1;
        end_point_old_j = location_of_sep(j+1);
        net_insert_line(start_point : end_point, start_point_j : end_point_j) = ...
                    net(start_point_old : end_point_old, start_point_old_j : end_point_old_j);
    end
end
imagesc(net_insert_line); hold on;
x = repmat(location_of_sep_new', num_sep ,1);
y = repmat(location_of_sep_new,1, num_sep);
x(:,end) = x(:,end) + 1.5;
y(end,:) = y(end, :) + 1.5;
z = zeros(size(x));
mesh(x,y,z,...
    'EdgeColor',linecolor,...
    'FaceAlpha',0,...
    'LineWidth',linewidth);
view(2);
grid off
% lc_line(location_of_sep, n_node, linewidth, linecolor);
hold on;
% bar region
n_node_new = length(net_insert_line);
extend = n_node_new / 10;
xlim([0, n_node_new + extend]);
ylim([0, n_node_new + extend]);
lc_bar_region_of_each_network(location_of_sep_new, n_node_new, extend, is_legend, legends, legend_fontsize);
axis off
end

% function lc_line(location_of_sep, n_node, linewidth, linecolor)
% % nNode: node个数
% n_net = length(location_of_sep);
% for i=1:n_net
%     if (i == 1)  
%         % Y
%         line([location_of_sep(i), location_of_sep(i)],[0, n_node],'color',linecolor,'LineWidth',linewidth);
%         % X
%         line([0, n_node],[location_of_sep(i), location_of_sep(i)],'color',linecolor,'LineWidth',linewidth);
%     elseif (i == n_net)
%         % Y
%         line([location_of_sep(i) + 0.5, location_of_sep(i) + 0.5],[0, n_node],'color',linecolor,'LineWidth',linewidth);
%         % X
%         line([0, n_node],[location_of_sep(i) + 0.5, location_of_sep(i) + 0.5],'color',linecolor,'LineWidth',linewidth);
%         
%     else
%         % Y
%         line([location_of_sep(i) + 0.5, location_of_sep(i) + 0.5],[0, n_node],'color',linecolor,'LineWidth',linewidth);
%         % X
%         line([0, n_node],[location_of_sep(i) + 0.5, location_of_sep(i) + 0.5],'color',linecolor,'LineWidth',linewidth);
%     end
%     
% end
% end

function lc_bar_region_of_each_network(location_of_sep, n_node, extend, is_legend, legends, legend_fontsize)
% To plot bar with sevral regions, each region with a unique color
% representting a network.
n_net = length(location_of_sep);
randseed(1);
color = jet(n_net) / 1.2;
barwidth = abs((n_node + extend / 2) - (n_node+extend));
extend_of_legends = extend + 4 ;
h = zeros(n_net - 1, 1);
for i = 1 : n_net-1
    h(i) = fill([location_of_sep(i), location_of_sep(i+1), location_of_sep(i+1), location_of_sep(i)], [n_node + extend / 2, n_node + extend / 2, n_node+extend n_node + extend], color(i,:));
    fill([ n_node + barwidth, n_node + barwidth, n_node + extend, n_node + extend], [location_of_sep(i), location_of_sep(i+1), location_of_sep(i+1), location_of_sep(i)], color(i,:))
    if is_legend
        % Y axix
        text(n_node + extend_of_legends, (location_of_sep(i+1) - location_of_sep(i)) / 2 +  location_of_sep(i),...
            legends{i}, 'fontsize', legend_fontsize, 'rotation', 0);
         % X axix
        text((location_of_sep(i+1) - location_of_sep(i)) / 2 +  location_of_sep(i), n_node + extend_of_legends,...
            legends{i}, 'fontsize', legend_fontsize, 'rotation', -90);
    end
end
end
脑疾病数据集的预处理-功能连接矩阵(FC) REST-meta-MDD,ABIDE数据集的预处理准备,绘制功能连接矩阵(FC)及使用nilearn绘制脑区图谱 阅读详情

相关推荐

matlab中列矩阵怎么表示_手把手教你画漂亮的功能连接矩阵图(附代码)

《本文同步发布于“脑之说”微信公众号,欢迎搜索关注~~》科研图片的重要性是非常重要的,审稿人看到一个低质量的或者欠美观的图片,很可能影响文章的审稿。本期我将介绍一种画功能连接矩阵热力图的程序。该程序使用简单,有了改代码再也不用担心类似下图的矩阵热力图。 以下几幅图都是来自一些神经、精神、心理学的顶级期刊,包括nature medicine,nature communications、br...

weixin_39627390的博客 2290

科研必备|Origin实战:快速绘制高颜值相关性系数矩阵图

本文详细介绍了使用Origin软件快速绘制高颜值相关性系数矩阵图的实战教程。通过Correlation Plot插件,科研人员无需编程即可高效完成数据可视化,生成符合期刊出版要求的专业图表。文章涵盖了从数据准备、插件安装、参数设置到深度美化的全流程,并提供了色彩映射、文本处理及常见问题解决方案,助力提升科研图表质量与工作效率。

weixin_29243279的博客 588

用Visio绘制功能结构图,告别熬夜手工排图的实用指南

在系统设计与技术文档撰写中,清晰的结构图是表达模块层次与逻辑关系的关键工具。许多人在绘制功能结构图时,常因层级规划混乱、连接线难对齐、导出图片模糊等问题反复返工。其实,通过区分功能模块与功能点、利用Visio的图层与容器功能、掌握自动布局和批量对齐技巧,就能显著提升绘图效率。从论文写作到项目汇报,规范的结构图不仅能直观呈现系统全貌,还能增强方案的专业性。本文围绕功能清单梳理、Visio绘图环境搭建、形状与连接线管理、高清导出等核心环节,总结了一套从层级规划到版面输出的完整方法,帮助读者快速绘制出清晰、规范的

weixin_30047059的博客 246

如何提取fMRI的时间序列,以及构建功能连接矩阵(functional connectivity)

图论分析中从fMRI中提取复杂网络的主要步骤。步骤一: 对采集的功能磁共振成像数据进行许多预处理步骤,包括切片之间的时间校正、重新对准、图像配准、基于分割的归一化和空间平滑。需要注意的是预处理步骤的选择和顺序可能会影响最终图指标测量的范围。预处理步骤可以参考:DPABI详细使用教材——数据准备、预处理流程、数据分析流程步骤二: 为了探索大规模的大脑网络,应用了适当的分割方案,例如解剖学自动标记图谱,将整个大脑划分为几个皮质和皮质下的解剖单元。......

从事脑科学核磁共振方法学研究,在Nature communications等权威期刊发表研究论文,熟练掌握磁共振处理方法和统计学方法,欢迎大家和我交流。 1万+

Seaborn 数据可视化基础

Seaborn 数据可视化基础

Deng872347348的博客 300

嵌入式:简单的service框架

在嵌入式中,我们获取一个资源、设置一个变量、更新数据的话最直接的方式就是直接调用一个函数。这样的写法也可以满足基本的功能,前提是这个系统是只要一个任务,只有一个while(1)如图1.1。图1.1当有两个或者两个以上的任务的时候,同时调用一个函数(设置一个状态值、操作同一个资源、操作指针等行为)的流程如图1.2。图1.2当两个任务同时操作一个资源的时候,就会有重入的问题,会导致想不到的异常问题(数据不对、指针异常等)。

stupid的博客 984

从零到一:RK3588平台上的星闪模块驱动移植全解析

本文详细解析了在RK3588平台上移植UB37星闪模块驱动的完整流程,涵盖内核配置、设备树适配、驱动编译、功能测试等关键步骤。通过实践指导,帮助开发者掌握星闪技术在嵌入式系统中的集成与应用,提升无线通信模块的开发效率。

qsc90123456的博客 335

ICM42670-P嵌入式开发实战:从寄存器配置到姿态解算全解析

本文全面解析ICM42670-P高性能6轴MEMS运动传感器的嵌入式开发实战,涵盖寄存器配置、数据采集滤波、低功耗优化及姿态解算算法。通过详细代码示例和应用案例,帮助开发者快速掌握从硬件对接到姿态跟踪系统的完整开发流程,适用于可穿戴设备和智能家居等低功耗应用场景。

gold的博客 1064

基于 YOLO + SAM 的自动图像标注实战

摘要: 本文提出一种基于YOLO检测和SAM分割的自动化数据标注流水线方案,通过YOLO定位目标并生成检测框,再以检测框为提示驱动SAM完成精细分割,最终输出YOLO格式的标注文件。该方案将人工标注升级为半自动流程,显著提升标注效率,尤其适用于多类别、大规模图像的实例级标注需求。代码模块化设计支持模型灵活替换,并集成异常处理与进度可视化功能。虽依赖YOLO检测质量且对小目标存在局限,但作为工程落地方案,可有效降低私有数据集构建成本,适用于工业检测、遥感等场景的冷启动标注。

qq_64366203的博客 1144

光电容积脉搏波PPG信号分析笔记

脉搏波信号PPG分析笔记

teresa_zp的专栏 6474

Elsevier期刊LaTeX双栏模板(cas-dc)实战:从Overleaf配置到投稿全流程

本文详细介绍了Elsevier期刊LaTeX双栏模板(cas-dc)在Overleaf平台上的配置与使用全流程,包括模板结构解析、标题与作者信息规范、摘要与关键词特殊格式、正文写作技巧、参考文献管理以及投稿前检查清单。特别针对Elsevier期刊投稿需求,提供了从模板安装到最终投稿的实用指南,帮助研究者高效完成论文排版工作。

weixin_28455801的博客 1322

避坑指南:STM32CubeMX安装后,你的第一个工程为什么中文全是乱码?

本文详细解析了STM32CubeMX安装后中文乱码问题的根源及解决方案。从诊断乱码现象到分析编码冲突背景,提供了新项目UTF-8化、旧项目GBK兼容及版本降级等多种实用方案,帮助开发者彻底解决这一常见问题。

weixin_30699955的博客 474

OpenCV计算机视觉实战(12)——图像金字塔与特征缩放

图像金字塔技术通过对原始图像按不同分辨率进行多层次表示,不仅能提升计算效率,还能为图像融合、检测与识别提供多尺度特征。高斯金字塔 (Gaussian Pyramid) 用于构建多级低通图像,拉普拉斯金字塔 (Laplacian Pyramid) 则提取各层之间的细节信息。本节将深入介绍如何使用 OpenCV 构建高斯与拉普拉斯金字塔,并以经典的图像融合案例,展示图像金字塔在特征缩放与融合中的强大应用。

qq_30167691的博客 1403

IEM模型,地表粗糙度模拟

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

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

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

上一篇: 图信号非参数假设检验:一种生成代替图信号的谱方法——A Spectral Method for Generating Surrogate Graph Signals
下一篇: Matlab偏最小二乘回归命令plsregress详解
sta@ma@brain
sta@ma@brain 优质创作者: 人工智能技术领域 优质创作者: 人工智能技术领域
博客等级 码龄10年 1万+粉丝 165原创
评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值