Struct argmin::core::test_utils::TestSparseProblem
source · [−]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
sourceimpl Clone for TestSparseProblem
impl Clone for TestSparseProblem
sourcefn clone(&self) -> TestSparseProblem
fn clone(&self) -> TestSparseProblem
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl CostFunction for TestSparseProblem
impl CostFunction for TestSparseProblem
sourcefn 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)?;
sourcefn bulk_cost<'a, P>(&self, params: &'a [P]) -> Result<Vec<Self::Output>, Error> where
P: Borrow<Self::Param> + SyncAlias,
Self::Output: SendAlias,
Self: SyncAlias,
fn bulk_cost<'a, P>(&self, params: &'a [P]) -> Result<Vec<Self::Output>, Error> where
P: Borrow<Self::Param> + SyncAlias,
Self::Output: SendAlias,
Self: SyncAlias,
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.
sourcefn 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.
sourceimpl Debug for TestSparseProblem
impl Debug for TestSparseProblem
sourceimpl Default for TestSparseProblem
impl Default for TestSparseProblem
sourcefn default() -> TestSparseProblem
fn default() -> TestSparseProblem
Returns the “default value” for a type. Read more
sourceimpl<'de> Deserialize<'de> for TestSparseProblem
impl<'de> Deserialize<'de> for TestSparseProblem
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Gradient for TestSparseProblem
impl Gradient for TestSparseProblem
sourcefn 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)?;
sourcefn bulk_gradient<'a, P>(
&self,
params: &'a [P]
) -> Result<Vec<Self::Gradient>, Error> where
P: Borrow<Self::Param> + SyncAlias,
Self::Gradient: SendAlias,
Self: SyncAlias,
fn bulk_gradient<'a, P>(
&self,
params: &'a [P]
) -> Result<Vec<Self::Gradient>, Error> where
P: Borrow<Self::Param> + SyncAlias,
Self::Gradient: SendAlias,
Self: SyncAlias,
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.
sourcefn 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.
sourceimpl Hash for TestSparseProblem
impl Hash for TestSparseProblem
sourceimpl PartialEq<TestSparseProblem> for TestSparseProblem
impl PartialEq<TestSparseProblem> for TestSparseProblem
sourcefn eq(&self, other: &TestSparseProblem) -> bool
fn eq(&self, other: &TestSparseProblem) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl Serialize for TestSparseProblem
impl Serialize for TestSparseProblem
impl Copy for TestSparseProblem
impl Eq for TestSparseProblem
impl StructuralEq for TestSparseProblem
impl StructuralPartialEq for TestSparseProblem
Auto Trait Implementations
impl RefUnwindSafe for TestSparseProblem
impl Send for TestSparseProblem
impl Sync for TestSparseProblem
impl Unpin for TestSparseProblem
impl UnwindSafe for TestSparseProblem
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more