Package: jutility
jutilityCollection of Python utilities intended to be useful for machine learning research and experiments.ContentsjutilityContentsInstall withpipUsage examplesplottingMaking a simple plotMultiple lines in a single LineVector fields (with optional normalisation)Shared colour barutilsweepUnit testsBuild package locallyUpdating package on PyPIInstall withpipThejutilitypackage is available asa Python package on PyPI, and can be installed withpipusing the following commands:python -m pip install -U pip
python -m pip install -U jutilityUsage examplesplottingMaking a simple plotimportnumpyasnpfromjutilityimportplottingx=np.linspace(-10,10,100,dtype=np.float32)plotting.plot(plotting.Line(x,np.log(1+np.exp(x)),label="Softplus",c="b"),plotting.Line(x,np.maximum(x,0),label="ReLU",c="r",ls="--"),legend=True,plot_name="Softplus vs ReLU",dir_name="images",)importnumpyasnpfromjutilityimportplottingrng=np.random.default_rng(0)x=np.linspace(0,2)f=lambdax:x+0.1*rng.normal(size=x.shape)plotting.plot(plotting.Line(x,f(x),c="b",marker="o",label="Blue data"),plotting.Line(x,np.exp(-f(x)),c="r",marker="o",label="Red data"),axis_properties=plotting.AxisProperties("x label","y label"),legend=True,plot_name="Simple plot",dir_name="images",)Multiple lines in a single Lineimportnumpyasnpfromjutilityimportplotting,utiln=100batch_size=20rng=np.random.default_rng(0)noise=rng.normal(size=[n,batch_size])x=np.linspace(-1,4,n).reshape(n,1)y=np.exp(-x)+0.1*noiseplotting.plot(plotting.Line(x,y,alpha=0.2,c="b",zorder=10),plotting.Line(x,np.mean(y,axis=1),c="r",zorder=20),plot_name="Multiple lines in a single Line",dir_name="images",)Vector fields (with optional normalisation)importnumpyasnpfromjutilityimportplotting,utiln=25x=np.linspace(-2,2,n).reshape(1,n)y=np.linspace(-2,2,n).reshape(n,1)dx=y-xdy=x+ymp=plotting.MultiPlot(plotting.Subplot(plotting.Quiver(x,y,dx,dy,zorder=10,normalise=False),axis_properties=plotting.AxisProperties(title="normalise=False")),plotting.Subplot(plotting.Quiver(x,y,dx,dy,zorder=10,normalise=True),axis_properties=plotting.AxisProperties(title="normalise=True")),figure_properties=plotting.FigureProperties(figsize=[10,4]))mp.save(plot_name="Vector field",dir_name="images")Shared colour barimportnumpyasnpfromjutilityimportplottingrng=np.random.default_rng(0)z1=rng.random((100,200))+5z2=rng.random((100,200))+2v_min=min(z1.min(),z2.min())v_max=max(z1.max(),z2.max())colour_bar=plotting.ColourBar(v_min,v_max)mp=plotting.MultiPlot(plotting.ImShow(c=z1,vmin=v_min,vmax=v_max),colour_bar,plotting.ImShow(c=z2,vmin=v_min,vmax=v_max),colour_bar,figure_properties=plotting.FigureProperties(num_rows=2,num_cols=2,width_ratios=[1,0.2],tight_layout=False,title="Shared colour bar",),)mp.save("Shared colour bar",dir_name="images")More complex examples coming soonutilComing soonsweepComing soon(in the meantime, seescripts/make_logo.pywhich made the logo above, andunit testsforutil,plotting, andsweep)Unit testsTo run all unit tests, installpytest(these tests have previously been run withpytestversion 5.4.1), and run the following command (at the time of writing, this takes about 17 seconds to run 42 unit tests, because several unit tests involve saving images or GIFs to disk):pytestBuild package locallyjutilitycan be built and installed locally using the following commands, replacing$WHEEL_NAMEwith the name of the wheel built by thepython -m buildcommand (for example,jutility-0.0.5-py3-none-any.whl):python -m build
python -m pip install --force-reinstall --no-deps dist/$WHEEL_NAMEUpdating package on PyPIThis package was uploaded to PyPI followingthe Packaging Python Projects tutorial in the official Python documentation.To update PyPI with a newer version, update theversiontag insetup.cfg, and then use the following commands:rm -rf dist/*
python -m build
python -m twine upload dist/*When prompted bytwine, enter__token__as the username, and paste an API token from thePyPI account management webpageas the password (including thepypi-prefix).