Added q_col and p_row methods and description (#3)
This commit is contained in:
@@ -44,6 +44,13 @@ model.p_factors();
|
||||
model.q_factors();
|
||||
```
|
||||
|
||||
Get the latent factors of a specific row or column
|
||||
|
||||
```rust
|
||||
model.p_row(row_index);
|
||||
model.q_col(column_index);
|
||||
```
|
||||
|
||||
Get the bias (average of all elements in the training matrix)
|
||||
|
||||
```rust
|
||||
|
||||
20
src/model.rs
20
src/model.rs
@@ -70,6 +70,26 @@ impl Model {
|
||||
unsafe { std::slice::from_raw_parts((*self.model).q, (self.columns() * self.factors()) as usize) }
|
||||
}
|
||||
|
||||
pub fn p_row(&self, row_index: i32) -> Option<&[f32]>{
|
||||
if row_index >= 0 && row_index < self.rows() {
|
||||
let factors = self.factors();
|
||||
let start_index = factors as usize * row_index as usize;
|
||||
let end_index = factors as usize * (row_index as usize + 1);
|
||||
return Some(&self.p_factors()[start_index..end_index]);
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
pub fn q_col(&self, column_index: i32) -> Option<&[f32]>{
|
||||
if column_index >= 0 && column_index < self.columns() {
|
||||
let factors = self.factors();
|
||||
let start_index = factors as usize * column_index as usize;
|
||||
let end_index = factors as usize * (column_index as usize + 1);
|
||||
return Some(&self.q_factors()[start_index..end_index]);
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
pub fn rmse(&self, data: &Matrix) -> f64 {
|
||||
let prob = data.to_problem();
|
||||
unsafe { calc_rmse(&prob, self.model) }
|
||||
|
||||
Reference in New Issue
Block a user