@@ -178,7 +178,7 @@ void printMatrix(double* matrix, int rows, int cols, string name)
178178 for (int j=0 ;j<cols;j++)
179179 {
180180 // cout << setprecision(5);
181- cout << std::right << setw (15 ) << setprecision ( 5 ) << matrix[i+j*rows];
181+ cout << std::right << setw (15 ) << matrix[i+j*rows];
182182 }
183183 cout << " \n " ;
184184 }
@@ -198,7 +198,7 @@ void printMatrixWithHeaders(double* matrix, int rows, int cols, vector<string> h
198198 for (int j=0 ;j<cols;j++)
199199 {
200200 // cout << setprecision(5);
201- cout << std::right << setw (15 ) << setprecision ( 5 ) << matrix[i+j*rows];
201+ cout << std::right << setw (15 ) << matrix[i+j*rows];
202202 // printf("% .5e ", matrix[i+j*rows]);
203203 }
204204 cout << " \n " ;
@@ -340,18 +340,27 @@ matrixData solveReconciledX(matrixData x, matrixData Sx, matrixData Ft, matrixDa
340340 // Sx*Ft
341341 double * tmpMatrixAf = (double *)calloc (Sx.rows *Ft.column ,sizeof (double ));
342342 solveMatrixMultiplication (Sx.data ,Ft.data ,Sx.rows ,Sx.column ,Ft.rows ,Ft.column ,tmpMatrixAf);
343-
344- // (Sx*Ft)*Fstar
343+ // printMatrix(tmpMatrixAf,Sx.rows,Ft.column,"Sx*Ft");
344+ // (Sx*Ft)*fstar
345345 double * tmpMatrixBf = (double *)calloc (Sx.rows *Fstar.column ,sizeof (double ));
346346 solveMatrixMultiplication (tmpMatrixAf,Fstar.data ,Sx.rows ,Ft.column ,Fstar.rows ,Fstar.column ,tmpMatrixBf);
347+ // printMatrix(tmpMatrixBf,Sx.rows,Fstar.column,"(Sx*Ft*fstar)");
347348
348349 matrixData rhs= {Sx.rows ,Fstar.column ,tmpMatrixBf};
349350 // matrixData rhs = Calculate_Sx_Ft_Fstar(Sx,Ft,Fstar);
350351
351352 double * reconciledX = (double *)calloc (x.rows *x.column ,sizeof (double ));
352353 solveMatrixSubtraction (x,rhs,reconciledX);
353-
354354 // printMatrix(reconciledX,x.rows,x.column,"reconciled X^cap ===> (x - (Sx*Ft*fstar))");
355+ if (ACTIVE_STREAM (LOG_JAC))
356+ {
357+ cout << " Calculations of Reconciled_x ==> (x - (Sx*Ft*f*))" << " \n " ;
358+ cout << " ====================================================" ;
359+ printMatrix (tmpMatrixAf,Sx.rows ,Ft.column ," Sx*Ft" );
360+ printMatrix (tmpMatrixBf,Sx.rows ,Fstar.column ," (Sx*Ft*f*)" );
361+ printMatrix (reconciledX,x.rows ,x.column ," x - (Sx*Ft*f*))" );
362+ cout << " ***** Completed ****** \n\n " ;
363+ }
355364 matrixData recon_x = {x.rows ,x.column ,reconciledX};
356365 // free(reconciledX);
357366 free (tmpMatrixAf);
@@ -374,15 +383,23 @@ matrixData solveReconciledSx(matrixData Sx, matrixData Ft, matrixData Fstar)
374383 // (Sx*Ft)*Fstar
375384 double * tmpMatrixB = (double *)calloc (Sx.rows *Fstar.column ,sizeof (double ));
376385 solveMatrixMultiplication (tmpMatrixA,Fstar.data ,Sx.rows ,Ft.column ,Fstar.rows ,Fstar.column ,tmpMatrixB);
377- // printMatrix1 (tmpMatrixB,Sx.rows,Fstar.column,"Reconciled-(Sx*Ft*Fstar)");
386+ // printMatrix (tmpMatrixB,Sx.rows,Fstar.column,"Reconciled-(Sx*Ft*Fstar)");
378387
379388 matrixData rhs= {Sx.rows ,Fstar.column ,tmpMatrixB};
380389
381390 // matrixData rhs = Calculate_Sx_Ft_Fstar(Sx,Ft,Fstar);
382391 double * reconciledSx = (double *)calloc (Sx.rows *Sx.column ,sizeof (double ));
383392 solveMatrixSubtraction (Sx,rhs,reconciledSx);
384-
385393 // printMatrix(reconciledSx,Sx.rows,Sx.column,"reconciled Sx ===> (Sx - (Sx*Ft*Fstar))");
394+ if (ACTIVE_STREAM (LOG_JAC))
395+ {
396+ cout << " Calculations of Reconciled_Sx ===> (Sx - (Sx*Ft*F*))" << " \n " ;
397+ cout << " ============================================" ;
398+ printMatrix (tmpMatrixA,Sx.rows ,Ft.column ," (Sx*Ft)" );
399+ printMatrix (tmpMatrixB,Sx.rows ,Fstar.column ," (Sx*Ft*F*)" );
400+ printMatrix (reconciledSx,Sx.rows ,Sx.column ," Sx - (Sx*Ft*F*))" );
401+ cout << " ***** Completed ****** \n\n " ;
402+ }
386403 matrixData recon_sx ={Sx.rows ,Sx.column ,reconciledSx};
387404 // free(reconciledSx);
388405 free (tmpMatrixA);
@@ -432,12 +449,15 @@ matrixData getTransposeMatrix(matrixData jacF)
432449 int rows=jacF.column ;
433450 int cols=jacF.rows ;
434451 double * jacFT = (double *)calloc (rows*cols,sizeof (double )); // allocate for Matrix F-transpose
435- for (int i=0 ;i<rows; i++)
452+ int k=0 ;
453+ for (int i=0 ;i<jacF.rows ; i++)
436454 {
437- for (int j=0 ;j<cols ;j++)
455+ for (int j=0 ;j<jacF. column ;j++)
438456 {
439457 // Perform matrix transpose store the elements in column major
440- jacFT[i*cols+j]= jacF.data [i+j*rows];
458+ // cout << (i1*jacF.rows+j1) << " index :" << (i1+j1*jacF.rows) << " value is: " << jacF.data[i1+j1*jacF.rows] << "\n";
459+ jacFT[k++]= jacF.data [i+j*jacF.rows ];
460+
441461 }
442462 }
443463 matrixData Ft_data ={rows,cols,jacFT};
@@ -495,6 +515,8 @@ inputData getInputDataFromStartAttribute(csvData Sx_result, matrixData Sx, DATA*
495515 {
496516 tempx[h] = data->simulationInfo ->inputVars [in];
497517 index.push_back (in);
518+ // cout << knowns[in] << " start value :" << data->simulationInfo->inputVars[in] << "\n";
519+ // cout << "fetch index :" << in << "\n";
498520 }
499521 }
500522 }
@@ -702,20 +724,24 @@ int RunReconciliation(DATA* data, threadData_t *threadData, inputData x, matrixD
702724 matrixData jacF = getJacobianMatrixF (data,threadData);
703725 matrixData jacFt = getTransposeMatrix (jacF);
704726
705- // printMatrix(jacF.data,jacF.rows,jacF.column,"checknewJacobian_F");
706- // printMatrix(jacFt.data,jacFt.rows,jacFt.column,"checknewJacobian_Ft");
727+ printMatrix (jacF.data ,jacF.rows ,jacF.column ," F" );
728+ printMatrix (jacFt.data ,jacFt.rows ,jacFt.column ," Ft" );
729+
707730
708731 double * setc = (double *)calloc (data->modelData ->nSetcVars ,sizeof (double )); // allocate data for setc array
709732 // store the setc data to compute for convergence as setc will be overriddeen with new values
710733 double * tmpsetc = (double *)calloc (data->modelData ->nSetcVars ,sizeof (double ));
711734
712- /* loop to store the data C(x,y) rhs side */
713- for (int i=0 ; i < data->modelData ->nSetcVars ; i++)
735+ /* loop to store the data C(x,y) rhs side, get the elements in reverse order */
736+ int t=0 ;
737+ for (int i=data->modelData ->nSetcVars ; i > 0 ; i--)
714738 {
715- setc[i]=data->simulationInfo ->setcVars [i];
716- tmpsetc[i]=data->simulationInfo ->setcVars [i];
717- // cout << "array_setc_vars:=>" << setc[i] << "\n";
739+ setc[t]=data->simulationInfo ->setcVars [i-1 ];
740+ tmpsetc[t]=data->simulationInfo ->setcVars [i-1 ];
741+ t++;
742+ // cout << "array_setc_vars:=>" << t << ":" << data->simulationInfo->setcVars[i-1] << "\n";
718743 }
744+
719745 int nsetcvars= data->modelData ->nSetcVars ;
720746 matrixData vector_c = {nsetcvars,1 ,tmpsetc};
721747 // allocate data for matrix multiplication F*Sx
@@ -727,7 +753,15 @@ int RunReconciliation(DATA* data, threadData_t *threadData, inputData x, matrixD
727753 double * tmpmatrixD = (double *)calloc (jacF.rows *jacFt.column ,sizeof (double ));
728754 solveMatrixMultiplication (tmpmatrixC,jacFt.data ,jacF.rows ,Sx.column ,jacFt.rows ,jacFt.column ,tmpmatrixD);
729755 // printMatrix(tmpmatrixD,jacF.rows,jacFt.column,"F*Sx*Ft");
730-
756+ // printMatrix(setc,nsetcvars,1,"c(x,y)");
757+ if (ACTIVE_STREAM (LOG_JAC))
758+ {
759+ cout << " Calculations of Matrix (F*Sx*Ft) f* = c(x,y) " << " \n " ;
760+ cout << " ============================================" ;
761+ printMatrix (tmpmatrixC,jacF.rows ,Sx.column ," F*Sx" );
762+ printMatrix (tmpmatrixD,jacF.rows ,jacFt.column ," F*Sx*Ft" );
763+ printMatrix (setc,nsetcvars,1 ," c(x,y)" );
764+ }
731765 /*
732766 * calculate f* for covariance matrix (F*Sx*Ftranspose).F*= c(x,y)
733767 * matrix setc will be overridden with new values which is the output
@@ -736,13 +770,23 @@ int RunReconciliation(DATA* data, threadData_t *threadData, inputData x, matrixD
736770 * B = setc
737771 */
738772 solveSystemFstar (jacF.rows ,1 ,tmpmatrixD,setc);
739- // printMatrix(setc,jacF.rows,1,"x^cap_f*");
740-
773+ // printMatrix(setc,jacF.rows,1,"f*");
774+ if (ACTIVE_STREAM (LOG_JAC))
775+ {
776+ printMatrix (setc,jacF.rows ,1 ," f*" );
777+ cout << " ***** Completed ****** \n\n " ;
778+ }
741779 matrixData tmpxcap ={x.rows ,1 ,x.data };
742780 matrixData tmpfstar = {jacF.rows ,1 ,setc};
743781 matrixData reconciled_X = solveReconciledX (tmpxcap,Sx,jacFt,tmpfstar);
744782 // printMatrix(reconciled_X.data,reconciled_X.rows,reconciled_X.column,"reconciled_X ===> (x - (Sx*Ft*fstar))");
745-
783+ if (ACTIVE_STREAM (LOG_JAC))
784+ {
785+ cout << " Calculations of Matrix (F*Sx*Ft) F* = F*Sx " << " \n " ;
786+ cout << " ===============================================" ;
787+ printMatrix (tmpmatrixC,jacF.rows ,Sx.column ," F*Sx" );
788+ printMatrix (tmpmatrixD,jacF.rows ,jacFt.column ," F*Sx*Ft" );
789+ }
746790 /*
747791 * calculate F* for covariance matrix (F*Sx*Ftranspose).F*= (F*Sx)
748792 * matrix C will be overridden with new values which is the output
@@ -752,50 +796,53 @@ int RunReconciliation(DATA* data, threadData_t *threadData, inputData x, matrixD
752796 */
753797 solveSystemFstar (jacF.rows ,Sx.column ,tmpmatrixD,tmpmatrixC);
754798 // printMatrix(tmpmatrixC,jacF.rows,Sx.column,"Sx_F*");
799+ if (ACTIVE_STREAM (LOG_JAC))
800+ {
801+ printMatrix (tmpmatrixC,jacF.rows ,Sx.column ," F*" );
802+ cout << " ***** Completed ****** \n\n " ;
803+ }
755804
756805 matrixData tmpFstar = {jacF.rows ,Sx.column ,tmpmatrixC};
757806 matrixData reconciled_Sx = solveReconciledSx (Sx,jacFt,tmpFstar);
758807 // printMatrix(reconciled_Sx.data,reconciled_Sx.rows,reconciled_Sx.column,"reconciled Sx ===> (Sx - (Sx*Ft*Fstar))");
759808
760809 double value = solveConvergence (data,reconciled_X,reconciled_Sx,x,Sx,jacF,vector_c,tmpfstar);
761- if (value > eps && iterationcount== 1 )
810+ if (value > eps )
762811 {
763- cout << " J*/r > " << eps << " , Value not Converged, Starting the Convergence Iteration \n " ;
764- cout << " ========================================================================= \n\n " ;
812+ cout << " J*/r" << " ( " << value << " ) " << " > " << eps << " , Value not Converged \n " ;
813+ cout << " ==========================================\n\n " ;
765814 }
766815 if (value > eps)
767816 {
768- cout << " Running Convergence iteration: " << iterationcount << " \n " ;
769- cout << " ================================" << " \n " ;
770- cout << " J*/r :=" << value << " \n " ;
771- printMatrix (jacF.data ,jacF.rows ,jacF.column ," F" );
772- printMatrix (setc,jacF.rows ,1 ," f*" );
773- printMatrix (tmpmatrixC,jacF.rows ,Sx.column ," F*" );
817+ cout << " Running Convergence iteration: " << iterationcount << " with the following reconciled values:" << " \n " ;
818+ cout << " ========================================================================" << " \n " ;
819+ // cout << "J*/r :=" << value << "\n";
820+ // printMatrix(jacF.data,jacF.rows,jacF.column,"F");
821+ // printMatrix(jacFt.data,jacFt.rows,jacFt.column,"Ft");
822+ // printMatrix(setc,jacF.rows,1,"f*");
823+ // printMatrix(tmpmatrixC,jacF.rows,Sx.column,"F*");
774824 printMatrixWithHeaders (reconciled_X.data ,reconciled_X.rows ,reconciled_X.column ,headers," reconciled_X ===> (x - (Sx*Ft*fstar))" );
775825 printMatrixWithHeaders (reconciled_Sx.data ,reconciled_Sx.rows ,reconciled_Sx.column ,headers," reconciled_Sx ===> (Sx - (Sx*Ft*Fstar))" );
776826 // free(x.data);
777827 // free(Sx.data);
778828 x.data =reconciled_X.data ;
779- Sx.data =reconciled_Sx.data ;
829+ // Sx.data=reconciled_Sx.data;
780830 iterationcount++;
781831 return RunReconciliation (data, threadData, x, Sx, jacF, jacFt,eps,iterationcount,headers);
782832 }
783833 if (value < eps && iterationcount==1 )
784834 {
785- cout << " J*/r < " << eps << " , Convergence iteration not required \n\n " ;
835+ cout << " J*/r" << " ( " << value << " ) " << " > " << eps << " , Convergence iteration not required \n\n " ;
786836 }
787837 else
788838 {
789- cout << " *****Convergence Completed******* \n\n " ;
839+ cout << " ***** Value Converged, Convergence Completed******* \n\n " ;
790840 }
791- cout << " Final Results\n " ;
841+ cout << " Final Results: \n " ;
792842 cout << " =============\n " ;
793843 cout << " Total Iteration to Converge : " << iterationcount << " \n " ;
794844 cout << " Final Converged Value(J*/r) : " << value << " \n " ;
795845 cout << " Epselon : " << eps << " \n " ;
796- printMatrix (jacF.data ,jacF.rows ,jacF.column ," F" );
797- printMatrix (setc,jacF.rows ,1 ," f*" );
798- printMatrix (tmpmatrixC,jacF.rows ,Sx.column ," F*" );
799846 printMatrixWithHeaders (reconciled_X.data ,reconciled_X.rows ,reconciled_X.column ,headers," reconciled_X ===> (x - (Sx*Ft*fstar))" );
800847 printMatrixWithHeaders (reconciled_Sx.data ,reconciled_Sx.rows ,reconciled_Sx.column ,headers," reconciled_Sx ===> (Sx - (Sx*Ft*Fstar))" );
801848 free (tmpFstar.data );
@@ -833,8 +880,8 @@ int dataReconciliation(DATA* data, threadData_t *threadData)
833880 cout<< " \n\n Initial Data" << " \n " << " =============\n " ;
834881 printMatrixWithHeaders (x.data ,x.rows ,x.column ,Sx_data.headers ," X" );
835882 printMatrixWithHeaders (Sx.data ,Sx.rows ,Sx.column ,Sx_data.headers ," Sx" );
836- printMatrix (jacF.data ,jacF.rows ,jacF.column ," F" );
837- printMatrix (jacFt.data ,jacFt.rows ,jacFt.column ," Ft" );
883+ // printMatrix(jacF.data,jacF.rows,jacF.column,"F");
884+ // printMatrix(jacFt.data,jacFt.rows,jacFt.column,"Ft");
838885 // Start the Algorithm
839886 RunReconciliation (data,threadData,x,Sx,jacF,jacFt,atof (epselon),1 ,Sx_data.headers );
840887 free (Sx.data );
0 commit comments