pub struct TestSparseProblem {}Expand description
A struct representing the following sparse problem.
Example 1: x = [1, 1, 0, 0], y = 1 Example 2: x = [0, 0, 1, 1], y = -1 Example 3: x = [1, 0, 0, 0], y = 1 Example 4: x = [0, 0, 1, 0], y = -1
cost = Σ (w^T x - y)^2
Implements CostFunction and Gradient.
Implementations§
Trait Implementations§
Source§impl Clone for TestSparseProblem
impl Clone for TestSparseProblem
impl Copy for TestSparseProblem
Source§impl CostFunction for TestSparseProblem
impl CostFunction for TestSparseProblem
Source§fn cost(&self, param: &Self::Param) -> Result<Self::Output, Error>
fn cost(&self, param: &Self::Param) -> Result<Self::Output, Error>
Returns a sum of squared errors.
§Example
use argmin::core::test_utils::TestSparseProblem;
use argmin::core::CostFunction;
let problem = TestSparseProblem::new();
let param = vec![1.0, 2.0, 3.0, 4.0];
let res = problem.cost(¶m)?;Source§fn bulk_cost<P>(&self, params: &[P]) -> Result<Vec<Self::Output>, Error>
fn bulk_cost<P>(&self, params: &[P]) -> Result<Vec<Self::Output>, Error>
Compute
cost in bulk. If the rayon feature is enabled, multiple calls to cost will be run in parallel using rayon, otherwise they will execute sequentially. If the rayon feature is enabled, parallelization can still be turned off by overwriting parallelize to return false. This can be useful in cases where it is preferable to parallelize only certain parts. Note that even if parallelize is set to false, the parameter vectors and the problem are still required to be Send and Sync. Those bounds are linked to the rayon feature. This method can be overwritten.Source§fn parallelize(&self) -> bool
fn parallelize(&self) -> bool
Indicates whether to parallelize calls to
cost when using bulk_cost. By default returns true, but can be set manually to false if needed. This allows users to turn off parallelization for certain traits implemented on their problem. Note that parallelization requires the rayon feature to be enabled, otherwise calls to cost will be executed sequentially independent of how parallelize is set.Source§impl Debug for TestSparseProblem
impl Debug for TestSparseProblem
Source§impl Default for TestSparseProblem
impl Default for TestSparseProblem
impl Eq for TestSparseProblem
Source§impl Gradient for TestSparseProblem
impl Gradient for TestSparseProblem
Source§fn gradient(&self, param: &Self::Param) -> Result<Self::Gradient, Error>
fn gradient(&self, param: &Self::Param) -> Result<Self::Gradient, Error>
Returns a gradient of the cost function.
§Example
use argmin::core::test_utils::TestSparseProblem;
use argmin::core::Gradient;
let problem = TestSparseProblem::new();
let param = vec![1.0, 2.0, 3.0, 4.0];
let res = problem.gradient(¶m)?;Source§fn bulk_gradient<P>(&self, params: &[P]) -> Result<Vec<Self::Gradient>, Error>
fn bulk_gradient<P>(&self, params: &[P]) -> Result<Vec<Self::Gradient>, Error>
Compute
gradient in bulk. If the rayon feature is enabled, multiple calls to gradient will be run in parallel using rayon, otherwise they will execute sequentially. If the rayon feature is enabled, parallelization can still be turned off by overwriting parallelize to return false. This can be useful in cases where it is preferable to parallelize only certain parts. Note that even if parallelize is set to false, the parameter vectors and the problem are still required to be Send and Sync. Those bounds are linked to the rayon feature. This method can be overwritten.Source§fn parallelize(&self) -> bool
fn parallelize(&self) -> bool
Indicates whether to parallelize calls to
gradient when using bulk_gradient. By default returns true, but can be set manually to false if needed. This allows users to turn off parallelization for certain traits implemented on their problem. Note that parallelization requires the rayon feature to be enabled, otherwise calls to gradient will be executed sequentially independent of how parallelize is set.Source§impl Hash for TestSparseProblem
impl Hash for TestSparseProblem
Source§impl PartialEq for TestSparseProblem
impl PartialEq for TestSparseProblem
impl StructuralPartialEq for TestSparseProblem
Auto Trait Implementations§
impl Freeze for TestSparseProblem
impl RefUnwindSafe for TestSparseProblem
impl Send for TestSparseProblem
impl Sync for TestSparseProblem
impl Unpin for TestSparseProblem
impl UnsafeUnpin for TestSparseProblem
impl UnwindSafe for TestSparseProblem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more