src/convex.rs

branch
dev
changeset 106
1256e7f7f7ad
parent 105
103aa137fcb2
child 107
441d30e66a4a
equal deleted inserted replaced
105:103aa137fcb2 106:1256e7f7f7ad
7 use crate::linops::{IdOp, Scaled}; 7 use crate::linops::{IdOp, Scaled};
8 use crate::mapping::{Mapping, Space}; 8 use crate::mapping::{Mapping, Space};
9 use crate::norms::*; 9 use crate::norms::*;
10 use crate::operator_arithmetic::{Constant, Weighted}; 10 use crate::operator_arithmetic::{Constant, Weighted};
11 use crate::types::*; 11 use crate::types::*;
12 use serde::{Deserialize, Serialize};
12 use std::marker::PhantomData; 13 use std::marker::PhantomData;
13 14
14 /// Trait for convex mappings. Has no features, just serves as a constraint 15 /// Trait for convex mappings. Has no features, just serves as a constraint
15 /// 16 ///
16 /// TODO: should constrain `Mapping::Codomain` to implement a partial order, 17 /// TODO: should constrain `Mapping::Codomain` to implement a partial order,
72 *y = self.prox(τ, &*y); 73 *y = self.prox(τ, &*y);
73 } 74 }
74 } 75 }
75 76
76 /// Constraint to the unit ball of the norm described by `E`. 77 /// Constraint to the unit ball of the norm described by `E`.
78 #[derive(Copy, Clone, Debug, Serialize, Deserialize)]
77 pub struct NormConstraint<F: Float, E: NormExponent> { 79 pub struct NormConstraint<F: Float, E: NormExponent> {
78 radius: F, 80 radius: F,
79 norm: NormMapping<F, E>, 81 norm: NormMapping<F, E>,
80 } 82 }
81 83
176 } 178 }
177 } 179 }
178 } 180 }
179 181
180 /// Projection to the unit ball of the norm described by `E`. 182 /// Projection to the unit ball of the norm described by `E`.
183 #[derive(Copy, Clone, Debug, Serialize, Deserialize)]
181 pub struct NormProjection<F: Float, E: NormExponent> { 184 pub struct NormProjection<F: Float, E: NormExponent> {
182 radius: F, 185 radius: F,
183 exponent: E, 186 exponent: E,
184 } 187 }
185 188
209 d.own().proj_ball(self.radius, self.exponent) 212 d.own().proj_ball(self.radius, self.exponent)
210 } 213 }
211 } 214 }
212 215
213 /// The zero mapping 216 /// The zero mapping
217 #[derive(Copy, Clone, Debug, Serialize, Deserialize)]
214 pub struct Zero<Domain: Space, F: Num>(PhantomData<(Domain, F)>); 218 pub struct Zero<Domain: Space, F: Num>(PhantomData<(Domain, F)>);
215 219
216 impl<Domain: Space, F: Num> Zero<Domain, F> { 220 impl<Domain: Space, F: Num> Zero<Domain, F> {
217 pub fn new() -> Self { 221 pub fn new() -> Self {
218 Zero(PhantomData) 222 Zero(PhantomData)
269 IdOp::new() 273 IdOp::new()
270 } 274 }
271 } 275 }
272 276
273 /// The zero indicator 277 /// The zero indicator
278 #[derive(Copy, Clone, Debug, Serialize, Deserialize)]
274 pub struct ZeroIndicator<Domain: Space, F: Num>(PhantomData<(Domain, F)>); 279 pub struct ZeroIndicator<Domain: Space, F: Num>(PhantomData<(Domain, F)>);
275 280
276 impl<Domain: Space, F: Num> ZeroIndicator<Domain, F> { 281 impl<Domain: Space, F: Num> ZeroIndicator<Domain, F> {
277 pub fn new() -> Self { 282 pub fn new() -> Self {
278 ZeroIndicator(PhantomData) 283 ZeroIndicator(PhantomData)
317 Zero::new() 322 Zero::new()
318 } 323 }
319 } 324 }
320 325
321 /// The squared Euclidean norm divided by two 326 /// The squared Euclidean norm divided by two
327 #[derive(Copy, Clone, Serialize, Deserialize)]
322 pub struct Norm222<F: Float>(PhantomData<F>); 328 pub struct Norm222<F: Float>(PhantomData<F>);
323 329
324 impl</*Domain: Euclidean<F>,*/ F: Float> Norm222<F> { 330 impl</*Domain: Euclidean<F>,*/ F: Float> Norm222<F> {
325 pub fn new() -> Self { 331 pub fn new() -> Self {
326 Norm222(PhantomData) 332 Norm222(PhantomData)

mercurial