fetish_lib/
feature_collection.rs1extern crate ndarray;
2extern crate ndarray_linalg;
3
4use ndarray::*;
5use crate::fourier_feature_collection::*;
6use crate::quadratic_feature_collection::*;
7use crate::sketched_linear_feature_collection::*;
8use crate::rand_utils::*;
9
10pub trait FeatureCollection {
11 fn get_in_dimensions(&self) -> usize;
13
14 fn get_dimension(&self) -> usize;
16
17 fn get_features(&self, in_vec: ArrayView1<f32>) -> Array1<f32>;
20
21 fn get_jacobian(&self, in_vec: ArrayView1<f32>) -> Array2<f32>;
25
26 fn get_features_mat(&self, in_mat : ArrayView2<f32>) -> Array2<f32> {
30 let n = in_mat.shape()[0];
31 let d = self.get_dimension();
32 let mut result = Array::zeros((n, d));
33 for i in 0..n {
34 let in_vec = in_mat.row(i).to_owned();
35 let feat_vec = self.get_features(in_vec.view());
36 result.row_mut(i).assign(&feat_vec);
37 }
38 result
39 }
40}
41
42pub fn get_total_feat_dims(feature_collections : &Vec<Box<dyn FeatureCollection>>) -> usize {
45 let mut total_feat_dims : usize = 0;
46 for collection in feature_collections.iter() {
47 total_feat_dims += collection.get_dimension();
48 }
49 total_feat_dims
50}