Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User aggregators #95

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
917e118
Merge branch 'master' into boa_evaluator
Jan 31, 2017
a6e1c3d
Initial commit for User Defined Aggregation support
Feb 1, 2017
a31e918
Fixing bug : Only one user defined aggregator runs in the presence of…
Feb 2, 2017
e4b0f05
REmoving unnecessary prints
Feb 2, 2017
ba6b2ff
Fixing a bug: Filter non aggregator functions from list
Feb 2, 2017
1829489
Merge branch 'boa_evaluator' into user_Aggregators
Feb 2, 2017
de27178
Fixing a test case as code generation has change.
Feb 2, 2017
a7fd7b6
Updating latest code generation string template.
Feb 2, 2017
81e8f37
Fixing bug in UserDefinedCode generating process. Fixing fullyqualifi…
Feb 3, 2017
2972425
adding naive bayes exmaple using user defined aggragation
Feb 3, 2017
b161ab2
Allowing creation of arrays of nested and complex types
Feb 12, 2017
81af781
Adding capability to convert a tuple into array if possible. If tuple…
Feb 12, 2017
3295b15
code for matrix transpose, inverse, summation and substraction suppor…
Feb 13, 2017
a05a385
Adding machine learning examples codes in test directory
Feb 14, 2017
ff5b37b
Adding matrix operations
Feb 14, 2017
6b6aa9f
Fixing bug in getCol method in matrix operations
Feb 15, 2017
0da11ef
linear regression optimized and unoptimized code
Feb 18, 2017
737060d
adding neural network withour back propogation
Feb 19, 2017
db0a04f
Changes in MatrixOperations and Adding Print facility for debugging H…
Feb 19, 2017
98eb3ac
removing merge conflicts
Feb 19, 2017
fb23150
adding back propogation in neural
Feb 20, 2017
491adfc
adding pca
Feb 21, 2017
72711ce
adding optimized pca
Feb 22, 2017
edf12ff
adding new machine learning algorCithms
Feb 22, 2017
656775d
Adding changes to support options as user defined aggregations
Feb 26, 2017
e691a5b
Changes to support serialization of ml model in Boa
Feb 26, 2017
390fc86
Storing the class as part of model
Feb 26, 2017
6ecf209
Adding serialization support for the model using simple json
Feb 26, 2017
fec8ee8
adding support for loading ml model
Feb 27, 2017
739eb3c
Allowing options in user defined aggregator class
Mar 2, 2017
459000f
adding training model usage
Mar 3, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding changes to support options as user defined aggregations
  • Loading branch information
nmtiwari committed Feb 26, 2017
commit 656775d8a77984fd8bbac07df50d9333b052c573
31 changes: 30 additions & 1 deletion src/java/boa/compiler/UserDefinedAgg.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package boa.compiler;


import boa.compiler.ast.statements.VarDeclStatement;
import boa.compiler.ast.types.AbstractType;
import org.stringtemplate.v4.ST;
import org.stringtemplate.v4.STGroup;
import org.stringtemplate.v4.STGroupFile;

import java.util.ArrayList;
import java.util.List;

