code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
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 |
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 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 |
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... | 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;
... | 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));
} | 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);
} | 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(cur... | 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;
} | 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)]++;
} | 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... | 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 =... | 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;
}
... | 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();
} | 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.initia... | 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 Arit... | java |
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 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(Regressor weakR)
{
if(weakR == null)
throw new NullPointerException();
this.weakR = weakR;
if(weakR instanceof Classifier)
this.weakL = (Classifier) weakR;
} | 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
... | 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
... | java |
private double pdf(double x, int j)
{
/*
* n
* ===== /x - x \
* 1 \ | i|
* f(x) = --- > K|------|
* n h / \ h /
* =====
* i = 1
*
*/
... | java |
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 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 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);... | 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;
} | 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
... | 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 Inde... | 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... | 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;
} | java |
public static List<Double> unmodifiableView(double[] array, int length)
{
return Collections.unmodifiableList(view(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);
} | 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);
} | java |
@Override
public void increment(int index, double val)
{
int baseIndex = getBaseIndex(index);
vecs[baseIndex].increment(index-lengthSums[baseIndex], val);
} | 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;
} | 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);
} | 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);
} | 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);
}
v... | 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);
}
} | 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
... | 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[... | 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;
} | 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);
} | 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);
} | 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;
} | 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;
} | java |
public double getDet()
{
double det = 1;
for(int i = 0; i < L.rows(); i++)
det *= L.get(i, i);
return det;
} | java |
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 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];
fi... | 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)
... | 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)
prun... | 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())
{
... | 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);
} | 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;
} | 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];//h... | 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;
} | java |
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 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 |
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,
... | 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)
{... | java |
protected static double getScore(DataSet workOn, Object evaluater, int folds, Random rand)
{
if(workOn instanceof ClassificationDataSet)
{
ClassificationModelEvaluation cme =
new ClassificationModelEvaluation((Classifier)evaluater,
(Classification... | 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;
} | java |
public static Vec extractTrueVec(Vec b)
{
while(b instanceof VecPaired)
b = ((VecPaired) b).getVector();
return b;
} | 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 ... | 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;
} | 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(d... | 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();
} | 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();
} | 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)
... | 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]... | java |
protected Parameter getParameterByName(String name) throws IllegalArgumentException
{
Parameter param;
if (baseClassifier != null)
param = ((Parameterized) baseClassifier).getParameter(name);
else
param = ((Parameterized) baseRegressor).getParameter(name);
... | java |
private double getPreScore(Vec x)
{
return k.evalSum(vecs, accelCache, alpha.getBackingArray(), x, 0, alpha.size());
} | 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");
... | 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[... | 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;
} | 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;
} | 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... | 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;
} | 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;
} | 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);
} | java |
public static <T> Comparator<T> getReverse(final Comparator<T> cmp)
{
return (T o1, T o2) -> -cmp.compare(o1, o2);
} | java |
public void reset()
{
for(int i = 0; i < index.size(); i++)
index.set(i, i);
} | java |
public <T extends Comparable<T>> void sort(List<T> list)
{
sort(list, defaultComp);
} | java |
public <T extends Comparable<T>> void sortR(List<T> list)
{
sort(list, getReverse(defaultComp));
} | 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
... | 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 n... | 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 regre... | 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;
} | 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("Expa... | java |
public Matrix transpose()
{
Matrix toReturn = new DenseMatrix(cols(), rows());
this.transpose(toReturn);
return toReturn;
} | 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));
} | 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 ==... | java |
protected double k(int a, int b)
{
evalCount++;
return kernel.eval(a, b, vecs, accelCache);
} | 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);
... | 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;
... | 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("D... | java |
public DataPointPair<Double> getDataPointPair(int i)
{
return new DataPointPair<>(getDataPoint(i), targets.get(i));
} | 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;
} | 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;
} | 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 remov... | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.