-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
index out of bounds error using logistic_regression #256
Comments
UpdateThe error happens when running the optimization, calling fn optimize<'a, X: Array1<T>, LS: LineSearchMethod<T>>(
&self,
f: &F<'_, T, X>,
df: &'a DF<'_, X>,
x0: &X,
ls: &'a LS,
) -> OptimizerResult<T, X> {
let mut state = self.init_state(x0);
df(&mut state.x_df, x0); // <<<
...
} |
Thanks for reporting this. |
Hi @EdmundsEcho
there are two major problems with your method call
The compiler correctly asks references to be used and I don't know how you made this code to run as every compiler I tried (on x86) returned this error (passing values instead of references).
Remember always to pass by reference as I will take a deeper look into this because it is always possible that there is some error buried in the API calls but for now I close this issue as resolved. Thanks for using the library. |
Thank you for the follow-up. Here is the code (it compiles :)) pub fn run_logit(&self) -> Result<LogitFindings> {
let x: &DenseMatrix<f64> = &self.inner.x;
let y: &Vec<u32> = &self.inner.y.iter().map(|f| *f as u32).collect();
println!("y vec height: {:?}", y.len());
println!("x matrix shape: {:?}", x.shape());
let lr = LogisticRegression::fit(x, y, Default::default())?;
// let y_hat = lr.predict(&x)?;
// todo: add the result to the dataframe and return findings
Ok(LogitFindings {})
} [dependencies]
...
smartcore = "0.3.1" |
Seems to be an edge case that we are not handling. I see that in the |
Where it starts pointing to an index out of bounds is in the I saw the checks. It makes me wonder if there is a underlying data structure ("under the hood") being used that somehow is not being build large enough?? |
I constructing the the DenseMatrix by way of ndarray and directly from polars. Here is as far as I can pinpoint. // optimization/first_order/logistic_regression.rs
impl<T: FloatNumber + RealNumber> FirstOrderOptimizer<T> for LBFGS {
///
fn optimize<'a, X: Array1<T>, LS: LineSearchMethod<T>>(
&self,
f: &F<'_, T, X>,
df: &'a DF<'_, X>,
x0: &X,
ls: &'a LS,
) -> OptimizerResult<T, X> {
let mut state = self.init_state(x0);
df(&mut state.x_df, x0); // <<< does not get past here
let g_converged = state.x_df.norm(std::f64::INFINITY) < self.g_atol;
let mut converged = g_converged;
let stopped = false;
...
} ... where let df = |g: &mut Vec<TX>, w: &Vec<TX>| {
objective.df(g, w)
}; The Array trait for DenseMatrix clearly demonstrates the issue: The |
Thanks, with the full example makes more sense. |
if it is like this, wouldn't we see one of the tests involving that method to fail? That method is used in many other places, like iterators and everything seems to work OK. @EdmundsEcho I have added your code to a test and everything works fine -> #257 Some checks:
Sorry I cannot replicate your problem. If you can tell me more about how to replicate your problem I would be glad to look into it. |
I think that we don't have the exact same data in our tests cases, right? We added a random test but it is not necessarily the same data. We would need to be sure. I would like to have an example of a DenseMatrix with this characteristics:
|
Great test on your partThank you for generating the test. It was convincing and enabled my working "upstream" as needed. Bug foundIt happens when Just to make the point, here is adjusted code base. The ultimate solution would involve changing the return to a // src/linalg/basic/matrix.rs
impl<T: Debug + Display + Copy + Sized> DenseMatrix<T> {
/// Create new instance of `DenseMatrix` without copying data.
/// `values` should be in column-major order.
pub fn new(nrows: usize, ncols: usize, values: Vec<T>, column_major: bool) -> Self {
assert!(
nrows * ncols == values.len(),
"Failed to instantiate DenseMatrix; data does not match shape"
);
DenseMatrix {
ncols,
nrows,
values,
column_major,
}
}
..
} False negative when trying to debug using
|
Thanks for the clarification! |
I'm submitting a
Current Behaviour:
When I call
I get an index out of bounds error.
Expected Behaviour:
It should compute the linear regression without throwing an error.
Steps to reproduce:
These are the input shapes
Snapshot:
Environment:
Do you want to work on this issue?
yes. I'm trying to debug it now. This said, I'm new to this lib and so want to make sure I'm not missing something.
The text was updated successfully, but these errors were encountered: