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§
source§impl Clone for TestSparseProblem
impl Clone for TestSparseProblem
source§fn clone(&self) -> TestSparseProblem
fn clone(&self) -> TestSparseProblem
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§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
source§fn default() -> TestSparseProblem
fn default() -> TestSparseProblem
Returns the “default value” for a type. Read more
source§impl<'de> Deserialize<'de> for TestSparseProblem
impl<'de> Deserialize<'de> for TestSparseProblem
source§fn 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
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
source§fn 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 ==
.source§impl Serialize for TestSparseProblem
impl Serialize for TestSparseProblem
impl Copy for TestSparseProblem
impl Eq 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§
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
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.