Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create BackStockPros #2443

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

OrsonTyphanel93
Copy link

@OrsonTyphanel93 OrsonTyphanel93 commented May 14, 2024

Backdoor attack via jumps-Diffusion and stochastic processes : BackStockPros

Hello Dear @beat-buesser ! , I recently performed a more specific and complex analysis on stochastic calculations and jumps incorporating a more advanced Bayesian analysis, in order to understand the change in data distribution during a backdoor attack, you will find attached the full code, you can also download in the code the full csv file containing all the details of this Bayesian stochastic analysis.

Description

This research paper presents a comprehensive approach for executing backdoor attacks on audio data. It uses a diffusion model and a Bayesian approach (via stochastic process effects). The effectiveness of the attack method and its discretion are confirmed by evaluation results, which highlight their ability to manipulate the integrity and security of audio systems.

  1. Simulation of a continuous change in performance due to backdoor triggering using the Ornstein-Uhlenbeck process
  2. Simulate performance fluctuations due to the backdoor trigger using the Ito formula for jump-diffusion
  3. Simulate the spread of the backdoor effect using the Black-Scholes to Diffusion method
  4. Simulate the spread of the backdoor effect over time using the Kolmogorov-Feller equation

After compilation, please examine the results of the csv file. This file contains information that can help improve understanding in various fields, such as finance, particle physics and chaotic time, where the passage of data to undetectable backdoors, biological simulations etc...

Testing

UPDATE Notebook: a more comprehensible version for those not familiar with Bayesian techniques BackStockPros, notebook complet

code update, this version is correctly optimal it integrates all simulations correctly in Bayesian execution

easy to understand
UPDATE Best (easy to understand )! please consider the following BackStockPros, notebook complet

Reference maybe
Reference nice
Reference 0
Reference 1
Reference 2
Reference 3
Reference 4
Reference 5
Reference 6
Reference 7
Reference 8
Reference 9
Reference 10
Reference 11
Reference 12
Reference 13, very nice
Reference 14, just very happy
Reference 15
Reference 16

This research paper presents a comprehensive approach for executing backdoor attacks on audio data. It uses a diffusion model and a Bayesian approach (via stochastic process effects). The effectiveness of the attack method and its discretion are confirmed by evaluation results, which highlight their ability to manipulate the integrity and security of audio systems.
@OrsonTyphanel93
Copy link
Author

FAQ

if you have trouble understanding the background of the entire code, focus on this one, I've simplified it to make it more comprehensible to those not familiar with Bayesian mirroring.

Usage/Examples

    def _bayesian_sampling_diffusion_model(
        self,
        T: int,
        alpha: np.ndarray,
        beta: np.ndarray,
        sigma: np.ndarray,
        noise_dist: Callable[[Any], np.ndarray],
        initial_state: np.ndarray,
        time_steps: int,
        theta: float,
        jump_size_dist: Callable[[Any], np.ndarray],
        non_linear_drift: Callable[[float, int], float],
        volatility: np.ndarray,  # Add this line to include the volatility parameter
        jump_volatility: float,
        dt: float = 0.01,
        # Additional parameters to reflect the dynamics of the simulation methods
        performance_fluctuations_prior=None,
        effect_spread_prior=None,
        continuous_performance_change_prior=None,
        backdoor_spread_prior=None
) -> pm.backends.base.MultiTrace:
     """
     Perform Bayesian sampling diffusion for a given time period, alpha, beta, sigma, and noise distribution.
     Incorporates the dynamics of simulate_performance_fluctuations, simulate_effect_spread,
     simulate_continuous_performance_change, and simulate_backdoor_spread.
     """
     assert isinstance(T, int), "Expected T to be an integer"
     assert isinstance(alpha, np.ndarray) and alpha.ndim == 1, "Expected alpha to be a 1D numpy array"
     assert isinstance(beta, np.ndarray) and beta.ndim == 1, "Expected beta to be a 1D numpy array"
     assert isinstance(sigma, np.ndarray) and sigma.ndim == 1, "Expected sigma to be a 1D numpy array"
     assert callable(noise_dist), "Expected noise_dist to be a callable function"
     assert isinstance(initial_state, np.ndarray), "Expected initial_state to be a numpy array"
     assert isinstance(time_steps, int), "Expected time_steps to be an integer"
     assert isinstance(theta, float), "Expected theta to be a float"
     assert callable(jump_size_dist), "Expected jump_size_dist to be a callable function"
     assert callable(non_linear_drift), "Expected non_linear_drift to be a callable function"
     assert isinstance(volatility, np.ndarray) and volatility.ndim == 1, "Expected volatility to be a 1D numpy array"
     assert isinstance(jump_volatility, float), "Expected jump_volatility to be a float"

     try:
        with Model() as model:
            # Define priors based on the simulation outputs
            if performance_fluctuations_prior is not None:
                x_T = Normal('x_T', mu=performance_fluctuations_prior[0], sigma=1)
            elif effect_spread_prior is not None:
                x_T = Normal('x_T', mu=effect_spread_prior[0], sigma=1)
            elif continuous_performance_change_prior is not None:
                x_T = Normal('x_T', mu=continuous_performance_change_prior[0], sigma=1)
            elif backdoor_spread_prior is not None:
                x_T = Normal('x_T', mu=backdoor_spread_prior[0], sigma=1)
            else:
                x_T = Normal('x_T', mu=noise_dist(initial_state), sigma=1)

            # Use the jump-diffusion process to update the state
            for t in range(T - 1, -1, -1):
                z = noise_dist(0) if t > 1 else 0
                x_t_minus_1 = Normal(f'x_{t}', mu=np.sqrt(alpha[t]) * (x_T - np.sqrt(1 - alpha[t]) * noise_dist(beta[t])) + sigma[t] * z, sigma=1)
                x_T = x_t_minus_1

            # Sample from the posterior
            trace = sample(2000, tune=1000, cores=2, chains=2, step=pm.NUTS())

        return trace

     except Exception as e:
            print(f"An error occurred: {e}")
            raise ```

@OrsonTyphanel93
Copy link
Author

OrsonTyphanel93 commented May 30, 2024

Definition :

Let (Wt)t ∈ ℝ+ be a (ℱt)t ∈ ℝ+-Brownian motion. The process (Xt)t ∈ ℝ+ is an Ito process if it can be written as

$$ X_t = x_0 + \int_0^t A_s ds + \int_0^t B_s dW_s, \text{ for } t \in [0, T], $$

where X0 = x0 almost surely, (At)t ∈ [0, T] and (Bt)t ∈ [0, T] are (ℱt)t ∈ ℝ+-adapted processes such that

$$ \int_0^T |A_s| ds < \infty \text{ and } \int_0^T |B_s|^2 ds < \infty. $$

Sometimes we will simply write $dX_t = A_t dt + B_t dW_t$.

Theorem:

Let (Xt)t ∈ ℝ+ be a (ℱt)t ∈ ℝ+-Ito process, and f : [0, T] × ℝ → ℝ be a function twice continuously differentiable in x and differentiable in t, then for t ∈ [0, T],

$$ f(t, X_t) = f(0, x_0) + \int_0^t \frac{\partial f(s, X_s)}{\partial t} ds + \int_0^t \frac{\partial f(s, X_s)}{\partial x} dX_s + \frac{1}{2} \int_0^t \frac{\partial^2 f(s, X_s)}{\partial x^2} d<X, X>_s. $$

The resolution in the case of the Black & Scholes model (1973) is done by setting $Y_t = \log(S_t).$ Given that $(S_t)_{t \in \mathbb{R}}$ is an Ito process, we apply (formally) the Ito formula to $f(x) = \log(x)$, thus obtaining

$$ \log(S_t) = \log(S_0) + \int_0^t \frac{dS_s}{S_s} + \frac{1}{2} \int_0^t -\frac{1}{S_s^2} \sigma^2 S_s^2 ds.] $$

This last equation can be rewritten as

$$ Y_t = Y_0 + \int_0^t (\mu - \frac{\sigma^2}{2}) dt + \sigma \epsilon_0^t dW_t $$

Given the process $Y_t = \log(S_t)$, we have:

$$ Y_t = \log(S_t) = \log(S_0) + (\mu - \frac{\sigma^2}{2})t + \sigma W_t, $$

which, upon taking the exponential, yields:

$$ S_t = S_0 \exp((\mu - \frac{\sigma^2}{2})t + \sigma W_t). $$

It is important to note that the logarithm function was not defined at 0, and the Ito formula is used here only ``formally''. Therefore, it is necessary to verify that this process is indeed a solution to the stochastic differential equation. Let us denote $S_t^* = g(t, W_t)$ where $g(t, x) = S_0 \exp((\mu - \sigma^2/2)t + \sigma x)$. Applying the Ito formula, we obtain:

$$ g\left(t, W_t\right)=g\left(0, W_0\right)+\int_0^t \frac{\partial g\left(s, W_s\right)}{\partial s} d s+\int_0^t \frac{\partial g\left(s, W_s\right)}{\partial x} d W_s+\frac{1}{2} \int_0^t \frac{\partial^2 g\left(s, W_s\right)}{\partial x^2} d<W, W>_s, $$

$$ g(t, W_t) = S_0 + \int_0^t S_s(\mu - \frac{\sigma^2}{2}) ds + \int_0^t S_s \sigma dW_s + \frac{1}{2} \int_0^t S_s \sigma^2 ds. $$

Theorem:

Let μ, σ be two real numbers, T > 0, and (Wt)t ∈ ℝ+ a standard Brownian motion. There exists a unique Ito process (St)t ∈ ℝ+ that verifies

$$ S_t = S_0 + \int_0^t \mu S_s ds + \int \sigma S_s dWs, $$

and this process is given by

$$ S_t = S_0 \exp((\mu - \frac{\sigma^2}{2})t + \sigma W_t) $$

We note that (St)t ∈ ℝ+ satisfies an equation if and only if (Yt)t ∈ ℝ+ (where Yt = log (St)) is a Brownian motion.

Itô Formula for Jump Process:

$$ X_t=X_0+\int_0^t a\left(X_s\right) d s+\int_0^t b\left(X_s\right) d W_s+\int_0^t c\left(X_s\right) d N_s . $$

Proposition Itô Formula for Jump Process :

If (Xt) is a jump-diffusion process and f : [0, ∞) → ℝn any function twice derivable, then f(Xt) is a jump-diffusion process and satisfies the following equation :

$$ f\left(X_t\right) = f\left(X_0\right) + \int_0^t \frac{\partial f}{\partial x}\left(X_s\right) a_s ds + \frac{1}{2} \int_0^t \frac{\partial^2 f}{\partial x^2}\left(X_s\right) b_s^2 ds + \int_0^t \frac{\partial f}{\partial x} b_s dW_s + \int_0^t\left(f\left(X_{s^-}+c\left(X_s\right)\right)-f\left(X_{s^-}\right)\right) dN_s. $$

The coefficient a ∈ 𝕃1([0, T], ℝn) is called the drift coefficient, b ∈ 𝕃2([0, T], ℝn × m) is called the diffusion coefficient and c(Xs) ∈ 𝕃2([0, T], ℝn) is called the jump coefficient. W is a m-dimensional Brownian motion and N a one dimensional Poisson process.

Recall that the diffusion process followed by the underlying asset is given by $d S_t = \mu S_t dt + \sigma S_t dW_t$

Ito's Lemma provides a general formula for the differential of a function of a stochastic process. If we have a stochastic process $S_t$ governed by

$$ d S_t = a(S_t, t) dt + b(S_t, t) dW_t, $$

and we define a new process $X_t = g(S_t)$, then according to Ito's Lemma,

$$ d X_t = \left(\frac{\partial g(x, t)}{\partial x} a + \frac{\partial g(x, t)}{\partial t} + \frac{1}{2} \frac{\partial^2 g(x, t)}{\partial x^2} b^2\right) dt + \frac{\partial g}{\partial x} b dW_t. $$

In the specific case of the Black-Scholes model, for any differentiable function $g$,

$$ d X_t=\left(\frac{\partial g(x, t)}{\partial x} \mu S_t+\frac{\partial g(x, t)}{\partial t}+\frac{1}{2} \frac{\partial^2 g(x, t)}{\partial x^2} \sigma^2 S_t^2\right) d t+\frac{\partial g}{\partial x} \sigma S_t d W_t $$

@OrsonTyphanel93
Copy link
Author

OrsonTyphanel93 commented May 30, 2024

FAQ

For those of you who like it, you can use this version for optimum transport performance..

Usage/Examples

def _bayesian_sampling_diffusion_model(
    self,
    T: int,
    alpha: np.ndarray,
    beta: np.ndarray,
    sigma: np.ndarray,
    noise_dist: Callable[[Any], np.ndarray],
    initial_state: np.ndarray,
    time_steps: int,
    theta: float,
    jump_size_dist: Callable[[Any], np.ndarray],
    non_linear_drift: Callable[[float, int], float],
    volatility: np.ndarray,  # Added to include the volatility parameter
    jump_volatility: float,
    dt: float = 0.01,
    # Additional parameters to reflect the dynamics of the simulation methods
    performance_fluctuations_prior=None,
    effect_spread_prior=None,
    continuous_performance_change_prior=None,
    backdoor_spread_prior=None
) -> pm.backends.base.MultiTrace:
    """
    Perform Bayesian sampling diffusion for a given time period, alpha, beta, sigma, and noise distribution.
    Incorporates the dynamics of simulate_performance_fluctuations, simulate_effect_spread,
    simulate_continuous_performance_change, and simulate_backdoor_spread, emphasizing transport and diffusion.
    """
    assert isinstance(T, int), "Expected T to be an integer"
    assert isinstance(alpha, np.ndarray) and alpha.ndim == 1, "Expected alpha to be a 1D numpy array"
    assert isinstance(beta, np.ndarray) and beta.ndim == 1, "Expected beta to be a 1D numpy array"
    assert isinstance(sigma, np.ndarray) and sigma.ndim == 1, "Expected sigma to be a 1D numpy array"
    assert callable(noise_dist), "Expected noise_dist to be a callable function"
    assert isinstance(initial_state, np.ndarray), "Expected initial_state to be a numpy array"
    assert isinstance(time_steps, int), "Expected time_steps to be an integer"
    assert isinstance(theta, float), "Expected theta to be a float"
    assert callable(jump_size_dist), "Expected jump_size_dist to be a callable function"
    assert callable(non_linear_drift), "Expected non_linear_drift to be a callable function"
    assert isinstance(volatility, np.ndarray) and volatility.ndim == 1, "Expected volatility to be a 1D numpy array"
    assert isinstance(jump_volatility, float), "Expected jump_volatility to be a float"

    try:
        with Model() as model:
            # Define priors based on the simulation outputs
            if performance_fluctuations_prior is not None:
                x_T = Normal('x_T', mu=performance_fluctuations_prior[0], sigma=1)
            elif effect_spread_prior is not None:
                x_T = Normal('x_T', mu=effect_spread_prior[0], sigma=1)
            elif continuous_performance_change_prior is not None:
                x_T = Normal('x_T', mu=continuous_performance_change_prior[0], sigma=1)
            elif backdoor_spread_prior is not None:
                x_T = Normal('x_T', mu=backdoor_spread_prior[0], sigma=1)
            else:
                x_T = Normal('x_T', mu=noise_dist(initial_state), sigma=1)

            # Emphasize transport through the deterministic component and diffusion through the stochastic component
            for t in range(T - 1, -1, -1):
                z = noise_dist(0) if t > 1 else 0
                # Transport component: deterministic movement based on the state and time
                transport_component = non_linear_drift(x_T, t)
                # Diffusion component: stochastic movement based on the noise distribution
                diffusion_component = sigma[t] * z
                x_t_minus_1 = Normal(f'x_{t}', mu=transport_component + diffusion_component, sigma=1)
                x_T = x_t_minus_1

            # Sample from the posterior
            trace = sample(2000, tune=1000, cores=2, chains=2, step=pm.NUTS(target_accept=0.99)) #step=pm.Metropolis() , step=pm.NUTS(), step=pm.NUTS(target_accept=0.99)

        return trace

    except Exception as e:
        print(f"An error occurred: {e}")
        raise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant