greedy
srcgreedy is a combinatorial optimization that greedily selects the phase of each transducer one at a time from a set of discrete candidates. The algorithm is based on the paper by Suzuki et al. (Suzuki et al., 2021).
greedy optimizes only the phases, not the intensities.
You give the intensities in intensities, and greedy chooses the phases for those intensities.
intensities takes either a uniform value for all transducers (Intensity) or a per-transducer buffer.
A transducer whose intensity is 0 is left out of the search and gets phase 0.
You must give the order in which the transducers are visited in order.
The indices run through the whole geometry (from 0 to geometry.num_transducers() - 1 in device order), and order should contain every transducer exactly once.
Visiting the transducers in random order is recommended, so you normally pass a sequence shuffled with random numbers.
greedy( &geometry, &foci, wavelength, &intensities, &order, &option, &mut dst,)?;greedy(geometry, foci, wavelength, intensities, order, option, dst)Holo.Greedy(geometry, foci, wavelength, intensities, order, option, dst);| Parameter | Type | Description |
|---|---|---|
geometry |
&Geometry |
Device layout |
foci |
&[AmplitudeTarget] |
Sequence of focal points (position and target amplitude) |
wavelength |
Length |
Wavelength |
intensities |
impl Into<PatternIntensity> |
Intensity (a uniform Intensity, or a per-device &[Vec<Intensity>] buffer) |
order |
&[usize] |
Order in which the transducers are visited (a sequence of indices) |
option |
&GreedyOption |
Additional options (see below) |
dst |
&mut [Vec<Phase>] |
Phase output buffer |
GreedyOption
Section titled “GreedyOption”GreedyOption { phase_quantization_levels, directivity, objective_func,}GreedyOption( phase_quantization_levels, directivity,)new GreedyOption{ PhaseQuantizationLevels = phaseQuantizationLevels, Directivity = directivity,}| Field | Type | Default |
|---|---|---|
phase_quantization_levels |
NonZeroU8 |
16 |
directivity |
Directivity |
Sphere |
objective_func |
fn(Complex<f32>, Amplitude) -> f32 |
abs_objective_func |
phase_quantization_levels— the number of divisions of the phase candidates. The larger it is, the higher the phase resolution.objective_func— the objective function that evaluates each candidate. The defaultabs_objective_funcreturns the absolute value of the difference between the magnitude of the synthesized sound pressure and the target amplitude.- Configurable only in the Rust version. In other languages, the default objective function is used.
Example
Section titled “Example”use std::num::NonZeroU8;
use rand::seq::SliceRandom;
use autd3_rs::geometry::{Autd3, Geometry, offset};use autd3_rs::units::{m, mm, s};use autd3_rs::value::Intensity;use autd3_rs_pattern::wavelength;use autd3_rs_pattern_holo::{ AmplitudeTarget, Directivity, GreedyOption, Pa, abs_objective_func, greedy,};
let geometry = Geometry::new(vec![Autd3::default()]);
let mut order: Vec<usize> = (0..geometry.num_transducers()).collect();order.shuffle(&mut rand::rng());
let mut phases = geometry.phase_buffer();
greedy( &geometry, &[ AmplitudeTarget { point: geometry.center() + offset(-30.0 * mm, 0.0 * mm, 150.0 * mm), amplitude: 2.5e3 * Pa, }, AmplitudeTarget { point: geometry.center() + offset(30.0 * mm, 0.0 * mm, 150.0 * mm), amplitude: 2.5e3 * Pa, }, ], wavelength(340.0 * m / s), Intensity::MAX, &order, &GreedyOption { phase_quantization_levels: NonZeroU8::new(16).unwrap(), directivity: Directivity::Sphere, objective_func: abs_objective_func, }, &mut phases,)?;import numpy as npfrom autd3.geometry import Autd3, Geometry, offsetfrom autd3.units import m, mm, sfrom autd3.value import Intensityfrom autd3_pattern import wavelengthfrom autd3_pattern_holo import ( AmplitudeTarget, Directivity, GreedyOption, Pa, greedy,)
geometry = Geometry([Autd3()])
order = np.random.default_rng().permutation(geometry.num_transducers())
phases = geometry.phase_buffer()
greedy( geometry, [ AmplitudeTarget( point=geometry.center() + offset(-30.0 * mm, 0.0 * mm, 150.0 * mm), amplitude=2.5e3 * Pa, ), AmplitudeTarget( point=geometry.center() + offset(30.0 * mm, 0.0 * mm, 150.0 * mm), amplitude=2.5e3 * Pa, ), ], wavelength(340 * m / s), Intensity.MAX, order, GreedyOption( phase_quantization_levels=16, directivity=Directivity.Sphere, ), phases,)using System;using System.Linq;using AUTD3;using AUTD3.Holo;using static AUTD3.Units;using static AUTD3.Holo.HoloUnits;
var geometry = new Geometry(new[] { new Autd3() });
var order = Enumerable.Range(0, geometry.NumTransducers).Select(i => (uint)i).ToArray();Random.Shared.Shuffle(order);
var phases = geometry.PhaseBuffer();
Holo.Greedy( geometry, new[] { new AmplitudeTarget(geometry.Center + Offset(-30.0f * mm, 0.0f * mm, 150.0f * mm), 2.5e3f * Pa), new AmplitudeTarget(geometry.Center + Offset(30.0f * mm, 0.0f * mm, 150.0f * mm), 2.5e3f * Pa), }, Pattern.Wavelength(340.0f * m / s), Intensity.Max, order, new GreedyOption { PhaseQuantizationLevels = 16, Directivity = Directivity.Sphere, }, phases);