Skip to main content

surMSE

A loss function @PyTorch, that allows the target to be exceeded in the target direction. image

思路说明

允许输入与目标方向相同,但模长比目标大.此时损失为零.
因为神经网络经常表现出输出稍微不达目标的特性,通过减弱使输出接近零的梯度,尝试缓解这个问题.

Install

pip install surMSE

Use

from surMSE import surMSE
...
loss=surMSE(input,target,dim=None,scale=True,eps=1e-8,meanOut=True,haveBatch=True,protect=None)

dim表示在哪些维度上计算损失,一般开启除Batch维之外的全部维度.设定为None则自动计算.
dim=None,haveBatch=True时,自动排除首维.dim=None,haveBatch=False时在全部维度上计算.
scale控制是否根据target模长控制对应样本损失的增益,如果开启,将通过target模长给损失加权;如果关闭,在一半空间上将等效于MSE.
meanOut控制是否在返回前使用平均的方法合并"dim"参数指定外的剩余维度.如果不开启,取决于数据维度和dim设置,返回的tensor将不一定只有一个元素.
protect柔性防止损失值超越protect值的样本对总损失造成过大影响.设置为0关闭此功能,设置为None自动设置当前批次损失值的平均值作为protect值.

Metadata

Release files for surMSE 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for surMSE 0.0.3
File Size Uploaded Provenance Actions
surmse-0.0.3.tar.gz 8.1 kB With provenance Details for surmse-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for surMSE 0.0.3
File Interpreter ABI Platform Actions
surmse-0.0.3-py3-none-any.whl Python 3 none any Details for surmse-0.0.3-py3-none-any.whl

Total release size: 16.5 kB

Release files / surmse-0.0.3.tar.gz

Download URL surmse-0.0.3.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9d6c5d41a116604c03a33e954fe85b727da0bd13ba73c096cc8fc01a27658d37
BLAKE2b-256 checksum
How to use checksums
d4c886436fefd470c8f0b807e3074effbd72e57936319953e5fd601d6a8024d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / surmse-0.0.3-py3-none-any.whl

Download URL surmse-0.0.3-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40452471f203c989c5e09a7cf3fa83dacf94547dc02e34600db6d19e9469cca2
BLAKE2b-256 checksum
How to use checksums
967a70cc258329735bd6bac3a59a8c3edfa9441bb23eedabb0c39a4c09e253b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Security for surMSE 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for surmse-0.0.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page