Skip to content

Commit c70e34b

Browse files
Add C++ bindings for data set statistics.
1 parent 4a710ff commit c70e34b

6 files changed

Lines changed: 171 additions & 1 deletion

File tree

lib/cppbind/mmscenegraph/include/mmscenegraph/_cxxbridge.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,4 +1280,12 @@ MMSCENEGRAPH_API_EXPORT bool shim_calc_quartiles(::rust::Slice<const double> sor
12801280
MMSCENEGRAPH_API_EXPORT bool shim_calc_interquartile_range(::rust::Slice<const double> sorted_data, double &out_median, double &out_iqr) noexcept;
12811281

12821282
MMSCENEGRAPH_API_EXPORT bool shim_calc_percentile_rank(::rust::Slice<const double> sorted_data, double value, double &out_rank) noexcept;
1283+
1284+
MMSCENEGRAPH_API_EXPORT bool shim_calc_mean_absolute_error(::rust::Slice<const double> actual, ::rust::Slice<const double> predicted, double &out_mae) noexcept;
1285+
1286+
MMSCENEGRAPH_API_EXPORT bool shim_calc_root_mean_square_error(::rust::Slice<const double> actual, ::rust::Slice<const double> predicted, double &out_rmse) noexcept;
1287+
1288+
MMSCENEGRAPH_API_EXPORT bool shim_calc_normalized_root_mean_square_error(::rust::Slice<const double> actual, ::rust::Slice<const double> predicted, double &out_nrmse) noexcept;
1289+
1290+
MMSCENEGRAPH_API_EXPORT bool shim_calc_coefficient_of_determination(::rust::Slice<const double> actual, ::rust::Slice<const double> predicted, double &out_r_squared) noexcept;
12831291
} // namespace mmscenegraph

lib/cppbind/mmscenegraph/include/mmscenegraph/statistics.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ bool calc_quantile(rust::Slice<const Real> &sorted_data, const Real probability,
132132
MMSCENEGRAPH_API_EXPORT
133133
bool calc_quartiles(rust::Slice<const Real> &sorted_data, Real &out_q1,
134134
Real &out_q2, Real &out_q3) noexcept;
135-
135+
136136
MMSCENEGRAPH_API_EXPORT
137137
bool calc_interquartile_range(rust::Slice<const Real> &sorted_data,
138138
Real &out_median, Real &out_iqr) noexcept;
@@ -141,6 +141,26 @@ MMSCENEGRAPH_API_EXPORT
141141
bool calc_percentile_rank(rust::Slice<const Real> &sorted_data,
142142
const Real value, Real &out_rank) noexcept;
143143

144+
MMSCENEGRAPH_API_EXPORT
145+
bool calc_mean_absolute_error(rust::Slice<const Real> &actual,
146+
rust::Slice<const Real> &predicted,
147+
Real &out_mae) noexcept;
148+
149+
MMSCENEGRAPH_API_EXPORT
150+
bool calc_root_mean_square_error(rust::Slice<const Real> &actual,
151+
rust::Slice<const Real> &predicted,
152+
Real &out_rmse) noexcept;
153+
154+
MMSCENEGRAPH_API_EXPORT
155+
bool calc_normalized_root_mean_square_error(rust::Slice<const Real> &actual,
156+
rust::Slice<const Real> &predicted,
157+
Real &out_nrmse) noexcept;
158+
159+
MMSCENEGRAPH_API_EXPORT
160+
bool calc_coefficient_of_determination(rust::Slice<const Real> &actual,
161+
rust::Slice<const Real> &predicted,
162+
Real &out_r_squared) noexcept;
163+
144164
} // namespace mmscenegraph
145165

146166
#endif // MM_SOLVER_MM_SCENE_GRAPH_STATISTICS_H

lib/cppbind/mmscenegraph/src/_cxxbridge.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,14 @@ bool mmscenegraph$cxxbridge1$shim_calc_quartiles(::rust::Slice<const double> sor
14181418
bool mmscenegraph$cxxbridge1$shim_calc_interquartile_range(::rust::Slice<const double> sorted_data, double &out_median, double &out_iqr) noexcept;
14191419

14201420
bool mmscenegraph$cxxbridge1$shim_calc_percentile_rank(::rust::Slice<const double> sorted_data, double value, double &out_rank) noexcept;
1421+
1422+
bool mmscenegraph$cxxbridge1$shim_calc_mean_absolute_error(::rust::Slice<const double> actual, ::rust::Slice<const double> predicted, double &out_mae) noexcept;
1423+
1424+
bool mmscenegraph$cxxbridge1$shim_calc_root_mean_square_error(::rust::Slice<const double> actual, ::rust::Slice<const double> predicted, double &out_rmse) noexcept;
1425+
1426+
bool mmscenegraph$cxxbridge1$shim_calc_normalized_root_mean_square_error(::rust::Slice<const double> actual, ::rust::Slice<const double> predicted, double &out_nrmse) noexcept;
1427+
1428+
bool mmscenegraph$cxxbridge1$shim_calc_coefficient_of_determination(::rust::Slice<const double> actual, ::rust::Slice<const double> predicted, double &out_r_squared) noexcept;
14211429
} // extern "C"
14221430
} // namespace mmscenegraph
14231431

