import%20marimo%0A%0A__generated_with%20%3D%20%220.18.4%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20plotly.graph_objects%20as%20go%0A%0A%20%20%20%20import%20palb_py%20as%20palb%0A%20%20%20%20return%20go%2C%20np%2C%20palb%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20%23%20Generate%20some%20random%20data%0A%20%20%20%20xs%20%3D%20np.linspace(-1%2C%201%2C%20100_000)%0A%20%20%20%20ys_true%20%3D%20-4%20*%20xs%20-%202%0A%20%20%20%20ys_noisy%20%3D%20ys_true%20%2B%20np.random.default_rng().laplace(0%2C%201%2C%20size%3Dxs.shape)%0A%20%20%20%20return%20xs%2C%20ys_noisy%2C%20ys_true%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20palb%2C%20xs%2C%20ys_noisy)%3A%0A%20%20%20%20%23%20use%20palb%20to%20fit%20a%20least%20absolute%20deviations%20line%0A%20%20%20%20slope%2C%20intercept%20%3D%20palb.l1line_xy(xs%2C%20ys_noisy).to_slope_intercept()%0A%20%20%20%20%23%20alternatively%2C%20if%20you%20have%20your%20data%20in%20an%20N%20by%202%20array%2C%20you%20can%20also%20use%20that%20directly%0A%20%20%20%20points%20%3D%20np.array(%5Bxs%2C%20ys_noisy%5D).T%0A%20%20%20%20slope%2C%20intercept%20%3D%20palb.l1line(points).to_slope_intercept()%0A%20%20%20%20return%20intercept%2C%20slope%0A%0A%0A%40app.cell%0Adef%20_(go%2C%20intercept%2C%20np%2C%20slope%2C%20xs%2C%20ys_noisy%2C%20ys_true)%3A%0A%20%20%20%20%23%20Plot%20ground%20truth%2C%20noisy%20data%2C%20and%20predicted%20line%0A%20%20%20%20xs_plot%20%3D%20np.linspace(xs%5B0%5D%2C%20xs%5B-1%5D%2C%20num%3D2)%0A%20%20%20%20fig%20%3D%20go.Figure(%0A%20%20%20%20%20%20%20%20data%3D%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20go.Scattergl(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20x%3Dxs%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20y%3Dys_noisy%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mode%3D%22markers%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20name%3D%22Noisy%20Data%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20marker%3Ddict(size%3D2)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20go.Scattergl(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20x%3Dxs_plot%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20y%3Dslope%20*%20xs_plot%20%2B%20intercept%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mode%3D%22lines%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20name%3D%22Predicted%20Line%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(width%3D4)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20go.Scattergl(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20x%3Dxs%5B%5B0%2C%20-1%5D%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20y%3Dys_true%5B%5B0%2C%20-1%5D%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mode%3D%22lines%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20name%3D%22True%20Line%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(width%3D4%2C%20dash%3D%22dash%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20fig%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
b82c823f0e068416e3d45934defc34c2