Skip to content

Commit

Permalink
minor bug fixes and more unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlizeng committed Sep 11, 2014
1 parent 9971a53 commit 24b1020
Show file tree
Hide file tree
Showing 57 changed files with 536 additions and 834 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ notifications:
email: false
before_install:
- sudo add-apt-repository ppa:staticfloat/julia-deps -y
- sudo add-apt-repository ppa:staticfloat/julianightlies -y
- sudo add-apt-repository ppa:staticfloat/juliareleases -y
- sudo apt-get update -qq -y
- sudo apt-get install libpcre3-dev julia -y
script:
- julia -e 'Pkg.init(); run(`ln -s $(pwd()) $(Pkg.dir("LinearLeastSquares"))`); Pkg.pin("LinearLeastSquares"); Pkg.resolve()'
- julia -e 'using LinearLeastSquares; @assert isdefined(:LinearLeastSquares); @assert typeof(LinearLeastSquares) === Module'
- julia --code-coverage test/runtests.jl
after_success:
- julia -e 'cd(Pkg.dir("LinearLeastSquares")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.2+
julia 0.3

45 changes: 0 additions & 45 deletions examples/regression.jl

This file was deleted.

22 changes: 22 additions & 0 deletions examples/regression/data.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Gadfly

# Set the random seed to get consistent data
srand(1)

# Number of examples to use
n = 100

# Specify the true value of the variable
true_coeffs = [2; -2; 0.5];

# Generate data
x_data = rand(n, 1) * 5;
x_data_expanded = hcat([x_data .^ i for i in 1 : 3]...)
y_data = x_data_expanded * true_coeffs + 0.5 * rand(n, 1)


p = plot(
x=x_data, y=y_data, Geom.point,
Theme(panel_fill=color("white"))
)
draw(PNG("data.png", 16cm, 12cm), p)
Binary file added examples/regression/data.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions examples/regression/linear_regression.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Simple Linear Regression
# Originally written by Keegan Go for lsqpy
# Translated into LinearLeastSquares.jl by Karanveer Mohan and David Zeng

using LinearLeastSquares
using Gadfly
# Set the random seed to get consistent data
srand(1)

# Number of examples to use
n = 100

# Specify the true value of the variable
true_coeffs = [2; -2; 0.5]

# Generate data
x_data = rand(n) * 5
x_data_expanded = hcat([x_data .^ i for i in 1 : 3]...)
y_data = x_data_expanded * true_coeffs + 0.5 * rand(n)

slope = Variable()
offset = Variable()
line = offset + x_data * slope
residuals = line - y_data
error = sum_squares(residuals)
optval = minimize!(error)

# plot the data and the line
t = [0; 5; 0.1]
p = plot(
layer(x=x_data, y=y_data, Geom.point),
layer(x=t, y=evaluate(slope) * t + evaluate(offset), Geom.line),
Theme(panel_fill=color("white"))
)
# draw(PNG("linear_regression.png", 16cm, 12cm), p)
Binary file added examples/regression/linear_regression.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,37 @@
# Translated into LinearLeastSquares.jl by Karanveer Mohan and David Zeng

using LinearLeastSquares
using Gadfly
# Set the random seed to get consistent data
srand(1)

# Number of examples to use
n = 100

# Specify the true value of the variable
true_coeffs = [2; -2; 0.5];
true_coeffs = [2; -2; 0.5]

# Generate data
x_data = rand(n, 1) * 5
x_data_expanded = hcat([x_data .^ i for i in 1 : 3]...)
y_data = x_data_expanded * true_coeffs + 0.5 * rand(n, 1)

quadratic_coeff = Variable();
slope = Variable();
offset = Variable();
quadratic = offset + x_data * slope + quadratic_coeff * x_data .^ 2;
residuals = quadratic - y_data;
error = sum_squares(residuals);
optval = minimize!(error);
quadratic_coeff = Variable()
slope = Variable()
offset = Variable()
quadratic = offset + x_data * slope + quadratic_coeff * x_data .^ 2
residuals = quadratic - y_data
error = sum_squares(residuals)
optval = minimize!(error)

# Create some evenly spaced points for plotting, again replicate powers
t = reshape([0 : 0.1 : 5], length([0 : 0.1 : 5]), 1);
t_squared = t .^ 2;
t = reshape([0 : 0.1 : 5], length([0 : 0.1 : 5]), 1)
t_squared = t .^ 2

# Plot our regressed function
plt.plot(x_data, y_data, "ro")
plt.plot(t, evaluate(offset) + t * evaluate(slope) + t_squared * evaluate(quadratic_coeff), "b")
plt.xlabel("x")
plt.ylabel("y")
plt.show()
p = plot(
layer(x=x_data, y=y_data, Geom.point),
layer(x=t, y=evaluate(offset) + t * evaluate(slope) + t_squared * evaluate(quadratic_coeff), Geom.line),
Theme(panel_fill=color("white"))
)
# draw(PNG("quadratic_regression.png", 16cm, 12cm), p)
Binary file added examples/regression/quadratic_regression.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 0 additions & 34 deletions examples/simple_classifier.jl

This file was deleted.

18 changes: 0 additions & 18 deletions examples/simple_lin_and_quad_reg/data.jl

This file was deleted.

Binary file removed examples/simple_lin_and_quad_reg/data.png
Binary file not shown.
Binary file removed examples/simple_lin_and_quad_reg/linear.png
Binary file not shown.
34 changes: 0 additions & 34 deletions examples/simple_lin_and_quad_reg/linear_regression.jl

This file was deleted.

Binary file removed examples/simple_lin_and_quad_reg/quadratic.png
Binary file not shown.

0 comments on commit 24b1020

Please sign in to comment.