Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Base infrastructure
  • Loading branch information
sas12028 committed Apr 20, 2017
1 parent fb63957 commit c6d1f00
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/BaseEvaluator.java
@@ -1,17 +1,20 @@

public class BaseEvaluator implements Evaluator{

WeightsParser wp;
// meant for beta to use
// when beta should use alpha's weights, have alpha commit to beta.csv and then call refreshWeights()

protected WeightsParser wp;
String file;
double[] weights;
protected double[] weights;

public BaseEvaluator(String file){
this.wp = new WeightsParser();
this.file = file;
this.weights = this.wp.getWeights(file);
}

private double dot(double[] a1, double[] a2){
private double dot(double[] a1, double[] a2){ // function for dot product
double res = 0;
for(int i = 0; i < a1.length; i++){
res += (a1[i] * a2[i]);
Expand All @@ -24,6 +27,10 @@ public class BaseEvaluator implements Evaluator{
return dot(this.weights, params);
}

public void refreshWeights(){
this.weights = this.wp.getWeights(this.file);
}


}

36 changes: 36 additions & 0 deletions src/LearningEvaluator.java
@@ -0,0 +1,36 @@
import java.util.ArrayList;
import org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression;

public class LearningEvaluator extends BaseEvaluator{

ArrayList<double[]> params;
ArrayList<Double> values;
double alpha; // learning parameter, higher alpha means weights are closer to the regression output
// alpha of 1 is directly setting weights to be regression weights
// ideally we start at 1 and lower alpha to get a convergence

public LearningEvaluator(String file, double alpha){
super(file);
params = new ArrayList<double[]>();
values = new ArrayList<Double>();
this.alpha = alpha;

}

public void setAlpha(double a){
alpha = a;
}

public void add_data(double[] features, double value){
values.add(value);
params.add(features);
}

public void commitWeights(String path){
this.wp.writeWeights(path, this.weights); // method to commit weights to beta. provide path to beta csv
}




}
3 changes: 3 additions & 0 deletions src/weights/alpha.csv
@@ -0,0 +1,3 @@
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10
10.0, 10.0, 10.0, 10.0, 10.0, 75.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0
10.0, 10.0, 10.0, 10.0, 10.0, 75.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0
1 change: 1 addition & 0 deletions src/weights/beta.csv
@@ -0,0 +1 @@
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10

0 comments on commit c6d1f00

Please sign in to comment.