id int32 0 165k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
17,400 | haifengl/smile | core/src/main/java/smile/association/FPGrowth.java | FPGrowth.grow | private long grow(PrintStream out, List<ItemSet> list, TotalSupportTree ttree, FPTree.Node node, int[] itemset, int support) {
int height = 0;
for (FPTree.Node currentNode = node; currentNode != null; currentNode = currentNode.parent) {
height ++;
}
int n = 0;
if (he... | java | private long grow(PrintStream out, List<ItemSet> list, TotalSupportTree ttree, FPTree.Node node, int[] itemset, int support) {
int height = 0;
for (FPTree.Node currentNode = node; currentNode != null; currentNode = currentNode.parent) {
height ++;
}
int n = 0;
if (he... | [
"private",
"long",
"grow",
"(",
"PrintStream",
"out",
",",
"List",
"<",
"ItemSet",
">",
"list",
",",
"TotalSupportTree",
"ttree",
",",
"FPTree",
".",
"Node",
"node",
",",
"int",
"[",
"]",
"itemset",
",",
"int",
"support",
")",
"{",
"int",
"height",
"="... | Mines all combinations along a single path tree | [
"Mines",
"all",
"combinations",
"along",
"a",
"single",
"path",
"tree"
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/association/FPGrowth.java#L346-L386 |
17,401 | haifengl/smile | core/src/main/java/smile/association/FPGrowth.java | FPGrowth.grow | private long grow(PrintStream out, List<ItemSet> list, TotalSupportTree ttree, HeaderTableItem header, int[] itemset, int[] localItemSupport, int[] prefixItemset) {
long n = 1;
int support = header.count;
int item = header.id;
itemset = insert(itemset, item);
collect(out, list, ... | java | private long grow(PrintStream out, List<ItemSet> list, TotalSupportTree ttree, HeaderTableItem header, int[] itemset, int[] localItemSupport, int[] prefixItemset) {
long n = 1;
int support = header.count;
int item = header.id;
itemset = insert(itemset, item);
collect(out, list, ... | [
"private",
"long",
"grow",
"(",
"PrintStream",
"out",
",",
"List",
"<",
"ItemSet",
">",
"list",
",",
"TotalSupportTree",
"ttree",
",",
"HeaderTableItem",
"header",
",",
"int",
"[",
"]",
"itemset",
",",
"int",
"[",
"]",
"localItemSupport",
",",
"int",
"[",
... | Mines FP-tree with respect to a single element in the header table.
@param header the header table item of interest.
@param itemset the item set represented by the current FP-tree. | [
"Mines",
"FP",
"-",
"tree",
"with",
"respect",
"to",
"a",
"single",
"element",
"in",
"the",
"header",
"table",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/association/FPGrowth.java#L393-L415 |
17,402 | haifengl/smile | core/src/main/java/smile/association/FPGrowth.java | FPGrowth.getLocalItemSupport | private boolean getLocalItemSupport(FPTree.Node node, int[] localItemSupport) {
boolean end = true;
Arrays.fill(localItemSupport, 0);
while (node != null) {
int support = node.count;
Node parent = node.parent;
while (parent != null) {
localItem... | java | private boolean getLocalItemSupport(FPTree.Node node, int[] localItemSupport) {
boolean end = true;
Arrays.fill(localItemSupport, 0);
while (node != null) {
int support = node.count;
Node parent = node.parent;
while (parent != null) {
localItem... | [
"private",
"boolean",
"getLocalItemSupport",
"(",
"FPTree",
".",
"Node",
"node",
",",
"int",
"[",
"]",
"localItemSupport",
")",
"{",
"boolean",
"end",
"=",
"true",
";",
"Arrays",
".",
"fill",
"(",
"localItemSupport",
",",
"0",
")",
";",
"while",
"(",
"no... | Counts the supports of single items in ancestor item sets linked list.
@return true if there are condition patterns given this node | [
"Counts",
"the",
"supports",
"of",
"single",
"items",
"in",
"ancestor",
"item",
"sets",
"linked",
"list",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/association/FPGrowth.java#L421-L437 |
17,403 | haifengl/smile | core/src/main/java/smile/association/FPGrowth.java | FPGrowth.getLocalFPTree | private FPTree getLocalFPTree(FPTree.Node node, int[] localItemSupport, int[] prefixItemset) {
FPTree tree = new FPTree(localItemSupport, minSupport);
while (node != null) {
Node parent = node.parent;
int i = prefixItemset.length;
while (parent != null) {
... | java | private FPTree getLocalFPTree(FPTree.Node node, int[] localItemSupport, int[] prefixItemset) {
FPTree tree = new FPTree(localItemSupport, minSupport);
while (node != null) {
Node parent = node.parent;
int i = prefixItemset.length;
while (parent != null) {
... | [
"private",
"FPTree",
"getLocalFPTree",
"(",
"FPTree",
".",
"Node",
"node",
",",
"int",
"[",
"]",
"localItemSupport",
",",
"int",
"[",
"]",
"prefixItemset",
")",
"{",
"FPTree",
"tree",
"=",
"new",
"FPTree",
"(",
"localItemSupport",
",",
"minSupport",
")",
"... | Generates a local FP tree
@param node the conditional patterns given this node to construct the local FP-tree.
@rerurn the local FP-tree. | [
"Generates",
"a",
"local",
"FP",
"tree"
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/association/FPGrowth.java#L444-L464 |
17,404 | haifengl/smile | core/src/main/java/smile/association/FPGrowth.java | FPGrowth.insert | static int[] insert(int[] itemset, int item) {
if (itemset == null) {
int[] newItemset = {item};
return newItemset;
} else {
int n = itemset.length + 1;
int[] newItemset = new int[n];
newItemset[0] = item;
System.array... | java | static int[] insert(int[] itemset, int item) {
if (itemset == null) {
int[] newItemset = {item};
return newItemset;
} else {
int n = itemset.length + 1;
int[] newItemset = new int[n];
newItemset[0] = item;
System.array... | [
"static",
"int",
"[",
"]",
"insert",
"(",
"int",
"[",
"]",
"itemset",
",",
"int",
"item",
")",
"{",
"if",
"(",
"itemset",
"==",
"null",
")",
"{",
"int",
"[",
"]",
"newItemset",
"=",
"{",
"item",
"}",
";",
"return",
"newItemset",
";",
"}",
"else",... | Insert a item to the front of an item set.
@param itemset the original item set.
@param item the new item to be inserted.
@return the combined item set | [
"Insert",
"a",
"item",
"to",
"the",
"front",
"of",
"an",
"item",
"set",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/association/FPGrowth.java#L472-L486 |
17,405 | haifengl/smile | core/src/main/java/smile/association/FPGrowth.java | FPGrowth.drop | static int[] drop(int[] itemset) {
if (itemset.length >= 1) {
int n = itemset.length - 1;
int[] newItemset = new int[n];
System.arraycopy(itemset, 1, newItemset, 0, n);
return newItemset;
} else {
return null;
}
} | java | static int[] drop(int[] itemset) {
if (itemset.length >= 1) {
int n = itemset.length - 1;
int[] newItemset = new int[n];
System.arraycopy(itemset, 1, newItemset, 0, n);
return newItemset;
} else {
return null;
}
} | [
"static",
"int",
"[",
"]",
"drop",
"(",
"int",
"[",
"]",
"itemset",
")",
"{",
"if",
"(",
"itemset",
".",
"length",
">=",
"1",
")",
"{",
"int",
"n",
"=",
"itemset",
".",
"length",
"-",
"1",
";",
"int",
"[",
"]",
"newItemset",
"=",
"new",
"int",
... | Drops an item form the front of an item set.
@param itemset the original item set.
@return the reduced item set or null if the original is empty | [
"Drops",
"an",
"item",
"form",
"the",
"front",
"of",
"an",
"item",
"set",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/association/FPGrowth.java#L493-L504 |
17,406 | haifengl/smile | plot/src/main/java/smile/plot/Axis.java | Axis.setSlice | private void setSlice() {
// slicing initialisation
if (labels == null) {
double min = base.getPrecisionUnit()[index] * Math.ceil(base.getLowerBounds()[index] / base.getPrecisionUnit()[index]);
double max = base.getPrecisionUnit()[index] * Math.floor(base.getUpperBounds()[index] ... | java | private void setSlice() {
// slicing initialisation
if (labels == null) {
double min = base.getPrecisionUnit()[index] * Math.ceil(base.getLowerBounds()[index] / base.getPrecisionUnit()[index]);
double max = base.getPrecisionUnit()[index] * Math.floor(base.getUpperBounds()[index] ... | [
"private",
"void",
"setSlice",
"(",
")",
"{",
"// slicing initialisation",
"if",
"(",
"labels",
"==",
"null",
")",
"{",
"double",
"min",
"=",
"base",
".",
"getPrecisionUnit",
"(",
")",
"[",
"index",
"]",
"*",
"Math",
".",
"ceil",
"(",
"base",
".",
"get... | Set the slices of axis. | [
"Set",
"the",
"slices",
"of",
"axis",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/plot/src/main/java/smile/plot/Axis.java#L139-L187 |
17,407 | haifengl/smile | plot/src/main/java/smile/plot/Axis.java | Axis.initGridLines | private void initGridLines() {
gridLines = new Line[base.getDimension() - 1][linesSlicing.length];
int i2 = 0;
for (int i = 0; i < base.getDimension() - 1; i++) {
if (i2 == index) {
i2++;
}
for (int j = 0; j < gridLines[i].length; j++) {
... | java | private void initGridLines() {
gridLines = new Line[base.getDimension() - 1][linesSlicing.length];
int i2 = 0;
for (int i = 0; i < base.getDimension() - 1; i++) {
if (i2 == index) {
i2++;
}
for (int j = 0; j < gridLines[i].length; j++) {
... | [
"private",
"void",
"initGridLines",
"(",
")",
"{",
"gridLines",
"=",
"new",
"Line",
"[",
"base",
".",
"getDimension",
"(",
")",
"-",
"1",
"]",
"[",
"linesSlicing",
".",
"length",
"]",
";",
"int",
"i2",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
... | Initialize grid lines. | [
"Initialize",
"grid",
"lines",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/plot/src/main/java/smile/plot/Axis.java#L267-L296 |
17,408 | haifengl/smile | plot/src/main/java/smile/plot/Axis.java | Axis.removeLabel | public Axis removeLabel(String label) {
if (labels == null) {
throw new IllegalStateException();
}
labels.remove(label);
setSlice();
initGridLabels();
return this;
} | java | public Axis removeLabel(String label) {
if (labels == null) {
throw new IllegalStateException();
}
labels.remove(label);
setSlice();
initGridLabels();
return this;
} | [
"public",
"Axis",
"removeLabel",
"(",
"String",
"label",
")",
"{",
"if",
"(",
"labels",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
")",
";",
"}",
"labels",
".",
"remove",
"(",
"label",
")",
";",
"setSlice",
"(",
")",
";",
"... | Remove a label from the axis. | [
"Remove",
"a",
"label",
"from",
"the",
"axis",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/plot/src/main/java/smile/plot/Axis.java#L359-L368 |
17,409 | haifengl/smile | plot/src/main/java/smile/plot/Axis.java | Axis.setAxisLabel | public Axis setAxisLabel(String label) {
if (label == null) {
if (index == 0) {
label = "X";
} else if (index == 1) {
label = "Y";
} else if (index == 2) {
label = "Z";
}
}
if (label != null) {
... | java | public Axis setAxisLabel(String label) {
if (label == null) {
if (index == 0) {
label = "X";
} else if (index == 1) {
label = "Y";
} else if (index == 2) {
label = "Z";
}
}
if (label != null) {
... | [
"public",
"Axis",
"setAxisLabel",
"(",
"String",
"label",
")",
"{",
"if",
"(",
"label",
"==",
"null",
")",
"{",
"if",
"(",
"index",
"==",
"0",
")",
"{",
"label",
"=",
"\"X\"",
";",
"}",
"else",
"if",
"(",
"index",
"==",
"1",
")",
"{",
"label",
... | Sets the label of this axis. | [
"Sets",
"the",
"label",
"of",
"this",
"axis",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/plot/src/main/java/smile/plot/Axis.java#L425-L467 |
17,410 | haifengl/smile | plot/src/main/java/smile/plot/Axis.java | Axis.paint | public void paint(Graphics g) {
if (gridLines != null) {
if (gridVisible) {
for (int i = 0; i < gridLines.length; i++) {
for (int j = 1; j < gridLines[i].length - 1; j++) {
gridLines[i][j].paint(g);
}
}
... | java | public void paint(Graphics g) {
if (gridLines != null) {
if (gridVisible) {
for (int i = 0; i < gridLines.length; i++) {
for (int j = 1; j < gridLines[i].length - 1; j++) {
gridLines[i][j].paint(g);
}
}
... | [
"public",
"void",
"paint",
"(",
"Graphics",
"g",
")",
"{",
"if",
"(",
"gridLines",
"!=",
"null",
")",
"{",
"if",
"(",
"gridVisible",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"gridLines",
".",
"length",
";",
"i",
"++",
")",
"{"... | Draw the axis. | [
"Draw",
"the",
"axis",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/plot/src/main/java/smile/plot/Axis.java#L483-L544 |
17,411 | haifengl/smile | core/src/main/java/smile/gap/BitString.java | BitString.singlePointCrossover | private void singlePointCrossover(BitString father, BitString mother, BitString[] offsprings) {
int point = 0; // crossover point
while (point == 0) {
point = Math.randomInt(length);
}
int[] son = new int[length];
System.arraycopy(father.bits, 0, son, 0, point);
... | java | private void singlePointCrossover(BitString father, BitString mother, BitString[] offsprings) {
int point = 0; // crossover point
while (point == 0) {
point = Math.randomInt(length);
}
int[] son = new int[length];
System.arraycopy(father.bits, 0, son, 0, point);
... | [
"private",
"void",
"singlePointCrossover",
"(",
"BitString",
"father",
",",
"BitString",
"mother",
",",
"BitString",
"[",
"]",
"offsprings",
")",
"{",
"int",
"point",
"=",
"0",
";",
"// crossover point",
"while",
"(",
"point",
"==",
"0",
")",
"{",
"point",
... | Single point crossover. | [
"Single",
"point",
"crossover",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/gap/BitString.java#L241-L257 |
17,412 | haifengl/smile | core/src/main/java/smile/gap/BitString.java | BitString.twoPointCrossover | private void twoPointCrossover(BitString father, BitString mother, BitString[] offsprings) {
int point1 = 0; // first crossover point
while (point1 == 0 || point1 == length - 1) {
point1 = Math.randomInt(length);
}
int point2 = 0; // second crossover point
while (poi... | java | private void twoPointCrossover(BitString father, BitString mother, BitString[] offsprings) {
int point1 = 0; // first crossover point
while (point1 == 0 || point1 == length - 1) {
point1 = Math.randomInt(length);
}
int point2 = 0; // second crossover point
while (poi... | [
"private",
"void",
"twoPointCrossover",
"(",
"BitString",
"father",
",",
"BitString",
"mother",
",",
"BitString",
"[",
"]",
"offsprings",
")",
"{",
"int",
"point1",
"=",
"0",
";",
"// first crossover point",
"while",
"(",
"point1",
"==",
"0",
"||",
"point1",
... | Two point crossover. | [
"Two",
"point",
"crossover",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/gap/BitString.java#L262-L291 |
17,413 | haifengl/smile | core/src/main/java/smile/gap/BitString.java | BitString.uniformCrossover | private void uniformCrossover(BitString father, BitString mother, BitString[] offsprings) {
int[] son = new int[length];
int[] daughter = new int[length];
for (int i = 0; i < length; i++) {
if (Math.random() < 0.5) {
son[i] = father.bits[i];
daughter[... | java | private void uniformCrossover(BitString father, BitString mother, BitString[] offsprings) {
int[] son = new int[length];
int[] daughter = new int[length];
for (int i = 0; i < length; i++) {
if (Math.random() < 0.5) {
son[i] = father.bits[i];
daughter[... | [
"private",
"void",
"uniformCrossover",
"(",
"BitString",
"father",
",",
"BitString",
"mother",
",",
"BitString",
"[",
"]",
"offsprings",
")",
"{",
"int",
"[",
"]",
"son",
"=",
"new",
"int",
"[",
"length",
"]",
";",
"int",
"[",
"]",
"daughter",
"=",
"ne... | Uniform crossover. | [
"Uniform",
"crossover",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/gap/BitString.java#L296-L312 |
17,414 | haifengl/smile | core/src/main/java/smile/projection/PCA.java | PCA.setProjection | public PCA setProjection(int p) {
if (p < 1 || p > n) {
throw new IllegalArgumentException("Invalid dimension of feature space: " + p);
}
this.p = p;
projection = Matrix.zeros(p, n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < p; j++) {
... | java | public PCA setProjection(int p) {
if (p < 1 || p > n) {
throw new IllegalArgumentException("Invalid dimension of feature space: " + p);
}
this.p = p;
projection = Matrix.zeros(p, n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < p; j++) {
... | [
"public",
"PCA",
"setProjection",
"(",
"int",
"p",
")",
"{",
"if",
"(",
"p",
"<",
"1",
"||",
"p",
">",
"n",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid dimension of feature space: \"",
"+",
"p",
")",
";",
"}",
"this",
".",
"p",
... | Set the projection matrix with given number of principal components.
@param p choose top p principal components used for projection. | [
"Set",
"the",
"projection",
"matrix",
"with",
"given",
"number",
"of",
"principal",
"components",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/projection/PCA.java#L251-L268 |
17,415 | haifengl/smile | plot/src/main/java/smile/swing/table/DefaultTableHeaderCellRenderer.java | DefaultTableHeaderCellRenderer.getSortKey | @SuppressWarnings("rawtypes")
protected SortKey getSortKey(JTable table, int column) {
RowSorter rowSorter = table.getRowSorter();
if (rowSorter == null) {
return null;
}
List sortedColumns = rowSorter.getSortKeys();
if (!sortedColumns.isEmpty()) {
re... | java | @SuppressWarnings("rawtypes")
protected SortKey getSortKey(JTable table, int column) {
RowSorter rowSorter = table.getRowSorter();
if (rowSorter == null) {
return null;
}
List sortedColumns = rowSorter.getSortKeys();
if (!sortedColumns.isEmpty()) {
re... | [
"@",
"SuppressWarnings",
"(",
"\"rawtypes\"",
")",
"protected",
"SortKey",
"getSortKey",
"(",
"JTable",
"table",
",",
"int",
"column",
")",
"{",
"RowSorter",
"rowSorter",
"=",
"table",
".",
"getRowSorter",
"(",
")",
";",
"if",
"(",
"rowSorter",
"==",
"null",... | Returns the current sort key, or null if the column is unsorted.
@param table the table
@param column the column index
@return the SortKey, or null if the column is unsorted | [
"Returns",
"the",
"current",
"sort",
"key",
"or",
"null",
"if",
"the",
"column",
"is",
"unsorted",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/plot/src/main/java/smile/swing/table/DefaultTableHeaderCellRenderer.java#L122-L134 |
17,416 | haifengl/smile | plot/src/main/java/smile/plot/PlotPanel.java | PlotPanel.organize | private void organize() {
int m = (int) Math.sqrt(contentPane.getComponentCount());
if (m <= 0) m = 1;
contentPane.setLayout(new GridLayout(m, 0, 0, 0));
} | java | private void organize() {
int m = (int) Math.sqrt(contentPane.getComponentCount());
if (m <= 0) m = 1;
contentPane.setLayout(new GridLayout(m, 0, 0, 0));
} | [
"private",
"void",
"organize",
"(",
")",
"{",
"int",
"m",
"=",
"(",
"int",
")",
"Math",
".",
"sqrt",
"(",
"contentPane",
".",
"getComponentCount",
"(",
")",
")",
";",
"if",
"(",
"m",
"<=",
"0",
")",
"m",
"=",
"1",
";",
"contentPane",
".",
"setLay... | Reorganize the plots in the frame. Basically, it reset the surface layout
based on the number of plots in the frame. | [
"Reorganize",
"the",
"plots",
"in",
"the",
"frame",
".",
"Basically",
"it",
"reset",
"the",
"surface",
"layout",
"based",
"on",
"the",
"number",
"of",
"plots",
"in",
"the",
"frame",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/plot/src/main/java/smile/plot/PlotPanel.java#L114-L118 |
17,417 | haifengl/smile | plot/src/main/java/smile/plot/PlotPanel.java | PlotPanel.initToolBar | private void initToolBar() {
toolbar = new JToolBar(JToolBar.VERTICAL);
toolbar.setFloatable(false);
add(toolbar, BorderLayout.WEST);
JButton button = makeButton("save", SAVE, "Save", "Save");
toolbar.add(button);
button = makeButton("print", PRINT, "Print", "Pr... | java | private void initToolBar() {
toolbar = new JToolBar(JToolBar.VERTICAL);
toolbar.setFloatable(false);
add(toolbar, BorderLayout.WEST);
JButton button = makeButton("save", SAVE, "Save", "Save");
toolbar.add(button);
button = makeButton("print", PRINT, "Print", "Pr... | [
"private",
"void",
"initToolBar",
"(",
")",
"{",
"toolbar",
"=",
"new",
"JToolBar",
"(",
"JToolBar",
".",
"VERTICAL",
")",
";",
"toolbar",
".",
"setFloatable",
"(",
"false",
")",
";",
"add",
"(",
"toolbar",
",",
"BorderLayout",
".",
"WEST",
")",
";",
"... | Initialize toolbar. | [
"Initialize",
"toolbar",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/plot/src/main/java/smile/plot/PlotPanel.java#L139-L149 |
17,418 | haifengl/smile | plot/src/main/java/smile/plot/PlotPanel.java | PlotPanel.makeButton | private JButton makeButton(String imageName, String actionCommand, String toolTipText, String altText) {
//Look for the image.
String imgLocation = "images/" + imageName + "16.png";
URL imageURL = PlotCanvas.class.getResource(imgLocation);
//Create and initialize the button.
JBu... | java | private JButton makeButton(String imageName, String actionCommand, String toolTipText, String altText) {
//Look for the image.
String imgLocation = "images/" + imageName + "16.png";
URL imageURL = PlotCanvas.class.getResource(imgLocation);
//Create and initialize the button.
JBu... | [
"private",
"JButton",
"makeButton",
"(",
"String",
"imageName",
",",
"String",
"actionCommand",
",",
"String",
"toolTipText",
",",
"String",
"altText",
")",
"{",
"//Look for the image.",
"String",
"imgLocation",
"=",
"\"images/\"",
"+",
"imageName",
"+",
"\"16.png\"... | Creates a button for toolbar. | [
"Creates",
"a",
"button",
"for",
"toolbar",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/plot/src/main/java/smile/plot/PlotPanel.java#L154-L173 |
17,419 | haifengl/smile | core/src/main/java/smile/util/SmileUtils.java | SmileUtils.sort | public static int[][] sort(Attribute[] attributes, double[][] x) {
int n = x.length;
int p = x[0].length;
double[] a = new double[n];
int[][] index = new int[p][];
for (int j = 0; j < p; j++) {
if (attributes[j].getType() == Attribute.Type.NUMERIC) {... | java | public static int[][] sort(Attribute[] attributes, double[][] x) {
int n = x.length;
int p = x[0].length;
double[] a = new double[n];
int[][] index = new int[p][];
for (int j = 0; j < p; j++) {
if (attributes[j].getType() == Attribute.Type.NUMERIC) {... | [
"public",
"static",
"int",
"[",
"]",
"[",
"]",
"sort",
"(",
"Attribute",
"[",
"]",
"attributes",
",",
"double",
"[",
"]",
"[",
"]",
"x",
")",
"{",
"int",
"n",
"=",
"x",
".",
"length",
";",
"int",
"p",
"=",
"x",
"[",
"0",
"]",
".",
"length",
... | Sorts each variable and returns the index of values in ascending order.
Only numeric attributes will be sorted. Note that the order of original
array is NOT altered.
@param x a set of variables to be sorted. Each row is an instance. Each
column is a variable.
@return the index of values in ascending order | [
"Sorts",
"each",
"variable",
"and",
"returns",
"the",
"index",
"of",
"values",
"in",
"ascending",
"order",
".",
"Only",
"numeric",
"attributes",
"will",
"be",
"sorted",
".",
"Note",
"that",
"the",
"order",
"of",
"original",
"array",
"is",
"NOT",
"altered",
... | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/util/SmileUtils.java#L49-L66 |
17,420 | haifengl/smile | core/src/main/java/smile/imputation/SVDImputation.java | SVDImputation.impute | public void impute(double[][] data, int maxIter) throws MissingValueImputationException {
if (maxIter < 1) {
throw new IllegalArgumentException("Invalid maximum number of iterations: " + maxIter);
}
int[] count = new int[data[0].length];
for (int i = 0; i < data.length; i++)... | java | public void impute(double[][] data, int maxIter) throws MissingValueImputationException {
if (maxIter < 1) {
throw new IllegalArgumentException("Invalid maximum number of iterations: " + maxIter);
}
int[] count = new int[data[0].length];
for (int i = 0; i < data.length; i++)... | [
"public",
"void",
"impute",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
",",
"int",
"maxIter",
")",
"throws",
"MissingValueImputationException",
"{",
"if",
"(",
"maxIter",
"<",
"1",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid maximum n... | Impute missing values in the dataset.
@param data a data set with missing values (represented as Double.NaN).
On output, missing values are filled with estimated values.
@param maxIter the maximum number of iterations. | [
"Impute",
"missing",
"values",
"in",
"the",
"dataset",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/imputation/SVDImputation.java#L75-L115 |
17,421 | haifengl/smile | core/src/main/java/smile/imputation/SVDImputation.java | SVDImputation.svdImpute | private void svdImpute(double[][] raw, double[][] data) {
SVD svd = Matrix.newInstance(data).svd();
int d = data[0].length;
for (int i = 0; i < raw.length; i++) {
int missing = 0;
for (int j = 0; j < d; j++) {
if (Double.isNaN(raw[i][j])) {
... | java | private void svdImpute(double[][] raw, double[][] data) {
SVD svd = Matrix.newInstance(data).svd();
int d = data[0].length;
for (int i = 0; i < raw.length; i++) {
int missing = 0;
for (int j = 0; j < d; j++) {
if (Double.isNaN(raw[i][j])) {
... | [
"private",
"void",
"svdImpute",
"(",
"double",
"[",
"]",
"[",
"]",
"raw",
",",
"double",
"[",
"]",
"[",
"]",
"data",
")",
"{",
"SVD",
"svd",
"=",
"Matrix",
".",
"newInstance",
"(",
"data",
")",
".",
"svd",
"(",
")",
";",
"int",
"d",
"=",
"data"... | Impute the missing values by SVD.
@param raw the raw data with missing values.
@param data the data with current imputations. | [
"Impute",
"the",
"missing",
"values",
"by",
"SVD",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/imputation/SVDImputation.java#L122-L166 |
17,422 | haifengl/smile | interpolation/src/main/java/smile/interpolation/BicubicInterpolation.java | BicubicInterpolation.bcuint | private static double bcuint(double[] y, double[] y1, double[] y2, double[] y12,
double x1l, double x1u, double x2l, double x2u, double x1p, double x2p) {
if (x1u == x1l) {
throw new IllegalArgumentException("Nearby control points take same value: " + x1u);
}
if... | java | private static double bcuint(double[] y, double[] y1, double[] y2, double[] y12,
double x1l, double x1u, double x2l, double x2u, double x1p, double x2p) {
if (x1u == x1l) {
throw new IllegalArgumentException("Nearby control points take same value: " + x1u);
}
if... | [
"private",
"static",
"double",
"bcuint",
"(",
"double",
"[",
"]",
"y",
",",
"double",
"[",
"]",
"y1",
",",
"double",
"[",
"]",
"y2",
",",
"double",
"[",
"]",
"y12",
",",
"double",
"x1l",
",",
"double",
"x1u",
",",
"double",
"x2l",
",",
"double",
... | Bicubic interpolation within a grid square. | [
"Bicubic",
"interpolation",
"within",
"a",
"grid",
"square",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/interpolation/src/main/java/smile/interpolation/BicubicInterpolation.java#L132-L156 |
17,423 | haifengl/smile | plot/src/main/java/smile/plot/Wireframe.java | Wireframe.plot | public static PlotCanvas plot(double[][] vertices, int[][] edges) {
double[] lowerBound = Math.colMin(vertices);
double[] upperBound = Math.colMax(vertices);
PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound);
Wireframe frame = new Wireframe(vertices, edges);
canvas.add... | java | public static PlotCanvas plot(double[][] vertices, int[][] edges) {
double[] lowerBound = Math.colMin(vertices);
double[] upperBound = Math.colMax(vertices);
PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound);
Wireframe frame = new Wireframe(vertices, edges);
canvas.add... | [
"public",
"static",
"PlotCanvas",
"plot",
"(",
"double",
"[",
"]",
"[",
"]",
"vertices",
",",
"int",
"[",
"]",
"[",
"]",
"edges",
")",
"{",
"double",
"[",
"]",
"lowerBound",
"=",
"Math",
".",
"colMin",
"(",
"vertices",
")",
";",
"double",
"[",
"]",... | Create a wire frame plot canvas.
@param vertices a n-by-2 or n-by-3 array which are coordinates of n vertices. | [
"Create",
"a",
"wire",
"frame",
"plot",
"canvas",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/plot/src/main/java/smile/plot/Wireframe.java#L78-L88 |
17,424 | haifengl/smile | core/src/main/java/smile/feature/SparseOneHotEncoder.java | SparseOneHotEncoder.feature | public int[] feature(double[] x) {
if (x.length != attributes.length) {
throw new IllegalArgumentException(String.format("Invalid feature vector size %d, expected %d", x.length, attributes.length));
}
int[] features = new int[attributes.length];
for (int i = 0; i < f... | java | public int[] feature(double[] x) {
if (x.length != attributes.length) {
throw new IllegalArgumentException(String.format("Invalid feature vector size %d, expected %d", x.length, attributes.length));
}
int[] features = new int[attributes.length];
for (int i = 0; i < f... | [
"public",
"int",
"[",
"]",
"feature",
"(",
"double",
"[",
"]",
"x",
")",
"{",
"if",
"(",
"x",
".",
"length",
"!=",
"attributes",
".",
"length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"format",
"(",
"\"Invalid feature ve... | Generates the compact representation of sparse binary features for given object.
@param x an object of interest.
@return an integer array of nonzero binary features. | [
"Generates",
"the",
"compact",
"representation",
"of",
"sparse",
"binary",
"features",
"for",
"given",
"object",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/feature/SparseOneHotEncoder.java#L69-L85 |
17,425 | haifengl/smile | symbolic/src/main/java/smile/symbolic/ExpressionParser.java | ExpressionParser.format | public String format(String s)
{
for(int i = 0; i < s.length(); i++) {
if(s.substring(i, i + 1).equals("*") && i > 0)
if(isOperand(s.substring(i - 1, i), var) && i < s.length() - 1 && s.substring(i + 1, i + 2).equals(var))
s = s.substring(0, i) + s.substring(i... | java | public String format(String s)
{
for(int i = 0; i < s.length(); i++) {
if(s.substring(i, i + 1).equals("*") && i > 0)
if(isOperand(s.substring(i - 1, i), var) && i < s.length() - 1 && s.substring(i + 1, i + 2).equals(var))
s = s.substring(0, i) + s.substring(i... | [
"public",
"String",
"format",
"(",
"String",
"s",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"s",
".",
"length",
"(",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"s",
".",
"substring",
"(",
"i",
",",
"i",
"+",
"1",
")",
".",... | Modifies the string to look more like it would if someone wrote the expression
out on paper.
@param s the mathematical expression. | [
"Modifies",
"the",
"string",
"to",
"look",
"more",
"like",
"it",
"would",
"if",
"someone",
"wrote",
"the",
"expression",
"out",
"on",
"paper",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/symbolic/src/main/java/smile/symbolic/ExpressionParser.java#L104-L113 |
17,426 | haifengl/smile | symbolic/src/main/java/smile/symbolic/ExpressionParser.java | ExpressionParser.parse | public String parse(String expression) throws InvalidExpressionException {
this.expression = expression;
try {
var = check();
} catch (InvalidExpressionException e) {
e.printStackTrace();
}
this.expression = formatString(expression);
System.out.... | java | public String parse(String expression) throws InvalidExpressionException {
this.expression = expression;
try {
var = check();
} catch (InvalidExpressionException e) {
e.printStackTrace();
}
this.expression = formatString(expression);
System.out.... | [
"public",
"String",
"parse",
"(",
"String",
"expression",
")",
"throws",
"InvalidExpressionException",
"{",
"this",
".",
"expression",
"=",
"expression",
";",
"try",
"{",
"var",
"=",
"check",
"(",
")",
";",
"}",
"catch",
"(",
"InvalidExpressionException",
"e",... | Creates tokens in polish notation for and re-formats the expression, unless an expression without valid syntax
is passed in.
@param expression a mathematical expression.
@return a modified version of the expression. | [
"Creates",
"tokens",
"in",
"polish",
"notation",
"for",
"and",
"re",
"-",
"formats",
"the",
"expression",
"unless",
"an",
"expression",
"without",
"valid",
"syntax",
"is",
"passed",
"in",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/symbolic/src/main/java/smile/symbolic/ExpressionParser.java#L121-L136 |
17,427 | haifengl/smile | symbolic/src/main/java/smile/symbolic/ExpressionParser.java | ExpressionParser.formatString | private String formatString(String exp)
{
exp = exp.replaceAll("\\s",""); // why
exp = exp.toLowerCase();
int count = 0;
if(exp.substring(0, 1).equals("-")) { // if expression starts with a minus sign, it is a unary one
exp = "$" + exp.substring(1); // replace
}... | java | private String formatString(String exp)
{
exp = exp.replaceAll("\\s",""); // why
exp = exp.toLowerCase();
int count = 0;
if(exp.substring(0, 1).equals("-")) { // if expression starts with a minus sign, it is a unary one
exp = "$" + exp.substring(1); // replace
}... | [
"private",
"String",
"formatString",
"(",
"String",
"exp",
")",
"{",
"exp",
"=",
"exp",
".",
"replaceAll",
"(",
"\"\\\\s\"",
",",
"\"\"",
")",
";",
"// why",
"exp",
"=",
"exp",
".",
"toLowerCase",
"(",
")",
";",
"int",
"count",
"=",
"0",
";",
"if",
... | adds and deletes characters to aid in the creation of the binary expression tree | [
"adds",
"and",
"deletes",
"characters",
"to",
"aid",
"in",
"the",
"creation",
"of",
"the",
"binary",
"expression",
"tree"
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/symbolic/src/main/java/smile/symbolic/ExpressionParser.java#L249-L285 |
17,428 | haifengl/smile | netlib/src/main/java/smile/netlib/NLMatrix.java | NLMatrix.reverse | static void reverse(double[] d, DenseMatrix V) {
int m = V.nrows();
int n = d.length;
int half = n / 2;
for (int i = 0; i < half; i++) {
double tmp = d[i];
d[i] = d[n - i - 1];
d[n - i - 1] = tmp;
}
for (int j = 0; j < half; j++) {
... | java | static void reverse(double[] d, DenseMatrix V) {
int m = V.nrows();
int n = d.length;
int half = n / 2;
for (int i = 0; i < half; i++) {
double tmp = d[i];
d[i] = d[n - i - 1];
d[n - i - 1] = tmp;
}
for (int j = 0; j < half; j++) {
... | [
"static",
"void",
"reverse",
"(",
"double",
"[",
"]",
"d",
",",
"DenseMatrix",
"V",
")",
"{",
"int",
"m",
"=",
"V",
".",
"nrows",
"(",
")",
";",
"int",
"n",
"=",
"d",
".",
"length",
";",
"int",
"half",
"=",
"n",
"/",
"2",
";",
"for",
"(",
"... | Reverse the array to match JMatrix. | [
"Reverse",
"the",
"array",
"to",
"match",
"JMatrix",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/netlib/src/main/java/smile/netlib/NLMatrix.java#L516-L532 |
17,429 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.logistic | public static double logistic(double x) {
double y = 0.0;
if (x < -40) {
y = 2.353853e+17;
} else if (x > 40) {
y = 1.0 + 4.248354e-18;
} else {
y = 1.0 + Math.exp(-x);
}
return 1.0 / y;
} | java | public static double logistic(double x) {
double y = 0.0;
if (x < -40) {
y = 2.353853e+17;
} else if (x > 40) {
y = 1.0 + 4.248354e-18;
} else {
y = 1.0 + Math.exp(-x);
}
return 1.0 / y;
} | [
"public",
"static",
"double",
"logistic",
"(",
"double",
"x",
")",
"{",
"double",
"y",
"=",
"0.0",
";",
"if",
"(",
"x",
"<",
"-",
"40",
")",
"{",
"y",
"=",
"2.353853e+17",
";",
"}",
"else",
"if",
"(",
"x",
">",
"40",
")",
"{",
"y",
"=",
"1.0"... | Logistic sigmoid function. | [
"Logistic",
"sigmoid",
"function",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L632-L643 |
17,430 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.round | public static double round(double x, int decimal) {
if (decimal < 0) {
return round(x / pow(10, -decimal)) * pow(10, -decimal);
} else {
return round(x * pow(10, decimal)) / pow(10, decimal);
}
} | java | public static double round(double x, int decimal) {
if (decimal < 0) {
return round(x / pow(10, -decimal)) * pow(10, -decimal);
} else {
return round(x * pow(10, decimal)) / pow(10, decimal);
}
} | [
"public",
"static",
"double",
"round",
"(",
"double",
"x",
",",
"int",
"decimal",
")",
"{",
"if",
"(",
"decimal",
"<",
"0",
")",
"{",
"return",
"round",
"(",
"x",
"/",
"pow",
"(",
"10",
",",
"-",
"decimal",
")",
")",
"*",
"pow",
"(",
"10",
",",... | Round a double vale to given digits such as 10^n, where n is a positive
or negative integer. | [
"Round",
"a",
"double",
"vale",
"to",
"given",
"digits",
"such",
"as",
"10^n",
"where",
"n",
"is",
"a",
"positive",
"or",
"negative",
"integer",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L663-L669 |
17,431 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.logFactorial | public static double logFactorial(int n) {
if (n < 0) {
throw new IllegalArgumentException(String.format("n has to be nonnegative: %d", n));
}
double f = 0.0;
for (int i = 2; i <= n; i++) {
f += Math.log(i);
}
return f;
} | java | public static double logFactorial(int n) {
if (n < 0) {
throw new IllegalArgumentException(String.format("n has to be nonnegative: %d", n));
}
double f = 0.0;
for (int i = 2; i <= n; i++) {
f += Math.log(i);
}
return f;
} | [
"public",
"static",
"double",
"logFactorial",
"(",
"int",
"n",
")",
"{",
"if",
"(",
"n",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"format",
"(",
"\"n has to be nonnegative: %d\"",
",",
"n",
")",
")",
";",
"}",
"... | log of factorial of n | [
"log",
"of",
"factorial",
"of",
"n"
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L693-L704 |
17,432 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.choose | public static double choose(int n, int k) {
if (n < 0 || k < 0) {
throw new IllegalArgumentException(String.format("Invalid n = %d, k = %d", n, k));
}
if (n < k) {
return 0.0;
}
return Math.floor(0.5 + Math.exp(logChoose(n, k)));
} | java | public static double choose(int n, int k) {
if (n < 0 || k < 0) {
throw new IllegalArgumentException(String.format("Invalid n = %d, k = %d", n, k));
}
if (n < k) {
return 0.0;
}
return Math.floor(0.5 + Math.exp(logChoose(n, k)));
} | [
"public",
"static",
"double",
"choose",
"(",
"int",
"n",
",",
"int",
"k",
")",
"{",
"if",
"(",
"n",
"<",
"0",
"||",
"k",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"format",
"(",
"\"Invalid n = %d, k = %d\"",
",... | n choose k. Returns 0 if n is less than k. | [
"n",
"choose",
"k",
".",
"Returns",
"0",
"if",
"n",
"is",
"less",
"than",
"k",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L709-L719 |
17,433 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.logChoose | public static double logChoose(int n, int k) {
if (n < 0 || k < 0 || k > n) {
throw new IllegalArgumentException(String.format("Invalid n = %d, k = %d", n, k));
}
return Math.logFactorial(n) - Math.logFactorial(k) - Math.logFactorial(n - k);
} | java | public static double logChoose(int n, int k) {
if (n < 0 || k < 0 || k > n) {
throw new IllegalArgumentException(String.format("Invalid n = %d, k = %d", n, k));
}
return Math.logFactorial(n) - Math.logFactorial(k) - Math.logFactorial(n - k);
} | [
"public",
"static",
"double",
"logChoose",
"(",
"int",
"n",
",",
"int",
"k",
")",
"{",
"if",
"(",
"n",
"<",
"0",
"||",
"k",
"<",
"0",
"||",
"k",
">",
"n",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"format",
"(",
"\... | log of n choose k | [
"log",
"of",
"n",
"choose",
"k"
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L724-L730 |
17,434 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.random | public static int[] random(double[] prob, int n) {
// set up alias table
double[] q = new double[prob.length];
for (int i = 0; i < prob.length; i++) {
q[i] = prob[i] * prob.length;
}
// initialize a with indices
int[] a = new int[prob.length];
for (in... | java | public static int[] random(double[] prob, int n) {
// set up alias table
double[] q = new double[prob.length];
for (int i = 0; i < prob.length; i++) {
q[i] = prob[i] * prob.length;
}
// initialize a with indices
int[] a = new int[prob.length];
for (in... | [
"public",
"static",
"int",
"[",
"]",
"random",
"(",
"double",
"[",
"]",
"prob",
",",
"int",
"n",
")",
"{",
"// set up alias table",
"double",
"[",
"]",
"q",
"=",
"new",
"double",
"[",
"prob",
".",
"length",
"]",
";",
"for",
"(",
"int",
"i",
"=",
... | Given a set of m probabilities, draw with replacement a set of n random
number in [0, m).
@param prob probabilities of size n. The prob argument can be used to
give a vector of weights for obtaining the elements of the vector being
sampled. They need not sum to one, but they should be nonnegative and
not all zero.
@ret... | [
"Given",
"a",
"set",
"of",
"m",
"probabilities",
"draw",
"with",
"replacement",
"a",
"set",
"of",
"n",
"random",
"number",
"in",
"[",
"0",
"m",
")",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L761-L814 |
17,435 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.random | public static double[] random(double lo, double hi, int n) {
double[] x = new double[n];
random.get().nextDoubles(x, lo, hi);
return x;
} | java | public static double[] random(double lo, double hi, int n) {
double[] x = new double[n];
random.get().nextDoubles(x, lo, hi);
return x;
} | [
"public",
"static",
"double",
"[",
"]",
"random",
"(",
"double",
"lo",
",",
"double",
"hi",
",",
"int",
"n",
")",
"{",
"double",
"[",
"]",
"x",
"=",
"new",
"double",
"[",
"n",
"]",
";",
"random",
".",
"get",
"(",
")",
".",
"nextDoubles",
"(",
"... | Generate n uniform random numbers in the range [lo, hi).
@param n size of the array
@param lo lower limit of range
@param hi upper limit of range
@return a uniform random real in the range [lo, hi) | [
"Generate",
"n",
"uniform",
"random",
"numbers",
"in",
"the",
"range",
"[",
"lo",
"hi",
")",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L849-L853 |
17,436 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.randomInt | public static int randomInt(int lo, int hi) {
int w = hi - lo;
return lo + random.get().nextInt(w);
} | java | public static int randomInt(int lo, int hi) {
int w = hi - lo;
return lo + random.get().nextInt(w);
} | [
"public",
"static",
"int",
"randomInt",
"(",
"int",
"lo",
",",
"int",
"hi",
")",
"{",
"int",
"w",
"=",
"hi",
"-",
"lo",
";",
"return",
"lo",
"+",
"random",
".",
"get",
"(",
")",
".",
"nextInt",
"(",
"w",
")",
";",
"}"
] | Returns a random integer in [lo, hi). | [
"Returns",
"a",
"random",
"integer",
"in",
"[",
"lo",
"hi",
")",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L865-L868 |
17,437 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.c | public static int[] c(int[]... x) {
int n = 0;
for (int i = 0; i < x.length; i++) {
n += x.length;
}
int[] y = new int[n];
for (int i = 0, k = 0; i < x.length; i++) {
for (int xi : x[i]) {
y[k++] = xi;
}
}
retur... | java | public static int[] c(int[]... x) {
int n = 0;
for (int i = 0; i < x.length; i++) {
n += x.length;
}
int[] y = new int[n];
for (int i = 0, k = 0; i < x.length; i++) {
for (int xi : x[i]) {
y[k++] = xi;
}
}
retur... | [
"public",
"static",
"int",
"[",
"]",
"c",
"(",
"int",
"[",
"]",
"...",
"x",
")",
"{",
"int",
"n",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"x",
".",
"length",
";",
"i",
"++",
")",
"{",
"n",
"+=",
"x",
".",
"length... | Merges multiple vectors into one. | [
"Merges",
"multiple",
"vectors",
"into",
"one",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L927-L940 |
17,438 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.contains | public static boolean contains(double[][] polygon, double x, double y) {
if (polygon.length <= 2) {
return false;
}
int hits = 0;
int n = polygon.length;
double lastx = polygon[n - 1][0];
double lasty = polygon[n - 1][1];
double curx, cury;
... | java | public static boolean contains(double[][] polygon, double x, double y) {
if (polygon.length <= 2) {
return false;
}
int hits = 0;
int n = polygon.length;
double lastx = polygon[n - 1][0];
double lasty = polygon[n - 1][1];
double curx, cury;
... | [
"public",
"static",
"boolean",
"contains",
"(",
"double",
"[",
"]",
"[",
"]",
"polygon",
",",
"double",
"x",
",",
"double",
"y",
")",
"{",
"if",
"(",
"polygon",
".",
"length",
"<=",
"2",
")",
"{",
"return",
"false",
";",
"}",
"int",
"hits",
"=",
... | Determines if the polygon contains the specified coordinates.
@param x the specified x coordinate.
@param y the specified y coordinate.
@return true if the Polygon contains the specified coordinates; false otherwise. | [
"Determines",
"if",
"the",
"polygon",
"contains",
"the",
"specified",
"coordinates",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1102-L1165 |
17,439 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.reverse | public static void reverse(int[] a) {
int i = 0, j = a.length - 1;
while (i < j) {
SortUtils.swap(a, i++, j--); // code for swap not shown, but easy enough
}
} | java | public static void reverse(int[] a) {
int i = 0, j = a.length - 1;
while (i < j) {
SortUtils.swap(a, i++, j--); // code for swap not shown, but easy enough
}
} | [
"public",
"static",
"void",
"reverse",
"(",
"int",
"[",
"]",
"a",
")",
"{",
"int",
"i",
"=",
"0",
",",
"j",
"=",
"a",
".",
"length",
"-",
"1",
";",
"while",
"(",
"i",
"<",
"j",
")",
"{",
"SortUtils",
".",
"swap",
"(",
"a",
",",
"i",
"++",
... | Reverses the order of the elements in the specified array.
@param a an array to reverse. | [
"Reverses",
"the",
"order",
"of",
"the",
"elements",
"in",
"the",
"specified",
"array",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1171-L1176 |
17,440 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.rowMin | public static double[] rowMin(double[][] data) {
double[] x = new double[data.length];
for (int i = 0; i < x.length; i++) {
x[i] = min(data[i]);
}
return x;
} | java | public static double[] rowMin(double[][] data) {
double[] x = new double[data.length];
for (int i = 0; i < x.length; i++) {
x[i] = min(data[i]);
}
return x;
} | [
"public",
"static",
"double",
"[",
"]",
"rowMin",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
")",
"{",
"double",
"[",
"]",
"x",
"=",
"new",
"double",
"[",
"data",
".",
"length",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"x",
... | Returns the row minimum for a matrix. | [
"Returns",
"the",
"row",
"minimum",
"for",
"a",
"matrix",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1533-L1541 |
17,441 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.rowMax | public static double[] rowMax(double[][] data) {
double[] x = new double[data.length];
for (int i = 0; i < x.length; i++) {
x[i] = max(data[i]);
}
return x;
} | java | public static double[] rowMax(double[][] data) {
double[] x = new double[data.length];
for (int i = 0; i < x.length; i++) {
x[i] = max(data[i]);
}
return x;
} | [
"public",
"static",
"double",
"[",
"]",
"rowMax",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
")",
"{",
"double",
"[",
"]",
"x",
"=",
"new",
"double",
"[",
"data",
".",
"length",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"x",
... | Returns the row maximum for a matrix. | [
"Returns",
"the",
"row",
"maximum",
"for",
"a",
"matrix",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1546-L1554 |
17,442 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.rowSums | public static double[] rowSums(double[][] data) {
double[] x = new double[data.length];
for (int i = 0; i < x.length; i++) {
x[i] = sum(data[i]);
}
return x;
} | java | public static double[] rowSums(double[][] data) {
double[] x = new double[data.length];
for (int i = 0; i < x.length; i++) {
x[i] = sum(data[i]);
}
return x;
} | [
"public",
"static",
"double",
"[",
"]",
"rowSums",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
")",
"{",
"double",
"[",
"]",
"x",
"=",
"new",
"double",
"[",
"data",
".",
"length",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"x",... | Returns the row sums for a matrix. | [
"Returns",
"the",
"row",
"sums",
"for",
"a",
"matrix",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1559-L1567 |
17,443 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.rowMeans | public static double[] rowMeans(double[][] data) {
double[] x = new double[data.length];
for (int i = 0; i < x.length; i++) {
x[i] = mean(data[i]);
}
return x;
} | java | public static double[] rowMeans(double[][] data) {
double[] x = new double[data.length];
for (int i = 0; i < x.length; i++) {
x[i] = mean(data[i]);
}
return x;
} | [
"public",
"static",
"double",
"[",
"]",
"rowMeans",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
")",
"{",
"double",
"[",
"]",
"x",
"=",
"new",
"double",
"[",
"data",
".",
"length",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"x"... | Returns the row means for a matrix. | [
"Returns",
"the",
"row",
"means",
"for",
"a",
"matrix",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1572-L1580 |
17,444 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.rowSds | public static double[] rowSds(double[][] data) {
double[] x = new double[data.length];
for (int i = 0; i < x.length; i++) {
x[i] = sd(data[i]);
}
return x;
} | java | public static double[] rowSds(double[][] data) {
double[] x = new double[data.length];
for (int i = 0; i < x.length; i++) {
x[i] = sd(data[i]);
}
return x;
} | [
"public",
"static",
"double",
"[",
"]",
"rowSds",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
")",
"{",
"double",
"[",
"]",
"x",
"=",
"new",
"double",
"[",
"data",
".",
"length",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"x",
... | Returns the row standard deviations for a matrix. | [
"Returns",
"the",
"row",
"standard",
"deviations",
"for",
"a",
"matrix",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1585-L1593 |
17,445 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.colMin | public static double[] colMin(double[][] data) {
double[] x = new double[data[0].length];
for (int i = 0; i < x.length; i++) {
x[i] = Double.POSITIVE_INFINITY;
}
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < x.length; j++) {
if (x[j]... | java | public static double[] colMin(double[][] data) {
double[] x = new double[data[0].length];
for (int i = 0; i < x.length; i++) {
x[i] = Double.POSITIVE_INFINITY;
}
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < x.length; j++) {
if (x[j]... | [
"public",
"static",
"double",
"[",
"]",
"colMin",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
")",
"{",
"double",
"[",
"]",
"x",
"=",
"new",
"double",
"[",
"data",
"[",
"0",
"]",
".",
"length",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
... | Returns the column minimum for a matrix. | [
"Returns",
"the",
"column",
"minimum",
"for",
"a",
"matrix",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1598-L1613 |
17,446 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.colMax | public static double[] colMax(double[][] data) {
double[] x = new double[data[0].length];
for (int i = 0; i < x.length; i++) {
x[i] = Double.NEGATIVE_INFINITY;
}
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < x.length; j++) {
if (x[j]... | java | public static double[] colMax(double[][] data) {
double[] x = new double[data[0].length];
for (int i = 0; i < x.length; i++) {
x[i] = Double.NEGATIVE_INFINITY;
}
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < x.length; j++) {
if (x[j]... | [
"public",
"static",
"double",
"[",
"]",
"colMax",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
")",
"{",
"double",
"[",
"]",
"x",
"=",
"new",
"double",
"[",
"data",
"[",
"0",
"]",
".",
"length",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
... | Returns the column maximum for a matrix. | [
"Returns",
"the",
"column",
"maximum",
"for",
"a",
"matrix",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1618-L1633 |
17,447 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.colSums | public static double[] colSums(double[][] data) {
double[] x = data[0].clone();
for (int i = 1; i < data.length; i++) {
for (int j = 0; j < x.length; j++) {
x[j] += data[i][j];
}
}
return x;
} | java | public static double[] colSums(double[][] data) {
double[] x = data[0].clone();
for (int i = 1; i < data.length; i++) {
for (int j = 0; j < x.length; j++) {
x[j] += data[i][j];
}
}
return x;
} | [
"public",
"static",
"double",
"[",
"]",
"colSums",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
")",
"{",
"double",
"[",
"]",
"x",
"=",
"data",
"[",
"0",
"]",
".",
"clone",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"data... | Returns the column sums for a matrix. | [
"Returns",
"the",
"column",
"sums",
"for",
"a",
"matrix",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1638-L1648 |
17,448 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.colMeans | public static double[] colMeans(double[][] data) {
double[] x = data[0].clone();
for (int i = 1; i < data.length; i++) {
for (int j = 0; j < x.length; j++) {
x[j] += data[i][j];
}
}
scale(1.0 / data.length, x);
return x;
} | java | public static double[] colMeans(double[][] data) {
double[] x = data[0].clone();
for (int i = 1; i < data.length; i++) {
for (int j = 0; j < x.length; j++) {
x[j] += data[i][j];
}
}
scale(1.0 / data.length, x);
return x;
} | [
"public",
"static",
"double",
"[",
"]",
"colMeans",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
")",
"{",
"double",
"[",
"]",
"x",
"=",
"data",
"[",
"0",
"]",
".",
"clone",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"dat... | Returns the column means for a matrix. | [
"Returns",
"the",
"column",
"means",
"for",
"a",
"matrix",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1653-L1665 |
17,449 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.colSds | public static double[] colSds(double[][] data) {
if (data.length < 2) {
throw new IllegalArgumentException("Array length is less than 2.");
}
int p = data[0].length;
double[] sum = new double[p];
double[] sumsq = new double[p];
for (double[] x : data) {
... | java | public static double[] colSds(double[][] data) {
if (data.length < 2) {
throw new IllegalArgumentException("Array length is less than 2.");
}
int p = data[0].length;
double[] sum = new double[p];
double[] sumsq = new double[p];
for (double[] x : data) {
... | [
"public",
"static",
"double",
"[",
"]",
"colSds",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
")",
"{",
"if",
"(",
"data",
".",
"length",
"<",
"2",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Array length is less than 2.\"",
")",
";",
"}... | Returns the column deviations for a matrix. | [
"Returns",
"the",
"column",
"deviations",
"for",
"a",
"matrix",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1670-L1691 |
17,450 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.sum | public static int sum(int[] x) {
double sum = 0.0;
for (int n : x) {
sum += n;
}
if (sum > Integer.MAX_VALUE || sum < -Integer.MAX_VALUE) {
throw new ArithmeticException("Sum overflow: " + sum);
}
return (int) sum;
} | java | public static int sum(int[] x) {
double sum = 0.0;
for (int n : x) {
sum += n;
}
if (sum > Integer.MAX_VALUE || sum < -Integer.MAX_VALUE) {
throw new ArithmeticException("Sum overflow: " + sum);
}
return (int) sum;
} | [
"public",
"static",
"int",
"sum",
"(",
"int",
"[",
"]",
"x",
")",
"{",
"double",
"sum",
"=",
"0.0",
";",
"for",
"(",
"int",
"n",
":",
"x",
")",
"{",
"sum",
"+=",
"n",
";",
"}",
"if",
"(",
"sum",
">",
"Integer",
".",
"MAX_VALUE",
"||",
"sum",
... | Returns the sum of an array. | [
"Returns",
"the",
"sum",
"of",
"an",
"array",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1696-L1708 |
17,451 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.median | public static <T extends Comparable<? super T>> T median(T[] a) {
return QuickSelect.median(a);
} | java | public static <T extends Comparable<? super T>> T median(T[] a) {
return QuickSelect.median(a);
} | [
"public",
"static",
"<",
"T",
"extends",
"Comparable",
"<",
"?",
"super",
"T",
">",
">",
"T",
"median",
"(",
"T",
"[",
"]",
"a",
")",
"{",
"return",
"QuickSelect",
".",
"median",
"(",
"a",
")",
";",
"}"
] | Find the median of an array of type double. The input array will
be rearranged. | [
"Find",
"the",
"median",
"of",
"an",
"array",
"of",
"type",
"double",
".",
"The",
"input",
"array",
"will",
"be",
"rearranged",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1764-L1766 |
17,452 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.var | public static double var(int[] x) {
if (x.length < 2) {
throw new IllegalArgumentException("Array length is less than 2.");
}
double sum = 0.0;
double sumsq = 0.0;
for (int xi : x) {
sum += xi;
sumsq += xi * xi;
}
int n = x.le... | java | public static double var(int[] x) {
if (x.length < 2) {
throw new IllegalArgumentException("Array length is less than 2.");
}
double sum = 0.0;
double sumsq = 0.0;
for (int xi : x) {
sum += xi;
sumsq += xi * xi;
}
int n = x.le... | [
"public",
"static",
"double",
"var",
"(",
"int",
"[",
"]",
"x",
")",
"{",
"if",
"(",
"x",
".",
"length",
"<",
"2",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Array length is less than 2.\"",
")",
";",
"}",
"double",
"sum",
"=",
"0.0",
... | Returns the variance of an array. | [
"Returns",
"the",
"variance",
"of",
"an",
"array",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L1856-L1870 |
17,453 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.squaredDistance | public static double squaredDistance(int[] x, int[] y) {
if (x.length != y.length) {
throw new IllegalArgumentException("Input vector sizes are different.");
}
double sum = 0.0;
for (int i = 0; i < x.length; i++) {
sum += sqr(x[i] - y[i]);
}
retu... | java | public static double squaredDistance(int[] x, int[] y) {
if (x.length != y.length) {
throw new IllegalArgumentException("Input vector sizes are different.");
}
double sum = 0.0;
for (int i = 0; i < x.length; i++) {
sum += sqr(x[i] - y[i]);
}
retu... | [
"public",
"static",
"double",
"squaredDistance",
"(",
"int",
"[",
"]",
"x",
",",
"int",
"[",
"]",
"y",
")",
"{",
"if",
"(",
"x",
".",
"length",
"!=",
"y",
".",
"length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Input vector sizes are... | The squared Euclidean distance. | [
"The",
"squared",
"Euclidean",
"distance",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L2160-L2171 |
17,454 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.dot | public static double dot(int[] x, int[] y) {
if (x.length != y.length) {
throw new IllegalArgumentException("Arrays have different length.");
}
double p = 0.0;
for (int i = 0; i < x.length; i++) {
p += x[i] * y[i];
}
return p;
} | java | public static double dot(int[] x, int[] y) {
if (x.length != y.length) {
throw new IllegalArgumentException("Arrays have different length.");
}
double p = 0.0;
for (int i = 0; i < x.length; i++) {
p += x[i] * y[i];
}
return p;
} | [
"public",
"static",
"double",
"dot",
"(",
"int",
"[",
"]",
"x",
",",
"int",
"[",
"]",
"y",
")",
"{",
"if",
"(",
"x",
".",
"length",
"!=",
"y",
".",
"length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Arrays have different length.\"",
... | Returns the dot product between two vectors. | [
"Returns",
"the",
"dot",
"product",
"between",
"two",
"vectors",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L2497-L2508 |
17,455 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.dot | public static double dot(SparseArray x, SparseArray y) {
Iterator<SparseArray.Entry> it1 = x.iterator();
Iterator<SparseArray.Entry> it2 = y.iterator();
SparseArray.Entry e1 = it1.hasNext() ? it1.next() : null;
SparseArray.Entry e2 = it2.hasNext() ? it2.next() : null;
double s =... | java | public static double dot(SparseArray x, SparseArray y) {
Iterator<SparseArray.Entry> it1 = x.iterator();
Iterator<SparseArray.Entry> it2 = y.iterator();
SparseArray.Entry e1 = it1.hasNext() ? it1.next() : null;
SparseArray.Entry e2 = it2.hasNext() ? it2.next() : null;
double s =... | [
"public",
"static",
"double",
"dot",
"(",
"SparseArray",
"x",
",",
"SparseArray",
"y",
")",
"{",
"Iterator",
"<",
"SparseArray",
".",
"Entry",
">",
"it1",
"=",
"x",
".",
"iterator",
"(",
")",
";",
"Iterator",
"<",
"SparseArray",
".",
"Entry",
">",
"it2... | Returns the dot product between two sparse arrays. | [
"Returns",
"the",
"dot",
"product",
"between",
"two",
"sparse",
"arrays",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L2545-L2565 |
17,456 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.cov | public static double cov(int[] x, int[] y) {
if (x.length != y.length) {
throw new IllegalArgumentException("Arrays have different length.");
}
if (x.length < 3) {
throw new IllegalArgumentException("array length has to be at least 3.");
}
double mx = me... | java | public static double cov(int[] x, int[] y) {
if (x.length != y.length) {
throw new IllegalArgumentException("Arrays have different length.");
}
if (x.length < 3) {
throw new IllegalArgumentException("array length has to be at least 3.");
}
double mx = me... | [
"public",
"static",
"double",
"cov",
"(",
"int",
"[",
"]",
"x",
",",
"int",
"[",
"]",
"y",
")",
"{",
"if",
"(",
"x",
".",
"length",
"!=",
"y",
".",
"length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Arrays have different length.\"",
... | Returns the covariance between two vectors. | [
"Returns",
"the",
"covariance",
"between",
"two",
"vectors",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L2570-L2590 |
17,457 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.cov | public static double[][] cov(double[][] data, double[] mu) {
double[][] sigma = new double[data[0].length][data[0].length];
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < mu.length; j++) {
for (int k = 0; k <= j; k++) {
sigma[j][k] += (data[i]... | java | public static double[][] cov(double[][] data, double[] mu) {
double[][] sigma = new double[data[0].length][data[0].length];
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < mu.length; j++) {
for (int k = 0; k <= j; k++) {
sigma[j][k] += (data[i]... | [
"public",
"static",
"double",
"[",
"]",
"[",
"]",
"cov",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
",",
"double",
"[",
"]",
"mu",
")",
"{",
"double",
"[",
"]",
"[",
"]",
"sigma",
"=",
"new",
"double",
"[",
"data",
"[",
"0",
"]",
".",
"length... | Returns the sample covariance matrix.
@param mu the known mean of data. | [
"Returns",
"the",
"sample",
"covariance",
"matrix",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L2653-L2672 |
17,458 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.cor | public static double cor(int[] x, int[] y) {
if (x.length != y.length) {
throw new IllegalArgumentException("Arrays have different length.");
}
if (x.length < 3) {
throw new IllegalArgumentException("array length has to be at least 3.");
}
double Sxy = c... | java | public static double cor(int[] x, int[] y) {
if (x.length != y.length) {
throw new IllegalArgumentException("Arrays have different length.");
}
if (x.length < 3) {
throw new IllegalArgumentException("array length has to be at least 3.");
}
double Sxy = c... | [
"public",
"static",
"double",
"cor",
"(",
"int",
"[",
"]",
"x",
",",
"int",
"[",
"]",
"y",
")",
"{",
"if",
"(",
"x",
".",
"length",
"!=",
"y",
".",
"length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Arrays have different length.\"",
... | Returns the correlation coefficient between two vectors. | [
"Returns",
"the",
"correlation",
"coefficient",
"between",
"two",
"vectors",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L2677-L2695 |
17,459 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.cor | public static double[][] cor(double[][] data, double[] mu) {
double[][] sigma = cov(data, mu);
int n = data[0].length;
double[] sd = new double[n];
for (int i = 0; i < n; i++) {
sd[i] = sqrt(sigma[i][i]);
}
for (int i = 0; i < n; i++) {
for (int ... | java | public static double[][] cor(double[][] data, double[] mu) {
double[][] sigma = cov(data, mu);
int n = data[0].length;
double[] sd = new double[n];
for (int i = 0; i < n; i++) {
sd[i] = sqrt(sigma[i][i]);
}
for (int i = 0; i < n; i++) {
for (int ... | [
"public",
"static",
"double",
"[",
"]",
"[",
"]",
"cor",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
",",
"double",
"[",
"]",
"mu",
")",
"{",
"double",
"[",
"]",
"[",
"]",
"sigma",
"=",
"cov",
"(",
"data",
",",
"mu",
")",
";",
"int",
"n",
"=... | Returns the sample correlation matrix.
@param mu the known mean of data. | [
"Returns",
"the",
"sample",
"correlation",
"matrix",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L2754-L2771 |
17,460 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.kendall | public static double kendall(int[] x, int[] y) {
if (x.length != y.length) {
throw new IllegalArgumentException("Input vector sizes are different.");
}
int is = 0, n2 = 0, n1 = 0, n = x.length;
double aa, a2, a1;
for (int j = 0; j < n - 1; j++) {
for (int... | java | public static double kendall(int[] x, int[] y) {
if (x.length != y.length) {
throw new IllegalArgumentException("Input vector sizes are different.");
}
int is = 0, n2 = 0, n1 = 0, n = x.length;
double aa, a2, a1;
for (int j = 0; j < n - 1; j++) {
for (int... | [
"public",
"static",
"double",
"kendall",
"(",
"int",
"[",
"]",
"x",
",",
"int",
"[",
"]",
"y",
")",
"{",
"if",
"(",
"x",
".",
"length",
"!=",
"y",
".",
"length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Input vector sizes are differe... | The Kendall Tau Rank Correlation Coefficient is used to measure the
degree of correspondence between sets of rankings where the measures
are not equidistant. It is used with non-parametric data. | [
"The",
"Kendall",
"Tau",
"Rank",
"Correlation",
"Coefficient",
"is",
"used",
"to",
"measure",
"the",
"degree",
"of",
"correspondence",
"between",
"sets",
"of",
"rankings",
"where",
"the",
"measures",
"are",
"not",
"equidistant",
".",
"It",
"is",
"used",
"with"... | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L2923-L2957 |
17,461 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.norm1 | public static double norm1(double[] x) {
double norm = 0.0;
for (double n : x) {
norm += Math.abs(n);
}
return norm;
} | java | public static double norm1(double[] x) {
double norm = 0.0;
for (double n : x) {
norm += Math.abs(n);
}
return norm;
} | [
"public",
"static",
"double",
"norm1",
"(",
"double",
"[",
"]",
"x",
")",
"{",
"double",
"norm",
"=",
"0.0",
";",
"for",
"(",
"double",
"n",
":",
"x",
")",
"{",
"norm",
"+=",
"Math",
".",
"abs",
"(",
"n",
")",
";",
"}",
"return",
"norm",
";",
... | L1 vector norm. | [
"L1",
"vector",
"norm",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L3044-L3052 |
17,462 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.norm2 | public static double norm2(double[] x) {
double norm = 0.0;
for (double n : x) {
norm += n * n;
}
norm = Math.sqrt(norm);
return norm;
} | java | public static double norm2(double[] x) {
double norm = 0.0;
for (double n : x) {
norm += n * n;
}
norm = Math.sqrt(norm);
return norm;
} | [
"public",
"static",
"double",
"norm2",
"(",
"double",
"[",
"]",
"x",
")",
"{",
"double",
"norm",
"=",
"0.0",
";",
"for",
"(",
"double",
"n",
":",
"x",
")",
"{",
"norm",
"+=",
"n",
"*",
"n",
";",
"}",
"norm",
"=",
"Math",
".",
"sqrt",
"(",
"no... | L2 vector norm. | [
"L2",
"vector",
"norm",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L3057-L3067 |
17,463 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.normInf | public static double normInf(double[] x) {
int n = x.length;
double f = Math.abs(x[0]);
for (int i = 1; i < n; i++) {
f = Math.max(f, Math.abs(x[i]));
}
return f;
} | java | public static double normInf(double[] x) {
int n = x.length;
double f = Math.abs(x[0]);
for (int i = 1; i < n; i++) {
f = Math.max(f, Math.abs(x[i]));
}
return f;
} | [
"public",
"static",
"double",
"normInf",
"(",
"double",
"[",
"]",
"x",
")",
"{",
"int",
"n",
"=",
"x",
".",
"length",
";",
"double",
"f",
"=",
"Math",
".",
"abs",
"(",
"x",
"[",
"0",
"]",
")",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i"... | L-infinity vector norm. Maximum absolute value. | [
"L",
"-",
"infinity",
"vector",
"norm",
".",
"Maximum",
"absolute",
"value",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L3072-L3081 |
17,464 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.standardize | public static void standardize(double[] x) {
double mu = mean(x);
double sigma = sd(x);
if (isZero(sigma)) {
logger.warn("array has variance of 0.");
return;
}
for (int i = 0; i < x.length; i++) {
x[i] = (x[i] - mu) / sigma;
}
} | java | public static void standardize(double[] x) {
double mu = mean(x);
double sigma = sd(x);
if (isZero(sigma)) {
logger.warn("array has variance of 0.");
return;
}
for (int i = 0; i < x.length; i++) {
x[i] = (x[i] - mu) / sigma;
}
} | [
"public",
"static",
"void",
"standardize",
"(",
"double",
"[",
"]",
"x",
")",
"{",
"double",
"mu",
"=",
"mean",
"(",
"x",
")",
";",
"double",
"sigma",
"=",
"sd",
"(",
"x",
")",
";",
"if",
"(",
"isZero",
"(",
"sigma",
")",
")",
"{",
"logger",
".... | Standardizes an array to mean 0 and variance 1. | [
"Standardizes",
"an",
"array",
"to",
"mean",
"0",
"and",
"variance",
"1",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L3093-L3105 |
17,465 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.standardize | public static void standardize(double[][] x) {
int n = x.length;
int p = x[0].length;
double[] center = colMeans(x);
for (int i = 0; i < n; i++) {
for (int j = 0; j < p; j++) {
x[i][j] = x[i][j] - center[j];
}
}
double[] scale = n... | java | public static void standardize(double[][] x) {
int n = x.length;
int p = x[0].length;
double[] center = colMeans(x);
for (int i = 0; i < n; i++) {
for (int j = 0; j < p; j++) {
x[i][j] = x[i][j] - center[j];
}
}
double[] scale = n... | [
"public",
"static",
"void",
"standardize",
"(",
"double",
"[",
"]",
"[",
"]",
"x",
")",
"{",
"int",
"n",
"=",
"x",
".",
"length",
";",
"int",
"p",
"=",
"x",
"[",
"0",
"]",
".",
"length",
";",
"double",
"[",
"]",
"center",
"=",
"colMeans",
"(",
... | Standardizes each column of a matrix to 0 mean and unit variance. | [
"Standardizes",
"each",
"column",
"of",
"a",
"matrix",
"to",
"0",
"mean",
"and",
"unit",
"variance",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L3143-L3167 |
17,466 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.unitize1 | public static void unitize1(double[] x) {
double n = norm1(x);
for (int i = 0; i < x.length; i++) {
x[i] /= n;
}
} | java | public static void unitize1(double[] x) {
double n = norm1(x);
for (int i = 0; i < x.length; i++) {
x[i] /= n;
}
} | [
"public",
"static",
"void",
"unitize1",
"(",
"double",
"[",
"]",
"x",
")",
"{",
"double",
"n",
"=",
"norm1",
"(",
"x",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"x",
".",
"length",
";",
"i",
"++",
")",
"{",
"x",
"[",
"i",
... | Unitize an array so that L1 norm of x is 1.
@param x an array of nonnegative double | [
"Unitize",
"an",
"array",
"so",
"that",
"L1",
"norm",
"of",
"x",
"is",
"1",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L3224-L3230 |
17,467 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.unitize2 | public static void unitize2(double[] x) {
double n = norm(x);
for (int i = 0; i < x.length; i++) {
x[i] /= n;
}
} | java | public static void unitize2(double[] x) {
double n = norm(x);
for (int i = 0; i < x.length; i++) {
x[i] /= n;
}
} | [
"public",
"static",
"void",
"unitize2",
"(",
"double",
"[",
"]",
"x",
")",
"{",
"double",
"n",
"=",
"norm",
"(",
"x",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"x",
".",
"length",
";",
"i",
"++",
")",
"{",
"x",
"[",
"i",
... | Unitize an array so that L2 norm of x = 1.
@param x the array of double | [
"Unitize",
"an",
"array",
"so",
"that",
"L2",
"norm",
"of",
"x",
"=",
"1",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L3237-L3243 |
17,468 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.row | private static int row(int[] r, int f) {
int i = 0;
while (i < r.length && r[i] < f) {
++i;
}
return ((i < r.length && r[i] == f) ? i : -1);
} | java | private static int row(int[] r, int f) {
int i = 0;
while (i < r.length && r[i] < f) {
++i;
}
return ((i < r.length && r[i] == f) ? i : -1);
} | [
"private",
"static",
"int",
"row",
"(",
"int",
"[",
"]",
"r",
",",
"int",
"f",
")",
"{",
"int",
"i",
"=",
"0",
";",
"while",
"(",
"i",
"<",
"r",
".",
"length",
"&&",
"r",
"[",
"i",
"]",
"<",
"f",
")",
"{",
"++",
"i",
";",
"}",
"return",
... | Returns the index of given frequency.
@param r the frequency list.
@param f the given frequency.
@return the index of given frequency or -1 if it doesn't exist in the list. | [
"Returns",
"the",
"index",
"of",
"given",
"frequency",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L3258-L3266 |
17,469 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.swap | public static void swap(int[] x, int i, int j) {
int s = x[i];
x[i] = x[j];
x[j] = s;
} | java | public static void swap(int[] x, int i, int j) {
int s = x[i];
x[i] = x[j];
x[j] = s;
} | [
"public",
"static",
"void",
"swap",
"(",
"int",
"[",
"]",
"x",
",",
"int",
"i",
",",
"int",
"j",
")",
"{",
"int",
"s",
"=",
"x",
"[",
"i",
"]",
";",
"x",
"[",
"i",
"]",
"=",
"x",
"[",
"j",
"]",
";",
"x",
"[",
"j",
"]",
"=",
"s",
";",
... | Swap two elements of an array. | [
"Swap",
"two",
"elements",
"of",
"an",
"array",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L3592-L3596 |
17,470 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.swap | public static <E> void swap(E[] x, E[] y) {
if (x.length != y.length) {
throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));
}
for (int i = 0; i < x.length; i++) {
E s = x[i];
x[i] = y[i];
... | java | public static <E> void swap(E[] x, E[] y) {
if (x.length != y.length) {
throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));
}
for (int i = 0; i < x.length; i++) {
E s = x[i];
x[i] = y[i];
... | [
"public",
"static",
"<",
"E",
">",
"void",
"swap",
"(",
"E",
"[",
"]",
"x",
",",
"E",
"[",
"]",
"y",
")",
"{",
"if",
"(",
"x",
".",
"length",
"!=",
"y",
".",
"length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"f... | Swap two arrays. | [
"Swap",
"two",
"arrays",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L3673-L3683 |
17,471 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.plus | public static void plus(double[] y, double[] x) {
if (x.length != y.length) {
throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));
}
for (int i = 0; i < x.length; i++) {
y[i] += x[i];
}
} | java | public static void plus(double[] y, double[] x) {
if (x.length != y.length) {
throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));
}
for (int i = 0; i < x.length; i++) {
y[i] += x[i];
}
} | [
"public",
"static",
"void",
"plus",
"(",
"double",
"[",
"]",
"y",
",",
"double",
"[",
"]",
"x",
")",
"{",
"if",
"(",
"x",
".",
"length",
"!=",
"y",
".",
"length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"format",
"... | Element-wise sum of two arrays y = x + y. | [
"Element",
"-",
"wise",
"sum",
"of",
"two",
"arrays",
"y",
"=",
"x",
"+",
"y",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L3760-L3768 |
17,472 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.minus | public static void minus(double[] y, double[] x) {
if (x.length != y.length) {
throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));
}
for (int i = 0; i < x.length; i++) {
y[i] -= x[i];
}
} | java | public static void minus(double[] y, double[] x) {
if (x.length != y.length) {
throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));
}
for (int i = 0; i < x.length; i++) {
y[i] -= x[i];
}
} | [
"public",
"static",
"void",
"minus",
"(",
"double",
"[",
"]",
"y",
",",
"double",
"[",
"]",
"x",
")",
"{",
"if",
"(",
"x",
".",
"length",
"!=",
"y",
".",
"length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"format",
... | Element-wise subtraction of two arrays y = y - x.
@param y minuend matrix
@param x subtrahend matrix | [
"Element",
"-",
"wise",
"subtraction",
"of",
"two",
"arrays",
"y",
"=",
"y",
"-",
"x",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L3775-L3783 |
17,473 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.pow | public static double[] pow(double[] x, double n) {
double[] array = new double[x.length];
for (int i = 0; i < x.length; i++) {
array[i] = Math.pow(x[i], n);
}
return array;
} | java | public static double[] pow(double[] x, double n) {
double[] array = new double[x.length];
for (int i = 0; i < x.length; i++) {
array[i] = Math.pow(x[i], n);
}
return array;
} | [
"public",
"static",
"double",
"[",
"]",
"pow",
"(",
"double",
"[",
"]",
"x",
",",
"double",
"n",
")",
"{",
"double",
"[",
"]",
"array",
"=",
"new",
"double",
"[",
"x",
".",
"length",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
... | Raise each element of an array to a scalar power.
@param x array
@param n scalar exponent
@return x<sup>n</sup> | [
"Raise",
"each",
"element",
"of",
"an",
"array",
"to",
"a",
"scalar",
"power",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L3824-L3830 |
17,474 | haifengl/smile | math/src/main/java/smile/math/Math.java | Math.sort | public static int[][] sort(double[][] x) {
int n = x.length;
int p = x[0].length;
double[] a = new double[n];
int[][] index = new int[p][];
for (int j = 0; j < p; j++) {
for (int i = 0; i < n; i++) {
a[i] = x[i][j];
}
... | java | public static int[][] sort(double[][] x) {
int n = x.length;
int p = x[0].length;
double[] a = new double[n];
int[][] index = new int[p][];
for (int j = 0; j < p; j++) {
for (int i = 0; i < n; i++) {
a[i] = x[i][j];
}
... | [
"public",
"static",
"int",
"[",
"]",
"[",
"]",
"sort",
"(",
"double",
"[",
"]",
"[",
"]",
"x",
")",
"{",
"int",
"n",
"=",
"x",
".",
"length",
";",
"int",
"p",
"=",
"x",
"[",
"0",
"]",
".",
"length",
";",
"double",
"[",
"]",
"a",
"=",
"new... | Sorts each variable and returns the index of values in ascending order.
Note that the order of original array is NOT altered.
@param x a set of variables to be sorted. Each row is an instance. Each
column is a variable.
@return the index of values in ascending order | [
"Sorts",
"each",
"variable",
"and",
"returns",
"the",
"index",
"of",
"values",
"in",
"ascending",
"order",
".",
"Note",
"that",
"the",
"order",
"of",
"original",
"array",
"is",
"NOT",
"altered",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/Math.java#L3880-L3895 |
17,475 | haifengl/smile | symbolic/src/main/java/smile/symbolic/ExpressionTree.java | ExpressionTree.createInfix | public String createInfix(Expression root)
{
String str = "";
String closeParen = "";
String leftOpenParen = "";
String leftCloseParen = "";
if(root == null) {
return str;
}
if (ExpressionParser.isOperand(root.getType(), var)) {
str +... | java | public String createInfix(Expression root)
{
String str = "";
String closeParen = "";
String leftOpenParen = "";
String leftCloseParen = "";
if(root == null) {
return str;
}
if (ExpressionParser.isOperand(root.getType(), var)) {
str +... | [
"public",
"String",
"createInfix",
"(",
"Expression",
"root",
")",
"{",
"String",
"str",
"=",
"\"\"",
";",
"String",
"closeParen",
"=",
"\"\"",
";",
"String",
"leftOpenParen",
"=",
"\"\"",
";",
"String",
"leftCloseParen",
"=",
"\"\"",
";",
"if",
"(",
"root... | creates string representing infix expression | [
"creates",
"string",
"representing",
"infix",
"expression"
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/symbolic/src/main/java/smile/symbolic/ExpressionTree.java#L121-L160 |
17,476 | haifengl/smile | symbolic/src/main/java/smile/symbolic/ExpressionTree.java | ExpressionTree.constructTree | public Expression constructTree(ArrayList<String> postTokens)
{
Expression root = null;
Stack<Expression> nodes = new Stack<>();
for(String str: postTokens)
{
if(str.isEmpty()){
continue;
}
if(str.matches("[-+]?[0-9]*\\.?[0-9]+([eE... | java | public Expression constructTree(ArrayList<String> postTokens)
{
Expression root = null;
Stack<Expression> nodes = new Stack<>();
for(String str: postTokens)
{
if(str.isEmpty()){
continue;
}
if(str.matches("[-+]?[0-9]*\\.?[0-9]+([eE... | [
"public",
"Expression",
"constructTree",
"(",
"ArrayList",
"<",
"String",
">",
"postTokens",
")",
"{",
"Expression",
"root",
"=",
"null",
";",
"Stack",
"<",
"Expression",
">",
"nodes",
"=",
"new",
"Stack",
"<>",
"(",
")",
";",
"for",
"(",
"String",
"str"... | reads the "tokens" in order from the list and builds a tree | [
"reads",
"the",
"tokens",
"in",
"order",
"from",
"the",
"list",
"and",
"builds",
"a",
"tree"
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/symbolic/src/main/java/smile/symbolic/ExpressionTree.java#L163-L198 |
17,477 | haifengl/smile | core/src/main/java/smile/classification/SVM.java | Trainer.train | public SVM<T> train(T[] x, int[] y, double[] weight) {
SVM<T> svm = null;
if (k == 2) {
svm = new SVM<>(kernel, Cp, Cn);
} else {
if (this.weight == null) {
svm = new SVM<>(kernel, Cp, k, strategy);
} else {
... | java | public SVM<T> train(T[] x, int[] y, double[] weight) {
SVM<T> svm = null;
if (k == 2) {
svm = new SVM<>(kernel, Cp, Cn);
} else {
if (this.weight == null) {
svm = new SVM<>(kernel, Cp, k, strategy);
} else {
... | [
"public",
"SVM",
"<",
"T",
">",
"train",
"(",
"T",
"[",
"]",
"x",
",",
"int",
"[",
"]",
"y",
",",
"double",
"[",
"]",
"weight",
")",
"{",
"SVM",
"<",
"T",
">",
"svm",
"=",
"null",
";",
"if",
"(",
"k",
"==",
"2",
")",
"{",
"svm",
"=",
"n... | Learns a SVM classifier with given training data.
@param x training instances.
@param y training labels in [0, k), where k is the number of classes.
@param weight instance weight. Must be positive. The soft margin penalty
for instance i will be weight[i] * C.
@return trained SVM classifier | [
"Learns",
"a",
"SVM",
"classifier",
"with",
"given",
"training",
"data",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/classification/SVM.java#L305-L324 |
17,478 | haifengl/smile | core/src/main/java/smile/classification/NaiveBayes.java | NaiveBayes.learn | public void learn(double[][] x, int[] y) {
if (model == Model.GENERAL) {
throw new UnsupportedOperationException("General-mode Naive Bayes classifier doesn't support online learning.");
}
if (model == Model.MULTINOMIAL) {
for (int i = 0; i < x.length; i++) {
... | java | public void learn(double[][] x, int[] y) {
if (model == Model.GENERAL) {
throw new UnsupportedOperationException("General-mode Naive Bayes classifier doesn't support online learning.");
}
if (model == Model.MULTINOMIAL) {
for (int i = 0; i < x.length; i++) {
... | [
"public",
"void",
"learn",
"(",
"double",
"[",
"]",
"[",
"]",
"x",
",",
"int",
"[",
"]",
"y",
")",
"{",
"if",
"(",
"model",
"==",
"Model",
".",
"GENERAL",
")",
"{",
"throw",
"new",
"UnsupportedOperationException",
"(",
"\"General-mode Naive Bayes classifie... | Online learning of naive Bayes classifier on sequences,
which are modeled as a bag of words. Note that this method is NOT
applicable for naive Bayes classifier with general generation model.
@param x training instances.
@param y training labels in [0, k), where k is the number of classes. | [
"Online",
"learning",
"of",
"naive",
"Bayes",
"classifier",
"on",
"sequences",
"which",
"are",
"modeled",
"as",
"a",
"bag",
"of",
"words",
".",
"Note",
"that",
"this",
"method",
"is",
"NOT",
"applicable",
"for",
"naive",
"Bayes",
"classifier",
"with",
"gener... | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/classification/NaiveBayes.java#L551-L602 |
17,479 | haifengl/smile | core/src/main/java/smile/classification/NaiveBayes.java | NaiveBayes.update | private void update() {
if (!predefinedPriori) {
for (int c = 0; c < k; c++) {
priori[c] = (nc[c] + EPSILON) / (n + k * EPSILON);
}
}
if (model == Model.MULTINOMIAL || model == Model.POLYAURN) {
for (int c = 0; c < k; c++) {
fo... | java | private void update() {
if (!predefinedPriori) {
for (int c = 0; c < k; c++) {
priori[c] = (nc[c] + EPSILON) / (n + k * EPSILON);
}
}
if (model == Model.MULTINOMIAL || model == Model.POLYAURN) {
for (int c = 0; c < k; c++) {
fo... | [
"private",
"void",
"update",
"(",
")",
"{",
"if",
"(",
"!",
"predefinedPriori",
")",
"{",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"k",
";",
"c",
"++",
")",
"{",
"priori",
"[",
"c",
"]",
"=",
"(",
"nc",
"[",
"c",
"]",
"+",
"EPSILON"... | Update conditional probabilities. | [
"Update",
"conditional",
"probabilities",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/classification/NaiveBayes.java#L607-L627 |
17,480 | haifengl/smile | core/src/main/java/smile/classification/NaiveBayes.java | NaiveBayes.predict | @Override
public int predict(double[] x, double[] posteriori) {
if (x.length != p) {
throw new IllegalArgumentException(String.format("Invalid input vector size: %d", x.length));
}
if (posteriori != null && posteriori.length != k) {
throw new IllegalArgumentException... | java | @Override
public int predict(double[] x, double[] posteriori) {
if (x.length != p) {
throw new IllegalArgumentException(String.format("Invalid input vector size: %d", x.length));
}
if (posteriori != null && posteriori.length != k) {
throw new IllegalArgumentException... | [
"@",
"Override",
"public",
"int",
"predict",
"(",
"double",
"[",
"]",
"x",
",",
"double",
"[",
"]",
"posteriori",
")",
"{",
"if",
"(",
"x",
".",
"length",
"!=",
"p",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"format",
... | Predict the class of an instance.
@param x the instance to be classified.
@param posteriori the array to store a posteriori probabilities on output.
@return the predicted class label. For MULTINOMIAL and BERNOULLI models,
returns -1 if the instance does not contain any feature words. | [
"Predict",
"the",
"class",
"of",
"an",
"instance",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/classification/NaiveBayes.java#L649-L711 |
17,481 | haifengl/smile | math/src/main/java/smile/math/SparseArray.java | SparseArray.get | public double get(int i) {
for (Entry e : array) {
if (e.i == i) {
return e.x;
}
}
return 0.0;
} | java | public double get(int i) {
for (Entry e : array) {
if (e.i == i) {
return e.x;
}
}
return 0.0;
} | [
"public",
"double",
"get",
"(",
"int",
"i",
")",
"{",
"for",
"(",
"Entry",
"e",
":",
"array",
")",
"{",
"if",
"(",
"e",
".",
"i",
"==",
"i",
")",
"{",
"return",
"e",
".",
"x",
";",
"}",
"}",
"return",
"0.0",
";",
"}"
] | Returns the value of i-th entry.
@param i the index of entry.
@return the value of entry, 0.0 if the index doesn't exist in the array. | [
"Returns",
"the",
"value",
"of",
"i",
"-",
"th",
"entry",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/SparseArray.java#L104-L112 |
17,482 | haifengl/smile | math/src/main/java/smile/math/SparseArray.java | SparseArray.set | public boolean set(int i, double x) {
if (x == 0.0) {
remove(i);
return false;
}
Iterator<Entry> it = array.iterator();
for (int k = 0; it.hasNext(); k++) {
Entry e = it.next();
if (e.i == i) {
e.x = x;
... | java | public boolean set(int i, double x) {
if (x == 0.0) {
remove(i);
return false;
}
Iterator<Entry> it = array.iterator();
for (int k = 0; it.hasNext(); k++) {
Entry e = it.next();
if (e.i == i) {
e.x = x;
... | [
"public",
"boolean",
"set",
"(",
"int",
"i",
",",
"double",
"x",
")",
"{",
"if",
"(",
"x",
"==",
"0.0",
")",
"{",
"remove",
"(",
"i",
")",
";",
"return",
"false",
";",
"}",
"Iterator",
"<",
"Entry",
">",
"it",
"=",
"array",
".",
"iterator",
"("... | Sets or add an entry.
@param i the index of entry.
@param x the value of entry.
@return true if a new entry added, false if an existing entry updated. | [
"Sets",
"or",
"add",
"an",
"entry",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/SparseArray.java#L120-L140 |
17,483 | haifengl/smile | math/src/main/java/smile/math/SparseArray.java | SparseArray.remove | public void remove(int i) {
Iterator<Entry> it = array.iterator();
while (it.hasNext()) {
Entry e = it.next();
if (e.i == i) {
it.remove();
break;
}
}
} | java | public void remove(int i) {
Iterator<Entry> it = array.iterator();
while (it.hasNext()) {
Entry e = it.next();
if (e.i == i) {
it.remove();
break;
}
}
} | [
"public",
"void",
"remove",
"(",
"int",
"i",
")",
"{",
"Iterator",
"<",
"Entry",
">",
"it",
"=",
"array",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"it",
".",
"hasNext",
"(",
")",
")",
"{",
"Entry",
"e",
"=",
"it",
".",
"next",
"(",
")",
... | Removes an entry.
@param i the index of entry. | [
"Removes",
"an",
"entry",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/SparseArray.java#L157-L166 |
17,484 | haifengl/smile | core/src/main/java/smile/regression/RandomForest.java | RandomForest.merge | public RandomForest merge(RandomForest other) {
if (this.importance.length != other.importance.length) {
throw new IllegalArgumentException("RandomForest have different sizes of feature vectors");
}
ArrayList<RegressionTree> mergedTrees = new ArrayList<>();
mergedTrees.addAl... | java | public RandomForest merge(RandomForest other) {
if (this.importance.length != other.importance.length) {
throw new IllegalArgumentException("RandomForest have different sizes of feature vectors");
}
ArrayList<RegressionTree> mergedTrees = new ArrayList<>();
mergedTrees.addAl... | [
"public",
"RandomForest",
"merge",
"(",
"RandomForest",
"other",
")",
"{",
"if",
"(",
"this",
".",
"importance",
".",
"length",
"!=",
"other",
".",
"importance",
".",
"length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"RandomForest have diffe... | Merges together two random forests and returns a new forest consisting of trees from both input forests. | [
"Merges",
"together",
"two",
"random",
"forests",
"and",
"returns",
"a",
"new",
"forest",
"consisting",
"of",
"trees",
"from",
"both",
"input",
"forests",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/regression/RandomForest.java#L585-L598 |
17,485 | haifengl/smile | data/src/main/java/smile/data/parser/SparseMatrixParser.java | SparseMatrixParser.parse | public SparseMatrix parse(InputStream stream) throws IOException, ParseException {
int nrows = 0, ncols = 0, n = 0;
int[] colIndex;
int[] rowIndex;
double[] data;
try (Scanner scanner = new Scanner(stream)) {
String line = scanner.nextLine();
String[] tok... | java | public SparseMatrix parse(InputStream stream) throws IOException, ParseException {
int nrows = 0, ncols = 0, n = 0;
int[] colIndex;
int[] rowIndex;
double[] data;
try (Scanner scanner = new Scanner(stream)) {
String line = scanner.nextLine();
String[] tok... | [
"public",
"SparseMatrix",
"parse",
"(",
"InputStream",
"stream",
")",
"throws",
"IOException",
",",
"ParseException",
"{",
"int",
"nrows",
"=",
"0",
",",
"ncols",
"=",
"0",
",",
"n",
"=",
"0",
";",
"int",
"[",
"]",
"colIndex",
";",
"int",
"[",
"]",
"... | Parse a Harwell-Boeing column-compressed sparse matrix dataset from an input stream.
@param stream the input stream of data.
@throws java.io.IOException | [
"Parse",
"a",
"Harwell",
"-",
"Boeing",
"column",
"-",
"compressed",
"sparse",
"matrix",
"dataset",
"from",
"an",
"input",
"stream",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/data/src/main/java/smile/data/parser/SparseMatrixParser.java#L89-L145 |
17,486 | haifengl/smile | math/src/main/java/smile/math/matrix/BiconjugateGradient.java | BiconjugateGradient.diagonalPreconditioner | private static Preconditioner diagonalPreconditioner(Matrix A) {
return new Preconditioner() {
public void asolve(double[] b, double[] x) {
double[] diag = A.diag();
int n = diag.length;
for (int i = 0; i < n; i++) {
x[i] = diag[i]... | java | private static Preconditioner diagonalPreconditioner(Matrix A) {
return new Preconditioner() {
public void asolve(double[] b, double[] x) {
double[] diag = A.diag();
int n = diag.length;
for (int i = 0; i < n; i++) {
x[i] = diag[i]... | [
"private",
"static",
"Preconditioner",
"diagonalPreconditioner",
"(",
"Matrix",
"A",
")",
"{",
"return",
"new",
"Preconditioner",
"(",
")",
"{",
"public",
"void",
"asolve",
"(",
"double",
"[",
"]",
"b",
",",
"double",
"[",
"]",
"x",
")",
"{",
"double",
"... | Returns a simple preconditioner matrix that is the
trivial diagonal part of A in some cases. | [
"Returns",
"a",
"simple",
"preconditioner",
"matrix",
"that",
"is",
"the",
"trivial",
"diagonal",
"part",
"of",
"A",
"in",
"some",
"cases",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/matrix/BiconjugateGradient.java#L35-L46 |
17,487 | haifengl/smile | math/src/main/java/smile/math/matrix/BiconjugateGradient.java | BiconjugateGradient.snorm | private static double snorm(double[] x, int itol) {
int n = x.length;
if (itol <= 3) {
double ans = 0.0;
for (int i = 0; i < n; i++) {
ans += x[i] * x[i];
}
return Math.sqrt(ans);
} else {
int isamax = 0;
fo... | java | private static double snorm(double[] x, int itol) {
int n = x.length;
if (itol <= 3) {
double ans = 0.0;
for (int i = 0; i < n; i++) {
ans += x[i] * x[i];
}
return Math.sqrt(ans);
} else {
int isamax = 0;
fo... | [
"private",
"static",
"double",
"snorm",
"(",
"double",
"[",
"]",
"x",
",",
"int",
"itol",
")",
"{",
"int",
"n",
"=",
"x",
".",
"length",
";",
"if",
"(",
"itol",
"<=",
"3",
")",
"{",
"double",
"ans",
"=",
"0.0",
";",
"for",
"(",
"int",
"i",
"=... | Compute L2 or L-infinity norms for a vector x, as signaled by itol. | [
"Compute",
"L2",
"or",
"L",
"-",
"infinity",
"norms",
"for",
"a",
"vector",
"x",
"as",
"signaled",
"by",
"itol",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/matrix/BiconjugateGradient.java#L291-L310 |
17,488 | haifengl/smile | demo/src/main/java/smile/demo/mds/SammonMappingDemo.java | SammonMappingDemo.learn | public JComponent learn() {
JPanel pane = new JPanel(new GridLayout(1, 2));
double[][] data = dataset[datasetIndex].toArray(new double[dataset[datasetIndex].size()][]);
String[] labels = dataset[datasetIndex].toArray(new String[dataset[datasetIndex].size()]);
if (labels[0] == null) {
... | java | public JComponent learn() {
JPanel pane = new JPanel(new GridLayout(1, 2));
double[][] data = dataset[datasetIndex].toArray(new double[dataset[datasetIndex].size()][]);
String[] labels = dataset[datasetIndex].toArray(new String[dataset[datasetIndex].size()]);
if (labels[0] == null) {
... | [
"public",
"JComponent",
"learn",
"(",
")",
"{",
"JPanel",
"pane",
"=",
"new",
"JPanel",
"(",
"new",
"GridLayout",
"(",
"1",
",",
"2",
")",
")",
";",
"double",
"[",
"]",
"[",
"]",
"data",
"=",
"dataset",
"[",
"datasetIndex",
"]",
".",
"toArray",
"("... | Execute the MDS algorithm and return a swing JComponent representing
the clusters. | [
"Execute",
"the",
"MDS",
"algorithm",
"and",
"return",
"a",
"swing",
"JComponent",
"representing",
"the",
"clusters",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/demo/src/main/java/smile/demo/mds/SammonMappingDemo.java#L95-L124 |
17,489 | haifengl/smile | math/src/main/java/smile/math/DoubleArrayList.java | DoubleArrayList.add | public void add(double[] vals) {
ensureCapacity(size + vals.length);
System.arraycopy(vals, 0, data, size, vals.length);
size += vals.length;
} | java | public void add(double[] vals) {
ensureCapacity(size + vals.length);
System.arraycopy(vals, 0, data, size, vals.length);
size += vals.length;
} | [
"public",
"void",
"add",
"(",
"double",
"[",
"]",
"vals",
")",
"{",
"ensureCapacity",
"(",
"size",
"+",
"vals",
".",
"length",
")",
";",
"System",
".",
"arraycopy",
"(",
"vals",
",",
"0",
",",
"data",
",",
"size",
",",
"vals",
".",
"length",
")",
... | Appends an array to the end of this list.
@param vals an array to be appended to this list. | [
"Appends",
"an",
"array",
"to",
"the",
"end",
"of",
"this",
"list",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/DoubleArrayList.java#L126-L130 |
17,490 | haifengl/smile | interpolation/src/main/java/smile/interpolation/LaplaceInterpolation.java | LaplaceInterpolation.snorm | private static double snorm(double[] sx) {
int n = sx.length;
double ans = 0.0;
for (int i = 0; i < n; i++) {
ans += sx[i] * sx[i];
}
return Math.sqrt(ans);
} | java | private static double snorm(double[] sx) {
int n = sx.length;
double ans = 0.0;
for (int i = 0; i < n; i++) {
ans += sx[i] * sx[i];
}
return Math.sqrt(ans);
} | [
"private",
"static",
"double",
"snorm",
"(",
"double",
"[",
"]",
"sx",
")",
"{",
"int",
"n",
"=",
"sx",
".",
"length",
";",
"double",
"ans",
"=",
"0.0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"a... | Compute squared root of L2 norms for a vector. | [
"Compute",
"squared",
"root",
"of",
"L2",
"norms",
"for",
"a",
"vector",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/interpolation/src/main/java/smile/interpolation/LaplaceInterpolation.java#L248-L256 |
17,491 | haifengl/smile | core/src/main/java/smile/regression/SVR.java | SVR.gram | private void gram(SupportVector i) {
int n = sv.size();
int m = MulticoreExecutor.getThreadPoolSize();
i.kcache = new DoubleArrayList(n);
if (n < 100 || m < 2) {
for (SupportVector v : sv) {
i.kcache.add(kernel.k(i.x, v.x));
}
} else {
... | java | private void gram(SupportVector i) {
int n = sv.size();
int m = MulticoreExecutor.getThreadPoolSize();
i.kcache = new DoubleArrayList(n);
if (n < 100 || m < 2) {
for (SupportVector v : sv) {
i.kcache.add(kernel.k(i.x, v.x));
}
} else {
... | [
"private",
"void",
"gram",
"(",
"SupportVector",
"i",
")",
"{",
"int",
"n",
"=",
"sv",
".",
"size",
"(",
")",
";",
"int",
"m",
"=",
"MulticoreExecutor",
".",
"getThreadPoolSize",
"(",
")",
";",
"i",
".",
"kcache",
"=",
"new",
"DoubleArrayList",
"(",
... | Calculate the row of kernel matrix for a vector i.
@param i data vector to evaluate kernel matrix. | [
"Calculate",
"the",
"row",
"of",
"kernel",
"matrix",
"for",
"a",
"vector",
"i",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/core/src/main/java/smile/regression/SVR.java#L412-L448 |
17,492 | haifengl/smile | plot/src/main/java/smile/plot/Dendrogram.java | Dendrogram.dfs | private int dfs(int[][] merge, int index, int[] order, int i) {
int n = merge.length + 1;
if (merge[index][0] > merge.length) {
i = dfs(merge, merge[index][0] - n, order, i);
} else {
order[i++] = merge[index][0];
}
if (merge[index][1] > merge.length) {
... | java | private int dfs(int[][] merge, int index, int[] order, int i) {
int n = merge.length + 1;
if (merge[index][0] > merge.length) {
i = dfs(merge, merge[index][0] - n, order, i);
} else {
order[i++] = merge[index][0];
}
if (merge[index][1] > merge.length) {
... | [
"private",
"int",
"dfs",
"(",
"int",
"[",
"]",
"[",
"]",
"merge",
",",
"int",
"index",
",",
"int",
"[",
"]",
"order",
",",
"int",
"i",
")",
"{",
"int",
"n",
"=",
"merge",
".",
"length",
"+",
"1",
";",
"if",
"(",
"merge",
"[",
"index",
"]",
... | DFS the tree to find the order of leafs to avoid the cross of lines in
the plot. | [
"DFS",
"the",
"tree",
"to",
"find",
"the",
"order",
"of",
"leafs",
"to",
"avoid",
"the",
"cross",
"of",
"lines",
"in",
"the",
"plot",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/plot/src/main/java/smile/plot/Dendrogram.java#L118-L134 |
17,493 | haifengl/smile | plot/src/main/java/smile/plot/Dendrogram.java | Dendrogram.plot | public static PlotCanvas plot(String id, int[][] merge, double[] height) {
int n = merge.length + 1;
Dendrogram dendrogram = new Dendrogram(merge, height);
double[] lowerBound = {-n / 100, 0};
double[] upperBound = {n + n / 100, 1.01 * dendrogram.getHeight()};
PlotCanvas canvas... | java | public static PlotCanvas plot(String id, int[][] merge, double[] height) {
int n = merge.length + 1;
Dendrogram dendrogram = new Dendrogram(merge, height);
double[] lowerBound = {-n / 100, 0};
double[] upperBound = {n + n / 100, 1.01 * dendrogram.getHeight()};
PlotCanvas canvas... | [
"public",
"static",
"PlotCanvas",
"plot",
"(",
"String",
"id",
",",
"int",
"[",
"]",
"[",
"]",
"merge",
",",
"double",
"[",
"]",
"height",
")",
"{",
"int",
"n",
"=",
"merge",
".",
"length",
"+",
"1",
";",
"Dendrogram",
"dendrogram",
"=",
"new",
"De... | Create a dendrogram plot.
@param id the id of the plot.
@param merge an n-1 by 2 matrix of which row i describes the merging of clusters at
step i of the clustering. If an element j in the row is less than n, then
observation j was merged at this stage. If j ≥ n then the merge
was with the cluster formed at the (ear... | [
"Create",
"a",
"dendrogram",
"plot",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/plot/src/main/java/smile/plot/Dendrogram.java#L185-L200 |
17,494 | haifengl/smile | data/src/main/java/smile/data/DateAttribute.java | DateAttribute.toDate | public Date toDate(double x) {
if (Double.isNaN(x)) {
return null;
}
return new Date(Double.doubleToRawLongBits(x));
} | java | public Date toDate(double x) {
if (Double.isNaN(x)) {
return null;
}
return new Date(Double.doubleToRawLongBits(x));
} | [
"public",
"Date",
"toDate",
"(",
"double",
"x",
")",
"{",
"if",
"(",
"Double",
".",
"isNaN",
"(",
"x",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"Date",
"(",
"Double",
".",
"doubleToRawLongBits",
"(",
"x",
")",
")",
";",
"}"
] | Retruns the date object from internal double encoding.
@param x the date in double encoding. | [
"Retruns",
"the",
"date",
"object",
"from",
"internal",
"double",
"encoding",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/data/src/main/java/smile/data/DateAttribute.java#L113-L119 |
17,495 | haifengl/smile | math/src/main/java/smile/math/matrix/JMatrix.java | JMatrix.cholesky | @Override
public Cholesky cholesky() {
if (nrows() != ncols()) {
throw new UnsupportedOperationException("Cholesky decomposition on non-square matrix");
}
int n = nrows();
// Main loop.
for (int j = 0; j < n; j++) {
double d = 0.0;
for (i... | java | @Override
public Cholesky cholesky() {
if (nrows() != ncols()) {
throw new UnsupportedOperationException("Cholesky decomposition on non-square matrix");
}
int n = nrows();
// Main loop.
for (int j = 0; j < n; j++) {
double d = 0.0;
for (i... | [
"@",
"Override",
"public",
"Cholesky",
"cholesky",
"(",
")",
"{",
"if",
"(",
"nrows",
"(",
")",
"!=",
"ncols",
"(",
")",
")",
"{",
"throw",
"new",
"UnsupportedOperationException",
"(",
"\"Cholesky decomposition on non-square matrix\"",
")",
";",
"}",
"int",
"n... | Cholesky decomposition for symmetric and positive definite matrix.
Only the lower triangular part will be used in the decomposition.
@throws IllegalArgumentException if the matrix is not positive definite. | [
"Cholesky",
"decomposition",
"for",
"symmetric",
"and",
"positive",
"definite",
"matrix",
".",
"Only",
"the",
"lower",
"triangular",
"part",
"will",
"be",
"used",
"in",
"the",
"decomposition",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/matrix/JMatrix.java#L909-L939 |
17,496 | haifengl/smile | math/src/main/java/smile/math/matrix/JMatrix.java | JMatrix.qr | @Override
public QR qr() {
// Initialize.
int m = nrows();
int n = ncols();
double[] rDiagonal = new double[n];
// Main loop.
for (int k = 0; k < n; k++) {
// Compute 2-norm of k-th column without under/overflow.
double nrm = 0.0;
... | java | @Override
public QR qr() {
// Initialize.
int m = nrows();
int n = ncols();
double[] rDiagonal = new double[n];
// Main loop.
for (int k = 0; k < n; k++) {
// Compute 2-norm of k-th column without under/overflow.
double nrm = 0.0;
... | [
"@",
"Override",
"public",
"QR",
"qr",
"(",
")",
"{",
"// Initialize.",
"int",
"m",
"=",
"nrows",
"(",
")",
";",
"int",
"n",
"=",
"ncols",
"(",
")",
";",
"double",
"[",
"]",
"rDiagonal",
"=",
"new",
"double",
"[",
"n",
"]",
";",
"// Main loop.",
... | QR Decomposition is computed by Householder reflections. | [
"QR",
"Decomposition",
"is",
"computed",
"by",
"Householder",
"reflections",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/matrix/JMatrix.java#L944-L993 |
17,497 | haifengl/smile | math/src/main/java/smile/math/matrix/JMatrix.java | JMatrix.balance | private static double[] balance(DenseMatrix A) {
double sqrdx = Math.RADIX * Math.RADIX;
int n = A.nrows();
double[] scale = new double[n];
for (int i = 0; i < n; i++) {
scale[i] = 1.0;
}
boolean done = false;
while (!done) {
done = true... | java | private static double[] balance(DenseMatrix A) {
double sqrdx = Math.RADIX * Math.RADIX;
int n = A.nrows();
double[] scale = new double[n];
for (int i = 0; i < n; i++) {
scale[i] = 1.0;
}
boolean done = false;
while (!done) {
done = true... | [
"private",
"static",
"double",
"[",
"]",
"balance",
"(",
"DenseMatrix",
"A",
")",
"{",
"double",
"sqrdx",
"=",
"Math",
".",
"RADIX",
"*",
"Math",
".",
"RADIX",
";",
"int",
"n",
"=",
"A",
".",
"nrows",
"(",
")",
";",
"double",
"[",
"]",
"scale",
"... | Given a square matrix, this routine replaces it by a balanced matrix with
identical eigenvalues. A symmetric matrix is already balanced and is
unaffected by this procedure. | [
"Given",
"a",
"square",
"matrix",
"this",
"routine",
"replaces",
"it",
"by",
"a",
"balanced",
"matrix",
"with",
"identical",
"eigenvalues",
".",
"A",
"symmetric",
"matrix",
"is",
"already",
"balanced",
"and",
"is",
"unaffected",
"by",
"this",
"procedure",
"."
... | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/matrix/JMatrix.java#L1815-L1865 |
17,498 | haifengl/smile | math/src/main/java/smile/math/matrix/JMatrix.java | JMatrix.balbak | private static void balbak(DenseMatrix V, double[] scale) {
int n = V.nrows();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
V.mul(i, j, scale[i]);
}
}
} | java | private static void balbak(DenseMatrix V, double[] scale) {
int n = V.nrows();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
V.mul(i, j, scale[i]);
}
}
} | [
"private",
"static",
"void",
"balbak",
"(",
"DenseMatrix",
"V",
",",
"double",
"[",
"]",
"scale",
")",
"{",
"int",
"n",
"=",
"V",
".",
"nrows",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"... | Form the eigenvectors of a real nonsymmetric matrix by back transforming
those of the corresponding balanced matrix determined by balance. | [
"Form",
"the",
"eigenvectors",
"of",
"a",
"real",
"nonsymmetric",
"matrix",
"by",
"back",
"transforming",
"those",
"of",
"the",
"corresponding",
"balanced",
"matrix",
"determined",
"by",
"balance",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/matrix/JMatrix.java#L1871-L1878 |
17,499 | haifengl/smile | math/src/main/java/smile/math/matrix/JMatrix.java | JMatrix.elmhes | private static int[] elmhes(DenseMatrix A) {
int n = A.nrows();
int[] perm = new int[n];
for (int m = 1; m < n - 1; m++) {
double x = 0.0;
int i = m;
for (int j = m; j < n; j++) {
if (Math.abs(A.get(j, m - 1)) > Math.abs(x)) {
... | java | private static int[] elmhes(DenseMatrix A) {
int n = A.nrows();
int[] perm = new int[n];
for (int m = 1; m < n - 1; m++) {
double x = 0.0;
int i = m;
for (int j = m; j < n; j++) {
if (Math.abs(A.get(j, m - 1)) > Math.abs(x)) {
... | [
"private",
"static",
"int",
"[",
"]",
"elmhes",
"(",
"DenseMatrix",
"A",
")",
"{",
"int",
"n",
"=",
"A",
".",
"nrows",
"(",
")",
";",
"int",
"[",
"]",
"perm",
"=",
"new",
"int",
"[",
"n",
"]",
";",
"for",
"(",
"int",
"m",
"=",
"1",
";",
"m"... | Reduce a real nonsymmetric matrix to upper Hessenberg form. | [
"Reduce",
"a",
"real",
"nonsymmetric",
"matrix",
"to",
"upper",
"Hessenberg",
"form",
"."
] | e27e43e90fbaacce3f99d30120cf9dd6a764c33d | https://github.com/haifengl/smile/blob/e27e43e90fbaacce3f99d30120cf9dd6a764c33d/math/src/main/java/smile/math/matrix/JMatrix.java#L1883-L1927 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.