@@ -1964,6 +1972,22 @@ MMSCENEGRAPH_API_EXPORT bool shim_calc_interquartile_range(::rust::Slice<const d
19641972
MMSCENEGRAPH_API_EXPORT bool shim_calc_percentile_rank(::rust::Slice<const double> sorted_data, double value, double &out_rank) noexcept {
19651973
return mmscenegraph$cxxbridge1$shim_calc_percentile_rank(sorted_data, value, out_rank);
19661974
}
1975+
1976+
MMSCENEGRAPH_API_EXPORT bool shim_calc_mean_absolute_error(::rust::Slice<const double> actual, ::rust::Slice<const double> predicted, double &out_mae) noexcept {
1977+
return mmscenegraph$cxxbridge1$shim_calc_mean_absolute_error(actual, predicted, out_mae);
1978+
}
1979+
1980+
MMSCENEGRAPH_API_EXPORT bool shim_calc_root_mean_square_error(::rust::Slice<const double> actual, ::rust::Slice<const double> predicted, double &out_rmse) noexcept {
1981+
return mmscenegraph$cxxbridge1$shim_calc_root_mean_square_error(actual, predicted, out_rmse);
1982+
}
1983+
1984+
MMSCENEGRAPH_API_EXPORT bool shim_calc_normalized_root_mean_square_error(::rust::Slice<const double> actual, ::rust::Slice<const double> predicted, double &out_nrmse) noexcept {
1985+
return mmscenegraph$cxxbridge1$shim_calc_normalized_root_mean_square_error(actual, predicted, out_nrmse);
1986+
}
1987+
1988+
MMSCENEGRAPH_API_EXPORT bool shim_calc_coefficient_of_determination(::rust::Slice<const double> actual, ::rust::Slice<const double> predicted, double &out_r_squared) noexcept {
1989+
return mmscenegraph$cxxbridge1$shim_calc_coefficient_of_determination(actual, predicted, out_r_squared);
1990+
}
19671991
} // namespace mmscenegraph
19681992

19691993
extern "C" {

lib/cppbind/mmscenegraph/src/cxxbridge.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ use crate::scenebake::shim_bake_scene_graph;
3535
use crate::scenegraph::shim_create_scene_graph_box;
3636
use crate::scenegraph::ShimSceneGraph;
3737
use crate::statistics::{
38+
shim_calc_coefficient_of_determination,
3839
shim_calc_interquartile_range,
3940
shim_calc_local_minima_maxima,
4041
shim_calc_mean_absolute_deviation,
42+
shim_calc_mean_absolute_error,
4143
shim_calc_median_absolute_deviation,
4244
shim_calc_median_absolute_deviation_sigma,
45+
shim_calc_normalized_root_mean_square_error,
4346
shim_calc_peak_to_peak,
4447
shim_calc_percentile_rank,
4548
shim_calc_population_coefficient_of_variation,
@@ -49,6 +52,7 @@ use crate::statistics::{
4952
shim_calc_population_variance,
5053
shim_calc_quantile,
5154
shim_calc_quartiles,
55+
shim_calc_root_mean_square_error,
5256
shim_calc_sample_coefficient_of_variation,
5357
shim_calc_sample_kurtosis_excess,
5458
shim_calc_sample_relative_standard_deviation,
@@ -667,5 +671,29 @@ pub mod ffi {
667671
value: f64,
668672
out_rank: &mut f64,
669673
) -> bool;
674+
675+
fn shim_calc_mean_absolute_error(
676+
actual: &[f64],
677+
predicted: &[f64],
678+
out_mae: &mut f64,
679+
) -> bool;
680+
681+
fn shim_calc_root_mean_square_error(
682+
actual: &[f64],
683+
predicted: &[f64],
684+
out_rmse: &mut f64,
685+
) -> bool;
686+
687+
fn shim_calc_normalized_root_mean_square_error(
688+
actual: &[f64],
689+
predicted: &[f64],
690+
out_nrmse: &mut f64,
691+
) -> bool;
692+
693+
fn shim_calc_coefficient_of_determination(
694+
actual: &[f64],
695+
predicted: &[f64],
696+
out_r_squared: &mut f64,
697+
) -> bool;
670698
}
671699
}

lib/cppbind/mmscenegraph/src/statistics.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,34 @@ bool calc_percentile_rank(rust::Slice<const Real> &sorted_data,
190190
return shim_calc_percentile_rank(sorted_data, value, out_rank);
191191
}
192192

193+
MMSCENEGRAPH_API_EXPORT
194+
bool calc_mean_absolute_error(rust::Slice<const Real> &actual,
195+
rust::Slice<const Real> &predicted,
196+
Real &out_mae) noexcept {
197+
return shim_calc_mean_absolute_error(actual, predicted, out_mae);
198+
}
199+
200+
MMSCENEGRAPH_API_EXPORT
201+
bool calc_root_mean_square_error(rust::Slice<const Real> &actual,
202+
rust::Slice<const Real> &predicted,
203+
Real &out_rmse) noexcept {
204+
return shim_calc_root_mean_square_error(actual, predicted, out_rmse);
205+
}
206+
207+
MMSCENEGRAPH_API_EXPORT
208+
bool calc_normalized_root_mean_square_error(rust::Slice<const Real> &actual,
209+
rust::Slice<const Real> &predicted,
210+
Real &out_nrmse) noexcept {
211+
return shim_calc_normalized_root_mean_square_error(actual, predicted,
212+
out_nrmse);
213+
}
214+
215+
MMSCENEGRAPH_API_EXPORT
216+
bool calc_coefficient_of_determination(rust::Slice<const Real> &actual,
217+
rust::Slice<const Real> &predicted,
218+
Real &out_r_squared) noexcept {
219+
return shim_calc_coefficient_of_determination(actual, predicted,
220+
out_r_squared);
221+
}
222+
193223
} // namespace mmscenegraph

