Instructions to use Zipeng365/WISP with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use Zipeng365/WISP with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("Zipeng365/WISP", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
Download tests/test_cis_features.py from Zipeng365/WISP: direct link, hf CLI and curl.
- Browser
- Download file 2.85 kB
-
https://huggingface.co/Zipeng365/WISP/resolve/main/tests/test_cis_features.py
- Command line
-
hf download hf://Zipeng365/WISP/tests/test_cis_features.py
-
curl -L -o test_cis_features.py https://huggingface.co/Zipeng365/WISP/resolve/main/tests/test_cis_features.py
2.85 kB
| """Backends for faithful finite normalization, ACF, symbolic thresholds and rank queries.""" | |
| import unittest | |
| from unittest.mock import patch | |
| import warnings | |
| import numpy as np | |
| from wisp_fast import features as fx | |
| class FaithfulCIS(unittest.TestCase): | |
| def test_normalization_acf(self): | |
| rng=np.random.default_rng(643) | |
| for t in (1,7,8,9,127,128,129,160,257,2049): | |
| for c in (1,2,3,7): | |
| x=rng.normal(size=(4,t,c));x[1]=3e4;x[2]=np.rint(x[2]) | |
| x[3,::3,0]=-0. | |
| ref=fx.ref._safe_zscore_per_window(x) | |
| np.testing.assert_array_equal(fx._normalize(x),ref) | |
| lags=(1,0,t,3,7,1) | |
| np.testing.assert_array_equal(fx._autocorr(x,lags),fx.ref._autocorr_features(x,lags)) | |
| neg=np.full((2,129,1),-0.) | |
| self.assertEqual(fx._normalize(neg).tobytes(),fx.ref._safe_zscore_per_window(neg).tobytes()) | |
| neg[:,::2]=0. | |
| self.assertEqual(fx._autocorr(neg,(1,2)).tobytes(),fx.ref._autocorr_features(neg,(1,2)).tobytes()) | |
| x=np.array([[[np.nan,0],[np.inf,1],[2,3]],[[0,1],[0,2],[0,3]]]) | |
| with warnings.catch_warnings(): | |
| warnings.simplefilter("ignore", RuntimeWarning) | |
| np.testing.assert_array_equal(fx._normalize(x),fx.ref._safe_zscore_per_window(x)) | |
| with self.assertRaises(ValueError):fx._family_kernels.normalize(ref,ref) | |
| with self.assertRaises(ValueError):fx._family_kernels.autocorr(ref,(1,),ref) | |
| def test_range_select_boundaries_and_degenerate(self): | |
| rng=np.random.default_rng(137) | |
| for t in (17,63,64,65,127,128,129,160,255,256,257): | |
| x=np.round(rng.normal(size=(5,t,3)),1);x[0,:,:]=1.25 | |
| x[1,:,0]=np.linspace(0,100,t);x[2,::2,1]=-0. | |
| for turbo in (True,False): | |
| m=fx.IntervalDistributionSketch(n_random_intervals=17,quantiles=(0.,.1,.25,.5,.75,.9,1.), | |
| fast_profile=turbo,zscore=False,random_state=7).fit(x) | |
| m.intervals_.extend([(0,t),(0,1),(t-1,t),(1,t-1)]) | |
| got=m.transform_normalized(x) | |
| with patch.object(fx,"_cis_intervals",None): | |
| reference=m.transform_normalized(x) | |
| np.testing.assert_array_equal(got,reference) | |
| def test_short_sort_respects_ties(self): | |
| rng=np.random.default_rng(66) | |
| for t in (8,32,127,256,512,513): | |
| v=np.round(rng.normal(size=(4,t,3)),1);v[0]=-.0 | |
| z=fx._symbolic_bundle([("ch",v)],6)["ch"] | |
| np.testing.assert_array_equal(z,fx._state_counts(v,6)) | |