Merge branch 'development' into ridge
This commit is contained in:
@@ -84,7 +84,7 @@ trait ObjectiveFunction<T: RealNumber, M: Matrix<T>> {
|
||||
let mut sum = T::zero();
|
||||
let p = x.shape().1;
|
||||
for i in 0..p {
|
||||
sum = sum + x.get(m_row, i) * w.get(0, i + v_col);
|
||||
sum += x.get(m_row, i) * w.get(0, i + v_col);
|
||||
}
|
||||
|
||||
sum + w.get(0, p + v_col)
|
||||
@@ -103,14 +103,14 @@ impl<T: RealNumber, M: Matrix<T>> PartialEq for LogisticRegression<T, M> {
|
||||
|| self.num_attributes != other.num_attributes
|
||||
|| self.classes.len() != other.classes.len()
|
||||
{
|
||||
return false;
|
||||
false
|
||||
} else {
|
||||
for i in 0..self.classes.len() {
|
||||
if (self.classes[i] - other.classes[i]).abs() > T::epsilon() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return self.coefficients == other.coefficients && self.intercept == other.intercept;
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,7 @@ impl<'a, T: RealNumber, M: Matrix<T>> ObjectiveFunction<T, M>
|
||||
|
||||
for i in 0..n {
|
||||
let wx = BinaryObjectiveFunction::partial_dot(w_bias, self.x, 0, i);
|
||||
f = f + (wx.ln_1pe() - (T::from(self.y[i]).unwrap()) * wx);
|
||||
f += wx.ln_1pe() - (T::from(self.y[i]).unwrap()) * wx;
|
||||
}
|
||||
|
||||
f
|
||||
@@ -171,7 +171,7 @@ impl<'a, T: RealNumber, M: Matrix<T>> ObjectiveFunction<T, M>
|
||||
);
|
||||
}
|
||||
prob.softmax_mut();
|
||||
f = f - prob.get(0, self.y[i]).ln();
|
||||
f -= prob.get(0, self.y[i]).ln();
|
||||
}
|
||||
|
||||
f
|
||||
@@ -217,9 +217,9 @@ impl<T: RealNumber, M: Matrix<T>> LogisticRegression<T, M> {
|
||||
let (_, y_nrows) = y_m.shape();
|
||||
|
||||
if x_nrows != y_nrows {
|
||||
return Err(Failed::fit(&format!(
|
||||
"Number of rows of X doesn't match number of rows of Y"
|
||||
)));
|
||||
return Err(Failed::fit(
|
||||
&"Number of rows of X doesn\'t match number of rows of Y".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let classes = y_m.unique();
|
||||
@@ -248,6 +248,7 @@ impl<T: RealNumber, M: Matrix<T>> LogisticRegression<T, M> {
|
||||
};
|
||||
|
||||
let result = LogisticRegression::minimize(x0, objective);
|
||||
|
||||
let weights = result.x;
|
||||
|
||||
Ok(LogisticRegression {
|
||||
@@ -269,7 +270,6 @@ impl<T: RealNumber, M: Matrix<T>> LogisticRegression<T, M> {
|
||||
};
|
||||
|
||||
let result = LogisticRegression::minimize(x0, objective);
|
||||
|
||||
let weights = result.x.reshape(k, num_attributes + 1);
|
||||
|
||||
Ok(LogisticRegression {
|
||||
@@ -332,8 +332,10 @@ impl<T: RealNumber, M: Matrix<T>> LogisticRegression<T, M> {
|
||||
|
||||
let df = |g: &mut M, w: &M| objective.df(g, w);
|
||||
|
||||
let mut ls: Backtracking<T> = Default::default();
|
||||
ls.order = FunctionOrder::THIRD;
|
||||
let ls: Backtracking<T> = Backtracking {
|
||||
order: FunctionOrder::THIRD,
|
||||
..Default::default()
|
||||
};
|
||||
let optimizer: LBFGS<T> = Default::default();
|
||||
|
||||
optimizer.optimize(&f, &df, &x0, &ls)
|
||||
@@ -371,7 +373,7 @@ mod tests {
|
||||
|
||||
let objective = MultiClassObjectiveFunction {
|
||||
x: &x,
|
||||
y: y,
|
||||
y,
|
||||
k: 3,
|
||||
phantom: PhantomData,
|
||||
};
|
||||
@@ -420,7 +422,7 @@ mod tests {
|
||||
|
||||
let objective = BinaryObjectiveFunction {
|
||||
x: &x,
|
||||
y: y,
|
||||
y,
|
||||
phantom: PhantomData,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user