function [H, array] = display_network(A, Opt_normalize, Opt_graycolor, cols, Opt_ Colmajor) % This function visualizes filters in matrix A. Each column of a is a% filter. We'll reshape each column into a square image and visualizes% on each cell of the visualization panel.% All other parameters is optional, usually you does not need to worry% about it.% Opt_normalize:whether We need to normalize , the filter so, all of% them can have similar contrast. Default value is true.% Opt_graycolor:whether We use gray as the heat map. Default is true.% cols:how Many columns is there in the display. Default value is the% SquareRoot of the number of columns in A.% opt_colmajor:you can switch convention to row major for A. in that% case, per row of a is a filter. Default value is false.Warning off allif~exist (' Opt_normalize ',' var ') ||IsEmpty(opt_normalize) opt_normalize= true;Endif~exist (' Opt_graycolor ',' var ') ||IsEmpty(Opt_graycolor) opt_graycolor= true;Endif~exist (' Opt_colmajor ',' var ') ||IsEmpty(opt_colmajor) Opt_colmajor = false;EndDisplay (opt_normalize)% RescaleA = A-mean (A (:));ifOpt_graycolor, ColorMap (gray);End% compute rows, cols[L, M]=size(A); sz=sqrt(L); buf=1;if~exist (' cols ',' var ')if Floor(sqrt(M)) ^2~= M n=Ceil(sqrt(M)); while MoD(M, N) ~=0&& n<1.2*sqrt(M), n=n+1;Endm=Ceil(m/n);Elsen=sqrt(M); M=n;EndElsen = cols; m =Ceil(m/n);Endarray=-ones(buf+m* (SZ+BUF), buf+n* (SZ+BUF));if~opt_graycolor array =0.1. * Array;Endif~opt_colmajor k=1; for I=1: M for J=1: NifK>m,Continue;EndClim=max (ABS(A (:, k)));ifOpt_normalize Array (buf+ (I-1) * (SZ+BUF) + (1: SZ), buf+ (J-1) * (SZ+BUF) + (1: SZ)) =Reshape(A (:, K), Sz,sz)/clim;ElseArray (buf+ (I-1) * (SZ+BUF) + (1: SZ), buf+ (J-1) * (SZ+BUF) + (1: SZ)) =Reshape(A (:, K), Sz,sz)/max (ABS(A (:)));Endk=k+1;End EndElsek=1; for J=1: N for I=1: MifK>m,Continue;EndClim=max (ABS(A (:, k)));ifOpt_normalize Array (buf+ (I-1) * (SZ+BUF) + (1: SZ), buf+ (J-1) * (SZ+BUF) + (1: SZ)) =Reshape(A (:, K), Sz,sz)/clim;ElseArray (buf+ (I-1) * (SZ+BUF) + (1: SZ), buf+ (J-1) * (SZ+BUF) + (1: SZ)) =Reshape(A (:, K), Sz,sz);Endk=k+1;End EndEndifOpt_graycolor H=imagesc (Array,' Erasemode ',' None ',[-1 1]);ElseH=imagesc (Array,' Erasemode ',' None ',[-1 1]);EndAxis Image offdrawnow;warning on all
Utilities (MATLAB)--visualizes Filters (visual filter)