importfastlowessasflimportnumpyasnpimportmatplotlib.pyplotasplt# Simulate noisy time series with trendnp.random.seed(42)t=np.linspace(0,100,500)trend=10+0.5*t+3*np.sin(t/10)noise=np.random.normal(0,3,len(t))y=trend+noise# Extract trend with LOWESSresult=fl.smooth(t,y,fraction=0.1,iterations=3)# Plotplt.figure(figsize=(12,5))plt.plot(t,y,"gray",alpha=0.5,label="Observed")plt.plot(t,result["y"],"b-",lwd=2,label="Trend (LOWESS)")plt.xlabel("Time")plt.ylabel("Value")plt.legend()plt.title("Trend Extraction")plt.show()
usefastLowess::prelude::*;usendarray::Array1;lett:Array1<f64>=Array1::linspace(0.0,100.0,500);lety:Array1<f64>=/* your data */;letmodel=Lowess::new().fraction(0.1).iterations(3).adapter(Batch).build()?;letresult=model.fit(&t,&y)?;// result.y contains the trend
constfl=require('fastlowess');// t and y are your time series arrays (Float64Array)constresult=fl.smooth(t,y,{fraction:0.1,iterations:3});console.log("Extracted trend:",result.y);
import{smooth}from'fastlowess-wasm';constresult=smooth(t,y,{fraction:0.1,iterations:3});// Trend values in result.y
#include"fastlowess.hpp"std::vector<double>t=/* time points */;std::vector<double>y=/* values */;autoresult=fastlowess::smooth(t,y,{.fraction=0.1,.iterations=3});// Trend in result.yVector()
# Smooth to get trendresult=fl.smooth(t,y,fraction=0.3,iterations=3,return_residuals=True)trend=result["y"]detrended=result["residuals"]# Analyze residuals for seasonality, etc.plt.figure(figsize=(12,4))plt.subplot(1,2,1)plt.plot(t,trend)plt.title("Extracted Trend")plt.subplot(1,2,2)plt.plot(t,detrended)plt.title("Detrended (Residuals)")plt.tight_layout()
# Smooth to get trend and residualsresult=smooth(t,y,fraction=0.3,iterations=3,return_residuals=true)trend=result.ydetrended=result.residualsprintln("Detrended variance: ",var(detrended))
result=fl.smooth(t,y,fraction=0.2,iterations=3,confidence_intervals=0.95,prediction_intervals=0.95)# Plot with uncertainty bandsplt.figure(figsize=(12,5))plt.plot(t,y,"gray",alpha=0.3)plt.plot(t,result["y"],"b-",lwd=2,label="Trend")plt.fill_between(t,result["prediction_lower"],result["prediction_upper"],alpha=0.2,color="blue",label="95% Prediction")plt.legend()
letmodel=Lowess::new().fraction(0.2).iterations(3).confidence_intervals(0.95).prediction_intervals(0.95).adapter(Batch).build()?;letresult=model.fit(&t,&y)?;// Access result.prediction_lower and result.prediction_upper
result=smooth(t,y,fraction=0.2,iterations=3,confidence_intervals=0.95,prediction_intervals=0.95)# Intervals are available in result.prediction_lower/upperprintln("First point 95% PI: [$(result.prediction_lower[1]), $(result.prediction_upper[1])]")
import{smooth}from'fastlowess-wasm';constresult=smooth(t,y,{fraction:0.2,iterations:3,predictionIntervals:0.95});// Access result.predictionLower and result.predictionUpper
#include"fastlowess.hpp"autoresult=fastlowess::smooth(t,y,{.fraction=0.2,.iterations=3,.confidence_intervals=0.95,.prediction_intervals=0.95});// Access result.predictionLower and result.predictionUpper
# Irregular time points (gaps in data)t_irregular=np.sort(np.random.uniform(0,100,200))y_irregular=10+t_irregular*0.3+np.random.normal(0,2,200)# LOWESS handles this seamlesslyresult=fl.smooth(t_irregular,y_irregular,fraction=0.2)
// Irregular sampling - no special handling neededlett_irregular:Array1<f64>=/*sorted irregular times */;lety_irregular:Array1<f64>=/* corresponding values*/;letmodel=Lowess::new().fraction(0.2).adapter(Batch).build()?;letresult=model.fit(&t_irregular,&y_irregular)?;
# Irregular time points (gaps in data)t_irregular=sort(rand(200).*100.0)y_irregular=10.0.+t_irregular.*0.3.+randn(200).*2.0# LOWESS handles this seamlesslyresult=smooth(t_irregular,y_irregular,fraction=0.2)
constfl=require('fastlowess');// No special handling needed for irregular spacingconstresult=fl.smooth(tIrregular,yIrregular,{fraction:0.2});
letfractions=[0.05,0.2,0.5];forfinfractions{letmodel=Lowess::new().fraction(f).adapter(Batch).build()?;letresult=model.fit(&t,&y)?;// Store or plot result.y for each scale}
fractions=[0.05,0.2,0.5]results=[smooth(t,y,fraction=f)forfinfractions]# results[i].y contains smoothed values for each fraction