MCPcopy Create free account

hub / github.com/breeze-sys/Label-Only-MIA-Go / functions

Functions123 in github.com/breeze-sys/Label-Only-MIA-Go

↓ 25 callersFunctionformatDuration
(d time.Duration)
bench_test.go:22
↓ 11 callersFunctionenvOrDefault
(key, fallback string)
main.go:153
↓ 11 callersFunctionrunBench
(name string, fn func(), iters int)
bench_test.go:33
↓ 9 callersFunctionGenUniform
GenUniform 生成符合均匀分布 (Uniform Distribution) 的随机向量。 对应 Python: np.random.uniform(low=min, high=max, size=size) 输入: - size: 向量长度 - min: 最小值 - max: 最大值
pkg/mathutils/noise.go:75
↓ 8 callersFunctionwriteJSON
(w http.ResponseWriter, value any, status int)
main.go:832
↓ 7 callersFunctionGenGaussian
GenGaussian 生成符合高斯/正态分布 (Gaussian/Normal Distribution) 的随机向量。 对应 Python: np.random.normal(loc=mean, scale=std, size=size) 输入: - size: 向量长度 (即 Flatten
pkg/mathutils/noise.go:47
↓ 7 callersFunctiondataset_split
r""" Randomly split a dataset into non-overlapping new datasets of given lengths. Arguments: dataset (Dataset): Dataset to be split
python_server/utils.py:132
↓ 6 callersMethodAttack
(sample Sample, model Model)
pkg/core/definitions.go:74
↓ 6 callersFunctionL2Distance
============================================================================ 距离度量工具库 (Distance Metrics) 对应 Python 库: foolbox.distances, numpy.linalg =
pkg/mathutils/distance.go:16
↓ 6 callersFunctionMeanAndStd
MeanAndStd 计算一组 float64 切片的均值 (Mean) 和样本标准差 (Sample Standard Deviation) 样本标准差使用 n-1 的自由度 (Bessel's correction)
pkg/mathutils/stats.go:125
↓ 6 callersFunctionSoftmax
Softmax 将 Logits (未归一化的分数) 转换为概率分布。 对应 Python: torch.nn.functional.softmax(dim=1) 公式: P_i = exp(x_i) / sum(exp(x_j)) 优化: 实现了 "Numerical Stability" (减去
pkg/mathutils/stats.go:92
↓ 6 callersFunctionprintVec
辅助函数:格式化打印向量
basic_test.go:28
↓ 6 callersFunctionvectorsEqual
辅助函数:用于比较两个浮点数切片是否相等(允许微小误差)
basic_test.go:13
↓ 5 callersFunctionCrossEntropy
============================================================================ 统计辅助工具库 (Statistical Helpers) 对应 Python: numpy (argmax, mean), torch.nn.f
pkg/mathutils/stats.go:15
↓ 5 callersFunctionNewHTTPClient
========================================== 2. 初始化:NewHTTPClient (对齐 main.go 的调用) ==========================================
pkg/client/http_client.go:50
↓ 4 callersFunctionClip
Clip 将向量中的每个元素限制在 [min, max] 范围内 对应 Python: np.clip (ART 中的 clip_image 核心)
pkg/mathutils/basic.go:70
↓ 4 callersFunctionNormalize
Normalize 将向量归一化为单位向量 (Unit Vector)。 对应 Python: v / np.linalg.norm(v) 用于将估算出来的梯度方向标准化。 注意:虽然中间计算用 float64 保证精度,但返回仍为 float32 以匹配 API 协议。
pkg/mathutils/geometry.go:28
↓ 4 callersFunctionVectorScale
VectorScale 向量与标量相乘 对应 Python: v * scalar (梯度缩放、步长控制)
pkg/mathutils/basic.go:60
↓ 4 callersFunctionapplyPreset
(cfg *runConfig, preset string)
main.go:172
↓ 4 callersFunctionnormalizeAuditMode
(mode string)
main.go:205
↓ 3 callersFunctionGenerateVariants
GenerateVariants 为原始图像生成指定数量的微扰变体(由 Member C 调用) 输入: - original: 原始图像 [0.1, 0.5, ...] - sigma: 扰动强度(标准差),通常取 0.001 - count: 需要生成的变体数量(通常为 10) 功能: 基于
pkg/mathutils/noise.go:98
↓ 3 callersMethodLoadBatch
1. LoadBatch: 顺序加载 (用于加载 1000 张审计目标图)
pkg/dataset/cifar10.go:18
↓ 3 callersFunctionpredict
(req: PredictRequest)
python_server/server.py:127
↓ 2 callersFunctionArgMax
ArgMax 找到切片中最大值的索引 (Index of Maximum Value)。 对应 Python: np.argmax(probs) 用途: 将模型输出的概率数组转换为具体的类别标签 (Label)。 例如: [0.1, 0.8, 0.1] -> 返回 1
pkg/mathutils/stats.go:36
↓ 2 callersFunctionInterpolate
Interpolate 执行线性插值 (Linear Interpolation)。 对应 Python: binary_search 中的中间点计算 公式: result = a + (b - a) * t 用于在“原图”和“对抗样本”之间寻找刚好能骗过模型的那个边界点。
pkg/mathutils/geometry.go:11
↓ 2 callersFunctionL2Norm
L2Norm 计算单个向量的 L2 范数 (模长)。 对应 Python: np.linalg.norm(v) 用于计算梯度的长度,或者在归一化向量时使用。
pkg/mathutils/distance.go:34
↓ 2 callersFunctionNewVector
NewVector 创建一个指定大小并填充特定值的向量 对应 Python: np.zeros, np.full
pkg/mathutils/basic.go:5
↓ 2 callersMethodPredict
Predict 返回最终标签 (Label-Only 基础功能)
pkg/core/definitions.go:61
↓ 2 callersMethodPredictBatch
PredictBatch 批量预测 (HSJA 涡轮增压)
pkg/core/definitions.go:64
↓ 2 callersFunctionVectorAdd
VectorAdd 两个向量对应元素相加 对应 Python: a + b (用于叠加噪声)
pkg/mathutils/basic.go:18
↓ 2 callersMethodbinarySearch
binarySearch refines an adversarial sample onto the decision boundary.
pkg/attack/hsja.go:112
↓ 2 callersFunctionbuildReport
(cfg runConfig, thresholds audit.AuditThresholds, results []core.AuditResult)
main.go:404
↓ 2 callersFunctioncheckHealth
(name, baseURL string)
main.go:661
↓ 2 callersFunctiondefaultConfig
()
main.go:128
↓ 2 callersFunctionrunAudit
(cfg runConfig)
main.go:476
↓ 2 callersFunctionwriteHTMLReport
(path string, report auditReport)
main.go:624
↓ 2 callersFunctionwriteJSONReport
(path string, report auditReport)
main.go:610
↓ 1 callersMethodAuditSample
(sample core.Sample)
pkg/audit/engine.go:41
↓ 1 callersFunctionCalibrateReference
CalibrateReference 计算路人集的统计基准,产出动态双阈值 (tau_d, tau_cv) 输入: dists 是一个二维切片,dists[i] 代表第 i 个路人图的 11 个测距值(1张原图 + 10个变体) 输出: tauD (距离阈值上限), tauCV (波动率/变异系数的
pkg/mathutils/stats.go:163
↓ 1 callersMethodGetRandomStrangers
2. GetRandomStrangers: 随机抽取 (用于现场定标,算出判定水位线) 对应任务:把路人图固定下来
pkg/dataset/cifar10.go:62
↓ 1 callersMethodLoadByIndices
(baseDir string, indices []int)
pkg/dataset/cifar10.go:108
↓ 1 callersFunctionMeanVector
MeanVector 计算一组向量的平均值向量。 对应 Python: np.mean(vectors, axis=0) 输入: 一个包含 n 个向量的切片 (Batch) 输出: 一个平均向量 用途: HopSkipJump 算法中,需要对多次随机扰动后的梯度估算值取平均,以消除噪声。
pkg/mathutils/stats.go:58
↓ 1 callersFunctionNewAuditPool
(e *audit.Engine, count int)
pkg/worker/pool.go:16
↓ 1 callersFunctionNewEngine
(t AuditThresholds, s, tg core.Model, atk core.Attacker)
pkg/audit/engine.go:37
↓ 1 callersFunctionNewHSJA
(cfg HSJAConfig)
pkg/attack/hsja.go:22
↓ 1 callersFunctionNewRelabeler
(m core.Model, batchSize int)
pkg/worker/relabel.go:14
↓ 1 callersMethodPredictBatch
PredictBatch: 批量预测标签 (用于 HSJA 涡轮增压)
pkg/client/http_client.go:117
↓ 1 callersMethodPredictLogits
PredictLogits: 获取原始分数 (用于算方案一的 Loss) —— 【这是你最需要的改动】
pkg/client/http_client.go:92
↓ 1 callersMethodPredictLogits
PredictLogits 返回原始概率/分数数组 (为了在 Go 本地算 Loss)
pkg/core/definitions.go:67
↓ 1 callersMethodRelabelAll
RelabelAll 使用“大卡车运输”模式,一次处理 128 张图
pkg/worker/relabel.go:19
↓ 1 callersMethodRunAudit
RunAudit 并发运行三段式审计逻辑 输入: 1000 个待审计样本 输出: 1000 个带红绿灯结论的审计报告
pkg/worker/pool.go:26
↓ 1 callersMethod__init__
(self, CNN_name, dataset, dropout=False)
python_server/classifier.py:28
↓ 1 callersMethod_make_layers
(self, cfg)
python_server/classifier.py:52
↓ 1 callersFunctionapplyStandardPreset
(cfg *runConfig)
main.go:160
↓ 1 callersMethodapproximateGradient
approximateGradient estimates the boundary normal with batched label queries.
pkg/attack/hsja.go:133
↓ 1 callersFunctionauditBoundaryOnlySample
(sample core.Sample, thresholds audit.AuditThresholds, hsja *attack.HSJA, targetModel *client.HTTPClient)
main.go:557
↓ 1 callersFunctioncalculate_thresholds
Calculate reference thresholds from boundary distance groups.
scripts/evaluation/eval.py:21
↓ 1 callersFunctioncalibrateThresholds
(cfg runConfig, thresholds *audit.AuditThresholds, hsja *attack.HSJA, targetModel *client.HTTPClient)
main.go:316
↓ 1 callersMethodcomputeDelta
(dist float32, iter int)
pkg/attack/hsja.go:174
↓ 1 callersMethodcomputeStepSize
(dist float32, iter int)
pkg/attack/hsja.go:181
↓ 1 callersFunctionevaluate_risk
Calculate a 0-100 membership risk score from boundary statistics.
scripts/evaluation/eval.py:57
↓ 1 callersMethodfusionLogic
(s1, s2 string)
pkg/audit/engine.go:140
↓ 1 callersFunctionget_losses_and_acc
(model, loader)
python_server/calc_thresholds.py:38
↓ 1 callersMethodinitialize
initialize searches for an initial sample that crosses the target boundary.
pkg/attack/hsja.go:97
↓ 1 callersFunctionisPredictedRisk
(conclusion string)
main.go:387
↓ 1 callersFunctionloadAuditSamples
(cfg runConfig)
main.go:353
↓ 1 callersFunctionloadConfigFromFlags
()
main.go:216
↓ 1 callersFunctionloadThresholds
(path string)
main.go:304
↓ 1 callersFunctionmain
()
scripts/evaluation/eval.py:84
↓ 1 callersFunctionmain
()
python_server/calc_thresholds.py:61
↓ 1 callersFunctionparse_args
()
scripts/evaluation/eval.py:13
↓ 1 callersFunctionprintSummary
(report auditReport)
main.go:648
↓ 1 callersMethodprobeAll
辅助函数微调:去掉原图合并,只跑变体
pkg/audit/engine.go:124
↓ 1 callersFunctionpublicListenURL
(addr string)
main.go:821
↓ 1 callersMethodrand_augment
Generate a set of distortions. Args: N: Number of augmentation transformations to apply sequentially. N is len(transforms)/
python_server/utils.py:209
↓ 1 callersFunctionriskLevel
(conclusion string)
main.go:391
↓ 1 callersMethodrotate_with_fill
(self, img, magnitude)
python_server/utils.py:228
↓ 1 callersFunctionrunBoundaryOnlySamples
(samples []core.Sample, cfg runConfig, thresholds audit.AuditThresholds, hsja *attack.HSJA, targetModel *clien
main.go:520
↓ 1 callersFunctionstartWebServer
(cfg runConfig, addr string)
main.go:684
MethodAttack
Attack estimates the distance from a sample to the target model decision boundary.
pkg/attack/hsja.go:42
FunctionClone
Clone 深拷贝一个向量,防止修改原数据 对应 Python: v.copy()
pkg/mathutils/basic.go:86
FunctionCosineSim
CosineSim 计算两个向量的余弦相似度。 用于评估梯度估算的准确性。
pkg/mathutils/geometry.go:69
MethodGetInputSize
()
pkg/client/http_client.go:147
MethodGetInputSize
()
pkg/core/definitions.go:69
FunctionL0Distance
L0Distance 计算两个向量之间的 L0 距离 (Hamming-like)。 对应 Python: np.count_nonzero(a != b) 统计有多少个像素点发生了变化(不考虑变化的幅度,只考虑是否变化)。 注意:由于浮点数精度问题,极小的差异也会被计入。
pkg/mathutils/distance.go:66
FunctionLinfDistance
LinfDistance 计算两个向量之间的切比雪夫距离 (L-infinity Distance)。 对应 Python: np.max(np.abs(a - b)) 即所有像素点中,差异最大的那个点的差异值。 常用于衡量对抗样本在 worst-case 下的扰动程度。
pkg/mathutils/distance.go:47
MethodPredict
========================================== 3. 核心功能实现 (实现 core.Model 接口) ========================================== Predict: 获取最终标签
pkg/client/http_client.go:71
FunctionProjectToSphere
ProjectToSphere 将向量投影到 L2 球面上。 用于限制扰动大小 (Epsilon)。 逻辑: 如果向量模长超过半径,则将其缩放到半径长度。
pkg/mathutils/geometry.go:48
FunctionSetSeed
SetSeed 设置随机数种子。 对应 Python: np.random.seed(seed) 用于复现实验结果。如果设置了相同的种子,生成的噪声序列将完全一致。
pkg/mathutils/noise.go:27
FunctionTestApplyPresetResetsFromSmokeToStandard
(t *testing.T)
basic_test.go:176
FunctionTestCalibrateReference
(t *testing.T)
basic_test.go:152
FunctionTestClip
(t *testing.T)
basic_test.go:104
FunctionTestClone
(t *testing.T)
basic_test.go:118
FunctionTestFullBenchmark
(t *testing.T)
bench_test.go:64
FunctionTestL2DistancePythonMatched
TestL2DistancePythonMatched 验证 Go 语言的 L2 计算和 Python np.linalg.norm 完全一致 (Task 13)
pkg/mathutils/l2_test.go:10
FunctionTestMeanAndStd
(t *testing.T)
basic_test.go:133
FunctionTestNewVector
(t *testing.T)
basic_test.go:32
FunctionTestVectorAdd
(t *testing.T)
basic_test.go:45
FunctionTestVectorMul
(t *testing.T)
basic_test.go:75
FunctionTestVectorScale
(t *testing.T)
basic_test.go:90
next →1–100 of 123, ranked by callers