public class UserDefinedAgg {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class needs a proper name: UserDefinedAggregator

private final String userGivenName;
private final String code;
Expand Down Expand Up @@ -34,7 +40,28 @@ public static class Builder {
private String userGivenFuncArg = null; // user given param names
private String funcArgType = null; // funcVarName of the compiler generated userGivenParams
private boolean isAggregator = false;
private String assignedToVar;
private List<String> aggregatorOptionParamId = new ArrayList<String>();
private List<String> aggregatorOptionParamInitializer = new ArrayList<String>();
private List<AbstractType> aggregatorOutputParamTypes = new ArrayList<AbstractType>();


public List<String> getAggregatorOptionParamId() {
return aggregatorOptionParamId;
}

public boolean addAggregatorOptionParamId(String code, int index) {
return this.aggregatorOptionParamId.add(aggregatorOutputParamTypes.get(index).type.toJavaType() + " " + code + ";\n");
}

public boolean addAggregatorOptionParamInitializer(String initializer) {
return this.aggregatorOptionParamInitializer.add(initializer);
}

public void setAggregatorOptionParamType(List<VarDeclStatement> params) {
for(VarDeclStatement stmt: params) {
this.aggregatorOutputParamTypes.add(stmt.getType());
}
}

public UserDefinedAgg build(){
return new UserDefinedAgg(this.funcVarName, this.generateCode());
Expand Down Expand Up @@ -129,6 +156,7 @@ private String generateCode() {
st.add("lambdaType", this.lambdaType);
st.add("lambdaName", this.lambdaName);
st.add("interface", fulQualifiedNameGne(this.lambdaInterface));
st.add("aggParams", getAggregatorOptionParamId());
if(this.funcArgType != null) {
st.add("funcArg", fulQualifiedNameGne(funcArgType));
}else {
Expand Down Expand Up @@ -197,5 +225,6 @@ private String typeParser(String typeName) {
}
return result;
}

}
}
14 changes: 14 additions & 0 deletions src/java/boa/compiler/ast/types/OutputType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import boa.compiler.ast.Component;
import boa.compiler.ast.Identifier;
import boa.compiler.ast.expressions.Expression;
import boa.compiler.ast.statements.VarDeclStatement;
import boa.compiler.visitors.AbstractVisitor;
import boa.compiler.visitors.AbstractVisitorNoArg;
import boa.compiler.visitors.AbstractVisitorNoReturn;
Expand All @@ -35,6 +36,7 @@ public class OutputType extends AbstractType {
protected Identifier id;
protected final List<Expression> args = new ArrayList<Expression>();
protected final List<Component> indices = new ArrayList<Component>();
protected final List<VarDeclStatement> params = new ArrayList<VarDeclStatement>();
protected Component t;
protected Component weight;

Expand Down Expand Up @@ -72,6 +74,18 @@ public void setArgs(final List<Expression> args) {
}
}

public void setParams(final List<VarDeclStatement> params) {
this.params.clear();
for (final VarDeclStatement e : params) {
e.setParent(this);
this.params.add(e);
}
}

public List<VarDeclStatement> getParams() {
return params;
}

public List<Component> getIndices() {
return indices;
}
Expand Down
14 changes: 14 additions & 0 deletions src/java/boa/compiler/visitors/CodeGeneratingVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public void visit(final VarDeclStatement n) {
UserDefinedAgg.Builder function = UserDefinedAggregators.findByUserGivenName(((OutputType)n.getType()).getId().getToken());
if(function != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems odd to set this here - shouldnt it already be set when it is found and returned?

function.isAggregator(true);
function.setAggregatorOptionParamType(((OutputType)n.getType()).getParams());
}
return;
}
Expand Down Expand Up @@ -839,6 +840,7 @@ public void visit(final Factor n) {
String accept = "";
abortGeneration = false;

n.env.setOperandType(n.getOperand().type);
if (!(n.getOp(0) instanceof Call)) {
n.getOperand().accept(this);
n.env.setOperandType(n.getOperand().type);
Expand Down Expand Up @@ -1370,6 +1372,18 @@ public void visit(final VarDeclStatement n) {
n.getInitializer().accept(this);
function.lambdaInit(code.removeLast());
}
if(n.getType() instanceof OutputType) {
function = UserDefinedAggregators.findByUserGivenName(((OutputType) n.getType()).getId().getToken());
if(function != null) {
int counter = 0;
for(VarDeclStatement stmt: ((OutputType) n.getType()).getParams()) {
stmt.accept(this);
String[] argCode = code.removeLast().split("=");
function.addAggregatorOptionParamId(argCode[0], counter++);
function.addAggregatorOptionParamInitializer(argCode[1]);
}
}
}
code.add("");
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/java/boa/compiler/visitors/TypeCheckingVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,10 @@ public void visit(final OutputType n, final SymbolTable env) {
if (n.getArgsSize() > 0 && annotation.formalParameters().length == 0)
throw new TypeCheckException(n.getArgs(), "output aggregator '" + n.getId().getToken() + "' takes no arguments");

for(VarDeclStatement stmt: n.getParams()) {
stmt.accept(this, env);
}

n.type = new BoaTable(type, indexTypes, tweight, annotation.canOmitWeight());
env.set(n.getId().getToken(), n.type);
n.getId().accept(this, env);
Expand Down
Loading