@@ -78,60 +78,60 @@ def plot_comparison(dt, dxdt_truth, dxdt_hat1, title1, dxdt_hat2, title2, dxdt_h
7878 fig .tight_layout ()
7979
8080
81- def robust_rme (x , x_hat , padding = 0 , M = 6 ):
81+ def robust_rme (u , v , padding = 0 , M = 6 ):
8282 """Robustified/Huberized Root Mean Error metric, used to determine fit between smooth estimate and data.
83- Equals np.linalg.norm(x [s] - x_hat [s]) / np.sqrt(N) if M=float('inf'), and dang close for M=6 or even 2.
83+ Equals np.linalg.norm(u [s] - v [s]) / np.sqrt(N) if M=float('inf'), and dang close for M=6 or even 2.
8484
85- :param np.array[float] x: noisy data
86- :param np.array[float] x_hat: estimated smoothed signal, returned by differentiation algorithms in addition
87- to derivative
85+ :param np.array[float] u: e.g. noisy data
86+ :param np.array[float] v: e.g. estimated smoothed signal, reconstructed from derivative
8887 :param int padding: number of snapshots on either side of the array to ignore when calculating
89- the metric. If :code:`'auto'`, defaults to 2.5% of the size of x
88+ the metric. If :code:`'auto'`, defaults to 2.5% of the size of inputs
9089 :param float M: Huber loss parameter in units of ~1.4*mean absolute deviation, intended to approximate
9190 standard deviation robustly.
9291
93- :return: **robust_rmse_x_hat** (float) -- RMS error between x_hat and data
92+ :return: (float) -- Robust root mean error between u and v
9493 """
95- if padding == 'auto' : padding = max (1 , int (0.025 * len (x )))
96- s = slice (padding , len (x )- padding ) # slice out data we want to measure
94+ if padding == 'auto' : padding = max (1 , int (0.025 * len (u )))
95+ s = slice (padding , len (u )- padding ) # slice out data we want to measure
9796 N = s .stop - s .start
9897
99- sigma = stats .median_abs_deviation (x [s ] - x_hat [s ], scale = 'normal' ) # M is in units of this robust scatter metric
98+ sigma = stats .median_abs_deviation (u [s ] - v [s ], scale = 'normal' ) # M is in units of this robust scatter metric
10099 if sigma < 1e-6 : sigma = 1 # guard against divide by zero
101- return np .sqrt (2 * np .mean (utility .huber ((x [s ] - x_hat [s ])/ sigma , M ))) * sigma
100+ return np .sqrt (2 * np .mean (utility .huber ((u [s ] - v [s ])/ sigma , M ))) * sigma
102101
103102
104- def rmse (dxdt_truth , dxdt_hat , padding = 0 ):
103+ def rmse (u , v , padding = 0 ):
105104 """True RMSE between vectors
106105
107- :param np.array[float] dxdt_truth: known true derivative
108- :param np.array[float] dxdt_hat: estimated derivative
106+ :param np.array[float] u: e.g. known true derivative
107+ :param np.array[float] v: e.g. estimated derivative
109108 :param int padding: number of snapshots on either side of the array to ignore when calculating
110- the metric. If :code:`'auto'`, defaults to 2.5% of the size of x
109+ the metric. If :code:`'auto'`, defaults to 2.5% of the size of inputs
111110
112- :return: **true_rmse_dxdt ** (float) -- RMS error between dxdt_hat and dxdt_truth, returns None if dxdt_hat is None
111+ :return: **true_rmse ** (float) -- RMS error between dxdt_hat and dxdt_truth, returns None if dxdt_hat is None
113112 """
114- if padding == 'auto' : padding = max (1 , int (0.025 * len (dxdt_truth )))
115- s = slice (padding , len (dxdt_hat )- padding ) # slice out data we want to measure
113+ if padding == 'auto' : padding = max (1 , int (0.025 * len (u )))
114+ s = slice (padding , len (u )- padding ) # slice out data we want to measure
116115 N = s .stop - s .start
117116
118- return np .linalg .norm (dxdt_truth [s ] - dxdt_hat [s ]) / np .sqrt (N )
117+ return np .linalg .norm (u [s ] - v [s ]) / np .sqrt (N )
119118
120119
121- def error_correlation (dxdt_truth , dxdt_hat , padding = 0 ):
122- """Calculate the error correlation (pearsons correlation coefficient) between vectors
120+ def error_correlation (u , v , padding = 0 ):
121+ """Calculate the error correlation (pearsons correlation coefficient) between the first vector and the
122+ difference between the two vectors.
123123
124- :param np.array[float] dxdt_truth: true value of dxdt, if known, optional
125- :param np.array[float] dxdt_hat: estimated xdot
124+ :param np.array[float] u: e.g. true value of dxdt, if known, optional
125+ :param np.array[float] v: e.g. estimated dxdt_hat
126126 :param int padding: number of snapshots on either side of the array to ignore when calculating
127- the metric. If :code:`'auto'`, defaults to 2.5% of the size of x
127+ the metric. If :code:`'auto'`, defaults to 2.5% of the size of inputs
128128
129129 :return: (float) -- r-squared correlation coefficient
130130 """
131- if padding == 'auto' : padding = max (1 , int (0.025 * len (dxdt_hat )))
132- s = slice (padding , len (dxdt_hat )- padding ) # slice out data we want to measure
131+ if padding == 'auto' : padding = max (1 , int (0.025 * len (u )))
132+ s = slice (padding , len (u )- padding ) # slice out data we want to measure
133133
134- return stats .linregress (dxdt_truth [s ], dxdt_hat [s ] - dxdt_truth [s ]).rvalue ** 2
134+ return stats .linregress (u [s ], v [s ] - u [s ]).rvalue ** 2
135135
136136
137137def total_variation (x , padding = 0 ):
0 commit comments