# brandenesmith/piecewiseLinearApproximation

Simple go package to compute piecewise linear approximations of time series data.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
 Failed to load latest commit information. README.md max.go min.go piecewiseLinearApprox.go piecewiseLinearApprox_test.go slope.go toLaTeX.go types.go valueAtTime.go

# piecewiseLinearApproximation

A simple go package to compute piecewise linear approximations of time series data. Specifically, this package takes a time series data set of points {(t,y) | t and y are real numbers with t monotonically increasing} and creates a constraint relation of the data. The package provides a function to produce the constraint relation table in LaTeX.

# Using the Package

To use this package simply fork the repository to your go workspace then, from the command line, navigate to `\$GOPATH/src/piecewiseLinearApproximation` and run `go install`.

With this completed, navigate to `\$GOPATH/src` and create a new directory. In this directory create, a new file with a main function as shown below.

```package main

import (
"fmt"
p "piecewiseLinearApproximation"
)

func main() {
var timeSeries1 = []p.Pair {
p.Pair{0, 0},
p.Pair{1, 1},
p.Pair{2, 2},
p.Pair{3, 3},
}

var tollerance float64 = 2

equations := p.PiecewiseLinearApprox(timeSeries1, tollerance)

// Output the equations and their intervals to the standard output.
for i := 0; i < len(equations); i++ {
fmt.Printf("%s, %g <= t <= %g\n", equations[i].Expression,
equations[i].Interval.X, equations[i].Interval.Y)
}

fmt.Printf("\n\n")

// Output a latex table to the standard output.
p.ToLaTeX(equations, "Solution (b)")
}```