Skip to content

Commit

Permalink
refactors biWeight to sqBiWeight and adds labels
Browse files Browse the repository at this point in the history
  • Loading branch information
jimbowring authored and jimbowring committed Mar 25, 2017
1 parent bf672a3 commit d2878fc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.cirdles.calamari.tasks.expressions.builtinExpressions.SquidExpressionMinus4;
import org.cirdles.calamari.tasks.expressions.customExpressions.CustomExpression_LnPbR_U;
import org.cirdles.calamari.tasks.expressions.customExpressions.CustomExpression_LnUO_U;
import org.cirdles.calamari.tasks.expressions.customExpressions.CustomExpression_Net204BiWt;
import org.cirdles.calamari.tasks.expressions.customExpressions.CustomExpression_Net204cts_sec;
import org.cirdles.calamari.tasks.expressions.parsing.ExpressionParser;
import org.cirdles.calamari.tasks.storedTasks.SquidBodorkosTask1;
Expand Down Expand Up @@ -100,6 +101,7 @@ public void initialize(URL url, ResourceBundle rb) {
CustomExpression_LnPbR_U.EXPRESSION,
CustomExpression_LnUO_U.EXPRESSION,
CustomExpression_Net204cts_sec.EXPRESSION,
CustomExpression_Net204BiWt.EXPRESSION,
SquidExpressionMinus1.EXPRESSION,
SquidExpressionMinus3.EXPRESSION,
SquidExpressionMinus4.EXPRESSION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class CustomExpression_Net204BiWt {
.addChild(0, new VariableNode(CustomExpression_Net204cts_sec.EXPRESSION.getName(),
"getTaskExpressionsEvaluationsPerSpotByField"));
((ExpressionTreeBuilderInterface) EXPRESSION).addChild(new ConstantNode("9", 9));
((ExpressionTreeBuilderInterface) EXPRESSION).setOperation(Function.biWeight());
((ExpressionTreeBuilderInterface) EXPRESSION).setOperation(Function.sqBiweight());

((ExpressionTree) EXPRESSION).setRootExpressionTree(true);
((ExpressionTree) EXPRESSION).setSquidSwitchSCSummaryCalculation(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public abstract class Function
protected String name;
protected int argumentCount;
protected int precedence;
// establish size of array resullting from evaluation
// establish size of array resulting from evaluation
protected int rowCount;
protected int colCount;
protected String[][] labelsForValues;

@Override
public void customizeXstream(XStream xstream) {
Expand All @@ -61,8 +62,8 @@ public static OperationOrFunctionInterface robReg() {
return new RobReg();
}

public static OperationOrFunctionInterface biWeight() {
return new Biweight();
public static OperationOrFunctionInterface sqBiweight() {
return new SqBiweight();
}

/**
Expand Down Expand Up @@ -162,4 +163,18 @@ public int getColCount() {
public void setColCount(int colCount) {
this.colCount = colCount;
}

/**
* @return the labelsForValues
*/
public String[][] getLabelsForValues() {
return labelsForValues;
}

/**
* @param labelsForValues the labelsForValues to set
*/
public void setLabelsForValues(String[][] labelsForValues) {
this.labelsForValues = labelsForValues;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.cirdles.calamari.tasks.expressions.functions;

import java.math.BigDecimal;
import java.util.List;
import org.cirdles.calamari.shrimp.ShrimpFractionExpressionInterface;
import org.cirdles.calamari.tasks.expressions.ExpressionTreeInterface;
Expand All @@ -24,36 +23,48 @@
*
* @author James F. Bowring
*/
public class Biweight extends Function {
public class SqBiweight extends Function {

public Biweight() {
name = "Biweight";
/**
* Provides the functionality of Squid's sqBiweight and biWt by calculating
* TukeysBiweight and returning mean, sigma, and 95% confidence and encoding
* the labels for each cell of the values array produced by eval2Array.
*
* @see
* https://raw.githubusercontent.com/CIRDLES/LudwigLibrary/master/vbaCode/squid2.5Basic/Resistant.bas
* @see
* https://raw.githubusercontent.com/CIRDLES/LudwigLibrary/master/vbaCode/squid2.5Basic/StringUtils.bas
*/
public SqBiweight() {
name = "sqBiweight";
argumentCount = 2;
precedence = 4;
rowCount = 1;
colCount = 2;
colCount = 3;
labelsForValues = new String[][]{{"Biwt Mean", "Biwt Sigma", "\u00B195%conf"}};
}

/**
* Requires that child 0 is a VariableNode that evaluates to a double array
* with one row and a column for each member of shrimpFractions and that
* child 1 is a ConstantNode that evaluates to an integer.
*
* @param childrenET the value of childrenET
* @param shrimpFractions the value of shrimpFraction
* @return the double[][]
* @param childrenET list containing child 0 and child 1
* @param shrimpFractions a list of shrimpFractions
* @return the double[1][3] array of mean, sigma, 95% confidence
*/
@Override
public double[][] eval2Array(
List<ExpressionTreeInterface> childrenET, List<ShrimpFractionExpressionInterface> shrimpFractions) {

double[][] retVal;
try {
// assume child 0 is a VariableNode
// assume child 1 is a number
double[][] variableValues = childrenET.get(0).eval2Array(shrimpFractions);
double [][] tuning = childrenET.get(1).eval2Array(shrimpFractions);
BigDecimal[] retValBD = org.cirdles.ludwig.TukeyBiweight.biweightMean(variableValues[0], tuning[0][0]);
retVal = new double[][]{{retValBD[0].doubleValue(), retValBD[1].doubleValue()}};
} catch (Exception e) {
retVal = new double[][]{{0.0, 0.0}};
double[][] tuning = childrenET.get(1).eval2Array(shrimpFractions);
double[][] tukeysBiweight = org.cirdles.ludwig.SquidMathUtils.tukeysBiweight(variableValues[0], tuning[0][0]);
retVal = new double[][]{{tukeysBiweight[0][0], tukeysBiweight[0][1], tukeysBiweight[0][2]}};
} catch (ArithmeticException e) {
retVal = new double[][]{{0.0, 0.0, 0.0}};
}

return retVal;
Expand All @@ -68,7 +79,7 @@ public double[][] eval2Array(
public String toStringMathML(List<ExpressionTreeInterface> childrenET) {
String retVal
= "<mrow>"
+ "<mi>RobReg</mi>"
+ "<mi>" + name + "</mi>"
+ "<mfenced>";

for (int i = 0; i < childrenET.size(); i++) {
Expand Down

0 comments on commit d2878fc

Please sign in to comment.