{'fraction_non_alphanumeric': 0.028590694538098448, 'fraction_numerical': 0.006877950101146325, 'mean_word_length': 4.626327769347496, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Variational framework for partially-measured physical system control: examples of vision neuroscience and optical random media

To characterize a physical system to behave as desired, either its underlying governing rules must be known a priori or the system itself be accurately measured. The complexity of full measurements of the system scales with its size. When exposed to real-world conditions, such as perturbations or time-varying settings, the system calibrated for a fixed working condition might require non-trivial re-calibration, a process that could be prohibitively expensive, inefficient and impractical for real-world use cases. In this work, we propose a learning procedure to obtain a desired target output from a physical system. We use Variational Auto-Encoders (VAE) to provide a generative model of the system function and use this model to obtain the required input of the system that produces the target output. We showcase the applicability of our method for two datasets in optical physics and neuroscience.


Introduction
In physical system characterization, a fundamental challenge is finding the proper continuous space input to a system that yields a desired functional output. For example, an open question in sensory/motor neuroscience is how to determine the input stimulation able to induce a desired behavior. So is controlling the output of an optical system, such as a turbid medium used for imaging, that could be non-linear and time-varying. In a linear physical system, the problem of finding the input that produces a desired output can be determined by monitoring its response to a series of arbitrary inputs and then computing the inverse of the system's transmission matrix (a mapping from inputs to outputs). This entails measuring the responses of the system fully. In practice, physical systems can only be partially measured and, more importantly, are nonlinear. So the transmission matrix formalism cannot be used. Even though the forward path of the system could be fully characterized, obtaining its inverse for large scale systems involving millions of variables is computationally intensive if not entirely intractable. Hence, resorting to data-driven methods that do not require full-measurements or linear approximation of the system, such as deep learning approaches, is inevitable. Deep learning techniques proposed for these tasks McIntosh et al. [2016], Rahmani et al. [2018] mostly take advantage of labeled data to do supervised training. For applications that require control over the response of one or an ensemble of targets, end-to-end supervised learning can fail due to the lack of labeled data within the distribution of desired target responses as well as inherent sensitivity of supervised approaches to perturbations in out-of-training-distribution data. Therefore, we instead propose a learning framework based on generative probabilistic models Mirza and Osindero [2014] and in specific, VAEs Kingma and Welling [2013] which involves in construction of a forward estimator of the possibly partially measured system. Once the forward model is obtained, a second estimator is trained to provide the required input of the system for producing the desired output. This latter estimator could be constraint so as to promote certain solutions. Therefore, contributions of this work are as follows: • Using the variational generative models, we provide a training algorithm for learning the distribution of the system's inputs that are needed to obtain a desired output of the system. • Using the sampling feature of the learned forward VAE model, we illustrate how our training algorithm learns to iteratively move towards the correct distribution of the inputs.
Related works: As opposed to the inference problem of estimating the input of the system from noisy sensory outputs in experimental disciplines such as microscopy Rivenson et al. [2017], optical tomography Würfl et al. [2016] and neuroscience Parthasarathy et al. [2017] that supervised deep learning approach is a fairly well-established technique, learning methods for control applications in these fields have yet to be matured. Closed-loop techniques based on deep networks have been proposed for a number of applications, such as for brain neuroscience Bashivan et al. [2019] wherein authors control the activity of individual neuronal sites in V4 area by optimizing single input stimuli. Likewise, for optical turbid-medium imaging, authors have used ML-based estimators for controlling the optical fields Rahmani et al. [2020]. As opposed to the previous works, we propose joint learning of the forward and backward models of the system with VAEs to implicitly impose compatibility of the sought-after solutions with the underlying physics of the problem. The latter, in essence, is akin to technique of untrained neural networks Van Veen et al. [2018], Ulyanov et al. [2018], Heckel and Hand [2018] in denoising and inpainting.

Generative modelling
Problem scenario In the most general form, we assume that a given input of a system, x i , is mapped to its output via the function f as in y i = f (x i ). Therein, x i ∈ C n and y i ∈ C m in the most general case. All known about f is that it could be a (non)linear time-varying function. We assume that all the noise sources are incorporated in f . Additionally, f can be sampled as many times as needed. In other words, exact output of the system, i.e. y i , is available for any given input x i . Yet, f is never measured nor analytically derived. Moreover, f might only be partially measured for which, the input-output relationship is modified to where ϕ is either identity (fully measured system) or some other functions (for example modulus |.| 2 function).
We seek to find the x * i that would produce a desired y * i . It is worth emphasizing that the experimentalist might only have access to the partially measured system while the objective is to obtain the desired output in the fully measured system. The problem, in its most general form, can be formulated as follows.
where M ζ : C n×l → C m , referred to henceforth as the Model, is a differentiable representation of f parameterized by ζ and A ξ : C n×m → C n , referred to henceforth as Actor, is a mapping that produces the input for M ζ . Therein, D is the distance between outputs y i sampled (experimentally) from y i = f (x i ) and the output of M ζ . σ is the distance between the desired target y * i and predicted output of M ζ given the output of is the latent space vector of size l. The two-term loss function L is then optimized with respect to the parameters ζ and ξ. The first RHS term in Eq. 1 is further explained below.
Forward estimator learning The forward mapping M ζ is estimated as a generative probabilistic VAE. The reason for this choice of model is two-fold. First, forward models that are fundamentally stochastic in nature (see example 2 in Results section) could be better represented by a probabilistic model rather than a ML estimator trained in a supervised learning manner. Additionally, even if f is deterministic, noise sources incorporated into f make it stochastic in practice. Second, the generative sampling feature of VAEs could be conveniently used to demonstrate how the correct control input x * i (that is required to generate y * i ) could be obtained iteratively. The VAE M ζ consists of two networks, an encoder and a decoder. The former is trained to transform input x i conditioned on the system's output y i onto the latent vector z that is enforced to be close to a normal distribution N (0, I); effectively learning the conditional distribution q Φ (z|y i ) parameterized by Φ. The decoder, on the other hand, takes the latent vector zdrawn from the encoder distribution N (µ enc , σ enc ) using reparameterization trick-to generate outputŷ i ; effectively learning the conditional distribution p θ (y i |z, x i ) parameterized by θ. The training of the VAE is carried out by optimizing the following loss function w.r.t. ζ : {θ, Φ} Higgins et al. [2016].
where β is the weighting factor between the two terms in the loss function and ρ is to denote a general purpose probability distribution.
Training algorithm A sketch of the networks and gradient flows is depicted below. Algorithm 1 presents the learning procedure for the system control. It involves in computing the variational updates of the forward model followed by training of the backward mapping. We compute an empirical performance metric between the outputs generated through the experimental system by the control inputs provided by the algorithm and the targets and reiterate if the performance is not satisfactory.

Results
Phase retrieval for optical system control The first example involves in characterization of a slowly time-varying, nonlinear physical system featuring random scramblers. The objective of this experiment is to find the appropriate complex input vector of the system, X * = {x * i } ∈ C n , that produces a desired target output, Y * = {y * µ } ∈ R m , given the partial measurements of the system as in y , where x * i (and respectively y * µ ) are elements of the input (output) vector and F µi is the complex-value measurement matrix. Although the problem in essence is a phase retrieval (PR) of the system's input, key differences with the conventional PR settings renders it more challenging. In particular, in the the original PR problem, F is entirely known a priori. In the current setting, F is not measured and therefore is unknown. Instead, tuples of an arbitrary input X and its corresponding output Y is available. Secondly, while in the conventional PR, outputs Y (generated via a teacher model) always belong to the support of F , the target output Y * may not belong to the support of F which requires finding the input that produces the closest output to the target in some metric. The optimization problem can then be re-written as: where we choose l 2 norm for the forward and backward metrics. The network architecture and optimization scheme is further explained in the Appendices. We tested our algorithm with MNIST dataset Cohen et al. [2017] as the target outputs. An example of the input-output of the system is shown in Appendix A. Fig. 1 (a) plots empirical l 2 norm as well as 2D Pearson correlation between the system's outputs and targets versus the iteration number. It can be seen that the algorithm almost reaches the 2D correlation (∼ 0.9) obtained with full-measurement techniques. Examples of the experimentally generated outputs using the proposed algorithm are also provided in Appendix A. Vision neuroscience In the second example, we apply the algorithm to a dataset comprising sequences of natural images x * ij ∈ R n×t and their corresponding count data y * ij ∈ N m×t . These images and the count data are, respectively, the stimuli entering the retina in Salamander and the elicited time-series count responses of a number of Retina Ganglion Cells (RGCs). Approximating the system as a Poisson process, the system f is defined as the function that takes the image sequences as input and gives a time-varying posterior mean as output. Models based on Convolutional Neural Networks (CNNs) have been recently proposed for this modeling McIntosh et al. [2016]. Given f , we intend to find a transformed version of the input images that while are constraint to be of lower resolution, still elicit similar neuronal responses (in some metric) to those of the original input images (refer to appendix C). This constraint is imposed implicitly by architecture of the Actor network explained in more details in the appendix. The loss function for this optimization problem reads as follows: where we choose Poisson loss both for the forward and backward mappings. Details of the true system f is given in the Appendix B. Fig. 1 plots the performance metric evolution of this task. It can be seen that the algorithm almost reaches the maximum possible performance of the system (2D correlation ∼ 0.3) within three iterations. The latent vector of the forward VAE Model of our algorithm is sampled at each iteration and projected to a 2-dimensional (2D) embedding using t-SNE. The true latent vector distribution required for obtaining the desired outputs is also shown. The network architecture and optimization scheme is further explained in the Appendices.

Discussion and conclusion
We proposed a framework based on VAEs for system control. We also demonstrated how VAEs could illustratively show iterative convergence of the posterior latent variables to those required for obtaining the target outputs. The relevance of the approach was showcased for two applications. The applicability of the method to problems that are chaotic or rapidly time-varying is interesting and perhaps more challenging due to their difficulty of latent space learning. We note that black-box treatment of the physical system by the algorithm should be treated with caution and further studied in future work.
CMOS camera) working at light wavelength 532 nm. An example of a random input and its corresponding system's output is depicted in Fig. 2. Some examples of system's output obtained with the input found with the proposed algorithm is also depicted in Fig. 3. Figure 2: An example of a random input to the system and its corresponding output. B Vision neuroscience task true system.
Instead of the experimental system, We used a CNN-based network trained with the entire dataset of the input image stimuli and their corresponding neuronal responses as the proxy for the true system f . Therefore, to be fair, only a third of the same dataset, randomly selected, is made available to our training algorithm. The architecture of f is identical to that of the forward model. An example of the input-output of this system is depicted in Fig. 4.

C Low-resolution constraint of vision neuroscience backward model
The backward model in the vision task, which has a U-net architecture Ronneberger et al. [2019], is constraint to find solutions that are of lower resolutions than the original high resolution stimuli. This is achieved by adjusting the bottleneck size in the network architecture (denoted in Table 3). Lower sizes for the bottleneck provide lower resolution solutions. The dimensionality reduction process is depicted in Fig. 5.

D Network architecture and optimization
The hyperparameters of the forward and backward networks, optimizers as well as training epochs used for training is summarized in Table 1. Architecture of the networks is presented in Table 2 and 3. Hyperparameters were chosen such that a balance between the two terms of losses in Eq. 1 is achieved.

E Code repository
All models, implemented in Tensorflow v. 2.1. on Nvidia GPU 2080 Ti, will be available upon publication.