Last active
August 29, 2015 14:13
-
-
Save digorithm/085d2f344d4fba5ca45b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.JFrame; | |
import org.math.plot.*; | |
public class GradientDescent{ | |
private double theta0; | |
private double theta1; | |
private int trendline; | |
// Algorithm settings | |
double alpha = 0.01; // learning rate | |
double tol = 1e-11; // tolerance to determine convergence | |
int maxiter = 9000; // maximum number of iterations in case convergence is not reached | |
int dispiter = 100; // interval for displaying results during iterations | |
int iters = 0; | |
//track of results | |
double[] theta0plot = new double[maxiter+1]; | |
double[] theta1plot = new double[maxiter+1]; | |
double[] tplot = new double[maxiter+1]; | |
InitialData initial_data; | |
Plot2DPanel plot; | |
public GradientDescent(InitialData id){ | |
//initial guesses | |
this.theta0 = 0; | |
this.theta1 = 0; | |
this.initial_data = id; | |
plot = new Plot2DPanel(); | |
plot.addScatterPlot("X-Y", initial_data.x, initial_data.y); | |
JFrame frame = new JFrame("Final X-Y Data"); | |
frame.setContentPane(plot); | |
frame.setSize(600, 600); | |
frame.setVisible(true); | |
} | |
[...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment