Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • d14115e
  • /
  • tensorly
  • /
  • metrics
  • /
  • tests
  • /
  • test_regression.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:f49060b5a02e7fa71b775a4afe2d2e606016e9d4
directory badge
swh:1:dir:ebef196ded594a32a4433fb1727b3fb0d8f99223

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
test_regression.py
import numpy as np
from ... import backend as T
from ..regression import MSE, RMSE, correlation

def test_MSE():
    """Test for MSE"""
    y_true = T.tensor([1, 0, 2, -2])
    y_pred = T.tensor([1, -1, 1, -1])
    true_mse = 0.75
    T.assert_array_almost_equal(MSE(y_true, y_pred), true_mse)

def test_RMSE():
    """Test for RMSE"""
    y_true = T.tensor([1, 0, 2, -2])
    y_pred = T.tensor([0, -1, 1, -1])
    true_mse = 1
    T.assert_array_almost_equal(MSE(y_true, y_pred), true_mse)

def test_correlation():
    """Test for correlation"""
    a = T.tensor(np.random.random(10))
    b = T.tensor(np.random.random(10))
    T.assert_array_almost_equal(correlation(a, a*2+1), 1)
    T.assert_array_almost_equal(correlation(a, -a*2+1), -1)
    
    a = T.tensor([1, 2, 3, 2, 1])
    b = T.tensor([1, 2, 3, 4, 5])
    T.assert_array_almost_equal(correlation(a, b), 0)

    a = T.tensor([[1, 2, 3, 2, 1]]*3)
    b = T.tensor([[1, 2, 3, 4, 5]]*3)
    res = T.tensor([0, 0, 0])
    T.assert_array_almost_equal(correlation(a, b, axis=1), res)


back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API