| 22 ProxPenalty, ProxTerm, RadonSquared, StepLengthBound, StepLengthBoundPD, StepLengthBoundPair, |
22 ProxPenalty, ProxTerm, RadonSquared, StepLengthBound, StepLengthBoundPD, StepLengthBoundPair, |
| 23 }; |
23 }; |
| 24 use crate::regularisation::{NonnegRadonRegTerm, RadonRegTerm, Regularisation, SlidingRegTerm}; |
24 use crate::regularisation::{NonnegRadonRegTerm, RadonRegTerm, Regularisation, SlidingRegTerm}; |
| 25 use crate::seminorms::*; |
25 use crate::seminorms::*; |
| 26 use crate::sliding_fb::{ |
26 use crate::sliding_fb::{ |
| 27 pointsource_sliding_fb_reg, SlidingFBConfig, TransportConfig, TransportProxPenalty, |
27 pointsource_sliding_fb_dom, SlidingFBConfig, TransportConfig, TransportProxPenalty, |
| 28 }; |
28 }; |
| 29 use crate::sliding_pdps::{ |
29 use crate::sliding_pdps::{ |
| 30 pointsource_sliding_fb_pair, pointsource_sliding_pdps_pair, SlidingPDPSConfig, |
30 pointsource_sliding_fb_pair_dom, pointsource_sliding_pdps_pair_dom, SlidingPDPSConfig, |
| 31 }; |
31 }; |
| 32 use crate::subproblem::{InnerMethod, InnerSettings}; |
32 use crate::subproblem::{InnerMethod, InnerSettings}; |
| 33 use crate::tolerance::Tolerance; |
33 use crate::tolerance::Tolerance; |
| 34 use crate::types::*; |
34 use crate::types::*; |
| 35 use crate::{AlgorithmOverrides, CommandLineArgs}; |
35 use crate::{AlgorithmOverrides, CommandLineArgs}; |
| 1009 RNDM<N, F>: SpikeMerging<F>, |
1009 RNDM<N, F>: SpikeMerging<F>, |
| 1010 Reg: SlidingRegTerm<Loc<N, F>, F>, |
1010 Reg: SlidingRegTerm<Loc<N, F>, F>, |
| 1011 P: TransportProxPenalty<Loc<N, F>, Dat::DerivativeDomain, Reg, F> + StepLengthBound<F, Dat>, |
1011 P: TransportProxPenalty<Loc<N, F>, Dat::DerivativeDomain, Reg, F> + StepLengthBound<F, Dat>, |
| 1012 Plot: Plotter<P::ReturnMapping, Dat::DerivativeDomain, RNDM<N, F>>, |
1012 Plot: Plotter<P::ReturnMapping, Dat::DerivativeDomain, RNDM<N, F>>, |
| 1013 { |
1013 { |
| |
1014 run_fb_dom(f, reg, prox_penalty, init, None, cont) |
| |
1015 } |
| |
1016 |
| |
1017 /// Runs FB-style algorithms if `alg` so requests and `prox_penalty` matches. |
| |
1018 /// |
| |
1019 /// `cont` gives a continuation attempt to find the algorithm matching the description `alg`. |
| |
1020 pub fn run_fb_dom<F, Dat, Reg, P, I, Plot, const N: usize>( |
| |
1021 f: &Dat, |
| |
1022 reg: &Reg, |
| |
1023 prox_penalty: &P, |
| |
1024 (alg, iterator, plotter, μ0, running): ( |
| |
1025 &AlgorithmConfig<F>, |
| |
1026 I, |
| |
1027 Plot, |
| |
1028 Option<RNDM<N, F>>, |
| |
1029 String, |
| |
1030 ), |
| |
1031 domain: Option<&P::Dom>, |
| |
1032 cont: impl FnOnce( |
| |
1033 (&AlgorithmConfig<F>, I, Plot, Option<RNDM<N, F>>, String), |
| |
1034 ) -> DynResult<RNDM<N, F>>, |
| |
1035 ) -> DynResult<RNDM<N, F>> |
| |
1036 where |
| |
1037 F: Float + ToNalgebraRealField, |
| |
1038 I: AlgIteratorFactory<IterInfo<F>>, |
| |
1039 Dat: DifferentiableMapping<RNDM<N, F>, Codomain = F> + BoundedCurvature<F>, |
| |
1040 Dat::DerivativeDomain: |
| |
1041 DifferentiableRealMapping<N, F> + ClosedMul<F> + MinMaxMapping<Loc<N, F>, F>, |
| |
1042 RNDM<N, F>: SpikeMerging<F>, |
| |
1043 Reg: SlidingRegTerm<Loc<N, F>, F>, |
| |
1044 P: TransportProxPenalty<Loc<N, F>, Dat::DerivativeDomain, Reg, F> + StepLengthBound<F, Dat>, |
| |
1045 Plot: Plotter<P::ReturnMapping, Dat::DerivativeDomain, RNDM<N, F>>, |
| |
1046 { |
| 1014 let pt = P::prox_type(); |
1047 let pt = P::prox_type(); |
| 1015 |
1048 |
| 1016 match alg { |
1049 match alg { |
| 1017 &AlgorithmConfig::FB(ref algconfig, prox_type) if prox_type == pt => { |
1050 &AlgorithmConfig::FB(ref algconfig, prox_type) if prox_type == pt => { |
| 1018 print!("{running}"); |
1051 print!("{running}"); |
| 1022 print!("{running}"); |
1055 print!("{running}"); |
| 1023 pointsource_fista_reg(f, reg, prox_penalty, algconfig, iterator, plotter, μ0) |
1056 pointsource_fista_reg(f, reg, prox_penalty, algconfig, iterator, plotter, μ0) |
| 1024 } |
1057 } |
| 1025 &AlgorithmConfig::SlidingFB(ref algconfig, prox_type) if prox_type == pt => { |
1058 &AlgorithmConfig::SlidingFB(ref algconfig, prox_type) if prox_type == pt => { |
| 1026 print!("{running}"); |
1059 print!("{running}"); |
| 1027 pointsource_sliding_fb_reg(f, reg, prox_penalty, algconfig, iterator, plotter, μ0) |
1060 pointsource_sliding_fb_dom(f, reg, prox_penalty, algconfig, iterator, plotter, μ0, domain) |
| 1028 } |
1061 } |
| 1029 _ => cont((alg, iterator, plotter, μ0, running)), |
1062 _ => cont((alg, iterator, plotter, μ0, running)), |
| 1030 } |
1063 } |
| 1031 } |
1064 } |
| 1032 |
1065 |
| 1259 algorithms, |
1292 algorithms, |
| 1260 make_plotter, |
1293 make_plotter, |
| 1261 save_extra, |
1294 save_extra, |
| 1262 (μ0, z, y), |
1295 (μ0, z, y), |
| 1263 |p| { |
1296 |p| { |
| 1264 run_pdps_pair(&f, ®, &RadonSquared, &opKz, &fnR, &fnH, p, |q| { |
1297 run_pdps_pair_dom(&f, ®, &RadonSquared, &opKz, &fnR, &fnH, p, None, |q| { |
| 1265 run_pdps_pair(&f, ®, &op𝒟, &opKz, &fnR, &fnH, q, |_| { |
1298 run_pdps_pair_dom(&f, ®, &op𝒟, &opKz, &fnR, &fnH, q, None, |_| { |
| 1266 Err(NotImplemented.into()) |
1299 Err(NotImplemented.into()) |
| 1267 }) |
1300 }) |
| 1268 }) |
1301 }) |
| 1269 .map(|Pair(μ, z)| (μ, z)) |
1302 .map(|Pair(μ, z)| (μ, z)) |
| 1270 }, |
1303 }, |
| 1279 algorithms, |
1312 algorithms, |
| 1280 make_plotter, |
1313 make_plotter, |
| 1281 save_extra, |
1314 save_extra, |
| 1282 (μ0, z, y), |
1315 (μ0, z, y), |
| 1283 |p| { |
1316 |p| { |
| 1284 run_pdps_pair(&f, ®, &RadonSquared, &opKz, &fnR, &fnH, p, |q| { |
1317 run_pdps_pair_dom(&f, ®, &RadonSquared, &opKz, &fnR, &fnH, p, None, |q| { |
| 1285 run_pdps_pair(&f, ®, &op𝒟, &opKz, &fnR, &fnH, q, |_| { |
1318 run_pdps_pair_dom(&f, ®, &op𝒟, &opKz, &fnR, &fnH, q, None, |_| { |
| 1286 Err(NotImplemented.into()) |
1319 Err(NotImplemented.into()) |
| 1287 }) |
1320 }) |
| 1288 }) |
1321 }) |
| 1289 .map(|Pair(μ, z)| (μ, z)) |
1322 .map(|Pair(μ, z)| (μ, z)) |
| 1290 }, |
1323 }, |
| 1295 } |
1328 } |
| 1296 } |
1329 } |
| 1297 |
1330 |
| 1298 type MeasureZ<F, Z, const N: usize> = Pair<RNDM<N, F>, Z>; |
1331 type MeasureZ<F, Z, const N: usize> = Pair<RNDM<N, F>, Z>; |
| 1299 |
1332 |
| |
1333 #[deprecated] |
| 1300 pub fn run_pdps_pair<F, S, Dat, Reg, Z, R, Y, KOpZ, H, P, I, Plot, const N: usize>( |
1334 pub fn run_pdps_pair<F, S, Dat, Reg, Z, R, Y, KOpZ, H, P, I, Plot, const N: usize>( |
| 1301 f: &Dat, |
1335 f: &Dat, |
| 1302 reg: &Reg, |
1336 reg: &Reg, |
| 1303 prox_penalty: &P, |
1337 prox_penalty: &P, |
| 1304 opKz: &KOpZ, |
1338 opKz: &KOpZ, |
| 1305 fnR: &R, |
1339 fnR: &R, |
| 1306 fnH: &H, |
1340 fnH: &H, |
| 1307 (alg, iterator, plotter, μ0zy, running): ( |
1341 init: ( |
| 1308 &AlgorithmConfig<F>, |
1342 &AlgorithmConfig<F>, |
| 1309 I, |
1343 I, |
| 1310 Plot, |
1344 Plot, |
| 1311 (Option<RNDM<N, F>>, Z, Y), |
1345 (Option<RNDM<N, F>>, Z, Y), |
| 1312 String, |
1346 String, |
| 1343 R: Prox<Z, Codomain = F>, |
1377 R: Prox<Z, Codomain = F>, |
| 1344 H: Conjugable<Y, F, Codomain = F>, |
1378 H: Conjugable<Y, F, Codomain = F>, |
| 1345 for<'b> H::Conjugate<'b>: Prox<Y>, |
1379 for<'b> H::Conjugate<'b>: Prox<Y>, |
| 1346 Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>, |
1380 Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>, |
| 1347 { |
1381 { |
| |
1382 run_pdps_pair_dom(f, reg, prox_penalty, opKz, fnR, fnH, init, None, cont) |
| |
1383 } |
| |
1384 |
| |
1385 pub fn run_pdps_pair_dom<F, S, Dat, Reg, Z, R, Y, KOpZ, H, P, I, Plot, const N: usize>( |
| |
1386 f: &Dat, |
| |
1387 reg: &Reg, |
| |
1388 prox_penalty: &P, |
| |
1389 opKz: &KOpZ, |
| |
1390 fnR: &R, |
| |
1391 fnH: &H, |
| |
1392 (alg, iterator, plotter, μ0zy, running): ( |
| |
1393 &AlgorithmConfig<F>, |
| |
1394 I, |
| |
1395 Plot, |
| |
1396 (Option<RNDM<N, F>>, Z, Y), |
| |
1397 String, |
| |
1398 ), |
| |
1399 domain: Option<&P::Dom>, |
| |
1400 cont: impl FnOnce( |
| |
1401 ( |
| |
1402 &AlgorithmConfig<F>, |
| |
1403 I, |
| |
1404 Plot, |
| |
1405 (Option<RNDM<N, F>>, Z, Y), |
| |
1406 String, |
| |
1407 ), |
| |
1408 ) -> DynResult<Pair<RNDM<N, F>, Z>>, |
| |
1409 ) -> DynResult<Pair<RNDM<N, F>, Z>> |
| |
1410 where |
| |
1411 F: Float + ToNalgebraRealField, |
| |
1412 I: AlgIteratorFactory<IterInfo<F>>, |
| |
1413 Dat: DifferentiableMapping<MeasureZ<F, Z, N>, Codomain = F, DerivativeDomain = Pair<S, Z>> |
| |
1414 + BoundedCurvature<F>, |
| |
1415 S: DifferentiableRealMapping<N, F> + ClosedMul<F> + MinMaxMapping<Loc<N, F>, F>, |
| |
1416 for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
| |
1417 //Pair<S, Z>: ClosedMul<F>, |
| |
1418 RNDM<N, F>: SpikeMerging<F>, |
| |
1419 Reg: SlidingRegTerm<Loc<N, F>, F>, |
| |
1420 P: TransportProxPenalty<Loc<N, F>, S, Reg, F>, |
| |
1421 KOpZ: BoundedLinear<Z, L2, L2, F, Codomain = Y> |
| |
1422 + GEMV<F, Z> |
| |
1423 + SimplyAdjointable<Z, Y, AdjointCodomain = Z>, |
| |
1424 KOpZ::SimpleAdjoint: GEMV<F, Y>, |
| |
1425 Y: ClosedEuclidean<F> + Clone, |
| |
1426 for<'b> &'b Y: Instance<Y>, |
| |
1427 Z: ClosedEuclidean<F> + Clone + ClosedMul<F> + AXPY, |
| |
1428 for<'b> &'b Z: Instance<Z>, |
| |
1429 R: Prox<Z, Codomain = F>, |
| |
1430 H: Conjugable<Y, F, Codomain = F>, |
| |
1431 for<'b> H::Conjugate<'b>: Prox<Y>, |
| |
1432 Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>, |
| |
1433 { |
| 1348 let pt = P::prox_type(); |
1434 let pt = P::prox_type(); |
| 1349 |
1435 |
| 1350 match alg { |
1436 match alg { |
| 1351 &AlgorithmConfig::ForwardPDPS(ref algconfig, prox_type) if prox_type == pt => { |
1437 &AlgorithmConfig::ForwardPDPS(ref algconfig, prox_type) if prox_type == pt => { |
| 1352 print!("{running}"); |
1438 print!("{running}"); |
| 1419 R: Prox<Z, Codomain = F>, |
1506 R: Prox<Z, Codomain = F>, |
| 1420 Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>, |
1507 Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>, |
| 1421 // We should not need to explicitly require this: |
1508 // We should not need to explicitly require this: |
| 1422 for<'b> &'b Loc<0, F>: Instance<Loc<0, F>>, |
1509 for<'b> &'b Loc<0, F>: Instance<Loc<0, F>>, |
| 1423 { |
1510 { |
| |
1511 run_fb_pair_dom(f, reg, prox_penalty, fnR, init, None, cont) |
| |
1512 } |
| |
1513 |
| |
1514 pub fn run_fb_pair_dom<F, S, Dat, Reg, Z, R, P, I, Plot, const N: usize>( |
| |
1515 f: &Dat, |
| |
1516 reg: &Reg, |
| |
1517 prox_penalty: &P, |
| |
1518 fnR: &R, |
| |
1519 (alg, iterator, plotter, μ0z, running): ( |
| |
1520 &AlgorithmConfig<F>, |
| |
1521 I, |
| |
1522 Plot, |
| |
1523 (Option<RNDM<N, F>>, Z), |
| |
1524 String, |
| |
1525 ), |
| |
1526 domain: Option<&P::Dom>, |
| |
1527 cont: impl FnOnce( |
| |
1528 ( |
| |
1529 &AlgorithmConfig<F>, |
| |
1530 I, |
| |
1531 Plot, |
| |
1532 (Option<RNDM<N, F>>, Z), |
| |
1533 String, |
| |
1534 ), |
| |
1535 ) -> DynResult<Pair<RNDM<N, F>, Z>>, |
| |
1536 ) -> DynResult<Pair<RNDM<N, F>, Z>> |
| |
1537 where |
| |
1538 F: Float + ToNalgebraRealField, |
| |
1539 I: AlgIteratorFactory<IterInfo<F>>, |
| |
1540 Dat: DifferentiableMapping<MeasureZ<F, Z, N>, Codomain = F, DerivativeDomain = Pair<S, Z>> |
| |
1541 + BoundedCurvature<F>, |
| |
1542 S: DifferentiableRealMapping<N, F> + ClosedMul<F> + MinMaxMapping<Loc<N, F>, F>, |
| |
1543 RNDM<N, F>: SpikeMerging<F>, |
| |
1544 Reg: SlidingRegTerm<Loc<N, F>, F>, |
| |
1545 P: TransportProxPenalty<Loc<N, F>, S, Reg, F>, |
| |
1546 for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
| |
1547 Z: ClosedEuclidean<F> + AXPY + Clone, |
| |
1548 for<'b> &'b Z: Instance<Z>, |
| |
1549 R: Prox<Z, Codomain = F>, |
| |
1550 Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>, |
| |
1551 // We should not need to explicitly require this: |
| |
1552 for<'b> &'b Loc<0, F>: Instance<Loc<0, F>>, |
| |
1553 { |
| 1424 let pt = P::prox_type(); |
1554 let pt = P::prox_type(); |
| 1425 |
1555 |
| 1426 match alg { |
1556 match alg { |
| 1427 &AlgorithmConfig::FB(ref algconfig, prox_type) if prox_type == pt => { |
1557 &AlgorithmConfig::FB(ref algconfig, prox_type) if prox_type == pt => { |
| 1428 print!("{running}"); |
1558 print!("{running}"); |
| 1429 pointsource_fb_pair(f, reg, prox_penalty, algconfig, iterator, plotter, μ0z, fnR) |
1559 pointsource_fb_pair(f, reg, prox_penalty, algconfig, iterator, plotter, μ0z, fnR) |
| 1430 } |
1560 } |
| 1431 &AlgorithmConfig::SlidingFB(ref algconfig, prox_type) if prox_type == pt => { |
1561 &AlgorithmConfig::SlidingFB(ref algconfig, prox_type) if prox_type == pt => { |
| 1432 print!("{running}"); |
1562 print!("{running}"); |
| 1433 pointsource_sliding_fb_pair( |
1563 pointsource_sliding_fb_pair_dom( |
| 1434 f, |
1564 f, |
| 1435 reg, |
1565 reg, |
| 1436 prox_penalty, |
1566 prox_penalty, |
| 1437 algconfig, |
1567 algconfig, |
| 1438 iterator, |
1568 iterator, |
| 1439 plotter, |
1569 plotter, |
| 1440 μ0z, |
1570 μ0z, |
| 1441 fnR, |
1571 fnR, |
| |
1572 domain |
| 1442 ) |
1573 ) |
| 1443 } |
1574 } |
| 1444 _ => cont((alg, iterator, plotter, μ0z, running)), |
1575 _ => cont((alg, iterator, plotter, μ0z, running)), |
| 1445 } |
1576 } |
| 1446 } |
1577 } |