src/convex.rs

branch
dev
changeset 164
fd9dba51afd3
parent 163
b4a47e8e80d1
child 168
93daa824c04a
equal deleted inserted replaced
163:b4a47e8e80d1 164:fd9dba51afd3
55 /// Trait for mappings with a proximap map 55 /// Trait for mappings with a proximap map
56 /// 56 ///
57 /// The conjugate type has to implement [`ConvexMapping`], but a `Conjugable` mapping need 57 /// The conjugate type has to implement [`ConvexMapping`], but a `Conjugable` mapping need
58 /// not be convex. 58 /// not be convex.
59 pub trait Prox<Domain: Space>: Mapping<Domain> { 59 pub trait Prox<Domain: Space>: Mapping<Domain> {
60 type Prox<'a>: Mapping<Domain, Codomain = Domain::OwnedSpace> 60 type Prox<'a>: Mapping<Domain, Codomain = Domain::Principal>
61 where 61 where
62 Self: 'a; 62 Self: 'a;
63 63
64 /// Returns a proximal mapping with weight τ 64 /// Returns a proximal mapping with weight τ
65 fn prox_mapping(&self, τ: Self::Codomain) -> Self::Prox<'_>; 65 fn prox_mapping(&self, τ: Self::Codomain) -> Self::Prox<'_>;
66 66
67 /// Calculate the proximal mapping with weight τ 67 /// Calculate the proximal mapping with weight τ
68 fn prox<I: Instance<Domain>>(&self, τ: Self::Codomain, z: I) -> Domain::OwnedSpace { 68 fn prox<I: Instance<Domain>>(&self, τ: Self::Codomain, z: I) -> Domain::Principal {
69 self.prox_mapping(τ).apply(z) 69 self.prox_mapping(τ).apply(z)
70 } 70 }
71 71
72 /// Calculate the proximal mapping with weight τ in-place 72 /// Calculate the proximal mapping with weight τ in-place
73 fn prox_mut<'b>(&self, τ: Self::Codomain, y: &'b mut Domain::OwnedSpace) 73 fn prox_mut<'b>(&self, τ: Self::Codomain, y: &'b mut Domain::Principal)
74 where 74 where
75 Domain::Decomp: DecompositionMut<Domain>, 75 Domain::Decomp: DecompositionMut<Domain>,
76 for<'a> &'a Domain::OwnedSpace: Instance<Domain>, 76 for<'a> &'a Domain::Principal: Instance<Domain>,
77 { 77 {
78 *y = self.prox(τ, &*y); 78 *y = self.prox(τ, &*y);
79 } 79 }
80 } 80 }
81 81
96 } 96 }
97 97
98 impl<F, E, Domain> Mapping<Domain> for NormConstraint<F, E> 98 impl<F, E, Domain> Mapping<Domain> for NormConstraint<F, E>
99 where 99 where
100 Domain: Space, 100 Domain: Space,
101 Domain::OwnedSpace: Norm<E, F>, 101 Domain::Principal: Norm<E, F>,
102 F: Float, 102 F: Float,
103 E: NormExponent, 103 E: NormExponent,
104 { 104 {
105 type Codomain = F; 105 type Codomain = F;
106 106
125 impl<E, F, Domain> Conjugable<Domain, F> for NormMapping<F, E> 125 impl<E, F, Domain> Conjugable<Domain, F> for NormMapping<F, E>
126 where 126 where
127 E: HasDualExponent, 127 E: HasDualExponent,
128 F: Float, 128 F: Float,
129 Domain: HasDual<F>, 129 Domain: HasDual<F>,
130 Domain::OwnedSpace: Norm<E, F>, 130 Domain::Principal: Norm<E, F>,
131 <Domain as HasDual<F>>::DualSpace: Norm<E::DualExp, F>, 131 <Domain as HasDual<F>>::DualSpace: Norm<E::DualExp, F>,
132 { 132 {
133 type Conjugate<'a> 133 type Conjugate<'a>
134 = NormConstraint<F, E::DualExp> 134 = NormConstraint<F, E::DualExp>
135 where 135 where
144 where 144 where
145 C: Constant<Type = F>, 145 C: Constant<Type = F>,
146 E: HasDualExponent, 146 E: HasDualExponent,
147 F: Float, 147 F: Float,
148 Domain: HasDual<F>, 148 Domain: HasDual<F>,
149 Domain::OwnedSpace: Norm<E, F>, 149 Domain::Principal: Norm<E, F>,
150 <Domain as HasDual<F>>::DualSpace: Norm<E::DualExp, F>, 150 <Domain as HasDual<F>>::DualSpace: Norm<E::DualExp, F>,
151 { 151 {
152 type Conjugate<'a> 152 type Conjugate<'a>
153 = NormConstraint<F, E::DualExp> 153 = NormConstraint<F, E::DualExp>
154 where 154 where
163 } 163 }
164 164
165 impl<Domain, E, F> Prox<Domain> for NormConstraint<F, E> 165 impl<Domain, E, F> Prox<Domain> for NormConstraint<F, E>
166 where 166 where
167 Domain: Space, 167 Domain: Space,
168 Domain::OwnedSpace: Norm<E, F>, 168 Domain::Principal: Norm<E, F>,
169 E: NormExponent, 169 E: NormExponent,
170 F: Float, 170 F: Float,
171 NormProjection<F, E>: Mapping<Domain, Codomain = Domain::OwnedSpace>, 171 NormProjection<F, E>: Mapping<Domain, Codomain = Domain::Principal>,
172 { 172 {
173 type Prox<'a> 173 type Prox<'a>
174 = NormProjection<F, E> 174 = NormProjection<F, E>
175 where 175 where
176 Self: 'a; 176 Self: 'a;
204 */ 204 */
205 205
206 impl<F, E, Domain> Mapping<Domain> for NormProjection<F, E> 206 impl<F, E, Domain> Mapping<Domain> for NormProjection<F, E>
207 where 207 where
208 Domain: Space, 208 Domain: Space,
209 Domain::OwnedSpace: ClosedSpace + Projection<F, E>, 209 Domain::Principal: ClosedSpace + Projection<F, E>,
210 F: Float, 210 F: Float,
211 E: NormExponent, 211 E: NormExponent,
212 { 212 {
213 type Codomain = Domain::OwnedSpace; 213 type Codomain = Domain::Principal;
214 214
215 fn apply<I: Instance<Domain>>(&self, d: I) -> Self::Codomain { 215 fn apply<I: Instance<Domain>>(&self, d: I) -> Self::Codomain {
216 d.own().proj_ball(self.radius, self.exponent) 216 d.own().proj_ball(self.radius, self.exponent)
217 } 217 }
218 } 218 }
251 } 251 }
252 252
253 impl<Domain, Predual, F: Float> Preconjugable<Domain, Predual, F> for Zero<Domain, F> 253 impl<Domain, Predual, F: Float> Preconjugable<Domain, Predual, F> for Zero<Domain, F>
254 where 254 where
255 Domain: Normed<F>, 255 Domain: Normed<F>,
256 Predual: HasDual<F, Owned = Predual>, 256 Predual: HasDual<F, PrincipalV = Predual>,
257 { 257 {
258 type Preconjugate<'a> 258 type Preconjugate<'a>
259 = ZeroIndicator<Predual, F> 259 = ZeroIndicator<Predual, F>
260 where 260 where
261 Self: 'a; 261 Self: 'a;
290 290
291 impl<Domain, F> Mapping<Domain> for ZeroIndicator<Domain, F> 291 impl<Domain, F> Mapping<Domain> for ZeroIndicator<Domain, F>
292 where 292 where
293 F: Float, 293 F: Float,
294 Domain: Space, 294 Domain: Space,
295 Domain::OwnedSpace: Normed<F>, 295 Domain::Principal: Normed<F>,
296 { 296 {
297 type Codomain = F; 297 type Codomain = F;
298 298
299 /// Compute the value of `self` at `x`. 299 /// Compute the value of `self` at `x`.
300 fn apply<I: Instance<Domain>>(&self, x: I) -> Self::Codomain { 300 fn apply<I: Instance<Domain>>(&self, x: I) -> Self::Codomain {
303 } 303 }
304 304
305 impl<Domain, F: Float> ConvexMapping<Domain, F> for ZeroIndicator<Domain, F> 305 impl<Domain, F: Float> ConvexMapping<Domain, F> for ZeroIndicator<Domain, F>
306 where 306 where
307 Domain: Space, 307 Domain: Space,
308 Domain::OwnedSpace: Normed<F>, 308 Domain::Principal: Normed<F>,
309 { 309 {
310 fn factor_of_strong_convexity(&self) -> F { 310 fn factor_of_strong_convexity(&self) -> F {
311 F::INFINITY 311 F::INFINITY
312 } 312 }
313 } 313 }
314 314
315 impl<Domain, F: Float> Conjugable<Domain, F> for ZeroIndicator<Domain, F> 315 impl<Domain, F: Float> Conjugable<Domain, F> for ZeroIndicator<Domain, F>
316 where 316 where
317 Domain: HasDual<F>, 317 Domain: HasDual<F>,
318 Domain::Owned: Normed<F>, 318 Domain::PrincipalV: Normed<F>,
319 { 319 {
320 type Conjugate<'a> 320 type Conjugate<'a>
321 = Zero<Domain::DualSpace, F> 321 = Zero<Domain::DualSpace, F>
322 where 322 where
323 Self: 'a; 323 Self: 'a;
329 } 329 }
330 330
331 impl<Domain, Predual, F: Float> Preconjugable<Domain, Predual, F> for ZeroIndicator<Domain, F> 331 impl<Domain, Predual, F: Float> Preconjugable<Domain, Predual, F> for ZeroIndicator<Domain, F>
332 where 332 where
333 Domain: Space, 333 Domain: Space,
334 Domain::OwnedSpace: Normed<F>, 334 Domain::Principal: Normed<F>,
335 Predual: HasDual<F>, 335 Predual: HasDual<F>,
336 { 336 {
337 type Preconjugate<'a> 337 type Preconjugate<'a>
338 = Zero<Predual, F> 338 = Zero<Predual, F>
339 where 339 where
345 } 345 }
346 } 346 }
347 347
348 impl<Domain, F> Prox<Domain> for ZeroIndicator<Domain, F> 348 impl<Domain, F> Prox<Domain> for ZeroIndicator<Domain, F>
349 where 349 where
350 Domain: AXPY<Field = F, Owned = Domain> + Normed<F>, 350 Domain: AXPY<Field = F, PrincipalV = Domain> + Normed<F>,
351 F: Float, 351 F: Float,
352 { 352 {
353 type Prox<'a> 353 type Prox<'a>
354 = SimpleZeroOp 354 = SimpleZeroOp
355 where 355 where
428 impl<X, F> DifferentiableImpl<X> for Norm222<F> 428 impl<X, F> DifferentiableImpl<X> for Norm222<F>
429 where 429 where
430 F: Float, 430 F: Float,
431 X: Euclidean<F>, 431 X: Euclidean<F>,
432 { 432 {
433 type Derivative = X::Owned; 433 type Derivative = X::PrincipalV;
434 434
435 fn differential_impl<I: Instance<X>>(&self, x: I) -> Self::Derivative { 435 fn differential_impl<I: Instance<X>>(&self, x: I) -> Self::Derivative {
436 x.into_owned() 436 x.into_owned()
437 } 437 }
438 } 438 }

mercurial