77import pandas as pd
88import os
99
10- from rbf_network import WendlandLinearNetwork
10+ from rbf_network import rbf_dict , RadialBasisFunctionNetwork
1111
1212def psi (x , y ):
1313 """
@@ -28,7 +28,7 @@ def visualize_psi(x, y, psi_values, centers, title="Stream Function"):
2828 plt .figure (figsize = (6 , 6 ))
2929 plt .contourf (x , y , psi_values , levels = 20 , cmap = 'viridis' )
3030 plt .colorbar (label = 'ψ' )
31- plt .title (title )
31+ plt .title (title + f" num_centers { len ( centers ) } " )
3232 plt .xlabel ('x' )
3333 plt .ylabel ('y' )
3434 plt .grid ()
@@ -64,7 +64,7 @@ def generate_centers(num_centers):
6464def estimate_convergence_order (csv_filename ):
6565 """
6666 Opens a CSV file containing numerical convergence results and estimates the
67- convergence order for each row using log-log error reduction.
67+ convergence order for each error column using log-log error reduction.
6868
6969 The last row's convergence order is set equal to the second-to-last row.
7070
@@ -75,33 +75,36 @@ def estimate_convergence_order(csv_filename):
7575 df = pd .read_csv (csv_filename )
7676
7777 # Ensure required columns exist
78- required_columns = {"point_dist" , "err_validation " }
78+ required_columns = {"point_dist" , "err_mean" , "err_max " }
7979 if not required_columns .issubset (df .columns ):
8080 raise ValueError (f"Missing required columns in CSV: { required_columns - set (df .columns )} " )
8181
82- # Compute convergence order using log-log slope formula
83- convergence_orders = []
82+ # List of error columns to process
83+ error_columns = ["err_mean" , "err_max" ]
84+
85+ for error_col in error_columns :
86+ convergence_orders = [] # Store convergence orders for this error type
8487
85- for i in range (len (df ) - 1 ): # Iterate up to the second-to-last row
86- h_coarse , h_fine = df .iloc [i ]["point_dist" ], df .iloc [i + 1 ]["point_dist" ]
87- err_coarse , err_fine = df .iloc [i ]["err_validation" ], df .iloc [i + 1 ]["err_validation" ]
88+ for i in range (len (df ) - 1 ): # Iterate up to the second-to-last row
89+ h_coarse , h_fine = df .iloc [i ]["point_dist" ], df .iloc [i + 1 ]["point_dist" ]
90+ err_coarse , err_fine = df .iloc [i ][error_col ], df .iloc [i + 1 ][error_col ]
8891
89- if err_coarse > 0 and err_fine > 0 : # Avoid log errors due to zero or negative values
90- p = np .log (err_coarse / err_fine ) / np .log (h_coarse / h_fine )
91- convergence_orders .append (p )
92- else :
93- convergence_orders .append (np .nan )
92+ if err_coarse > 0 and err_fine > 0 : # Avoid log errors due to zero or negative values
93+ p = np .log (err_coarse / err_fine ) / np .log (h_coarse / h_fine )
94+ convergence_orders .append (p )
95+ else :
96+ convergence_orders .append (np .nan )
9497
95- # Ensure last row gets the same convergence order as the previous row
96- convergence_orders .append (convergence_orders [- 1 ] if len (convergence_orders ) > 0 else np .nan )
98+ # Ensure last row gets the same convergence order as the previous row
99+ convergence_orders .append (convergence_orders [- 1 ] if len (convergence_orders ) > 0 else np .nan )
97100
98- # Add convergence order column
99- df ["error_convergence_order " ] = convergence_orders
101+ # Add convergence order column to DataFrame
102+ df [f" { error_col } _convergence_order " ] = convergence_orders
100103
101104 # Save the updated CSV file
102105 df .to_csv (csv_filename , index = False )
103106
104- print (f"Updated { csv_filename } with convergence orders." )
107+ print (f"Updated { csv_filename } with convergence orders for { error_columns } ." )
105108
106109def main (num_points ):
107110 # Generate training data
@@ -123,7 +126,7 @@ def main(num_points):
123126 smoothness = 4 # C^4 smoothness
124127
125128 # Initialize model
126- model = WendlandLinearNetwork (centers , r_max , smoothness )
129+ model = RadialBasisFunctionNetwork (centers , r_max , rbf_dict , rbf_type = "gaussian" )
127130
128131 # Optimizer and loss
129132 optimizer = optim .Adam (model .parameters (), lr = 0.05 )
@@ -175,8 +178,8 @@ def main(num_points):
175178 csv_filename = "stream_function_validation.csv"
176179
177180 # Define the header and the values to be appended
178- header = ["num_points" , "point_dist" , "r_max" , "err_validation " ]
179- data = [num_points , 1.0 / num_points , r_max , np .mean (err_val )]
181+ header = ["num_points" , "point_dist" , "r_max" , "err_mean" , "err_max " ]
182+ data = [num_points , 1.0 / num_points , r_max , np .mean (err_val ), np . max ( err_val ) ]
180183
181184 # Check if file exists
182185 file_exists = os .path .isfile (csv_filename )
0 commit comments