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
package GraphModels; | |
/** | |
* | |
* @author rodrigo | |
*/ | |
public class Vertex { | |
/* This Data Structure will be capable to represent a Vertex, |
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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package GraphModels; | |
/** | |
* |
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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package GraphModels; | |
import java.io.BufferedReader; | |
import java.io.FileNotFoundException; |
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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package graphproject; | |
import GraphModels.*; | |
import java.io.IOException; | |
import java.util.ArrayList; |
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 InitialData{ | |
public static double[] x = {2, 4, 6, 8}; | |
public static double[] y = {2, 5, 5, 8}; | |
public void plotData(){ | |
Plot2DPanel plot = new Plot2DPanel(); |
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 |
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
public double hypothesisFunction(double x){ | |
return this.theta1*x + theta0; | |
} |
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
public double deriveTheta1(){ | |
double sum = 0; | |
for (int j=0; j<initial_data.x.length; j++){ | |
sum += (initial_data.y[j] - hypothesisFunction(initial_data.x[j])) * initial_data.x[j]; | |
} | |
return -2 * sum / initial_data.x.length; | |
} | |
public double deriveTheta0(){ |
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
public void execute(){ | |
do { | |
this.theta1 -= alpha * deriveTheta1(); | |
this.theta0 -= alpha * deriveTheta0(); | |
//used for plotting | |
tplot[iters] = iters; | |
theta0plot[iters] = theta0; | |
theta1plot[iters] = theta1; |
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
public void addTrendLine(Plot2DPanel plot, boolean removePrev){ | |
if (removePrev){ | |
plot.removePlot(trendline); | |
} | |
double[] yEnd = new double[initial_data.x.length]; | |
for (int i=0; i<initial_data.x.length; i++) | |
yEnd[i] = hypothesisFunction(initial_data.x[i]); | |
trendline = plot.addLinePlot("final", initial_data.x, yEnd); | |
} |
OlderNewer