神经生物学系:-神经生物学研究【20270005】 - w(t)=sin(tabs​)+clamp(tan(tabs​),−2

📅 2026-11-30 👤 拼多多助力营销技巧 📂 首码项目 👁️ 393 次阅读

Technical Documentation: Waveform Generation for SNN Classification

Project Repository: https://gitee.com/waterruby/ANNA.git License: Apache License 2.0

1. Overview

This document describes the waveform generation strategy used for training a spiking neural network (SNN) on a four‑class classification task. The key challenge is to ensure that the network learns phase‑invariant features for the base sinusoidal class while preserving discriminative, phase‑independent features for the other classes.

2. Class Definitions

ClassDescriptionMathematical form0Sinusoid with random phase

sin

⁡

(

t

abs

+

ϕ

)

\sin(t_{\text{abs}} + \phi)

sin(tabs​+ϕ),

ϕ

∼

U

(

0

,

2

π

)

\phi \sim \mathcal{U}(0, 2\pi)

ϕ∼U(0,2π)1Sinusoid + squared absolute time

sin

⁡

(

t

abs

)

+

t

abs

2

\sin(t_{\text{abs}}) + t_{\text{abs}}^2

sin(tabs​)+tabs2​2Sinusoid + clipped tangent

sin

⁡

(

t

abs

)

+

c

l

a

m

p

(

tan

⁡

(

t

abs

)

,

−

2

,

2

)

\sin(t_{\text{abs}}) + \mathrm{clamp}(\tan(t_{\text{abs}}), -2, 2)

sin(tabs​)+clamp(tan(tabs​),−2,2)3Sum of sinusoid and cosine

sin

⁡

(

t

abs

)

+

cos

⁡

(

t

abs

)

\sin(t_{\text{abs}}) + \cos(t_{\text{abs}})

sin(tabs​)+cos(tabs​)

Where

t

abs

∈

[

0

,

2

π

]

t_{\text{abs}} \in [0, 2\pi]

tabs​∈[0,2π] is the absolute angle (fixed for all samples).

3. Rationale

3.1 Class 0 – Random Phase Sinusoid

Goal: Force the network to become insensitive to phase shifts.Implementation: Each sample uses a uniformly random phase

ϕ

\phi

ϕ. Hence the underlying waveform is a pure sinusoid but its starting point varies across samples.Effect: The network cannot overfit to a fixed starting point; it must learn the shape (sinusoid) independent of phase. This drastically increases the diversity of class‑0 samples (infinite variations in practice).

3.2 Classes 1, 2, 3 – Fixed Absolute Angle

Goal: Preserve deterministic, reproducible features that are easy to separate.Why fixed angle?

The additive components (

t

abs

2

t_{\text{abs}}^2

tabs2​,

tan

⁡

(

t

abs

)

\tan(t_{\text{abs}})

tan(tabs​), and

cos

⁡

(

t

abs

)

\cos(t_{\text{abs}})

cos(tabs​)) break the phase symmetry.Using an absolute angle ensures that the position of the distinctive structures (e.g., the sharp rise from

t

2

t^2

t2, the spike of

tan

⁡

\tan

tan near

π

/

2

\pi/2

π/2, or the bump of

cos

⁡

\cos

cos) is consistent across all samples of the same class.This allows the SNN to learn temporally localised features that are strongly correlated with the class label.

4. Data Generation Procedure

For each sample in a batch:

Choose a random class

c

∈

{

0

,

1

,

2

,

3

}

c \in \{0,1,2,3\}

c∈{0,1,2,3} uniformly.If

c

=

0

c = 0

c=0:

Draw a random phase

ϕ

∼

U

(

0

,

2

π

)

\phi \sim \mathcal{U}(0, 2\pi)

ϕ∼U(0,2π).Compute the waveform:

w

(

t

)

=

sin

⁡

(

t

abs

+

ϕ

)

w(t) = \sin(t_{\text{abs}} + \phi)

w(t)=sin(tabs​+ϕ). If

c

=

1

c = 1

c=1:

w

(

t

)

=

sin

⁡

(

t

abs

)

+

t

abs

2

w(t) = \sin(t_{\text{abs}}) + t_{\text{abs}}^2

w(t)=sin(tabs​)+tabs2​. If

c

=

2

c = 2

c=2:

w

(

t

)

=

sin

⁡

(

t

abs

)

+

c

l

a

m

p

(

tan

⁡

(

t

abs

)

,

−

2.0

,

2.0

)

w(t) = \sin(t_{\text{abs}}) + \mathrm{clamp}(\tan(t_{\text{abs}}), -2.0, 2.0)

w(t)=sin(tabs​)+clamp(tan(tabs​),−2.0,2.0). If

c

=

3

c = 3

c=3:

w

(

t

)

=

sin

⁡

(

t

abs

)

+

cos

⁡

(

t

abs

)

w(t) = \sin(t_{\text{abs}}) + \cos(t_{\text{abs}})

w(t)=sin(tabs​)+cos(tabs​). Normalise each waveform independently to the range

[

0 拼多多帮助力入口

,

1

]

[0,1]

[0,1] (or

[

−

1

,

1

]

[-1,1]

[−1,1] depending on the network’s input encoding) using its own minimum and maximum:

w

norm

=

w

−

min

⁡

(

w

)

max

⁡

(

w

)

−

min

⁡

(

w

)

+

ϵ

w_{\text{norm}} = \frac{w - \min(w)}{\max(w) - \min(w) + \epsilon}

wnorm​=max(w)−min(w)+ϵw−min(w)​ where

ϵ

\epsilon

ϵ is a small constant to avoid division by zero.

5. Why This Approach Works

Phase‑invariance learning: By exposing class‑0 with many random phases, the network is forced to ignore phase and extract the sinusoidal shape.Distinctive temporal landmarks: Classes 1–3 have features that appear at fixed absolute angles (e.g., the maximum of

t

2

t^2

t2 at

t

=

2

π

t=2\pi

t=2π, the

tan

⁡

\tan

tan spike at

π

/

2

\pi/2

π/2). The SNN can use its temporal dynamics (e.g., precise spike timing) to detect these landmarks.Improved generalisation: The validation and test sets are generated with the same protocol but using a fixed random seed to ensure reproducibility. During inference, the network sees previously unseen phases for class‑0, and its performance demonstrates true phase invariance.

6. Implementation Example (PyTorch)

import torch

import numpy as np

def generate_waveform_batch(batch_size, time_steps, device='cpu', fixed_seed=None):

if fixed_seed is not None:

np.random.seed(fixed_seed)

t_abs = torch.linspace(0, 2*np.pi, time_steps).to(device)

sin_abs = torch.sin(t_abs)

cos_abs = torch.cos(t_abs)

t2_abs = t_abs ** 2

tan_abs = torch.tan(t_abs).clamp(-2.0, 2.0)

sin_cos = sin_abs + cos_abs

batch_wave = []

batch_label = []

for _ in range(batch_size):

label = np.random.randint(0, 4)

if label == 0:

phase = np.random.uniform(0, 2*np.pi)

wave = torch.sin(t_abs + phase)

elif label == 1:

wave = sin_abs + t2_abs

elif label == 2:

wave = sin_abs + tan_abs

else:

wave = sin_cos

# Normalise each sample to [0,1]

w_min = wave.min()

w_max = wave.max()

if w_max - w_min < 1e-8:

wave = torch.zeros_like(wave)

else:

wave = (wave - w_min) / (w_max - w_min)

batch_wave.append(wave)

batch_label.append(label)

return torch.stack(batch_wave), torch.tensor(batch_label, dtype=torch.long, device=device)

7. Expected Outcomes

The SNN trained with this data generation strategy should achieve >85% validation accuracy after fine‑tuning.Class‑0 accuracy will be robust to different phase offsets, while classes 1–3 will be recognised by their fixed temporal features.Compared to a naive approach (all classes using absolute angles), the network will not overfit to a single phase pattern and will generalise much better to real‑world audio where phase is irrelevant.

8. License

This work is licensed under the Apache License, Version 2.0. A copy of the license can be found in the repository root or at https://www.apache.org/licenses/LICENSE-2.0.

SPDX-License-Identifier: Apache-2.0

9. Repository Information

Main Repository: https://gitee.com/waterruby/ANNA.gitDocumentation: See docs/waveform_generation.mdIssues: https://gitee.com/waterruby/ANNA.git/issues

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