%%%****************** test_rnn_gen.m *********************%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%% Info %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% File Name : test_rnn_gen.m %%% %%% Type : m function file %%% %%% Parent : use_rnn_gen.m %%% %%% External Calls : vardef.m %%% %%% Internal Calls : Prepare_Tst_Patterns %%% %%% calculate_rate %%% %%% calculate_ffm_output %%% %%% save_response_txt %%% %%% save_response_m %%% %%% Date : September, 1, 1999 %%% %%% Author : Hossam Eldin Mostafa Abdelbaki %%% %%% Address : University of Centeral Florida, %%% %%% : School of Computer Science %%% %%% Email : ahossam@cs.ucf.edu %%% %%% Home Page : http://www.cs.ucf.edu/~ahossam/ %%% %%% Help : read the manual file (rnnsimv2.pdf) %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function q_cal_1 = test_rnn_gen(kind,TEST_INPUT_1,r_1,Weights_File_Name_1,Log_File_Name_1, ... Temp_Log_File_Name_1) vardef; if(nargin > 2) r = r_1; end if(nargin > 3) Weights_File_Name = Weights_File_Name_1; mess = sprintf('load %s',Weights_File_Name); disp(mess) eval(mess); end SAVE_TEXT_LOG = 0; SAVE_MFILE_LOG = 0; if(nargin > 4) Log_File_Name = Log_File_Name_1; SAVE_TEXT_LOG = 1; end if(nargin > 5) Temp_Log_File_Name = Temp_Log_File_Name_1; SAVE_MFILE_LOG = 1; end TEST_INPUT = TEST_INPUT_1; start = last_iter; sz = size(TEST_INPUT); N_Test_Patterns = sz(1); prepare_tst_patterns; %%%%%%%%%%%%%%%%%%% BEGIN TESTING MODE %%%%%%%%%%%%%%%%%%%%%%%%%%%% %if(nargin == 1) r = calculate_rate; %end q_cal =[]; for k = 1:N_Test_Patterns if(kind == '1') q = calculate_ffm_output(k); end if(kind == '2') q = solve_nonlinear_equations_1(k); %Solve for q end for i = 1:N_Output q_cal(k,i) = q(output_index(i)); end end %for %%%%%%%%%%%%%%%%%%% END TESTING MODE %%%%%%%%%%%%%%%%%%%%%%%%%%%% if(SAVE_TEXT_LOG == 1) save_response_txt; end if(SAVE_MFILE_LOG == 1) save_response_m; end q_cal_1 = q_cal; %%%%%%%%%%%%%%%%%%% END TESTING MODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%% FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%% Prepare_Tst_Patterns %%%%%%%%%%%%%%%%%%%%%%%%% function prepare_tst_patterns() global N_Test_Patterns TEST_INPUT N_Input LAMBDA lambda N_Total %disp(' Preparing Test Patterns ....'); %%%%%%%%%%%%Function: Preparing Inputs for Testing %%%%%%%%%%%%%%% %####### Setting the Excitatory and Inhibitatory Training Patterns ######## %N_Test_Patterns = N_Patterns; Applied_lambda = zeros(N_Test_Patterns,N_Input); Applied_LAMBDA = zeros(N_Test_Patterns,N_Input); %yyy = size(TEST_INPUT); %N_Test_Patterns = yyy(1); for i = 1:N_Test_Patterns for j = 1:N_Input if (TEST_INPUT(i,j) >= 0) Applied_LAMBDA(i,j) = TEST_INPUT(i,j); elseif(TEST_INPUT(i,j) <0) Applied_lambda(i,j)= -TEST_INPUT(i,j); end end end %##### Preparing LAMBDA ################# %fill = zeros(N_Test_Patterns , N_Total - N_Input); %LAMBDA=[Applied_LAMBDA fill]; for k = 1:N_Test_Patterns for i = 1:N_Input LAMBDA(k,i) = Applied_LAMBDA(k,i) ; end for i = (N_Input+1):N_Total LAMBDA(k,i) = 0.0; end end %##### Preparing lambda ################# %Applied_lambda=zeros(N_Test_Patterns,N_Input); %fill = zeros(N_Test_Patterns , N_Total - N_Input); %lambda=[Applied_lambda fill]; for k = 1:N_Test_Patterns for i = 1:N_Input lambda(k,i) = Applied_lambda(k,i) ; end for i = (N_Input+1):N_Total lambda(k,i) = 0.0; end end %%%%%%%%%%%%%%%%%%%%% end Prepare_Tst_Patterns %%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%% calculate_rate %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function r_result = calculate_rate() global N_Total wplus wminus R_IN R_Out FIX_RIN N_Output output_index AUTO_MAPPING N_Input; for i = 1:N_Total r_result(i) = 0.0; end if(FIX_RIN == 1 ) for i = 1:N_Input r_result(i) = R_IN; end for i = (N_Input+1):N_Total for j = 1:N_Total r_result(i) = r_result(i) + wplus(i,j) + wminus(i,j); end end end if(FIX_RIN == 0 ) for i = 1:N_Total for j = 1:N_Total r_result(i) = r_result(i) + wplus(i,j) + wminus(i,j); end end end if(AUTO_MAPPING == 0) for i = 1:N_Output r_result(output_index(i)) = R_Out; end end %%%%%%%%%%%%%%%%%%%% end calculate_rate %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%% calculate_ffm_output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function q_result = calculate_ffm_output(k) global wplus wminus; global r; global N_Total N_Input; global R_Out; global output_index LAMBDA lambda y D Res; q = zeros(1,N_Total); for i = 1:N_Total N(i) = 0.0; D(i) = 0.0; for j = 1:N_Total N(i) = N(i) + q(j) * wplus(j,i); D(i) = D(i) + q(j) * wminus(j,i); end N(i) = N(i) + LAMBDA(k,i); D(i) = D(i) + r(i) + lambda(k,i); q(i) = N(i)/D(i); if(D(i) ~= 0) q(i) = N(i)/D(i); end if(D(i) == 0) q(i) = 1.0; end if(q(i) > 1.0) q(i) = 1.0; end if(q(i) < 0.0) q(i) = 0.0; end end q_result = q; %%%%%%%%%%%%%%%%%%%% end calculate_ffm_output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%% solve_nonlinear_equations_1 %%%%%%%%%%%%%%%%%%%%%%%%%%% function q_result = solve_nonlinear_equations_1(k) global wplus wminus; global r; global N_Total; global R_Out; global output_index LAMBDA lambda y D Res; lambda_minus = .2*rand(1,N_Total); for i = 1:N_Total for j = 1:N_Total if(r(i) ~= 0) Pplus(i,j) = wplus(i,j)/r(i); Pminus(i,j) = wminus(i,j)/r(i); else Pplus(i,j) = 0; Pminus(i,j) = 0; end end end for llll = 1:200 for i = 1:N_Total for j = 1:N_Total if(i == j) F(i,j) = r(i)/(r(i) + lambda_minus(i)); else F(i,j)=0; end end end lambda_plus = LAMBDA(k,:)*inv(eye(N_Total,N_Total)-F*Pplus); G = lambda_plus*F*Pminus + lambda(k,:); % abs(lambda_minus - G) % llll % pause iii = 0; for ll = 1:length(lambda_minus) if(abs(lambda_minus(i) - G(i)) > .001 | lambda_minus(i) < 0) iii = iii + 1; end end if(iii > 0) lambda_minus = G; else break; end end for i = 1:N_Total for j = 1:N_Total if(i == j) F(i,j) = r(i)/(r(i) + lambda_minus(i)); end if(i ~= j) F(i,j)=0; end end end lambda_plus = LAMBDA(k,:)*inv(eye(N_Total,N_Total)-F*Pplus); for i = 1:N_Total q(i) = lambda_plus(i)/(r(i)+lambda_minus(i)); if q(i) > 1 q(i) = 1; end if(q(i) < 0) q(i) = 0; end D(i) = lambda_minus(i)+r(i); end q_result = q; %%%%%%%%%%%%%%%%%%%%% end solve_nonlinear_equations %%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%% save_response_txt %%%%%%%%%%%%%%%%%%%%%%%%%%% function save_response_txt() global N_Test_Patterns Log_File_Name last_iter MSEaveg q_cal N_Output N_Input TEST_INPUT mess = sprintf(' Saving to log text file ....( %s )',Log_File_Name); disp(mess); fid = fopen(Log_File_Name,'w'); fprintf(fid,'Iteration No. %d MSE = %12.9f \n',last_iter, MSEaveg); fprintf(fid,'--------------------------------------------\n'); for k = 1:N_Test_Patterns fprintf(fid,'pattern No. %d: \n',k); for i=1:N_Input fprintf(fid,'%12.9f ',TEST_INPUT(k,i)); end fprintf(fid,'\n Response: \n'); for i = 1:N_Output fprintf(fid,'%12.9f ',q_cal(k,i)); end fprintf(fid,'\n'); end fclose(fid); %%%%%%%%%%%%%%%%%%%%% end save_response_txt %%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%% save_response_m %%%%%%%%%%%%%%%%%%%%%%%%%%% function save_response_m() global N_Test_Patterns Temp_Log_File_Name last_iter MSEaveg q_cal N_Output mess = sprintf(' Saving to log m file ....( %s )',Temp_Log_File_Name); disp(mess); fid = fopen(Temp_Log_File_Name,'w'); fprintf(fid,'%%Iteration No. %d MSE = %12.9f \n',last_iter, MSEaveg); fprintf(fid,'RESPONSE = [\n'); for k = 1:N_Test_Patterns for i = 1:N_Output fprintf(fid,'%12.9f ',q_cal(k,i)); end fprintf(fid,'\n'); end fprintf(fid,'];\n'); fclose(fid); %%%%%%%%%%%%%%%%%%%%% end save_response_m %%%%%%%%%%%%%%%%%%%%%%%%%%% %%%************************ end test_rnn_gen.m ************************%%%