repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
partition
stringclasses
1 value
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/svm/PlattSMO.java
PlattSMO.decisionFunctionR
protected double decisionFunctionR(int v) { double sum = 0; for (int i = 0; i < vecs.size(); i++) if (alphas[i] != alpha_s[i])//multipler would be zero sum += (alphas[i] - alpha_s[i]) * kEval(v, i); return sum; }
java
protected double decisionFunctionR(int v) { double sum = 0; for (int i = 0; i < vecs.size(); i++) if (alphas[i] != alpha_s[i])//multipler would be zero sum += (alphas[i] - alpha_s[i]) * kEval(v, i); return sum; }
[ "protected", "double", "decisionFunctionR", "(", "int", "v", ")", "{", "double", "sum", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "vecs", ".", "size", "(", ")", ";", "i", "++", ")", "if", "(", "alphas", "[", "i", "]", "!...
Returns the local decision function for regression training purposes without the bias term @param v the index of the point to select @return the decision function output sans bias
[ "Returns", "the", "local", "decision", "function", "for", "regression", "training", "purposes", "without", "the", "bias", "term" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/svm/PlattSMO.java#L1063-L1071
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/svm/PlattSMO.java
PlattSMO.setEpsilon
public void setEpsilon(double epsilon) { if(Double.isNaN(epsilon) || Double.isInfinite(epsilon) || epsilon <= 0) throw new IllegalArgumentException("epsilon must be in (0, infty), not " + epsilon); this.epsilon = epsilon; }
java
public void setEpsilon(double epsilon) { if(Double.isNaN(epsilon) || Double.isInfinite(epsilon) || epsilon <= 0) throw new IllegalArgumentException("epsilon must be in (0, infty), not " + epsilon); this.epsilon = epsilon; }
[ "public", "void", "setEpsilon", "(", "double", "epsilon", ")", "{", "if", "(", "Double", ".", "isNaN", "(", "epsilon", ")", "||", "Double", ".", "isInfinite", "(", "epsilon", ")", "||", "epsilon", "<=", "0", ")", "throw", "new", "IllegalArgumentException",...
Sets the epsilon for the epsilon insensitive loss when performing regression. This variable has no impact during classification problems. For regression problems, any predicated value that is within the epsilon of the target will be treated as "correct". Increasing epsilon usually decreases the number of support vectors, but may reduce the accuracy of the model @param epsilon the positive value for the acceptable error when doing regression
[ "Sets", "the", "epsilon", "for", "the", "epsilon", "insensitive", "loss", "when", "performing", "regression", ".", "This", "variable", "has", "no", "impact", "during", "classification", "problems", ".", "For", "regression", "problems", "any", "predicated", "value"...
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/svm/PlattSMO.java#L1213-L1218
train
EdwardRaff/JSAT
JSAT/src/jsat/regression/RANSAC.java
RANSAC.setMaxPointError
public void setMaxPointError(double maxPointError) { if(maxPointError < 0 || Double.isInfinite(maxPointError) || Double.isNaN(maxPointError)) throw new ArithmeticException("The error must be a positive value, not " + maxPointError ); this.maxPointError = maxPointError; }
java
public void setMaxPointError(double maxPointError) { if(maxPointError < 0 || Double.isInfinite(maxPointError) || Double.isNaN(maxPointError)) throw new ArithmeticException("The error must be a positive value, not " + maxPointError ); this.maxPointError = maxPointError; }
[ "public", "void", "setMaxPointError", "(", "double", "maxPointError", ")", "{", "if", "(", "maxPointError", "<", "0", "||", "Double", ".", "isInfinite", "(", "maxPointError", ")", "||", "Double", ".", "isNaN", "(", "maxPointError", ")", ")", "throw", "new", ...
Each data point not in the initial training set will be tested against. If a data points error is sufficiently small, it will be added to the set of inliers. @param maxPointError the new maximum error a data point may have to be considered an inlier.
[ "Each", "data", "point", "not", "in", "the", "initial", "training", "set", "will", "be", "tested", "against", ".", "If", "a", "data", "points", "error", "is", "sufficiently", "small", "it", "will", "be", "added", "to", "the", "set", "of", "inliers", "." ...
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/regression/RANSAC.java#L258-L263
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/boosting/LogitBoost.java
LogitBoost.P
protected double P(DataPoint x) { /** * F(x) * e * p(x) = --------------- * F(x) - F(x) * e + e */ double fx = F(x); double efx = Math.exp(fx); double enfx = Math.exp(-fx); if(Double.isInfinite(efx) && efx > 0 && enfx < 1e-15)//Well classified point could return a Infinity which turns into NaN return 1.0; return efx/(efx + enfx); }
java
protected double P(DataPoint x) { /** * F(x) * e * p(x) = --------------- * F(x) - F(x) * e + e */ double fx = F(x); double efx = Math.exp(fx); double enfx = Math.exp(-fx); if(Double.isInfinite(efx) && efx > 0 && enfx < 1e-15)//Well classified point could return a Infinity which turns into NaN return 1.0; return efx/(efx + enfx); }
[ "protected", "double", "P", "(", "DataPoint", "x", ")", "{", "/**\n * F(x)\n * e\n * p(x) = ---------------\n * F(x) - F(x)\n * e + e\n */", "double", "fx", "=", "F", "(", "x", ")", ";", ...
Returns the probability that a given data point belongs to class 1 @param x the data point in question @return P(y = 1 | x)
[ "Returns", "the", "probability", "that", "a", "given", "data", "point", "belongs", "to", "class", "1" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/boosting/LogitBoost.java#L195-L210
train
EdwardRaff/JSAT
JSAT/src/jsat/lossfunctions/LogisticLoss.java
LogisticLoss.loss
public static double loss(double pred, double y) { final double x = -y * pred; if (x >= 30)//as x -> inf, L(x) -> x. At 30 exp(x) is O(10^13), getting unstable. L(x)-x at this value is O(10^-14), also avoids exp and log ops return x; else if (x <= -30) return 0; return log(1 + exp(x)); }
java
public static double loss(double pred, double y) { final double x = -y * pred; if (x >= 30)//as x -> inf, L(x) -> x. At 30 exp(x) is O(10^13), getting unstable. L(x)-x at this value is O(10^-14), also avoids exp and log ops return x; else if (x <= -30) return 0; return log(1 + exp(x)); }
[ "public", "static", "double", "loss", "(", "double", "pred", ",", "double", "y", ")", "{", "final", "double", "x", "=", "-", "y", "*", "pred", ";", "if", "(", "x", ">=", "30", ")", "//as x -> inf, L(x) -> x. At 30 exp(x) is O(10^13), getting unstable. L(x)-x at ...
Computes the logistic loss @param pred the predicted value @param y the true value @return the logistic loss
[ "Computes", "the", "logistic", "loss" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/lossfunctions/LogisticLoss.java#L30-L38
train
EdwardRaff/JSAT
JSAT/src/jsat/lossfunctions/LogisticLoss.java
LogisticLoss.deriv
public static double deriv(double pred, double y) { final double x = y * pred; if (x >= 30) return 0; else if (x <= -30) return y; return -y / (1 + exp(y * pred)); }
java
public static double deriv(double pred, double y) { final double x = y * pred; if (x >= 30) return 0; else if (x <= -30) return y; return -y / (1 + exp(y * pred)); }
[ "public", "static", "double", "deriv", "(", "double", "pred", ",", "double", "y", ")", "{", "final", "double", "x", "=", "y", "*", "pred", ";", "if", "(", "x", ">=", "30", ")", "return", "0", ";", "else", "if", "(", "x", "<=", "-", "30", ")", ...
Computes the first derivative of the logistic loss @param pred the predicted value @param y the true value @return the first derivative of the logistic loss
[ "Computes", "the", "first", "derivative", "of", "the", "logistic", "loss" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/lossfunctions/LogisticLoss.java#L47-L56
train
EdwardRaff/JSAT
JSAT/src/jsat/lossfunctions/LogisticLoss.java
LogisticLoss.deriv2
public static double deriv2(double pred, double y) { final double x = y * pred; if (x >= 30) return 0; else if (x <= -30) return 0; final double p = 1 / (1 + exp(y * pred)); return p * (1 - p); }
java
public static double deriv2(double pred, double y) { final double x = y * pred; if (x >= 30) return 0; else if (x <= -30) return 0; final double p = 1 / (1 + exp(y * pred)); return p * (1 - p); }
[ "public", "static", "double", "deriv2", "(", "double", "pred", ",", "double", "y", ")", "{", "final", "double", "x", "=", "y", "*", "pred", ";", "if", "(", "x", ">=", "30", ")", "return", "0", ";", "else", "if", "(", "x", "<=", "-", "30", ")", ...
Computes the second derivative of the logistic loss @param pred the predicted value @param y the true value @return the second derivative of the logistic loss
[ "Computes", "the", "second", "derivative", "of", "the", "logistic", "loss" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/lossfunctions/LogisticLoss.java#L65-L76
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/trees/MDA.java
MDA.walkCorruptedPath
private TreeNodeVisitor walkCorruptedPath(TreeLearner model, DataPoint dp, int j, Random rand) { TreeNodeVisitor curNode = model.getTreeNodeVisitor(); while(!curNode.isLeaf()) { int path = curNode.getPath(dp); int numChild = curNode.childrenCount(); if(curNode.featuresUsed().contains(j))//corrupt the feature! { //this gets us a random OTHER path, wont be the same b/c we would need to wrap around 1 farther path = (path + rand.nextInt(numChild)) % numChild; } if(curNode.isPathDisabled(path)) break; else curNode = curNode.getChild(path); } return curNode; }
java
private TreeNodeVisitor walkCorruptedPath(TreeLearner model, DataPoint dp, int j, Random rand) { TreeNodeVisitor curNode = model.getTreeNodeVisitor(); while(!curNode.isLeaf()) { int path = curNode.getPath(dp); int numChild = curNode.childrenCount(); if(curNode.featuresUsed().contains(j))//corrupt the feature! { //this gets us a random OTHER path, wont be the same b/c we would need to wrap around 1 farther path = (path + rand.nextInt(numChild)) % numChild; } if(curNode.isPathDisabled(path)) break; else curNode = curNode.getChild(path); } return curNode; }
[ "private", "TreeNodeVisitor", "walkCorruptedPath", "(", "TreeLearner", "model", ",", "DataPoint", "dp", ",", "int", "j", ",", "Random", "rand", ")", "{", "TreeNodeVisitor", "curNode", "=", "model", ".", "getTreeNodeVisitor", "(", ")", ";", "while", "(", "!", ...
walks the tree down to a leaf node, adding corruption for a specific feature @param model the tree model to walk @param dp the data point to push down the tree @param j the feature index to corrupt @param rand source of randomness @return the leaf node
[ "walks", "the", "tree", "down", "to", "a", "leaf", "node", "adding", "corruption", "for", "a", "specific", "feature" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/trees/MDA.java#L139-L158
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/linear/AROW.java
AROW.setR
public void setR(double r) { if(Double.isNaN(r) || Double.isInfinite(r) || r <= 0) throw new IllegalArgumentException("r must be a postive constant, not " + r); this.r = r; }
java
public void setR(double r) { if(Double.isNaN(r) || Double.isInfinite(r) || r <= 0) throw new IllegalArgumentException("r must be a postive constant, not " + r); this.r = r; }
[ "public", "void", "setR", "(", "double", "r", ")", "{", "if", "(", "Double", ".", "isNaN", "(", "r", ")", "||", "Double", ".", "isInfinite", "(", "r", ")", "||", "r", "<=", "0", ")", "throw", "new", "IllegalArgumentException", "(", "\"r must be a posti...
Sets the r parameter of AROW, which controls the regularization. Larger values reduce the change in the model on each update. @param r the regularization parameter in (0, Inf)
[ "Sets", "the", "r", "parameter", "of", "AROW", "which", "controls", "the", "regularization", ".", "Larger", "values", "reduce", "the", "change", "in", "the", "model", "on", "each", "update", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/linear/AROW.java#L125-L130
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/boosting/Bagging.java
Bagging.sampleWithReplacement
static public void sampleWithReplacement(int[] sampleCounts, int samples, Random rand) { Arrays.fill(sampleCounts, 0); for(int i = 0; i < samples; i++) sampleCounts[rand.nextInt(sampleCounts.length)]++; }
java
static public void sampleWithReplacement(int[] sampleCounts, int samples, Random rand) { Arrays.fill(sampleCounts, 0); for(int i = 0; i < samples; i++) sampleCounts[rand.nextInt(sampleCounts.length)]++; }
[ "static", "public", "void", "sampleWithReplacement", "(", "int", "[", "]", "sampleCounts", ",", "int", "samples", ",", "Random", "rand", ")", "{", "Arrays", ".", "fill", "(", "sampleCounts", ",", "0", ")", ";", "for", "(", "int", "i", "=", "0", ";", ...
Performs the sampling based on the number of data points, storing the counts in an array to be constructed from XXXX @param sampleCounts an array to keep count of how many times each data point was sampled. The array will be filled with zeros before sampling starts @param samples the number of samples to take from the data set @param rand the source of randomness
[ "Performs", "the", "sampling", "based", "on", "the", "number", "of", "data", "points", "storing", "the", "counts", "in", "an", "array", "to", "be", "constructed", "from", "XXXX" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/boosting/Bagging.java#L369-L374
train
EdwardRaff/JSAT
JSAT/src/jsat/regression/StochasticGradientBoosting.java
StochasticGradientBoosting.setTrainingProportion
public void setTrainingProportion(double trainingProportion) { //+- Inf case captured in >1 <= 0 case if(trainingProportion > 1 || trainingProportion <= 0 || Double.isNaN(trainingProportion)) throw new ArithmeticException("Training Proportion is invalid"); this.trainingProportion = trainingProportion; }
java
public void setTrainingProportion(double trainingProportion) { //+- Inf case captured in >1 <= 0 case if(trainingProportion > 1 || trainingProportion <= 0 || Double.isNaN(trainingProportion)) throw new ArithmeticException("Training Proportion is invalid"); this.trainingProportion = trainingProportion; }
[ "public", "void", "setTrainingProportion", "(", "double", "trainingProportion", ")", "{", "//+- Inf case captured in >1 <= 0 case", "if", "(", "trainingProportion", ">", "1", "||", "trainingProportion", "<=", "0", "||", "Double", ".", "isNaN", "(", "trainingProportion",...
The GB version uses the whole data set at each iteration. SGB can use a fraction of the data set at each iteration in order to reduce overfitting and add randomness. @param trainingProportion the fraction of training the data set to use for each iteration of SGB @throws ArithmeticException if the trainingPortion is not a valid fraction in (0, 1]
[ "The", "GB", "version", "uses", "the", "whole", "data", "set", "at", "each", "iteration", ".", "SGB", "can", "use", "a", "fraction", "of", "the", "data", "set", "at", "each", "iteration", "in", "order", "to", "reduce", "overfitting", "and", "add", "rando...
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/regression/StochasticGradientBoosting.java#L197-L203
train
EdwardRaff/JSAT
JSAT/src/jsat/regression/StochasticGradientBoosting.java
StochasticGradientBoosting.getDerivativeFunc
private Function1D getDerivativeFunc(final RegressionDataSet backingResidsList, final Regressor h) { final Function1D fhPrime = (double x) -> { double c1 = x;//c2=c1-eps double eps = 1e-5; double c1Pc2 = c1 * 2 - eps;//c1+c2 = c1+c1-eps double result = 0; /* * Computing the estimate of the derivative directly, f'(x) approx = f(x)-f(x-eps) * * hEst is the output of the new regressor, target is the true residual target value * * So we have several * (hEst_i c1 - target)^2 - (hEst_i c2 -target)^2 //4 muls, 3 subs * Where c2 = c1-eps * Which simplifies to * (c1 - c2) hEst ((c1 + c2) hEst - 2 target) * = * eps hEst (c1Pc2 hEst - 2 target)//3 muls, 1 sub, 1 shift (mul by 2) * * because eps is on the outside and independent of each * individual summation, we can move it out and do the eps * multiplicatio ont he final result. Reducing us to * * 2 muls, 1 sub, 1 shift (mul by 2) * * per loop * * Which reduce computation, and allows us to get the result * in one pass of the data */ for(int i = 0; i < backingResidsList.size(); i++) { double hEst = h.regress(backingResidsList.getDataPoint(i)); double target = backingResidsList.getTargetValue(i); result += hEst * (c1Pc2 * hEst - 2 * target); } return result * eps; }; return fhPrime; }
java
private Function1D getDerivativeFunc(final RegressionDataSet backingResidsList, final Regressor h) { final Function1D fhPrime = (double x) -> { double c1 = x;//c2=c1-eps double eps = 1e-5; double c1Pc2 = c1 * 2 - eps;//c1+c2 = c1+c1-eps double result = 0; /* * Computing the estimate of the derivative directly, f'(x) approx = f(x)-f(x-eps) * * hEst is the output of the new regressor, target is the true residual target value * * So we have several * (hEst_i c1 - target)^2 - (hEst_i c2 -target)^2 //4 muls, 3 subs * Where c2 = c1-eps * Which simplifies to * (c1 - c2) hEst ((c1 + c2) hEst - 2 target) * = * eps hEst (c1Pc2 hEst - 2 target)//3 muls, 1 sub, 1 shift (mul by 2) * * because eps is on the outside and independent of each * individual summation, we can move it out and do the eps * multiplicatio ont he final result. Reducing us to * * 2 muls, 1 sub, 1 shift (mul by 2) * * per loop * * Which reduce computation, and allows us to get the result * in one pass of the data */ for(int i = 0; i < backingResidsList.size(); i++) { double hEst = h.regress(backingResidsList.getDataPoint(i)); double target = backingResidsList.getTargetValue(i); result += hEst * (c1Pc2 * hEst - 2 * target); } return result * eps; }; return fhPrime; }
[ "private", "Function1D", "getDerivativeFunc", "(", "final", "RegressionDataSet", "backingResidsList", ",", "final", "Regressor", "h", ")", "{", "final", "Function1D", "fhPrime", "=", "(", "double", "x", ")", "->", "{", "double", "c1", "=", "x", ";", "//c2=c1-e...
Returns a function object that approximates the derivative of the squared error of the Regressor as a function of the constant factor multiplied on the Regressor's output. @param backingResidsList the DataPointPair list of residuals @param h the regressor that is having the error of its output minimized @return a Function object approximating the derivative of the squared error
[ "Returns", "a", "function", "object", "that", "approximates", "the", "derivative", "of", "the", "squared", "error", "of", "the", "Regressor", "as", "a", "function", "of", "the", "constant", "factor", "multiplied", "on", "the", "Regressor", "s", "output", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/regression/StochasticGradientBoosting.java#L320-L365
train
EdwardRaff/JSAT
JSAT/src/jsat/io/ARFFLoader.java
ARFFLoader.loadArffFile
public static SimpleDataSet loadArffFile(File file) { try { return loadArffFile(new FileReader(file)); } catch (FileNotFoundException ex) { Logger.getLogger(ARFFLoader.class.getName()).log(Level.SEVERE, null, ex); return null; } }
java
public static SimpleDataSet loadArffFile(File file) { try { return loadArffFile(new FileReader(file)); } catch (FileNotFoundException ex) { Logger.getLogger(ARFFLoader.class.getName()).log(Level.SEVERE, null, ex); return null; } }
[ "public", "static", "SimpleDataSet", "loadArffFile", "(", "File", "file", ")", "{", "try", "{", "return", "loadArffFile", "(", "new", "FileReader", "(", "file", ")", ")", ";", "}", "catch", "(", "FileNotFoundException", "ex", ")", "{", "Logger", ".", "getL...
Uses the given file path to load a data set from an ARFF file. @param file the path to the ARFF file to load @return the data set from the ARFF file, or null if the file could not be loaded.
[ "Uses", "the", "given", "file", "path", "to", "load", "a", "data", "set", "from", "an", "ARFF", "file", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/io/ARFFLoader.java#L38-L49
train
EdwardRaff/JSAT
JSAT/src/jsat/io/ARFFLoader.java
ARFFLoader.nameTrim
private static String nameTrim(String in) { in = in.trim(); if(in.startsWith("'") || in.startsWith("\"")) in = in.substring(1); if(in.endsWith("'") || in.startsWith("\"")) in = in.substring(0, in.length()-1); return in.trim(); }
java
private static String nameTrim(String in) { in = in.trim(); if(in.startsWith("'") || in.startsWith("\"")) in = in.substring(1); if(in.endsWith("'") || in.startsWith("\"")) in = in.substring(0, in.length()-1); return in.trim(); }
[ "private", "static", "String", "nameTrim", "(", "String", "in", ")", "{", "in", "=", "in", ".", "trim", "(", ")", ";", "if", "(", "in", ".", "startsWith", "(", "\"'\"", ")", "||", "in", ".", "startsWith", "(", "\"\\\"\"", ")", ")", "in", "=", "in...
Removes the quotes at the end and front of a string if there are any, as well as spaces at the front and end @param in the string to trim @return the white space and quote trimmed string
[ "Removes", "the", "quotes", "at", "the", "end", "and", "front", "of", "a", "string", "if", "there", "are", "any", "as", "well", "as", "spaces", "at", "the", "front", "and", "end" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/io/ARFFLoader.java#L341-L349
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/neuralnetwork/SOM.java
SOM.setInitialLearningRate
public void setInitialLearningRate(double initialLearningRate) { if(Double.isInfinite(initialLearningRate) || Double.isNaN(initialLearningRate) || initialLearningRate <= 0) throw new ArithmeticException("Learning rate must be a positive constant, not " + initialLearningRate); this.initialLearningRate = initialLearningRate; }
java
public void setInitialLearningRate(double initialLearningRate) { if(Double.isInfinite(initialLearningRate) || Double.isNaN(initialLearningRate) || initialLearningRate <= 0) throw new ArithmeticException("Learning rate must be a positive constant, not " + initialLearningRate); this.initialLearningRate = initialLearningRate; }
[ "public", "void", "setInitialLearningRate", "(", "double", "initialLearningRate", ")", "{", "if", "(", "Double", ".", "isInfinite", "(", "initialLearningRate", ")", "||", "Double", ".", "isNaN", "(", "initialLearningRate", ")", "||", "initialLearningRate", "<=", "...
Sets the rate at which input is incorporated at each iteration of the SOM algorithm @param initialLearningRate the rate the SOM learns at
[ "Sets", "the", "rate", "at", "which", "input", "is", "incorporated", "at", "each", "iteration", "of", "the", "SOM", "algorithm" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/neuralnetwork/SOM.java#L180-L185
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/CategoricalResults.java
CategoricalResults.setProb
public void setProb(int cat, double prob) { if(cat > probabilities.length) throw new IndexOutOfBoundsException("There are only " + probabilities.length + " posibilties, " + cat + " is invalid"); else if(prob < 0 || Double.isInfinite(prob) || Double.isNaN(prob)) throw new ArithmeticException("Only zero and positive values are valid, not " + prob); probabilities[cat] = prob; }
java
public void setProb(int cat, double prob) { if(cat > probabilities.length) throw new IndexOutOfBoundsException("There are only " + probabilities.length + " posibilties, " + cat + " is invalid"); else if(prob < 0 || Double.isInfinite(prob) || Double.isNaN(prob)) throw new ArithmeticException("Only zero and positive values are valid, not " + prob); probabilities[cat] = prob; }
[ "public", "void", "setProb", "(", "int", "cat", ",", "double", "prob", ")", "{", "if", "(", "cat", ">", "probabilities", ".", "length", ")", "throw", "new", "IndexOutOfBoundsException", "(", "\"There are only \"", "+", "probabilities", ".", "length", "+", "\...
Sets the probability that a sample belongs to a given category. @param cat the category @param prob the value to set, may be greater then one. @throws IndexOutOfBoundsException if a non existent category is specified @throws ArithmeticException if the value set is negative or not a number
[ "Sets", "the", "probability", "that", "a", "sample", "belongs", "to", "a", "given", "category", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/CategoricalResults.java#L56-L63
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/CategoricalResults.java
CategoricalResults.mostLikely
public int mostLikely() { int top = 0; for(int i = 1; i < probabilities.length; i++) { if(probabilities[i] > probabilities[top]) top = i; } return top; }
java
public int mostLikely() { int top = 0; for(int i = 1; i < probabilities.length; i++) { if(probabilities[i] > probabilities[top]) top = i; } return top; }
[ "public", "int", "mostLikely", "(", ")", "{", "int", "top", "=", "0", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<", "probabilities", ".", "length", ";", "i", "++", ")", "{", "if", "(", "probabilities", "[", "i", "]", ">", "probabilities",...
Returns the category that is the most likely according to the current probability values @return the the most likely category
[ "Returns", "the", "category", "that", "is", "the", "most", "likely", "according", "to", "the", "current", "probability", "values" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/CategoricalResults.java#L85-L95
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/boosting/Wagging.java
Wagging.setWeakLearner
public void setWeakLearner(Classifier weakL) { if(weakL == null) throw new NullPointerException(); this.weakL = weakL; if(weakL instanceof Regressor) this.weakR = (Regressor) weakL; }
java
public void setWeakLearner(Classifier weakL) { if(weakL == null) throw new NullPointerException(); this.weakL = weakL; if(weakL instanceof Regressor) this.weakR = (Regressor) weakL; }
[ "public", "void", "setWeakLearner", "(", "Classifier", "weakL", ")", "{", "if", "(", "weakL", "==", "null", ")", "throw", "new", "NullPointerException", "(", ")", ";", "this", ".", "weakL", "=", "weakL", ";", "if", "(", "weakL", "instanceof", "Regressor", ...
Sets the weak learner used for classification. If it also supports regressions that will be set as well. @param weakL the weak learner to use
[ "Sets", "the", "weak", "learner", "used", "for", "classification", ".", "If", "it", "also", "supports", "regressions", "that", "will", "be", "set", "as", "well", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/boosting/Wagging.java#L111-L118
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/boosting/Wagging.java
Wagging.setWeakLearner
public void setWeakLearner(Regressor weakR) { if(weakR == null) throw new NullPointerException(); this.weakR = weakR; if(weakR instanceof Classifier) this.weakL = (Classifier) weakR; }
java
public void setWeakLearner(Regressor weakR) { if(weakR == null) throw new NullPointerException(); this.weakR = weakR; if(weakR instanceof Classifier) this.weakL = (Classifier) weakR; }
[ "public", "void", "setWeakLearner", "(", "Regressor", "weakR", ")", "{", "if", "(", "weakR", "==", "null", ")", "throw", "new", "NullPointerException", "(", ")", ";", "this", ".", "weakR", "=", "weakR", ";", "if", "(", "weakR", "instanceof", "Classifier", ...
Sets the weak learner used for regressions . If it also supports classification that will be set as well. @param weakR the weak learner to use
[ "Sets", "the", "weak", "learner", "used", "for", "regressions", ".", "If", "it", "also", "supports", "classification", "that", "will", "be", "set", "as", "well", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/boosting/Wagging.java#L134-L141
train
EdwardRaff/JSAT
JSAT/src/jsat/linear/HessenbergForm.java
HessenbergForm.hess
public static void hess(Matrix A, ExecutorService threadpool) { if(!A.isSquare()) throw new ArithmeticException("Only square matrices can be converted to Upper Hessenberg form"); int m = A.rows(); /** * Space used to store the vector for updating the columns of A */ DenseVector columnUpdateTmp = new DenseVector(m); double[] vk = new double[m]; /** * Space used for updating the sub matrix at step i */ double[] subMatrixUpdateTmp = new double[m]; double tmp;//Used for temp values for(int i = 0; i < m-2; i++) { //Holds the norm, sqrt{a_i^2 + ... + a_m^2} double s = 0.0; //First step of the loop done outside to do extra bit double sigh = A.get(i+1, i);//Holds the multiplication factor vk[i+1] = sigh; s += sigh*sigh; sigh = sigh > 0 ? 1 : -1;//Sign dosnt change the squaring, so we do it first for(int j = i+2; j < m; j++) { tmp = A.get(j, i); vk[j] = tmp; s += tmp*tmp; } double s1 = -sigh*Math.sqrt(s); //Now re use s to quickly get the norm of vk, since it will be almost the same vector s -= vk[i+1]*vk[i+1]; vk[i+1] -= s1; s += vk[i+1]*vk[i+1]; double s1Inv = 1.0/Math.sqrt(s);//Re use to store the norm of vk. Do the inverse to multiply quickly instead of divide for(int j = i+1; j < m; j++) vk[j] *= s1Inv; //Update sub sub matrix A[i+1:m, i:m] //NOTE: The first column that will be altered can be done ourslves, since we know the value set (s1) and that all below it will ber zero Matrix subA = new SubMatrix(A, i+1, i, m, m); DenseVector vVec = new DenseVector(vk, i+1, m); Vec tmpV = new DenseVector(subMatrixUpdateTmp, i, m); tmpV.zeroOut(); vVec.multiply(subA, tmpV); if(threadpool == null) OuterProductUpdate(subA, vVec, tmpV, -2.0); else OuterProductUpdate(subA, vVec, tmpV, -2.0, threadpool); //Zero out ourselves after. //TODO implement so we dont compute the first row A.set(i+1, i, s1); for(int j = i+2; j < m; j++) A.set(j, i, 0.0); //Update the columns of A[0:m, i+1:m] subA = new SubMatrix(A, 0, i+1, m, m); columnUpdateTmp.zeroOut(); subA.multiply(vVec, 1.0, columnUpdateTmp); if(threadpool == null) OuterProductUpdate(subA, columnUpdateTmp, vVec, -2.0); else OuterProductUpdate(subA, columnUpdateTmp, vVec, -2.0, threadpool); } }
java
public static void hess(Matrix A, ExecutorService threadpool) { if(!A.isSquare()) throw new ArithmeticException("Only square matrices can be converted to Upper Hessenberg form"); int m = A.rows(); /** * Space used to store the vector for updating the columns of A */ DenseVector columnUpdateTmp = new DenseVector(m); double[] vk = new double[m]; /** * Space used for updating the sub matrix at step i */ double[] subMatrixUpdateTmp = new double[m]; double tmp;//Used for temp values for(int i = 0; i < m-2; i++) { //Holds the norm, sqrt{a_i^2 + ... + a_m^2} double s = 0.0; //First step of the loop done outside to do extra bit double sigh = A.get(i+1, i);//Holds the multiplication factor vk[i+1] = sigh; s += sigh*sigh; sigh = sigh > 0 ? 1 : -1;//Sign dosnt change the squaring, so we do it first for(int j = i+2; j < m; j++) { tmp = A.get(j, i); vk[j] = tmp; s += tmp*tmp; } double s1 = -sigh*Math.sqrt(s); //Now re use s to quickly get the norm of vk, since it will be almost the same vector s -= vk[i+1]*vk[i+1]; vk[i+1] -= s1; s += vk[i+1]*vk[i+1]; double s1Inv = 1.0/Math.sqrt(s);//Re use to store the norm of vk. Do the inverse to multiply quickly instead of divide for(int j = i+1; j < m; j++) vk[j] *= s1Inv; //Update sub sub matrix A[i+1:m, i:m] //NOTE: The first column that will be altered can be done ourslves, since we know the value set (s1) and that all below it will ber zero Matrix subA = new SubMatrix(A, i+1, i, m, m); DenseVector vVec = new DenseVector(vk, i+1, m); Vec tmpV = new DenseVector(subMatrixUpdateTmp, i, m); tmpV.zeroOut(); vVec.multiply(subA, tmpV); if(threadpool == null) OuterProductUpdate(subA, vVec, tmpV, -2.0); else OuterProductUpdate(subA, vVec, tmpV, -2.0, threadpool); //Zero out ourselves after. //TODO implement so we dont compute the first row A.set(i+1, i, s1); for(int j = i+2; j < m; j++) A.set(j, i, 0.0); //Update the columns of A[0:m, i+1:m] subA = new SubMatrix(A, 0, i+1, m, m); columnUpdateTmp.zeroOut(); subA.multiply(vVec, 1.0, columnUpdateTmp); if(threadpool == null) OuterProductUpdate(subA, columnUpdateTmp, vVec, -2.0); else OuterProductUpdate(subA, columnUpdateTmp, vVec, -2.0, threadpool); } }
[ "public", "static", "void", "hess", "(", "Matrix", "A", ",", "ExecutorService", "threadpool", ")", "{", "if", "(", "!", "A", ".", "isSquare", "(", ")", ")", "throw", "new", "ArithmeticException", "(", "\"Only square matrices can be converted to Upper Hessenberg form...
Alters the matrix A such that it is in upper Hessenberg form. @param A the matrix to transform into upper Hessenberg form
[ "Alters", "the", "matrix", "A", "such", "that", "it", "is", "in", "upper", "Hessenberg", "form", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/linear/HessenbergForm.java#L25-L96
train
EdwardRaff/JSAT
JSAT/src/jsat/distributions/empirical/KernelDensityEstimator.java
KernelDensityEstimator.autoKernel
public static KernelFunction autoKernel(Vec dataPoints ) { if(dataPoints.length() < 30) return GaussKF.getInstance(); else if(dataPoints.length() < 1000) return EpanechnikovKF.getInstance(); else//For very large data sets, Uniform is FAST and just as accurate return UniformKF.getInstance(); }
java
public static KernelFunction autoKernel(Vec dataPoints ) { if(dataPoints.length() < 30) return GaussKF.getInstance(); else if(dataPoints.length() < 1000) return EpanechnikovKF.getInstance(); else//For very large data sets, Uniform is FAST and just as accurate return UniformKF.getInstance(); }
[ "public", "static", "KernelFunction", "autoKernel", "(", "Vec", "dataPoints", ")", "{", "if", "(", "dataPoints", ".", "length", "(", ")", "<", "30", ")", "return", "GaussKF", ".", "getInstance", "(", ")", ";", "else", "if", "(", "dataPoints", ".", "lengt...
Automatically selects a good Kernel function for the data set that balances Execution time and accuracy @param dataPoints @return a kernel that will work well for the given distribution
[ "Automatically", "selects", "a", "good", "Kernel", "function", "for", "the", "data", "set", "that", "balances", "Execution", "time", "and", "accuracy" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/distributions/empirical/KernelDensityEstimator.java#L65-L73
train
EdwardRaff/JSAT
JSAT/src/jsat/distributions/empirical/KernelDensityEstimator.java
KernelDensityEstimator.pdf
private double pdf(double x, int j) { /* * n * ===== /x - x \ * 1 \ | i| * f(x) = --- > K|------| * n h / \ h / * ===== * i = 1 * */ //Only values within a certain range will have an effect on the result, so we will skip to that range! int from = Arrays.binarySearch(X, x-h*k.cutOff()); int to = Arrays.binarySearch(X, x+h*k.cutOff()); //Mostly likely the exact value of x is not in the list, so it returns the inseration points from = from < 0 ? -from-1 : from; to = to < 0 ? -to-1 : to; //Univariate opt, if uniform weights, the sum is just the number of elements divide by half if(weights.length == 0 && k instanceof UniformKF) return (to-from)*0.5/ (sumOFWeights*h); double sum = 0; for(int i = Math.max(0, from); i < Math.min(X.length, to+1); i++) if(i != j) sum += k.k( (x-X[i])/h )*getWeight(i); return sum / (sumOFWeights * h); }
java
private double pdf(double x, int j) { /* * n * ===== /x - x \ * 1 \ | i| * f(x) = --- > K|------| * n h / \ h / * ===== * i = 1 * */ //Only values within a certain range will have an effect on the result, so we will skip to that range! int from = Arrays.binarySearch(X, x-h*k.cutOff()); int to = Arrays.binarySearch(X, x+h*k.cutOff()); //Mostly likely the exact value of x is not in the list, so it returns the inseration points from = from < 0 ? -from-1 : from; to = to < 0 ? -to-1 : to; //Univariate opt, if uniform weights, the sum is just the number of elements divide by half if(weights.length == 0 && k instanceof UniformKF) return (to-from)*0.5/ (sumOFWeights*h); double sum = 0; for(int i = Math.max(0, from); i < Math.min(X.length, to+1); i++) if(i != j) sum += k.k( (x-X[i])/h )*getWeight(i); return sum / (sumOFWeights * h); }
[ "private", "double", "pdf", "(", "double", "x", ",", "int", "j", ")", "{", "/*\n * n\n * ===== /x - x \\\n * 1 \\ | i|\n * f(x) = --- > K|------|\n * n h / \\ h /\n * =====\...
Computes the Leave One Out PDF of the estimator @param x the value to get the pdf of @param j the sorted index of the value to leave. If a negative value is given, the PDF with all values is returned @return the pdf with the given index left out
[ "Computes", "the", "Leave", "One", "Out", "PDF", "of", "the", "estimator" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/distributions/empirical/KernelDensityEstimator.java#L185-L216
train
EdwardRaff/JSAT
JSAT/src/jsat/lossfunctions/EpsilonInsensitiveLoss.java
EpsilonInsensitiveLoss.loss
public static double loss(double pred, double y, double eps) { final double x = Math.abs(pred - y); return Math.max(0, x-eps); }
java
public static double loss(double pred, double y, double eps) { final double x = Math.abs(pred - y); return Math.max(0, x-eps); }
[ "public", "static", "double", "loss", "(", "double", "pred", ",", "double", "y", ",", "double", "eps", ")", "{", "final", "double", "x", "=", "Math", ".", "abs", "(", "pred", "-", "y", ")", ";", "return", "Math", ".", "max", "(", "0", ",", "x", ...
Computes the &epsilon;-insensitive loss @param pred the predicted value @param y the true value @param eps the epsilon tolerance @return the &epsilon;-insensitive loss
[ "Computes", "the", "&epsilon", ";", "-", "insensitive", "loss" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/lossfunctions/EpsilonInsensitiveLoss.java#L24-L28
train
EdwardRaff/JSAT
JSAT/src/jsat/lossfunctions/EpsilonInsensitiveLoss.java
EpsilonInsensitiveLoss.deriv
public static double deriv(double pred, double y, double eps) { final double x = pred - y; if(eps < Math.abs(x)) return Math.signum(x); else return 0; }
java
public static double deriv(double pred, double y, double eps) { final double x = pred - y; if(eps < Math.abs(x)) return Math.signum(x); else return 0; }
[ "public", "static", "double", "deriv", "(", "double", "pred", ",", "double", "y", ",", "double", "eps", ")", "{", "final", "double", "x", "=", "pred", "-", "y", ";", "if", "(", "eps", "<", "Math", ".", "abs", "(", "x", ")", ")", "return", "Math",...
Computes the first derivative of the &epsilon;-insensitive loss @param pred the predicted value @param y the true value @param eps the epsilon tolerance @return the first derivative of the &epsilon;-insensitive loss
[ "Computes", "the", "first", "derivative", "of", "the", "&epsilon", ";", "-", "insensitive", "loss" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/lossfunctions/EpsilonInsensitiveLoss.java#L38-L45
train
EdwardRaff/JSAT
JSAT/src/jsat/utils/GridDataGenerator.java
GridDataGenerator.generateData
public SimpleDataSet generateData(int samples) { int totalClasses = 1; for(int d : dimensions) totalClasses *= d; catDataInfo = new CategoricalData[] { new CategoricalData(totalClasses) } ; List<DataPoint> dataPoints = new ArrayList<DataPoint>(totalClasses*samples); int[] curClassPointer = new int[1]; for(int i = 0; i < dimensions[0]; i++) { int[] curDim = new int[dimensions.length]; curDim[0] = i; addSamples(curClassPointer, 0, samples, dataPoints, curDim); } return new SimpleDataSet(dataPoints); }
java
public SimpleDataSet generateData(int samples) { int totalClasses = 1; for(int d : dimensions) totalClasses *= d; catDataInfo = new CategoricalData[] { new CategoricalData(totalClasses) } ; List<DataPoint> dataPoints = new ArrayList<DataPoint>(totalClasses*samples); int[] curClassPointer = new int[1]; for(int i = 0; i < dimensions[0]; i++) { int[] curDim = new int[dimensions.length]; curDim[0] = i; addSamples(curClassPointer, 0, samples, dataPoints, curDim); } return new SimpleDataSet(dataPoints); }
[ "public", "SimpleDataSet", "generateData", "(", "int", "samples", ")", "{", "int", "totalClasses", "=", "1", ";", "for", "(", "int", "d", ":", "dimensions", ")", "totalClasses", "*=", ";", "catDataInfo", "=", "new", "CategoricalData", "[", "]", "{", "new",...
Generates a new data set. @param samples the number of sample data points to create for each class in the data set. @return A data set the contains the data points with matching class labels.
[ "Generates", "a", "new", "data", "set", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/GridDataGenerator.java#L118-L135
train
EdwardRaff/JSAT
JSAT/src/jsat/math/decayrates/ExponetialDecay.java
ExponetialDecay.setMinRate
public void setMinRate(double min) { if(min <= 0 || Double.isNaN(min) || Double.isInfinite(min)) throw new RuntimeException("minRate should be positive, not " + min); this.min = min; }
java
public void setMinRate(double min) { if(min <= 0 || Double.isNaN(min) || Double.isInfinite(min)) throw new RuntimeException("minRate should be positive, not " + min); this.min = min; }
[ "public", "void", "setMinRate", "(", "double", "min", ")", "{", "if", "(", "min", "<=", "0", "||", "Double", ".", "isNaN", "(", "min", ")", "||", "Double", ".", "isInfinite", "(", "min", ")", ")", "throw", "new", "RuntimeException", "(", "\"minRate sho...
Sets the minimum learning rate to return @param min the minimum learning rate to return
[ "Sets", "the", "minimum", "learning", "rate", "to", "return" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/math/decayrates/ExponetialDecay.java#L65-L70
train
EdwardRaff/JSAT
JSAT/src/jsat/math/FastMath.java
FastMath.digamma
public static double digamma(double x) { if(x == 0) return Double.NaN;//complex infinity else if(x < 0)//digamma(1-x) == digamma(x)+pi/tan(pi*x), to make x positive { if(Math.rint(x) == x) return Double.NaN;//the zeros are complex infinity return digamma(1-x)-PI/tan(PI*x); } /* * shift over 2 values to the left and use truncated approximation * log(x+2)-1/(2 (x+2))-1/(12 (x+2)^2) -1/x-1/(x+1), * the x+2 and x and x+1 are grouped sepratly */ double xp2 = x+2; return log(xp2)-(6*x+13)/(12*xp2*xp2)-(2*x+1)/(x*x+x); }
java
public static double digamma(double x) { if(x == 0) return Double.NaN;//complex infinity else if(x < 0)//digamma(1-x) == digamma(x)+pi/tan(pi*x), to make x positive { if(Math.rint(x) == x) return Double.NaN;//the zeros are complex infinity return digamma(1-x)-PI/tan(PI*x); } /* * shift over 2 values to the left and use truncated approximation * log(x+2)-1/(2 (x+2))-1/(12 (x+2)^2) -1/x-1/(x+1), * the x+2 and x and x+1 are grouped sepratly */ double xp2 = x+2; return log(xp2)-(6*x+13)/(12*xp2*xp2)-(2*x+1)/(x*x+x); }
[ "public", "static", "double", "digamma", "(", "double", "x", ")", "{", "if", "(", "x", "==", "0", ")", "return", "Double", ".", "NaN", ";", "//complex infinity", "else", "if", "(", "x", "<", "0", ")", "//digamma(1-x) == digamma(x)+pi/tan(pi*x), to make x posit...
Computes the digamma function of the input @param x the input value @return &psi;(x)
[ "Computes", "the", "digamma", "function", "of", "the", "input" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/math/FastMath.java#L225-L244
train
EdwardRaff/JSAT
JSAT/src/jsat/clustering/hierarchical/NNChainHAC.java
NNChainHAC.fixMergeOrderAndAssign
private void fixMergeOrderAndAssign(double[] mergedDistance, IntList merge_kept, IntList merge_removed, int lowK, final int N, int highK, int[] designations) { //Now that we are done clustering, we need to re-order the merges so that the smallest distances are mergered first IndexTable it = new IndexTable(mergedDistance); it.apply(merge_kept); it.apply(merge_removed); it.apply(mergedDistance); for(int i = 0; i < it.length(); i++) { merges[merges.length-i*2-1] = merge_removed.get(i); merges[merges.length-i*2-2] = merge_kept.get(i); } //Now lets figure out a guess at the cluster size /* * Keep track of the average dist when merging, mark when it becomes abnormaly large as a guess at K */ OnLineStatistics distChange = new OnLineStatistics(); double maxStndDevs = Double.MIN_VALUE; /** * How many clusters to return */ int clusterSize = lowK; for(int i = 0; i < mergedDistance.length; i++) { //Keep track of the changes in cluster size, and mark if this one was abnormall large distChange.add(mergedDistance[i]); int curK = N - i; if (curK >= lowK && curK <= highK)//In the cluster window? { double stndDevs = (mergedDistance[i] - distChange.getMean()) / distChange.getStandardDeviation(); if (stndDevs > maxStndDevs) { maxStndDevs = stndDevs; clusterSize = curK; } } } PriorityHAC.assignClusterDesignations(designations, clusterSize, merges); }
java
private void fixMergeOrderAndAssign(double[] mergedDistance, IntList merge_kept, IntList merge_removed, int lowK, final int N, int highK, int[] designations) { //Now that we are done clustering, we need to re-order the merges so that the smallest distances are mergered first IndexTable it = new IndexTable(mergedDistance); it.apply(merge_kept); it.apply(merge_removed); it.apply(mergedDistance); for(int i = 0; i < it.length(); i++) { merges[merges.length-i*2-1] = merge_removed.get(i); merges[merges.length-i*2-2] = merge_kept.get(i); } //Now lets figure out a guess at the cluster size /* * Keep track of the average dist when merging, mark when it becomes abnormaly large as a guess at K */ OnLineStatistics distChange = new OnLineStatistics(); double maxStndDevs = Double.MIN_VALUE; /** * How many clusters to return */ int clusterSize = lowK; for(int i = 0; i < mergedDistance.length; i++) { //Keep track of the changes in cluster size, and mark if this one was abnormall large distChange.add(mergedDistance[i]); int curK = N - i; if (curK >= lowK && curK <= highK)//In the cluster window? { double stndDevs = (mergedDistance[i] - distChange.getMean()) / distChange.getStandardDeviation(); if (stndDevs > maxStndDevs) { maxStndDevs = stndDevs; clusterSize = curK; } } } PriorityHAC.assignClusterDesignations(designations, clusterSize, merges); }
[ "private", "void", "fixMergeOrderAndAssign", "(", "double", "[", "]", "mergedDistance", ",", "IntList", "merge_kept", ",", "IntList", "merge_removed", ",", "int", "lowK", ",", "final", "int", "N", ",", "int", "highK", ",", "int", "[", "]", "designations", ")...
After clustering, we need to fix up the merge order - since the NNchain only gets the merges correct, not their ordering. This also figures out what number of clusters to use @param mergedDistance @param merge_kept @param merge_removed @param lowK @param N @param highK @param designations
[ "After", "clustering", "we", "need", "to", "fix", "up", "the", "merge", "order", "-", "since", "the", "NNchain", "only", "gets", "the", "merges", "correct", "not", "their", "ordering", ".", "This", "also", "figures", "out", "what", "number", "of", "cluster...
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/clustering/hierarchical/NNChainHAC.java#L412-L456
train
EdwardRaff/JSAT
JSAT/src/jsat/utils/concurrent/TreeBarrier.java
TreeBarrier.await
public void await(int ID) throws InterruptedException { if(parties == 1)//what are you doing?! return; final boolean startCondition = competitionCondition; int competingFor = (locks.length*2-1-ID)/2; while (competingFor >= 0) { final Lock node = locks[competingFor]; if (node.tryLock())//we lose, must wait { synchronized (node)//ignore warning, its correct. We are using the lock both for competition AND to do an internal wait { while(competitionCondition == startCondition) node.wait(); } node.unlock(); wakeUpTarget(competingFor*2+1); wakeUpTarget(competingFor*2+2); return; } else //we win, comete for another round! { if(competingFor == 0) break;//we have won the last round! competingFor = (competingFor-1)/2; } } //We won! Inform the losers competitionCondition = !competitionCondition; wakeUpTarget(0);//biggest loser }
java
public void await(int ID) throws InterruptedException { if(parties == 1)//what are you doing?! return; final boolean startCondition = competitionCondition; int competingFor = (locks.length*2-1-ID)/2; while (competingFor >= 0) { final Lock node = locks[competingFor]; if (node.tryLock())//we lose, must wait { synchronized (node)//ignore warning, its correct. We are using the lock both for competition AND to do an internal wait { while(competitionCondition == startCondition) node.wait(); } node.unlock(); wakeUpTarget(competingFor*2+1); wakeUpTarget(competingFor*2+2); return; } else //we win, comete for another round! { if(competingFor == 0) break;//we have won the last round! competingFor = (competingFor-1)/2; } } //We won! Inform the losers competitionCondition = !competitionCondition; wakeUpTarget(0);//biggest loser }
[ "public", "void", "await", "(", "int", "ID", ")", "throws", "InterruptedException", "{", "if", "(", "parties", "==", "1", ")", "//what are you doing?!", "return", ";", "final", "boolean", "startCondition", "=", "competitionCondition", ";", "int", "competingFor", ...
Waits for all threads to reach this barrier. @param ID the id of the thread attempting to reach the barrier. @throws InterruptedException if one of the threads was interrupted while waiting on the barrier
[ "Waits", "for", "all", "threads", "to", "reach", "this", "barrier", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/concurrent/TreeBarrier.java#L45-L79
train
EdwardRaff/JSAT
JSAT/src/jsat/math/optimization/ModifiedOWLQN.java
ModifiedOWLQN.setBeta
public void setBeta(double beta) { if(beta <= 0 || beta >= 1 || Double.isNaN(beta)) throw new IllegalArgumentException("shrinkage term must be in (0, 1), not " + beta); this.beta = beta; }
java
public void setBeta(double beta) { if(beta <= 0 || beta >= 1 || Double.isNaN(beta)) throw new IllegalArgumentException("shrinkage term must be in (0, 1), not " + beta); this.beta = beta; }
[ "public", "void", "setBeta", "(", "double", "beta", ")", "{", "if", "(", "beta", "<=", "0", "||", "beta", ">=", "1", "||", "Double", ".", "isNaN", "(", "beta", ")", ")", "throw", "new", "IllegalArgumentException", "(", "\"shrinkage term must be in (0, 1), no...
Sets the shrinkage term used for the line search. @param beta the line search shrinkage term
[ "Sets", "the", "shrinkage", "term", "used", "for", "the", "line", "search", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/math/optimization/ModifiedOWLQN.java#L176-L181
train
EdwardRaff/JSAT
JSAT/src/jsat/utils/DoubleList.java
DoubleList.unmodifiableView
public static List<Double> unmodifiableView(double[] array, int length) { return Collections.unmodifiableList(view(array, length)); }
java
public static List<Double> unmodifiableView(double[] array, int length) { return Collections.unmodifiableList(view(array, length)); }
[ "public", "static", "List", "<", "Double", ">", "unmodifiableView", "(", "double", "[", "]", "array", ",", "int", "length", ")", "{", "return", "Collections", ".", "unmodifiableList", "(", "view", "(", "array", ",", "length", ")", ")", ";", "}" ]
Creates an returns an unmodifiable view of the given double array that requires only a small object allocation. @param array the array to wrap into an unmodifiable list @param length the number of values of the array to use, starting from zero @return an unmodifiable list view of the array
[ "Creates", "an", "returns", "an", "unmodifiable", "view", "of", "the", "given", "double", "array", "that", "requires", "only", "a", "small", "object", "allocation", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/DoubleList.java#L285-L288
train
EdwardRaff/JSAT
JSAT/src/jsat/utils/DoubleList.java
DoubleList.view
public static DoubleList view(double[] array, int length) { if(length > array.length || length < 0) throw new IllegalArgumentException("length must be non-negative and no more than the size of the array("+array.length+"), not " + length); return new DoubleList(array, length); }
java
public static DoubleList view(double[] array, int length) { if(length > array.length || length < 0) throw new IllegalArgumentException("length must be non-negative and no more than the size of the array("+array.length+"), not " + length); return new DoubleList(array, length); }
[ "public", "static", "DoubleList", "view", "(", "double", "[", "]", "array", ",", "int", "length", ")", "{", "if", "(", "length", ">", "array", ".", "length", "||", "length", "<", "0", ")", "throw", "new", "IllegalArgumentException", "(", "\"length must be ...
Creates and returns a view of the given double array that requires only a small object allocation. Changes to the list will be reflected in the array up to a point. If the modification would require increasing the capacity of the array, a new array will be allocated - at which point operations will no longer be reflected in the original array. @param array the array to wrap by a DoubleList object @param length the initial length of the list @return a DoubleList backed by the given array, unless modified to the point of requiring the allocation of a new array
[ "Creates", "and", "returns", "a", "view", "of", "the", "given", "double", "array", "that", "requires", "only", "a", "small", "object", "allocation", ".", "Changes", "to", "the", "list", "will", "be", "reflected", "in", "the", "array", "up", "to", "a", "p...
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/DoubleList.java#L302-L307
train
EdwardRaff/JSAT
JSAT/src/jsat/datatransform/AutoDeskewTransform.java
AutoDeskewTransform.updateStats
private void updateStats(final List<Double> lambdas, OnLineStatistics[][] stats, int indx, double val, double[] mins, double weight) { for (int k = 0; k < lambdas.size(); k++) stats[k][indx].add(transform(val, lambdas.get(k), mins[indx]), weight); }
java
private void updateStats(final List<Double> lambdas, OnLineStatistics[][] stats, int indx, double val, double[] mins, double weight) { for (int k = 0; k < lambdas.size(); k++) stats[k][indx].add(transform(val, lambdas.get(k), mins[indx]), weight); }
[ "private", "void", "updateStats", "(", "final", "List", "<", "Double", ">", "lambdas", ",", "OnLineStatistics", "[", "]", "[", "]", "stats", ",", "int", "indx", ",", "double", "val", ",", "double", "[", "]", "mins", ",", "double", "weight", ")", "{", ...
Updates the online stats for each value of lambda @param lambdas the list of lambda values @param stats the array of statistics trackers @param indx the feature index to add to @param val the value at the given feature index @param mins the minimum value array @param weight the weight to the given update
[ "Updates", "the", "online", "stats", "for", "each", "value", "of", "lambda" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/datatransform/AutoDeskewTransform.java#L312-L316
train
EdwardRaff/JSAT
JSAT/src/jsat/linear/ConcatenatedVec.java
ConcatenatedVec.increment
@Override public void increment(int index, double val) { int baseIndex = getBaseIndex(index); vecs[baseIndex].increment(index-lengthSums[baseIndex], val); }
java
@Override public void increment(int index, double val) { int baseIndex = getBaseIndex(index); vecs[baseIndex].increment(index-lengthSums[baseIndex], val); }
[ "@", "Override", "public", "void", "increment", "(", "int", "index", ",", "double", "val", ")", "{", "int", "baseIndex", "=", "getBaseIndex", "(", "index", ")", ";", "vecs", "[", "baseIndex", "]", ".", "increment", "(", "index", "-", "lengthSums", "[", ...
The following are implemented only for performance reasons
[ "The", "following", "are", "implemented", "only", "for", "performance", "reasons" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/linear/ConcatenatedVec.java#L77-L82
train
EdwardRaff/JSAT
JSAT/src/jsat/distributions/kernels/RationalQuadraticKernel.java
RationalQuadraticKernel.setC
public void setC(double c) { if(c <= 0 || Double.isNaN(c) || Double.isInfinite(c)) throw new IllegalArgumentException("coefficient must be in (0, Inf), not " + c); this.c = c; }
java
public void setC(double c) { if(c <= 0 || Double.isNaN(c) || Double.isInfinite(c)) throw new IllegalArgumentException("coefficient must be in (0, Inf), not " + c); this.c = c; }
[ "public", "void", "setC", "(", "double", "c", ")", "{", "if", "(", "c", "<=", "0", "||", "Double", ".", "isNaN", "(", "c", ")", "||", "Double", ".", "isInfinite", "(", "c", ")", ")", "throw", "new", "IllegalArgumentException", "(", "\"coefficient must ...
Sets the positive additive coefficient @param c the positive additive coefficient
[ "Sets", "the", "positive", "additive", "coefficient" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/distributions/kernels/RationalQuadraticKernel.java#L36-L41
train
EdwardRaff/JSAT
JSAT/src/jsat/linear/RowColumnOps.java
RowColumnOps.addDiag
public static void addDiag(Matrix A, int start, int to, double c) { for(int i = start; i < to; i++) A.increment(i, i, c); }
java
public static void addDiag(Matrix A, int start, int to, double c) { for(int i = start; i < to; i++) A.increment(i, i, c); }
[ "public", "static", "void", "addDiag", "(", "Matrix", "A", ",", "int", "start", ",", "int", "to", ",", "double", "c", ")", "{", "for", "(", "int", "i", "=", "start", ";", "i", "<", "to", ";", "i", "++", ")", "A", ".", "increment", "(", "i", "...
Updates the values along the main diagonal of the matrix by adding a constant to them @param A the matrix to perform the update on @param start the first index of the diagonals to update (inclusive) @param to the last index of the diagonals to update (exclusive) @param c the constant to add to the diagonal
[ "Updates", "the", "values", "along", "the", "main", "diagonal", "of", "the", "matrix", "by", "adding", "a", "constant", "to", "them" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/linear/RowColumnOps.java#L17-L21
train
EdwardRaff/JSAT
JSAT/src/jsat/linear/RowColumnOps.java
RowColumnOps.fillRow
public static void fillRow(Matrix A, int i, int from, int to, double val) { for(int j = from; j < to; j++) A.set(i, j, val); }
java
public static void fillRow(Matrix A, int i, int from, int to, double val) { for(int j = from; j < to; j++) A.set(i, j, val); }
[ "public", "static", "void", "fillRow", "(", "Matrix", "A", ",", "int", "i", ",", "int", "from", ",", "int", "to", ",", "double", "val", ")", "{", "for", "(", "int", "j", "=", "from", ";", "j", "<", "to", ";", "j", "++", ")", "A", ".", "set", ...
Fills the values in a row of the matrix @param A the matrix in question @param i the row of the matrix @param from the first column index to fill (inclusive) @param to the last column index to fill (exclusive) @param val the value to fill into the matrix
[ "Fills", "the", "values", "in", "a", "row", "of", "the", "matrix" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/linear/RowColumnOps.java#L418-L422
train
EdwardRaff/JSAT
JSAT/src/jsat/utils/IntPriorityQueue.java
IntPriorityQueue.indexArrayStore
private void indexArrayStore(int e, int i) { if (valueIndexStore.length < e) { int oldLength = valueIndexStore.length; valueIndexStore = Arrays.copyOf(valueIndexStore, e + 2); Arrays.fill(valueIndexStore, oldLength, valueIndexStore.length, -1); } valueIndexStore[e] = i; }
java
private void indexArrayStore(int e, int i) { if (valueIndexStore.length < e) { int oldLength = valueIndexStore.length; valueIndexStore = Arrays.copyOf(valueIndexStore, e + 2); Arrays.fill(valueIndexStore, oldLength, valueIndexStore.length, -1); } valueIndexStore[e] = i; }
[ "private", "void", "indexArrayStore", "(", "int", "e", ",", "int", "i", ")", "{", "if", "(", "valueIndexStore", ".", "length", "<", "e", ")", "{", "int", "oldLength", "=", "valueIndexStore", ".", "length", ";", "valueIndexStore", "=", "Arrays", ".", "cop...
Sets the given index to use the specific value @param e the value to store the index of @param i the index of the value
[ "Sets", "the", "given", "index", "to", "use", "the", "specific", "value" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/IntPriorityQueue.java#L214-L223
train
EdwardRaff/JSAT
JSAT/src/jsat/utils/IntPriorityQueue.java
IntPriorityQueue.heapifyUp
private void heapifyUp(int i) { int iP = parent(i); while(i != 0 && cmp(i, iP) < 0)//Should not be greater then our parent { swapHeapValues(iP, i); i = iP; iP = parent(i); } }
java
private void heapifyUp(int i) { int iP = parent(i); while(i != 0 && cmp(i, iP) < 0)//Should not be greater then our parent { swapHeapValues(iP, i); i = iP; iP = parent(i); } }
[ "private", "void", "heapifyUp", "(", "int", "i", ")", "{", "int", "iP", "=", "parent", "(", "i", ")", ";", "while", "(", "i", "!=", "0", "&&", "cmp", "(", "i", ",", "iP", ")", "<", "0", ")", "//Should not be greater then our parent", "{", "swapHeapVa...
Heapify up from the given index in the heap and make sure everything is correct. Stops when the child value is in correct order with its parent. @param i the index in the heap to start checking from.
[ "Heapify", "up", "from", "the", "given", "index", "in", "the", "heap", "and", "make", "sure", "everything", "is", "correct", ".", "Stops", "when", "the", "child", "value", "is", "in", "correct", "order", "with", "its", "parent", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/IntPriorityQueue.java#L272-L281
train
EdwardRaff/JSAT
JSAT/src/jsat/utils/IntPriorityQueue.java
IntPriorityQueue.swapHeapValues
private void swapHeapValues(int i, int j) { if(fastValueRemove == Mode.HASH) { valueIndexMap.put(heap[i], j); valueIndexMap.put(heap[j], i); } else if(fastValueRemove == Mode.BOUNDED) { //Already in the array, so just need to set valueIndexStore[heap[i]] = j; valueIndexStore[heap[j]] = i; } int tmp = heap[i]; heap[i] = heap[j]; heap[j] = tmp; }
java
private void swapHeapValues(int i, int j) { if(fastValueRemove == Mode.HASH) { valueIndexMap.put(heap[i], j); valueIndexMap.put(heap[j], i); } else if(fastValueRemove == Mode.BOUNDED) { //Already in the array, so just need to set valueIndexStore[heap[i]] = j; valueIndexStore[heap[j]] = i; } int tmp = heap[i]; heap[i] = heap[j]; heap[j] = tmp; }
[ "private", "void", "swapHeapValues", "(", "int", "i", ",", "int", "j", ")", "{", "if", "(", "fastValueRemove", "==", "Mode", ".", "HASH", ")", "{", "valueIndexMap", ".", "put", "(", "heap", "[", "i", "]", ",", "j", ")", ";", "valueIndexMap", ".", "...
Swaps the values stored in the heap for the given indices @param i the first index to be swapped @param j the second index to be swapped
[ "Swaps", "the", "values", "stored", "in", "the", "heap", "for", "the", "given", "indices" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/IntPriorityQueue.java#L288-L304
train
EdwardRaff/JSAT
JSAT/src/jsat/utils/IntPriorityQueue.java
IntPriorityQueue.removeHeapNode
protected int removeHeapNode(int i) { int val = heap[i]; int rightMost = --size; heap[i] = heap[rightMost]; heap[rightMost] = 0; if(fastValueRemove == Mode.HASH) { valueIndexMap.remove(val); if(size != 0) valueIndexMap.put(heap[i], i); } else if(fastValueRemove == Mode.BOUNDED) { valueIndexStore[val] = -1; } heapDown(i); return val; }
java
protected int removeHeapNode(int i) { int val = heap[i]; int rightMost = --size; heap[i] = heap[rightMost]; heap[rightMost] = 0; if(fastValueRemove == Mode.HASH) { valueIndexMap.remove(val); if(size != 0) valueIndexMap.put(heap[i], i); } else if(fastValueRemove == Mode.BOUNDED) { valueIndexStore[val] = -1; } heapDown(i); return val; }
[ "protected", "int", "removeHeapNode", "(", "int", "i", ")", "{", "int", "val", "=", "heap", "[", "i", "]", ";", "int", "rightMost", "=", "--", "size", ";", "heap", "[", "i", "]", "=", "heap", "[", "rightMost", "]", ";", "heap", "[", "rightMost", ...
Removes the node specified from the heap @param i the valid heap node index to remove from the heap @return the value that was stored in the heap node
[ "Removes", "the", "node", "specified", "from", "the", "heap" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/IntPriorityQueue.java#L321-L339
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/neuralnetwork/regularizers/Max2NormRegularizer.java
Max2NormRegularizer.setMaxNorm
public void setMaxNorm(double maxNorm) { if(Double.isNaN(maxNorm) || Double.isInfinite(maxNorm) || maxNorm <= 0) throw new IllegalArgumentException("The maximum norm must be a positive constant, not " + maxNorm); this.maxNorm = maxNorm; }
java
public void setMaxNorm(double maxNorm) { if(Double.isNaN(maxNorm) || Double.isInfinite(maxNorm) || maxNorm <= 0) throw new IllegalArgumentException("The maximum norm must be a positive constant, not " + maxNorm); this.maxNorm = maxNorm; }
[ "public", "void", "setMaxNorm", "(", "double", "maxNorm", ")", "{", "if", "(", "Double", ".", "isNaN", "(", "maxNorm", ")", "||", "Double", ".", "isInfinite", "(", "maxNorm", ")", "||", "maxNorm", "<=", "0", ")", "throw", "new", "IllegalArgumentException",...
Sets the maximum allowed 2 norm for a single neuron's weights @param maxNorm the maximum norm per neuron's weights
[ "Sets", "the", "maximum", "allowed", "2", "norm", "for", "a", "single", "neuron", "s", "weights" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/neuralnetwork/regularizers/Max2NormRegularizer.java#L34-L39
train
EdwardRaff/JSAT
JSAT/src/jsat/lossfunctions/HuberLoss.java
HuberLoss.loss
public static double loss(double pred, double y, double c) { final double x = y - pred; if (Math.abs(x) <= c) return x * x * 0.5; else return c * (Math.abs(x) - c / 2); }
java
public static double loss(double pred, double y, double c) { final double x = y - pred; if (Math.abs(x) <= c) return x * x * 0.5; else return c * (Math.abs(x) - c / 2); }
[ "public", "static", "double", "loss", "(", "double", "pred", ",", "double", "y", ",", "double", "c", ")", "{", "final", "double", "x", "=", "y", "-", "pred", ";", "if", "(", "Math", ".", "abs", "(", "x", ")", "<=", "c", ")", "return", "x", "*",...
Computes the HuberLoss loss @param pred the predicted value @param y the true value @param c the threshold value @return the HuberLoss loss
[ "Computes", "the", "HuberLoss", "loss" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/lossfunctions/HuberLoss.java#L43-L50
train
EdwardRaff/JSAT
JSAT/src/jsat/lossfunctions/HuberLoss.java
HuberLoss.deriv
public static double deriv(double pred, double y, double c) { double x = pred-y; if (Math.abs(x) <= c) return x; else return c * Math.signum(x); }
java
public static double deriv(double pred, double y, double c) { double x = pred-y; if (Math.abs(x) <= c) return x; else return c * Math.signum(x); }
[ "public", "static", "double", "deriv", "(", "double", "pred", ",", "double", "y", ",", "double", "c", ")", "{", "double", "x", "=", "pred", "-", "y", ";", "if", "(", "Math", ".", "abs", "(", "x", ")", "<=", "c", ")", "return", "x", ";", "else",...
Computes the first derivative of the HuberLoss loss @param pred the predicted value @param y the true value @param c the threshold value @return the first derivative of the HuberLoss loss
[ "Computes", "the", "first", "derivative", "of", "the", "HuberLoss", "loss" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/lossfunctions/HuberLoss.java#L60-L68
train
EdwardRaff/JSAT
JSAT/src/jsat/linear/CholeskyDecomposition.java
CholeskyDecomposition.solve
public Vec solve(Vec b) { //Solve A x = L L^T x = b, for x //First solve L y = b Vec y = forwardSub(L, b); //Sole L^T x = y Vec x = backSub(L, y); return x; }
java
public Vec solve(Vec b) { //Solve A x = L L^T x = b, for x //First solve L y = b Vec y = forwardSub(L, b); //Sole L^T x = y Vec x = backSub(L, y); return x; }
[ "public", "Vec", "solve", "(", "Vec", "b", ")", "{", "//Solve A x = L L^T x = b, for x ", "//First solve L y = b", "Vec", "y", "=", "forwardSub", "(", "L", ",", "b", ")", ";", "//Sole L^T x = y", "Vec", "x", "=", "backSub", "(", "L", ",", "y", ")", ";", ...
Solves the linear system of equations A x = b @param b the vectors of values @return the vector x such that A x = b
[ "Solves", "the", "linear", "system", "of", "equations", "A", "x", "=", "b" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/linear/CholeskyDecomposition.java#L136-L146
train
EdwardRaff/JSAT
JSAT/src/jsat/linear/CholeskyDecomposition.java
CholeskyDecomposition.solve
public Matrix solve(Matrix B) { //Solve A x = L L^T x = b, for x //First solve L y = b Matrix y = forwardSub(L, B); //Sole L^T x = y Matrix x = backSub(L, y); return x; }
java
public Matrix solve(Matrix B) { //Solve A x = L L^T x = b, for x //First solve L y = b Matrix y = forwardSub(L, B); //Sole L^T x = y Matrix x = backSub(L, y); return x; }
[ "public", "Matrix", "solve", "(", "Matrix", "B", ")", "{", "//Solve A x = L L^T x = b, for x ", "//First solve L y = b", "Matrix", "y", "=", "forwardSub", "(", "L", ",", "B", ")", ";", "//Sole L^T x = y", "Matrix", "x", "=", "backSub", "(", "L", ",", "y", "...
Solves the linear system of equations A x = B @param B the matrix of values @return the matrix c such that A x = B
[ "Solves", "the", "linear", "system", "of", "equations", "A", "x", "=", "B" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/linear/CholeskyDecomposition.java#L153-L163
train
EdwardRaff/JSAT
JSAT/src/jsat/linear/CholeskyDecomposition.java
CholeskyDecomposition.getDet
public double getDet() { double det = 1; for(int i = 0; i < L.rows(); i++) det *= L.get(i, i); return det; }
java
public double getDet() { double det = 1; for(int i = 0; i < L.rows(); i++) det *= L.get(i, i); return det; }
[ "public", "double", "getDet", "(", ")", "{", "double", "det", "=", "1", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "L", ".", "rows", "(", ")", ";", "i", "++", ")", "det", "*=", "L", ".", "get", "(", "i", ",", "i", ")", ";", "...
Computes the determinant of A @return the determinant of A
[ "Computes", "the", "determinant", "of", "A" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/linear/CholeskyDecomposition.java#L187-L193
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/linear/LinearSGD.java
LinearSGD.applyL2Reg
private void applyL2Reg(final double eta_t) { if(lambda0 > 0)//apply L2 regularization for(Vec v : ws) v.mutableMultiply(1-eta_t*lambda0); }
java
private void applyL2Reg(final double eta_t) { if(lambda0 > 0)//apply L2 regularization for(Vec v : ws) v.mutableMultiply(1-eta_t*lambda0); }
[ "private", "void", "applyL2Reg", "(", "final", "double", "eta_t", ")", "{", "if", "(", "lambda0", ">", "0", ")", "//apply L2 regularization", "for", "(", "Vec", "v", ":", "ws", ")", "v", ".", "mutableMultiply", "(", "1", "-", "eta_t", "*", "lambda0", "...
Applies L2 regularization to the model @param eta_t the learning rate in use
[ "Applies", "L2", "regularization", "to", "the", "model" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/linear/LinearSGD.java#L449-L454
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/linear/LinearSGD.java
LinearSGD.applyL1Reg
private void applyL1Reg(final double eta_t, Vec x) { //apply l1 regularization if(lambda1 > 0) { l1U += eta_t*lambda1;//line 6: in Tsuruoka et al paper, figure 2 for(int k = 0; k < ws.length; k++) { final Vec w_k = ws[k]; final double[] l1Q_k = l1Q[k]; for(IndexValue iv : x) { final int i = iv.getIndex(); //see "APPLYPENALTY(i)" on line 15: from Figure 2 in Tsuruoka et al paper final double z = w_k.get(i); double newW_i = 0; if (z > 0) newW_i = Math.max(0, z - (l1U + l1Q_k[i])); else if(z < 0) newW_i = Math.min(0, z + (l1U - l1Q_k[i])); l1Q_k[i] += (newW_i - z); w_k.set(i, newW_i); } } } }
java
private void applyL1Reg(final double eta_t, Vec x) { //apply l1 regularization if(lambda1 > 0) { l1U += eta_t*lambda1;//line 6: in Tsuruoka et al paper, figure 2 for(int k = 0; k < ws.length; k++) { final Vec w_k = ws[k]; final double[] l1Q_k = l1Q[k]; for(IndexValue iv : x) { final int i = iv.getIndex(); //see "APPLYPENALTY(i)" on line 15: from Figure 2 in Tsuruoka et al paper final double z = w_k.get(i); double newW_i = 0; if (z > 0) newW_i = Math.max(0, z - (l1U + l1Q_k[i])); else if(z < 0) newW_i = Math.min(0, z + (l1U - l1Q_k[i])); l1Q_k[i] += (newW_i - z); w_k.set(i, newW_i); } } } }
[ "private", "void", "applyL1Reg", "(", "final", "double", "eta_t", ",", "Vec", "x", ")", "{", "//apply l1 regularization", "if", "(", "lambda1", ">", "0", ")", "{", "l1U", "+=", "eta_t", "*", "lambda1", ";", "//line 6: in Tsuruoka et al paper, figure 2", "for", ...
Applies L1 regularization to the model @param eta_t the learning rate in use @param x the input vector the update is from
[ "Applies", "L1", "regularization", "to", "the", "model" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/linear/LinearSGD.java#L461-L486
train
EdwardRaff/JSAT
JSAT/src/jsat/linear/vectorcollection/lsh/RandomProjectionLSH.java
RandomProjectionLSH.projectVector
private void projectVector(Vec vec, int slot, int[] projLocation, Vec projected) { randProjMatrix.multiply(vec, 1.0, projected); int pos = 0; int bitsLeft = Integer.SIZE; int curVal = 0; while(pos < slotsPerEntry) { while(bitsLeft > 0) { curVal <<= 1; if(projected.get(pos*Integer.SIZE+(Integer.SIZE-bitsLeft)) >= 0) curVal |= 1; bitsLeft--; } projLocation[slot+pos] = curVal; curVal = 0; bitsLeft = Integer.SIZE; pos++; } }
java
private void projectVector(Vec vec, int slot, int[] projLocation, Vec projected) { randProjMatrix.multiply(vec, 1.0, projected); int pos = 0; int bitsLeft = Integer.SIZE; int curVal = 0; while(pos < slotsPerEntry) { while(bitsLeft > 0) { curVal <<= 1; if(projected.get(pos*Integer.SIZE+(Integer.SIZE-bitsLeft)) >= 0) curVal |= 1; bitsLeft--; } projLocation[slot+pos] = curVal; curVal = 0; bitsLeft = Integer.SIZE; pos++; } }
[ "private", "void", "projectVector", "(", "Vec", "vec", ",", "int", "slot", ",", "int", "[", "]", "projLocation", ",", "Vec", "projected", ")", "{", "randProjMatrix", ".", "multiply", "(", "vec", ",", "1.0", ",", "projected", ")", ";", "int", "pos", "="...
Projects a given vector into the array of integers. @param vecs the vector to project @param slot the index into the array to start placing the bit values @param projected a vector full of zeros of the same length as {@link #getSignatureBitLength() } to use as a temp space.
[ "Projects", "a", "given", "vector", "into", "the", "array", "of", "integers", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/linear/vectorcollection/lsh/RandomProjectionLSH.java#L223-L244
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/trees/TreePruner.java
TreePruner.prune
public static void prune(TreeNodeVisitor root, PruningMethod method, ClassificationDataSet testSet) { //TODO add vargs for extra arguments that may be used by pruning methods if(method == PruningMethod.NONE ) return; else if(method == PruningMethod.REDUCED_ERROR) pruneReduceError(null, -1, root, testSet); else if(method == PruningMethod.ERROR_BASED) pruneErrorBased(null, -1, root, testSet, 0.25); else throw new RuntimeException("BUG: please report"); }
java
public static void prune(TreeNodeVisitor root, PruningMethod method, ClassificationDataSet testSet) { //TODO add vargs for extra arguments that may be used by pruning methods if(method == PruningMethod.NONE ) return; else if(method == PruningMethod.REDUCED_ERROR) pruneReduceError(null, -1, root, testSet); else if(method == PruningMethod.ERROR_BASED) pruneErrorBased(null, -1, root, testSet, 0.25); else throw new RuntimeException("BUG: please report"); }
[ "public", "static", "void", "prune", "(", "TreeNodeVisitor", "root", ",", "PruningMethod", "method", ",", "ClassificationDataSet", "testSet", ")", "{", "//TODO add vargs for extra arguments that may be used by pruning methods", "if", "(", "method", "==", "PruningMethod", "....
Performs pruning starting from the root node of a tree @param root the root node of a decision tree @param method the pruning method to use @param testSet the test set of data points to use for pruning
[ "Performs", "pruning", "starting", "from", "the", "root", "node", "of", "a", "tree" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/trees/TreePruner.java#L66-L77
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/trees/TreePruner.java
TreePruner.pruneReduceError
private static int pruneReduceError(TreeNodeVisitor parent, int pathFollowed, TreeNodeVisitor current, ClassificationDataSet testSet) { if(current == null) return 0; int nodesPruned = 0; //If we are not a leaf, prune our children if(!current.isLeaf()) { //Each child should only be given testing points that would decend down that path int numSplits = current.childrenCount(); List<ClassificationDataSet> splits = new ArrayList<>(numSplits); IntList hadMissing = new IntList(); double[] fracs = new double[numSplits]; double wSum = 0; for (int i = 0; i < numSplits; i++) splits.add(testSet.emptyClone()); for(int i = 0; i < testSet.size(); i++) { double w_i = testSet.getWeight(i); int path = current.getPath(testSet.getDataPoint(i)); if(path >= 0) { splits.get(path).addDataPoint(testSet.getDataPoint(i), testSet.getDataPointCategory(i), w_i); wSum += w_i; fracs[path] += w_i; } else//missing value hadMissing.add(i); } //normalize fracs for(int i = 0; i < numSplits; i++) fracs[i] /= wSum+1e-15; if(!hadMissing.isEmpty()) DecisionStump.distributMissing(splits, fracs, testSet, hadMissing); for (int i = numSplits - 1; i >= 0; i--)//Go backwards so child removals dont affect indices nodesPruned += pruneReduceError(current, i, current.getChild(i), splits.get(i)); } //If we pruned all our children, we may have become a leaf! Should we prune ourselves? if(current.isLeaf() && parent != null)//Compare this nodes accuracy vs its parrent { double childCorrect = 0; double parrentCorrect = 0; for(int i = 0; i < testSet.size(); i++) { DataPoint dp = testSet.getDataPoint(i); int truth = testSet.getDataPointCategory(i); if(current.localClassify(dp).mostLikely() == truth) childCorrect += testSet.getWeight(i); if(parent.localClassify(dp).mostLikely() == truth) parrentCorrect += testSet.getWeight(i); } if(parrentCorrect >= childCorrect)//We use >= b/c if they are the same, we assume smaller trees are better { parent.disablePath(pathFollowed); return nodesPruned+1;//We prune our children and ourselves } return nodesPruned; } return nodesPruned; }
java
private static int pruneReduceError(TreeNodeVisitor parent, int pathFollowed, TreeNodeVisitor current, ClassificationDataSet testSet) { if(current == null) return 0; int nodesPruned = 0; //If we are not a leaf, prune our children if(!current.isLeaf()) { //Each child should only be given testing points that would decend down that path int numSplits = current.childrenCount(); List<ClassificationDataSet> splits = new ArrayList<>(numSplits); IntList hadMissing = new IntList(); double[] fracs = new double[numSplits]; double wSum = 0; for (int i = 0; i < numSplits; i++) splits.add(testSet.emptyClone()); for(int i = 0; i < testSet.size(); i++) { double w_i = testSet.getWeight(i); int path = current.getPath(testSet.getDataPoint(i)); if(path >= 0) { splits.get(path).addDataPoint(testSet.getDataPoint(i), testSet.getDataPointCategory(i), w_i); wSum += w_i; fracs[path] += w_i; } else//missing value hadMissing.add(i); } //normalize fracs for(int i = 0; i < numSplits; i++) fracs[i] /= wSum+1e-15; if(!hadMissing.isEmpty()) DecisionStump.distributMissing(splits, fracs, testSet, hadMissing); for (int i = numSplits - 1; i >= 0; i--)//Go backwards so child removals dont affect indices nodesPruned += pruneReduceError(current, i, current.getChild(i), splits.get(i)); } //If we pruned all our children, we may have become a leaf! Should we prune ourselves? if(current.isLeaf() && parent != null)//Compare this nodes accuracy vs its parrent { double childCorrect = 0; double parrentCorrect = 0; for(int i = 0; i < testSet.size(); i++) { DataPoint dp = testSet.getDataPoint(i); int truth = testSet.getDataPointCategory(i); if(current.localClassify(dp).mostLikely() == truth) childCorrect += testSet.getWeight(i); if(parent.localClassify(dp).mostLikely() == truth) parrentCorrect += testSet.getWeight(i); } if(parrentCorrect >= childCorrect)//We use >= b/c if they are the same, we assume smaller trees are better { parent.disablePath(pathFollowed); return nodesPruned+1;//We prune our children and ourselves } return nodesPruned; } return nodesPruned; }
[ "private", "static", "int", "pruneReduceError", "(", "TreeNodeVisitor", "parent", ",", "int", "pathFollowed", ",", "TreeNodeVisitor", "current", ",", "ClassificationDataSet", "testSet", ")", "{", "if", "(", "current", "==", "null", ")", "return", "0", ";", "int"...
Performs pruning to reduce error on the testing set @param parent the parent of the current node, may be null @param pathFollowed the path from the parent that lead to the current node @param current the current node being considered @param testSet the set of testing points to apply to this node @return the number of nodes pruned from the tree
[ "Performs", "pruning", "to", "reduce", "error", "on", "the", "testing", "set" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/trees/TreePruner.java#L87-L156
train
EdwardRaff/JSAT
JSAT/src/jsat/distributions/Levy.java
Levy.setScale
public void setScale(double scale) { if(scale <= 0 || Double.isNaN(scale) || Double.isInfinite(scale)) throw new ArithmeticException("Scale must be a positive value, not " + scale); this.scale = scale; this.logScale = log(scale); }
java
public void setScale(double scale) { if(scale <= 0 || Double.isNaN(scale) || Double.isInfinite(scale)) throw new ArithmeticException("Scale must be a positive value, not " + scale); this.scale = scale; this.logScale = log(scale); }
[ "public", "void", "setScale", "(", "double", "scale", ")", "{", "if", "(", "scale", "<=", "0", "||", "Double", ".", "isNaN", "(", "scale", ")", "||", "Double", ".", "isInfinite", "(", "scale", ")", ")", "throw", "new", "ArithmeticException", "(", "\"Sc...
Sets the scale of the Levy distribution @param scale the new scale value, must be positive
[ "Sets", "the", "scale", "of", "the", "Levy", "distribution" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/distributions/Levy.java#L33-L39
train
EdwardRaff/JSAT
JSAT/src/jsat/distributions/Levy.java
Levy.setLocation
public void setLocation(double location) { if(Double.isNaN(location) || Double.isInfinite(location)) throw new ArithmeticException("location must be a real number"); this.location = location; }
java
public void setLocation(double location) { if(Double.isNaN(location) || Double.isInfinite(location)) throw new ArithmeticException("location must be a real number"); this.location = location; }
[ "public", "void", "setLocation", "(", "double", "location", ")", "{", "if", "(", "Double", ".", "isNaN", "(", "location", ")", "||", "Double", ".", "isInfinite", "(", "location", ")", ")", "throw", "new", "ArithmeticException", "(", "\"location must be a real ...
Sets location of the Levy distribution. @param location the new location
[ "Sets", "location", "of", "the", "Levy", "distribution", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/distributions/Levy.java#L54-L59
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/svm/extended/CPM.java
CPM.sgdTrain
private void sgdTrain(ClassificationDataSet D, MatrixOfVecs W, Vec b, int sign_mul, boolean parallel) { IntList order = new IntList(D.size()); ListUtils.addRange(order, 0, D.size(), 1); final double lambda_adj = lambda/(D.size()*epochs); int[] owned = new int[K];//how many points does thsi guy own? int assigned_positive_instances = 0;//how many points in the positive class have been assigned? int[] assignments = new int[D.size()];//who owns each data point Arrays.fill(assignments, -1);//Starts out that no one is assigned! Vec dots = new DenseVector(W.rows()); long t = 0; for(int epoch = 0; epoch < epochs; epoch++) { Collections.shuffle(order); for(int i : order) { t++; double eta = 1/(lambda_adj*t); Vec x_i = D.getDataPoint(i).getNumericalValues(); int y_i = (D.getDataPointCategory(i)*2-1)*sign_mul; //this sets dots = bias, which we then add to with matrix-vector product //result is the same as dots = W x_i + b b.copyTo(dots); W.multiply(x_i, 1.0, dots); if(y_i == -1) { for(int k = 0; k < K; k++) if(dots.get(k) > -1) { W.getRowView(k).mutableSubtract(eta, x_i); b.increment(k, -eta); } } else//y_i == 1 { int k_true_max = 0; for(int k = 1; k < dots.length(); k++) if(dots.get(k) > dots.get(k_true_max)) k_true_max = k; if(dots.get(k_true_max) < 1) { int z = ASSIGN(dots, i, k_true_max, owned, assignments, assigned_positive_instances); W.getRowView(z).mutableAdd(eta, x_i); b.increment(z, eta); //book keeping if(assignments[i] < 0)//first assignment, inc counter assigned_positive_instances++; else//change owner, decrement ownership count owned[assignments[i]]--; owned[z]++; assignments[i] = z; } } // W.mutableMultiply(1-eta*lambda); //equivalent form, more stable W.mutableMultiply(1-1.0/t); b.mutableMultiply(1-1.0/t); } } }
java
private void sgdTrain(ClassificationDataSet D, MatrixOfVecs W, Vec b, int sign_mul, boolean parallel) { IntList order = new IntList(D.size()); ListUtils.addRange(order, 0, D.size(), 1); final double lambda_adj = lambda/(D.size()*epochs); int[] owned = new int[K];//how many points does thsi guy own? int assigned_positive_instances = 0;//how many points in the positive class have been assigned? int[] assignments = new int[D.size()];//who owns each data point Arrays.fill(assignments, -1);//Starts out that no one is assigned! Vec dots = new DenseVector(W.rows()); long t = 0; for(int epoch = 0; epoch < epochs; epoch++) { Collections.shuffle(order); for(int i : order) { t++; double eta = 1/(lambda_adj*t); Vec x_i = D.getDataPoint(i).getNumericalValues(); int y_i = (D.getDataPointCategory(i)*2-1)*sign_mul; //this sets dots = bias, which we then add to with matrix-vector product //result is the same as dots = W x_i + b b.copyTo(dots); W.multiply(x_i, 1.0, dots); if(y_i == -1) { for(int k = 0; k < K; k++) if(dots.get(k) > -1) { W.getRowView(k).mutableSubtract(eta, x_i); b.increment(k, -eta); } } else//y_i == 1 { int k_true_max = 0; for(int k = 1; k < dots.length(); k++) if(dots.get(k) > dots.get(k_true_max)) k_true_max = k; if(dots.get(k_true_max) < 1) { int z = ASSIGN(dots, i, k_true_max, owned, assignments, assigned_positive_instances); W.getRowView(z).mutableAdd(eta, x_i); b.increment(z, eta); //book keeping if(assignments[i] < 0)//first assignment, inc counter assigned_positive_instances++; else//change owner, decrement ownership count owned[assignments[i]]--; owned[z]++; assignments[i] = z; } } // W.mutableMultiply(1-eta*lambda); //equivalent form, more stable W.mutableMultiply(1-1.0/t); b.mutableMultiply(1-1.0/t); } } }
[ "private", "void", "sgdTrain", "(", "ClassificationDataSet", "D", ",", "MatrixOfVecs", "W", ",", "Vec", "b", ",", "int", "sign_mul", ",", "boolean", "parallel", ")", "{", "IntList", "order", "=", "new", "IntList", "(", "D", ".", "size", "(", ")", ")", ...
Training procedure that can be applied to each version of the CPM sub-problem. @param D the dataset to train on @param W the weight matrix of vectors to use @param b a vector that stores the associated bias terms for each weigh vector. @param sign_mul Either positive or negative 1. Controls whether or not the positive or negative class is to be enveloped by the polytype
[ "Training", "procedure", "that", "can", "be", "applied", "to", "each", "version", "of", "the", "CPM", "sub", "-", "problem", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/svm/extended/CPM.java#L413-L482
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/linear/STGD.java
STGD.setLearningRate
public void setLearningRate(double learningRate) { if(Double.isInfinite(learningRate) || Double.isNaN(learningRate) || learningRate <= 0) throw new IllegalArgumentException("Learning rate must be positive, not " + learningRate); this.learningRate = learningRate; }
java
public void setLearningRate(double learningRate) { if(Double.isInfinite(learningRate) || Double.isNaN(learningRate) || learningRate <= 0) throw new IllegalArgumentException("Learning rate must be positive, not " + learningRate); this.learningRate = learningRate; }
[ "public", "void", "setLearningRate", "(", "double", "learningRate", ")", "{", "if", "(", "Double", ".", "isInfinite", "(", "learningRate", ")", "||", "Double", ".", "isNaN", "(", "learningRate", ")", "||", "learningRate", "<=", "0", ")", "throw", "new", "I...
Sets the learning rate to use @param learningRate the learning rate &gt; 0.
[ "Sets", "the", "learning", "rate", "to", "use" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/linear/STGD.java#L108-L113
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/linear/STGD.java
STGD.setThreshold
public void setThreshold(double threshold) { if(Double.isNaN(threshold) || threshold <= 0) throw new IllegalArgumentException("Threshold must be positive, not " + threshold); this.threshold = threshold; }
java
public void setThreshold(double threshold) { if(Double.isNaN(threshold) || threshold <= 0) throw new IllegalArgumentException("Threshold must be positive, not " + threshold); this.threshold = threshold; }
[ "public", "void", "setThreshold", "(", "double", "threshold", ")", "{", "if", "(", "Double", ".", "isNaN", "(", "threshold", ")", "||", "threshold", "<=", "0", ")", "throw", "new", "IllegalArgumentException", "(", "\"Threshold must be positive, not \"", "+", "th...
Sets the threshold for a coefficient value to avoid regularization. While a coefficient reaches this magnitude, regularization will not be applied. @param threshold the coefficient regularization threshold in ( 0, Infinity ]
[ "Sets", "the", "threshold", "for", "a", "coefficient", "value", "to", "avoid", "regularization", ".", "While", "a", "coefficient", "reaches", "this", "magnitude", "regularization", "will", "not", "be", "applied", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/linear/STGD.java#L130-L135
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/linear/STGD.java
STGD.setGravity
public void setGravity(double gravity) { if(Double.isInfinite(gravity) || Double.isNaN(gravity) || gravity <= 0) throw new IllegalArgumentException("Gravity must be positive, not " + gravity); this.gravity = gravity; }
java
public void setGravity(double gravity) { if(Double.isInfinite(gravity) || Double.isNaN(gravity) || gravity <= 0) throw new IllegalArgumentException("Gravity must be positive, not " + gravity); this.gravity = gravity; }
[ "public", "void", "setGravity", "(", "double", "gravity", ")", "{", "if", "(", "Double", ".", "isInfinite", "(", "gravity", ")", "||", "Double", ".", "isNaN", "(", "gravity", ")", "||", "gravity", "<=", "0", ")", "throw", "new", "IllegalArgumentException",...
Sets the gravity regularization parameter that "weighs down" the coefficient values. Larger gravity values impose stronger regularization, and encourage greater sparsity. @param gravity the regularization parameter in ( 0, Infinity )
[ "Sets", "the", "gravity", "regularization", "parameter", "that", "weighs", "down", "the", "coefficient", "values", ".", "Larger", "gravity", "values", "impose", "stronger", "regularization", "and", "encourage", "greater", "sparsity", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/linear/STGD.java#L153-L158
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/linear/STGD.java
STGD.performUpdate
private void performUpdate(final Vec x, final double y, final double yHat) { for(IndexValue iv : x) { final int j = iv.getIndex(); w.set(j, T(w.get(j)+2*learningRate*(y-yHat)*iv.getValue(), ((time-t[j])/K)*gravity*learningRate, threshold)); t[j] += ((time-t[j])/K)*K; } }
java
private void performUpdate(final Vec x, final double y, final double yHat) { for(IndexValue iv : x) { final int j = iv.getIndex(); w.set(j, T(w.get(j)+2*learningRate*(y-yHat)*iv.getValue(), ((time-t[j])/K)*gravity*learningRate, threshold)); t[j] += ((time-t[j])/K)*K; } }
[ "private", "void", "performUpdate", "(", "final", "Vec", "x", ",", "final", "double", "y", ",", "final", "double", "yHat", ")", "{", "for", "(", "IndexValue", "iv", ":", "x", ")", "{", "final", "int", "j", "=", "iv", ".", "getIndex", "(", ")", ";",...
Performs the sparse update of the weight vector @param x the input vector @param y the true value @param yHat the predicted value
[ "Performs", "the", "sparse", "update", "of", "the", "weight", "vector" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/linear/STGD.java#L277-L289
train
EdwardRaff/JSAT
JSAT/src/jsat/datatransform/featureselection/SFS.java
SFS.SFSSelectFeature
static protected int SFSSelectFeature(Set<Integer> available, DataSet dataSet, Set<Integer> catToRemove, Set<Integer> numToRemove, Set<Integer> catSelecteed, Set<Integer> numSelected, Object evaluater, int folds, Random rand, double[] PbestScore, int minFeatures) { int nCat = dataSet.getNumCategoricalVars(); int curBest = -1; double curBestScore = Double.POSITIVE_INFINITY; for(int feature : available) { removeFeature(feature, nCat, catToRemove, numToRemove); DataSet workOn = dataSet.shallowClone(); RemoveAttributeTransform remove = new RemoveAttributeTransform(workOn, catToRemove, numToRemove); workOn.applyTransform(remove); double score = getScore(workOn, evaluater, folds, rand); if(score < curBestScore) { curBestScore = score; curBest = feature; } addFeature(feature, nCat, catToRemove, numToRemove); } if(curBestScore <= 1e-14 && PbestScore[0] <= 1e-14 && catSelecteed.size() + numSelected.size() >= minFeatures ) return -1; if (curBestScore < PbestScore[0] || catSelecteed.size() + numSelected.size() < minFeatures || Math.abs(PbestScore[0]-curBestScore) < 1e-3) { PbestScore[0] = curBestScore; addFeature(curBest, nCat, catSelecteed, numSelected); removeFeature(curBest, nCat, catToRemove, numToRemove); available.remove(curBest); return curBest; } else return -1; //No possible improvment & weve got enough }
java
static protected int SFSSelectFeature(Set<Integer> available, DataSet dataSet, Set<Integer> catToRemove, Set<Integer> numToRemove, Set<Integer> catSelecteed, Set<Integer> numSelected, Object evaluater, int folds, Random rand, double[] PbestScore, int minFeatures) { int nCat = dataSet.getNumCategoricalVars(); int curBest = -1; double curBestScore = Double.POSITIVE_INFINITY; for(int feature : available) { removeFeature(feature, nCat, catToRemove, numToRemove); DataSet workOn = dataSet.shallowClone(); RemoveAttributeTransform remove = new RemoveAttributeTransform(workOn, catToRemove, numToRemove); workOn.applyTransform(remove); double score = getScore(workOn, evaluater, folds, rand); if(score < curBestScore) { curBestScore = score; curBest = feature; } addFeature(feature, nCat, catToRemove, numToRemove); } if(curBestScore <= 1e-14 && PbestScore[0] <= 1e-14 && catSelecteed.size() + numSelected.size() >= minFeatures ) return -1; if (curBestScore < PbestScore[0] || catSelecteed.size() + numSelected.size() < minFeatures || Math.abs(PbestScore[0]-curBestScore) < 1e-3) { PbestScore[0] = curBestScore; addFeature(curBest, nCat, catSelecteed, numSelected); removeFeature(curBest, nCat, catToRemove, numToRemove); available.remove(curBest); return curBest; } else return -1; //No possible improvment & weve got enough }
[ "static", "protected", "int", "SFSSelectFeature", "(", "Set", "<", "Integer", ">", "available", ",", "DataSet", "dataSet", ",", "Set", "<", "Integer", ">", "catToRemove", ",", "Set", "<", "Integer", ">", "numToRemove", ",", "Set", "<", "Integer", ">", "cat...
Attempts to add one feature to the list of features while increasing or maintaining the current accuracy @param available the set of available features from [0, n) to consider for adding @param dataSet the original data set to perform feature selection from @param catToRemove the current set of categorical features to remove @param numToRemove the current set of numerical features to remove @param catSelecteed the current set of categorical features we are keeping @param numSelected the current set of numerical features we are keeping @param evaluater the classifier or regressor to perform evaluations with @param folds the number of cross validation folds to determine performance @param rand the source of randomness @param PbestScore an array to behave as a pointer to the best score seen so far @param minFeatures the minimum number of features needed @return the feature that was selected to add, or -1 if none were added.
[ "Attempts", "to", "add", "one", "feature", "to", "the", "list", "of", "features", "while", "increasing", "or", "maintaining", "the", "current", "accuracy" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/datatransform/featureselection/SFS.java#L256-L297
train
EdwardRaff/JSAT
JSAT/src/jsat/datatransform/featureselection/SFS.java
SFS.getScore
protected static double getScore(DataSet workOn, Object evaluater, int folds, Random rand) { if(workOn instanceof ClassificationDataSet) { ClassificationModelEvaluation cme = new ClassificationModelEvaluation((Classifier)evaluater, (ClassificationDataSet)workOn); cme.evaluateCrossValidation(folds, rand); return cme.getErrorRate(); } else if(workOn instanceof RegressionDataSet) { RegressionModelEvaluation rme = new RegressionModelEvaluation((Regressor)evaluater, (RegressionDataSet)workOn); rme.evaluateCrossValidation(folds, rand); return rme.getMeanError(); } return Double.POSITIVE_INFINITY; }
java
protected static double getScore(DataSet workOn, Object evaluater, int folds, Random rand) { if(workOn instanceof ClassificationDataSet) { ClassificationModelEvaluation cme = new ClassificationModelEvaluation((Classifier)evaluater, (ClassificationDataSet)workOn); cme.evaluateCrossValidation(folds, rand); return cme.getErrorRate(); } else if(workOn instanceof RegressionDataSet) { RegressionModelEvaluation rme = new RegressionModelEvaluation((Regressor)evaluater, (RegressionDataSet)workOn); rme.evaluateCrossValidation(folds, rand); return rme.getMeanError(); } return Double.POSITIVE_INFINITY; }
[ "protected", "static", "double", "getScore", "(", "DataSet", "workOn", ",", "Object", "evaluater", ",", "int", "folds", ",", "Random", "rand", ")", "{", "if", "(", "workOn", "instanceof", "ClassificationDataSet", ")", "{", "ClassificationModelEvaluation", "cme", ...
The score function for a data set and a learner by cross validation of a classifier @param workOn the transformed data set to test from with cross validation @param evaluater the learning algorithm to use @param folds the number of cross validation folds to perform @param rand the source of randomness @return the score value in terms of cross validated error
[ "The", "score", "function", "for", "a", "data", "set", "and", "a", "learner", "by", "cross", "validation", "of", "a", "classifier" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/datatransform/featureselection/SFS.java#L309-L330
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/bayesian/AODE.java
AODE.setM
public void setM(double m) { if(m < 0 || Double.isInfinite(m) || Double.isNaN(m)) throw new ArithmeticException("The minimum count must be a non negative number"); this.m = m; }
java
public void setM(double m) { if(m < 0 || Double.isInfinite(m) || Double.isNaN(m)) throw new ArithmeticException("The minimum count must be a non negative number"); this.m = m; }
[ "public", "void", "setM", "(", "double", "m", ")", "{", "if", "(", "m", "<", "0", "||", "Double", ".", "isInfinite", "(", "m", ")", "||", "Double", ".", "isNaN", "(", "m", ")", ")", "throw", "new", "ArithmeticException", "(", "\"The minimum count must ...
Sets the minimum prior observation value needed for an attribute combination to have enough support to be included in the final estimate. @param m the minimum needed score
[ "Sets", "the", "minimum", "prior", "observation", "value", "needed", "for", "an", "attribute", "combination", "to", "have", "enough", "support", "to", "be", "included", "in", "the", "final", "estimate", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/bayesian/AODE.java#L133-L138
train
EdwardRaff/JSAT
JSAT/src/jsat/linear/VecPaired.java
VecPaired.extractTrueVec
public static Vec extractTrueVec(Vec b) { while(b instanceof VecPaired) b = ((VecPaired) b).getVector(); return b; }
java
public static Vec extractTrueVec(Vec b) { while(b instanceof VecPaired) b = ((VecPaired) b).getVector(); return b; }
[ "public", "static", "Vec", "extractTrueVec", "(", "Vec", "b", ")", "{", "while", "(", "b", "instanceof", "VecPaired", ")", "b", "=", "(", "(", "VecPaired", ")", "b", ")", ".", "getVector", "(", ")", ";", "return", "b", ";", "}" ]
This method is used assuming multiple VecPaired are used together. The implementation of the vector may have logic to handle the case that the other vector is of the same type. This will go through every layer of VecPaired to return the final base vector. @param b a Vec, that may or may not be an instance of {@link VecPaired} @return the final Vec backing b, which may be b itself.
[ "This", "method", "is", "used", "assuming", "multiple", "VecPaired", "are", "used", "together", ".", "The", "implementation", "of", "the", "vector", "may", "have", "logic", "to", "handle", "the", "case", "that", "the", "other", "vector", "is", "of", "the", ...
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/linear/VecPaired.java#L316-L321
train
EdwardRaff/JSAT
JSAT/src/jsat/text/TextDataLoader.java
TextDataLoader.addWord
private boolean addWord(String word, SparseVector vec, Integer value) { Integer indx = wordIndex.get(word); if(indx == null)//this word has never been seen before! { Integer index_for_new_word; if((index_for_new_word = wordIndex.putIfAbsent(word, -1)) == null)//I won the race to insert this word into the map { /* * we need to do this increment after words to avoid a race * condition where two people incrment currentLength for the * same word, as that will throw off other word additions * before we can fix the problem */ index_for_new_word = currentLength.getAndIncrement(); wordIndex.put(word, index_for_new_word);//overwrite with correct value } if(index_for_new_word < 0) return false; //possible race on tdf as well when two threads found same new word at the same time AtomicInteger termCount = new AtomicInteger(0), tmp = null; tmp = termDocumentFrequencys.putIfAbsent(index_for_new_word, termCount); if(tmp != null) termCount = tmp; termCount.incrementAndGet(); int newLen = Math.max(index_for_new_word+1, vec.length()); vec.setLength(newLen); vec.set(index_for_new_word, value); } else//this word has been seen before { if(indx < 0) return false; AtomicInteger toInc = termDocumentFrequencys.get(indx); if (toInc == null) { //wordIndex and termDocumnetFrequences are not updated //atomicly together, so could get index but not have tDF ready toInc = termDocumentFrequencys.putIfAbsent(indx, new AtomicInteger(1)); if (toInc == null)//other person finished adding before we "fixed" via putIfAbsent toInc = termDocumentFrequencys.get(indx); } toInc.incrementAndGet(); if (vec.length() <= indx)//happens when another thread sees the word first and adds it, then get check and find it- but haven't increased our vector legnth vec.setLength(indx+1); vec.set(indx, value); } return true; }
java
private boolean addWord(String word, SparseVector vec, Integer value) { Integer indx = wordIndex.get(word); if(indx == null)//this word has never been seen before! { Integer index_for_new_word; if((index_for_new_word = wordIndex.putIfAbsent(word, -1)) == null)//I won the race to insert this word into the map { /* * we need to do this increment after words to avoid a race * condition where two people incrment currentLength for the * same word, as that will throw off other word additions * before we can fix the problem */ index_for_new_word = currentLength.getAndIncrement(); wordIndex.put(word, index_for_new_word);//overwrite with correct value } if(index_for_new_word < 0) return false; //possible race on tdf as well when two threads found same new word at the same time AtomicInteger termCount = new AtomicInteger(0), tmp = null; tmp = termDocumentFrequencys.putIfAbsent(index_for_new_word, termCount); if(tmp != null) termCount = tmp; termCount.incrementAndGet(); int newLen = Math.max(index_for_new_word+1, vec.length()); vec.setLength(newLen); vec.set(index_for_new_word, value); } else//this word has been seen before { if(indx < 0) return false; AtomicInteger toInc = termDocumentFrequencys.get(indx); if (toInc == null) { //wordIndex and termDocumnetFrequences are not updated //atomicly together, so could get index but not have tDF ready toInc = termDocumentFrequencys.putIfAbsent(indx, new AtomicInteger(1)); if (toInc == null)//other person finished adding before we "fixed" via putIfAbsent toInc = termDocumentFrequencys.get(indx); } toInc.incrementAndGet(); if (vec.length() <= indx)//happens when another thread sees the word first and adds it, then get check and find it- but haven't increased our vector legnth vec.setLength(indx+1); vec.set(indx, value); } return true; }
[ "private", "boolean", "addWord", "(", "String", "word", ",", "SparseVector", "vec", ",", "Integer", "value", ")", "{", "Integer", "indx", "=", "wordIndex", ".", "get", "(", "word", ")", ";", "if", "(", "indx", "==", "null", ")", "//this word has never been...
Does the work to add a given word to the sparse vector. May not succeed in race conditions when two ore more threads are trying to add a word at the same time. @param word the word to add to the vector @param vec the location to store the word occurrence @param entry the number of times the word occurred @return {@code true} if the word was successfully added. {@code false} if the word wasn't added due to a race- and should be tried again
[ "Does", "the", "work", "to", "add", "a", "given", "word", "to", "the", "sparse", "vector", ".", "May", "not", "succeed", "in", "race", "conditions", "when", "two", "ore", "more", "threads", "are", "trying", "to", "add", "a", "word", "at", "the", "same"...
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/text/TextDataLoader.java#L215-L268
train
EdwardRaff/JSAT
JSAT/src/jsat/distributions/discrete/Poisson.java
Poisson.setLambda
public void setLambda(double lambda) { if (Double.isNaN(lambda) || lambda <= 0 || Double.isInfinite(lambda)) throw new IllegalArgumentException("lambda must be positive, not " + lambda); this.lambda = lambda; }
java
public void setLambda(double lambda) { if (Double.isNaN(lambda) || lambda <= 0 || Double.isInfinite(lambda)) throw new IllegalArgumentException("lambda must be positive, not " + lambda); this.lambda = lambda; }
[ "public", "void", "setLambda", "(", "double", "lambda", ")", "{", "if", "(", "Double", ".", "isNaN", "(", "lambda", ")", "||", "lambda", "<=", "0", "||", "Double", ".", "isInfinite", "(", "lambda", ")", ")", "throw", "new", "IllegalArgumentException", "(...
Sets the average rate of the event occurring in a unit of time @param lambda the average rate of the event occurring
[ "Sets", "the", "average", "rate", "of", "the", "event", "occurring", "in", "a", "unit", "of", "time" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/distributions/discrete/Poisson.java#L58-L63
train
EdwardRaff/JSAT
JSAT/src/jsat/linear/vectorcollection/KDTree.java
KDTree.getMedianIndex
public int getMedianIndex(final List<Integer> data, int pivot) { int medianIndex = data.size()/2; //What if more than one point have the samve value? Keep incrementing until that dosn't happen while(medianIndex < data.size()-1 && allVecs.get(data.get(medianIndex)).get(pivot) == allVecs.get(data.get(medianIndex+1)).get(pivot)) medianIndex++; return medianIndex; }
java
public int getMedianIndex(final List<Integer> data, int pivot) { int medianIndex = data.size()/2; //What if more than one point have the samve value? Keep incrementing until that dosn't happen while(medianIndex < data.size()-1 && allVecs.get(data.get(medianIndex)).get(pivot) == allVecs.get(data.get(medianIndex+1)).get(pivot)) medianIndex++; return medianIndex; }
[ "public", "int", "getMedianIndex", "(", "final", "List", "<", "Integer", ">", "data", ",", "int", "pivot", ")", "{", "int", "medianIndex", "=", "data", ".", "size", "(", ")", "/", "2", ";", "//What if more than one point have the samve value? Keep incrementing unt...
Returns the index for the median, adjusted incase multiple features have the same value. @param data the dataset to get the median index of @param pivot the dimension to pivot on, and ensure the median index has a different value on the left side @return
[ "Returns", "the", "index", "for", "the", "median", "adjusted", "incase", "multiple", "features", "have", "the", "same", "value", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/linear/vectorcollection/KDTree.java#L615-L622
train
EdwardRaff/JSAT
JSAT/src/jsat/distributions/discrete/Zipf.java
Zipf.setCardinality
public void setCardinality(double cardinality) { if (cardinality < 0 || Double.isNaN(cardinality)) throw new IllegalArgumentException("Cardinality must be a positive integer or infinity, not " + cardinality); this.cardinality = Math.ceil(cardinality); fixCache(); }
java
public void setCardinality(double cardinality) { if (cardinality < 0 || Double.isNaN(cardinality)) throw new IllegalArgumentException("Cardinality must be a positive integer or infinity, not " + cardinality); this.cardinality = Math.ceil(cardinality); fixCache(); }
[ "public", "void", "setCardinality", "(", "double", "cardinality", ")", "{", "if", "(", "cardinality", "<", "0", "||", "Double", ".", "isNaN", "(", "cardinality", ")", ")", "throw", "new", "IllegalArgumentException", "(", "\"Cardinality must be a positive integer or ...
Sets the cardinality of the distribution, defining the maximum number of items that Zipf can return. @param cardinality the maximum output range of the distribution, can be {@link Double#POSITIVE_INFINITY infinite}.
[ "Sets", "the", "cardinality", "of", "the", "distribution", "defining", "the", "maximum", "number", "of", "items", "that", "Zipf", "can", "return", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/distributions/discrete/Zipf.java#L87-L93
train
EdwardRaff/JSAT
JSAT/src/jsat/distributions/discrete/Zipf.java
Zipf.setSkew
public void setSkew(double skew) { if(skew <= 0 || Double.isNaN(skew) || Double.isInfinite(skew)) throw new IllegalArgumentException("Skew must be a positive value, not " + skew); this.skew = skew; fixCache(); }
java
public void setSkew(double skew) { if(skew <= 0 || Double.isNaN(skew) || Double.isInfinite(skew)) throw new IllegalArgumentException("Skew must be a positive value, not " + skew); this.skew = skew; fixCache(); }
[ "public", "void", "setSkew", "(", "double", "skew", ")", "{", "if", "(", "skew", "<=", "0", "||", "Double", ".", "isNaN", "(", "skew", ")", "||", "Double", ".", "isInfinite", "(", "skew", ")", ")", "throw", "new", "IllegalArgumentException", "(", "\"Sk...
Sets the skewness of the distribution. Lower values spread out the probability distribution, while higher values concentrate on the lowest ranks. @param skew the positive value for the distribution's skew
[ "Sets", "the", "skewness", "of", "the", "distribution", ".", "Lower", "values", "spread", "out", "the", "probability", "distribution", "while", "higher", "values", "concentrate", "on", "the", "lowest", "ranks", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/distributions/discrete/Zipf.java#L111-L117
train
EdwardRaff/JSAT
JSAT/src/jsat/io/DataWriter.java
DataWriter.writePoint
public void writePoint(double weight, DataPoint dp, double label) throws IOException { ByteArrayOutputStream baos = local_baos.get(); pointToBytes(weight, dp, label, baos); if(baos.size() >= LOCAL_BUFFER_SIZE)//We've got a big chunk of data, lets dump it synchronized(out) { baos.writeTo(out); baos.reset(); } }
java
public void writePoint(double weight, DataPoint dp, double label) throws IOException { ByteArrayOutputStream baos = local_baos.get(); pointToBytes(weight, dp, label, baos); if(baos.size() >= LOCAL_BUFFER_SIZE)//We've got a big chunk of data, lets dump it synchronized(out) { baos.writeTo(out); baos.reset(); } }
[ "public", "void", "writePoint", "(", "double", "weight", ",", "DataPoint", "dp", ",", "double", "label", ")", "throws", "IOException", "{", "ByteArrayOutputStream", "baos", "=", "local_baos", ".", "get", "(", ")", ";", "pointToBytes", "(", "weight", ",", "dp...
Write out the given data point to the output stream @param weight weight of the given data point to write out @param dp the data point to write to the file @param label The associated label for this dataum. If {@link #type} is a {@link DataSetType#SIMPLE} set, this value will be ignored. If {@link DataSetType#CLASSIFICATION}, the value will be assumed to be an integer class label. @throws java.io.IOException
[ "Write", "out", "the", "given", "data", "point", "to", "the", "output", "stream" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/io/DataWriter.java#L114-L124
train
EdwardRaff/JSAT
JSAT/src/jsat/datatransform/PolynomialTransform.java
PolynomialTransform.increment
private int increment(int[] setTo, int max, int curCount) { setTo[0]++; curCount++; if(curCount <= max) return curCount; int carryPos = 0; while(carryPos < setTo.length-1 && curCount > max) { curCount-=setTo[carryPos]; setTo[carryPos] = 0; setTo[++carryPos]++; curCount++; } return curCount; }
java
private int increment(int[] setTo, int max, int curCount) { setTo[0]++; curCount++; if(curCount <= max) return curCount; int carryPos = 0; while(carryPos < setTo.length-1 && curCount > max) { curCount-=setTo[carryPos]; setTo[carryPos] = 0; setTo[++carryPos]++; curCount++; } return curCount; }
[ "private", "int", "increment", "(", "int", "[", "]", "setTo", ",", "int", "max", ",", "int", "curCount", ")", "{", "setTo", "[", "0", "]", "++", ";", "curCount", "++", ";", "if", "(", "curCount", "<=", "max", ")", "return", "curCount", ";", "int", ...
Increments the array to contain representation of the next combination of values in the polynomial @param setTo the array of values marking how many multiples of that value will be used in construction of the point @param max the degree of the polynomial @param curCount the current sum of all counts in the array <tt>setTo</tt> @return the new value of <tt>curCount</tt>
[ "Increments", "the", "array", "to", "contain", "representation", "of", "the", "next", "combination", "of", "values", "in", "the", "polynomial" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/datatransform/PolynomialTransform.java#L91-L110
train
EdwardRaff/JSAT
JSAT/src/jsat/parameters/ModelSearch.java
ModelSearch.getParameterByName
protected Parameter getParameterByName(String name) throws IllegalArgumentException { Parameter param; if (baseClassifier != null) param = ((Parameterized) baseClassifier).getParameter(name); else param = ((Parameterized) baseRegressor).getParameter(name); if (param == null) throw new IllegalArgumentException("Parameter " + name + " does not exist"); return param; }
java
protected Parameter getParameterByName(String name) throws IllegalArgumentException { Parameter param; if (baseClassifier != null) param = ((Parameterized) baseClassifier).getParameter(name); else param = ((Parameterized) baseRegressor).getParameter(name); if (param == null) throw new IllegalArgumentException("Parameter " + name + " does not exist"); return param; }
[ "protected", "Parameter", "getParameterByName", "(", "String", "name", ")", "throws", "IllegalArgumentException", "{", "Parameter", "param", ";", "if", "(", "baseClassifier", "!=", "null", ")", "param", "=", "(", "(", "Parameterized", ")", "baseClassifier", ")", ...
Finds the parameter object with the given name, or throws an exception if a parameter with the given name does not exist. @param name the name to search for @return the parameter object in question @throws IllegalArgumentException if the name is not found
[ "Finds", "the", "parameter", "object", "with", "the", "given", "name", "or", "throws", "an", "exception", "if", "a", "parameter", "with", "the", "given", "name", "does", "not", "exist", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/parameters/ModelSearch.java#L319-L329
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/linear/kernelized/CSKLR.java
CSKLR.getPreScore
private double getPreScore(Vec x) { return k.evalSum(vecs, accelCache, alpha.getBackingArray(), x, 0, alpha.size()); }
java
private double getPreScore(Vec x) { return k.evalSum(vecs, accelCache, alpha.getBackingArray(), x, 0, alpha.size()); }
[ "private", "double", "getPreScore", "(", "Vec", "x", ")", "{", "return", "k", ".", "evalSum", "(", "vecs", ",", "accelCache", ",", "alpha", ".", "getBackingArray", "(", ")", ",", "x", ",", "0", ",", "alpha", ".", "size", "(", ")", ")", ";", "}" ]
Computes the margin score for the given data point @param x the input vector @return the margin score
[ "Computes", "the", "margin", "score", "for", "the", "given", "data", "point" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/linear/kernelized/CSKLR.java#L372-L375
train
EdwardRaff/JSAT
JSAT/src/jsat/distributions/multivariate/NormalM.java
NormalM.setCovariance
public void setCovariance(Matrix covMatrix) { if(!covMatrix.isSquare()) throw new ArithmeticException("Covariance matrix must be square"); else if(covMatrix.rows() != this.mean.length()) throw new ArithmeticException("Covariance matrix does not agree with the mean"); CholeskyDecomposition cd = new CholeskyDecomposition(covMatrix.clone()); L = cd.getLT(); L.mutableTranspose(); LUPDecomposition lup = new LUPDecomposition(covMatrix.clone()); int k = mean.length(); double det = lup.det(); if(Double.isNaN(det) || det < 1e-10) { //Numerical unstable or sub rank matrix. Use the SVD to work with the more stable pesudo matrix SingularValueDecomposition svd = new SingularValueDecomposition(covMatrix.clone()); //We need the rank deficient PDF and pesude inverse this.logPDFConst = 0.5*log(svd.getPseudoDet() * pow(2*PI, svd.getRank())); this.invCovariance = svd.getPseudoInverse(); } else { this.logPDFConst = (-k*log(2*PI)-log(det))*0.5; this.invCovariance = lup.solve(Matrix.eye(k)); } }
java
public void setCovariance(Matrix covMatrix) { if(!covMatrix.isSquare()) throw new ArithmeticException("Covariance matrix must be square"); else if(covMatrix.rows() != this.mean.length()) throw new ArithmeticException("Covariance matrix does not agree with the mean"); CholeskyDecomposition cd = new CholeskyDecomposition(covMatrix.clone()); L = cd.getLT(); L.mutableTranspose(); LUPDecomposition lup = new LUPDecomposition(covMatrix.clone()); int k = mean.length(); double det = lup.det(); if(Double.isNaN(det) || det < 1e-10) { //Numerical unstable or sub rank matrix. Use the SVD to work with the more stable pesudo matrix SingularValueDecomposition svd = new SingularValueDecomposition(covMatrix.clone()); //We need the rank deficient PDF and pesude inverse this.logPDFConst = 0.5*log(svd.getPseudoDet() * pow(2*PI, svd.getRank())); this.invCovariance = svd.getPseudoInverse(); } else { this.logPDFConst = (-k*log(2*PI)-log(det))*0.5; this.invCovariance = lup.solve(Matrix.eye(k)); } }
[ "public", "void", "setCovariance", "(", "Matrix", "covMatrix", ")", "{", "if", "(", "!", "covMatrix", ".", "isSquare", "(", ")", ")", "throw", "new", "ArithmeticException", "(", "\"Covariance matrix must be square\"", ")", ";", "else", "if", "(", "covMatrix", ...
Sets the covariance matrix for this matrix. @param covMatrix set the covariance matrix used for this distribution @throws ArithmeticException if the covariance matrix is not square, does not agree with the mean, or is not positive definite. An exception may not be throw for all bad matrices.
[ "Sets", "the", "covariance", "matrix", "for", "this", "matrix", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/distributions/multivariate/NormalM.java#L96-L123
train
EdwardRaff/JSAT
JSAT/src/jsat/clustering/PAM.java
PAM.cluster
protected double cluster(DataSet data, boolean doInit, int[] medioids, int[] assignments, List<Double> cacheAccel, boolean parallel) { DoubleAdder totalDistance =new DoubleAdder(); LongAdder changes = new LongAdder(); Arrays.fill(assignments, -1);//-1, invalid category! int[] bestMedCand = new int[medioids.length]; double[] bestMedCandDist = new double[medioids.length]; List<Vec> X = data.getDataVectors(); final List<Double> accel; if(doInit) { TrainableDistanceMetric.trainIfNeeded(dm, data); accel = dm.getAccelerationCache(X); selectIntialPoints(data, medioids, dm, accel, rand, seedSelection); } else accel = cacheAccel; int iter = 0; do { changes.reset(); totalDistance.reset(); ParallelUtils.run(parallel, data.size(), (start, end)-> { for(int i = start; i < end; i++) { int assignment = 0; double minDist = dm.dist(medioids[0], i, X, accel); for (int k = 1; k < medioids.length; k++) { double dist = dm.dist(medioids[k], i, X, accel); if (dist < minDist) { minDist = dist; assignment = k; } } //Update which cluster it is in if (assignments[i] != assignment) { changes.increment(); assignments[i] = assignment; } totalDistance.add(minDist * minDist); } }); //TODO this update may be faster by using more memory, and actually moiving people about in the assignment loop above //Update the medoids Arrays.fill(bestMedCandDist, Double.MAX_VALUE); for(int i = 0; i < data.size(); i++) { double thisCandidateDistance; final int clusterID = assignments[i]; final int medCandadate = i; final int ii = i; thisCandidateDistance = ParallelUtils.range(data.size(), parallel) .filter(j -> j != ii && assignments[j] == clusterID) .mapToDouble(j -> Math.pow(dm.dist(medCandadate, j, X, accel), 2)) .sum(); if(thisCandidateDistance < bestMedCandDist[clusterID]) { bestMedCand[clusterID] = i; bestMedCandDist[clusterID] = thisCandidateDistance; } } System.arraycopy(bestMedCand, 0, medioids, 0, medioids.length); } while( changes.sum() > 0 && iter++ < iterLimit); return totalDistance.sum(); }
java
protected double cluster(DataSet data, boolean doInit, int[] medioids, int[] assignments, List<Double> cacheAccel, boolean parallel) { DoubleAdder totalDistance =new DoubleAdder(); LongAdder changes = new LongAdder(); Arrays.fill(assignments, -1);//-1, invalid category! int[] bestMedCand = new int[medioids.length]; double[] bestMedCandDist = new double[medioids.length]; List<Vec> X = data.getDataVectors(); final List<Double> accel; if(doInit) { TrainableDistanceMetric.trainIfNeeded(dm, data); accel = dm.getAccelerationCache(X); selectIntialPoints(data, medioids, dm, accel, rand, seedSelection); } else accel = cacheAccel; int iter = 0; do { changes.reset(); totalDistance.reset(); ParallelUtils.run(parallel, data.size(), (start, end)-> { for(int i = start; i < end; i++) { int assignment = 0; double minDist = dm.dist(medioids[0], i, X, accel); for (int k = 1; k < medioids.length; k++) { double dist = dm.dist(medioids[k], i, X, accel); if (dist < minDist) { minDist = dist; assignment = k; } } //Update which cluster it is in if (assignments[i] != assignment) { changes.increment(); assignments[i] = assignment; } totalDistance.add(minDist * minDist); } }); //TODO this update may be faster by using more memory, and actually moiving people about in the assignment loop above //Update the medoids Arrays.fill(bestMedCandDist, Double.MAX_VALUE); for(int i = 0; i < data.size(); i++) { double thisCandidateDistance; final int clusterID = assignments[i]; final int medCandadate = i; final int ii = i; thisCandidateDistance = ParallelUtils.range(data.size(), parallel) .filter(j -> j != ii && assignments[j] == clusterID) .mapToDouble(j -> Math.pow(dm.dist(medCandadate, j, X, accel), 2)) .sum(); if(thisCandidateDistance < bestMedCandDist[clusterID]) { bestMedCand[clusterID] = i; bestMedCandDist[clusterID] = thisCandidateDistance; } } System.arraycopy(bestMedCand, 0, medioids, 0, medioids.length); } while( changes.sum() > 0 && iter++ < iterLimit); return totalDistance.sum(); }
[ "protected", "double", "cluster", "(", "DataSet", "data", ",", "boolean", "doInit", ",", "int", "[", "]", "medioids", ",", "int", "[", "]", "assignments", ",", "List", "<", "Double", ">", "cacheAccel", ",", "boolean", "parallel", ")", "{", "DoubleAdder", ...
Performs the actual work of PAM. @param data the data set to apply PAM to @param doInit {@code true} if the initialization procedure of training the distance metric, initiating its cache, and selecting he seeds, should be done. @param medioids the array to store the indices that get chosen as the medoids. The length of the array indicates how many medoids should be obtained. @param assignments an array of the same length as <tt>data</tt>, each value indicating what cluster that point belongs to. @param cacheAccel the pre-computed distance acceleration cache. May be {@code null}. @param parallel the value of parallel @return the double
[ "Performs", "the", "actual", "work", "of", "PAM", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/clustering/PAM.java#L167-L246
train
EdwardRaff/JSAT
JSAT/src/jsat/math/optimization/stochastic/AdaDelta.java
AdaDelta.setRho
public void setRho(double rho) { if(rho <= 0 || rho >= 1 || Double.isNaN(rho)) throw new IllegalArgumentException("Rho must be in (0, 1)"); this.rho = rho; }
java
public void setRho(double rho) { if(rho <= 0 || rho >= 1 || Double.isNaN(rho)) throw new IllegalArgumentException("Rho must be in (0, 1)"); this.rho = rho; }
[ "public", "void", "setRho", "(", "double", "rho", ")", "{", "if", "(", "rho", "<=", "0", "||", "rho", ">=", "1", "||", "Double", ".", "isNaN", "(", "rho", ")", ")", "throw", "new", "IllegalArgumentException", "(", "\"Rho must be in (0, 1)\"", ")", ";", ...
Sets the decay rate used by AdaDelta. Lower values focus more on the current gradient, where higher values incorporate a longer history. @param rho the decay rate in (0, 1) to use
[ "Sets", "the", "decay", "rate", "used", "by", "AdaDelta", ".", "Lower", "values", "focus", "more", "on", "the", "current", "gradient", "where", "higher", "values", "incorporate", "a", "longer", "history", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/math/optimization/stochastic/AdaDelta.java#L70-L75
train
EdwardRaff/JSAT
JSAT/src/jsat/math/ExponentialMovingStatistics.java
ExponentialMovingStatistics.setSmoothing
public void setSmoothing(double smoothing) { if (smoothing <= 0 || smoothing > 1 || Double.isNaN(smoothing)) throw new IllegalArgumentException("Smoothing must be in (0, 1], not " + smoothing); this.smoothing = smoothing; }
java
public void setSmoothing(double smoothing) { if (smoothing <= 0 || smoothing > 1 || Double.isNaN(smoothing)) throw new IllegalArgumentException("Smoothing must be in (0, 1], not " + smoothing); this.smoothing = smoothing; }
[ "public", "void", "setSmoothing", "(", "double", "smoothing", ")", "{", "if", "(", "smoothing", "<=", "0", "||", "smoothing", ">", "1", "||", "Double", ".", "isNaN", "(", "smoothing", ")", ")", "throw", "new", "IllegalArgumentException", "(", "\"Smoothing mu...
Sets the smoothing parameter value to use. Must be in the range (0, 1]. Changing this value will impact how quickly the statistics adapt to changes, with larger values increasing rate of change and smaller values decreasing it. @param smoothing the smoothing value to use
[ "Sets", "the", "smoothing", "parameter", "value", "to", "use", ".", "Must", "be", "in", "the", "range", "(", "0", "1", "]", ".", "Changing", "this", "value", "will", "impact", "how", "quickly", "the", "statistics", "adapt", "to", "changes", "with", "larg...
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/math/ExponentialMovingStatistics.java#L86-L91
train
EdwardRaff/JSAT
JSAT/src/jsat/math/ExponentialMovingStatistics.java
ExponentialMovingStatistics.add
public void add(double x) { if (Double.isNaN(mean))//fist case { mean = x; variance = 0; } else//general case { //first update stnd deviation variance = (1-smoothing)*(variance + smoothing*Math.pow(x-mean, 2)); mean = (1-smoothing)*mean + smoothing*x; } }
java
public void add(double x) { if (Double.isNaN(mean))//fist case { mean = x; variance = 0; } else//general case { //first update stnd deviation variance = (1-smoothing)*(variance + smoothing*Math.pow(x-mean, 2)); mean = (1-smoothing)*mean + smoothing*x; } }
[ "public", "void", "add", "(", "double", "x", ")", "{", "if", "(", "Double", ".", "isNaN", "(", "mean", ")", ")", "//fist case", "{", "mean", "=", "x", ";", "variance", "=", "0", ";", "}", "else", "//general case", "{", "//first update stnd deviation ", ...
Adds the given data point to the statistics @param x the new value to add to the moving statistics
[ "Adds", "the", "given", "data", "point", "to", "the", "statistics" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/math/ExponentialMovingStatistics.java#L107-L121
train
EdwardRaff/JSAT
JSAT/src/jsat/distributions/discrete/UniformDiscrete.java
UniformDiscrete.setMinMax
public void setMinMax(int min, int max) { if(min >= max) throw new IllegalArgumentException("The input minimum (" + min + ") must be less than the given max (" + max + ")"); this.min = min; this.max = max; }
java
public void setMinMax(int min, int max) { if(min >= max) throw new IllegalArgumentException("The input minimum (" + min + ") must be less than the given max (" + max + ")"); this.min = min; this.max = max; }
[ "public", "void", "setMinMax", "(", "int", "min", ",", "int", "max", ")", "{", "if", "(", "min", ">=", "max", ")", "throw", "new", "IllegalArgumentException", "(", "\"The input minimum (\"", "+", "min", "+", "\") must be less than the given max (\"", "+", "max",...
Sets the minimum and maximum values at the same time, this is useful if setting them one at a time may have caused a conflict with the previous values @param min the new minimum value to occur @param max the new maximum value to occur
[ "Sets", "the", "minimum", "and", "maximum", "values", "at", "the", "same", "time", "this", "is", "useful", "if", "setting", "them", "one", "at", "a", "time", "may", "have", "caused", "a", "conflict", "with", "the", "previous", "values" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/distributions/discrete/UniformDiscrete.java#L55-L61
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/linear/NHERD.java
NHERD.setC
public void setC(double C) { if(Double.isNaN(C) || Double.isInfinite(C) || C <= 0) throw new IllegalArgumentException("C must be a postive constant, not " + C); this.C = C; }
java
public void setC(double C) { if(Double.isNaN(C) || Double.isInfinite(C) || C <= 0) throw new IllegalArgumentException("C must be a postive constant, not " + C); this.C = C; }
[ "public", "void", "setC", "(", "double", "C", ")", "{", "if", "(", "Double", ".", "isNaN", "(", "C", ")", "||", "Double", ".", "isInfinite", "(", "C", ")", "||", "C", "<=", "0", ")", "throw", "new", "IllegalArgumentException", "(", "\"C must be a posti...
Set the aggressiveness parameter. Increasing the value of this parameter increases the aggressiveness of the algorithm. It must be a positive value. This parameter essentially performs a type of regularization on the updates @param C the positive aggressiveness parameter
[ "Set", "the", "aggressiveness", "parameter", ".", "Increasing", "the", "value", "of", "this", "parameter", "increases", "the", "aggressiveness", "of", "the", "algorithm", ".", "It", "must", "be", "a", "positive", "value", ".", "This", "parameter", "essentially",...
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/linear/NHERD.java#L130-L135
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/linear/kernelized/BOGD.java
BOGD.guessRegularization
public static Distribution guessRegularization(DataSet d) { double T2 = d.size(); T2*=T2; return new LogUniform(Math.pow(2, -3)/T2, Math.pow(2, 3)/T2); }
java
public static Distribution guessRegularization(DataSet d) { double T2 = d.size(); T2*=T2; return new LogUniform(Math.pow(2, -3)/T2, Math.pow(2, 3)/T2); }
[ "public", "static", "Distribution", "guessRegularization", "(", "DataSet", "d", ")", "{", "double", "T2", "=", "d", ".", "size", "(", ")", ";", "T2", "*=", "T2", ";", "return", "new", "LogUniform", "(", "Math", ".", "pow", "(", "2", ",", "-", "3", ...
Guesses the distribution to use for the Regularization parameter @param d the dataset to get the guess for @return the guess for the Regularization parameter @see #setRegularization(double)
[ "Guesses", "the", "distribution", "to", "use", "for", "the", "Regularization", "parameter" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/linear/kernelized/BOGD.java#L388-L394
train
EdwardRaff/JSAT
JSAT/src/jsat/utils/IndexTable.java
IndexTable.getReverse
public static <T> Comparator<T> getReverse(final Comparator<T> cmp) { return (T o1, T o2) -> -cmp.compare(o1, o2); }
java
public static <T> Comparator<T> getReverse(final Comparator<T> cmp) { return (T o1, T o2) -> -cmp.compare(o1, o2); }
[ "public", "static", "<", "T", ">", "Comparator", "<", "T", ">", "getReverse", "(", "final", "Comparator", "<", "T", ">", "cmp", ")", "{", "return", "(", "T", "o1", ",", "T", "o2", ")", "->", "-", "cmp", ".", "compare", "(", "o1", ",", "o2", ")"...
Obtains the reverse order comparator @param <T> the data type @param cmp the original comparator @return the reverse order comparator
[ "Obtains", "the", "reverse", "order", "comparator" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/IndexTable.java#L38-L41
train
EdwardRaff/JSAT
JSAT/src/jsat/utils/IndexTable.java
IndexTable.reset
public void reset() { for(int i = 0; i < index.size(); i++) index.set(i, i); }
java
public void reset() { for(int i = 0; i < index.size(); i++) index.set(i, i); }
[ "public", "void", "reset", "(", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "index", ".", "size", "(", ")", ";", "i", "++", ")", "index", ".", "set", "(", "i", ",", "i", ")", ";", "}" ]
Resets the index table so that the returned indices are in linear order, meaning the original input would be returned in its original order instead of sorted order.
[ "Resets", "the", "index", "table", "so", "that", "the", "returned", "indices", "are", "in", "linear", "order", "meaning", "the", "original", "input", "would", "be", "returned", "in", "its", "original", "order", "instead", "of", "sorted", "order", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/IndexTable.java#L111-L115
train
EdwardRaff/JSAT
JSAT/src/jsat/utils/IndexTable.java
IndexTable.sort
public <T extends Comparable<T>> void sort(List<T> list) { sort(list, defaultComp); }
java
public <T extends Comparable<T>> void sort(List<T> list) { sort(list, defaultComp); }
[ "public", "<", "T", "extends", "Comparable", "<", "T", ">", ">", "void", "sort", "(", "List", "<", "T", ">", "list", ")", "{", "sort", "(", "list", ",", "defaultComp", ")", ";", "}" ]
Adjust this index table to contain the sorted index order for the given list @param <T> the data type @param list the list of objects
[ "Adjust", "this", "index", "table", "to", "contain", "the", "sorted", "index", "order", "for", "the", "given", "list" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/IndexTable.java#L151-L154
train
EdwardRaff/JSAT
JSAT/src/jsat/utils/IndexTable.java
IndexTable.sortR
public <T extends Comparable<T>> void sortR(List<T> list) { sort(list, getReverse(defaultComp)); }
java
public <T extends Comparable<T>> void sortR(List<T> list) { sort(list, getReverse(defaultComp)); }
[ "public", "<", "T", "extends", "Comparable", "<", "T", ">", ">", "void", "sortR", "(", "List", "<", "T", ">", "list", ")", "{", "sort", "(", "list", ",", "getReverse", "(", "defaultComp", ")", ")", ";", "}" ]
Adjusts this index table to contain the reverse sorted index order for the given list @param <T> the data type @param list the list of objects
[ "Adjusts", "this", "index", "table", "to", "contain", "the", "reverse", "sorted", "index", "order", "for", "the", "given", "list" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/IndexTable.java#L162-L165
train
EdwardRaff/JSAT
JSAT/src/jsat/utils/IndexTable.java
IndexTable.sort
public <T> void sort(List<T> list, Comparator<T> cmp) { if(index.size() < list.size()) for(int i = index.size(); i < list.size(); i++ ) index.add(i); if(list.size() == index.size()) Collections.sort(index, new IndexViewCompList(list, cmp)); else { Collections.sort(index);//so [0, list.size) is at the front Collections.sort(index.subList(0, list.size()), new IndexViewCompList(list, cmp)); } prevSize = list.size(); }
java
public <T> void sort(List<T> list, Comparator<T> cmp) { if(index.size() < list.size()) for(int i = index.size(); i < list.size(); i++ ) index.add(i); if(list.size() == index.size()) Collections.sort(index, new IndexViewCompList(list, cmp)); else { Collections.sort(index);//so [0, list.size) is at the front Collections.sort(index.subList(0, list.size()), new IndexViewCompList(list, cmp)); } prevSize = list.size(); }
[ "public", "<", "T", ">", "void", "sort", "(", "List", "<", "T", ">", "list", ",", "Comparator", "<", "T", ">", "cmp", ")", "{", "if", "(", "index", ".", "size", "(", ")", "<", "list", ".", "size", "(", ")", ")", "for", "(", "int", "i", "=",...
Sets up the index table based on the given list of the same size and comparator. @param <T> the type in use @param list the list of points to obtain a sorted IndexTable for @param cmp the comparator to determined the sorted order
[ "Sets", "up", "the", "index", "table", "based", "on", "the", "given", "list", "of", "the", "same", "size", "and", "comparator", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/IndexTable.java#L176-L189
train
EdwardRaff/JSAT
JSAT/src/jsat/SimpleDataSet.java
SimpleDataSet.asClassificationDataSet
public ClassificationDataSet asClassificationDataSet(int index) { if(index < 0) throw new IllegalArgumentException("Index must be a non-negative value"); else if(getNumCategoricalVars() == 0) throw new IllegalArgumentException("Dataset has no categorical variables, can not create classification dataset"); else if(index >= getNumCategoricalVars()) throw new IllegalArgumentException("Index " + index + " is larger than number of categorical features " + getNumCategoricalVars()); return new ClassificationDataSet(this, index); }
java
public ClassificationDataSet asClassificationDataSet(int index) { if(index < 0) throw new IllegalArgumentException("Index must be a non-negative value"); else if(getNumCategoricalVars() == 0) throw new IllegalArgumentException("Dataset has no categorical variables, can not create classification dataset"); else if(index >= getNumCategoricalVars()) throw new IllegalArgumentException("Index " + index + " is larger than number of categorical features " + getNumCategoricalVars()); return new ClassificationDataSet(this, index); }
[ "public", "ClassificationDataSet", "asClassificationDataSet", "(", "int", "index", ")", "{", "if", "(", "index", "<", "0", ")", "throw", "new", "IllegalArgumentException", "(", "\"Index must be a non-negative value\"", ")", ";", "else", "if", "(", "getNumCategoricalVa...
Converts this dataset into one meant for classification problems. The given categorical feature index is removed from the data and made the target variable for the classification problem. @param index the classification variable index, should be in the range [0, {@link #getNumCategoricalVars() }) @return a new dataset where one categorical variable is removed and made the target of a classification dataset
[ "Converts", "this", "dataset", "into", "one", "meant", "for", "classification", "problems", ".", "The", "given", "categorical", "feature", "index", "is", "removed", "from", "the", "data", "and", "made", "the", "target", "variable", "for", "the", "classification"...
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/SimpleDataSet.java#L88-L97
train
EdwardRaff/JSAT
JSAT/src/jsat/SimpleDataSet.java
SimpleDataSet.asRegressionDataSet
public RegressionDataSet asRegressionDataSet(int index) { if(index < 0) throw new IllegalArgumentException("Index must be a non-negative value"); else if(getNumNumericalVars()== 0) throw new IllegalArgumentException("Dataset has no numeric variables, can not create regression dataset"); else if(index >= getNumNumericalVars()) throw new IllegalArgumentException("Index " + index + " i larger than number of numeric features " + getNumNumericalVars()); RegressionDataSet rds = new RegressionDataSet(this.datapoints.toList(), index); for(int i = 0; i < size(); i++) rds.setWeight(i, this.getWeight(i)); return rds; }
java
public RegressionDataSet asRegressionDataSet(int index) { if(index < 0) throw new IllegalArgumentException("Index must be a non-negative value"); else if(getNumNumericalVars()== 0) throw new IllegalArgumentException("Dataset has no numeric variables, can not create regression dataset"); else if(index >= getNumNumericalVars()) throw new IllegalArgumentException("Index " + index + " i larger than number of numeric features " + getNumNumericalVars()); RegressionDataSet rds = new RegressionDataSet(this.datapoints.toList(), index); for(int i = 0; i < size(); i++) rds.setWeight(i, this.getWeight(i)); return rds; }
[ "public", "RegressionDataSet", "asRegressionDataSet", "(", "int", "index", ")", "{", "if", "(", "index", "<", "0", ")", "throw", "new", "IllegalArgumentException", "(", "\"Index must be a non-negative value\"", ")", ";", "else", "if", "(", "getNumNumericalVars", "("...
Converts this dataset into one meant for regression problems. The given numeric feature index is removed from the data and made the target variable for the regression problem. @param index the regression variable index, should be in the range [0, {@link #getNumNumericalVars() }) @return a new dataset where one numeric variable is removed and made the target of a regression dataset
[ "Converts", "this", "dataset", "into", "one", "meant", "for", "regression", "problems", ".", "The", "given", "numeric", "feature", "index", "is", "removed", "from", "the", "data", "and", "made", "the", "target", "variable", "for", "the", "regression", "problem...
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/SimpleDataSet.java#L109-L122
train
EdwardRaff/JSAT
JSAT/src/jsat/math/optimization/NelderMead.java
NelderMead.setReflection
public void setReflection(double reflection) { if(reflection <=0 || Double.isNaN(reflection) || Double.isInfinite(reflection) ) throw new ArithmeticException("Reflection constant must be > 0, not " + reflection); this.reflection = reflection; }
java
public void setReflection(double reflection) { if(reflection <=0 || Double.isNaN(reflection) || Double.isInfinite(reflection) ) throw new ArithmeticException("Reflection constant must be > 0, not " + reflection); this.reflection = reflection; }
[ "public", "void", "setReflection", "(", "double", "reflection", ")", "{", "if", "(", "reflection", "<=", "0", "||", "Double", ".", "isNaN", "(", "reflection", ")", "||", "Double", ".", "isInfinite", "(", "reflection", ")", ")", "throw", "new", "ArithmeticE...
Sets the reflection constant, which must be greater than 0 @param reflection the reflection constant
[ "Sets", "the", "reflection", "constant", "which", "must", "be", "greater", "than", "0" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/math/optimization/NelderMead.java#L61-L66
train
EdwardRaff/JSAT
JSAT/src/jsat/math/optimization/NelderMead.java
NelderMead.setExpansion
public void setExpansion(double expansion) { if(expansion <= 1 || Double.isNaN(expansion) || Double.isInfinite(expansion) ) throw new ArithmeticException("Expansion constant must be > 1, not " + expansion); else if(expansion <= reflection) throw new ArithmeticException("Expansion constant must be less than the reflection constant"); this.expansion = expansion; }
java
public void setExpansion(double expansion) { if(expansion <= 1 || Double.isNaN(expansion) || Double.isInfinite(expansion) ) throw new ArithmeticException("Expansion constant must be > 1, not " + expansion); else if(expansion <= reflection) throw new ArithmeticException("Expansion constant must be less than the reflection constant"); this.expansion = expansion; }
[ "public", "void", "setExpansion", "(", "double", "expansion", ")", "{", "if", "(", "expansion", "<=", "1", "||", "Double", ".", "isNaN", "(", "expansion", ")", "||", "Double", ".", "isInfinite", "(", "expansion", ")", ")", "throw", "new", "ArithmeticExcept...
Sets the expansion constant, which must be greater than 1 and the reflection constant @param expansion
[ "Sets", "the", "expansion", "constant", "which", "must", "be", "greater", "than", "1", "and", "the", "reflection", "constant" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/math/optimization/NelderMead.java#L72-L79
train
EdwardRaff/JSAT
JSAT/src/jsat/linear/Matrix.java
Matrix.transpose
public Matrix transpose() { Matrix toReturn = new DenseMatrix(cols(), rows()); this.transpose(toReturn); return toReturn; }
java
public Matrix transpose() { Matrix toReturn = new DenseMatrix(cols(), rows()); this.transpose(toReturn); return toReturn; }
[ "public", "Matrix", "transpose", "(", ")", "{", "Matrix", "toReturn", "=", "new", "DenseMatrix", "(", "cols", "(", ")", ",", "rows", "(", ")", ")", ";", "this", ".", "transpose", "(", "toReturn", ")", ";", "return", "toReturn", ";", "}" ]
Returns a new matrix that is the transpose of this matrix. @return a new matrix <tt>A</tt>'
[ "Returns", "a", "new", "matrix", "that", "is", "the", "transpose", "of", "this", "matrix", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/linear/Matrix.java#L440-L445
train
EdwardRaff/JSAT
JSAT/src/jsat/linear/Matrix.java
Matrix.copyTo
public void copyTo(Matrix other) { if (this.rows() != other.rows() || this.cols() != other.cols()) throw new ArithmeticException("Matrices are not of the same dimension"); for(int i = 0; i < rows(); i++) this.getRowView(i).copyTo(other.getRowView(i)); }
java
public void copyTo(Matrix other) { if (this.rows() != other.rows() || this.cols() != other.cols()) throw new ArithmeticException("Matrices are not of the same dimension"); for(int i = 0; i < rows(); i++) this.getRowView(i).copyTo(other.getRowView(i)); }
[ "public", "void", "copyTo", "(", "Matrix", "other", ")", "{", "if", "(", "this", ".", "rows", "(", ")", "!=", "other", ".", "rows", "(", ")", "||", "this", ".", "cols", "(", ")", "!=", "other", ".", "cols", "(", ")", ")", "throw", "new", "Arith...
Copes the values of this matrix into the other matrix of the same dimensions @param other the matrix to overwrite the values of
[ "Copes", "the", "values", "of", "this", "matrix", "into", "the", "other", "matrix", "of", "the", "same", "dimensions" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/linear/Matrix.java#L849-L855
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/svm/SupportVectorLearner.java
SupportVectorLearner.accessingRow
protected void accessingRow(int r) { if (r < 0) { specific_row_cache_row = -1; specific_row_cache_values = null; return; } if(cacheMode == CacheMode.ROWS) { double[] cache = partialCache.get(r); if (cache == null)//not present { //make a row cache = new double[vecs.size()]; Arrays.fill(cache, Double.NaN); double[] cache_missed = partialCache.putIfAbsentAndGet(r, cache); if(cache_missed != null) cache = cache_missed; } specific_row_cache_values = cache; specific_row_cache_row = r; } }
java
protected void accessingRow(int r) { if (r < 0) { specific_row_cache_row = -1; specific_row_cache_values = null; return; } if(cacheMode == CacheMode.ROWS) { double[] cache = partialCache.get(r); if (cache == null)//not present { //make a row cache = new double[vecs.size()]; Arrays.fill(cache, Double.NaN); double[] cache_missed = partialCache.putIfAbsentAndGet(r, cache); if(cache_missed != null) cache = cache_missed; } specific_row_cache_values = cache; specific_row_cache_row = r; } }
[ "protected", "void", "accessingRow", "(", "int", "r", ")", "{", "if", "(", "r", "<", "0", ")", "{", "specific_row_cache_row", "=", "-", "1", ";", "specific_row_cache_values", "=", "null", ";", "return", ";", "}", "if", "(", "cacheMode", "==", "CacheMode"...
This method allows the caller to hint that they are about to access many kernel values for a specific row. The row may be selected out from the cache into its own location to avoid excess LRU overhead. Giving a negative index indicates that we are done with the row, and removes it. This method may be called multiple times with different row values. But when done accessing a specific row, a negative value should be passed in. @param r the row to cache explicitly to avoid LRU overhead. Or a negative value to indicate that we are done with any specific row.
[ "This", "method", "allows", "the", "caller", "to", "hint", "that", "they", "are", "about", "to", "access", "many", "kernel", "values", "for", "a", "specific", "row", ".", "The", "row", "may", "be", "selected", "out", "from", "the", "cache", "into", "its"...
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/svm/SupportVectorLearner.java#L409-L434
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/svm/SupportVectorLearner.java
SupportVectorLearner.k
protected double k(int a, int b) { evalCount++; return kernel.eval(a, b, vecs, accelCache); }
java
protected double k(int a, int b) { evalCount++; return kernel.eval(a, b, vecs, accelCache); }
[ "protected", "double", "k", "(", "int", "a", ",", "int", "b", ")", "{", "evalCount", "++", ";", "return", "kernel", ".", "eval", "(", "a", ",", "b", ",", "vecs", ",", "accelCache", ")", ";", "}" ]
Internal kernel eval source. Only call directly if you KNOW you will not be re-using the resulting value and intentionally wish to skip the caching system @param a the first vector index @param b the second vector index @return the kernel evaluation of k(a, b)
[ "Internal", "kernel", "eval", "source", ".", "Only", "call", "directly", "if", "you", "KNOW", "you", "will", "not", "be", "re", "-", "using", "the", "resulting", "value", "and", "intentionally", "wish", "to", "skip", "the", "caching", "system" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/svm/SupportVectorLearner.java#L445-L449
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/svm/SupportVectorLearner.java
SupportVectorLearner.sparsify
protected void sparsify() { final int N = vecs.size(); int accSize = accelCache == null ? 0 : accelCache.size()/N; int svCount = 0; for(int i = 0; i < N; i++) if(alphas[i] != 0)//Its a support vector { ListUtils.swap(vecs, svCount, i); if(accelCache != null) for(int j = i*accSize; j < (i+1)*accSize; j++) ListUtils.swap(accelCache, svCount*accSize+j-i*accSize, j); alphas[svCount++] = alphas[i]; } vecs = new ArrayList<Vec>(vecs.subList(0, svCount)); alphas = Arrays.copyOfRange(alphas, 0, svCount); }
java
protected void sparsify() { final int N = vecs.size(); int accSize = accelCache == null ? 0 : accelCache.size()/N; int svCount = 0; for(int i = 0; i < N; i++) if(alphas[i] != 0)//Its a support vector { ListUtils.swap(vecs, svCount, i); if(accelCache != null) for(int j = i*accSize; j < (i+1)*accSize; j++) ListUtils.swap(accelCache, svCount*accSize+j-i*accSize, j); alphas[svCount++] = alphas[i]; } vecs = new ArrayList<Vec>(vecs.subList(0, svCount)); alphas = Arrays.copyOfRange(alphas, 0, svCount); }
[ "protected", "void", "sparsify", "(", ")", "{", "final", "int", "N", "=", "vecs", ".", "size", "(", ")", ";", "int", "accSize", "=", "accelCache", "==", "null", "?", "0", ":", "accelCache", ".", "size", "(", ")", "/", "N", ";", "int", "svCount", ...
Sparsifies the SVM by removing the vectors with &alpha; = 0 from the dataset.
[ "Sparsifies", "the", "SVM", "by", "removing", "the", "vectors", "with", "&alpha", ";", "=", "0", "from", "the", "dataset", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/svm/SupportVectorLearner.java#L455-L472
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/linear/SDCA.java
SDCA.setLambda
@Parameter.WarmParameter(prefLowToHigh = false) public void setLambda(double lambda) { if(lambda <= 0 || Double.isInfinite(lambda) || Double.isNaN(lambda)) throw new IllegalArgumentException("Regularization term lambda must be a positive value, not " + lambda); this.lambda = lambda; }
java
@Parameter.WarmParameter(prefLowToHigh = false) public void setLambda(double lambda) { if(lambda <= 0 || Double.isInfinite(lambda) || Double.isNaN(lambda)) throw new IllegalArgumentException("Regularization term lambda must be a positive value, not " + lambda); this.lambda = lambda; }
[ "@", "Parameter", ".", "WarmParameter", "(", "prefLowToHigh", "=", "false", ")", "public", "void", "setLambda", "(", "double", "lambda", ")", "{", "if", "(", "lambda", "<=", "0", "||", "Double", ".", "isInfinite", "(", "lambda", ")", "||", "Double", ".",...
Sets the regularization term, where larger values indicate a larger regularization penalty. @param lambda the positive regularization term
[ "Sets", "the", "regularization", "term", "where", "larger", "values", "indicate", "a", "larger", "regularization", "penalty", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/linear/SDCA.java#L172-L178
train
EdwardRaff/JSAT
JSAT/src/jsat/regression/RegressionDataSet.java
RegressionDataSet.addDataPoint
public void addDataPoint(Vec numerical, int[] categories, double val) { if(numerical.length() != numNumerVals) throw new RuntimeException("Data point does not contain enough numerical data points"); if(categories.length != categories.length) throw new RuntimeException("Data point does not contain enough categorical data points"); for(int i = 0; i < categories.length; i++) if(!this.categories[i].isValidCategory(categories[i]) && categories[i] >= 0) // >= so that missing values (negative) are allowed throw new RuntimeException("Categoriy value given is invalid"); DataPoint dp = new DataPoint(numerical, categories, this.categories); addDataPoint(dp, val); }
java
public void addDataPoint(Vec numerical, int[] categories, double val) { if(numerical.length() != numNumerVals) throw new RuntimeException("Data point does not contain enough numerical data points"); if(categories.length != categories.length) throw new RuntimeException("Data point does not contain enough categorical data points"); for(int i = 0; i < categories.length; i++) if(!this.categories[i].isValidCategory(categories[i]) && categories[i] >= 0) // >= so that missing values (negative) are allowed throw new RuntimeException("Categoriy value given is invalid"); DataPoint dp = new DataPoint(numerical, categories, this.categories); addDataPoint(dp, val); }
[ "public", "void", "addDataPoint", "(", "Vec", "numerical", ",", "int", "[", "]", "categories", ",", "double", "val", ")", "{", "if", "(", "numerical", ".", "length", "(", ")", "!=", "numNumerVals", ")", "throw", "new", "RuntimeException", "(", "\"Data poin...
Creates a new data point to be added to the data set. The arguments will be used directly, modifying them after will effect the data set. @param numerical the numerical values for the data point @param categories the categorical values for the data point @param val the target value to predict @throws IllegalArgumentException if the given values are inconsistent with the data this class stores.
[ "Creates", "a", "new", "data", "point", "to", "be", "added", "to", "the", "data", "set", ".", "The", "arguments", "will", "be", "used", "directly", "modifying", "them", "after", "will", "effect", "the", "data", "set", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/regression/RegressionDataSet.java#L164-L177
train
EdwardRaff/JSAT
JSAT/src/jsat/regression/RegressionDataSet.java
RegressionDataSet.getDataPointPair
public DataPointPair<Double> getDataPointPair(int i) { return new DataPointPair<>(getDataPoint(i), targets.get(i)); }
java
public DataPointPair<Double> getDataPointPair(int i) { return new DataPointPair<>(getDataPoint(i), targets.get(i)); }
[ "public", "DataPointPair", "<", "Double", ">", "getDataPointPair", "(", "int", "i", ")", "{", "return", "new", "DataPointPair", "<>", "(", "getDataPoint", "(", "i", ")", ",", "targets", ".", "get", "(", "i", ")", ")", ";", "}" ]
Returns the i'th data point in the data set paired with its target regressor value. Modifying the DataPointPair will effect the data set. @param i the index of the data point to obtain @return the i'th DataPOintPair
[ "Returns", "the", "i", "th", "data", "point", "in", "the", "data", "set", "paired", "with", "its", "target", "regressor", "value", ".", "Modifying", "the", "DataPointPair", "will", "effect", "the", "data", "set", "." ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/regression/RegressionDataSet.java#L219-L222
train
EdwardRaff/JSAT
JSAT/src/jsat/datatransform/RemoveAttributeTransform.java
RemoveAttributeTransform.getReverseNumericMap
public Map<Integer, Integer> getReverseNumericMap() { Map<Integer, Integer> map = new HashMap<Integer, Integer>(); for(int newIndex = 0; newIndex < numIndexMap.length; newIndex++) map.put(newIndex, numIndexMap[newIndex]); return map; }
java
public Map<Integer, Integer> getReverseNumericMap() { Map<Integer, Integer> map = new HashMap<Integer, Integer>(); for(int newIndex = 0; newIndex < numIndexMap.length; newIndex++) map.put(newIndex, numIndexMap[newIndex]); return map; }
[ "public", "Map", "<", "Integer", ",", "Integer", ">", "getReverseNumericMap", "(", ")", "{", "Map", "<", "Integer", ",", "Integer", ">", "map", "=", "new", "HashMap", "<", "Integer", ",", "Integer", ">", "(", ")", ";", "for", "(", "int", "newIndex", ...
Returns a mapping from the numeric indices in the transformed space back to their original indices @return a mapping from the transformed numeric space to the original one
[ "Returns", "a", "mapping", "from", "the", "numeric", "indices", "in", "the", "transformed", "space", "back", "to", "their", "original", "indices" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/datatransform/RemoveAttributeTransform.java#L91-L97
train
EdwardRaff/JSAT
JSAT/src/jsat/datatransform/RemoveAttributeTransform.java
RemoveAttributeTransform.getReverseNominalMap
public Map<Integer, Integer> getReverseNominalMap() { Map<Integer, Integer> map = new HashMap<Integer, Integer>(); for(int newIndex = 0; newIndex < catIndexMap.length; newIndex++) map.put(newIndex, catIndexMap[newIndex]); return map; }
java
public Map<Integer, Integer> getReverseNominalMap() { Map<Integer, Integer> map = new HashMap<Integer, Integer>(); for(int newIndex = 0; newIndex < catIndexMap.length; newIndex++) map.put(newIndex, catIndexMap[newIndex]); return map; }
[ "public", "Map", "<", "Integer", ",", "Integer", ">", "getReverseNominalMap", "(", ")", "{", "Map", "<", "Integer", ",", "Integer", ">", "map", "=", "new", "HashMap", "<", "Integer", ",", "Integer", ">", "(", ")", ";", "for", "(", "int", "newIndex", ...
Returns a mapping from the nominal indices in the transformed space back to their original indices @return a mapping from the transformed nominal space to the original one
[ "Returns", "a", "mapping", "from", "the", "nominal", "indices", "in", "the", "transformed", "space", "back", "to", "their", "original", "indices" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/datatransform/RemoveAttributeTransform.java#L115-L121
train
EdwardRaff/JSAT
JSAT/src/jsat/datatransform/RemoveAttributeTransform.java
RemoveAttributeTransform.setUp
protected final void setUp(DataSet dataSet, Set<Integer> categoricalToRemove, Set<Integer> numericalToRemove) { for(int i : categoricalToRemove) if (i >= dataSet.getNumCategoricalVars()) throw new RuntimeException("The data set does not have a categorical value " + i + " to remove"); for(int i : numericalToRemove) if (i >= dataSet.getNumNumericalVars()) throw new RuntimeException("The data set does not have a numercal value " + i + " to remove"); catIndexMap = new int[dataSet.getNumCategoricalVars()-categoricalToRemove.size()]; newCatHeader = new CategoricalData[catIndexMap.length]; numIndexMap = new int[dataSet.getNumNumericalVars()-numericalToRemove.size()]; int k = 0; for(int i = 0; i < dataSet.getNumCategoricalVars(); i++) { if(categoricalToRemove.contains(i)) continue; newCatHeader[k] = dataSet.getCategories()[i].clone(); catIndexMap[k++] = i; } k = 0; for(int i = 0; i < dataSet.getNumNumericalVars(); i++) { if(numericalToRemove.contains(i)) continue; numIndexMap[k++] = i; } }
java
protected final void setUp(DataSet dataSet, Set<Integer> categoricalToRemove, Set<Integer> numericalToRemove) { for(int i : categoricalToRemove) if (i >= dataSet.getNumCategoricalVars()) throw new RuntimeException("The data set does not have a categorical value " + i + " to remove"); for(int i : numericalToRemove) if (i >= dataSet.getNumNumericalVars()) throw new RuntimeException("The data set does not have a numercal value " + i + " to remove"); catIndexMap = new int[dataSet.getNumCategoricalVars()-categoricalToRemove.size()]; newCatHeader = new CategoricalData[catIndexMap.length]; numIndexMap = new int[dataSet.getNumNumericalVars()-numericalToRemove.size()]; int k = 0; for(int i = 0; i < dataSet.getNumCategoricalVars(); i++) { if(categoricalToRemove.contains(i)) continue; newCatHeader[k] = dataSet.getCategories()[i].clone(); catIndexMap[k++] = i; } k = 0; for(int i = 0; i < dataSet.getNumNumericalVars(); i++) { if(numericalToRemove.contains(i)) continue; numIndexMap[k++] = i; } }
[ "protected", "final", "void", "setUp", "(", "DataSet", "dataSet", ",", "Set", "<", "Integer", ">", "categoricalToRemove", ",", "Set", "<", "Integer", ">", "numericalToRemove", ")", "{", "for", "(", "int", "i", ":", "categoricalToRemove", ")", "if", "(", "i...
Sets up the Remove Attribute Transform properly @param dataSet the data set to remove the attributes from @param categoricalToRemove the categorical attributes to remove @param numericalToRemove the numeric attributes to remove
[ "Sets", "up", "the", "Remove", "Attribute", "Transform", "properly" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/datatransform/RemoveAttributeTransform.java#L137-L164
train