LM

Gain for multiple focal points based on the Levenberg-Marquardt method (LM method). The LM method is an optimization method for nonlinear least squares problems proposed by Levenberg1 and Marquardt2, and the implementation is based on Madsen’s text3.

use autd3::prelude::*;
use autd3_gain_holo::{EmissionConstraint, NalgebraBackend, Pa, LM, LMOption};
use std::num::NonZeroUsize;
use std::sync::Arc;

fn main() {
let x1 = 0.;
let y1 = 0.;
let z1 = 0.;
let x2 = 0.;
let y2 = 0.;
let z2 = 0.;
let backend = Arc::new(NalgebraBackend::default());
let _ = 
LM {
    foci: vec![
        (Point3::new(x1, y1, z1), 5e3 * Pa),
        (Point3::new(x2, y2, z2), 5e3 * Pa),
    ],
    option: LMOption {
        eps_1: 1e-8,
        eps_2: 1e-8,
        tau: 1e-3,
        k_max: NonZeroUsize::new(5).unwrap(),
        initial: vec![],
        constraint: EmissionConstraint::Clamp(EmitIntensity::MIN, EmitIntensity::MAX),
        ..Default::default()
    },
    backend,
};
}
#include<autd3.hpp>
#include "autd3/gain/holo.hpp"

using namespace autd3;
using gain::holo::Pa;

int main() {
const auto x1 = 0.0;
const auto y1 = 0.0;
const auto z1 = 0.0;
const auto x2 = 0.0;
const auto y2 = 0.0;
const auto z2 = 0.0;
const auto backend = std::make_shared<gain::holo::NalgebraBackend>();
auto g = gain::holo::LM(
    std::vector<std::pair<Point3, gain::holo::Amplitude>>{
        {Point3(x1, y1, z1), 5e3 * Pa},
        {Point3(x2, y2, z2), 5e3 * Pa},
    },
    gain::holo::LMOption{
        .eps_1 = 1e-8,
        .eps_2 = 1e-8,
        .tau = 1e-3,
        .k_max = 5,
        .initial = {},
        .constraint = gain::holo::EmissionConstraint::Clamp(
            std::numeric_limits<EmitIntensity>::min(),
            std::numeric_limits<EmitIntensity>::max()),
    },
    backend);
return 0; }
using AUTD3Sharp.Gain.Holo;

using AUTD3Sharp;
using AUTD3Sharp.Utils;
using static AUTD3Sharp.Units;
var x1 = 0.0f;
var y1 = 0.0f;
var z1 = 0.0f;
var x2 = 0.0f;
var y2 = 0.0f;
var z2 = 0.0f;
var backend = new NalgebraBackend();
new LM(
    foci: [
             (new Point3(x1, y1, z1), 5e3f * Pa),
             (new Point3(x2, y2, z2), 5e3f * Pa)
    ],
    option: new LMOption
    {
        Eps1 = 1e-8f,
        Eps2 = 1e-8f,
        Tau = 1e-3f,
        KMax = 5,
        Initial = [],
        EmissionConstraint = EmissionConstraint.Clamp(EmitIntensity.Min, EmitIntensity.Max),
    },
    backend: backend
);
import numpy as np
from pyautd3 import EmitIntensity
from pyautd3.gain.holo import LM, EmissionConstraint, LMOption, NalgebraBackend, Pa

x1 = 0.0
y1 = 0.0
z1 = 0.0
x2 = 0.0
y2 = 0.0
z2 = 0.0
backend = NalgebraBackend()
LM(
    foci=[(np.array([x1, y1, z1]), 5e3 * Pa), (np.array([x2, y2, z2]), 5e3 * Pa)],
    option=LMOption(
        eps_1=1e-8,
        eps_2=1e-8,
        tau=1e-3,
        k_max=5,
        initial = None,
        constraint=EmissionConstraint.Clamp(EmitIntensity.MIN, EmitIntensity.MAX),
    ),
    backend=backend,
)

The defaults for each parameter are as above. For details on the parameters, refer to the text3.

1

Levenberg, Kenneth. “A method for the solution of certain non-linear problems in least squares.” Quarterly of applied mathematics 2.2 (1944): 164-168.

2

Marquardt, Donald W. “An algorithm for least-squares estimation of nonlinear parameters.” Journal of the society for Industrial and Applied Mathematics 11.2 (1963): 431-441.

3

Madsen, Kaj, Hans Bruun Nielsen, and Ole Tingleff. “Methods for non-linear least squares problems.” (2004).