src/convex.rs

branch
dev
changeset 131
8264d72aa347
parent 129
d2994e34a5f5
equal deleted inserted replaced
130:0a689881b0f1 131:8264d72aa347
357 pub fn new() -> Self { 357 pub fn new() -> Self {
358 Norm222(PhantomData) 358 Norm222(PhantomData)
359 } 359 }
360 } 360 }
361 361
362 impl<X: Euclidean<F>, F: Float> Mapping<X> for Norm222<F> { 362 impl<X: Euclidean<Field = F>, F: Float> Mapping<X> for Norm222<F> {
363 type Codomain = F; 363 type Codomain = F;
364 364
365 /// Compute the value of `self` at `x`. 365 /// Compute the value of `self` at `x`.
366 fn apply<I: Instance<X>>(&self, x: I) -> Self::Codomain { 366 fn apply<I: Instance<X>>(&self, x: I) -> Self::Codomain {
367 x.eval(|z| z.norm2_squared() / F::TWO) 367 x.eval(|z| z.norm2_squared() / F::TWO)
368 } 368 }
369 } 369 }
370 370
371 impl<X: Euclidean<F>, F: Float> ConvexMapping<X, F> for Norm222<F> { 371 impl<X: Euclidean<Field = F>, F: Float> ConvexMapping<X, F> for Norm222<F> {
372 fn factor_of_strong_convexity(&self) -> F { 372 fn factor_of_strong_convexity(&self) -> F {
373 F::ONE 373 F::ONE
374 } 374 }
375 } 375 }
376 376
377 impl<X: Euclidean<F>, F: Float> Conjugable<X, F> for Norm222<F> { 377 impl<X: Euclidean<Field = F>, F: Float> Conjugable<X, F> for Norm222<F> {
378 type Conjugate<'a> 378 type Conjugate<'a>
379 = Self 379 = Self
380 where 380 where
381 Self: 'a; 381 Self: 'a;
382 382
384 fn conjugate(&self) -> Self::Conjugate<'_> { 384 fn conjugate(&self) -> Self::Conjugate<'_> {
385 Self::new() 385 Self::new()
386 } 386 }
387 } 387 }
388 388
389 impl<X: Euclidean<F>, F: Float> Preconjugable<X, X, F> for Norm222<F> { 389 impl<X: Euclidean<Field = F>, F: Float> Preconjugable<X, X, F> for Norm222<F> {
390 type Preconjugate<'a> 390 type Preconjugate<'a>
391 = Self 391 = Self
392 where 392 where
393 Self: 'a; 393 Self: 'a;
394 394
399 } 399 }
400 400
401 impl<X, F> Prox<X> for Norm222<F> 401 impl<X, F> Prox<X> for Norm222<F>
402 where 402 where
403 F: Float, 403 F: Float,
404 X: Euclidean<F, Output = X>, 404 X: Euclidean<Field = F, Output = X>,
405 { 405 {
406 type Prox<'a> 406 type Prox<'a>
407 = Scaled<F> 407 = Scaled<F>
408 where 408 where
409 Self: 'a; 409 Self: 'a;
414 } 414 }
415 415
416 impl<X, F> DifferentiableImpl<X> for Norm222<F> 416 impl<X, F> DifferentiableImpl<X> for Norm222<F>
417 where 417 where
418 F: Float, 418 F: Float,
419 X: Euclidean<F, Output = X>, 419 X: Euclidean<Field = F, Output = X>,
420 { 420 {
421 type Derivative = X; 421 type Derivative = X;
422 422
423 fn differential_impl<I: Instance<X>>(&self, x: I) -> X { 423 fn differential_impl<I: Instance<X>>(&self, x: I) -> X {
424 x.own() 424 x.own()
426 } 426 }
427 427
428 impl<X, F> LipschitzDifferentiableImpl<X, L2> for Norm222<F> 428 impl<X, F> LipschitzDifferentiableImpl<X, L2> for Norm222<F>
429 where 429 where
430 F: Float, 430 F: Float,
431 X: Euclidean<F, Output = X>, 431 X: Euclidean<Field = F, Output = X>,
432 { 432 {
433 type FloatType = F; 433 type FloatType = F;
434 434
435 fn diff_lipschitz_factor(&self, _: L2) -> DynResult<Self::FloatType> { 435 fn diff_lipschitz_factor(&self, _: L2) -> DynResult<Self::FloatType> {
436 Ok(F::ONE) 436 Ok(F::ONE)

mercurial