| 1084 /// |
1084 /// |
| 1085 /// For the moment, due to restrictions of the Frank–Wolfe implementation, only the |
1085 /// For the moment, due to restrictions of the Frank–Wolfe implementation, only the |
| 1086 /// $L^2$-squared data term is enabled through the type signatures. |
1086 /// $L^2$-squared data term is enabled through the type signatures. |
| 1087 /// |
1087 /// |
| 1088 /// `cont` gives a continuation attempt to find the algorithm matching the description `alg`. |
1088 /// `cont` gives a continuation attempt to find the algorithm matching the description `alg`. |
| 1089 pub fn run_fw<'a, F, A, Reg, I, Plot, const N: usize>( |
1089 pub fn run_fw<'a, F, U, A, Reg, I, Plot>( |
| 1090 f: &'a DataTerm<F, RNDM<N, F>, A, Norm222<F>>, |
1090 f: &'a DataTerm<F, DiscreteMeasure<U, F>, A, Norm222<F>>, |
| 1091 reg: &Reg, |
1091 reg: &Reg, |
| 1092 (alg, iterator, plotter, μ0, running): ( |
1092 (alg, iterator, plotter, μ0, running): ( |
| 1093 &AlgorithmConfig<F>, |
1093 &AlgorithmConfig<F>, |
| 1094 I, |
1094 I, |
| 1095 Plot, |
1095 Plot, |
| 1096 Option<RNDM<N, F>>, |
1096 Option<DiscreteMeasure<U, F>>, |
| 1097 String, |
1097 String, |
| 1098 ), |
1098 ), |
| 1099 cont: impl FnOnce( |
1099 cont: impl FnOnce( |
| 1100 (&AlgorithmConfig<F>, I, Plot, Option<RNDM<N, F>>, String), |
1100 ( |
| 1101 ) -> DynResult<RNDM<N, F>>, |
1101 &AlgorithmConfig<F>, |
| 1102 ) -> DynResult<RNDM<N, F>> |
1102 I, |
| |
1103 Plot, |
| |
1104 Option<DiscreteMeasure<U, F>>, |
| |
1105 String, |
| |
1106 ), |
| |
1107 ) -> DynResult<DiscreteMeasure<U, F>>, |
| |
1108 ) -> DynResult<DiscreteMeasure<U, F>> |
| 1103 where |
1109 where |
| 1104 F: Float + ToNalgebraRealField, |
1110 F: Float + ToNalgebraRealField, |
| |
1111 U: Space + Clone + PartialEq, |
| 1105 I: AlgIteratorFactory<IterInfo<F>>, |
1112 I: AlgIteratorFactory<IterInfo<F>>, |
| 1106 A: ForwardModel<RNDM<N, F>, F>, |
1113 A: ForwardModel<DiscreteMeasure<U, F>, F>, |
| 1107 A::PreadjointCodomain: MinMaxMapping<Loc<N, F>, F>, |
1114 A::PreadjointCodomain: MinMaxMapping<U, F>, |
| 1108 for<'b> &'b A::PreadjointCodomain: Instance<A::PreadjointCodomain>, |
1115 for<'b> &'b A::PreadjointCodomain: Instance<A::PreadjointCodomain>, |
| 1109 Cube<N, F>: P2Minimise<Loc<N, F>, F>, |
1116 DiscreteMeasure<U, F>: SpikeMerging<F>, |
| 1110 RNDM<N, F>: SpikeMerging<F>, |
1117 Reg: RegTermFW<F, U, A, ValueIteratorFactory<F, AlgIteratorOptions>>, |
| 1111 Reg: RegTermFW<F, A, ValueIteratorFactory<F, AlgIteratorOptions>, N>, |
1118 Plot: Plotter<A::PreadjointCodomain, A::PreadjointCodomain, DiscreteMeasure<U, F>>, |
| 1112 Plot: Plotter<A::PreadjointCodomain, A::PreadjointCodomain, RNDM<N, F>>, |
|
| 1113 { |
1119 { |
| 1114 match alg { |
1120 match alg { |
| 1115 &AlgorithmConfig::FW(ref algconfig) => { |
1121 &AlgorithmConfig::FW(ref algconfig) => { |
| 1116 print!("{running}"); |
1122 print!("{running}"); |
| 1117 pointsource_fw_reg(f, reg, algconfig, iterator, plotter, μ0) |
1123 pointsource_fw_reg(f, reg, algconfig, iterator, plotter, μ0) |
| 1379 _ => Err(NotImplemented.into()), |
1385 _ => Err(NotImplemented.into()), |
| 1380 } |
1386 } |
| 1381 } |
1387 } |
| 1382 } |
1388 } |
| 1383 |
1389 |
| 1384 type MeasureZ<F, Z, const N: usize> = Pair<RNDM<N, F>, Z>; |
1390 type MeasureZ<F, Z, U> = Pair<DiscreteMeasure<U, F>, Z>; |
| 1385 |
1391 |
| 1386 #[deprecated] |
1392 #[deprecated] |
| 1387 pub fn run_pdps_pair<F, S, Dat, Reg, Z, R, Y, KOpZ, H, P, I, Plot, const N: usize>( |
1393 pub fn run_pdps_pair<F, S, Dat, Reg, Z, R, Y, KOpZ, H, P, I, Plot, U>( |
| 1388 f: &Dat, |
1394 f: &Dat, |
| 1389 reg: &Reg, |
1395 reg: &Reg, |
| 1390 prox_penalty: &P, |
1396 prox_penalty: &P, |
| 1391 opKz: &KOpZ, |
1397 opKz: &KOpZ, |
| 1392 fnR: &R, |
1398 fnR: &R, |
| 1393 fnH: &H, |
1399 fnH: &H, |
| 1394 init: ( |
1400 init: ( |
| 1395 &AlgorithmConfig<F>, |
1401 &AlgorithmConfig<F>, |
| 1396 I, |
1402 I, |
| 1397 Plot, |
1403 Plot, |
| 1398 (Option<RNDM<N, F>>, Z, Y), |
1404 (Option<DiscreteMeasure<U, F>>, Z, Y), |
| 1399 String, |
1405 String, |
| 1400 ), |
1406 ), |
| 1401 cont: impl FnOnce( |
1407 cont: impl FnOnce( |
| 1402 ( |
1408 ( |
| 1403 &AlgorithmConfig<F>, |
1409 &AlgorithmConfig<F>, |
| 1404 I, |
1410 I, |
| 1405 Plot, |
1411 Plot, |
| 1406 (Option<RNDM<N, F>>, Z, Y), |
1412 (Option<DiscreteMeasure<U, F>>, Z, Y), |
| 1407 String, |
1413 String, |
| 1408 ), |
1414 ), |
| 1409 ) -> DynResult<Pair<RNDM<N, F>, Z>>, |
1415 ) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>>, |
| 1410 ) -> DynResult<Pair<RNDM<N, F>, Z>> |
1416 ) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>> |
| 1411 where |
1417 where |
| 1412 F: Float + ToNalgebraRealField, |
1418 F: Float + ToNalgebraRealField, |
| |
1419 U: Space + Clone + Dist<L2, F>, |
| |
1420 for<'a> &'a U: Instance<U>, |
| 1413 I: AlgIteratorFactory<IterInfo<F>>, |
1421 I: AlgIteratorFactory<IterInfo<F>>, |
| 1414 Dat: DifferentiableMapping<MeasureZ<F, Z, N>, Codomain = F, DerivativeDomain = Pair<S, Z>> |
1422 Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>> |
| 1415 + BoundedCurvature<F>, |
1423 + BoundedCurvature<F>, |
| 1416 S: DifferentiableRealMapping<N, F> + ClosedMul<F> + MinMaxMapping<Loc<N, F>, F>, |
1424 S: DifferentiableMapping<U, Codomain = F> + ClosedMul<F> + MinMaxMapping<U, F>, |
| 1417 for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
1425 for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
| 1418 //Pair<S, Z>: ClosedMul<F>, |
1426 //Pair<S, Z>: ClosedMul<F>, |
| 1419 RNDM<N, F>: SpikeMerging<F>, |
1427 DiscreteMeasure<U, F>: SpikeMerging<F>, |
| 1420 Reg: SlidingRegTerm<Loc<N, F>, F>, |
1428 Reg: SlidingRegTerm<U, F>, |
| 1421 P: TransportProxPenalty<Loc<N, F>, S, Reg, F>, |
1429 P: TransportProxPenalty<U, S, Reg, F>, |
| 1422 KOpZ: BoundedLinear<Z, L2, L2, F, Codomain = Y> |
1430 KOpZ: BoundedLinear<Z, L2, L2, F, Codomain = Y> |
| 1423 + GEMV<F, Z> |
1431 + GEMV<F, Z> |
| 1424 + SimplyAdjointable<Z, Y, AdjointCodomain = Z>, |
1432 + SimplyAdjointable<Z, Y, AdjointCodomain = Z>, |
| 1425 KOpZ::SimpleAdjoint: GEMV<F, Y>, |
1433 KOpZ::SimpleAdjoint: GEMV<F, Y>, |
| 1426 Y: ClosedEuclidean<F> + Clone, |
1434 Y: ClosedEuclidean<F> + Clone, |
| 1443 &mut FullSpace, |
1451 &mut FullSpace, |
| 1444 cont, |
1452 cont, |
| 1445 ) |
1453 ) |
| 1446 } |
1454 } |
| 1447 |
1455 |
| 1448 pub fn run_pdps_pair_dom<F, S, Dat, Reg, Z, R, Y, KOpZ, H, P, I, Plot, const N: usize>( |
1456 pub fn run_pdps_pair_dom<F, S, Dat, Reg, Z, R, Y, KOpZ, H, P, I, Plot, U>( |
| 1449 f: &Dat, |
1457 f: &Dat, |
| 1450 reg: &Reg, |
1458 reg: &Reg, |
| 1451 prox_penalty: &P, |
1459 prox_penalty: &P, |
| 1452 opKz: &KOpZ, |
1460 opKz: &KOpZ, |
| 1453 fnR: &R, |
1461 fnR: &R, |
| 1454 fnH: &H, |
1462 fnH: &H, |
| 1455 (alg, iterator, plotter, μ0zy, running): ( |
1463 (alg, iterator, plotter, μ0zy, running): ( |
| 1456 &AlgorithmConfig<F>, |
1464 &AlgorithmConfig<F>, |
| 1457 I, |
1465 I, |
| 1458 Plot, |
1466 Plot, |
| 1459 (Option<RNDM<N, F>>, Z, Y), |
1467 (Option<DiscreteMeasure<U, F>>, Z, Y), |
| 1460 String, |
1468 String, |
| 1461 ), |
1469 ), |
| 1462 domain: &mut impl AdmissibleDomain<Loc<N, F>>, |
1470 domain: &mut impl AdmissibleDomain<U>, |
| 1463 cont: impl FnOnce( |
1471 cont: impl FnOnce( |
| 1464 ( |
1472 ( |
| 1465 &AlgorithmConfig<F>, |
1473 &AlgorithmConfig<F>, |
| 1466 I, |
1474 I, |
| 1467 Plot, |
1475 Plot, |
| 1468 (Option<RNDM<N, F>>, Z, Y), |
1476 (Option<DiscreteMeasure<U, F>>, Z, Y), |
| 1469 String, |
1477 String, |
| 1470 ), |
1478 ), |
| 1471 ) -> DynResult<Pair<RNDM<N, F>, Z>>, |
1479 ) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>>, |
| 1472 ) -> DynResult<Pair<RNDM<N, F>, Z>> |
1480 ) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>> |
| 1473 where |
1481 where |
| 1474 F: Float + ToNalgebraRealField, |
1482 F: Float + ToNalgebraRealField, |
| |
1483 U: Space + Clone + Dist<L2, F>, |
| |
1484 for<'a> &'a U: Instance<U>, |
| 1475 I: AlgIteratorFactory<IterInfo<F>>, |
1485 I: AlgIteratorFactory<IterInfo<F>>, |
| 1476 Dat: DifferentiableMapping<MeasureZ<F, Z, N>, Codomain = F, DerivativeDomain = Pair<S, Z>> |
1486 Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>> |
| 1477 + BoundedCurvature<F>, |
1487 + BoundedCurvature<F>, |
| 1478 S: DifferentiableRealMapping<N, F> + ClosedMul<F> + MinMaxMapping<Loc<N, F>, F>, |
1488 S: DifferentiableMapping<U, Codomain = F> + ClosedMul<F> + MinMaxMapping<U, F>, |
| 1479 for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
1489 for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
| 1480 //Pair<S, Z>: ClosedMul<F>, |
1490 //Pair<S, Z>: ClosedMul<F>, |
| 1481 RNDM<N, F>: SpikeMerging<F>, |
1491 DiscreteMeasure<U, F>: SpikeMerging<F>, |
| 1482 Reg: SlidingRegTerm<Loc<N, F>, F>, |
1492 Reg: SlidingRegTerm<U, F>, |
| 1483 P: TransportProxPenalty<Loc<N, F>, S, Reg, F>, |
1493 P: TransportProxPenalty<U, S, Reg, F>, |
| 1484 KOpZ: BoundedLinear<Z, L2, L2, F, Codomain = Y> |
1494 KOpZ: BoundedLinear<Z, L2, L2, F, Codomain = Y> |
| 1485 + GEMV<F, Z> |
1495 + GEMV<F, Z> |
| 1486 + SimplyAdjointable<Z, Y, AdjointCodomain = Z>, |
1496 + SimplyAdjointable<Z, Y, AdjointCodomain = Z>, |
| 1487 KOpZ::SimpleAdjoint: GEMV<F, Y>, |
1497 KOpZ::SimpleAdjoint: GEMV<F, Y>, |
| 1488 Y: ClosedEuclidean<F> + Clone, |
1498 Y: ClosedEuclidean<F> + Clone, |
| 1531 } |
1541 } |
| 1532 _ => cont((alg, iterator, plotter, μ0zy, running)), |
1542 _ => cont((alg, iterator, plotter, μ0zy, running)), |
| 1533 } |
1543 } |
| 1534 } |
1544 } |
| 1535 |
1545 |
| 1536 pub fn run_fb_pair<F, S, Dat, Reg, Z, R, P, I, Plot, const N: usize>( |
1546 pub fn run_fb_pair<F, S, Dat, Reg, Z, R, P, I, Plot, U>( |
| 1537 f: &Dat, |
1547 f: &Dat, |
| 1538 reg: &Reg, |
1548 reg: &Reg, |
| 1539 prox_penalty: &P, |
1549 prox_penalty: &P, |
| 1540 fnR: &R, |
1550 fnR: &R, |
| 1541 init: ( |
1551 init: ( |
| 1542 &AlgorithmConfig<F>, |
1552 &AlgorithmConfig<F>, |
| 1543 I, |
1553 I, |
| 1544 Plot, |
1554 Plot, |
| 1545 (Option<RNDM<N, F>>, Z), |
1555 (Option<DiscreteMeasure<U, F>>, Z), |
| 1546 String, |
1556 String, |
| 1547 ), |
1557 ), |
| 1548 cont: impl FnOnce( |
1558 cont: impl FnOnce( |
| 1549 ( |
1559 ( |
| 1550 &AlgorithmConfig<F>, |
1560 &AlgorithmConfig<F>, |
| 1551 I, |
1561 I, |
| 1552 Plot, |
1562 Plot, |
| 1553 (Option<RNDM<N, F>>, Z), |
1563 (Option<DiscreteMeasure<U, F>>, Z), |
| 1554 String, |
1564 String, |
| 1555 ), |
1565 ), |
| 1556 ) -> DynResult<Pair<RNDM<N, F>, Z>>, |
1566 ) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>>, |
| 1557 ) -> DynResult<Pair<RNDM<N, F>, Z>> |
1567 ) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>> |
| 1558 where |
1568 where |
| 1559 F: Float + ToNalgebraRealField, |
1569 F: Float + ToNalgebraRealField, |
| |
1570 U: Space + Clone + Dist<L2, F>, |
| |
1571 for<'a> &'a U: Instance<U>, |
| 1560 I: AlgIteratorFactory<IterInfo<F>>, |
1572 I: AlgIteratorFactory<IterInfo<F>>, |
| 1561 Dat: DifferentiableMapping<MeasureZ<F, Z, N>, Codomain = F, DerivativeDomain = Pair<S, Z>> |
1573 Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>> |
| 1562 + BoundedCurvature<F>, |
1574 + BoundedCurvature<F>, |
| 1563 S: DifferentiableRealMapping<N, F> + ClosedMul<F> + MinMaxMapping<Loc<N, F>, F>, |
1575 S: DifferentiableMapping<U, Codomain = F> + ClosedMul<F> + MinMaxMapping<U, F>, |
| 1564 RNDM<N, F>: SpikeMerging<F>, |
1576 DiscreteMeasure<U, F>: SpikeMerging<F>, |
| 1565 Reg: SlidingRegTerm<Loc<N, F>, F>, |
1577 Reg: SlidingRegTerm<U, F>, |
| 1566 P: TransportProxPenalty<Loc<N, F>, S, Reg, F>, |
1578 P: TransportProxPenalty<U, S, Reg, F>, |
| 1567 for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
1579 for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
| 1568 Z: ClosedEuclidean<F> + AXPY + Clone, |
1580 Z: ClosedEuclidean<F> + AXPY + Clone, |
| 1569 for<'b> &'b Z: Instance<Z>, |
1581 for<'b> &'b Z: Instance<Z>, |
| 1570 R: Prox<Z, Codomain = F>, |
1582 R: Prox<Z, Codomain = F>, |
| 1571 Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>, |
1583 Plot: Plotter<P::ReturnMapping, S, DiscreteMeasure<U, F>>, |
| 1572 // We should not need to explicitly require this: |
1584 // We should not need to explicitly require this: |
| 1573 for<'b> &'b Loc<0, F>: Instance<Loc<0, F>>, |
1585 for<'b> &'b Loc<0, F>: Instance<Loc<0, F>>, |
| 1574 { |
1586 { |
| 1575 run_fb_pair_dom(f, reg, prox_penalty, fnR, init, &mut FullSpace, cont) |
1587 run_fb_pair_dom(f, reg, prox_penalty, fnR, init, &mut FullSpace, cont) |
| 1576 } |
1588 } |
| 1577 |
1589 |
| 1578 pub fn run_fb_pair_dom<F, S, Dat, Reg, Z, R, P, I, Plot, const N: usize>( |
1590 pub fn run_fb_pair_dom<F, S, Dat, Reg, Z, R, P, I, Plot, U>( |
| 1579 f: &Dat, |
1591 f: &Dat, |
| 1580 reg: &Reg, |
1592 reg: &Reg, |
| 1581 prox_penalty: &P, |
1593 prox_penalty: &P, |
| 1582 fnR: &R, |
1594 fnR: &R, |
| 1583 (alg, iterator, plotter, μ0z, running): ( |
1595 (alg, iterator, plotter, μ0z, running): ( |
| 1584 &AlgorithmConfig<F>, |
1596 &AlgorithmConfig<F>, |
| 1585 I, |
1597 I, |
| 1586 Plot, |
1598 Plot, |
| 1587 (Option<RNDM<N, F>>, Z), |
1599 (Option<DiscreteMeasure<U, F>>, Z), |
| 1588 String, |
1600 String, |
| 1589 ), |
1601 ), |
| 1590 domain: &mut impl AdmissibleDomain<Loc<N, F>>, |
1602 domain: &mut impl AdmissibleDomain<U>, |
| 1591 cont: impl FnOnce( |
1603 cont: impl FnOnce( |
| 1592 ( |
1604 ( |
| 1593 &AlgorithmConfig<F>, |
1605 &AlgorithmConfig<F>, |
| 1594 I, |
1606 I, |
| 1595 Plot, |
1607 Plot, |
| 1596 (Option<RNDM<N, F>>, Z), |
1608 (Option<DiscreteMeasure<U, F>>, Z), |
| 1597 String, |
1609 String, |
| 1598 ), |
1610 ), |
| 1599 ) -> DynResult<Pair<RNDM<N, F>, Z>>, |
1611 ) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>>, |
| 1600 ) -> DynResult<Pair<RNDM<N, F>, Z>> |
1612 ) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>> |
| 1601 where |
1613 where |
| 1602 F: Float + ToNalgebraRealField, |
1614 F: Float + ToNalgebraRealField, |
| |
1615 U: Space + Clone + Dist<L2, F>, |
| |
1616 for<'a> &'a U: Instance<U>, |
| 1603 I: AlgIteratorFactory<IterInfo<F>>, |
1617 I: AlgIteratorFactory<IterInfo<F>>, |
| 1604 Dat: DifferentiableMapping<MeasureZ<F, Z, N>, Codomain = F, DerivativeDomain = Pair<S, Z>> |
1618 Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>> |
| 1605 + BoundedCurvature<F>, |
1619 + BoundedCurvature<F>, |
| 1606 S: DifferentiableRealMapping<N, F> + ClosedMul<F> + MinMaxMapping<Loc<N, F>, F>, |
1620 S: DifferentiableMapping<U, Codomain = F> + ClosedMul<F> + MinMaxMapping<U, F>, |
| 1607 RNDM<N, F>: SpikeMerging<F>, |
1621 DiscreteMeasure<U, F>: SpikeMerging<F>, |
| 1608 Reg: SlidingRegTerm<Loc<N, F>, F>, |
1622 Reg: SlidingRegTerm<U, F>, |
| 1609 P: TransportProxPenalty<Loc<N, F>, S, Reg, F>, |
1623 P: TransportProxPenalty<U, S, Reg, F>, |
| 1610 for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
1624 for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
| 1611 Z: ClosedEuclidean<F> + AXPY + Clone, |
1625 Z: ClosedEuclidean<F> + AXPY + Clone, |
| 1612 for<'b> &'b Z: Instance<Z>, |
1626 for<'b> &'b Z: Instance<Z>, |
| 1613 R: Prox<Z, Codomain = F>, |
1627 R: Prox<Z, Codomain = F>, |
| 1614 Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>, |
1628 Plot: Plotter<P::ReturnMapping, S, DiscreteMeasure<U, F>>, |
| 1615 // We should not need to explicitly require this: |
1629 // We should not need to explicitly require this: |
| 1616 for<'b> &'b Loc<0, F>: Instance<Loc<0, F>>, |
1630 for<'b> &'b Loc<0, F>: Instance<Loc<0, F>>, |
| 1617 { |
1631 { |
| 1618 let pt = P::prox_type(); |
1632 let pt = P::prox_type(); |
| 1619 |
1633 |