lib/cppbind/mmscenegraph/src/statistics.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020

2121
use mmscenegraph_rust::constant::Real as CoreReal;
2222
use mmscenegraph_rust::math::statistics::{
23+
calc_coefficient_of_determination as core_calc_coefficient_of_determination,
2324
calc_interquartile_range as core_calc_interquartile_range,
2425
calc_local_minima_maxima as core_calc_local_minima_maxima,
2526
calc_mean_absolute_deviation as core_calc_mean_absolute_deviation,
27+
calc_mean_absolute_error as core_calc_mean_absolute_error,
2628
calc_median_absolute_deviation as core_calc_median_absolute_deviation,
2729
calc_median_absolute_deviation_sigma as core_calc_median_absolute_deviation_sigma,
30+
calc_normalized_root_mean_square_error as core_calc_normalized_root_mean_square_error,
2831
calc_peak_to_peak as core_calc_peak_to_peak,
2932
calc_percentile_rank as core_calc_percentile_rank,
3033
calc_population_coefficient_of_variation as core_calc_population_coefficient_of_variation,
@@ -33,6 +36,7 @@ use mmscenegraph_rust::math::statistics::{
3336
calc_population_standard_deviation as core_calc_population_standard_deviation,
3437
calc_population_variance as core_calc_population_variance,
3538
calc_quantile as core_calc_quantile, calc_quartiles as core_calc_quartiles,
39+
calc_root_mean_square_error as core_calc_root_mean_square_error,
3640
calc_sample_coefficient_of_variation as core_calc_sample_coefficient_of_variation,
3741
calc_sample_kurtosis_excess as core_calc_sample_kurtosis_excess,
3842
calc_sample_relative_standard_deviation as core_calc_sample_relative_standard_deviation,
@@ -501,3 +505,59 @@ pub fn shim_calc_percentile_rank(
501505
Err(_) => false,
502506
}
503507
}
508+
509+
pub fn shim_calc_mean_absolute_error(
510+
actual: &[CoreReal],
511+
predicted: &[CoreReal],
512+
out_mae: &mut CoreReal,
513+
) -> bool {
514+
match core_calc_mean_absolute_error(actual, predicted) {
515+
Ok(mae) => {
516+
*out_mae = mae;
517+
true
518+
}
519+
Err(_) => false,
520+
}
521+
}
522+
523+
pub fn shim_calc_root_mean_square_error(
524+
actual: &[CoreReal],
525+
predicted: &[CoreReal],
526+
out_rmse: &mut CoreReal,
527+
) -> bool {
528+
match core_calc_root_mean_square_error(actual, predicted) {
529+
Ok(rmse) => {
530+
*out_rmse = rmse;
531+
true
532+
}
533+
Err(_) => false,
534+
}
535+
}
536+
537+
pub fn shim_calc_normalized_root_mean_square_error(
538+
actual: &[CoreReal],
539+
predicted: &[CoreReal],
540+
out_nrmse: &mut CoreReal,
541+
) -> bool {
542+
match core_calc_normalized_root_mean_square_error(actual, predicted) {
543+
Ok(nrmse) => {
544+
*out_nrmse = nrmse;
545+
true
546+
}
547+
Err(_) => false,
548+
}
549+
}
550+
551+
pub fn shim_calc_coefficient_of_determination(
552+
actual: &[CoreReal],
553+
predicted: &[CoreReal],
554+
out_r_squared: &mut CoreReal,
555+
) -> bool {
556+
match core_calc_coefficient_of_determination(actual, predicted) {
557+
Ok(r_squared) => {
558+
*out_r_squared = r_squared;
559+
true
560+
}
561+
Err(_) => false,
562+
}
563+
}

0 commit comments

Comments
 (0)