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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
12,200
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serializer/AgentSerializer.java
|
AgentSerializer.getValue
|
@SuppressWarnings("rawtypes")
protected Object getValue(GetterMethodCover method, Object value) {
if(method.isByte()) {
value = ((Byte)value).intValue();
}
else if(method.isChar()) {
value = (int)((Character)value).charValue();
}
else if(method.isFloat()) {
value = ((Float)value).doubleValue();
}
else if(method.isLong()) {
value = ((Long)value).doubleValue();
}
else if(method.isShort()) {
value = ((Short)value).intValue();
}
else if(method.isObject()) {
value = parseObject(method, value);
}
else if(method.isObjectArray()) {
value = parseArray(method, value);
}
else if(method.isArrayObjectCollection()) {
return parseArrayObjectCollection(method, (Collection)value);
}
else if(method.isObjectCollection()) {
return parseObjectCollection(method, (Collection)value);
}
else if(method.isArrayCollection()) {
return parseArrayCollection(method, (Collection)value);
}
else if(method.isArray() || method.isColection()) {
return transformSimpleValue(value);
}
return value;
}
|
java
|
@SuppressWarnings("rawtypes")
protected Object getValue(GetterMethodCover method, Object value) {
if(method.isByte()) {
value = ((Byte)value).intValue();
}
else if(method.isChar()) {
value = (int)((Character)value).charValue();
}
else if(method.isFloat()) {
value = ((Float)value).doubleValue();
}
else if(method.isLong()) {
value = ((Long)value).doubleValue();
}
else if(method.isShort()) {
value = ((Short)value).intValue();
}
else if(method.isObject()) {
value = parseObject(method, value);
}
else if(method.isObjectArray()) {
value = parseArray(method, value);
}
else if(method.isArrayObjectCollection()) {
return parseArrayObjectCollection(method, (Collection)value);
}
else if(method.isObjectCollection()) {
return parseObjectCollection(method, (Collection)value);
}
else if(method.isArrayCollection()) {
return parseArrayCollection(method, (Collection)value);
}
else if(method.isArray() || method.isColection()) {
return transformSimpleValue(value);
}
return value;
}
|
[
"@",
"SuppressWarnings",
"(",
"\"rawtypes\"",
")",
"protected",
"Object",
"getValue",
"(",
"GetterMethodCover",
"method",
",",
"Object",
"value",
")",
"{",
"if",
"(",
"method",
".",
"isByte",
"(",
")",
")",
"{",
"value",
"=",
"(",
"(",
"Byte",
")",
"value",
")",
".",
"intValue",
"(",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isChar",
"(",
")",
")",
"{",
"value",
"=",
"(",
"int",
")",
"(",
"(",
"Character",
")",
"value",
")",
".",
"charValue",
"(",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isFloat",
"(",
")",
")",
"{",
"value",
"=",
"(",
"(",
"Float",
")",
"value",
")",
".",
"doubleValue",
"(",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isLong",
"(",
")",
")",
"{",
"value",
"=",
"(",
"(",
"Long",
")",
"value",
")",
".",
"doubleValue",
"(",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isShort",
"(",
")",
")",
"{",
"value",
"=",
"(",
"(",
"Short",
")",
"value",
")",
".",
"intValue",
"(",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isObject",
"(",
")",
")",
"{",
"value",
"=",
"parseObject",
"(",
"method",
",",
"value",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isObjectArray",
"(",
")",
")",
"{",
"value",
"=",
"parseArray",
"(",
"method",
",",
"value",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isArrayObjectCollection",
"(",
")",
")",
"{",
"return",
"parseArrayObjectCollection",
"(",
"method",
",",
"(",
"Collection",
")",
"value",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isObjectCollection",
"(",
")",
")",
"{",
"return",
"parseObjectCollection",
"(",
"method",
",",
"(",
"Collection",
")",
"value",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isArrayCollection",
"(",
")",
")",
"{",
"return",
"parseArrayCollection",
"(",
"method",
",",
"(",
"Collection",
")",
"value",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isArray",
"(",
")",
"||",
"method",
".",
"isColection",
"(",
")",
")",
"{",
"return",
"transformSimpleValue",
"(",
"value",
")",
";",
"}",
"return",
"value",
";",
"}"
] |
Call getter method and get value
@param method structure of getter method
@param value object to call method
@return a value
|
[
"Call",
"getter",
"method",
"and",
"get",
"value"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serializer/AgentSerializer.java#L64-L100
|
12,201
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/BuddyListInitEventHandler.java
|
BuddyListInitEventHandler.updateBuddyProperties
|
private void updateBuddyProperties(BuddyProperties buddyProperties,
ApiBuddyProperties apiBuddyProperties) {
apiBuddyProperties.setInited(buddyProperties.isInited());
apiBuddyProperties.setNickName(buddyProperties.getNickName());
apiBuddyProperties.setOnline(buddyProperties.isOnline());
apiBuddyProperties.setState(buddyProperties.getState());
}
|
java
|
private void updateBuddyProperties(BuddyProperties buddyProperties,
ApiBuddyProperties apiBuddyProperties) {
apiBuddyProperties.setInited(buddyProperties.isInited());
apiBuddyProperties.setNickName(buddyProperties.getNickName());
apiBuddyProperties.setOnline(buddyProperties.isOnline());
apiBuddyProperties.setState(buddyProperties.getState());
}
|
[
"private",
"void",
"updateBuddyProperties",
"(",
"BuddyProperties",
"buddyProperties",
",",
"ApiBuddyProperties",
"apiBuddyProperties",
")",
"{",
"apiBuddyProperties",
".",
"setInited",
"(",
"buddyProperties",
".",
"isInited",
"(",
")",
")",
";",
"apiBuddyProperties",
".",
"setNickName",
"(",
"buddyProperties",
".",
"getNickName",
"(",
")",
")",
";",
"apiBuddyProperties",
".",
"setOnline",
"(",
"buddyProperties",
".",
"isOnline",
"(",
")",
")",
";",
"apiBuddyProperties",
".",
"setState",
"(",
"buddyProperties",
".",
"getState",
"(",
")",
")",
";",
"}"
] |
Update buddy properties of user
@param buddyProperties smartfox user's buddy properties
@param apiBuddyProperties api user's buddy properties
|
[
"Update",
"buddy",
"properties",
"of",
"user"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/BuddyListInitEventHandler.java#L59-L65
|
12,202
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/FgModel.java
|
FgModel.apply
|
void apply(final LambdaUnaryOpDouble lambda) {
params.apply(new FnIntDoubleToDouble() {
@Override
public double call(int idx, double val) {
return lambda.call(val);
}
});
}
|
java
|
void apply(final LambdaUnaryOpDouble lambda) {
params.apply(new FnIntDoubleToDouble() {
@Override
public double call(int idx, double val) {
return lambda.call(val);
}
});
}
|
[
"void",
"apply",
"(",
"final",
"LambdaUnaryOpDouble",
"lambda",
")",
"{",
"params",
".",
"apply",
"(",
"new",
"FnIntDoubleToDouble",
"(",
")",
"{",
"@",
"Override",
"public",
"double",
"call",
"(",
"int",
"idx",
",",
"double",
"val",
")",
"{",
"return",
"lambda",
".",
"call",
"(",
"val",
")",
";",
"}",
"}",
")",
";",
"}"
] |
ONLY FOR TESTING.
|
[
"ONLY",
"FOR",
"TESTING",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/FgModel.java#L166-L173
|
12,203
|
JodaOrg/joda-collect
|
src/main/java/org/joda/collect/grid/ImmutableCell.java
|
ImmutableCell.validateCounts
|
ImmutableCell<V> validateCounts(int rowCount, int columnCount) {
if (row >= rowCount || column >= columnCount) {
throw new IndexOutOfBoundsException("Invalid row-column: " + row + "," + column + " for grid " + rowCount + "x" + columnCount);
}
return this;
}
|
java
|
ImmutableCell<V> validateCounts(int rowCount, int columnCount) {
if (row >= rowCount || column >= columnCount) {
throw new IndexOutOfBoundsException("Invalid row-column: " + row + "," + column + " for grid " + rowCount + "x" + columnCount);
}
return this;
}
|
[
"ImmutableCell",
"<",
"V",
">",
"validateCounts",
"(",
"int",
"rowCount",
",",
"int",
"columnCount",
")",
"{",
"if",
"(",
"row",
">=",
"rowCount",
"||",
"column",
">=",
"columnCount",
")",
"{",
"throw",
"new",
"IndexOutOfBoundsException",
"(",
"\"Invalid row-column: \"",
"+",
"row",
"+",
"\",\"",
"+",
"column",
"+",
"\" for grid \"",
"+",
"rowCount",
"+",
"\"x\"",
"+",
"columnCount",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Validates this cell against the specified counts.
|
[
"Validates",
"this",
"cell",
"against",
"the",
"specified",
"counts",
"."
] |
a4b05d5eebad5beb41715c0678cf11835cf0fa3f
|
https://github.com/JodaOrg/joda-collect/blob/a4b05d5eebad5beb41715c0678cf11835cf0fa3f/src/main/java/org/joda/collect/grid/ImmutableCell.java#L118-L123
|
12,204
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/sch/tasks/SumPaths.java
|
SumPaths.approxSumPaths
|
public static double approxSumPaths(WeightedIntDiGraph g, RealVector startWeights, RealVector endWeights,
Iterator<DiEdge> seq, DoubleConsumer c) {
// we keep track of the total weight of discovered paths ending along
// each edge and the total weight
// of all paths ending at each node (including the empty path); on each
// time step, we
// at each step, we pick an edge (s, t), update the sum at s, and extend
// each of those (including
// the empty path starting there) with the edge (s, t)
DefaultDict<DiEdge, Double> prefixWeightsEndingAt = new DefaultDict<DiEdge, Double>(Void -> 0.0);
// we'll maintain node sums and overall sum with subtraction rather than
// re-adding (it's an approximation anyway!)
RealVector currentSums = startWeights.copy();
double currentTotal = currentSums.dotProduct(endWeights);
if (c != null) {
c.accept(currentTotal);
}
for (DiEdge e : ScheduleUtils.iterable(seq)) {
int s = e.get1();
int t = e.get2();
// compute the new sums
double oldTargetSum = currentSums.getEntry(t);
double oldEdgeSum = prefixWeightsEndingAt.get(e);
// new edge sum is the source sum times the edge weight
double newEdgeSum = currentSums.getEntry(s) * g.getWeight(e);
// new target sum is the old target sum plus the difference between
// the new and old edge sums
double newTargetSum = oldTargetSum + (newEdgeSum - oldEdgeSum);
// the new total is the old total plus the difference in new and
// target
double newTotal = currentTotal + (newTargetSum - oldTargetSum) * endWeights.getEntry(t);
// store the new sums
prefixWeightsEndingAt.put(e, newEdgeSum);
currentSums.setEntry(t, newTargetSum);
currentTotal = newTotal;
// and report the new total to the consumer
if (c != null) {
c.accept(currentTotal);
}
}
return currentTotal;
}
|
java
|
public static double approxSumPaths(WeightedIntDiGraph g, RealVector startWeights, RealVector endWeights,
Iterator<DiEdge> seq, DoubleConsumer c) {
// we keep track of the total weight of discovered paths ending along
// each edge and the total weight
// of all paths ending at each node (including the empty path); on each
// time step, we
// at each step, we pick an edge (s, t), update the sum at s, and extend
// each of those (including
// the empty path starting there) with the edge (s, t)
DefaultDict<DiEdge, Double> prefixWeightsEndingAt = new DefaultDict<DiEdge, Double>(Void -> 0.0);
// we'll maintain node sums and overall sum with subtraction rather than
// re-adding (it's an approximation anyway!)
RealVector currentSums = startWeights.copy();
double currentTotal = currentSums.dotProduct(endWeights);
if (c != null) {
c.accept(currentTotal);
}
for (DiEdge e : ScheduleUtils.iterable(seq)) {
int s = e.get1();
int t = e.get2();
// compute the new sums
double oldTargetSum = currentSums.getEntry(t);
double oldEdgeSum = prefixWeightsEndingAt.get(e);
// new edge sum is the source sum times the edge weight
double newEdgeSum = currentSums.getEntry(s) * g.getWeight(e);
// new target sum is the old target sum plus the difference between
// the new and old edge sums
double newTargetSum = oldTargetSum + (newEdgeSum - oldEdgeSum);
// the new total is the old total plus the difference in new and
// target
double newTotal = currentTotal + (newTargetSum - oldTargetSum) * endWeights.getEntry(t);
// store the new sums
prefixWeightsEndingAt.put(e, newEdgeSum);
currentSums.setEntry(t, newTargetSum);
currentTotal = newTotal;
// and report the new total to the consumer
if (c != null) {
c.accept(currentTotal);
}
}
return currentTotal;
}
|
[
"public",
"static",
"double",
"approxSumPaths",
"(",
"WeightedIntDiGraph",
"g",
",",
"RealVector",
"startWeights",
",",
"RealVector",
"endWeights",
",",
"Iterator",
"<",
"DiEdge",
">",
"seq",
",",
"DoubleConsumer",
"c",
")",
"{",
"// we keep track of the total weight of discovered paths ending along",
"// each edge and the total weight",
"// of all paths ending at each node (including the empty path); on each",
"// time step, we",
"// at each step, we pick an edge (s, t), update the sum at s, and extend",
"// each of those (including",
"// the empty path starting there) with the edge (s, t)",
"DefaultDict",
"<",
"DiEdge",
",",
"Double",
">",
"prefixWeightsEndingAt",
"=",
"new",
"DefaultDict",
"<",
"DiEdge",
",",
"Double",
">",
"(",
"Void",
"->",
"0.0",
")",
";",
"// we'll maintain node sums and overall sum with subtraction rather than",
"// re-adding (it's an approximation anyway!)",
"RealVector",
"currentSums",
"=",
"startWeights",
".",
"copy",
"(",
")",
";",
"double",
"currentTotal",
"=",
"currentSums",
".",
"dotProduct",
"(",
"endWeights",
")",
";",
"if",
"(",
"c",
"!=",
"null",
")",
"{",
"c",
".",
"accept",
"(",
"currentTotal",
")",
";",
"}",
"for",
"(",
"DiEdge",
"e",
":",
"ScheduleUtils",
".",
"iterable",
"(",
"seq",
")",
")",
"{",
"int",
"s",
"=",
"e",
".",
"get1",
"(",
")",
";",
"int",
"t",
"=",
"e",
".",
"get2",
"(",
")",
";",
"// compute the new sums",
"double",
"oldTargetSum",
"=",
"currentSums",
".",
"getEntry",
"(",
"t",
")",
";",
"double",
"oldEdgeSum",
"=",
"prefixWeightsEndingAt",
".",
"get",
"(",
"e",
")",
";",
"// new edge sum is the source sum times the edge weight",
"double",
"newEdgeSum",
"=",
"currentSums",
".",
"getEntry",
"(",
"s",
")",
"*",
"g",
".",
"getWeight",
"(",
"e",
")",
";",
"// new target sum is the old target sum plus the difference between",
"// the new and old edge sums",
"double",
"newTargetSum",
"=",
"oldTargetSum",
"+",
"(",
"newEdgeSum",
"-",
"oldEdgeSum",
")",
";",
"// the new total is the old total plus the difference in new and",
"// target",
"double",
"newTotal",
"=",
"currentTotal",
"+",
"(",
"newTargetSum",
"-",
"oldTargetSum",
")",
"*",
"endWeights",
".",
"getEntry",
"(",
"t",
")",
";",
"// store the new sums",
"prefixWeightsEndingAt",
".",
"put",
"(",
"e",
",",
"newEdgeSum",
")",
";",
"currentSums",
".",
"setEntry",
"(",
"t",
",",
"newTargetSum",
")",
";",
"currentTotal",
"=",
"newTotal",
";",
"// and report the new total to the consumer",
"if",
"(",
"c",
"!=",
"null",
")",
"{",
"c",
".",
"accept",
"(",
"currentTotal",
")",
";",
"}",
"}",
"return",
"currentTotal",
";",
"}"
] |
Computes the approximate sum of paths through the graph where the weight
of each path is the product of edge weights along the path;
If consumer c is not null, it will be given the intermediate estimates as
they are available
|
[
"Computes",
"the",
"approximate",
"sum",
"of",
"paths",
"through",
"the",
"graph",
"where",
"the",
"weight",
"of",
"each",
"path",
"is",
"the",
"product",
"of",
"edge",
"weights",
"along",
"the",
"path",
";"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/sch/tasks/SumPaths.java#L170-L213
|
12,205
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/hash/MurmurHash.java
|
MurmurHash.hash32
|
public static int hash32(final long data, int seed) {
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
final int m = 0x5bd1e995;
final int r = 24;
// Initialize the hash to a random value
final int length = 8;
int h = seed^length;
for (int i=0; i<2; i++) {
int k = (i==0) ? (int) (data & 0xffffffffL) : (int) ((data >>> 32) & 0xffffffffL);
k *= m;
k ^= k >>> r;
k *= m;
h *= m;
h ^= k;
}
h ^= h >>> 13;
h *= m;
h ^= h >>> 15;
return h;
}
|
java
|
public static int hash32(final long data, int seed) {
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
final int m = 0x5bd1e995;
final int r = 24;
// Initialize the hash to a random value
final int length = 8;
int h = seed^length;
for (int i=0; i<2; i++) {
int k = (i==0) ? (int) (data & 0xffffffffL) : (int) ((data >>> 32) & 0xffffffffL);
k *= m;
k ^= k >>> r;
k *= m;
h *= m;
h ^= k;
}
h ^= h >>> 13;
h *= m;
h ^= h >>> 15;
return h;
}
|
[
"public",
"static",
"int",
"hash32",
"(",
"final",
"long",
"data",
",",
"int",
"seed",
")",
"{",
"// 'm' and 'r' are mixing constants generated offline.",
"// They're not really 'magic', they just happen to work well.",
"final",
"int",
"m",
"=",
"0x5bd1e995",
";",
"final",
"int",
"r",
"=",
"24",
";",
"// Initialize the hash to a random value",
"final",
"int",
"length",
"=",
"8",
";",
"int",
"h",
"=",
"seed",
"^",
"length",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"2",
";",
"i",
"++",
")",
"{",
"int",
"k",
"=",
"(",
"i",
"==",
"0",
")",
"?",
"(",
"int",
")",
"(",
"data",
"&",
"0xffffffff",
"L",
")",
":",
"(",
"int",
")",
"(",
"(",
"data",
">>>",
"32",
")",
"&",
"0xffffffff",
"L",
")",
";",
"k",
"*=",
"m",
";",
"k",
"^=",
"k",
">>>",
"r",
";",
"k",
"*=",
"m",
";",
"h",
"*=",
"m",
";",
"h",
"^=",
"k",
";",
"}",
"h",
"^=",
"h",
">>>",
"13",
";",
"h",
"*=",
"m",
";",
"h",
"^=",
"h",
">>>",
"15",
";",
"return",
"h",
";",
"}"
] |
My conversion of MurmurHash to take a long as input.
|
[
"My",
"conversion",
"of",
"MurmurHash",
"to",
"take",
"a",
"long",
"as",
"input",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/hash/MurmurHash.java#L38-L62
|
12,206
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/vartensor/LazyVarTensor.java
|
LazyVarTensor.ensureVarTensor
|
private void ensureVarTensor() {
if (vt == null) {
log.warn("Generating VarTensor for a GlobalFactor. This should only ever be done during testing.");
vt = BruteForceInferencer.safeNewVarTensor(s, f);
if (fillVal != null) {
vt.fill(fillVal);
}
}
}
|
java
|
private void ensureVarTensor() {
if (vt == null) {
log.warn("Generating VarTensor for a GlobalFactor. This should only ever be done during testing.");
vt = BruteForceInferencer.safeNewVarTensor(s, f);
if (fillVal != null) {
vt.fill(fillVal);
}
}
}
|
[
"private",
"void",
"ensureVarTensor",
"(",
")",
"{",
"if",
"(",
"vt",
"==",
"null",
")",
"{",
"log",
".",
"warn",
"(",
"\"Generating VarTensor for a GlobalFactor. This should only ever be done during testing.\"",
")",
";",
"vt",
"=",
"BruteForceInferencer",
".",
"safeNewVarTensor",
"(",
"s",
",",
"f",
")",
";",
"if",
"(",
"fillVal",
"!=",
"null",
")",
"{",
"vt",
".",
"fill",
"(",
"fillVal",
")",
";",
"}",
"}",
"}"
] |
Ensures that the VarTensor is loaded.
|
[
"Ensures",
"that",
"the",
"VarTensor",
"is",
"loaded",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/vartensor/LazyVarTensor.java#L63-L71
|
12,207
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/ServerUserEventHandler.java
|
ServerUserEventHandler.checkUserAgent
|
protected Object checkUserAgent(ServerUserHandlerClass handler, ApiUser userAgent) {
if(handler.getUserClass().isAssignableFrom(userAgent.getClass()))
return userAgent;
return UserAgentUtil.getGameUser(userAgent, handler.getUserClass());
}
|
java
|
protected Object checkUserAgent(ServerUserHandlerClass handler, ApiUser userAgent) {
if(handler.getUserClass().isAssignableFrom(userAgent.getClass()))
return userAgent;
return UserAgentUtil.getGameUser(userAgent, handler.getUserClass());
}
|
[
"protected",
"Object",
"checkUserAgent",
"(",
"ServerUserHandlerClass",
"handler",
",",
"ApiUser",
"userAgent",
")",
"{",
"if",
"(",
"handler",
".",
"getUserClass",
"(",
")",
".",
"isAssignableFrom",
"(",
"userAgent",
".",
"getClass",
"(",
")",
")",
")",
"return",
"userAgent",
";",
"return",
"UserAgentUtil",
".",
"getGameUser",
"(",
"userAgent",
",",
"handler",
".",
"getUserClass",
"(",
")",
")",
";",
"}"
] |
Check whether context of user agent is application or game
@param handler structure of handler
@param userAgent user agent object
@return user agent or game user agent object
|
[
"Check",
"whether",
"context",
"of",
"user",
"agent",
"is",
"application",
"or",
"game"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/ServerUserEventHandler.java#L48-L52
|
12,208
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/hypergraph/Hyperedge.java
|
Hyperedge.getLabel
|
public String getLabel() {
if (label == null) {
// Lazily construct an edge label from the head and tail nodes.
StringBuilder label = new StringBuilder();
label.append(headNode.getLabel());
label.append("<--");
for (Hypernode tailNode : tailNodes) {
label.append(tailNode.getLabel());
label.append(",");
}
if (tailNodes.length > 0) {
label.deleteCharAt(label.length()-1);
}
return label.toString();
}
return label;
}
|
java
|
public String getLabel() {
if (label == null) {
// Lazily construct an edge label from the head and tail nodes.
StringBuilder label = new StringBuilder();
label.append(headNode.getLabel());
label.append("<--");
for (Hypernode tailNode : tailNodes) {
label.append(tailNode.getLabel());
label.append(",");
}
if (tailNodes.length > 0) {
label.deleteCharAt(label.length()-1);
}
return label.toString();
}
return label;
}
|
[
"public",
"String",
"getLabel",
"(",
")",
"{",
"if",
"(",
"label",
"==",
"null",
")",
"{",
"// Lazily construct an edge label from the head and tail nodes.",
"StringBuilder",
"label",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"label",
".",
"append",
"(",
"headNode",
".",
"getLabel",
"(",
")",
")",
";",
"label",
".",
"append",
"(",
"\"<--\"",
")",
";",
"for",
"(",
"Hypernode",
"tailNode",
":",
"tailNodes",
")",
"{",
"label",
".",
"append",
"(",
"tailNode",
".",
"getLabel",
"(",
")",
")",
";",
"label",
".",
"append",
"(",
"\",\"",
")",
";",
"}",
"if",
"(",
"tailNodes",
".",
"length",
">",
"0",
")",
"{",
"label",
".",
"deleteCharAt",
"(",
"label",
".",
"length",
"(",
")",
"-",
"1",
")",
";",
"}",
"return",
"label",
".",
"toString",
"(",
")",
";",
"}",
"return",
"label",
";",
"}"
] |
Gets a name for this edge.
|
[
"Gets",
"a",
"name",
"for",
"this",
"edge",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/hypergraph/Hyperedge.java#L41-L57
|
12,209
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/util/AgentUtil.java
|
AgentUtil.getUserAgent
|
public static ApiUser getUserAgent(User sfsUser) {
Object userAgent = sfsUser.getProperty(APIKey.USER);
if(userAgent == null)
throw new RuntimeException("Can not get user agent");
return (ApiUser)userAgent;
}
|
java
|
public static ApiUser getUserAgent(User sfsUser) {
Object userAgent = sfsUser.getProperty(APIKey.USER);
if(userAgent == null)
throw new RuntimeException("Can not get user agent");
return (ApiUser)userAgent;
}
|
[
"public",
"static",
"ApiUser",
"getUserAgent",
"(",
"User",
"sfsUser",
")",
"{",
"Object",
"userAgent",
"=",
"sfsUser",
".",
"getProperty",
"(",
"APIKey",
".",
"USER",
")",
";",
"if",
"(",
"userAgent",
"==",
"null",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"Can not get user agent\"",
")",
";",
"return",
"(",
"ApiUser",
")",
"userAgent",
";",
"}"
] |
Get user agent object mapped to smartfox user object
@param sfsUser smartfox user object
@return user agent object
|
[
"Get",
"user",
"agent",
"object",
"mapped",
"to",
"smartfox",
"user",
"object"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/util/AgentUtil.java#L27-L32
|
12,210
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/util/AgentUtil.java
|
AgentUtil.getRoomAgent
|
public static ApiRoom getRoomAgent(Room sfsRoom) {
Object roomAgent = sfsRoom.getProperty(APIKey.ROOM);
if(roomAgent == null)
throw new RuntimeException("Can not get user agent");
return (ApiRoom)roomAgent;
}
|
java
|
public static ApiRoom getRoomAgent(Room sfsRoom) {
Object roomAgent = sfsRoom.getProperty(APIKey.ROOM);
if(roomAgent == null)
throw new RuntimeException("Can not get user agent");
return (ApiRoom)roomAgent;
}
|
[
"public",
"static",
"ApiRoom",
"getRoomAgent",
"(",
"Room",
"sfsRoom",
")",
"{",
"Object",
"roomAgent",
"=",
"sfsRoom",
".",
"getProperty",
"(",
"APIKey",
".",
"ROOM",
")",
";",
"if",
"(",
"roomAgent",
"==",
"null",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"Can not get user agent\"",
")",
";",
"return",
"(",
"ApiRoom",
")",
"roomAgent",
";",
"}"
] |
Get room agent object mapped to smartfox room object
@param sfsRoom smartfox room object
@return room agent object
|
[
"Get",
"room",
"agent",
"object",
"mapped",
"to",
"smartfox",
"room",
"object"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/util/AgentUtil.java#L40-L45
|
12,211
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/collections/QMaps.java
|
QMaps.zip
|
public static <X,Y> Map<X,Y> zip(List<X> keys, List<Y> values) {
if (keys.size() != values.size()) {
throw new IllegalArgumentException("Lengths are not equal");
}
Map<X,Y> map = new HashMap<>(keys.size());
for (int i=0; i<keys.size(); i++) {
map.put(keys.get(i), values.get(i));
}
return map;
}
|
java
|
public static <X,Y> Map<X,Y> zip(List<X> keys, List<Y> values) {
if (keys.size() != values.size()) {
throw new IllegalArgumentException("Lengths are not equal");
}
Map<X,Y> map = new HashMap<>(keys.size());
for (int i=0; i<keys.size(); i++) {
map.put(keys.get(i), values.get(i));
}
return map;
}
|
[
"public",
"static",
"<",
"X",
",",
"Y",
">",
"Map",
"<",
"X",
",",
"Y",
">",
"zip",
"(",
"List",
"<",
"X",
">",
"keys",
",",
"List",
"<",
"Y",
">",
"values",
")",
"{",
"if",
"(",
"keys",
".",
"size",
"(",
")",
"!=",
"values",
".",
"size",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Lengths are not equal\"",
")",
";",
"}",
"Map",
"<",
"X",
",",
"Y",
">",
"map",
"=",
"new",
"HashMap",
"<>",
"(",
"keys",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"map",
".",
"put",
"(",
"keys",
".",
"get",
"(",
"i",
")",
",",
"values",
".",
"get",
"(",
"i",
")",
")",
";",
"}",
"return",
"map",
";",
"}"
] |
Like Python's zip, this creates a map by zipping together the key and values lists.
|
[
"Like",
"Python",
"s",
"zip",
"this",
"creates",
"a",
"map",
"by",
"zipping",
"together",
"the",
"key",
"and",
"values",
"lists",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/collections/QMaps.java#L166-L175
|
12,212
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/feat/ObsFeatureConjoiner.java
|
ObsFeatureConjoiner.extractAllFeats
|
private void extractAllFeats(FgExampleList data, FactorTemplateList templates) {
// Create a "no-op" counter.
IFgModel counts = new IFgModel() {
@Override
public void addAfterScaling(FeatureVector fv, double multiplier) { }
@Override
public void add(int feat, double addend) { }
};
// Loop over all factors in the dataset.
for (int i=0; i<data.size(); i++) {
if (i % 1000 == 0) {
log.debug("Processing example: " + i);
}
LFgExample ex = data.get(i);
FactorGraph fgLat = MarginalLogLikelihood.getFgLat(ex.getFactorGraph(), ex.getGoldConfig());
// Create a "no-op" inferencer, which returns arbitrary marginals.
NoOpInferencer inferencer = new NoOpInferencer(ex.getFactorGraph());
for (int a=0; a<ex.getFactorGraph().getNumFactors(); a++) {
Factor f = fgLat.getFactor(a);
if (f instanceof ObsFeatureCarrier && f instanceof TemplateFactor) {
// For each observation function extractor.
int t = templates.getTemplateId((TemplateFactor) f);
if (t != -1) {
((ObsFeatureCarrier) f).getObsFeatures();
}
} else {
// For each standard factor.
f = ex.getFactorGraph().getFactor(a);
if (f instanceof GlobalFactor) {
((GlobalFactor) f).addExpectedPartials(counts, 0, inferencer, a);
} else {
VarTensor marg = inferencer.getMarginalsForFactorId(a);
f.addExpectedPartials(counts, marg, 0);
}
}
}
}
}
|
java
|
private void extractAllFeats(FgExampleList data, FactorTemplateList templates) {
// Create a "no-op" counter.
IFgModel counts = new IFgModel() {
@Override
public void addAfterScaling(FeatureVector fv, double multiplier) { }
@Override
public void add(int feat, double addend) { }
};
// Loop over all factors in the dataset.
for (int i=0; i<data.size(); i++) {
if (i % 1000 == 0) {
log.debug("Processing example: " + i);
}
LFgExample ex = data.get(i);
FactorGraph fgLat = MarginalLogLikelihood.getFgLat(ex.getFactorGraph(), ex.getGoldConfig());
// Create a "no-op" inferencer, which returns arbitrary marginals.
NoOpInferencer inferencer = new NoOpInferencer(ex.getFactorGraph());
for (int a=0; a<ex.getFactorGraph().getNumFactors(); a++) {
Factor f = fgLat.getFactor(a);
if (f instanceof ObsFeatureCarrier && f instanceof TemplateFactor) {
// For each observation function extractor.
int t = templates.getTemplateId((TemplateFactor) f);
if (t != -1) {
((ObsFeatureCarrier) f).getObsFeatures();
}
} else {
// For each standard factor.
f = ex.getFactorGraph().getFactor(a);
if (f instanceof GlobalFactor) {
((GlobalFactor) f).addExpectedPartials(counts, 0, inferencer, a);
} else {
VarTensor marg = inferencer.getMarginalsForFactorId(a);
f.addExpectedPartials(counts, marg, 0);
}
}
}
}
}
|
[
"private",
"void",
"extractAllFeats",
"(",
"FgExampleList",
"data",
",",
"FactorTemplateList",
"templates",
")",
"{",
"// Create a \"no-op\" counter.",
"IFgModel",
"counts",
"=",
"new",
"IFgModel",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"addAfterScaling",
"(",
"FeatureVector",
"fv",
",",
"double",
"multiplier",
")",
"{",
"}",
"@",
"Override",
"public",
"void",
"add",
"(",
"int",
"feat",
",",
"double",
"addend",
")",
"{",
"}",
"}",
";",
"// Loop over all factors in the dataset. ",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"data",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"%",
"1000",
"==",
"0",
")",
"{",
"log",
".",
"debug",
"(",
"\"Processing example: \"",
"+",
"i",
")",
";",
"}",
"LFgExample",
"ex",
"=",
"data",
".",
"get",
"(",
"i",
")",
";",
"FactorGraph",
"fgLat",
"=",
"MarginalLogLikelihood",
".",
"getFgLat",
"(",
"ex",
".",
"getFactorGraph",
"(",
")",
",",
"ex",
".",
"getGoldConfig",
"(",
")",
")",
";",
"// Create a \"no-op\" inferencer, which returns arbitrary marginals.",
"NoOpInferencer",
"inferencer",
"=",
"new",
"NoOpInferencer",
"(",
"ex",
".",
"getFactorGraph",
"(",
")",
")",
";",
"for",
"(",
"int",
"a",
"=",
"0",
";",
"a",
"<",
"ex",
".",
"getFactorGraph",
"(",
")",
".",
"getNumFactors",
"(",
")",
";",
"a",
"++",
")",
"{",
"Factor",
"f",
"=",
"fgLat",
".",
"getFactor",
"(",
"a",
")",
";",
"if",
"(",
"f",
"instanceof",
"ObsFeatureCarrier",
"&&",
"f",
"instanceof",
"TemplateFactor",
")",
"{",
"// For each observation function extractor.",
"int",
"t",
"=",
"templates",
".",
"getTemplateId",
"(",
"(",
"TemplateFactor",
")",
"f",
")",
";",
"if",
"(",
"t",
"!=",
"-",
"1",
")",
"{",
"(",
"(",
"ObsFeatureCarrier",
")",
"f",
")",
".",
"getObsFeatures",
"(",
")",
";",
"}",
"}",
"else",
"{",
"// For each standard factor. ",
"f",
"=",
"ex",
".",
"getFactorGraph",
"(",
")",
".",
"getFactor",
"(",
"a",
")",
";",
"if",
"(",
"f",
"instanceof",
"GlobalFactor",
")",
"{",
"(",
"(",
"GlobalFactor",
")",
"f",
")",
".",
"addExpectedPartials",
"(",
"counts",
",",
"0",
",",
"inferencer",
",",
"a",
")",
";",
"}",
"else",
"{",
"VarTensor",
"marg",
"=",
"inferencer",
".",
"getMarginalsForFactorId",
"(",
"a",
")",
";",
"f",
".",
"addExpectedPartials",
"(",
"counts",
",",
"marg",
",",
"0",
")",
";",
"}",
"}",
"}",
"}",
"}"
] |
Loops through all examples to create the features, thereby ensuring that the FTS are initialized.
|
[
"Loops",
"through",
"all",
"examples",
"to",
"create",
"the",
"features",
"thereby",
"ensuring",
"that",
"the",
"FTS",
"are",
"initialized",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/feat/ObsFeatureConjoiner.java#L224-L262
|
12,213
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/feat/ObsFeatureConjoiner.java
|
ObsFeatureConjoiner.countFeatures
|
private IntIntDenseVector[][] countFeatures(FgExampleList data, FactorTemplateList templates) {
IntIntDenseVector[][] counts = new IntIntDenseVector[numTemplates][];
for (int t=0; t<numTemplates; t++) {
FactorTemplate template = templates.get(t);
int numConfigs = template.getNumConfigs();
int numFeats = template.getAlphabet().size();
counts[t] = new IntIntDenseVector[numConfigs];
for (int c=0; c<numConfigs; c++) {
counts[t][c] = new IntIntDenseVector(numFeats);
}
}
for (int i=0; i<data.size(); i++) {
LFgExample ex = data.get(i);
FactorGraph fg = ex.getFactorGraph();
for (int a=0; a<ex.getFactorGraph().getNumFactors(); a++) {
Factor f = fg.getFactor(a);
if (f instanceof ObsFeatureCarrier && f instanceof TemplateFactor) {
int t = templates.getTemplateId((TemplateFactor) f);
if (t != -1) {
FeatureVector fv = ((ObsFeatureCarrier) f).getObsFeatures();
// We must clamp the predicted variables and loop over the latent ones.
VarConfig predVc = ex.getGoldConfigPred(a);
IntIter iter = IndexForVc.getConfigIter(ex.getFactorGraph().getFactor(a).getVars(), predVc);
while (iter.hasNext()) {
// The configuration of all the latent/predicted variables,
// where the predicted variables have been clamped.
int config = iter.next();
for (IntDoubleEntry entry : fv) {
counts[t][config].add(entry.index(), 1);
}
}
}
}
}
}
return counts;
}
|
java
|
private IntIntDenseVector[][] countFeatures(FgExampleList data, FactorTemplateList templates) {
IntIntDenseVector[][] counts = new IntIntDenseVector[numTemplates][];
for (int t=0; t<numTemplates; t++) {
FactorTemplate template = templates.get(t);
int numConfigs = template.getNumConfigs();
int numFeats = template.getAlphabet().size();
counts[t] = new IntIntDenseVector[numConfigs];
for (int c=0; c<numConfigs; c++) {
counts[t][c] = new IntIntDenseVector(numFeats);
}
}
for (int i=0; i<data.size(); i++) {
LFgExample ex = data.get(i);
FactorGraph fg = ex.getFactorGraph();
for (int a=0; a<ex.getFactorGraph().getNumFactors(); a++) {
Factor f = fg.getFactor(a);
if (f instanceof ObsFeatureCarrier && f instanceof TemplateFactor) {
int t = templates.getTemplateId((TemplateFactor) f);
if (t != -1) {
FeatureVector fv = ((ObsFeatureCarrier) f).getObsFeatures();
// We must clamp the predicted variables and loop over the latent ones.
VarConfig predVc = ex.getGoldConfigPred(a);
IntIter iter = IndexForVc.getConfigIter(ex.getFactorGraph().getFactor(a).getVars(), predVc);
while (iter.hasNext()) {
// The configuration of all the latent/predicted variables,
// where the predicted variables have been clamped.
int config = iter.next();
for (IntDoubleEntry entry : fv) {
counts[t][config].add(entry.index(), 1);
}
}
}
}
}
}
return counts;
}
|
[
"private",
"IntIntDenseVector",
"[",
"]",
"[",
"]",
"countFeatures",
"(",
"FgExampleList",
"data",
",",
"FactorTemplateList",
"templates",
")",
"{",
"IntIntDenseVector",
"[",
"]",
"[",
"]",
"counts",
"=",
"new",
"IntIntDenseVector",
"[",
"numTemplates",
"]",
"[",
"",
"]",
";",
"for",
"(",
"int",
"t",
"=",
"0",
";",
"t",
"<",
"numTemplates",
";",
"t",
"++",
")",
"{",
"FactorTemplate",
"template",
"=",
"templates",
".",
"get",
"(",
"t",
")",
";",
"int",
"numConfigs",
"=",
"template",
".",
"getNumConfigs",
"(",
")",
";",
"int",
"numFeats",
"=",
"template",
".",
"getAlphabet",
"(",
")",
".",
"size",
"(",
")",
";",
"counts",
"[",
"t",
"]",
"=",
"new",
"IntIntDenseVector",
"[",
"numConfigs",
"]",
";",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"numConfigs",
";",
"c",
"++",
")",
"{",
"counts",
"[",
"t",
"]",
"[",
"c",
"]",
"=",
"new",
"IntIntDenseVector",
"(",
"numFeats",
")",
";",
"}",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"data",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"LFgExample",
"ex",
"=",
"data",
".",
"get",
"(",
"i",
")",
";",
"FactorGraph",
"fg",
"=",
"ex",
".",
"getFactorGraph",
"(",
")",
";",
"for",
"(",
"int",
"a",
"=",
"0",
";",
"a",
"<",
"ex",
".",
"getFactorGraph",
"(",
")",
".",
"getNumFactors",
"(",
")",
";",
"a",
"++",
")",
"{",
"Factor",
"f",
"=",
"fg",
".",
"getFactor",
"(",
"a",
")",
";",
"if",
"(",
"f",
"instanceof",
"ObsFeatureCarrier",
"&&",
"f",
"instanceof",
"TemplateFactor",
")",
"{",
"int",
"t",
"=",
"templates",
".",
"getTemplateId",
"(",
"(",
"TemplateFactor",
")",
"f",
")",
";",
"if",
"(",
"t",
"!=",
"-",
"1",
")",
"{",
"FeatureVector",
"fv",
"=",
"(",
"(",
"ObsFeatureCarrier",
")",
"f",
")",
".",
"getObsFeatures",
"(",
")",
";",
"// We must clamp the predicted variables and loop over the latent ones.",
"VarConfig",
"predVc",
"=",
"ex",
".",
"getGoldConfigPred",
"(",
"a",
")",
";",
"IntIter",
"iter",
"=",
"IndexForVc",
".",
"getConfigIter",
"(",
"ex",
".",
"getFactorGraph",
"(",
")",
".",
"getFactor",
"(",
"a",
")",
".",
"getVars",
"(",
")",
",",
"predVc",
")",
";",
"while",
"(",
"iter",
".",
"hasNext",
"(",
")",
")",
"{",
"// The configuration of all the latent/predicted variables,",
"// where the predicted variables have been clamped.",
"int",
"config",
"=",
"iter",
".",
"next",
"(",
")",
";",
"for",
"(",
"IntDoubleEntry",
"entry",
":",
"fv",
")",
"{",
"counts",
"[",
"t",
"]",
"[",
"config",
"]",
".",
"add",
"(",
"entry",
".",
"index",
"(",
")",
",",
"1",
")",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"return",
"counts",
";",
"}"
] |
Counts the number of times each feature appears in the gold training data.
|
[
"Counts",
"the",
"number",
"of",
"times",
"each",
"feature",
"appears",
"in",
"the",
"gold",
"training",
"data",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/feat/ObsFeatureConjoiner.java#L267-L303
|
12,214
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/BuddyEventHandler.java
|
BuddyEventHandler.notifyToHandler
|
protected void notifyToHandler(ServerHandlerClass handler,
ApiZone zone, ApiBuddyImpl buddy) {
ReflectMethodUtil.invokeHandleMethod(
handler.getHandleMethod(),
handler.newInstance(),
context, zone, buddy);
}
|
java
|
protected void notifyToHandler(ServerHandlerClass handler,
ApiZone zone, ApiBuddyImpl buddy) {
ReflectMethodUtil.invokeHandleMethod(
handler.getHandleMethod(),
handler.newInstance(),
context, zone, buddy);
}
|
[
"protected",
"void",
"notifyToHandler",
"(",
"ServerHandlerClass",
"handler",
",",
"ApiZone",
"zone",
",",
"ApiBuddyImpl",
"buddy",
")",
"{",
"ReflectMethodUtil",
".",
"invokeHandleMethod",
"(",
"handler",
".",
"getHandleMethod",
"(",
")",
",",
"handler",
".",
"newInstance",
"(",
")",
",",
"context",
",",
"zone",
",",
"buddy",
")",
";",
"}"
] |
Notify event to handler
@param handler structure of handler class
@param zone api zone reference
@param buddy api buddy reference
|
[
"Notify",
"event",
"to",
"handler"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/BuddyEventHandler.java#L73-L79
|
12,215
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/VTensor.java
|
VTensor.checkIndices
|
private void checkIndices(int... indices) {
if (indices.length != dims.length) {
throw new IllegalArgumentException(String.format(
"Indices array is not the correct length. expected=%d actual=%d",
indices.length, dims.length));
}
for (int i=0; i<indices.length; i++) {
if (indices[i] < 0 || dims[i] <= indices[i]) {
throw new IllegalArgumentException(String.format(
"Indices array contains an index that is out of bounds: i=%d index=%d",
i, indices[i]));
}
}
}
|
java
|
private void checkIndices(int... indices) {
if (indices.length != dims.length) {
throw new IllegalArgumentException(String.format(
"Indices array is not the correct length. expected=%d actual=%d",
indices.length, dims.length));
}
for (int i=0; i<indices.length; i++) {
if (indices[i] < 0 || dims[i] <= indices[i]) {
throw new IllegalArgumentException(String.format(
"Indices array contains an index that is out of bounds: i=%d index=%d",
i, indices[i]));
}
}
}
|
[
"private",
"void",
"checkIndices",
"(",
"int",
"...",
"indices",
")",
"{",
"if",
"(",
"indices",
".",
"length",
"!=",
"dims",
".",
"length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"format",
"(",
"\"Indices array is not the correct length. expected=%d actual=%d\"",
",",
"indices",
".",
"length",
",",
"dims",
".",
"length",
")",
")",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"indices",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"indices",
"[",
"i",
"]",
"<",
"0",
"||",
"dims",
"[",
"i",
"]",
"<=",
"indices",
"[",
"i",
"]",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"format",
"(",
"\"Indices array contains an index that is out of bounds: i=%d index=%d\"",
",",
"i",
",",
"indices",
"[",
"i",
"]",
")",
")",
";",
"}",
"}",
"}"
] |
Checks that the indices are valid.
|
[
"Checks",
"that",
"the",
"indices",
"are",
"valid",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/VTensor.java#L196-L209
|
12,216
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/VTensor.java
|
VTensor.getValuesAsNativeArray
|
public double[] getValuesAsNativeArray() {
double[] vs = new double[this.size()];
for (int c = 0; c < vs.length; c++) {
vs[c] = getValue(c);
}
return vs;
}
|
java
|
public double[] getValuesAsNativeArray() {
double[] vs = new double[this.size()];
for (int c = 0; c < vs.length; c++) {
vs[c] = getValue(c);
}
return vs;
}
|
[
"public",
"double",
"[",
"]",
"getValuesAsNativeArray",
"(",
")",
"{",
"double",
"[",
"]",
"vs",
"=",
"new",
"double",
"[",
"this",
".",
"size",
"(",
")",
"]",
";",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"vs",
".",
"length",
";",
"c",
"++",
")",
"{",
"vs",
"[",
"c",
"]",
"=",
"getValue",
"(",
"c",
")",
";",
"}",
"return",
"vs",
";",
"}"
] |
Gets a copy of the internal values as a native array.
|
[
"Gets",
"a",
"copy",
"of",
"the",
"internal",
"values",
"as",
"a",
"native",
"array",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/VTensor.java#L627-L633
|
12,217
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/VTensor.java
|
VTensor.combine
|
public static VTensor combine(VTensor t1, VTensor t2) {
checkSameDims(t1, t2);
checkSameAlgebra(t1, t2);
int[] dims3 = IntArrays.insertEntry(t1.getDims(), 0, 2);
VTensor y = new VTensor(t1.s, dims3);
y.addTensor(t1, 0, 0);
y.addTensor(t2, 0, 1);
return y;
}
|
java
|
public static VTensor combine(VTensor t1, VTensor t2) {
checkSameDims(t1, t2);
checkSameAlgebra(t1, t2);
int[] dims3 = IntArrays.insertEntry(t1.getDims(), 0, 2);
VTensor y = new VTensor(t1.s, dims3);
y.addTensor(t1, 0, 0);
y.addTensor(t2, 0, 1);
return y;
}
|
[
"public",
"static",
"VTensor",
"combine",
"(",
"VTensor",
"t1",
",",
"VTensor",
"t2",
")",
"{",
"checkSameDims",
"(",
"t1",
",",
"t2",
")",
";",
"checkSameAlgebra",
"(",
"t1",
",",
"t2",
")",
";",
"int",
"[",
"]",
"dims3",
"=",
"IntArrays",
".",
"insertEntry",
"(",
"t1",
".",
"getDims",
"(",
")",
",",
"0",
",",
"2",
")",
";",
"VTensor",
"y",
"=",
"new",
"VTensor",
"(",
"t1",
".",
"s",
",",
"dims3",
")",
";",
"y",
".",
"addTensor",
"(",
"t1",
",",
"0",
",",
"0",
")",
";",
"y",
".",
"addTensor",
"(",
"t2",
",",
"0",
",",
"1",
")",
";",
"return",
"y",
";",
"}"
] |
Combines two identically sized tensors by adding an initial dimension of size 2.
@param t1 The first tensor to add.
@param t2 The second tensor to add.
@return The combined tensor.
|
[
"Combines",
"two",
"identically",
"sized",
"tensors",
"by",
"adding",
"an",
"initial",
"dimension",
"of",
"size",
"2",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/VTensor.java#L668-L677
|
12,218
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/train/DepTensorFromBeliefs.java
|
DepTensorFromBeliefs.guessNumWords
|
static int guessNumWords(Beliefs b) {
int n = -1;
for (int v=0; v<b.varBeliefs.length; v++) {
Var var = b.varBeliefs[v].getVars().get(0);
if (var instanceof LinkVar) {
LinkVar link = (LinkVar) var;
int p = link.getParent();
int c = link.getChild();
n = Math.max(n, Math.max(p, c));
}
}
return n+1;
}
|
java
|
static int guessNumWords(Beliefs b) {
int n = -1;
for (int v=0; v<b.varBeliefs.length; v++) {
Var var = b.varBeliefs[v].getVars().get(0);
if (var instanceof LinkVar) {
LinkVar link = (LinkVar) var;
int p = link.getParent();
int c = link.getChild();
n = Math.max(n, Math.max(p, c));
}
}
return n+1;
}
|
[
"static",
"int",
"guessNumWords",
"(",
"Beliefs",
"b",
")",
"{",
"int",
"n",
"=",
"-",
"1",
";",
"for",
"(",
"int",
"v",
"=",
"0",
";",
"v",
"<",
"b",
".",
"varBeliefs",
".",
"length",
";",
"v",
"++",
")",
"{",
"Var",
"var",
"=",
"b",
".",
"varBeliefs",
"[",
"v",
"]",
".",
"getVars",
"(",
")",
".",
"get",
"(",
"0",
")",
";",
"if",
"(",
"var",
"instanceof",
"LinkVar",
")",
"{",
"LinkVar",
"link",
"=",
"(",
"LinkVar",
")",
"var",
";",
"int",
"p",
"=",
"link",
".",
"getParent",
"(",
")",
";",
"int",
"c",
"=",
"link",
".",
"getChild",
"(",
")",
";",
"n",
"=",
"Math",
".",
"max",
"(",
"n",
",",
"Math",
".",
"max",
"(",
"p",
",",
"c",
")",
")",
";",
"}",
"}",
"return",
"n",
"+",
"1",
";",
"}"
] |
Gets the maximum index of a parent or child in a LinkVar, plus one.
|
[
"Gets",
"the",
"maximum",
"index",
"of",
"a",
"parent",
"or",
"child",
"in",
"a",
"LinkVar",
"plus",
"one",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/train/DepTensorFromBeliefs.java#L74-L86
|
12,219
|
jeffreyning/nh-micro
|
nh-micro-template/src/main/java/com/nh/micro/template/MicroServiceTemplateSupport.java
|
MicroServiceTemplateSupport.getSingleInfoServiceByRep
|
public Map getSingleInfoServiceByRep(String sql,Map requestParamMap) throws Exception{
List placeList=new ArrayList();
sqlTemplateService(sql,requestParamMap,placeList);
String realSql=sqlTemplateService(sql,requestParamMap,placeList);;
Map retMap= getInnerDao().querySingleObjJoinByCondition(realSql,placeList.toArray());
CheckModelTypeUtil.addMetaCols(retMap);
CheckModelTypeUtil.changeNoStrCols(retMap);
return retMap;
}
|
java
|
public Map getSingleInfoServiceByRep(String sql,Map requestParamMap) throws Exception{
List placeList=new ArrayList();
sqlTemplateService(sql,requestParamMap,placeList);
String realSql=sqlTemplateService(sql,requestParamMap,placeList);;
Map retMap= getInnerDao().querySingleObjJoinByCondition(realSql,placeList.toArray());
CheckModelTypeUtil.addMetaCols(retMap);
CheckModelTypeUtil.changeNoStrCols(retMap);
return retMap;
}
|
[
"public",
"Map",
"getSingleInfoServiceByRep",
"(",
"String",
"sql",
",",
"Map",
"requestParamMap",
")",
"throws",
"Exception",
"{",
"List",
"placeList",
"=",
"new",
"ArrayList",
"(",
")",
";",
"sqlTemplateService",
"(",
"sql",
",",
"requestParamMap",
",",
"placeList",
")",
";",
"String",
"realSql",
"=",
"sqlTemplateService",
"(",
"sql",
",",
"requestParamMap",
",",
"placeList",
")",
";",
";",
"Map",
"retMap",
"=",
"getInnerDao",
"(",
")",
".",
"querySingleObjJoinByCondition",
"(",
"realSql",
",",
"placeList",
".",
"toArray",
"(",
")",
")",
";",
"CheckModelTypeUtil",
".",
"addMetaCols",
"(",
"retMap",
")",
";",
"CheckModelTypeUtil",
".",
"changeNoStrCols",
"(",
"retMap",
")",
";",
"return",
"retMap",
";",
"}"
] |
add 20190430 by ning
|
[
"add",
"20190430",
"by",
"ning"
] |
f1cb420a092f8ba94317519ede739974decb5617
|
https://github.com/jeffreyning/nh-micro/blob/f1cb420a092f8ba94317519ede739974decb5617/nh-micro-template/src/main/java/com/nh/micro/template/MicroServiceTemplateSupport.java#L2182-L2190
|
12,220
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/globalfac/ConstituencyTreeFactor.java
|
ConstituencyTreeFactor.setOutMsgs
|
private void setOutMsgs(VarTensor outMsg, SpanVar span, double outMsgTrue, double outMsgFalse) {
// Set the outgoing messages.
Algebra s = outMsg.getAlgebra();
outMsg.setValue(SpanVar.FALSE, s.fromLogProb(outMsgFalse));
outMsg.setValue(SpanVar.TRUE, s.fromLogProb(outMsgTrue));
if (log.isTraceEnabled()) {
log.trace(String.format("outMsgTrue: %s = %.2f", span.getName(), outMsg.getValue(LinkVar.TRUE)));
log.trace(String.format("outMsgFalse: %s = %.2f", span.getName(), outMsg.getValue(LinkVar.FALSE)));
}
assert !outMsg.containsBadValues() : "message = " + outMsg;
}
|
java
|
private void setOutMsgs(VarTensor outMsg, SpanVar span, double outMsgTrue, double outMsgFalse) {
// Set the outgoing messages.
Algebra s = outMsg.getAlgebra();
outMsg.setValue(SpanVar.FALSE, s.fromLogProb(outMsgFalse));
outMsg.setValue(SpanVar.TRUE, s.fromLogProb(outMsgTrue));
if (log.isTraceEnabled()) {
log.trace(String.format("outMsgTrue: %s = %.2f", span.getName(), outMsg.getValue(LinkVar.TRUE)));
log.trace(String.format("outMsgFalse: %s = %.2f", span.getName(), outMsg.getValue(LinkVar.FALSE)));
}
assert !outMsg.containsBadValues() : "message = " + outMsg;
}
|
[
"private",
"void",
"setOutMsgs",
"(",
"VarTensor",
"outMsg",
",",
"SpanVar",
"span",
",",
"double",
"outMsgTrue",
",",
"double",
"outMsgFalse",
")",
"{",
"// Set the outgoing messages.",
"Algebra",
"s",
"=",
"outMsg",
".",
"getAlgebra",
"(",
")",
";",
"outMsg",
".",
"setValue",
"(",
"SpanVar",
".",
"FALSE",
",",
"s",
".",
"fromLogProb",
"(",
"outMsgFalse",
")",
")",
";",
"outMsg",
".",
"setValue",
"(",
"SpanVar",
".",
"TRUE",
",",
"s",
".",
"fromLogProb",
"(",
"outMsgTrue",
")",
")",
";",
"if",
"(",
"log",
".",
"isTraceEnabled",
"(",
")",
")",
"{",
"log",
".",
"trace",
"(",
"String",
".",
"format",
"(",
"\"outMsgTrue: %s = %.2f\"",
",",
"span",
".",
"getName",
"(",
")",
",",
"outMsg",
".",
"getValue",
"(",
"LinkVar",
".",
"TRUE",
")",
")",
")",
";",
"log",
".",
"trace",
"(",
"String",
".",
"format",
"(",
"\"outMsgFalse: %s = %.2f\"",
",",
"span",
".",
"getName",
"(",
")",
",",
"outMsg",
".",
"getValue",
"(",
"LinkVar",
".",
"FALSE",
")",
")",
")",
";",
"}",
"assert",
"!",
"outMsg",
".",
"containsBadValues",
"(",
")",
":",
"\"message = \"",
"+",
"outMsg",
";",
"}"
] |
Sets the outgoing messages.
|
[
"Sets",
"the",
"outgoing",
"messages",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/globalfac/ConstituencyTreeFactor.java#L310-L323
|
12,221
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/globalfac/ConstituencyTreeFactor.java
|
ConstituencyTreeFactor.getChart
|
private static boolean[][] getChart(int n, VarConfig vc) {
boolean[][] chart = new boolean[n][n+1];
int count = 0;
for (Var v : vc.getVars()) {
SpanVar span = (SpanVar) v;
chart[span.getStart()][span.getEnd()] = (vc.getState(span) == SpanVar.TRUE);
count++;
}
if (count != (n*(n+1)/2)) {
// We didn't see a span variable for every chart cell.
return null;
}
return chart;
}
|
java
|
private static boolean[][] getChart(int n, VarConfig vc) {
boolean[][] chart = new boolean[n][n+1];
int count = 0;
for (Var v : vc.getVars()) {
SpanVar span = (SpanVar) v;
chart[span.getStart()][span.getEnd()] = (vc.getState(span) == SpanVar.TRUE);
count++;
}
if (count != (n*(n+1)/2)) {
// We didn't see a span variable for every chart cell.
return null;
}
return chart;
}
|
[
"private",
"static",
"boolean",
"[",
"]",
"[",
"]",
"getChart",
"(",
"int",
"n",
",",
"VarConfig",
"vc",
")",
"{",
"boolean",
"[",
"]",
"[",
"]",
"chart",
"=",
"new",
"boolean",
"[",
"n",
"]",
"[",
"n",
"+",
"1",
"]",
";",
"int",
"count",
"=",
"0",
";",
"for",
"(",
"Var",
"v",
":",
"vc",
".",
"getVars",
"(",
")",
")",
"{",
"SpanVar",
"span",
"=",
"(",
"SpanVar",
")",
"v",
";",
"chart",
"[",
"span",
".",
"getStart",
"(",
")",
"]",
"[",
"span",
".",
"getEnd",
"(",
")",
"]",
"=",
"(",
"vc",
".",
"getState",
"(",
"span",
")",
"==",
"SpanVar",
".",
"TRUE",
")",
";",
"count",
"++",
";",
"}",
"if",
"(",
"count",
"!=",
"(",
"n",
"*",
"(",
"n",
"+",
"1",
")",
"/",
"2",
")",
")",
"{",
"// We didn't see a span variable for every chart cell.",
"return",
"null",
";",
"}",
"return",
"chart",
";",
"}"
] |
Creates a boolean chart representing the set of spans which are "on", or
null if the number of span variables in the assignment is invalid.
|
[
"Creates",
"a",
"boolean",
"chart",
"representing",
"the",
"set",
"of",
"spans",
"which",
"are",
"on",
"or",
"null",
"if",
"the",
"number",
"of",
"span",
"variables",
"in",
"the",
"assignment",
"is",
"invalid",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/globalfac/ConstituencyTreeFactor.java#L367-L380
|
12,222
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/globalfac/ConstituencyTreeFactor.java
|
ConstituencyTreeFactor.isTree
|
private static boolean isTree(int n, boolean[][] chart) {
if (!chart[0][n]) {
// Root must be a span.
return false;
}
for (int width = 1; width <= n; width++) {
for (int start = 0; start <= n - width; start++) {
int end = start + width;
if (width == 1) {
if (!chart[start][end]) {
// All width 1 spans must be set.
return false;
}
} else {
if (chart[start][end]) {
// Count the number of pairs of child spans which could have been combined to form this span.
int childPairCount = 0;
for (int mid = start + 1; mid <= end - 1; mid++) {
if (chart[start][mid] && chart[mid][end]) {
childPairCount++;
}
}
if (childPairCount != 1) {
// This span should have been built from exactly one pair of child spans.
return false;
}
}
}
}
}
return true;
}
|
java
|
private static boolean isTree(int n, boolean[][] chart) {
if (!chart[0][n]) {
// Root must be a span.
return false;
}
for (int width = 1; width <= n; width++) {
for (int start = 0; start <= n - width; start++) {
int end = start + width;
if (width == 1) {
if (!chart[start][end]) {
// All width 1 spans must be set.
return false;
}
} else {
if (chart[start][end]) {
// Count the number of pairs of child spans which could have been combined to form this span.
int childPairCount = 0;
for (int mid = start + 1; mid <= end - 1; mid++) {
if (chart[start][mid] && chart[mid][end]) {
childPairCount++;
}
}
if (childPairCount != 1) {
// This span should have been built from exactly one pair of child spans.
return false;
}
}
}
}
}
return true;
}
|
[
"private",
"static",
"boolean",
"isTree",
"(",
"int",
"n",
",",
"boolean",
"[",
"]",
"[",
"]",
"chart",
")",
"{",
"if",
"(",
"!",
"chart",
"[",
"0",
"]",
"[",
"n",
"]",
")",
"{",
"// Root must be a span.",
"return",
"false",
";",
"}",
"for",
"(",
"int",
"width",
"=",
"1",
";",
"width",
"<=",
"n",
";",
"width",
"++",
")",
"{",
"for",
"(",
"int",
"start",
"=",
"0",
";",
"start",
"<=",
"n",
"-",
"width",
";",
"start",
"++",
")",
"{",
"int",
"end",
"=",
"start",
"+",
"width",
";",
"if",
"(",
"width",
"==",
"1",
")",
"{",
"if",
"(",
"!",
"chart",
"[",
"start",
"]",
"[",
"end",
"]",
")",
"{",
"// All width 1 spans must be set.",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"chart",
"[",
"start",
"]",
"[",
"end",
"]",
")",
"{",
"// Count the number of pairs of child spans which could have been combined to form this span.",
"int",
"childPairCount",
"=",
"0",
";",
"for",
"(",
"int",
"mid",
"=",
"start",
"+",
"1",
";",
"mid",
"<=",
"end",
"-",
"1",
";",
"mid",
"++",
")",
"{",
"if",
"(",
"chart",
"[",
"start",
"]",
"[",
"mid",
"]",
"&&",
"chart",
"[",
"mid",
"]",
"[",
"end",
"]",
")",
"{",
"childPairCount",
"++",
";",
"}",
"}",
"if",
"(",
"childPairCount",
"!=",
"1",
")",
"{",
"// This span should have been built from exactly one pair of child spans.",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] |
Returns true if the boolean chart represents a set of spans that form a
valid constituency tree, false otherwise.
|
[
"Returns",
"true",
"if",
"the",
"boolean",
"chart",
"represents",
"a",
"set",
"of",
"spans",
"that",
"form",
"a",
"valid",
"constituency",
"tree",
"false",
"otherwise",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/globalfac/ConstituencyTreeFactor.java#L386-L417
|
12,223
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/IndexForVc.java
|
IndexForVc.getConfigIter
|
public static IndexForVc getConfigIter(VarSet indexVars, VarConfig config) {
int fixedConfigContrib = getConfigIndex(indexVars, config);
VarSet forVars = new VarSet(indexVars);
forVars.removeAll(config.getVars());
return new IndexForVc(indexVars, forVars, fixedConfigContrib);
}
|
java
|
public static IndexForVc getConfigIter(VarSet indexVars, VarConfig config) {
int fixedConfigContrib = getConfigIndex(indexVars, config);
VarSet forVars = new VarSet(indexVars);
forVars.removeAll(config.getVars());
return new IndexForVc(indexVars, forVars, fixedConfigContrib);
}
|
[
"public",
"static",
"IndexForVc",
"getConfigIter",
"(",
"VarSet",
"indexVars",
",",
"VarConfig",
"config",
")",
"{",
"int",
"fixedConfigContrib",
"=",
"getConfigIndex",
"(",
"indexVars",
",",
"config",
")",
";",
"VarSet",
"forVars",
"=",
"new",
"VarSet",
"(",
"indexVars",
")",
";",
"forVars",
".",
"removeAll",
"(",
"config",
".",
"getVars",
"(",
")",
")",
";",
"return",
"new",
"IndexForVc",
"(",
"indexVars",
",",
"forVars",
",",
"fixedConfigContrib",
")",
";",
"}"
] |
Iterates over all the configurations of indexVars where the subset of
variables in config have been clamped to their given values. The
iterator returns the configuration index of variables in indexVars.
@param indexVars Variable set over which to iterate.
@param config Clamped assignment.
@return Iterator.
|
[
"Iterates",
"over",
"all",
"the",
"configurations",
"of",
"indexVars",
"where",
"the",
"subset",
"of",
"variables",
"in",
"config",
"have",
"been",
"clamped",
"to",
"their",
"given",
"values",
".",
"The",
"iterator",
"returns",
"the",
"configuration",
"index",
"of",
"variables",
"in",
"indexVars",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/IndexForVc.java#L46-L51
|
12,224
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/IndexForVc.java
|
IndexForVc.getConfigArr
|
public static int[] getConfigArr(VarSet vars, VarConfig config) {
IntArrayList a = new IntArrayList(config.getVars().calcNumConfigs());
IntIter iter = getConfigIter(vars, config);
while (iter.hasNext()) {
a.add(iter.next());
}
return a.toNativeArray();
}
|
java
|
public static int[] getConfigArr(VarSet vars, VarConfig config) {
IntArrayList a = new IntArrayList(config.getVars().calcNumConfigs());
IntIter iter = getConfigIter(vars, config);
while (iter.hasNext()) {
a.add(iter.next());
}
return a.toNativeArray();
}
|
[
"public",
"static",
"int",
"[",
"]",
"getConfigArr",
"(",
"VarSet",
"vars",
",",
"VarConfig",
"config",
")",
"{",
"IntArrayList",
"a",
"=",
"new",
"IntArrayList",
"(",
"config",
".",
"getVars",
"(",
")",
".",
"calcNumConfigs",
"(",
")",
")",
";",
"IntIter",
"iter",
"=",
"getConfigIter",
"(",
"vars",
",",
"config",
")",
";",
"while",
"(",
"iter",
".",
"hasNext",
"(",
")",
")",
"{",
"a",
".",
"add",
"(",
"iter",
".",
"next",
"(",
")",
")",
";",
"}",
"return",
"a",
".",
"toNativeArray",
"(",
")",
";",
"}"
] |
Gets an array version of the configuration iterator.
@see edu.jhu.pacaya.gm.model.IndexForVc#getConfigIter
|
[
"Gets",
"an",
"array",
"version",
"of",
"the",
"configuration",
"iterator",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/IndexForVc.java#L57-L64
|
12,225
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/IndexForVc.java
|
IndexForVc.getConfigIndex
|
public static int getConfigIndex(VarSet vars, VarConfig config) {
int configIndex = 0;
int numStatesProd = 1;
for (int v=vars.size()-1; v >= 0; v--) {
Var var = vars.get(v);
int state = config.getState(var, 0);
configIndex += state * numStatesProd;
numStatesProd *= var.getNumStates();
}
return configIndex;
}
|
java
|
public static int getConfigIndex(VarSet vars, VarConfig config) {
int configIndex = 0;
int numStatesProd = 1;
for (int v=vars.size()-1; v >= 0; v--) {
Var var = vars.get(v);
int state = config.getState(var, 0);
configIndex += state * numStatesProd;
numStatesProd *= var.getNumStates();
}
return configIndex;
}
|
[
"public",
"static",
"int",
"getConfigIndex",
"(",
"VarSet",
"vars",
",",
"VarConfig",
"config",
")",
"{",
"int",
"configIndex",
"=",
"0",
";",
"int",
"numStatesProd",
"=",
"1",
";",
"for",
"(",
"int",
"v",
"=",
"vars",
".",
"size",
"(",
")",
"-",
"1",
";",
"v",
">=",
"0",
";",
"v",
"--",
")",
"{",
"Var",
"var",
"=",
"vars",
".",
"get",
"(",
"v",
")",
";",
"int",
"state",
"=",
"config",
".",
"getState",
"(",
"var",
",",
"0",
")",
";",
"configIndex",
"+=",
"state",
"*",
"numStatesProd",
";",
"numStatesProd",
"*=",
"var",
".",
"getNumStates",
"(",
")",
";",
"}",
"return",
"configIndex",
";",
"}"
] |
Gets the index of the configuration of the variables where all those in config
have the specified value, and all other variables in vars have the zero state.
@param vars The variable set over which to iterate.
@param config An assignment to a subset of vars.
@return The configuration index.
|
[
"Gets",
"the",
"index",
"of",
"the",
"configuration",
"of",
"the",
"variables",
"where",
"all",
"those",
"in",
"config",
"have",
"the",
"specified",
"value",
"and",
"all",
"other",
"variables",
"in",
"vars",
"have",
"the",
"zero",
"state",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/IndexForVc.java#L74-L84
|
12,226
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/data/LibDaiFgIo.java
|
LibDaiFgIo.configIdToLibDaiIx
|
public static int configIdToLibDaiIx(int configId, VarSet vs) {
int[] indices = vs.getVarConfigAsArray(configId);
int[] dims = vs.getDims();
return Tensor.ravelIndexMatlab(indices, dims);
}
|
java
|
public static int configIdToLibDaiIx(int configId, VarSet vs) {
int[] indices = vs.getVarConfigAsArray(configId);
int[] dims = vs.getDims();
return Tensor.ravelIndexMatlab(indices, dims);
}
|
[
"public",
"static",
"int",
"configIdToLibDaiIx",
"(",
"int",
"configId",
",",
"VarSet",
"vs",
")",
"{",
"int",
"[",
"]",
"indices",
"=",
"vs",
".",
"getVarConfigAsArray",
"(",
"configId",
")",
";",
"int",
"[",
"]",
"dims",
"=",
"vs",
".",
"getDims",
"(",
")",
";",
"return",
"Tensor",
".",
"ravelIndexMatlab",
"(",
"indices",
",",
"dims",
")",
";",
"}"
] |
converts the internal pacaya index of a config on the varset into the
libdai index corresponding to the same configuration
|
[
"converts",
"the",
"internal",
"pacaya",
"index",
"of",
"a",
"config",
"on",
"the",
"varset",
"into",
"the",
"libdai",
"index",
"corresponding",
"to",
"the",
"same",
"configuration"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/data/LibDaiFgIo.java#L158-L162
|
12,227
|
mcaserta/spring-crypto-utils
|
src/main/java/com/springcryptoutils/core/key/PrivateKeyRegistryByAliasImpl.java
|
PrivateKeyRegistryByAliasImpl.get
|
public PrivateKey get(KeyStoreChooser keyStoreChooser, PrivateKeyChooserByAlias privateKeyChooserByAlias) {
CacheKey cacheKey = new CacheKey(keyStoreChooser.getKeyStoreName(), privateKeyChooserByAlias.getAlias());
PrivateKey retrievedPrivateKey = cache.get(cacheKey);
if (retrievedPrivateKey != null) {
return retrievedPrivateKey;
}
KeyStore keyStore = keyStoreRegistry.get(keyStoreChooser);
if (keyStore != null) {
PrivateKeyFactoryBean factory = new PrivateKeyFactoryBean();
factory.setKeystore(keyStore);
factory.setAlias(privateKeyChooserByAlias.getAlias());
factory.setPassword(privateKeyChooserByAlias.getPassword());
try {
factory.afterPropertiesSet();
PrivateKey privateKey = (PrivateKey) factory.getObject();
if (privateKey != null) {
cache.put(cacheKey, privateKey);
}
return privateKey;
} catch (Exception e) {
throw new PrivateKeyException("error initializing private key factory bean", e);
}
}
return null;
}
|
java
|
public PrivateKey get(KeyStoreChooser keyStoreChooser, PrivateKeyChooserByAlias privateKeyChooserByAlias) {
CacheKey cacheKey = new CacheKey(keyStoreChooser.getKeyStoreName(), privateKeyChooserByAlias.getAlias());
PrivateKey retrievedPrivateKey = cache.get(cacheKey);
if (retrievedPrivateKey != null) {
return retrievedPrivateKey;
}
KeyStore keyStore = keyStoreRegistry.get(keyStoreChooser);
if (keyStore != null) {
PrivateKeyFactoryBean factory = new PrivateKeyFactoryBean();
factory.setKeystore(keyStore);
factory.setAlias(privateKeyChooserByAlias.getAlias());
factory.setPassword(privateKeyChooserByAlias.getPassword());
try {
factory.afterPropertiesSet();
PrivateKey privateKey = (PrivateKey) factory.getObject();
if (privateKey != null) {
cache.put(cacheKey, privateKey);
}
return privateKey;
} catch (Exception e) {
throw new PrivateKeyException("error initializing private key factory bean", e);
}
}
return null;
}
|
[
"public",
"PrivateKey",
"get",
"(",
"KeyStoreChooser",
"keyStoreChooser",
",",
"PrivateKeyChooserByAlias",
"privateKeyChooserByAlias",
")",
"{",
"CacheKey",
"cacheKey",
"=",
"new",
"CacheKey",
"(",
"keyStoreChooser",
".",
"getKeyStoreName",
"(",
")",
",",
"privateKeyChooserByAlias",
".",
"getAlias",
"(",
")",
")",
";",
"PrivateKey",
"retrievedPrivateKey",
"=",
"cache",
".",
"get",
"(",
"cacheKey",
")",
";",
"if",
"(",
"retrievedPrivateKey",
"!=",
"null",
")",
"{",
"return",
"retrievedPrivateKey",
";",
"}",
"KeyStore",
"keyStore",
"=",
"keyStoreRegistry",
".",
"get",
"(",
"keyStoreChooser",
")",
";",
"if",
"(",
"keyStore",
"!=",
"null",
")",
"{",
"PrivateKeyFactoryBean",
"factory",
"=",
"new",
"PrivateKeyFactoryBean",
"(",
")",
";",
"factory",
".",
"setKeystore",
"(",
"keyStore",
")",
";",
"factory",
".",
"setAlias",
"(",
"privateKeyChooserByAlias",
".",
"getAlias",
"(",
")",
")",
";",
"factory",
".",
"setPassword",
"(",
"privateKeyChooserByAlias",
".",
"getPassword",
"(",
")",
")",
";",
"try",
"{",
"factory",
".",
"afterPropertiesSet",
"(",
")",
";",
"PrivateKey",
"privateKey",
"=",
"(",
"PrivateKey",
")",
"factory",
".",
"getObject",
"(",
")",
";",
"if",
"(",
"privateKey",
"!=",
"null",
")",
"{",
"cache",
".",
"put",
"(",
"cacheKey",
",",
"privateKey",
")",
";",
"}",
"return",
"privateKey",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"PrivateKeyException",
"(",
"\"error initializing private key factory bean\"",
",",
"e",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns the selected private key or null if not found.
@param keyStoreChooser the keystore chooser
@param privateKeyChooserByAlias the private key chooser by alias
@return the selected private key or null if not found
|
[
"Returns",
"the",
"selected",
"private",
"key",
"or",
"null",
"if",
"not",
"found",
"."
] |
1dbf6211542fb1e3f9297941d691e7e89cc72c46
|
https://github.com/mcaserta/spring-crypto-utils/blob/1dbf6211542fb1e3f9297941d691e7e89cc72c46/src/main/java/com/springcryptoutils/core/key/PrivateKeyRegistryByAliasImpl.java#L53-L82
|
12,228
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/Tensor.java
|
Tensor.unravelIndex
|
public static int[] unravelIndex(int configIx, int... dims) {
int numConfigs = IntArrays.prod(dims);
assert configIx < numConfigs;
int[] strides = getStrides(dims);
return unravelIndexFromStrides(configIx, strides);
}
|
java
|
public static int[] unravelIndex(int configIx, int... dims) {
int numConfigs = IntArrays.prod(dims);
assert configIx < numConfigs;
int[] strides = getStrides(dims);
return unravelIndexFromStrides(configIx, strides);
}
|
[
"public",
"static",
"int",
"[",
"]",
"unravelIndex",
"(",
"int",
"configIx",
",",
"int",
"...",
"dims",
")",
"{",
"int",
"numConfigs",
"=",
"IntArrays",
".",
"prod",
"(",
"dims",
")",
";",
"assert",
"configIx",
"<",
"numConfigs",
";",
"int",
"[",
"]",
"strides",
"=",
"getStrides",
"(",
"dims",
")",
";",
"return",
"unravelIndexFromStrides",
"(",
"configIx",
",",
"strides",
")",
";",
"}"
] |
Returns an integer array of the same length as dims that matches the configIx'th configuration
if enumerated configurations in order such that the leftmost dimension changes slowest
|
[
"Returns",
"an",
"integer",
"array",
"of",
"the",
"same",
"length",
"as",
"dims",
"that",
"matches",
"the",
"configIx",
"th",
"configuration",
"if",
"enumerated",
"configurations",
"in",
"order",
"such",
"that",
"the",
"leftmost",
"dimension",
"changes",
"slowest"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/Tensor.java#L54-L59
|
12,229
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/Tensor.java
|
Tensor.unravelIndexMatlab
|
public static int[] unravelIndexMatlab(int configIx, int... dims) {
dims = dims.clone();
ArrayUtils.reverse(dims);
int[] config = unravelIndex(configIx, dims);
ArrayUtils.reverse(config);
return config;
}
|
java
|
public static int[] unravelIndexMatlab(int configIx, int... dims) {
dims = dims.clone();
ArrayUtils.reverse(dims);
int[] config = unravelIndex(configIx, dims);
ArrayUtils.reverse(config);
return config;
}
|
[
"public",
"static",
"int",
"[",
"]",
"unravelIndexMatlab",
"(",
"int",
"configIx",
",",
"int",
"...",
"dims",
")",
"{",
"dims",
"=",
"dims",
".",
"clone",
"(",
")",
";",
"ArrayUtils",
".",
"reverse",
"(",
"dims",
")",
";",
"int",
"[",
"]",
"config",
"=",
"unravelIndex",
"(",
"configIx",
",",
"dims",
")",
";",
"ArrayUtils",
".",
"reverse",
"(",
"config",
")",
";",
"return",
"config",
";",
"}"
] |
Returns an integer array of the same length as dims that matches the configIx'th configuration
if enumerated configurations in order such that the rightmost dimension is fastest
|
[
"Returns",
"an",
"integer",
"array",
"of",
"the",
"same",
"length",
"as",
"dims",
"that",
"matches",
"the",
"configIx",
"th",
"configuration",
"if",
"enumerated",
"configurations",
"in",
"order",
"such",
"that",
"the",
"rightmost",
"dimension",
"is",
"fastest"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/Tensor.java#L65-L71
|
12,230
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/Tensor.java
|
Tensor.unravelIndexFromStrides
|
public static int[] unravelIndexFromStrides(int configIx, int... strides) {
int offset = 0;
int[] config = new int[strides.length];
// fill things out from slowest to fastest
for (int i = 0; i < strides.length; i++) {
// how many strides are we passed the offset
int ix = (configIx - offset) / strides[i];
config[i] = ix;
// move the offset
offset += ix * strides[i];
}
return config;
}
|
java
|
public static int[] unravelIndexFromStrides(int configIx, int... strides) {
int offset = 0;
int[] config = new int[strides.length];
// fill things out from slowest to fastest
for (int i = 0; i < strides.length; i++) {
// how many strides are we passed the offset
int ix = (configIx - offset) / strides[i];
config[i] = ix;
// move the offset
offset += ix * strides[i];
}
return config;
}
|
[
"public",
"static",
"int",
"[",
"]",
"unravelIndexFromStrides",
"(",
"int",
"configIx",
",",
"int",
"...",
"strides",
")",
"{",
"int",
"offset",
"=",
"0",
";",
"int",
"[",
"]",
"config",
"=",
"new",
"int",
"[",
"strides",
".",
"length",
"]",
";",
"// fill things out from slowest to fastest",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"strides",
".",
"length",
";",
"i",
"++",
")",
"{",
"// how many strides are we passed the offset",
"int",
"ix",
"=",
"(",
"configIx",
"-",
"offset",
")",
"/",
"strides",
"[",
"i",
"]",
";",
"config",
"[",
"i",
"]",
"=",
"ix",
";",
"// move the offset",
"offset",
"+=",
"ix",
"*",
"strides",
"[",
"i",
"]",
";",
"}",
"return",
"config",
";",
"}"
] |
strides are given in order from left to right, slowest to fastest
|
[
"strides",
"are",
"given",
"in",
"order",
"from",
"left",
"to",
"right",
"slowest",
"to",
"fastest"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/Tensor.java#L76-L88
|
12,231
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/Tensor.java
|
Tensor.setValue
|
public double setValue(int idx, double val) {
double prev = values[idx];
values[idx] = val;
return prev;
}
|
java
|
public double setValue(int idx, double val) {
double prev = values[idx];
values[idx] = val;
return prev;
}
|
[
"public",
"double",
"setValue",
"(",
"int",
"idx",
",",
"double",
"val",
")",
"{",
"double",
"prev",
"=",
"values",
"[",
"idx",
"]",
";",
"values",
"[",
"idx",
"]",
"=",
"val",
";",
"return",
"prev",
";",
"}"
] |
Sets the value of the idx'th entry.
|
[
"Sets",
"the",
"value",
"of",
"the",
"idx",
"th",
"entry",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/Tensor.java#L231-L235
|
12,232
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/Tensor.java
|
Tensor.add
|
public void add(double addend) {
for (int c = 0; c < this.values.length; c++) {
addValue(c, addend);
}
}
|
java
|
public void add(double addend) {
for (int c = 0; c < this.values.length; c++) {
addValue(c, addend);
}
}
|
[
"public",
"void",
"add",
"(",
"double",
"addend",
")",
"{",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"this",
".",
"values",
".",
"length",
";",
"c",
"++",
")",
"{",
"addValue",
"(",
"c",
",",
"addend",
")",
";",
"}",
"}"
] |
Add the addend to each value.
|
[
"Add",
"the",
"addend",
"to",
"each",
"value",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/Tensor.java#L268-L272
|
12,233
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/Tensor.java
|
Tensor.multiply
|
public void multiply(double val) {
for (int c = 0; c < this.values.length; c++) {
multiplyValue(c, val);
}
}
|
java
|
public void multiply(double val) {
for (int c = 0; c < this.values.length; c++) {
multiplyValue(c, val);
}
}
|
[
"public",
"void",
"multiply",
"(",
"double",
"val",
")",
"{",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"this",
".",
"values",
".",
"length",
";",
"c",
"++",
")",
"{",
"multiplyValue",
"(",
"c",
",",
"val",
")",
";",
"}",
"}"
] |
Scale each value by lambda.
|
[
"Scale",
"each",
"value",
"by",
"lambda",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/Tensor.java#L281-L285
|
12,234
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/Tensor.java
|
Tensor.divide
|
public void divide(double val) {
for (int c = 0; c < this.values.length; c++) {
divideValue(c, val);
}
}
|
java
|
public void divide(double val) {
for (int c = 0; c < this.values.length; c++) {
divideValue(c, val);
}
}
|
[
"public",
"void",
"divide",
"(",
"double",
"val",
")",
"{",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"this",
".",
"values",
".",
"length",
";",
"c",
"++",
")",
"{",
"divideValue",
"(",
"c",
",",
"val",
")",
";",
"}",
"}"
] |
Divide each value by lambda.
|
[
"Divide",
"each",
"value",
"by",
"lambda",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/Tensor.java#L288-L292
|
12,235
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/Tensor.java
|
Tensor.select
|
public Tensor select(int dim, int idx) {
int[] yDims = IntArrays.removeEntry(this.getDims(), dim);
Tensor y = new Tensor(s, yDims);
DimIter yIter = new DimIter(y.getDims());
while (yIter.hasNext()) {
int[] yIdx = yIter.next();
int[] xIdx = IntArrays.insertEntry(yIdx, dim, idx);
y.set(yIdx, this.get(xIdx));
}
return y;
}
|
java
|
public Tensor select(int dim, int idx) {
int[] yDims = IntArrays.removeEntry(this.getDims(), dim);
Tensor y = new Tensor(s, yDims);
DimIter yIter = new DimIter(y.getDims());
while (yIter.hasNext()) {
int[] yIdx = yIter.next();
int[] xIdx = IntArrays.insertEntry(yIdx, dim, idx);
y.set(yIdx, this.get(xIdx));
}
return y;
}
|
[
"public",
"Tensor",
"select",
"(",
"int",
"dim",
",",
"int",
"idx",
")",
"{",
"int",
"[",
"]",
"yDims",
"=",
"IntArrays",
".",
"removeEntry",
"(",
"this",
".",
"getDims",
"(",
")",
",",
"dim",
")",
";",
"Tensor",
"y",
"=",
"new",
"Tensor",
"(",
"s",
",",
"yDims",
")",
";",
"DimIter",
"yIter",
"=",
"new",
"DimIter",
"(",
"y",
".",
"getDims",
"(",
")",
")",
";",
"while",
"(",
"yIter",
".",
"hasNext",
"(",
")",
")",
"{",
"int",
"[",
"]",
"yIdx",
"=",
"yIter",
".",
"next",
"(",
")",
";",
"int",
"[",
"]",
"xIdx",
"=",
"IntArrays",
".",
"insertEntry",
"(",
"yIdx",
",",
"dim",
",",
"idx",
")",
";",
"y",
".",
"set",
"(",
"yIdx",
",",
"this",
".",
"get",
"(",
"xIdx",
")",
")",
";",
"}",
"return",
"y",
";",
"}"
] |
Selects a sub-tensor from this one. This can be though of as fixing a particular dimension to
a given index.
@param dim The dimension to treat as fixed.
@param idx The index of that dimension to fix.
@return The sub-tensor selected.
|
[
"Selects",
"a",
"sub",
"-",
"tensor",
"from",
"this",
"one",
".",
"This",
"can",
"be",
"though",
"of",
"as",
"fixing",
"a",
"particular",
"dimension",
"to",
"a",
"given",
"index",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/Tensor.java#L516-L526
|
12,236
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/Tensor.java
|
Tensor.addTensor
|
public void addTensor(Tensor addend, int dim, int idx) {
checkSameAlgebra(this, addend);
DimIter yIter = new DimIter(addend.getDims());
while (yIter.hasNext()) {
int[] yIdx = yIter.next();
int[] xIdx = IntArrays.insertEntry(yIdx, dim, idx);
this.add(xIdx, addend.get(yIdx));
}
}
|
java
|
public void addTensor(Tensor addend, int dim, int idx) {
checkSameAlgebra(this, addend);
DimIter yIter = new DimIter(addend.getDims());
while (yIter.hasNext()) {
int[] yIdx = yIter.next();
int[] xIdx = IntArrays.insertEntry(yIdx, dim, idx);
this.add(xIdx, addend.get(yIdx));
}
}
|
[
"public",
"void",
"addTensor",
"(",
"Tensor",
"addend",
",",
"int",
"dim",
",",
"int",
"idx",
")",
"{",
"checkSameAlgebra",
"(",
"this",
",",
"addend",
")",
";",
"DimIter",
"yIter",
"=",
"new",
"DimIter",
"(",
"addend",
".",
"getDims",
"(",
")",
")",
";",
"while",
"(",
"yIter",
".",
"hasNext",
"(",
")",
")",
"{",
"int",
"[",
"]",
"yIdx",
"=",
"yIter",
".",
"next",
"(",
")",
";",
"int",
"[",
"]",
"xIdx",
"=",
"IntArrays",
".",
"insertEntry",
"(",
"yIdx",
",",
"dim",
",",
"idx",
")",
";",
"this",
".",
"add",
"(",
"xIdx",
",",
"addend",
".",
"get",
"(",
"yIdx",
")",
")",
";",
"}",
"}"
] |
Adds a smaller tensor to this one, inserting it at a specified dimension
and index. This can be thought of as selecting the sub-tensor of this tensor adding the
smaller tensor to it.
This is the larger tensor (i.e. the augend).
@param addend The smaller tensor (i.e. the addend)
@param dim The dimension which will be treated as fixed on the larger tensor.
@param idx The index at which that dimension will be fixed.
|
[
"Adds",
"a",
"smaller",
"tensor",
"to",
"this",
"one",
"inserting",
"it",
"at",
"a",
"specified",
"dimension",
"and",
"index",
".",
"This",
"can",
"be",
"thought",
"of",
"as",
"selecting",
"the",
"sub",
"-",
"tensor",
"of",
"this",
"tensor",
"adding",
"the",
"smaller",
"tensor",
"to",
"it",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/Tensor.java#L539-L547
|
12,237
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/VarSet.java
|
VarSet.getVarConfig
|
public VarConfig getVarConfig(int configIndex) {
// Configuration as an array of ints, one for each variable.
int i;
int[] states = getVarConfigAsArray(configIndex);
VarConfig config = new VarConfig();
i=0;
for (Var var : this) {
config.put(var, states[i++]);
}
return config;
}
|
java
|
public VarConfig getVarConfig(int configIndex) {
// Configuration as an array of ints, one for each variable.
int i;
int[] states = getVarConfigAsArray(configIndex);
VarConfig config = new VarConfig();
i=0;
for (Var var : this) {
config.put(var, states[i++]);
}
return config;
}
|
[
"public",
"VarConfig",
"getVarConfig",
"(",
"int",
"configIndex",
")",
"{",
"// Configuration as an array of ints, one for each variable.",
"int",
"i",
";",
"int",
"[",
"]",
"states",
"=",
"getVarConfigAsArray",
"(",
"configIndex",
")",
";",
"VarConfig",
"config",
"=",
"new",
"VarConfig",
"(",
")",
";",
"i",
"=",
"0",
";",
"for",
"(",
"Var",
"var",
":",
"this",
")",
"{",
"config",
".",
"put",
"(",
"var",
",",
"states",
"[",
"i",
"++",
"]",
")",
";",
"}",
"return",
"config",
";",
"}"
] |
Gets the variable configuration corresponding to the given configuration index.
@param configIndex The config index.
@return The variable configuration.
|
[
"Gets",
"the",
"variable",
"configuration",
"corresponding",
"to",
"the",
"given",
"configuration",
"index",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/VarSet.java#L108-L119
|
12,238
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/VarSet.java
|
VarSet.getVarConfigAsArray
|
public void getVarConfigAsArray(int configIndex, int[] putInto) {
if(putInto.length != this.size())
throw new IllegalArgumentException();
int i = putInto.length - 1;
for (int v=this.size()-1; v >= 0; v--) {
Var var = this.get(v);
putInto[i--] = configIndex % var.getNumStates();
configIndex /= var.getNumStates();
}
}
|
java
|
public void getVarConfigAsArray(int configIndex, int[] putInto) {
if(putInto.length != this.size())
throw new IllegalArgumentException();
int i = putInto.length - 1;
for (int v=this.size()-1; v >= 0; v--) {
Var var = this.get(v);
putInto[i--] = configIndex % var.getNumStates();
configIndex /= var.getNumStates();
}
}
|
[
"public",
"void",
"getVarConfigAsArray",
"(",
"int",
"configIndex",
",",
"int",
"[",
"]",
"putInto",
")",
"{",
"if",
"(",
"putInto",
".",
"length",
"!=",
"this",
".",
"size",
"(",
")",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
")",
";",
"int",
"i",
"=",
"putInto",
".",
"length",
"-",
"1",
";",
"for",
"(",
"int",
"v",
"=",
"this",
".",
"size",
"(",
")",
"-",
"1",
";",
"v",
">=",
"0",
";",
"v",
"--",
")",
"{",
"Var",
"var",
"=",
"this",
".",
"get",
"(",
"v",
")",
";",
"putInto",
"[",
"i",
"--",
"]",
"=",
"configIndex",
"%",
"var",
".",
"getNumStates",
"(",
")",
";",
"configIndex",
"/=",
"var",
".",
"getNumStates",
"(",
")",
";",
"}",
"}"
] |
this is the "no-allocation" version of the non-void method of the same name.
|
[
"this",
"is",
"the",
"no",
"-",
"allocation",
"version",
"of",
"the",
"non",
"-",
"void",
"method",
"of",
"the",
"same",
"name",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/VarSet.java#L140-L149
|
12,239
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/VarSet.java
|
VarSet.getDims
|
public int[] getDims() {
int[] dims = new int[size()];
for (int i = 0; i < size(); i++) {
dims[i] = get(i).getNumStates();
}
return dims;
}
|
java
|
public int[] getDims() {
int[] dims = new int[size()];
for (int i = 0; i < size(); i++) {
dims[i] = get(i).getNumStates();
}
return dims;
}
|
[
"public",
"int",
"[",
"]",
"getDims",
"(",
")",
"{",
"int",
"[",
"]",
"dims",
"=",
"new",
"int",
"[",
"size",
"(",
")",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"dims",
"[",
"i",
"]",
"=",
"get",
"(",
"i",
")",
".",
"getNumStates",
"(",
")",
";",
"}",
"return",
"dims",
";",
"}"
] |
Returns an array holding the number of values the corresponding variables can take on
|
[
"Returns",
"an",
"array",
"holding",
"the",
"number",
"of",
"values",
"the",
"corresponding",
"variables",
"can",
"take",
"on"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/VarSet.java#L154-L160
|
12,240
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/sys/System.java
|
System.runCommand
|
public static void runCommand(String[] cmdArray, File logFile, File dir) {
Process proc = System.runProcess(cmdArray, logFile, dir);
if (proc.exitValue() != 0) {
throw new RuntimeException("Command failed with exit code " + proc.exitValue() + ": "
+ System.cmdToString(cmdArray) + "\n" + QFiles.tail(logFile));
}
}
|
java
|
public static void runCommand(String[] cmdArray, File logFile, File dir) {
Process proc = System.runProcess(cmdArray, logFile, dir);
if (proc.exitValue() != 0) {
throw new RuntimeException("Command failed with exit code " + proc.exitValue() + ": "
+ System.cmdToString(cmdArray) + "\n" + QFiles.tail(logFile));
}
}
|
[
"public",
"static",
"void",
"runCommand",
"(",
"String",
"[",
"]",
"cmdArray",
",",
"File",
"logFile",
",",
"File",
"dir",
")",
"{",
"Process",
"proc",
"=",
"System",
".",
"runProcess",
"(",
"cmdArray",
",",
"logFile",
",",
"dir",
")",
";",
"if",
"(",
"proc",
".",
"exitValue",
"(",
")",
"!=",
"0",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Command failed with exit code \"",
"+",
"proc",
".",
"exitValue",
"(",
")",
"+",
"\": \"",
"+",
"System",
".",
"cmdToString",
"(",
"cmdArray",
")",
"+",
"\"\\n\"",
"+",
"QFiles",
".",
"tail",
"(",
"logFile",
")",
")",
";",
"}",
"}"
] |
Checks the exit code and throws an Exception if the process failed.
|
[
"Checks",
"the",
"exit",
"code",
"and",
"throws",
"an",
"Exception",
"if",
"the",
"process",
"failed",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/sys/System.java#L20-L26
|
12,241
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/sys/System.java
|
System.runProcess
|
public static Process runProcess(String[] cmdArray, File logFile, File dir) {
try {
ProcessBuilder pb = new ProcessBuilder(cmdArray);
pb.redirectErrorStream(true);
pb.directory(dir);
Process proc = pb.start();
if (logFile != null) {
// Redirect stderr and stdout to logFile
// TODO: in Java 7, use redirectOutput(Redirect.to(logFile))
InputStream inputStream = new BufferedInputStream(proc.getInputStream());
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(logFile));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
inputStream.close();
out.flush();
out.close();
}
proc.waitFor();
return proc;
} catch (Exception e) {
String tail = "";
try {
tail = QFiles.tail(logFile);
} catch (Throwable t) {
// Ignore new exceptions
}
throw new RuntimeException("Exception thrown while trying to exec command " + System.cmdToString(cmdArray) + "\n"
+ tail, e);
}
}
|
java
|
public static Process runProcess(String[] cmdArray, File logFile, File dir) {
try {
ProcessBuilder pb = new ProcessBuilder(cmdArray);
pb.redirectErrorStream(true);
pb.directory(dir);
Process proc = pb.start();
if (logFile != null) {
// Redirect stderr and stdout to logFile
// TODO: in Java 7, use redirectOutput(Redirect.to(logFile))
InputStream inputStream = new BufferedInputStream(proc.getInputStream());
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(logFile));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
inputStream.close();
out.flush();
out.close();
}
proc.waitFor();
return proc;
} catch (Exception e) {
String tail = "";
try {
tail = QFiles.tail(logFile);
} catch (Throwable t) {
// Ignore new exceptions
}
throw new RuntimeException("Exception thrown while trying to exec command " + System.cmdToString(cmdArray) + "\n"
+ tail, e);
}
}
|
[
"public",
"static",
"Process",
"runProcess",
"(",
"String",
"[",
"]",
"cmdArray",
",",
"File",
"logFile",
",",
"File",
"dir",
")",
"{",
"try",
"{",
"ProcessBuilder",
"pb",
"=",
"new",
"ProcessBuilder",
"(",
"cmdArray",
")",
";",
"pb",
".",
"redirectErrorStream",
"(",
"true",
")",
";",
"pb",
".",
"directory",
"(",
"dir",
")",
";",
"Process",
"proc",
"=",
"pb",
".",
"start",
"(",
")",
";",
"if",
"(",
"logFile",
"!=",
"null",
")",
"{",
"// Redirect stderr and stdout to logFile",
"// TODO: in Java 7, use redirectOutput(Redirect.to(logFile))",
"InputStream",
"inputStream",
"=",
"new",
"BufferedInputStream",
"(",
"proc",
".",
"getInputStream",
"(",
")",
")",
";",
"BufferedOutputStream",
"out",
"=",
"new",
"BufferedOutputStream",
"(",
"new",
"FileOutputStream",
"(",
"logFile",
")",
")",
";",
"int",
"read",
"=",
"0",
";",
"byte",
"[",
"]",
"bytes",
"=",
"new",
"byte",
"[",
"1024",
"]",
";",
"while",
"(",
"(",
"read",
"=",
"inputStream",
".",
"read",
"(",
"bytes",
")",
")",
"!=",
"-",
"1",
")",
"{",
"out",
".",
"write",
"(",
"bytes",
",",
"0",
",",
"read",
")",
";",
"}",
"inputStream",
".",
"close",
"(",
")",
";",
"out",
".",
"flush",
"(",
")",
";",
"out",
".",
"close",
"(",
")",
";",
"}",
"proc",
".",
"waitFor",
"(",
")",
";",
"return",
"proc",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"String",
"tail",
"=",
"\"\"",
";",
"try",
"{",
"tail",
"=",
"QFiles",
".",
"tail",
"(",
"logFile",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"// Ignore new exceptions",
"}",
"throw",
"new",
"RuntimeException",
"(",
"\"Exception thrown while trying to exec command \"",
"+",
"System",
".",
"cmdToString",
"(",
"cmdArray",
")",
"+",
"\"\\n\"",
"+",
"tail",
",",
"e",
")",
";",
"}",
"}"
] |
Returns the Process which contains the exit code.
|
[
"Returns",
"the",
"Process",
"which",
"contains",
"the",
"exit",
"code",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/sys/System.java#L31-L69
|
12,242
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/inf/BeliefPropagation.java
|
BeliefPropagation.forwardSendMessage
|
private void forwardSendMessage(int edge, int iter) {
// Update the residual
double oldResidual = residuals[edge];
residuals[edge] = smartResidual(msgs[edge], newMsgs[edge], edge);
if (oldResidual > prm.convergenceThreshold && residuals[edge] <= prm.convergenceThreshold) {
// This message has (newly) converged.
numConverged ++;
}
if (oldResidual <= prm.convergenceThreshold && residuals[edge] > prm.convergenceThreshold) {
// This message was marked as converged, but is no longer converged.
numConverged--;
}
// Check for oscillation. Did the argmax change?
if (log.isTraceEnabled() && iter > 0) {
if (msgs[edge].getArgmaxConfigId() != newMsgs[edge].getArgmaxConfigId()) {
oscillationCount.incrementAndGet();
}
sendCount.incrementAndGet();
log.trace("Residual: {} {}", fg.edgeToString(edge), residuals[edge]);
}
// Update the cached belief.
int child = bg.childE(edge);
if (!bg.isT1T2(edge) && bg.numNbsT1(child) >= prm.minVarNbsForCache) {
varBeliefs[child].elemDivBP(msgs[edge]);
varBeliefs[child].elemMultiply(newMsgs[edge]);
assert !varBeliefs[child].containsBadValues() : "varBeliefs[child] = " + varBeliefs[child];
} else if (bg.isT1T2(edge) && bg.numNbsT2(child) >= prm.minFacNbsForCache){
Factor f = bg.t2E(edge);
if (! (f instanceof GlobalFactor)) {
facBeliefs[child].divBP(msgs[edge]);
facBeliefs[child].prod(newMsgs[edge]);
assert !facBeliefs[child].containsBadValues() : "facBeliefs[child] = " + facBeliefs[child];
}
}
// Send message: Just swap the pointers to the current message and the new message, so
// that we don't have to create a new factor object.
VarTensor oldMessage = msgs[edge];
msgs[edge] = newMsgs[edge];
newMsgs[edge] = oldMessage;
assert !msgs[edge].containsBadValues() : "msgs[edge] = " + msgs[edge];
if (log.isTraceEnabled()) {
log.trace("Message sent: {} {}", fg.edgeToString(edge), msgs[edge]);
}
}
|
java
|
private void forwardSendMessage(int edge, int iter) {
// Update the residual
double oldResidual = residuals[edge];
residuals[edge] = smartResidual(msgs[edge], newMsgs[edge], edge);
if (oldResidual > prm.convergenceThreshold && residuals[edge] <= prm.convergenceThreshold) {
// This message has (newly) converged.
numConverged ++;
}
if (oldResidual <= prm.convergenceThreshold && residuals[edge] > prm.convergenceThreshold) {
// This message was marked as converged, but is no longer converged.
numConverged--;
}
// Check for oscillation. Did the argmax change?
if (log.isTraceEnabled() && iter > 0) {
if (msgs[edge].getArgmaxConfigId() != newMsgs[edge].getArgmaxConfigId()) {
oscillationCount.incrementAndGet();
}
sendCount.incrementAndGet();
log.trace("Residual: {} {}", fg.edgeToString(edge), residuals[edge]);
}
// Update the cached belief.
int child = bg.childE(edge);
if (!bg.isT1T2(edge) && bg.numNbsT1(child) >= prm.minVarNbsForCache) {
varBeliefs[child].elemDivBP(msgs[edge]);
varBeliefs[child].elemMultiply(newMsgs[edge]);
assert !varBeliefs[child].containsBadValues() : "varBeliefs[child] = " + varBeliefs[child];
} else if (bg.isT1T2(edge) && bg.numNbsT2(child) >= prm.minFacNbsForCache){
Factor f = bg.t2E(edge);
if (! (f instanceof GlobalFactor)) {
facBeliefs[child].divBP(msgs[edge]);
facBeliefs[child].prod(newMsgs[edge]);
assert !facBeliefs[child].containsBadValues() : "facBeliefs[child] = " + facBeliefs[child];
}
}
// Send message: Just swap the pointers to the current message and the new message, so
// that we don't have to create a new factor object.
VarTensor oldMessage = msgs[edge];
msgs[edge] = newMsgs[edge];
newMsgs[edge] = oldMessage;
assert !msgs[edge].containsBadValues() : "msgs[edge] = " + msgs[edge];
if (log.isTraceEnabled()) {
log.trace("Message sent: {} {}", fg.edgeToString(edge), msgs[edge]);
}
}
|
[
"private",
"void",
"forwardSendMessage",
"(",
"int",
"edge",
",",
"int",
"iter",
")",
"{",
"// Update the residual",
"double",
"oldResidual",
"=",
"residuals",
"[",
"edge",
"]",
";",
"residuals",
"[",
"edge",
"]",
"=",
"smartResidual",
"(",
"msgs",
"[",
"edge",
"]",
",",
"newMsgs",
"[",
"edge",
"]",
",",
"edge",
")",
";",
"if",
"(",
"oldResidual",
">",
"prm",
".",
"convergenceThreshold",
"&&",
"residuals",
"[",
"edge",
"]",
"<=",
"prm",
".",
"convergenceThreshold",
")",
"{",
"// This message has (newly) converged.",
"numConverged",
"++",
";",
"}",
"if",
"(",
"oldResidual",
"<=",
"prm",
".",
"convergenceThreshold",
"&&",
"residuals",
"[",
"edge",
"]",
">",
"prm",
".",
"convergenceThreshold",
")",
"{",
"// This message was marked as converged, but is no longer converged.",
"numConverged",
"--",
";",
"}",
"// Check for oscillation. Did the argmax change?",
"if",
"(",
"log",
".",
"isTraceEnabled",
"(",
")",
"&&",
"iter",
">",
"0",
")",
"{",
"if",
"(",
"msgs",
"[",
"edge",
"]",
".",
"getArgmaxConfigId",
"(",
")",
"!=",
"newMsgs",
"[",
"edge",
"]",
".",
"getArgmaxConfigId",
"(",
")",
")",
"{",
"oscillationCount",
".",
"incrementAndGet",
"(",
")",
";",
"}",
"sendCount",
".",
"incrementAndGet",
"(",
")",
";",
"log",
".",
"trace",
"(",
"\"Residual: {} {}\"",
",",
"fg",
".",
"edgeToString",
"(",
"edge",
")",
",",
"residuals",
"[",
"edge",
"]",
")",
";",
"}",
"// Update the cached belief.",
"int",
"child",
"=",
"bg",
".",
"childE",
"(",
"edge",
")",
";",
"if",
"(",
"!",
"bg",
".",
"isT1T2",
"(",
"edge",
")",
"&&",
"bg",
".",
"numNbsT1",
"(",
"child",
")",
">=",
"prm",
".",
"minVarNbsForCache",
")",
"{",
"varBeliefs",
"[",
"child",
"]",
".",
"elemDivBP",
"(",
"msgs",
"[",
"edge",
"]",
")",
";",
"varBeliefs",
"[",
"child",
"]",
".",
"elemMultiply",
"(",
"newMsgs",
"[",
"edge",
"]",
")",
";",
"assert",
"!",
"varBeliefs",
"[",
"child",
"]",
".",
"containsBadValues",
"(",
")",
":",
"\"varBeliefs[child] = \"",
"+",
"varBeliefs",
"[",
"child",
"]",
";",
"}",
"else",
"if",
"(",
"bg",
".",
"isT1T2",
"(",
"edge",
")",
"&&",
"bg",
".",
"numNbsT2",
"(",
"child",
")",
">=",
"prm",
".",
"minFacNbsForCache",
")",
"{",
"Factor",
"f",
"=",
"bg",
".",
"t2E",
"(",
"edge",
")",
";",
"if",
"(",
"!",
"(",
"f",
"instanceof",
"GlobalFactor",
")",
")",
"{",
"facBeliefs",
"[",
"child",
"]",
".",
"divBP",
"(",
"msgs",
"[",
"edge",
"]",
")",
";",
"facBeliefs",
"[",
"child",
"]",
".",
"prod",
"(",
"newMsgs",
"[",
"edge",
"]",
")",
";",
"assert",
"!",
"facBeliefs",
"[",
"child",
"]",
".",
"containsBadValues",
"(",
")",
":",
"\"facBeliefs[child] = \"",
"+",
"facBeliefs",
"[",
"child",
"]",
";",
"}",
"}",
"// Send message: Just swap the pointers to the current message and the new message, so",
"// that we don't have to create a new factor object.",
"VarTensor",
"oldMessage",
"=",
"msgs",
"[",
"edge",
"]",
";",
"msgs",
"[",
"edge",
"]",
"=",
"newMsgs",
"[",
"edge",
"]",
";",
"newMsgs",
"[",
"edge",
"]",
"=",
"oldMessage",
";",
"assert",
"!",
"msgs",
"[",
"edge",
"]",
".",
"containsBadValues",
"(",
")",
":",
"\"msgs[edge] = \"",
"+",
"msgs",
"[",
"edge",
"]",
";",
"if",
"(",
"log",
".",
"isTraceEnabled",
"(",
")",
")",
"{",
"log",
".",
"trace",
"(",
"\"Message sent: {} {}\"",
",",
"fg",
".",
"edgeToString",
"(",
"edge",
")",
",",
"msgs",
"[",
"edge",
"]",
")",
";",
"}",
"}"
] |
Sends the message that is currently "pending" for this edge. This just
copies the message in the "pending slot" to the "message slot" for this
edge.
@param edge The edge over which the message should be sent.
@param iter The current iteration.
|
[
"Sends",
"the",
"message",
"that",
"is",
"currently",
"pending",
"for",
"this",
"edge",
".",
"This",
"just",
"copies",
"the",
"message",
"in",
"the",
"pending",
"slot",
"to",
"the",
"message",
"slot",
"for",
"this",
"edge",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/inf/BeliefPropagation.java#L421-L468
|
12,243
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/inf/BeliefPropagation.java
|
BeliefPropagation.smartResidual
|
private double smartResidual(VarTensor message, VarTensor newMessage, int edge) {
// This is intentionally NOT the semiring zero.
return CachingBpSchedule.isConstantMsg(edge, fg) ? 0.0 : getResidual(message, newMessage);
}
|
java
|
private double smartResidual(VarTensor message, VarTensor newMessage, int edge) {
// This is intentionally NOT the semiring zero.
return CachingBpSchedule.isConstantMsg(edge, fg) ? 0.0 : getResidual(message, newMessage);
}
|
[
"private",
"double",
"smartResidual",
"(",
"VarTensor",
"message",
",",
"VarTensor",
"newMessage",
",",
"int",
"edge",
")",
"{",
"// This is intentionally NOT the semiring zero.",
"return",
"CachingBpSchedule",
".",
"isConstantMsg",
"(",
"edge",
",",
"fg",
")",
"?",
"0.0",
":",
"getResidual",
"(",
"message",
",",
"newMessage",
")",
";",
"}"
] |
Returns the "converged" residual for constant messages, and the actual residual otherwise.
|
[
"Returns",
"the",
"converged",
"residual",
"for",
"constant",
"messages",
"and",
"the",
"actual",
"residual",
"otherwise",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/inf/BeliefPropagation.java#L471-L474
|
12,244
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/inf/BeliefPropagation.java
|
BeliefPropagation.getResidual
|
private double getResidual(VarTensor t1, VarTensor t2) {
assert s == t1.getAlgebra() && s == t2.getAlgebra();
Tensor.checkEqualSize(t1, t2);
Tensor.checkSameAlgebra(t1, t2);
double residual = Double.NEGATIVE_INFINITY;
for (int c=0; c<t1.size(); c++) {
double abs = Math.abs(s.toLogProb(t1.get(c)) - s.toLogProb(t2.get(c)));
if (abs > residual) {
residual = abs;
}
}
return residual;
}
|
java
|
private double getResidual(VarTensor t1, VarTensor t2) {
assert s == t1.getAlgebra() && s == t2.getAlgebra();
Tensor.checkEqualSize(t1, t2);
Tensor.checkSameAlgebra(t1, t2);
double residual = Double.NEGATIVE_INFINITY;
for (int c=0; c<t1.size(); c++) {
double abs = Math.abs(s.toLogProb(t1.get(c)) - s.toLogProb(t2.get(c)));
if (abs > residual) {
residual = abs;
}
}
return residual;
}
|
[
"private",
"double",
"getResidual",
"(",
"VarTensor",
"t1",
",",
"VarTensor",
"t2",
")",
"{",
"assert",
"s",
"==",
"t1",
".",
"getAlgebra",
"(",
")",
"&&",
"s",
"==",
"t2",
".",
"getAlgebra",
"(",
")",
";",
"Tensor",
".",
"checkEqualSize",
"(",
"t1",
",",
"t2",
")",
";",
"Tensor",
".",
"checkSameAlgebra",
"(",
"t1",
",",
"t2",
")",
";",
"double",
"residual",
"=",
"Double",
".",
"NEGATIVE_INFINITY",
";",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"t1",
".",
"size",
"(",
")",
";",
"c",
"++",
")",
"{",
"double",
"abs",
"=",
"Math",
".",
"abs",
"(",
"s",
".",
"toLogProb",
"(",
"t1",
".",
"get",
"(",
"c",
")",
")",
"-",
"s",
".",
"toLogProb",
"(",
"t2",
".",
"get",
"(",
"c",
")",
")",
")",
";",
"if",
"(",
"abs",
">",
"residual",
")",
"{",
"residual",
"=",
"abs",
";",
"}",
"}",
"return",
"residual",
";",
"}"
] |
Gets the residual for a new message, as the maximum error over all assignments.
Following the definition of Sutton & McCallum (2007), we compute the residual as the infinity
norm of the difference of the log of the message vectors.
Note: the returned value is NOT in the semiring / abstract algebra. It is the actual value
described above.
|
[
"Gets",
"the",
"residual",
"for",
"a",
"new",
"message",
"as",
"the",
"maximum",
"error",
"over",
"all",
"assignments",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/inf/BeliefPropagation.java#L485-L497
|
12,245
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/inf/BeliefPropagation.java
|
BeliefPropagation.calcProductAtVar
|
private void calcProductAtVar(int v, VarTensor prod, int excl1, int excl2) {
for (int nb=0; nb<bg.numNbsT1(v); nb++) {
if (nb == excl1 || nb == excl2) {
// Don't include messages to these neighbors.
continue;
}
// Get message from neighbor to this node.
VarTensor nbMsg = msgs[bg.opposingT1(v, nb)];
// Since the node is a variable, this is an element-wise product.
prod.elemMultiply(nbMsg);
}
}
|
java
|
private void calcProductAtVar(int v, VarTensor prod, int excl1, int excl2) {
for (int nb=0; nb<bg.numNbsT1(v); nb++) {
if (nb == excl1 || nb == excl2) {
// Don't include messages to these neighbors.
continue;
}
// Get message from neighbor to this node.
VarTensor nbMsg = msgs[bg.opposingT1(v, nb)];
// Since the node is a variable, this is an element-wise product.
prod.elemMultiply(nbMsg);
}
}
|
[
"private",
"void",
"calcProductAtVar",
"(",
"int",
"v",
",",
"VarTensor",
"prod",
",",
"int",
"excl1",
",",
"int",
"excl2",
")",
"{",
"for",
"(",
"int",
"nb",
"=",
"0",
";",
"nb",
"<",
"bg",
".",
"numNbsT1",
"(",
"v",
")",
";",
"nb",
"++",
")",
"{",
"if",
"(",
"nb",
"==",
"excl1",
"||",
"nb",
"==",
"excl2",
")",
"{",
"// Don't include messages to these neighbors.",
"continue",
";",
"}",
"// Get message from neighbor to this node.",
"VarTensor",
"nbMsg",
"=",
"msgs",
"[",
"bg",
".",
"opposingT1",
"(",
"v",
",",
"nb",
")",
"]",
";",
"// Since the node is a variable, this is an element-wise product. ",
"prod",
".",
"elemMultiply",
"(",
"nbMsg",
")",
";",
"}",
"}"
] |
Computes the product of all messages being sent to a node, optionally excluding messages sent
from another node or two.
Upon completion, prod will be multiplied by the product of all incoming messages to node,
except for the message from exclNode1 / exclNode2 if specified.
@param node The node to which all the messages are being sent.
@param prod An input / output tensor with which the product will (destructively) be taken.
@param exclNode1 If non-null, any message sent from exclNode1 to node will be excluded from
the product.
@param exclNode2 If non-null, any message sent from exclNode2 to node will be excluded from
the product.
|
[
"Computes",
"the",
"product",
"of",
"all",
"messages",
"being",
"sent",
"to",
"a",
"node",
"optionally",
"excluding",
"messages",
"sent",
"from",
"another",
"node",
"or",
"two",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/inf/BeliefPropagation.java#L886-L897
|
12,246
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/inf/BeliefPropagation.java
|
BeliefPropagation.calcVarBeliefs
|
private VarTensor calcVarBeliefs(Var var) {
// Compute the product of all messages sent to this variable.
VarTensor prod = new VarTensor(s, new VarSet(var), s.one());
calcProductAtVar(var.getId(), prod, -1, -1);
return prod;
}
|
java
|
private VarTensor calcVarBeliefs(Var var) {
// Compute the product of all messages sent to this variable.
VarTensor prod = new VarTensor(s, new VarSet(var), s.one());
calcProductAtVar(var.getId(), prod, -1, -1);
return prod;
}
|
[
"private",
"VarTensor",
"calcVarBeliefs",
"(",
"Var",
"var",
")",
"{",
"// Compute the product of all messages sent to this variable.",
"VarTensor",
"prod",
"=",
"new",
"VarTensor",
"(",
"s",
",",
"new",
"VarSet",
"(",
"var",
")",
",",
"s",
".",
"one",
"(",
")",
")",
";",
"calcProductAtVar",
"(",
"var",
".",
"getId",
"(",
")",
",",
"prod",
",",
"-",
"1",
",",
"-",
"1",
")",
";",
"return",
"prod",
";",
"}"
] |
Gets the unnormalized variable beleifs.
|
[
"Gets",
"the",
"unnormalized",
"variable",
"beleifs",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/inf/BeliefPropagation.java#L924-L929
|
12,247
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/inf/BeliefPropagation.java
|
BeliefPropagation.calcFactorBeliefs
|
private VarTensor calcFactorBeliefs(Factor factor) {
if (factor instanceof GlobalFactor) {
log.warn("Getting marginals of a global factor is not supported."
+ " This will require exponential space to store the resulting factor."
+ " This should only be used for testing.");
}
// Compute the product of all messages sent to this factor.
VarTensor prod = safeNewVarTensor(factor);
calcProductAtFactor(factor.getId(), prod, -1, -1);
return prod;
}
|
java
|
private VarTensor calcFactorBeliefs(Factor factor) {
if (factor instanceof GlobalFactor) {
log.warn("Getting marginals of a global factor is not supported."
+ " This will require exponential space to store the resulting factor."
+ " This should only be used for testing.");
}
// Compute the product of all messages sent to this factor.
VarTensor prod = safeNewVarTensor(factor);
calcProductAtFactor(factor.getId(), prod, -1, -1);
return prod;
}
|
[
"private",
"VarTensor",
"calcFactorBeliefs",
"(",
"Factor",
"factor",
")",
"{",
"if",
"(",
"factor",
"instanceof",
"GlobalFactor",
")",
"{",
"log",
".",
"warn",
"(",
"\"Getting marginals of a global factor is not supported.\"",
"+",
"\" This will require exponential space to store the resulting factor.\"",
"+",
"\" This should only be used for testing.\"",
")",
";",
"}",
"// Compute the product of all messages sent to this factor.",
"VarTensor",
"prod",
"=",
"safeNewVarTensor",
"(",
"factor",
")",
";",
"calcProductAtFactor",
"(",
"factor",
".",
"getId",
"(",
")",
",",
"prod",
",",
"-",
"1",
",",
"-",
"1",
")",
";",
"return",
"prod",
";",
"}"
] |
Gets the unnormalized factor beleifs.
|
[
"Gets",
"the",
"unnormalized",
"factor",
"beleifs",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/inf/BeliefPropagation.java#L932-L942
|
12,248
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/files/QFiles.java
|
QFiles.getTempPath
|
private static File getTempPath(String prefix, File parentDir) throws IOException {
final int maxI = (int)Math.pow(10, NUM_DIGITS);
String formatStr = "%s_%0"+NUM_DIGITS+"d";
File path;
int i;
for (i=0; i<maxI; i++) {
path = new File(parentDir, String.format(formatStr, prefix, i));
if (!path.exists()) {
return path;
}
}
// If we ran out of short file names, just create a long one
path = File.createTempFile(prefix, "", parentDir);
if (!path.delete()) {
throw new RuntimeException("Could not delete temp file as expected: " + path);
}
return path;
}
|
java
|
private static File getTempPath(String prefix, File parentDir) throws IOException {
final int maxI = (int)Math.pow(10, NUM_DIGITS);
String formatStr = "%s_%0"+NUM_DIGITS+"d";
File path;
int i;
for (i=0; i<maxI; i++) {
path = new File(parentDir, String.format(formatStr, prefix, i));
if (!path.exists()) {
return path;
}
}
// If we ran out of short file names, just create a long one
path = File.createTempFile(prefix, "", parentDir);
if (!path.delete()) {
throw new RuntimeException("Could not delete temp file as expected: " + path);
}
return path;
}
|
[
"private",
"static",
"File",
"getTempPath",
"(",
"String",
"prefix",
",",
"File",
"parentDir",
")",
"throws",
"IOException",
"{",
"final",
"int",
"maxI",
"=",
"(",
"int",
")",
"Math",
".",
"pow",
"(",
"10",
",",
"NUM_DIGITS",
")",
";",
"String",
"formatStr",
"=",
"\"%s_%0\"",
"+",
"NUM_DIGITS",
"+",
"\"d\"",
";",
"File",
"path",
";",
"int",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"maxI",
";",
"i",
"++",
")",
"{",
"path",
"=",
"new",
"File",
"(",
"parentDir",
",",
"String",
".",
"format",
"(",
"formatStr",
",",
"prefix",
",",
"i",
")",
")",
";",
"if",
"(",
"!",
"path",
".",
"exists",
"(",
")",
")",
"{",
"return",
"path",
";",
"}",
"}",
"// If we ran out of short file names, just create a long one",
"path",
"=",
"File",
".",
"createTempFile",
"(",
"prefix",
",",
"\"\"",
",",
"parentDir",
")",
";",
"if",
"(",
"!",
"path",
".",
"delete",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Could not delete temp file as expected: \"",
"+",
"path",
")",
";",
"}",
"return",
"path",
";",
"}"
] |
Creates a file object of a currently available path, but does
not create the file. This method is not thread safe.
|
[
"Creates",
"a",
"file",
"object",
"of",
"a",
"currently",
"available",
"path",
"but",
"does",
"not",
"create",
"the",
"file",
".",
"This",
"method",
"is",
"not",
"thread",
"safe",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/files/QFiles.java#L98-L115
|
12,249
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/files/QFiles.java
|
QFiles.readUntil
|
public static void readUntil(BufferedReader reader, String breakpoint) throws IOException {
String line;
while ((line = reader.readLine()) != null) {
if (line.equals(breakpoint)) {
return;
}
}
}
|
java
|
public static void readUntil(BufferedReader reader, String breakpoint) throws IOException {
String line;
while ((line = reader.readLine()) != null) {
if (line.equals(breakpoint)) {
return;
}
}
}
|
[
"public",
"static",
"void",
"readUntil",
"(",
"BufferedReader",
"reader",
",",
"String",
"breakpoint",
")",
"throws",
"IOException",
"{",
"String",
"line",
";",
"while",
"(",
"(",
"line",
"=",
"reader",
".",
"readLine",
"(",
")",
")",
"!=",
"null",
")",
"{",
"if",
"(",
"line",
".",
"equals",
"(",
"breakpoint",
")",
")",
"{",
"return",
";",
"}",
"}",
"}"
] |
Read until the current line equals the breakpoint string.
|
[
"Read",
"until",
"the",
"current",
"line",
"equals",
"the",
"breakpoint",
"string",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/files/QFiles.java#L147-L154
|
12,250
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/parse/cky/PcfgInsideOutside.java
|
PcfgInsideOutside.runOutsideAlgorithm
|
public static void runOutsideAlgorithm(final int[] sent, final CnfGrammar grammar, final LoopOrder loopOrder, final Chart inChart, final Chart outChart, final Scorer scorer) {
// Base case.
// -- part I: outsideScore(S, 0, n) = 0 = log(1).
ChartCell outRootCell = outChart.getCell(0, sent.length);
outRootCell.updateCell(grammar.getRootSymbol(), 0, -1, null);
// -- part II: outsideScore(A, 0, n) = -inf = log(0) for all A \neq S.
// This second part of the base case is the default initialization for each cell.
// We still start at width = n so that we can apply unary rules to our
// base case root terminal S.
//
// For each cell in the chart. (width decreasing)
for (int width = sent.length; width >= 1; width--) {
for (int start = 0; start <= sent.length - width; start++) {
int end = start + width;
ChartCell outCell = outChart.getCell(start, end);
// Apply unary rules.
ScoresSnapshot scoresSnapshot = outCell.getScoresSnapshot();
int[] nts = outCell.getNts();
for(final int parentNt : nts) {
for (final Rule r : grammar.getUnaryRulesWithParent(parentNt)) {
// TODO: Check whether this outside rule even matters.
// Arguably this would create an outside chart that is
// incomplete.
//ChartCell inCell = inChart.getCell(start, end); // TODO: move this out of the loop.
//if (inCell.getScore(r.getLeftChild()) > Double.NEGATIVE_INFINITY) {
double score = scorer.score(r, start, end, end)
+ scoresSnapshot.getScore(parentNt);
outCell.updateCell(r.getLeftChild(), score, end, r);
//}
}
}
// Apply binary rules.
if (loopOrder == LoopOrder.CARTESIAN_PRODUCT) {
processCellCartesianProduct(grammar, inChart, outChart, start, end, outCell, scorer);
} else if (loopOrder == LoopOrder.LEFT_CHILD) {
processCellLeftChild(grammar, inChart, outChart, start, end, outCell, scorer);
} else if (loopOrder == LoopOrder.RIGHT_CHILD) {
processCellRightChild(grammar, inChart, outChart, start, end, outCell, scorer);
} else {
throw new RuntimeException("Not implemented: " + loopOrder);
}
}
}
// Apply lexical rules to each word.
for (int i = 0; i <= sent.length - 1; i++) {
ChartCell outCell = outChart.getCell(i, i+1);
ScoresSnapshot scoresSnapshot = outCell.getScoresSnapshot();
for (final Rule r : grammar.getLexicalRulesWithChild(sent[i])) {
double score = scorer.score(r, i, i+1, i+1)
+ scoresSnapshot.getScore(r.getParent());
outCell.updateCell(r.getLeftChild(), score, i+1, r);
}
}
}
|
java
|
public static void runOutsideAlgorithm(final int[] sent, final CnfGrammar grammar, final LoopOrder loopOrder, final Chart inChart, final Chart outChart, final Scorer scorer) {
// Base case.
// -- part I: outsideScore(S, 0, n) = 0 = log(1).
ChartCell outRootCell = outChart.getCell(0, sent.length);
outRootCell.updateCell(grammar.getRootSymbol(), 0, -1, null);
// -- part II: outsideScore(A, 0, n) = -inf = log(0) for all A \neq S.
// This second part of the base case is the default initialization for each cell.
// We still start at width = n so that we can apply unary rules to our
// base case root terminal S.
//
// For each cell in the chart. (width decreasing)
for (int width = sent.length; width >= 1; width--) {
for (int start = 0; start <= sent.length - width; start++) {
int end = start + width;
ChartCell outCell = outChart.getCell(start, end);
// Apply unary rules.
ScoresSnapshot scoresSnapshot = outCell.getScoresSnapshot();
int[] nts = outCell.getNts();
for(final int parentNt : nts) {
for (final Rule r : grammar.getUnaryRulesWithParent(parentNt)) {
// TODO: Check whether this outside rule even matters.
// Arguably this would create an outside chart that is
// incomplete.
//ChartCell inCell = inChart.getCell(start, end); // TODO: move this out of the loop.
//if (inCell.getScore(r.getLeftChild()) > Double.NEGATIVE_INFINITY) {
double score = scorer.score(r, start, end, end)
+ scoresSnapshot.getScore(parentNt);
outCell.updateCell(r.getLeftChild(), score, end, r);
//}
}
}
// Apply binary rules.
if (loopOrder == LoopOrder.CARTESIAN_PRODUCT) {
processCellCartesianProduct(grammar, inChart, outChart, start, end, outCell, scorer);
} else if (loopOrder == LoopOrder.LEFT_CHILD) {
processCellLeftChild(grammar, inChart, outChart, start, end, outCell, scorer);
} else if (loopOrder == LoopOrder.RIGHT_CHILD) {
processCellRightChild(grammar, inChart, outChart, start, end, outCell, scorer);
} else {
throw new RuntimeException("Not implemented: " + loopOrder);
}
}
}
// Apply lexical rules to each word.
for (int i = 0; i <= sent.length - 1; i++) {
ChartCell outCell = outChart.getCell(i, i+1);
ScoresSnapshot scoresSnapshot = outCell.getScoresSnapshot();
for (final Rule r : grammar.getLexicalRulesWithChild(sent[i])) {
double score = scorer.score(r, i, i+1, i+1)
+ scoresSnapshot.getScore(r.getParent());
outCell.updateCell(r.getLeftChild(), score, i+1, r);
}
}
}
|
[
"public",
"static",
"void",
"runOutsideAlgorithm",
"(",
"final",
"int",
"[",
"]",
"sent",
",",
"final",
"CnfGrammar",
"grammar",
",",
"final",
"LoopOrder",
"loopOrder",
",",
"final",
"Chart",
"inChart",
",",
"final",
"Chart",
"outChart",
",",
"final",
"Scorer",
"scorer",
")",
"{",
"// Base case.",
"// -- part I: outsideScore(S, 0, n) = 0 = log(1).",
"ChartCell",
"outRootCell",
"=",
"outChart",
".",
"getCell",
"(",
"0",
",",
"sent",
".",
"length",
")",
";",
"outRootCell",
".",
"updateCell",
"(",
"grammar",
".",
"getRootSymbol",
"(",
")",
",",
"0",
",",
"-",
"1",
",",
"null",
")",
";",
"// -- part II: outsideScore(A, 0, n) = -inf = log(0) for all A \\neq S.",
"// This second part of the base case is the default initialization for each cell. ",
"// We still start at width = n so that we can apply unary rules to our",
"// base case root terminal S.",
"// ",
"// For each cell in the chart. (width decreasing)",
"for",
"(",
"int",
"width",
"=",
"sent",
".",
"length",
";",
"width",
">=",
"1",
";",
"width",
"--",
")",
"{",
"for",
"(",
"int",
"start",
"=",
"0",
";",
"start",
"<=",
"sent",
".",
"length",
"-",
"width",
";",
"start",
"++",
")",
"{",
"int",
"end",
"=",
"start",
"+",
"width",
";",
"ChartCell",
"outCell",
"=",
"outChart",
".",
"getCell",
"(",
"start",
",",
"end",
")",
";",
"// Apply unary rules.",
"ScoresSnapshot",
"scoresSnapshot",
"=",
"outCell",
".",
"getScoresSnapshot",
"(",
")",
";",
"int",
"[",
"]",
"nts",
"=",
"outCell",
".",
"getNts",
"(",
")",
";",
"for",
"(",
"final",
"int",
"parentNt",
":",
"nts",
")",
"{",
"for",
"(",
"final",
"Rule",
"r",
":",
"grammar",
".",
"getUnaryRulesWithParent",
"(",
"parentNt",
")",
")",
"{",
"// TODO: Check whether this outside rule even matters.",
"// Arguably this would create an outside chart that is",
"// incomplete.",
"//ChartCell inCell = inChart.getCell(start, end); // TODO: move this out of the loop.",
"//if (inCell.getScore(r.getLeftChild()) > Double.NEGATIVE_INFINITY) { ",
"double",
"score",
"=",
"scorer",
".",
"score",
"(",
"r",
",",
"start",
",",
"end",
",",
"end",
")",
"+",
"scoresSnapshot",
".",
"getScore",
"(",
"parentNt",
")",
";",
"outCell",
".",
"updateCell",
"(",
"r",
".",
"getLeftChild",
"(",
")",
",",
"score",
",",
"end",
",",
"r",
")",
";",
"//}",
"}",
"}",
"// Apply binary rules.",
"if",
"(",
"loopOrder",
"==",
"LoopOrder",
".",
"CARTESIAN_PRODUCT",
")",
"{",
"processCellCartesianProduct",
"(",
"grammar",
",",
"inChart",
",",
"outChart",
",",
"start",
",",
"end",
",",
"outCell",
",",
"scorer",
")",
";",
"}",
"else",
"if",
"(",
"loopOrder",
"==",
"LoopOrder",
".",
"LEFT_CHILD",
")",
"{",
"processCellLeftChild",
"(",
"grammar",
",",
"inChart",
",",
"outChart",
",",
"start",
",",
"end",
",",
"outCell",
",",
"scorer",
")",
";",
"}",
"else",
"if",
"(",
"loopOrder",
"==",
"LoopOrder",
".",
"RIGHT_CHILD",
")",
"{",
"processCellRightChild",
"(",
"grammar",
",",
"inChart",
",",
"outChart",
",",
"start",
",",
"end",
",",
"outCell",
",",
"scorer",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Not implemented: \"",
"+",
"loopOrder",
")",
";",
"}",
"}",
"}",
"// Apply lexical rules to each word.",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<=",
"sent",
".",
"length",
"-",
"1",
";",
"i",
"++",
")",
"{",
"ChartCell",
"outCell",
"=",
"outChart",
".",
"getCell",
"(",
"i",
",",
"i",
"+",
"1",
")",
";",
"ScoresSnapshot",
"scoresSnapshot",
"=",
"outCell",
".",
"getScoresSnapshot",
"(",
")",
";",
"for",
"(",
"final",
"Rule",
"r",
":",
"grammar",
".",
"getLexicalRulesWithChild",
"(",
"sent",
"[",
"i",
"]",
")",
")",
"{",
"double",
"score",
"=",
"scorer",
".",
"score",
"(",
"r",
",",
"i",
",",
"i",
"+",
"1",
",",
"i",
"+",
"1",
")",
"+",
"scoresSnapshot",
".",
"getScore",
"(",
"r",
".",
"getParent",
"(",
")",
")",
";",
"outCell",
".",
"updateCell",
"(",
"r",
".",
"getLeftChild",
"(",
")",
",",
"score",
",",
"i",
"+",
"1",
",",
"r",
")",
";",
"}",
"}",
"}"
] |
Runs the outside algorithm, given an inside chart.
@param sent The input sentence.
@param grammar The input grammar.
@param loopOrder The loop order to use when parsing.
@param inChart The inside chart, already populated.
@param outChart The outside chart (the output of this function).
|
[
"Runs",
"the",
"outside",
"algorithm",
"given",
"an",
"inside",
"chart",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/parse/cky/PcfgInsideOutside.java#L127-L184
|
12,251
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/StochasticGradientApproximation.java
|
StochasticGradientApproximation.estimateGradientFd
|
public static IntDoubleVector estimateGradientFd(Function fn, IntDoubleVector x, double epsilon) {
int numParams = fn.getNumDimensions();
IntDoubleVector gradFd = new IntDoubleDenseVector(numParams);
for (int j=0; j<numParams; j++) {
// Test the deriviative d/dx_j(f_i(\vec{x}))
IntDoubleVector d = new IntDoubleDenseVector(numParams);
d.set(j, 1);
double dotFd = getGradDotDirApprox(fn, x, d, epsilon);
if (Double.isNaN(dotFd)) {
log.warn("Hit NaN");
}
gradFd.set(j, dotFd);
}
return gradFd;
}
|
java
|
public static IntDoubleVector estimateGradientFd(Function fn, IntDoubleVector x, double epsilon) {
int numParams = fn.getNumDimensions();
IntDoubleVector gradFd = new IntDoubleDenseVector(numParams);
for (int j=0; j<numParams; j++) {
// Test the deriviative d/dx_j(f_i(\vec{x}))
IntDoubleVector d = new IntDoubleDenseVector(numParams);
d.set(j, 1);
double dotFd = getGradDotDirApprox(fn, x, d, epsilon);
if (Double.isNaN(dotFd)) {
log.warn("Hit NaN");
}
gradFd.set(j, dotFd);
}
return gradFd;
}
|
[
"public",
"static",
"IntDoubleVector",
"estimateGradientFd",
"(",
"Function",
"fn",
",",
"IntDoubleVector",
"x",
",",
"double",
"epsilon",
")",
"{",
"int",
"numParams",
"=",
"fn",
".",
"getNumDimensions",
"(",
")",
";",
"IntDoubleVector",
"gradFd",
"=",
"new",
"IntDoubleDenseVector",
"(",
"numParams",
")",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"numParams",
";",
"j",
"++",
")",
"{",
"// Test the deriviative d/dx_j(f_i(\\vec{x}))",
"IntDoubleVector",
"d",
"=",
"new",
"IntDoubleDenseVector",
"(",
"numParams",
")",
";",
"d",
".",
"set",
"(",
"j",
",",
"1",
")",
";",
"double",
"dotFd",
"=",
"getGradDotDirApprox",
"(",
"fn",
",",
"x",
",",
"d",
",",
"epsilon",
")",
";",
"if",
"(",
"Double",
".",
"isNaN",
"(",
"dotFd",
")",
")",
"{",
"log",
".",
"warn",
"(",
"\"Hit NaN\"",
")",
";",
"}",
"gradFd",
".",
"set",
"(",
"j",
",",
"dotFd",
")",
";",
"}",
"return",
"gradFd",
";",
"}"
] |
Estimates a gradient of a function by an independent finite-difference computation along each
dimension of the domain of the function.
@param fn Function on which to approximate the gradient.
@param x Point at which to approximate the gradient.
@param epsilon The size of the finite difference step.
@return The approximate gradient.
|
[
"Estimates",
"a",
"gradient",
"of",
"a",
"function",
"by",
"an",
"independent",
"finite",
"-",
"difference",
"computation",
"along",
"each",
"dimension",
"of",
"the",
"domain",
"of",
"the",
"function",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/StochasticGradientApproximation.java#L35-L49
|
12,252
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/parse/cky/chart/Chart.java
|
Chart.reset
|
public void reset(Sentence sentence) {
this.sentence = sentence;
// Ensure that the chart is large enough.
if (sentence.size() > chart.length){
chart = getNewChart(sentence, grammar, cellType, parseType, constraint);
} else {
// Clear the chart.
//
// Note that we only need to clear the portion that will be used while parsing this sentence.
for (int i = 0; i < sentence.size(); i++) {
for (int j = i+1; j < sentence.size() + 1; j++) {
chart[i][j].reset(sentence);
}
}
}
}
|
java
|
public void reset(Sentence sentence) {
this.sentence = sentence;
// Ensure that the chart is large enough.
if (sentence.size() > chart.length){
chart = getNewChart(sentence, grammar, cellType, parseType, constraint);
} else {
// Clear the chart.
//
// Note that we only need to clear the portion that will be used while parsing this sentence.
for (int i = 0; i < sentence.size(); i++) {
for (int j = i+1; j < sentence.size() + 1; j++) {
chart[i][j].reset(sentence);
}
}
}
}
|
[
"public",
"void",
"reset",
"(",
"Sentence",
"sentence",
")",
"{",
"this",
".",
"sentence",
"=",
"sentence",
";",
"// Ensure that the chart is large enough.",
"if",
"(",
"sentence",
".",
"size",
"(",
")",
">",
"chart",
".",
"length",
")",
"{",
"chart",
"=",
"getNewChart",
"(",
"sentence",
",",
"grammar",
",",
"cellType",
",",
"parseType",
",",
"constraint",
")",
";",
"}",
"else",
"{",
"// Clear the chart.",
"//",
"// Note that we only need to clear the portion that will be used while parsing this sentence.",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"sentence",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"i",
"+",
"1",
";",
"j",
"<",
"sentence",
".",
"size",
"(",
")",
"+",
"1",
";",
"j",
"++",
")",
"{",
"chart",
"[",
"i",
"]",
"[",
"j",
"]",
".",
"reset",
"(",
"sentence",
")",
";",
"}",
"}",
"}",
"}"
] |
Resets the chart for the input sentence.
|
[
"Resets",
"the",
"chart",
"for",
"the",
"input",
"sentence",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/parse/cky/chart/Chart.java#L72-L87
|
12,253
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/parse/cky/chart/Chart.java
|
Chart.getNewChart
|
private static ChartCell[][] getNewChart(Sentence sentence, CnfGrammar grammar, ChartCellType cellType, ParseType parseType, ChartCellConstraint constraint) {
ChartCell[][] chart = new ChartCell[sentence.size()][sentence.size()+1];
for (int i = 0; i < chart.length; i++) {
for (int j = i+1; j < chart[i].length; j++) {
if (parseType == ParseType.INSIDE && cellType != ChartCellType.FULL) {
throw new RuntimeException("Inside algorithm not implemented for cell type: " + cellType);
}
ChartCell cell;
switch(cellType) {
case SINGLE_HASH:
chart[i][j] = new SingleHashChartCell(grammar, false);
break;
case SINGLE_HASH_BREAK_TIES:
chart[i][j] = new SingleHashChartCell(grammar, true);
break;
case CONSTRAINED_SINGLE:
cell = new SingleHashChartCell(grammar, true);
chart[i][j] = new ConstrainedChartCell(i, j, cell, constraint, sentence);
break;
case DOUBLE_HASH:
chart[i][j] = new DoubleHashChartCell(grammar);
break;
case FULL:
chart[i][j] = new FullChartCell(i, j, grammar, parseType);
break;
case FULL_BREAK_TIES:
chart[i][j] = new FullTieBreakerChartCell(grammar, true);
break;
case CONSTRAINED_FULL:
cell = new FullTieBreakerChartCell(grammar, true);
chart[i][j] = new ConstrainedChartCell(i, j, cell, constraint, sentence);
break;
default:
throw new RuntimeException("not implemented for " + cellType);
}
}
}
return chart;
}
|
java
|
private static ChartCell[][] getNewChart(Sentence sentence, CnfGrammar grammar, ChartCellType cellType, ParseType parseType, ChartCellConstraint constraint) {
ChartCell[][] chart = new ChartCell[sentence.size()][sentence.size()+1];
for (int i = 0; i < chart.length; i++) {
for (int j = i+1; j < chart[i].length; j++) {
if (parseType == ParseType.INSIDE && cellType != ChartCellType.FULL) {
throw new RuntimeException("Inside algorithm not implemented for cell type: " + cellType);
}
ChartCell cell;
switch(cellType) {
case SINGLE_HASH:
chart[i][j] = new SingleHashChartCell(grammar, false);
break;
case SINGLE_HASH_BREAK_TIES:
chart[i][j] = new SingleHashChartCell(grammar, true);
break;
case CONSTRAINED_SINGLE:
cell = new SingleHashChartCell(grammar, true);
chart[i][j] = new ConstrainedChartCell(i, j, cell, constraint, sentence);
break;
case DOUBLE_HASH:
chart[i][j] = new DoubleHashChartCell(grammar);
break;
case FULL:
chart[i][j] = new FullChartCell(i, j, grammar, parseType);
break;
case FULL_BREAK_TIES:
chart[i][j] = new FullTieBreakerChartCell(grammar, true);
break;
case CONSTRAINED_FULL:
cell = new FullTieBreakerChartCell(grammar, true);
chart[i][j] = new ConstrainedChartCell(i, j, cell, constraint, sentence);
break;
default:
throw new RuntimeException("not implemented for " + cellType);
}
}
}
return chart;
}
|
[
"private",
"static",
"ChartCell",
"[",
"]",
"[",
"]",
"getNewChart",
"(",
"Sentence",
"sentence",
",",
"CnfGrammar",
"grammar",
",",
"ChartCellType",
"cellType",
",",
"ParseType",
"parseType",
",",
"ChartCellConstraint",
"constraint",
")",
"{",
"ChartCell",
"[",
"]",
"[",
"]",
"chart",
"=",
"new",
"ChartCell",
"[",
"sentence",
".",
"size",
"(",
")",
"]",
"[",
"sentence",
".",
"size",
"(",
")",
"+",
"1",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"chart",
".",
"length",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"i",
"+",
"1",
";",
"j",
"<",
"chart",
"[",
"i",
"]",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"parseType",
"==",
"ParseType",
".",
"INSIDE",
"&&",
"cellType",
"!=",
"ChartCellType",
".",
"FULL",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Inside algorithm not implemented for cell type: \"",
"+",
"cellType",
")",
";",
"}",
"ChartCell",
"cell",
";",
"switch",
"(",
"cellType",
")",
"{",
"case",
"SINGLE_HASH",
":",
"chart",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"new",
"SingleHashChartCell",
"(",
"grammar",
",",
"false",
")",
";",
"break",
";",
"case",
"SINGLE_HASH_BREAK_TIES",
":",
"chart",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"new",
"SingleHashChartCell",
"(",
"grammar",
",",
"true",
")",
";",
"break",
";",
"case",
"CONSTRAINED_SINGLE",
":",
"cell",
"=",
"new",
"SingleHashChartCell",
"(",
"grammar",
",",
"true",
")",
";",
"chart",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"new",
"ConstrainedChartCell",
"(",
"i",
",",
"j",
",",
"cell",
",",
"constraint",
",",
"sentence",
")",
";",
"break",
";",
"case",
"DOUBLE_HASH",
":",
"chart",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"new",
"DoubleHashChartCell",
"(",
"grammar",
")",
";",
"break",
";",
"case",
"FULL",
":",
"chart",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"new",
"FullChartCell",
"(",
"i",
",",
"j",
",",
"grammar",
",",
"parseType",
")",
";",
"break",
";",
"case",
"FULL_BREAK_TIES",
":",
"chart",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"new",
"FullTieBreakerChartCell",
"(",
"grammar",
",",
"true",
")",
";",
"break",
";",
"case",
"CONSTRAINED_FULL",
":",
"cell",
"=",
"new",
"FullTieBreakerChartCell",
"(",
"grammar",
",",
"true",
")",
";",
"chart",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"new",
"ConstrainedChartCell",
"(",
"i",
",",
"j",
",",
"cell",
",",
"constraint",
",",
"sentence",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"RuntimeException",
"(",
"\"not implemented for \"",
"+",
"cellType",
")",
";",
"}",
"}",
"}",
"return",
"chart",
";",
"}"
] |
Gets a new chart of the appropriate size for the sentence, specific to
this grammar, and with cells of the specified type.
|
[
"Gets",
"a",
"new",
"chart",
"of",
"the",
"appropriate",
"size",
"for",
"the",
"sentence",
"specific",
"to",
"this",
"grammar",
"and",
"with",
"cells",
"of",
"the",
"specified",
"type",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/parse/cky/chart/Chart.java#L93-L131
|
12,254
|
mcaserta/spring-crypto-utils
|
src/main/java/com/springcryptoutils/core/cipher/symmetric/CiphererWithStaticKeyImpl.java
|
CiphererWithStaticKeyImpl.setInitializationVector
|
public void setInitializationVector(String initializationVector) {
try {
this.initializationVectorSpec = new IvParameterSpec(Base64.decodeBase64(initializationVector.getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
throw new SymmetricEncryptionException("UTF-8 is an unsupported encoding on this platform", e);
}
}
|
java
|
public void setInitializationVector(String initializationVector) {
try {
this.initializationVectorSpec = new IvParameterSpec(Base64.decodeBase64(initializationVector.getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
throw new SymmetricEncryptionException("UTF-8 is an unsupported encoding on this platform", e);
}
}
|
[
"public",
"void",
"setInitializationVector",
"(",
"String",
"initializationVector",
")",
"{",
"try",
"{",
"this",
".",
"initializationVectorSpec",
"=",
"new",
"IvParameterSpec",
"(",
"Base64",
".",
"decodeBase64",
"(",
"initializationVector",
".",
"getBytes",
"(",
"\"UTF-8\"",
")",
")",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e",
")",
"{",
"throw",
"new",
"SymmetricEncryptionException",
"(",
"\"UTF-8 is an unsupported encoding on this platform\"",
",",
"e",
")",
";",
"}",
"}"
] |
A base64 encoded representation of the raw byte array containing the
initialization vector.
@param initializationVector the initialization vector
@throws SymmetricEncryptionException on runtime errors
|
[
"A",
"base64",
"encoded",
"representation",
"of",
"the",
"raw",
"byte",
"array",
"containing",
"the",
"initialization",
"vector",
"."
] |
1dbf6211542fb1e3f9297941d691e7e89cc72c46
|
https://github.com/mcaserta/spring-crypto-utils/blob/1dbf6211542fb1e3f9297941d691e7e89cc72c46/src/main/java/com/springcryptoutils/core/cipher/symmetric/CiphererWithStaticKeyImpl.java#L90-L96
|
12,255
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/inf/Beliefs.java
|
Beliefs.getValue
|
@Override
public double getValue(int idx) {
int vSize = MVecArray.count(varBeliefs);
if (idx < vSize) {
return MVecArray.getValue(idx, varBeliefs);
} else {
return MVecArray.getValue(idx - vSize, facBeliefs);
}
}
|
java
|
@Override
public double getValue(int idx) {
int vSize = MVecArray.count(varBeliefs);
if (idx < vSize) {
return MVecArray.getValue(idx, varBeliefs);
} else {
return MVecArray.getValue(idx - vSize, facBeliefs);
}
}
|
[
"@",
"Override",
"public",
"double",
"getValue",
"(",
"int",
"idx",
")",
"{",
"int",
"vSize",
"=",
"MVecArray",
".",
"count",
"(",
"varBeliefs",
")",
";",
"if",
"(",
"idx",
"<",
"vSize",
")",
"{",
"return",
"MVecArray",
".",
"getValue",
"(",
"idx",
",",
"varBeliefs",
")",
";",
"}",
"else",
"{",
"return",
"MVecArray",
".",
"getValue",
"(",
"idx",
"-",
"vSize",
",",
"facBeliefs",
")",
";",
"}",
"}"
] |
Gets a particular value by treating this object as a vector.
NOTE: This implementation is O(n).
@param idx The index of the value to get.
@return The value at that index.
|
[
"Gets",
"a",
"particular",
"value",
"by",
"treating",
"this",
"object",
"as",
"a",
"vector",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/inf/Beliefs.java#L62-L70
|
12,256
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/inf/Beliefs.java
|
Beliefs.setValue
|
public double setValue(int idx, double val) {
int vSize = MVecArray.count(varBeliefs);
if (idx < vSize) {
return MVecArray.setValue(idx, val, varBeliefs);
} else {
return MVecArray.setValue(idx - vSize, val, facBeliefs);
}
}
|
java
|
public double setValue(int idx, double val) {
int vSize = MVecArray.count(varBeliefs);
if (idx < vSize) {
return MVecArray.setValue(idx, val, varBeliefs);
} else {
return MVecArray.setValue(idx - vSize, val, facBeliefs);
}
}
|
[
"public",
"double",
"setValue",
"(",
"int",
"idx",
",",
"double",
"val",
")",
"{",
"int",
"vSize",
"=",
"MVecArray",
".",
"count",
"(",
"varBeliefs",
")",
";",
"if",
"(",
"idx",
"<",
"vSize",
")",
"{",
"return",
"MVecArray",
".",
"setValue",
"(",
"idx",
",",
"val",
",",
"varBeliefs",
")",
";",
"}",
"else",
"{",
"return",
"MVecArray",
".",
"setValue",
"(",
"idx",
"-",
"vSize",
",",
"val",
",",
"facBeliefs",
")",
";",
"}",
"}"
] |
Sets a particular value by treating this object as a vector.
NOTE: This implementation is O(n).
@param idx The index of the value to set.
@param val The value to set.
@return The previous value at that index.
|
[
"Sets",
"a",
"particular",
"value",
"by",
"treating",
"this",
"object",
"as",
"a",
"vector",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/inf/Beliefs.java#L81-L88
|
12,257
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/data/bayesnet/BayesNetReader.java
|
BayesNetReader.readBnAsFg
|
public FactorGraph readBnAsFg(File networkFile, File cpdFile) throws IOException {
return readBnAsFg(new FileInputStream(networkFile), new FileInputStream(cpdFile));
}
|
java
|
public FactorGraph readBnAsFg(File networkFile, File cpdFile) throws IOException {
return readBnAsFg(new FileInputStream(networkFile), new FileInputStream(cpdFile));
}
|
[
"public",
"FactorGraph",
"readBnAsFg",
"(",
"File",
"networkFile",
",",
"File",
"cpdFile",
")",
"throws",
"IOException",
"{",
"return",
"readBnAsFg",
"(",
"new",
"FileInputStream",
"(",
"networkFile",
")",
",",
"new",
"FileInputStream",
"(",
"cpdFile",
")",
")",
";",
"}"
] |
Reads a Bayesian Network from a network file and a CPD file, and returns
a factor graph representation of it.
|
[
"Reads",
"a",
"Bayesian",
"Network",
"from",
"a",
"network",
"file",
"and",
"a",
"CPD",
"file",
"and",
"returns",
"a",
"factor",
"graph",
"representation",
"of",
"it",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/data/bayesnet/BayesNetReader.java#L42-L44
|
12,258
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/data/bayesnet/BayesNetReader.java
|
BayesNetReader.readBnAsFg
|
public FactorGraph readBnAsFg(InputStream networkIs, InputStream cpdIs) throws IOException {
// Read network file.
BufferedReader networkReader = new BufferedReader(new InputStreamReader(networkIs));
// -- read the number of variables.
int numVars = Integer.parseInt(networkReader.readLine().trim());
varMap = new HashMap<String,Var>();
VarSet allVars = new VarSet();
for (int i = 0; i < numVars; i++) {
Var var = parseVar(networkReader.readLine());
allVars.add(var);
varMap.put(var.getName(), var);
}
assert (allVars.size() == numVars);
// -- read the dependencies between variables.
// ....or not...
networkReader.close();
// Read CPD file.
BufferedReader cpdReader = new BufferedReader(new InputStreamReader(cpdIs));
factorMap = new LinkedHashMap<VarSet, ExplicitFactor>();
String line;
while ((line = cpdReader.readLine()) != null) {
// Parse out the variable configuration.
VarConfig config = new VarConfig();
String[] assns = whitespaceOrComma.split(line);
for (int i=0; i<assns.length-1; i++) {
String assn = assns[i];
String[] va = equals.split(assn);
assert(va.length == 2);
String varName = va[0];
String stateName = va[1];
config.put(varMap.get(varName), stateName);
}
// The double is the last value on the line.
double value = Double.parseDouble(assns[assns.length-1]);
// Factor graphs store the log value.
value = FastMath.log(value);
// Get the factor for this configuration, creating a new one if necessary.
VarSet vars = config.getVars();
ExplicitFactor f = factorMap.get(vars);
if (f == null) { f = new ExplicitFactor(vars); }
// Set the value in the factor.
f.setValue(config.getConfigIndex(), value);
factorMap.put(vars, f);
}
cpdReader.close();
// Create the factor graph.
FactorGraph fg = new FactorGraph();
for (ExplicitFactor f : factorMap.values()) {
fg.addFactor(f);
}
return fg;
}
|
java
|
public FactorGraph readBnAsFg(InputStream networkIs, InputStream cpdIs) throws IOException {
// Read network file.
BufferedReader networkReader = new BufferedReader(new InputStreamReader(networkIs));
// -- read the number of variables.
int numVars = Integer.parseInt(networkReader.readLine().trim());
varMap = new HashMap<String,Var>();
VarSet allVars = new VarSet();
for (int i = 0; i < numVars; i++) {
Var var = parseVar(networkReader.readLine());
allVars.add(var);
varMap.put(var.getName(), var);
}
assert (allVars.size() == numVars);
// -- read the dependencies between variables.
// ....or not...
networkReader.close();
// Read CPD file.
BufferedReader cpdReader = new BufferedReader(new InputStreamReader(cpdIs));
factorMap = new LinkedHashMap<VarSet, ExplicitFactor>();
String line;
while ((line = cpdReader.readLine()) != null) {
// Parse out the variable configuration.
VarConfig config = new VarConfig();
String[] assns = whitespaceOrComma.split(line);
for (int i=0; i<assns.length-1; i++) {
String assn = assns[i];
String[] va = equals.split(assn);
assert(va.length == 2);
String varName = va[0];
String stateName = va[1];
config.put(varMap.get(varName), stateName);
}
// The double is the last value on the line.
double value = Double.parseDouble(assns[assns.length-1]);
// Factor graphs store the log value.
value = FastMath.log(value);
// Get the factor for this configuration, creating a new one if necessary.
VarSet vars = config.getVars();
ExplicitFactor f = factorMap.get(vars);
if (f == null) { f = new ExplicitFactor(vars); }
// Set the value in the factor.
f.setValue(config.getConfigIndex(), value);
factorMap.put(vars, f);
}
cpdReader.close();
// Create the factor graph.
FactorGraph fg = new FactorGraph();
for (ExplicitFactor f : factorMap.values()) {
fg.addFactor(f);
}
return fg;
}
|
[
"public",
"FactorGraph",
"readBnAsFg",
"(",
"InputStream",
"networkIs",
",",
"InputStream",
"cpdIs",
")",
"throws",
"IOException",
"{",
"// Read network file.",
"BufferedReader",
"networkReader",
"=",
"new",
"BufferedReader",
"(",
"new",
"InputStreamReader",
"(",
"networkIs",
")",
")",
";",
"// -- read the number of variables.",
"int",
"numVars",
"=",
"Integer",
".",
"parseInt",
"(",
"networkReader",
".",
"readLine",
"(",
")",
".",
"trim",
"(",
")",
")",
";",
"varMap",
"=",
"new",
"HashMap",
"<",
"String",
",",
"Var",
">",
"(",
")",
";",
"VarSet",
"allVars",
"=",
"new",
"VarSet",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"numVars",
";",
"i",
"++",
")",
"{",
"Var",
"var",
"=",
"parseVar",
"(",
"networkReader",
".",
"readLine",
"(",
")",
")",
";",
"allVars",
".",
"add",
"(",
"var",
")",
";",
"varMap",
".",
"put",
"(",
"var",
".",
"getName",
"(",
")",
",",
"var",
")",
";",
"}",
"assert",
"(",
"allVars",
".",
"size",
"(",
")",
"==",
"numVars",
")",
";",
"// -- read the dependencies between variables.",
"// ....or not...",
"networkReader",
".",
"close",
"(",
")",
";",
"// Read CPD file.",
"BufferedReader",
"cpdReader",
"=",
"new",
"BufferedReader",
"(",
"new",
"InputStreamReader",
"(",
"cpdIs",
")",
")",
";",
"factorMap",
"=",
"new",
"LinkedHashMap",
"<",
"VarSet",
",",
"ExplicitFactor",
">",
"(",
")",
";",
"String",
"line",
";",
"while",
"(",
"(",
"line",
"=",
"cpdReader",
".",
"readLine",
"(",
")",
")",
"!=",
"null",
")",
"{",
"// Parse out the variable configuration. ",
"VarConfig",
"config",
"=",
"new",
"VarConfig",
"(",
")",
";",
"String",
"[",
"]",
"assns",
"=",
"whitespaceOrComma",
".",
"split",
"(",
"line",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"assns",
".",
"length",
"-",
"1",
";",
"i",
"++",
")",
"{",
"String",
"assn",
"=",
"assns",
"[",
"i",
"]",
";",
"String",
"[",
"]",
"va",
"=",
"equals",
".",
"split",
"(",
"assn",
")",
";",
"assert",
"(",
"va",
".",
"length",
"==",
"2",
")",
";",
"String",
"varName",
"=",
"va",
"[",
"0",
"]",
";",
"String",
"stateName",
"=",
"va",
"[",
"1",
"]",
";",
"config",
".",
"put",
"(",
"varMap",
".",
"get",
"(",
"varName",
")",
",",
"stateName",
")",
";",
"}",
"// The double is the last value on the line.",
"double",
"value",
"=",
"Double",
".",
"parseDouble",
"(",
"assns",
"[",
"assns",
".",
"length",
"-",
"1",
"]",
")",
";",
"// Factor graphs store the log value.",
"value",
"=",
"FastMath",
".",
"log",
"(",
"value",
")",
";",
"// Get the factor for this configuration, creating a new one if necessary.",
"VarSet",
"vars",
"=",
"config",
".",
"getVars",
"(",
")",
";",
"ExplicitFactor",
"f",
"=",
"factorMap",
".",
"get",
"(",
"vars",
")",
";",
"if",
"(",
"f",
"==",
"null",
")",
"{",
"f",
"=",
"new",
"ExplicitFactor",
"(",
"vars",
")",
";",
"}",
"// Set the value in the factor.",
"f",
".",
"setValue",
"(",
"config",
".",
"getConfigIndex",
"(",
")",
",",
"value",
")",
";",
"factorMap",
".",
"put",
"(",
"vars",
",",
"f",
")",
";",
"}",
"cpdReader",
".",
"close",
"(",
")",
";",
"// Create the factor graph.",
"FactorGraph",
"fg",
"=",
"new",
"FactorGraph",
"(",
")",
";",
"for",
"(",
"ExplicitFactor",
"f",
":",
"factorMap",
".",
"values",
"(",
")",
")",
"{",
"fg",
".",
"addFactor",
"(",
"f",
")",
";",
"}",
"return",
"fg",
";",
"}"
] |
Reads a Bayesian Network from a network InputStream and a CPD InputStream, and returns
a factor graph representation of it.
|
[
"Reads",
"a",
"Bayesian",
"Network",
"from",
"a",
"network",
"InputStream",
"and",
"a",
"CPD",
"InputStream",
"and",
"returns",
"a",
"factor",
"graph",
"representation",
"of",
"it",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/data/bayesnet/BayesNetReader.java#L50-L110
|
12,259
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/data/bayesnet/BayesNetReader.java
|
BayesNetReader.parseVar
|
private static Var parseVar(String varLine) {
String[] ws = whitespace.split(varLine);
String name = ws[0];
List<String> stateNames = Arrays.asList(comma.split(ws[1]));
int numStates = stateNames.size();
return new Var(VarType.PREDICTED, numStates, name, stateNames);
}
|
java
|
private static Var parseVar(String varLine) {
String[] ws = whitespace.split(varLine);
String name = ws[0];
List<String> stateNames = Arrays.asList(comma.split(ws[1]));
int numStates = stateNames.size();
return new Var(VarType.PREDICTED, numStates, name, stateNames);
}
|
[
"private",
"static",
"Var",
"parseVar",
"(",
"String",
"varLine",
")",
"{",
"String",
"[",
"]",
"ws",
"=",
"whitespace",
".",
"split",
"(",
"varLine",
")",
";",
"String",
"name",
"=",
"ws",
"[",
"0",
"]",
";",
"List",
"<",
"String",
">",
"stateNames",
"=",
"Arrays",
".",
"asList",
"(",
"comma",
".",
"split",
"(",
"ws",
"[",
"1",
"]",
")",
")",
";",
"int",
"numStates",
"=",
"stateNames",
".",
"size",
"(",
")",
";",
"return",
"new",
"Var",
"(",
"VarType",
".",
"PREDICTED",
",",
"numStates",
",",
"name",
",",
"stateNames",
")",
";",
"}"
] |
Reads a variable from a line containing the variable name, a space, then
a comma-separated list of the values it can take.
|
[
"Reads",
"a",
"variable",
"from",
"a",
"line",
"containing",
"the",
"variable",
"name",
"a",
"space",
"then",
"a",
"comma",
"-",
"separated",
"list",
"of",
"the",
"values",
"it",
"can",
"take",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/data/bayesnet/BayesNetReader.java#L116-L122
|
12,260
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/sch/util/OrderedSet.java
|
OrderedSet.add
|
@Override
public boolean add(T e) {
if (elements.add(e)) {
ordered.add(e);
return true;
} else {
return false;
}
}
|
java
|
@Override
public boolean add(T e) {
if (elements.add(e)) {
ordered.add(e);
return true;
} else {
return false;
}
}
|
[
"@",
"Override",
"public",
"boolean",
"add",
"(",
"T",
"e",
")",
"{",
"if",
"(",
"elements",
".",
"add",
"(",
"e",
")",
")",
"{",
"ordered",
".",
"add",
"(",
"e",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
maintain the set so that it is easy to test membership, the list so that
there is a fixed order
|
[
"maintain",
"the",
"set",
"so",
"that",
"it",
"is",
"easy",
"to",
"test",
"membership",
"the",
"list",
"so",
"that",
"there",
"is",
"a",
"fixed",
"order"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/sch/util/OrderedSet.java#L61-L69
|
12,261
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/sch/util/OrderedSet.java
|
OrderedSet.remove
|
@Override
public boolean remove(Object o) {
if (elements.remove(o)) {
ordered.remove(o);
return true;
} else {
return false;
}
}
|
java
|
@Override
public boolean remove(Object o) {
if (elements.remove(o)) {
ordered.remove(o);
return true;
} else {
return false;
}
}
|
[
"@",
"Override",
"public",
"boolean",
"remove",
"(",
"Object",
"o",
")",
"{",
"if",
"(",
"elements",
".",
"remove",
"(",
"o",
")",
")",
"{",
"ordered",
".",
"remove",
"(",
"o",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
remove will be slow
|
[
"remove",
"will",
"be",
"slow"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/sch/util/OrderedSet.java#L74-L83
|
12,262
|
mcaserta/spring-crypto-utils
|
src/main/java/com/springcryptoutils/core/digest/DigesterImpl.java
|
DigesterImpl.digest
|
public String digest(String message) {
final byte[] messageAsByteArray;
try {
messageAsByteArray = message.getBytes(charsetName);
} catch (UnsupportedEncodingException e) {
throw new DigestException("error converting message to byte array: charsetName=" + charsetName, e);
}
final byte[] digest = digest(messageAsByteArray);
switch (outputMode) {
case BASE64:
return Base64.encodeBase64String(digest);
case HEX:
return Hex.encodeHexString(digest);
default:
return null;
}
}
|
java
|
public String digest(String message) {
final byte[] messageAsByteArray;
try {
messageAsByteArray = message.getBytes(charsetName);
} catch (UnsupportedEncodingException e) {
throw new DigestException("error converting message to byte array: charsetName=" + charsetName, e);
}
final byte[] digest = digest(messageAsByteArray);
switch (outputMode) {
case BASE64:
return Base64.encodeBase64String(digest);
case HEX:
return Hex.encodeHexString(digest);
default:
return null;
}
}
|
[
"public",
"String",
"digest",
"(",
"String",
"message",
")",
"{",
"final",
"byte",
"[",
"]",
"messageAsByteArray",
";",
"try",
"{",
"messageAsByteArray",
"=",
"message",
".",
"getBytes",
"(",
"charsetName",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e",
")",
"{",
"throw",
"new",
"DigestException",
"(",
"\"error converting message to byte array: charsetName=\"",
"+",
"charsetName",
",",
"e",
")",
";",
"}",
"final",
"byte",
"[",
"]",
"digest",
"=",
"digest",
"(",
"messageAsByteArray",
")",
";",
"switch",
"(",
"outputMode",
")",
"{",
"case",
"BASE64",
":",
"return",
"Base64",
".",
"encodeBase64String",
"(",
"digest",
")",
";",
"case",
"HEX",
":",
"return",
"Hex",
".",
"encodeHexString",
"(",
"digest",
")",
";",
"default",
":",
"return",
"null",
";",
"}",
"}"
] |
Returns the message digest. The representation of the message digest
depends on the outputMode property.
@param message the message
@return the message digest
@see #setOutputMode(OutputMode)
|
[
"Returns",
"the",
"message",
"digest",
".",
"The",
"representation",
"of",
"the",
"message",
"digest",
"depends",
"on",
"the",
"outputMode",
"property",
"."
] |
1dbf6211542fb1e3f9297941d691e7e89cc72c46
|
https://github.com/mcaserta/spring-crypto-utils/blob/1dbf6211542fb1e3f9297941d691e7e89cc72c46/src/main/java/com/springcryptoutils/core/digest/DigesterImpl.java#L97-L116
|
12,263
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/sch/graph/WeightedIntDiGraph.java
|
WeightedIntDiGraph.addEdge
|
@Override
public void addEdge(DiEdge e) {
if (!getEdges().contains(e)) {
super.addEdge(e);
weights.put(e, makeDefaultWeight.apply(e));
}
}
|
java
|
@Override
public void addEdge(DiEdge e) {
if (!getEdges().contains(e)) {
super.addEdge(e);
weights.put(e, makeDefaultWeight.apply(e));
}
}
|
[
"@",
"Override",
"public",
"void",
"addEdge",
"(",
"DiEdge",
"e",
")",
"{",
"if",
"(",
"!",
"getEdges",
"(",
")",
".",
"contains",
"(",
"e",
")",
")",
"{",
"super",
".",
"addEdge",
"(",
"e",
")",
";",
"weights",
".",
"put",
"(",
"e",
",",
"makeDefaultWeight",
".",
"apply",
"(",
"e",
")",
")",
";",
"}",
"}"
] |
Attempts to adds the edge to the graph with default weight if not already present;
If the edge is already present, does nothing.
|
[
"Attempts",
"to",
"adds",
"the",
"edge",
"to",
"the",
"graph",
"with",
"default",
"weight",
"if",
"not",
"already",
"present",
";",
"If",
"the",
"edge",
"is",
"already",
"present",
"does",
"nothing",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/sch/graph/WeightedIntDiGraph.java#L50-L56
|
12,264
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/sch/graph/WeightedIntDiGraph.java
|
WeightedIntDiGraph.addEdge
|
public void addEdge(DiEdge e, double w) {
if (!getEdges().contains(e)) {
super.addEdge(e);
weights.put(e, w);
}
}
|
java
|
public void addEdge(DiEdge e, double w) {
if (!getEdges().contains(e)) {
super.addEdge(e);
weights.put(e, w);
}
}
|
[
"public",
"void",
"addEdge",
"(",
"DiEdge",
"e",
",",
"double",
"w",
")",
"{",
"if",
"(",
"!",
"getEdges",
"(",
")",
".",
"contains",
"(",
"e",
")",
")",
"{",
"super",
".",
"addEdge",
"(",
"e",
")",
";",
"weights",
".",
"put",
"(",
"e",
",",
"w",
")",
";",
"}",
"}"
] |
Adds the edge with the given weight
|
[
"Adds",
"the",
"edge",
"with",
"the",
"given",
"weight"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/sch/graph/WeightedIntDiGraph.java#L61-L66
|
12,265
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/sch/graph/WeightedIntDiGraph.java
|
WeightedIntDiGraph.setWeight
|
public void setWeight(int s, int t, double w) {
DiEdge e = edge(s, t);
assertEdge(e);
weights.put(e, w);
}
|
java
|
public void setWeight(int s, int t, double w) {
DiEdge e = edge(s, t);
assertEdge(e);
weights.put(e, w);
}
|
[
"public",
"void",
"setWeight",
"(",
"int",
"s",
",",
"int",
"t",
",",
"double",
"w",
")",
"{",
"DiEdge",
"e",
"=",
"edge",
"(",
"s",
",",
"t",
")",
";",
"assertEdge",
"(",
"e",
")",
";",
"weights",
".",
"put",
"(",
"e",
",",
"w",
")",
";",
"}"
] |
Sets the weight of the edge s->t to be w if the edge is present,
otherwise, an IndexOutOfBoundsException is thrown
|
[
"Sets",
"the",
"weight",
"of",
"the",
"edge",
"s",
"-",
">",
"t",
"to",
"be",
"w",
"if",
"the",
"edge",
"is",
"present",
"otherwise",
"an",
"IndexOutOfBoundsException",
"is",
"thrown"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/sch/graph/WeightedIntDiGraph.java#L112-L116
|
12,266
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/collections/QLists.java
|
QLists.sublist
|
public static <X> ArrayList<X> sublist(List<X> list, int start, int end) {
ArrayList<X> sublist = new ArrayList<X>();
for (int i=start; i<end; i++) {
sublist.add(list.get(i));
}
return sublist;
}
|
java
|
public static <X> ArrayList<X> sublist(List<X> list, int start, int end) {
ArrayList<X> sublist = new ArrayList<X>();
for (int i=start; i<end; i++) {
sublist.add(list.get(i));
}
return sublist;
}
|
[
"public",
"static",
"<",
"X",
">",
"ArrayList",
"<",
"X",
">",
"sublist",
"(",
"List",
"<",
"X",
">",
"list",
",",
"int",
"start",
",",
"int",
"end",
")",
"{",
"ArrayList",
"<",
"X",
">",
"sublist",
"=",
"new",
"ArrayList",
"<",
"X",
">",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"start",
";",
"i",
"<",
"end",
";",
"i",
"++",
")",
"{",
"sublist",
".",
"add",
"(",
"list",
".",
"get",
"(",
"i",
")",
")",
";",
"}",
"return",
"sublist",
";",
"}"
] |
Creates a new list containing a slice of the original list.
@param list The original list.
@param start The index of the first element of the slice (inclusive).
@param end The index of the last element of the slice (exclusive).
@return A sublist containing elements [start, end).
|
[
"Creates",
"a",
"new",
"list",
"containing",
"a",
"slice",
"of",
"the",
"original",
"list",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/collections/QLists.java#L26-L32
|
12,267
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/collections/QLists.java
|
QLists.getInternedList
|
public static ArrayList<String> getInternedList(List<String> oldList) {
ArrayList<String> newList = new ArrayList<String>(oldList.size());
for (String elem : oldList) {
newList.add(elem.intern());
}
return newList;
}
|
java
|
public static ArrayList<String> getInternedList(List<String> oldList) {
ArrayList<String> newList = new ArrayList<String>(oldList.size());
for (String elem : oldList) {
newList.add(elem.intern());
}
return newList;
}
|
[
"public",
"static",
"ArrayList",
"<",
"String",
">",
"getInternedList",
"(",
"List",
"<",
"String",
">",
"oldList",
")",
"{",
"ArrayList",
"<",
"String",
">",
"newList",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
"oldList",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"String",
"elem",
":",
"oldList",
")",
"{",
"newList",
".",
"add",
"(",
"elem",
".",
"intern",
"(",
")",
")",
";",
"}",
"return",
"newList",
";",
"}"
] |
Gets a new list of Strings that have been interned.
|
[
"Gets",
"a",
"new",
"list",
"of",
"Strings",
"that",
"have",
"been",
"interned",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/collections/QLists.java#L97-L103
|
12,268
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/collections/QLists.java
|
QLists.intern
|
public static void intern(List<String> list) {
if (list == null) {
return;
}
for (int i=0; i<list.size(); i++) {
String interned = list.get(i);
if (interned != null) {
interned = interned.intern();
}
list.set(i, interned);
}
}
|
java
|
public static void intern(List<String> list) {
if (list == null) {
return;
}
for (int i=0; i<list.size(); i++) {
String interned = list.get(i);
if (interned != null) {
interned = interned.intern();
}
list.set(i, interned);
}
}
|
[
"public",
"static",
"void",
"intern",
"(",
"List",
"<",
"String",
">",
"list",
")",
"{",
"if",
"(",
"list",
"==",
"null",
")",
"{",
"return",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"list",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"String",
"interned",
"=",
"list",
".",
"get",
"(",
"i",
")",
";",
"if",
"(",
"interned",
"!=",
"null",
")",
"{",
"interned",
"=",
"interned",
".",
"intern",
"(",
")",
";",
"}",
"list",
".",
"set",
"(",
"i",
",",
"interned",
")",
";",
"}",
"}"
] |
Interns a list of strings in place.
|
[
"Interns",
"a",
"list",
"of",
"strings",
"in",
"place",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/collections/QLists.java#L106-L117
|
12,269
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/sch/util/Indexed.java
|
Indexed.collect
|
public static <T> Collection<T> collect(Iterable<T> stream) {
LinkedList<T> collection = new LinkedList<>();
for (T e : stream) {
collection.add(e);
}
return collection;
}
|
java
|
public static <T> Collection<T> collect(Iterable<T> stream) {
LinkedList<T> collection = new LinkedList<>();
for (T e : stream) {
collection.add(e);
}
return collection;
}
|
[
"public",
"static",
"<",
"T",
">",
"Collection",
"<",
"T",
">",
"collect",
"(",
"Iterable",
"<",
"T",
">",
"stream",
")",
"{",
"LinkedList",
"<",
"T",
">",
"collection",
"=",
"new",
"LinkedList",
"<>",
"(",
")",
";",
"for",
"(",
"T",
"e",
":",
"stream",
")",
"{",
"collection",
".",
"add",
"(",
"e",
")",
";",
"}",
"return",
"collection",
";",
"}"
] |
Returns a Collections that contains all of the objects from the
underlying stream in order
|
[
"Returns",
"a",
"Collections",
"that",
"contains",
"all",
"of",
"the",
"objects",
"from",
"the",
"underlying",
"stream",
"in",
"order"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/sch/util/Indexed.java#L72-L78
|
12,270
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/sch/util/Indexed.java
|
Indexed.enumerate
|
public static <T> Iterable<Indexed<T>> enumerate(Iterable<T> stream) {
return new Iterable<Indexed<T>>() {
@Override
public Iterator<Indexed<T>> iterator() {
Iterator<T> itr = stream.iterator();
return new Iterator<Indexed<T>>() {
private int i = 0;
@Override
public boolean hasNext() {
return itr.hasNext();
}
@Override
public Indexed<T> next() {
Indexed<T> nextPair = new Indexed<T>(itr.next(), i);
i++;
return nextPair;
}
};
}
};
}
|
java
|
public static <T> Iterable<Indexed<T>> enumerate(Iterable<T> stream) {
return new Iterable<Indexed<T>>() {
@Override
public Iterator<Indexed<T>> iterator() {
Iterator<T> itr = stream.iterator();
return new Iterator<Indexed<T>>() {
private int i = 0;
@Override
public boolean hasNext() {
return itr.hasNext();
}
@Override
public Indexed<T> next() {
Indexed<T> nextPair = new Indexed<T>(itr.next(), i);
i++;
return nextPair;
}
};
}
};
}
|
[
"public",
"static",
"<",
"T",
">",
"Iterable",
"<",
"Indexed",
"<",
"T",
">",
">",
"enumerate",
"(",
"Iterable",
"<",
"T",
">",
"stream",
")",
"{",
"return",
"new",
"Iterable",
"<",
"Indexed",
"<",
"T",
">",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"Iterator",
"<",
"Indexed",
"<",
"T",
">",
">",
"iterator",
"(",
")",
"{",
"Iterator",
"<",
"T",
">",
"itr",
"=",
"stream",
".",
"iterator",
"(",
")",
";",
"return",
"new",
"Iterator",
"<",
"Indexed",
"<",
"T",
">",
">",
"(",
")",
"{",
"private",
"int",
"i",
"=",
"0",
";",
"@",
"Override",
"public",
"boolean",
"hasNext",
"(",
")",
"{",
"return",
"itr",
".",
"hasNext",
"(",
")",
";",
"}",
"@",
"Override",
"public",
"Indexed",
"<",
"T",
">",
"next",
"(",
")",
"{",
"Indexed",
"<",
"T",
">",
"nextPair",
"=",
"new",
"Indexed",
"<",
"T",
">",
"(",
"itr",
".",
"next",
"(",
")",
",",
"i",
")",
";",
"i",
"++",
";",
"return",
"nextPair",
";",
"}",
"}",
";",
"}",
"}",
";",
"}"
] |
Returns an iterable over Index objects that each hold one of the original
objects of the stream as well its index in the stream
|
[
"Returns",
"an",
"iterable",
"over",
"Index",
"objects",
"that",
"each",
"hold",
"one",
"of",
"the",
"original",
"objects",
"of",
"the",
"stream",
"as",
"well",
"its",
"index",
"in",
"the",
"stream"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/sch/util/Indexed.java#L84-L108
|
12,271
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/parse/dep/edmonds/DisjointSets.java
|
DisjointSets.find
|
public int find(int element) {
if (trees[element] != element)
trees[element] = find(trees[element]);
return trees[element];
}
|
java
|
public int find(int element) {
if (trees[element] != element)
trees[element] = find(trees[element]);
return trees[element];
}
|
[
"public",
"int",
"find",
"(",
"int",
"element",
")",
"{",
"if",
"(",
"trees",
"[",
"element",
"]",
"!=",
"element",
")",
"trees",
"[",
"element",
"]",
"=",
"find",
"(",
"trees",
"[",
"element",
"]",
")",
";",
"return",
"trees",
"[",
"element",
"]",
";",
"}"
] |
Return the set where the given element is. This implementation compresses
the followed path.
@param element
@return
|
[
"Return",
"the",
"set",
"where",
"the",
"given",
"element",
"is",
".",
"This",
"implementation",
"compresses",
"the",
"followed",
"path",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/parse/dep/edmonds/DisjointSets.java#L40-L44
|
12,272
|
mcaserta/spring-crypto-utils
|
src/main/java/com/springcryptoutils/core/certificate/CertificateRegistryByAliasImpl.java
|
CertificateRegistryByAliasImpl.get
|
public Certificate get(KeyStoreChooser keyStoreChooser, CertificateChooserByAlias certificateChooserByAlias) {
CacheCert cacheCert = new CacheCert(keyStoreChooser.getKeyStoreName(), certificateChooserByAlias.getAlias());
Certificate retrievedCertificate = cache.get(cacheCert);
if (retrievedCertificate != null) {
return retrievedCertificate;
}
KeyStore keyStore = keyStoreRegistry.get(keyStoreChooser);
if (keyStore != null) {
CertificateFactoryBean factory = new CertificateFactoryBean();
factory.setKeystore(keyStore);
factory.setAlias(certificateChooserByAlias.getAlias());
try {
factory.afterPropertiesSet();
Certificate certificate = (Certificate) factory.getObject();
if (certificate != null) {
cache.put(cacheCert, certificate);
}
return certificate;
} catch (Exception e) {
throw new CertificateException("error initializing the certificate factory bean", e);
}
}
return null;
}
|
java
|
public Certificate get(KeyStoreChooser keyStoreChooser, CertificateChooserByAlias certificateChooserByAlias) {
CacheCert cacheCert = new CacheCert(keyStoreChooser.getKeyStoreName(), certificateChooserByAlias.getAlias());
Certificate retrievedCertificate = cache.get(cacheCert);
if (retrievedCertificate != null) {
return retrievedCertificate;
}
KeyStore keyStore = keyStoreRegistry.get(keyStoreChooser);
if (keyStore != null) {
CertificateFactoryBean factory = new CertificateFactoryBean();
factory.setKeystore(keyStore);
factory.setAlias(certificateChooserByAlias.getAlias());
try {
factory.afterPropertiesSet();
Certificate certificate = (Certificate) factory.getObject();
if (certificate != null) {
cache.put(cacheCert, certificate);
}
return certificate;
} catch (Exception e) {
throw new CertificateException("error initializing the certificate factory bean", e);
}
}
return null;
}
|
[
"public",
"Certificate",
"get",
"(",
"KeyStoreChooser",
"keyStoreChooser",
",",
"CertificateChooserByAlias",
"certificateChooserByAlias",
")",
"{",
"CacheCert",
"cacheCert",
"=",
"new",
"CacheCert",
"(",
"keyStoreChooser",
".",
"getKeyStoreName",
"(",
")",
",",
"certificateChooserByAlias",
".",
"getAlias",
"(",
")",
")",
";",
"Certificate",
"retrievedCertificate",
"=",
"cache",
".",
"get",
"(",
"cacheCert",
")",
";",
"if",
"(",
"retrievedCertificate",
"!=",
"null",
")",
"{",
"return",
"retrievedCertificate",
";",
"}",
"KeyStore",
"keyStore",
"=",
"keyStoreRegistry",
".",
"get",
"(",
"keyStoreChooser",
")",
";",
"if",
"(",
"keyStore",
"!=",
"null",
")",
"{",
"CertificateFactoryBean",
"factory",
"=",
"new",
"CertificateFactoryBean",
"(",
")",
";",
"factory",
".",
"setKeystore",
"(",
"keyStore",
")",
";",
"factory",
".",
"setAlias",
"(",
"certificateChooserByAlias",
".",
"getAlias",
"(",
")",
")",
";",
"try",
"{",
"factory",
".",
"afterPropertiesSet",
"(",
")",
";",
"Certificate",
"certificate",
"=",
"(",
"Certificate",
")",
"factory",
".",
"getObject",
"(",
")",
";",
"if",
"(",
"certificate",
"!=",
"null",
")",
"{",
"cache",
".",
"put",
"(",
"cacheCert",
",",
"certificate",
")",
";",
"}",
"return",
"certificate",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"CertificateException",
"(",
"\"error initializing the certificate factory bean\"",
",",
"e",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns the selected certificate or null if not found.
@param keyStoreChooser the keystore chooser
@param certificateChooserByAlias the certificate chooser by alias
@return the selected certificate or null if not found
|
[
"Returns",
"the",
"selected",
"certificate",
"or",
"null",
"if",
"not",
"found",
"."
] |
1dbf6211542fb1e3f9297941d691e7e89cc72c46
|
https://github.com/mcaserta/spring-crypto-utils/blob/1dbf6211542fb1e3f9297941d691e7e89cc72c46/src/main/java/com/springcryptoutils/core/certificate/CertificateRegistryByAliasImpl.java#L50-L78
|
12,273
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/ServerRoomEventHandler.java
|
ServerRoomEventHandler.checkHandler
|
protected boolean checkHandler(RoomHandlerClass handler,
ApiRoom roomAgent, Object user) {
return (handler.getRoomClass().isAssignableFrom(roomAgent.getClass())) &&
(roomAgent.getName().startsWith(handler.getRoomName()));
}
|
java
|
protected boolean checkHandler(RoomHandlerClass handler,
ApiRoom roomAgent, Object user) {
return (handler.getRoomClass().isAssignableFrom(roomAgent.getClass())) &&
(roomAgent.getName().startsWith(handler.getRoomName()));
}
|
[
"protected",
"boolean",
"checkHandler",
"(",
"RoomHandlerClass",
"handler",
",",
"ApiRoom",
"roomAgent",
",",
"Object",
"user",
")",
"{",
"return",
"(",
"handler",
".",
"getRoomClass",
"(",
")",
".",
"isAssignableFrom",
"(",
"roomAgent",
".",
"getClass",
"(",
")",
")",
")",
"&&",
"(",
"roomAgent",
".",
"getName",
"(",
")",
".",
"startsWith",
"(",
"handler",
".",
"getRoomName",
"(",
")",
")",
")",
";",
"}"
] |
Validate the handler
@param handler structure of handler class
@param roomAgent room agent object
@param user user agent object
@return true or false
|
[
"Validate",
"the",
"handler"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/ServerRoomEventHandler.java#L93-L97
|
12,274
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/ServerRoomEventHandler.java
|
ServerRoomEventHandler.callHandleMethod
|
private void callHandleMethod(Method method, Object instance,
Object roomAgent, Object userAgent) {
ReflectMethodUtil.invokeHandleMethod(method,
instance, context, roomAgent, userAgent);
}
|
java
|
private void callHandleMethod(Method method, Object instance,
Object roomAgent, Object userAgent) {
ReflectMethodUtil.invokeHandleMethod(method,
instance, context, roomAgent, userAgent);
}
|
[
"private",
"void",
"callHandleMethod",
"(",
"Method",
"method",
",",
"Object",
"instance",
",",
"Object",
"roomAgent",
",",
"Object",
"userAgent",
")",
"{",
"ReflectMethodUtil",
".",
"invokeHandleMethod",
"(",
"method",
",",
"instance",
",",
"context",
",",
"roomAgent",
",",
"userAgent",
")",
";",
"}"
] |
Invoke handle method
@param method handle method
@param instance object to invoke method
@param roomAgent room agent object
@param userAgent user agent object
|
[
"Invoke",
"handle",
"method"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/ServerRoomEventHandler.java#L107-L111
|
12,275
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/UpdateRoomImpl.java
|
UpdateRoomImpl.execute
|
@SuppressWarnings("unchecked")
@Override
public ApiRoom execute() {
Room sfsRoom = CommandUtil.getSfsRoom(agent, extension);
User sfsUser = CommandUtil.getSfsUser(user, api);
//check null
if(sfsRoom == null) return null;
//get variables from agent
AgentClassUnwrapper unwrapper = context.getRoomAgentClass(
agent.getClass()).getUnwrapper();
List<RoomVariable> variables =
new RoomAgentSerializer().serialize(unwrapper, agent);
List<RoomVariable> answer = variables;
if(includedVars.size() > 0)
answer = getVariables(variables, includedVars);
answer.removeAll(getVariables(answer, excludedVars));
//notify to client and serverself
if(toClient) api.setRoomVariables(sfsUser, sfsRoom, answer);
//only for server
else sfsRoom.setVariables(answer);
return agent;
}
|
java
|
@SuppressWarnings("unchecked")
@Override
public ApiRoom execute() {
Room sfsRoom = CommandUtil.getSfsRoom(agent, extension);
User sfsUser = CommandUtil.getSfsUser(user, api);
//check null
if(sfsRoom == null) return null;
//get variables from agent
AgentClassUnwrapper unwrapper = context.getRoomAgentClass(
agent.getClass()).getUnwrapper();
List<RoomVariable> variables =
new RoomAgentSerializer().serialize(unwrapper, agent);
List<RoomVariable> answer = variables;
if(includedVars.size() > 0)
answer = getVariables(variables, includedVars);
answer.removeAll(getVariables(answer, excludedVars));
//notify to client and serverself
if(toClient) api.setRoomVariables(sfsUser, sfsRoom, answer);
//only for server
else sfsRoom.setVariables(answer);
return agent;
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"@",
"Override",
"public",
"ApiRoom",
"execute",
"(",
")",
"{",
"Room",
"sfsRoom",
"=",
"CommandUtil",
".",
"getSfsRoom",
"(",
"agent",
",",
"extension",
")",
";",
"User",
"sfsUser",
"=",
"CommandUtil",
".",
"getSfsUser",
"(",
"user",
",",
"api",
")",
";",
"//check null",
"if",
"(",
"sfsRoom",
"==",
"null",
")",
"return",
"null",
";",
"//get variables from agent",
"AgentClassUnwrapper",
"unwrapper",
"=",
"context",
".",
"getRoomAgentClass",
"(",
"agent",
".",
"getClass",
"(",
")",
")",
".",
"getUnwrapper",
"(",
")",
";",
"List",
"<",
"RoomVariable",
">",
"variables",
"=",
"new",
"RoomAgentSerializer",
"(",
")",
".",
"serialize",
"(",
"unwrapper",
",",
"agent",
")",
";",
"List",
"<",
"RoomVariable",
">",
"answer",
"=",
"variables",
";",
"if",
"(",
"includedVars",
".",
"size",
"(",
")",
">",
"0",
")",
"answer",
"=",
"getVariables",
"(",
"variables",
",",
"includedVars",
")",
";",
"answer",
".",
"removeAll",
"(",
"getVariables",
"(",
"answer",
",",
"excludedVars",
")",
")",
";",
"//notify to client and serverself",
"if",
"(",
"toClient",
")",
"api",
".",
"setRoomVariables",
"(",
"sfsUser",
",",
"sfsRoom",
",",
"answer",
")",
";",
"//only for server",
"else",
"sfsRoom",
".",
"setVariables",
"(",
"answer",
")",
";",
"return",
"agent",
";",
"}"
] |
Execute update room variables
|
[
"Execute",
"update",
"room",
"variables"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/UpdateRoomImpl.java#L46-L73
|
12,276
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/hypergraph/depparse/HyperDepParser.java
|
HyperDepParser.getEdgeMarginalsRealSemiring
|
public static EdgeScores getEdgeMarginalsRealSemiring(O2AllGraDpHypergraph graph, Scores sc) {
Algebra s = graph.getAlgebra();
int nplus = graph.getNumTokens()+1;
Hypernode[][][][] c = graph.getChart();
EdgeScores marg = new EdgeScores(graph.getNumTokens(), 0.0);
for (int width = 1; width < nplus; width++) {
for (int i = 0; i < nplus - width; i++) {
int j = i + width;
for (int g=0; g<nplus; g++) {
if (i <= g && g <= j && !(i==0 && g==O2AllGraDpHypergraph.NIL)) { continue; }
if (j > 0) {
marg.incrScore(i-1, j-1, s.toReal(sc.marginal[c[i][j][g][O2AllGraDpHypergraph.INCOMPLETE].getId()]));
}
if (i > 0) {
marg.incrScore(j-1, i-1, s.toReal(sc.marginal[c[j][i][g][O2AllGraDpHypergraph.INCOMPLETE].getId()]));
}
}
}
}
return marg;
}
|
java
|
public static EdgeScores getEdgeMarginalsRealSemiring(O2AllGraDpHypergraph graph, Scores sc) {
Algebra s = graph.getAlgebra();
int nplus = graph.getNumTokens()+1;
Hypernode[][][][] c = graph.getChart();
EdgeScores marg = new EdgeScores(graph.getNumTokens(), 0.0);
for (int width = 1; width < nplus; width++) {
for (int i = 0; i < nplus - width; i++) {
int j = i + width;
for (int g=0; g<nplus; g++) {
if (i <= g && g <= j && !(i==0 && g==O2AllGraDpHypergraph.NIL)) { continue; }
if (j > 0) {
marg.incrScore(i-1, j-1, s.toReal(sc.marginal[c[i][j][g][O2AllGraDpHypergraph.INCOMPLETE].getId()]));
}
if (i > 0) {
marg.incrScore(j-1, i-1, s.toReal(sc.marginal[c[j][i][g][O2AllGraDpHypergraph.INCOMPLETE].getId()]));
}
}
}
}
return marg;
}
|
[
"public",
"static",
"EdgeScores",
"getEdgeMarginalsRealSemiring",
"(",
"O2AllGraDpHypergraph",
"graph",
",",
"Scores",
"sc",
")",
"{",
"Algebra",
"s",
"=",
"graph",
".",
"getAlgebra",
"(",
")",
";",
"int",
"nplus",
"=",
"graph",
".",
"getNumTokens",
"(",
")",
"+",
"1",
";",
"Hypernode",
"[",
"]",
"[",
"]",
"[",
"]",
"[",
"]",
"c",
"=",
"graph",
".",
"getChart",
"(",
")",
";",
"EdgeScores",
"marg",
"=",
"new",
"EdgeScores",
"(",
"graph",
".",
"getNumTokens",
"(",
")",
",",
"0.0",
")",
";",
"for",
"(",
"int",
"width",
"=",
"1",
";",
"width",
"<",
"nplus",
";",
"width",
"++",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"nplus",
"-",
"width",
";",
"i",
"++",
")",
"{",
"int",
"j",
"=",
"i",
"+",
"width",
";",
"for",
"(",
"int",
"g",
"=",
"0",
";",
"g",
"<",
"nplus",
";",
"g",
"++",
")",
"{",
"if",
"(",
"i",
"<=",
"g",
"&&",
"g",
"<=",
"j",
"&&",
"!",
"(",
"i",
"==",
"0",
"&&",
"g",
"==",
"O2AllGraDpHypergraph",
".",
"NIL",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"j",
">",
"0",
")",
"{",
"marg",
".",
"incrScore",
"(",
"i",
"-",
"1",
",",
"j",
"-",
"1",
",",
"s",
".",
"toReal",
"(",
"sc",
".",
"marginal",
"[",
"c",
"[",
"i",
"]",
"[",
"j",
"]",
"[",
"g",
"]",
"[",
"O2AllGraDpHypergraph",
".",
"INCOMPLETE",
"]",
".",
"getId",
"(",
")",
"]",
")",
")",
";",
"}",
"if",
"(",
"i",
">",
"0",
")",
"{",
"marg",
".",
"incrScore",
"(",
"j",
"-",
"1",
",",
"i",
"-",
"1",
",",
"s",
".",
"toReal",
"(",
"sc",
".",
"marginal",
"[",
"c",
"[",
"j",
"]",
"[",
"i",
"]",
"[",
"g",
"]",
"[",
"O2AllGraDpHypergraph",
".",
"INCOMPLETE",
"]",
".",
"getId",
"(",
")",
"]",
")",
")",
";",
"}",
"}",
"}",
"}",
"return",
"marg",
";",
"}"
] |
Gets the edge marginals in the real semiring from an all-grandparents hypergraph and its marginals in scores.
|
[
"Gets",
"the",
"edge",
"marginals",
"in",
"the",
"real",
"semiring",
"from",
"an",
"all",
"-",
"grandparents",
"hypergraph",
"and",
"its",
"marginals",
"in",
"scores",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/hypergraph/depparse/HyperDepParser.java#L163-L184
|
12,277
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/globalfac/ProjDepTreeFactor.java
|
ProjDepTreeFactor.hasOneParentPerToken
|
public static boolean hasOneParentPerToken(int n, VarConfig vc) {
int[] parents = new int[n];
Arrays.fill(parents, -2);
for (Var v : vc.getVars()) {
if (v instanceof LinkVar) {
LinkVar link = (LinkVar) v;
if (vc.getState(v) == LinkVar.TRUE) {
if (parents[link.getChild()] != -2) {
// Multiple parents defined for the same child.
return false;
}
parents[link.getChild()] = link.getParent();
}
}
}
return !ArrayUtils.contains(parents, -2);
}
|
java
|
public static boolean hasOneParentPerToken(int n, VarConfig vc) {
int[] parents = new int[n];
Arrays.fill(parents, -2);
for (Var v : vc.getVars()) {
if (v instanceof LinkVar) {
LinkVar link = (LinkVar) v;
if (vc.getState(v) == LinkVar.TRUE) {
if (parents[link.getChild()] != -2) {
// Multiple parents defined for the same child.
return false;
}
parents[link.getChild()] = link.getParent();
}
}
}
return !ArrayUtils.contains(parents, -2);
}
|
[
"public",
"static",
"boolean",
"hasOneParentPerToken",
"(",
"int",
"n",
",",
"VarConfig",
"vc",
")",
"{",
"int",
"[",
"]",
"parents",
"=",
"new",
"int",
"[",
"n",
"]",
";",
"Arrays",
".",
"fill",
"(",
"parents",
",",
"-",
"2",
")",
";",
"for",
"(",
"Var",
"v",
":",
"vc",
".",
"getVars",
"(",
")",
")",
"{",
"if",
"(",
"v",
"instanceof",
"LinkVar",
")",
"{",
"LinkVar",
"link",
"=",
"(",
"LinkVar",
")",
"v",
";",
"if",
"(",
"vc",
".",
"getState",
"(",
"v",
")",
"==",
"LinkVar",
".",
"TRUE",
")",
"{",
"if",
"(",
"parents",
"[",
"link",
".",
"getChild",
"(",
")",
"]",
"!=",
"-",
"2",
")",
"{",
"// Multiple parents defined for the same child.",
"return",
"false",
";",
"}",
"parents",
"[",
"link",
".",
"getChild",
"(",
")",
"]",
"=",
"link",
".",
"getParent",
"(",
")",
";",
"}",
"}",
"}",
"return",
"!",
"ArrayUtils",
".",
"contains",
"(",
"parents",
",",
"-",
"2",
")",
";",
"}"
] |
Returns whether this variable assignment specifies one parent per token.
|
[
"Returns",
"whether",
"this",
"variable",
"assignment",
"specifies",
"one",
"parent",
"per",
"token",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/globalfac/ProjDepTreeFactor.java#L229-L245
|
12,278
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/globalfac/ProjDepTreeFactor.java
|
ProjDepTreeFactor.getParents
|
public static int[] getParents(int n, VarConfig vc) {
int[] parents = new int[n];
Arrays.fill(parents, -2);
for (Var v : vc.getVars()) {
if (v instanceof LinkVar) {
LinkVar link = (LinkVar) v;
if (vc.getState(v) == LinkVar.TRUE) {
if (parents[link.getChild()] != -2) {
throw new IllegalStateException(
"Multiple parents defined for the same child. Is this VarConfig for only one example?");
}
parents[link.getChild()] = link.getParent();
}
}
}
return parents;
}
|
java
|
public static int[] getParents(int n, VarConfig vc) {
int[] parents = new int[n];
Arrays.fill(parents, -2);
for (Var v : vc.getVars()) {
if (v instanceof LinkVar) {
LinkVar link = (LinkVar) v;
if (vc.getState(v) == LinkVar.TRUE) {
if (parents[link.getChild()] != -2) {
throw new IllegalStateException(
"Multiple parents defined for the same child. Is this VarConfig for only one example?");
}
parents[link.getChild()] = link.getParent();
}
}
}
return parents;
}
|
[
"public",
"static",
"int",
"[",
"]",
"getParents",
"(",
"int",
"n",
",",
"VarConfig",
"vc",
")",
"{",
"int",
"[",
"]",
"parents",
"=",
"new",
"int",
"[",
"n",
"]",
";",
"Arrays",
".",
"fill",
"(",
"parents",
",",
"-",
"2",
")",
";",
"for",
"(",
"Var",
"v",
":",
"vc",
".",
"getVars",
"(",
")",
")",
"{",
"if",
"(",
"v",
"instanceof",
"LinkVar",
")",
"{",
"LinkVar",
"link",
"=",
"(",
"LinkVar",
")",
"v",
";",
"if",
"(",
"vc",
".",
"getState",
"(",
"v",
")",
"==",
"LinkVar",
".",
"TRUE",
")",
"{",
"if",
"(",
"parents",
"[",
"link",
".",
"getChild",
"(",
")",
"]",
"!=",
"-",
"2",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Multiple parents defined for the same child. Is this VarConfig for only one example?\"",
")",
";",
"}",
"parents",
"[",
"link",
".",
"getChild",
"(",
")",
"]",
"=",
"link",
".",
"getParent",
"(",
")",
";",
"}",
"}",
"}",
"return",
"parents",
";",
"}"
] |
Extracts the parents as defined by a variable assignment for a single
sentence.
NOTE: This should NOT be used for decoding since a proper decoder will
enforce the tree constraint.
@param n The sentence length.
@param vc The variable assignment.
@return The parents array.
|
[
"Extracts",
"the",
"parents",
"as",
"defined",
"by",
"a",
"variable",
"assignment",
"for",
"a",
"single",
"sentence",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/globalfac/ProjDepTreeFactor.java#L258-L274
|
12,279
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/inf/BruteForceInferencer.java
|
BruteForceInferencer.getProductOfAllFactors
|
private static VarTensor getProductOfAllFactors(FactorGraph fg, Algebra s) {
VarTensor joint = new VarTensor(s, new VarSet(), s.one());
for (int a=0; a<fg.getNumFactors(); a++) {
Factor f = fg.getFactor(a);
VarTensor factor = safeNewVarTensor(s, f);
assert !factor.containsBadValues() : factor;
joint.prod(factor);
}
return joint;
}
|
java
|
private static VarTensor getProductOfAllFactors(FactorGraph fg, Algebra s) {
VarTensor joint = new VarTensor(s, new VarSet(), s.one());
for (int a=0; a<fg.getNumFactors(); a++) {
Factor f = fg.getFactor(a);
VarTensor factor = safeNewVarTensor(s, f);
assert !factor.containsBadValues() : factor;
joint.prod(factor);
}
return joint;
}
|
[
"private",
"static",
"VarTensor",
"getProductOfAllFactors",
"(",
"FactorGraph",
"fg",
",",
"Algebra",
"s",
")",
"{",
"VarTensor",
"joint",
"=",
"new",
"VarTensor",
"(",
"s",
",",
"new",
"VarSet",
"(",
")",
",",
"s",
".",
"one",
"(",
")",
")",
";",
"for",
"(",
"int",
"a",
"=",
"0",
";",
"a",
"<",
"fg",
".",
"getNumFactors",
"(",
")",
";",
"a",
"++",
")",
"{",
"Factor",
"f",
"=",
"fg",
".",
"getFactor",
"(",
"a",
")",
";",
"VarTensor",
"factor",
"=",
"safeNewVarTensor",
"(",
"s",
",",
"f",
")",
";",
"assert",
"!",
"factor",
".",
"containsBadValues",
"(",
")",
":",
"factor",
";",
"joint",
".",
"prod",
"(",
"factor",
")",
";",
"}",
"return",
"joint",
";",
"}"
] |
Gets the product of all the factors in the factor graph. If working in
the log-domain, this will do factor addition.
@return The product of all the factors.
|
[
"Gets",
"the",
"product",
"of",
"all",
"the",
"factors",
"in",
"the",
"factor",
"graph",
".",
"If",
"working",
"in",
"the",
"log",
"-",
"domain",
"this",
"will",
"do",
"factor",
"addition",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/inf/BruteForceInferencer.java#L53-L62
|
12,280
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/UserZoneEventHandler.java
|
UserZoneEventHandler.checkHandler
|
protected boolean checkHandler(ZoneHandlerClass handler, ApiZone apiZone) {
return apiZone.getName().startsWith(handler.getZoneName());
}
|
java
|
protected boolean checkHandler(ZoneHandlerClass handler, ApiZone apiZone) {
return apiZone.getName().startsWith(handler.getZoneName());
}
|
[
"protected",
"boolean",
"checkHandler",
"(",
"ZoneHandlerClass",
"handler",
",",
"ApiZone",
"apiZone",
")",
"{",
"return",
"apiZone",
".",
"getName",
"(",
")",
".",
"startsWith",
"(",
"handler",
".",
"getZoneName",
"(",
")",
")",
";",
"}"
] |
Check zone name
@param handler
structure of handle class
@param apiZone
api zone reference
@return true of false
|
[
"Check",
"zone",
"name"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/UserZoneEventHandler.java#L120-L122
|
12,281
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/UserZoneEventHandler.java
|
UserZoneEventHandler.callHandleMethod
|
private void callHandleMethod(Method method, Object instance, ApiZone apiZone,
Object userAgent) {
ReflectMethodUtil.invokeHandleMethod(method, instance, context, apiZone, userAgent);
}
|
java
|
private void callHandleMethod(Method method, Object instance, ApiZone apiZone,
Object userAgent) {
ReflectMethodUtil.invokeHandleMethod(method, instance, context, apiZone, userAgent);
}
|
[
"private",
"void",
"callHandleMethod",
"(",
"Method",
"method",
",",
"Object",
"instance",
",",
"ApiZone",
"apiZone",
",",
"Object",
"userAgent",
")",
"{",
"ReflectMethodUtil",
".",
"invokeHandleMethod",
"(",
"method",
",",
"instance",
",",
"context",
",",
"apiZone",
",",
"userAgent",
")",
";",
"}"
] |
Call handle method
@param method
handle method
@param instance
object to call method
@param apiZone
api zone reference
@param userAgent
user agent reference
|
[
"Call",
"handle",
"method"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/UserZoneEventHandler.java#L136-L139
|
12,282
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/sch/util/dist/TruncatedNormal.java
|
TruncatedNormal.probabilityTruncZero
|
public static double probabilityTruncZero(double a, double b, double mu, double sigma) {
// clip at zero
a = Math.max(a, 0.0);
b = Math.max(b, 0.0);
final double denom = sigma * SQRT2;
final double scaledSDA = (a - mu) / denom;
final double scaledSDB = (b - mu) / denom;
// compute prob
final double probNormTimes2 = Erf.erf(scaledSDA, scaledSDB);
// renormalize
final double scaledSD0 = -mu / denom;
final double reZTimes2 = Erf.erfc(scaledSD0);
return probNormTimes2 / reZTimes2;
}
|
java
|
public static double probabilityTruncZero(double a, double b, double mu, double sigma) {
// clip at zero
a = Math.max(a, 0.0);
b = Math.max(b, 0.0);
final double denom = sigma * SQRT2;
final double scaledSDA = (a - mu) / denom;
final double scaledSDB = (b - mu) / denom;
// compute prob
final double probNormTimes2 = Erf.erf(scaledSDA, scaledSDB);
// renormalize
final double scaledSD0 = -mu / denom;
final double reZTimes2 = Erf.erfc(scaledSD0);
return probNormTimes2 / reZTimes2;
}
|
[
"public",
"static",
"double",
"probabilityTruncZero",
"(",
"double",
"a",
",",
"double",
"b",
",",
"double",
"mu",
",",
"double",
"sigma",
")",
"{",
"// clip at zero",
"a",
"=",
"Math",
".",
"max",
"(",
"a",
",",
"0.0",
")",
";",
"b",
"=",
"Math",
".",
"max",
"(",
"b",
",",
"0.0",
")",
";",
"final",
"double",
"denom",
"=",
"sigma",
"*",
"SQRT2",
";",
"final",
"double",
"scaledSDA",
"=",
"(",
"a",
"-",
"mu",
")",
"/",
"denom",
";",
"final",
"double",
"scaledSDB",
"=",
"(",
"b",
"-",
"mu",
")",
"/",
"denom",
";",
"// compute prob ",
"final",
"double",
"probNormTimes2",
"=",
"Erf",
".",
"erf",
"(",
"scaledSDA",
",",
"scaledSDB",
")",
";",
"// renormalize",
"final",
"double",
"scaledSD0",
"=",
"-",
"mu",
"/",
"denom",
";",
"final",
"double",
"reZTimes2",
"=",
"Erf",
".",
"erfc",
"(",
"scaledSD0",
")",
";",
"return",
"probNormTimes2",
"/",
"reZTimes2",
";",
"}"
] |
returns the probability of x falling within the range of a to b
under a normal distribution with mean mu and standard deviation sigma
if the distribution is truncated below 0 and renormalized
a and b should both be greater than or equal to 0 but this is not checked
|
[
"returns",
"the",
"probability",
"of",
"x",
"falling",
"within",
"the",
"range",
"of",
"a",
"to",
"b",
"under",
"a",
"normal",
"distribution",
"with",
"mean",
"mu",
"and",
"standard",
"deviation",
"sigma",
"if",
"the",
"distribution",
"is",
"truncated",
"below",
"0",
"and",
"renormalized"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/sch/util/dist/TruncatedNormal.java#L89-L102
|
12,283
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/sch/util/dist/TruncatedNormal.java
|
TruncatedNormal.meanTruncLower
|
public static double meanTruncLower(double mu, double sigma, double lowerBound) {
double alpha = (lowerBound - mu) / sigma;
double phiAlpha = densityNonTrunc(alpha, 0, 1.0);
double cPhiAlpha = cumulativeNonTrunc(alpha, 0, 1.0);
return mu + sigma * phiAlpha / (1.0 - cPhiAlpha);
}
|
java
|
public static double meanTruncLower(double mu, double sigma, double lowerBound) {
double alpha = (lowerBound - mu) / sigma;
double phiAlpha = densityNonTrunc(alpha, 0, 1.0);
double cPhiAlpha = cumulativeNonTrunc(alpha, 0, 1.0);
return mu + sigma * phiAlpha / (1.0 - cPhiAlpha);
}
|
[
"public",
"static",
"double",
"meanTruncLower",
"(",
"double",
"mu",
",",
"double",
"sigma",
",",
"double",
"lowerBound",
")",
"{",
"double",
"alpha",
"=",
"(",
"lowerBound",
"-",
"mu",
")",
"/",
"sigma",
";",
"double",
"phiAlpha",
"=",
"densityNonTrunc",
"(",
"alpha",
",",
"0",
",",
"1.0",
")",
";",
"double",
"cPhiAlpha",
"=",
"cumulativeNonTrunc",
"(",
"alpha",
",",
"0",
",",
"1.0",
")",
";",
"return",
"mu",
"+",
"sigma",
"*",
"phiAlpha",
"/",
"(",
"1.0",
"-",
"cPhiAlpha",
")",
";",
"}"
] |
Returns the mean of the normal distribution truncated to 0 for values of x < lowerBound
|
[
"Returns",
"the",
"mean",
"of",
"the",
"normal",
"distribution",
"truncated",
"to",
"0",
"for",
"values",
"of",
"x",
"<",
"lowerBound"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/sch/util/dist/TruncatedNormal.java#L189-L194
|
12,284
|
JodaOrg/joda-collect
|
src/main/java/org/joda/collect/grid/MutableCell.java
|
MutableCell.set
|
void set(int row, int column, V value) {
this.row = row;
this.column = column;
this.value = value;
}
|
java
|
void set(int row, int column, V value) {
this.row = row;
this.column = column;
this.value = value;
}
|
[
"void",
"set",
"(",
"int",
"row",
",",
"int",
"column",
",",
"V",
"value",
")",
"{",
"this",
".",
"row",
"=",
"row",
";",
"this",
".",
"column",
"=",
"column",
";",
"this",
".",
"value",
"=",
"value",
";",
"}"
] |
Sets the content of the cell.
@param row the row index
@param column the column index
@param value the value
|
[
"Sets",
"the",
"content",
"of",
"the",
"cell",
"."
] |
a4b05d5eebad5beb41715c0678cf11835cf0fa3f
|
https://github.com/JodaOrg/joda-collect/blob/a4b05d5eebad5beb41715c0678cf11835cf0fa3f/src/main/java/org/joda/collect/grid/MutableCell.java#L74-L78
|
12,285
|
artikcloud/artikcloud-java
|
src/main/java/cloud/artik/api/DevicesApi.java
|
DevicesApi.getDevice
|
public DeviceEnvelope getDevice(String deviceId) throws ApiException {
ApiResponse<DeviceEnvelope> resp = getDeviceWithHttpInfo(deviceId);
return resp.getData();
}
|
java
|
public DeviceEnvelope getDevice(String deviceId) throws ApiException {
ApiResponse<DeviceEnvelope> resp = getDeviceWithHttpInfo(deviceId);
return resp.getData();
}
|
[
"public",
"DeviceEnvelope",
"getDevice",
"(",
"String",
"deviceId",
")",
"throws",
"ApiException",
"{",
"ApiResponse",
"<",
"DeviceEnvelope",
">",
"resp",
"=",
"getDeviceWithHttpInfo",
"(",
"deviceId",
")",
";",
"return",
"resp",
".",
"getData",
"(",
")",
";",
"}"
] |
Get Device
Retrieves a device
@param deviceId deviceId (required)
@return DeviceEnvelope
@throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
|
[
"Get",
"Device",
"Retrieves",
"a",
"device"
] |
412f447573e7796ab4f685c0bdd5eb76185a365c
|
https://github.com/artikcloud/artikcloud-java/blob/412f447573e7796ab4f685c0bdd5eb76185a365c/src/main/java/cloud/artik/api/DevicesApi.java#L483-L486
|
12,286
|
artikcloud/artikcloud-java
|
src/main/java/cloud/artik/api/SubscriptionsApi.java
|
SubscriptionsApi.deleteSubscription
|
public SubscriptionEnvelope deleteSubscription(String subId) throws ApiException {
ApiResponse<SubscriptionEnvelope> resp = deleteSubscriptionWithHttpInfo(subId);
return resp.getData();
}
|
java
|
public SubscriptionEnvelope deleteSubscription(String subId) throws ApiException {
ApiResponse<SubscriptionEnvelope> resp = deleteSubscriptionWithHttpInfo(subId);
return resp.getData();
}
|
[
"public",
"SubscriptionEnvelope",
"deleteSubscription",
"(",
"String",
"subId",
")",
"throws",
"ApiException",
"{",
"ApiResponse",
"<",
"SubscriptionEnvelope",
">",
"resp",
"=",
"deleteSubscriptionWithHttpInfo",
"(",
"subId",
")",
";",
"return",
"resp",
".",
"getData",
"(",
")",
";",
"}"
] |
Delete Subscription
Delete Subscription
@param subId Subscription ID. (required)
@return SubscriptionEnvelope
@throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
|
[
"Delete",
"Subscription",
"Delete",
"Subscription"
] |
412f447573e7796ab4f685c0bdd5eb76185a365c
|
https://github.com/artikcloud/artikcloud-java/blob/412f447573e7796ab4f685c0bdd5eb76185a365c/src/main/java/cloud/artik/api/SubscriptionsApi.java#L246-L249
|
12,287
|
Harium/keel
|
src/main/java/jdt/triangulation/GridIndex.java
|
GridIndex.init
|
private void init(DelaunayTriangulation delaunay, int xCellCount, int yCellCount, BoundingBox region) {
indexDelaunay = delaunay;
indexRegion = region;
x_size = region.getWidth() / yCellCount;
y_size = region.getHeight() / xCellCount;
// The grid will hold a trinagle for each cell, so a point (x,y) will lie
// in the cell representing the grid partition of region to a
// xCellCount on yCellCount grid
grid = new Triangle[xCellCount][yCellCount];
Triangle colStartTriangle = indexDelaunay.find(middleOfCell(0, 0));
updateCellValues(0, 0, xCellCount - 1, yCellCount - 1, colStartTriangle);
}
|
java
|
private void init(DelaunayTriangulation delaunay, int xCellCount, int yCellCount, BoundingBox region) {
indexDelaunay = delaunay;
indexRegion = region;
x_size = region.getWidth() / yCellCount;
y_size = region.getHeight() / xCellCount;
// The grid will hold a trinagle for each cell, so a point (x,y) will lie
// in the cell representing the grid partition of region to a
// xCellCount on yCellCount grid
grid = new Triangle[xCellCount][yCellCount];
Triangle colStartTriangle = indexDelaunay.find(middleOfCell(0, 0));
updateCellValues(0, 0, xCellCount - 1, yCellCount - 1, colStartTriangle);
}
|
[
"private",
"void",
"init",
"(",
"DelaunayTriangulation",
"delaunay",
",",
"int",
"xCellCount",
",",
"int",
"yCellCount",
",",
"BoundingBox",
"region",
")",
"{",
"indexDelaunay",
"=",
"delaunay",
";",
"indexRegion",
"=",
"region",
";",
"x_size",
"=",
"region",
".",
"getWidth",
"(",
")",
"/",
"yCellCount",
";",
"y_size",
"=",
"region",
".",
"getHeight",
"(",
")",
"/",
"xCellCount",
";",
"// The grid will hold a trinagle for each cell, so a point (x,y) will lie\r",
"// in the cell representing the grid partition of region to a\r",
"// xCellCount on yCellCount grid\r",
"grid",
"=",
"new",
"Triangle",
"[",
"xCellCount",
"]",
"[",
"yCellCount",
"]",
";",
"Triangle",
"colStartTriangle",
"=",
"indexDelaunay",
".",
"find",
"(",
"middleOfCell",
"(",
"0",
",",
"0",
")",
")",
";",
"updateCellValues",
"(",
"0",
",",
"0",
",",
"xCellCount",
"-",
"1",
",",
"yCellCount",
"-",
"1",
",",
"colStartTriangle",
")",
";",
"}"
] |
Initialize the grid index
@param delaunay delaunay triangulation to index
@param xCellCount number of grid cells in a row
@param yCellCount number of grid cells in a column
@param region geographic region to index
|
[
"Initialize",
"the",
"grid",
"index"
] |
0369ae674f9e664bccc5f9e161ae7e7a3b949a1e
|
https://github.com/Harium/keel/blob/0369ae674f9e664bccc5f9e161ae7e7a3b949a1e/src/main/java/jdt/triangulation/GridIndex.java#L104-L117
|
12,288
|
Harium/keel
|
src/main/java/jdt/triangulation/GridIndex.java
|
GridIndex.findCellTriangleOf
|
public Triangle findCellTriangleOf(Point3D point) {
int x_index = (int) ((point.x - indexRegion.minX()) / x_size);
int y_index = (int) ((point.y - indexRegion.minY()) / y_size);
return grid[x_index][y_index];
}
|
java
|
public Triangle findCellTriangleOf(Point3D point) {
int x_index = (int) ((point.x - indexRegion.minX()) / x_size);
int y_index = (int) ((point.y - indexRegion.minY()) / y_size);
return grid[x_index][y_index];
}
|
[
"public",
"Triangle",
"findCellTriangleOf",
"(",
"Point3D",
"point",
")",
"{",
"int",
"x_index",
"=",
"(",
"int",
")",
"(",
"(",
"point",
".",
"x",
"-",
"indexRegion",
".",
"minX",
"(",
")",
")",
"/",
"x_size",
")",
";",
"int",
"y_index",
"=",
"(",
"int",
")",
"(",
"(",
"point",
".",
"y",
"-",
"indexRegion",
".",
"minY",
"(",
")",
")",
"/",
"y_size",
")",
";",
"return",
"grid",
"[",
"x_index",
"]",
"[",
"y_index",
"]",
";",
"}"
] |
Finds a triangle near the given point
@param point a query point
@return a triangle at the same cell of the point
|
[
"Finds",
"a",
"triangle",
"near",
"the",
"given",
"point"
] |
0369ae674f9e664bccc5f9e161ae7e7a3b949a1e
|
https://github.com/Harium/keel/blob/0369ae674f9e664bccc5f9e161ae7e7a3b949a1e/src/main/java/jdt/triangulation/GridIndex.java#L125-L129
|
12,289
|
Harium/keel
|
src/main/java/jdt/triangulation/GridIndex.java
|
GridIndex.updateIndex
|
public void updateIndex(Iterator<Triangle> updatedTriangles) {
// Gather the bounding box of the updated area
BoundingBox updatedRegion = new BoundingBox();
while (updatedTriangles.hasNext()) {
updatedRegion = updatedRegion.unionWith(updatedTriangles.next().getBoundingBox());
}
if (updatedRegion.isNull()) // No update...
return;
// Bad news - the updated region lies outside the indexed region.
// The whole index must be recalculated
if (!indexRegion.contains(updatedRegion)) {
init(indexDelaunay,
(int) (indexRegion.getWidth() / x_size),
(int) (indexRegion.getHeight() / y_size),
indexRegion.unionWith(updatedRegion));
} else {
// Find the cell region to be updated
Vector2i minInvalidCell = getCellOf(updatedRegion.getMinPoint());
Vector2i maxInvalidCell = getCellOf(updatedRegion.getMaxPoint());
// And update it with fresh triangles
Triangle adjacentValidTriangle = findValidTriangle(minInvalidCell);
updateCellValues(minInvalidCell.getX(), minInvalidCell.getY(), maxInvalidCell.getX(), maxInvalidCell.getY(), adjacentValidTriangle);
}
}
|
java
|
public void updateIndex(Iterator<Triangle> updatedTriangles) {
// Gather the bounding box of the updated area
BoundingBox updatedRegion = new BoundingBox();
while (updatedTriangles.hasNext()) {
updatedRegion = updatedRegion.unionWith(updatedTriangles.next().getBoundingBox());
}
if (updatedRegion.isNull()) // No update...
return;
// Bad news - the updated region lies outside the indexed region.
// The whole index must be recalculated
if (!indexRegion.contains(updatedRegion)) {
init(indexDelaunay,
(int) (indexRegion.getWidth() / x_size),
(int) (indexRegion.getHeight() / y_size),
indexRegion.unionWith(updatedRegion));
} else {
// Find the cell region to be updated
Vector2i minInvalidCell = getCellOf(updatedRegion.getMinPoint());
Vector2i maxInvalidCell = getCellOf(updatedRegion.getMaxPoint());
// And update it with fresh triangles
Triangle adjacentValidTriangle = findValidTriangle(minInvalidCell);
updateCellValues(minInvalidCell.getX(), minInvalidCell.getY(), maxInvalidCell.getX(), maxInvalidCell.getY(), adjacentValidTriangle);
}
}
|
[
"public",
"void",
"updateIndex",
"(",
"Iterator",
"<",
"Triangle",
">",
"updatedTriangles",
")",
"{",
"// Gather the bounding box of the updated area\r",
"BoundingBox",
"updatedRegion",
"=",
"new",
"BoundingBox",
"(",
")",
";",
"while",
"(",
"updatedTriangles",
".",
"hasNext",
"(",
")",
")",
"{",
"updatedRegion",
"=",
"updatedRegion",
".",
"unionWith",
"(",
"updatedTriangles",
".",
"next",
"(",
")",
".",
"getBoundingBox",
"(",
")",
")",
";",
"}",
"if",
"(",
"updatedRegion",
".",
"isNull",
"(",
")",
")",
"// No update...\r",
"return",
";",
"// Bad news - the updated region lies outside the indexed region.\r",
"// The whole index must be recalculated\r",
"if",
"(",
"!",
"indexRegion",
".",
"contains",
"(",
"updatedRegion",
")",
")",
"{",
"init",
"(",
"indexDelaunay",
",",
"(",
"int",
")",
"(",
"indexRegion",
".",
"getWidth",
"(",
")",
"/",
"x_size",
")",
",",
"(",
"int",
")",
"(",
"indexRegion",
".",
"getHeight",
"(",
")",
"/",
"y_size",
")",
",",
"indexRegion",
".",
"unionWith",
"(",
"updatedRegion",
")",
")",
";",
"}",
"else",
"{",
"// Find the cell region to be updated\r",
"Vector2i",
"minInvalidCell",
"=",
"getCellOf",
"(",
"updatedRegion",
".",
"getMinPoint",
"(",
")",
")",
";",
"Vector2i",
"maxInvalidCell",
"=",
"getCellOf",
"(",
"updatedRegion",
".",
"getMaxPoint",
"(",
")",
")",
";",
"// And update it with fresh triangles\r",
"Triangle",
"adjacentValidTriangle",
"=",
"findValidTriangle",
"(",
"minInvalidCell",
")",
";",
"updateCellValues",
"(",
"minInvalidCell",
".",
"getX",
"(",
")",
",",
"minInvalidCell",
".",
"getY",
"(",
")",
",",
"maxInvalidCell",
".",
"getX",
"(",
")",
",",
"maxInvalidCell",
".",
"getY",
"(",
")",
",",
"adjacentValidTriangle",
")",
";",
"}",
"}"
] |
Updates the grid index to reflect changes to the triangulation. Note that added
triangles outside the indexed region will force to recompute the whole index
with the enlarged region.
@param updatedTriangles changed triangles of the triangulation. This may be added triangles,
removed triangles or both. All that matter is that they cover the
changed area.
|
[
"Updates",
"the",
"grid",
"index",
"to",
"reflect",
"changes",
"to",
"the",
"triangulation",
".",
"Note",
"that",
"added",
"triangles",
"outside",
"the",
"indexed",
"region",
"will",
"force",
"to",
"recompute",
"the",
"whole",
"index",
"with",
"the",
"enlarged",
"region",
"."
] |
0369ae674f9e664bccc5f9e161ae7e7a3b949a1e
|
https://github.com/Harium/keel/blob/0369ae674f9e664bccc5f9e161ae7e7a3b949a1e/src/main/java/jdt/triangulation/GridIndex.java#L145-L173
|
12,290
|
Harium/keel
|
src/main/java/jdt/triangulation/GridIndex.java
|
GridIndex.getCellOf
|
private Vector2i getCellOf(Point3D coordinate) {
int xCell = (int) ((coordinate.x - indexRegion.minX()) / x_size);
int yCell = (int) ((coordinate.y - indexRegion.minY()) / y_size);
return new Vector2i(xCell, yCell);
}
|
java
|
private Vector2i getCellOf(Point3D coordinate) {
int xCell = (int) ((coordinate.x - indexRegion.minX()) / x_size);
int yCell = (int) ((coordinate.y - indexRegion.minY()) / y_size);
return new Vector2i(xCell, yCell);
}
|
[
"private",
"Vector2i",
"getCellOf",
"(",
"Point3D",
"coordinate",
")",
"{",
"int",
"xCell",
"=",
"(",
"int",
")",
"(",
"(",
"coordinate",
".",
"x",
"-",
"indexRegion",
".",
"minX",
"(",
")",
")",
"/",
"x_size",
")",
";",
"int",
"yCell",
"=",
"(",
"int",
")",
"(",
"(",
"coordinate",
".",
"y",
"-",
"indexRegion",
".",
"minY",
"(",
")",
")",
"/",
"y_size",
")",
";",
"return",
"new",
"Vector2i",
"(",
"xCell",
",",
"yCell",
")",
";",
"}"
] |
Locates the grid cell point covering the given coordinate
@param coordinate world coordinate to locate
@return cell covering the coordinate
|
[
"Locates",
"the",
"grid",
"cell",
"point",
"covering",
"the",
"given",
"coordinate"
] |
0369ae674f9e664bccc5f9e161ae7e7a3b949a1e
|
https://github.com/Harium/keel/blob/0369ae674f9e664bccc5f9e161ae7e7a3b949a1e/src/main/java/jdt/triangulation/GridIndex.java#L217-L221
|
12,291
|
Harium/keel
|
src/main/java/jdt/triangulation/GridIndex.java
|
GridIndex.middleOfCell
|
private Vector3 middleOfCell(int x_index, int y_index) {
float middleXCell = (float) (indexRegion.minX() + x_index * x_size + x_size / 2);
float middleYCell = (float) (indexRegion.minY() + y_index * y_size + y_size / 2);
return new Vector3(middleXCell, middleYCell, 0);
}
|
java
|
private Vector3 middleOfCell(int x_index, int y_index) {
float middleXCell = (float) (indexRegion.minX() + x_index * x_size + x_size / 2);
float middleYCell = (float) (indexRegion.minY() + y_index * y_size + y_size / 2);
return new Vector3(middleXCell, middleYCell, 0);
}
|
[
"private",
"Vector3",
"middleOfCell",
"(",
"int",
"x_index",
",",
"int",
"y_index",
")",
"{",
"float",
"middleXCell",
"=",
"(",
"float",
")",
"(",
"indexRegion",
".",
"minX",
"(",
")",
"+",
"x_index",
"*",
"x_size",
"+",
"x_size",
"/",
"2",
")",
";",
"float",
"middleYCell",
"=",
"(",
"float",
")",
"(",
"indexRegion",
".",
"minY",
"(",
")",
"+",
"y_index",
"*",
"y_size",
"+",
"y_size",
"/",
"2",
")",
";",
"return",
"new",
"Vector3",
"(",
"middleXCell",
",",
"middleYCell",
",",
"0",
")",
";",
"}"
] |
Create a point at the center of a cell
@param x_index horizontal cell index
@param y_index vertical cell index
@return Point at the center of the cell at (x_index, y_index)
|
[
"Create",
"a",
"point",
"at",
"the",
"center",
"of",
"a",
"cell"
] |
0369ae674f9e664bccc5f9e161ae7e7a3b949a1e
|
https://github.com/Harium/keel/blob/0369ae674f9e664bccc5f9e161ae7e7a3b949a1e/src/main/java/jdt/triangulation/GridIndex.java#L230-L234
|
12,292
|
Harium/keel
|
src/main/java/com/harium/keel/catalano/math/function/Gamma.java
|
Gamma.Function
|
public static double Function(double x) {
double[] P =
{
1.60119522476751861407E-4,
1.19135147006586384913E-3,
1.04213797561761569935E-2,
4.76367800457137231464E-2,
2.07448227648435975150E-1,
4.94214826801497100753E-1,
9.99999999999999996796E-1
};
double[] Q =
{
-2.31581873324120129819E-5,
5.39605580493303397842E-4,
-4.45641913851797240494E-3,
1.18139785222060435552E-2,
3.58236398605498653373E-2,
-2.34591795718243348568E-1,
7.14304917030273074085E-2,
1.00000000000000000320E0
};
double p, z;
double q = Math.abs(x);
if (q > 33.0) {
if (x < 0.0) {
p = Math.floor(q);
if (p == q) {
try {
throw new ArithmeticException("Overflow");
} catch (Exception e) {
e.printStackTrace();
}
}
z = q - p;
if (z > 0.5) {
p += 1.0;
z = q - p;
}
z = q * Math.sin(Math.PI * z);
if (z == 0.0) {
try {
throw new ArithmeticException("Overflow");
} catch (Exception e) {
e.printStackTrace();
}
}
z = Math.abs(z);
z = Math.PI / (z * Stirling(q));
return -z;
} else {
return Stirling(x);
}
}
z = 1.0;
while (x >= 3.0) {
x -= 1.0;
z *= x;
}
while (x < 0.0) {
if (x == 0.0) {
throw new ArithmeticException();
} else if (x > -1.0E-9) {
return (z / ((1.0 + 0.5772156649015329 * x) * x));
}
z /= x;
x += 1.0;
}
while (x < 2.0) {
if (x == 0.0) {
throw new ArithmeticException();
} else if (x < 1.0E-9) {
return (z / ((1.0 + 0.5772156649015329 * x) * x));
}
z /= x;
x += 1.0;
}
if ((x == 2.0) || (x == 3.0)) return z;
x -= 2.0;
p = Special.Polevl(x, P, 6);
q = Special.Polevl(x, Q, 7);
return z * p / q;
}
|
java
|
public static double Function(double x) {
double[] P =
{
1.60119522476751861407E-4,
1.19135147006586384913E-3,
1.04213797561761569935E-2,
4.76367800457137231464E-2,
2.07448227648435975150E-1,
4.94214826801497100753E-1,
9.99999999999999996796E-1
};
double[] Q =
{
-2.31581873324120129819E-5,
5.39605580493303397842E-4,
-4.45641913851797240494E-3,
1.18139785222060435552E-2,
3.58236398605498653373E-2,
-2.34591795718243348568E-1,
7.14304917030273074085E-2,
1.00000000000000000320E0
};
double p, z;
double q = Math.abs(x);
if (q > 33.0) {
if (x < 0.0) {
p = Math.floor(q);
if (p == q) {
try {
throw new ArithmeticException("Overflow");
} catch (Exception e) {
e.printStackTrace();
}
}
z = q - p;
if (z > 0.5) {
p += 1.0;
z = q - p;
}
z = q * Math.sin(Math.PI * z);
if (z == 0.0) {
try {
throw new ArithmeticException("Overflow");
} catch (Exception e) {
e.printStackTrace();
}
}
z = Math.abs(z);
z = Math.PI / (z * Stirling(q));
return -z;
} else {
return Stirling(x);
}
}
z = 1.0;
while (x >= 3.0) {
x -= 1.0;
z *= x;
}
while (x < 0.0) {
if (x == 0.0) {
throw new ArithmeticException();
} else if (x > -1.0E-9) {
return (z / ((1.0 + 0.5772156649015329 * x) * x));
}
z /= x;
x += 1.0;
}
while (x < 2.0) {
if (x == 0.0) {
throw new ArithmeticException();
} else if (x < 1.0E-9) {
return (z / ((1.0 + 0.5772156649015329 * x) * x));
}
z /= x;
x += 1.0;
}
if ((x == 2.0) || (x == 3.0)) return z;
x -= 2.0;
p = Special.Polevl(x, P, 6);
q = Special.Polevl(x, Q, 7);
return z * p / q;
}
|
[
"public",
"static",
"double",
"Function",
"(",
"double",
"x",
")",
"{",
"double",
"[",
"]",
"P",
"=",
"{",
"1.60119522476751861407E-4",
",",
"1.19135147006586384913E-3",
",",
"1.04213797561761569935E-2",
",",
"4.76367800457137231464E-2",
",",
"2.07448227648435975150E-1",
",",
"4.94214826801497100753E-1",
",",
"9.99999999999999996796E-1",
"}",
";",
"double",
"[",
"]",
"Q",
"=",
"{",
"-",
"2.31581873324120129819E-5",
",",
"5.39605580493303397842E-4",
",",
"-",
"4.45641913851797240494E-3",
",",
"1.18139785222060435552E-2",
",",
"3.58236398605498653373E-2",
",",
"-",
"2.34591795718243348568E-1",
",",
"7.14304917030273074085E-2",
",",
"1.00000000000000000320E0",
"}",
";",
"double",
"p",
",",
"z",
";",
"double",
"q",
"=",
"Math",
".",
"abs",
"(",
"x",
")",
";",
"if",
"(",
"q",
">",
"33.0",
")",
"{",
"if",
"(",
"x",
"<",
"0.0",
")",
"{",
"p",
"=",
"Math",
".",
"floor",
"(",
"q",
")",
";",
"if",
"(",
"p",
"==",
"q",
")",
"{",
"try",
"{",
"throw",
"new",
"ArithmeticException",
"(",
"\"Overflow\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}",
"z",
"=",
"q",
"-",
"p",
";",
"if",
"(",
"z",
">",
"0.5",
")",
"{",
"p",
"+=",
"1.0",
";",
"z",
"=",
"q",
"-",
"p",
";",
"}",
"z",
"=",
"q",
"*",
"Math",
".",
"sin",
"(",
"Math",
".",
"PI",
"*",
"z",
")",
";",
"if",
"(",
"z",
"==",
"0.0",
")",
"{",
"try",
"{",
"throw",
"new",
"ArithmeticException",
"(",
"\"Overflow\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}",
"z",
"=",
"Math",
".",
"abs",
"(",
"z",
")",
";",
"z",
"=",
"Math",
".",
"PI",
"/",
"(",
"z",
"*",
"Stirling",
"(",
"q",
")",
")",
";",
"return",
"-",
"z",
";",
"}",
"else",
"{",
"return",
"Stirling",
"(",
"x",
")",
";",
"}",
"}",
"z",
"=",
"1.0",
";",
"while",
"(",
"x",
">=",
"3.0",
")",
"{",
"x",
"-=",
"1.0",
";",
"z",
"*=",
"x",
";",
"}",
"while",
"(",
"x",
"<",
"0.0",
")",
"{",
"if",
"(",
"x",
"==",
"0.0",
")",
"{",
"throw",
"new",
"ArithmeticException",
"(",
")",
";",
"}",
"else",
"if",
"(",
"x",
">",
"-",
"1.0E-9",
")",
"{",
"return",
"(",
"z",
"/",
"(",
"(",
"1.0",
"+",
"0.5772156649015329",
"*",
"x",
")",
"*",
"x",
")",
")",
";",
"}",
"z",
"/=",
"x",
";",
"x",
"+=",
"1.0",
";",
"}",
"while",
"(",
"x",
"<",
"2.0",
")",
"{",
"if",
"(",
"x",
"==",
"0.0",
")",
"{",
"throw",
"new",
"ArithmeticException",
"(",
")",
";",
"}",
"else",
"if",
"(",
"x",
"<",
"1.0E-9",
")",
"{",
"return",
"(",
"z",
"/",
"(",
"(",
"1.0",
"+",
"0.5772156649015329",
"*",
"x",
")",
"*",
"x",
")",
")",
";",
"}",
"z",
"/=",
"x",
";",
"x",
"+=",
"1.0",
";",
"}",
"if",
"(",
"(",
"x",
"==",
"2.0",
")",
"||",
"(",
"x",
"==",
"3.0",
")",
")",
"return",
"z",
";",
"x",
"-=",
"2.0",
";",
"p",
"=",
"Special",
".",
"Polevl",
"(",
"x",
",",
"P",
",",
"6",
")",
";",
"q",
"=",
"Special",
".",
"Polevl",
"(",
"x",
",",
"Q",
",",
"7",
")",
";",
"return",
"z",
"*",
"p",
"/",
"q",
";",
"}"
] |
Gamma function of the specified value.
@param x Value.
@return Result.
|
[
"Gamma",
"function",
"of",
"the",
"specified",
"value",
"."
] |
0369ae674f9e664bccc5f9e161ae7e7a3b949a1e
|
https://github.com/Harium/keel/blob/0369ae674f9e664bccc5f9e161ae7e7a3b949a1e/src/main/java/com/harium/keel/catalano/math/function/Gamma.java#L55-L152
|
12,293
|
Harium/keel
|
src/main/java/com/harium/keel/catalano/math/function/Gamma.java
|
Gamma.Stirling
|
public static double Stirling(double x) {
double[] STIR = {
7.87311395793093628397E-4,
-2.29549961613378126380E-4,
-2.68132617805781232825E-3,
3.47222221605458667310E-3,
8.33333333333482257126E-2,
};
double MAXSTIR = 143.01608;
double w = 1.0 / x;
double y = Math.exp(x);
w = 1.0 + w * Special.Polevl(w, STIR, 4);
if (x > MAXSTIR) {
double v = Math.pow(x, 0.5 * x - 0.25);
y = v * (v / y);
} else {
y = Math.pow(x, x - 0.5) / y;
}
y = 2.50662827463100050242E0 * y * w;
return y;
}
|
java
|
public static double Stirling(double x) {
double[] STIR = {
7.87311395793093628397E-4,
-2.29549961613378126380E-4,
-2.68132617805781232825E-3,
3.47222221605458667310E-3,
8.33333333333482257126E-2,
};
double MAXSTIR = 143.01608;
double w = 1.0 / x;
double y = Math.exp(x);
w = 1.0 + w * Special.Polevl(w, STIR, 4);
if (x > MAXSTIR) {
double v = Math.pow(x, 0.5 * x - 0.25);
y = v * (v / y);
} else {
y = Math.pow(x, x - 0.5) / y;
}
y = 2.50662827463100050242E0 * y * w;
return y;
}
|
[
"public",
"static",
"double",
"Stirling",
"(",
"double",
"x",
")",
"{",
"double",
"[",
"]",
"STIR",
"=",
"{",
"7.87311395793093628397E-4",
",",
"-",
"2.29549961613378126380E-4",
",",
"-",
"2.68132617805781232825E-3",
",",
"3.47222221605458667310E-3",
",",
"8.33333333333482257126E-2",
",",
"}",
";",
"double",
"MAXSTIR",
"=",
"143.01608",
";",
"double",
"w",
"=",
"1.0",
"/",
"x",
";",
"double",
"y",
"=",
"Math",
".",
"exp",
"(",
"x",
")",
";",
"w",
"=",
"1.0",
"+",
"w",
"*",
"Special",
".",
"Polevl",
"(",
"w",
",",
"STIR",
",",
"4",
")",
";",
"if",
"(",
"x",
">",
"MAXSTIR",
")",
"{",
"double",
"v",
"=",
"Math",
".",
"pow",
"(",
"x",
",",
"0.5",
"*",
"x",
"-",
"0.25",
")",
";",
"y",
"=",
"v",
"*",
"(",
"v",
"/",
"y",
")",
";",
"}",
"else",
"{",
"y",
"=",
"Math",
".",
"pow",
"(",
"x",
",",
"x",
"-",
"0.5",
")",
"/",
"y",
";",
"}",
"y",
"=",
"2.50662827463100050242E0",
"*",
"y",
"*",
"w",
";",
"return",
"y",
";",
"}"
] |
Gamma function as computed by Stirling's formula.
@param x Value.
@return Result.
|
[
"Gamma",
"function",
"as",
"computed",
"by",
"Stirling",
"s",
"formula",
"."
] |
0369ae674f9e664bccc5f9e161ae7e7a3b949a1e
|
https://github.com/Harium/keel/blob/0369ae674f9e664bccc5f9e161ae7e7a3b949a1e/src/main/java/com/harium/keel/catalano/math/function/Gamma.java#L258-L283
|
12,294
|
Harium/keel
|
src/main/java/com/harium/keel/catalano/math/function/Gamma.java
|
Gamma.Digamma
|
public static double Digamma(double x) {
double s = 0;
double w = 0;
double y = 0;
double z = 0;
double nz = 0;
boolean negative = false;
if (x <= 0.0) {
negative = true;
double q = x;
double p = (int) Math.floor(q);
if (p == q) {
try {
throw new ArithmeticException("Function computation resulted in arithmetic overflow.");
} catch (Exception e) {
e.printStackTrace();
}
}
nz = q - p;
if (nz != 0.5) {
if (nz > 0.5) {
p = p + 1.0;
nz = q - p;
}
nz = Math.PI / Math.tan(Math.PI * nz);
} else {
nz = 0.0;
}
x = 1.0 - x;
}
if (x <= 10.0 && x == Math.floor(x)) {
y = 0.0;
int n = (int) Math.floor(x);
for (int i = 1; i <= n - 1; i++) {
w = i;
y = y + 1.0 / w;
}
y = y - 0.57721566490153286061;
} else {
s = x;
w = 0.0;
while (s < 10.0) {
w = w + 1.0 / s;
s = s + 1.0;
}
if (s < 1.0E17) {
z = 1.0 / (s * s);
double polv = 8.33333333333333333333E-2;
polv = polv * z - 2.10927960927960927961E-2;
polv = polv * z + 7.57575757575757575758E-3;
polv = polv * z - 4.16666666666666666667E-3;
polv = polv * z + 3.96825396825396825397E-3;
polv = polv * z - 8.33333333333333333333E-3;
polv = polv * z + 8.33333333333333333333E-2;
y = z * polv;
} else {
y = 0.0;
}
y = Math.log(s) - 0.5 / s - y - w;
}
if (negative == true) {
y = y - nz;
}
return y;
}
|
java
|
public static double Digamma(double x) {
double s = 0;
double w = 0;
double y = 0;
double z = 0;
double nz = 0;
boolean negative = false;
if (x <= 0.0) {
negative = true;
double q = x;
double p = (int) Math.floor(q);
if (p == q) {
try {
throw new ArithmeticException("Function computation resulted in arithmetic overflow.");
} catch (Exception e) {
e.printStackTrace();
}
}
nz = q - p;
if (nz != 0.5) {
if (nz > 0.5) {
p = p + 1.0;
nz = q - p;
}
nz = Math.PI / Math.tan(Math.PI * nz);
} else {
nz = 0.0;
}
x = 1.0 - x;
}
if (x <= 10.0 && x == Math.floor(x)) {
y = 0.0;
int n = (int) Math.floor(x);
for (int i = 1; i <= n - 1; i++) {
w = i;
y = y + 1.0 / w;
}
y = y - 0.57721566490153286061;
} else {
s = x;
w = 0.0;
while (s < 10.0) {
w = w + 1.0 / s;
s = s + 1.0;
}
if (s < 1.0E17) {
z = 1.0 / (s * s);
double polv = 8.33333333333333333333E-2;
polv = polv * z - 2.10927960927960927961E-2;
polv = polv * z + 7.57575757575757575758E-3;
polv = polv * z - 4.16666666666666666667E-3;
polv = polv * z + 3.96825396825396825397E-3;
polv = polv * z - 8.33333333333333333333E-3;
polv = polv * z + 8.33333333333333333333E-2;
y = z * polv;
} else {
y = 0.0;
}
y = Math.log(s) - 0.5 / s - y - w;
}
if (negative == true) {
y = y - nz;
}
return y;
}
|
[
"public",
"static",
"double",
"Digamma",
"(",
"double",
"x",
")",
"{",
"double",
"s",
"=",
"0",
";",
"double",
"w",
"=",
"0",
";",
"double",
"y",
"=",
"0",
";",
"double",
"z",
"=",
"0",
";",
"double",
"nz",
"=",
"0",
";",
"boolean",
"negative",
"=",
"false",
";",
"if",
"(",
"x",
"<=",
"0.0",
")",
"{",
"negative",
"=",
"true",
";",
"double",
"q",
"=",
"x",
";",
"double",
"p",
"=",
"(",
"int",
")",
"Math",
".",
"floor",
"(",
"q",
")",
";",
"if",
"(",
"p",
"==",
"q",
")",
"{",
"try",
"{",
"throw",
"new",
"ArithmeticException",
"(",
"\"Function computation resulted in arithmetic overflow.\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}",
"nz",
"=",
"q",
"-",
"p",
";",
"if",
"(",
"nz",
"!=",
"0.5",
")",
"{",
"if",
"(",
"nz",
">",
"0.5",
")",
"{",
"p",
"=",
"p",
"+",
"1.0",
";",
"nz",
"=",
"q",
"-",
"p",
";",
"}",
"nz",
"=",
"Math",
".",
"PI",
"/",
"Math",
".",
"tan",
"(",
"Math",
".",
"PI",
"*",
"nz",
")",
";",
"}",
"else",
"{",
"nz",
"=",
"0.0",
";",
"}",
"x",
"=",
"1.0",
"-",
"x",
";",
"}",
"if",
"(",
"x",
"<=",
"10.0",
"&&",
"x",
"==",
"Math",
".",
"floor",
"(",
"x",
")",
")",
"{",
"y",
"=",
"0.0",
";",
"int",
"n",
"=",
"(",
"int",
")",
"Math",
".",
"floor",
"(",
"x",
")",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<=",
"n",
"-",
"1",
";",
"i",
"++",
")",
"{",
"w",
"=",
"i",
";",
"y",
"=",
"y",
"+",
"1.0",
"/",
"w",
";",
"}",
"y",
"=",
"y",
"-",
"0.57721566490153286061",
";",
"}",
"else",
"{",
"s",
"=",
"x",
";",
"w",
"=",
"0.0",
";",
"while",
"(",
"s",
"<",
"10.0",
")",
"{",
"w",
"=",
"w",
"+",
"1.0",
"/",
"s",
";",
"s",
"=",
"s",
"+",
"1.0",
";",
"}",
"if",
"(",
"s",
"<",
"1.0E17",
")",
"{",
"z",
"=",
"1.0",
"/",
"(",
"s",
"*",
"s",
")",
";",
"double",
"polv",
"=",
"8.33333333333333333333E-2",
";",
"polv",
"=",
"polv",
"*",
"z",
"-",
"2.10927960927960927961E-2",
";",
"polv",
"=",
"polv",
"*",
"z",
"+",
"7.57575757575757575758E-3",
";",
"polv",
"=",
"polv",
"*",
"z",
"-",
"4.16666666666666666667E-3",
";",
"polv",
"=",
"polv",
"*",
"z",
"+",
"3.96825396825396825397E-3",
";",
"polv",
"=",
"polv",
"*",
"z",
"-",
"8.33333333333333333333E-3",
";",
"polv",
"=",
"polv",
"*",
"z",
"+",
"8.33333333333333333333E-2",
";",
"y",
"=",
"z",
"*",
"polv",
";",
"}",
"else",
"{",
"y",
"=",
"0.0",
";",
"}",
"y",
"=",
"Math",
".",
"log",
"(",
"s",
")",
"-",
"0.5",
"/",
"s",
"-",
"y",
"-",
"w",
";",
"}",
"if",
"(",
"negative",
"==",
"true",
")",
"{",
"y",
"=",
"y",
"-",
"nz",
";",
"}",
"return",
"y",
";",
"}"
] |
Digamma function.
@param x Value.
@return Result.
|
[
"Digamma",
"function",
"."
] |
0369ae674f9e664bccc5f9e161ae7e7a3b949a1e
|
https://github.com/Harium/keel/blob/0369ae674f9e664bccc5f9e161ae7e7a3b949a1e/src/main/java/com/harium/keel/catalano/math/function/Gamma.java#L291-L367
|
12,295
|
Harium/keel
|
src/main/java/com/harium/keel/catalano/math/function/Gamma.java
|
Gamma.ComplementedIncomplete
|
public static double ComplementedIncomplete(double a, double x) {
final double big = 4.503599627370496e15;
final double biginv = 2.22044604925031308085e-16;
double ans, ax, c, yc, r, t, y, z;
double pk, pkm1, pkm2, qk, qkm1, qkm2;
if (x <= 0 || a <= 0) return 1.0;
if (x < 1.0 || x < a) return 1.0 - Incomplete(a, x);
ax = a * Math.log(x) - x - Log(a);
if (ax < -Constants.LogMax) return 0.0;
ax = Math.exp(ax);
// continued fraction
y = 1.0 - a;
z = x + y + 1.0;
c = 0.0;
pkm2 = 1.0;
qkm2 = x;
pkm1 = x + 1.0;
qkm1 = z * x;
ans = pkm1 / qkm1;
do {
c += 1.0;
y += 1.0;
z += 2.0;
yc = y * c;
pk = pkm1 * z - pkm2 * yc;
qk = qkm1 * z - qkm2 * yc;
if (qk != 0) {
r = pk / qk;
t = Math.abs((ans - r) / r);
ans = r;
} else
t = 1.0;
pkm2 = pkm1;
pkm1 = pk;
qkm2 = qkm1;
qkm1 = qk;
if (Math.abs(pk) > big) {
pkm2 *= biginv;
pkm1 *= biginv;
qkm2 *= biginv;
qkm1 *= biginv;
}
} while (t > Constants.DoubleEpsilon);
return ans * ax;
}
|
java
|
public static double ComplementedIncomplete(double a, double x) {
final double big = 4.503599627370496e15;
final double biginv = 2.22044604925031308085e-16;
double ans, ax, c, yc, r, t, y, z;
double pk, pkm1, pkm2, qk, qkm1, qkm2;
if (x <= 0 || a <= 0) return 1.0;
if (x < 1.0 || x < a) return 1.0 - Incomplete(a, x);
ax = a * Math.log(x) - x - Log(a);
if (ax < -Constants.LogMax) return 0.0;
ax = Math.exp(ax);
// continued fraction
y = 1.0 - a;
z = x + y + 1.0;
c = 0.0;
pkm2 = 1.0;
qkm2 = x;
pkm1 = x + 1.0;
qkm1 = z * x;
ans = pkm1 / qkm1;
do {
c += 1.0;
y += 1.0;
z += 2.0;
yc = y * c;
pk = pkm1 * z - pkm2 * yc;
qk = qkm1 * z - qkm2 * yc;
if (qk != 0) {
r = pk / qk;
t = Math.abs((ans - r) / r);
ans = r;
} else
t = 1.0;
pkm2 = pkm1;
pkm1 = pk;
qkm2 = qkm1;
qkm1 = qk;
if (Math.abs(pk) > big) {
pkm2 *= biginv;
pkm1 *= biginv;
qkm2 *= biginv;
qkm1 *= biginv;
}
} while (t > Constants.DoubleEpsilon);
return ans * ax;
}
|
[
"public",
"static",
"double",
"ComplementedIncomplete",
"(",
"double",
"a",
",",
"double",
"x",
")",
"{",
"final",
"double",
"big",
"=",
"4.503599627370496e15",
";",
"final",
"double",
"biginv",
"=",
"2.22044604925031308085e-16",
";",
"double",
"ans",
",",
"ax",
",",
"c",
",",
"yc",
",",
"r",
",",
"t",
",",
"y",
",",
"z",
";",
"double",
"pk",
",",
"pkm1",
",",
"pkm2",
",",
"qk",
",",
"qkm1",
",",
"qkm2",
";",
"if",
"(",
"x",
"<=",
"0",
"||",
"a",
"<=",
"0",
")",
"return",
"1.0",
";",
"if",
"(",
"x",
"<",
"1.0",
"||",
"x",
"<",
"a",
")",
"return",
"1.0",
"-",
"Incomplete",
"(",
"a",
",",
"x",
")",
";",
"ax",
"=",
"a",
"*",
"Math",
".",
"log",
"(",
"x",
")",
"-",
"x",
"-",
"Log",
"(",
"a",
")",
";",
"if",
"(",
"ax",
"<",
"-",
"Constants",
".",
"LogMax",
")",
"return",
"0.0",
";",
"ax",
"=",
"Math",
".",
"exp",
"(",
"ax",
")",
";",
"// continued fraction",
"y",
"=",
"1.0",
"-",
"a",
";",
"z",
"=",
"x",
"+",
"y",
"+",
"1.0",
";",
"c",
"=",
"0.0",
";",
"pkm2",
"=",
"1.0",
";",
"qkm2",
"=",
"x",
";",
"pkm1",
"=",
"x",
"+",
"1.0",
";",
"qkm1",
"=",
"z",
"*",
"x",
";",
"ans",
"=",
"pkm1",
"/",
"qkm1",
";",
"do",
"{",
"c",
"+=",
"1.0",
";",
"y",
"+=",
"1.0",
";",
"z",
"+=",
"2.0",
";",
"yc",
"=",
"y",
"*",
"c",
";",
"pk",
"=",
"pkm1",
"*",
"z",
"-",
"pkm2",
"*",
"yc",
";",
"qk",
"=",
"qkm1",
"*",
"z",
"-",
"qkm2",
"*",
"yc",
";",
"if",
"(",
"qk",
"!=",
"0",
")",
"{",
"r",
"=",
"pk",
"/",
"qk",
";",
"t",
"=",
"Math",
".",
"abs",
"(",
"(",
"ans",
"-",
"r",
")",
"/",
"r",
")",
";",
"ans",
"=",
"r",
";",
"}",
"else",
"t",
"=",
"1.0",
";",
"pkm2",
"=",
"pkm1",
";",
"pkm1",
"=",
"pk",
";",
"qkm2",
"=",
"qkm1",
";",
"qkm1",
"=",
"qk",
";",
"if",
"(",
"Math",
".",
"abs",
"(",
"pk",
")",
">",
"big",
")",
"{",
"pkm2",
"*=",
"biginv",
";",
"pkm1",
"*=",
"biginv",
";",
"qkm2",
"*=",
"biginv",
";",
"qkm1",
"*=",
"biginv",
";",
"}",
"}",
"while",
"(",
"t",
">",
"Constants",
".",
"DoubleEpsilon",
")",
";",
"return",
"ans",
"*",
"ax",
";",
"}"
] |
Complemented incomplete gamma function.
@param a Value.
@param x Value.
@return Result.
|
[
"Complemented",
"incomplete",
"gamma",
"function",
"."
] |
0369ae674f9e664bccc5f9e161ae7e7a3b949a1e
|
https://github.com/Harium/keel/blob/0369ae674f9e664bccc5f9e161ae7e7a3b949a1e/src/main/java/com/harium/keel/catalano/math/function/Gamma.java#L376-L428
|
12,296
|
Harium/keel
|
src/main/java/com/harium/keel/catalano/math/function/Gamma.java
|
Gamma.Incomplete
|
public static double Incomplete(double a, double x) {
double ans, ax, c, r;
if (x <= 0 || a <= 0) return 0.0;
if (x > 1.0 && x > a) return 1.0 - ComplementedIncomplete(a, x);
ax = a * Math.log(x) - x - Log(a);
if (ax < -Constants.LogMax) return (0.0);
ax = Math.exp(ax);
r = a;
c = 1.0;
ans = 1.0;
do {
r += 1.0;
c *= x / r;
ans += c;
} while (c / ans > Constants.DoubleEpsilon);
return (ans * ax / a);
}
|
java
|
public static double Incomplete(double a, double x) {
double ans, ax, c, r;
if (x <= 0 || a <= 0) return 0.0;
if (x > 1.0 && x > a) return 1.0 - ComplementedIncomplete(a, x);
ax = a * Math.log(x) - x - Log(a);
if (ax < -Constants.LogMax) return (0.0);
ax = Math.exp(ax);
r = a;
c = 1.0;
ans = 1.0;
do {
r += 1.0;
c *= x / r;
ans += c;
} while (c / ans > Constants.DoubleEpsilon);
return (ans * ax / a);
}
|
[
"public",
"static",
"double",
"Incomplete",
"(",
"double",
"a",
",",
"double",
"x",
")",
"{",
"double",
"ans",
",",
"ax",
",",
"c",
",",
"r",
";",
"if",
"(",
"x",
"<=",
"0",
"||",
"a",
"<=",
"0",
")",
"return",
"0.0",
";",
"if",
"(",
"x",
">",
"1.0",
"&&",
"x",
">",
"a",
")",
"return",
"1.0",
"-",
"ComplementedIncomplete",
"(",
"a",
",",
"x",
")",
";",
"ax",
"=",
"a",
"*",
"Math",
".",
"log",
"(",
"x",
")",
"-",
"x",
"-",
"Log",
"(",
"a",
")",
";",
"if",
"(",
"ax",
"<",
"-",
"Constants",
".",
"LogMax",
")",
"return",
"(",
"0.0",
")",
";",
"ax",
"=",
"Math",
".",
"exp",
"(",
"ax",
")",
";",
"r",
"=",
"a",
";",
"c",
"=",
"1.0",
";",
"ans",
"=",
"1.0",
";",
"do",
"{",
"r",
"+=",
"1.0",
";",
"c",
"*=",
"x",
"/",
"r",
";",
"ans",
"+=",
"c",
";",
"}",
"while",
"(",
"c",
"/",
"ans",
">",
"Constants",
".",
"DoubleEpsilon",
")",
";",
"return",
"(",
"ans",
"*",
"ax",
"/",
"a",
")",
";",
"}"
] |
Incomplete gamma function.
@param a Value.
@param x Value.
@return Result.
|
[
"Incomplete",
"gamma",
"function",
"."
] |
0369ae674f9e664bccc5f9e161ae7e7a3b949a1e
|
https://github.com/Harium/keel/blob/0369ae674f9e664bccc5f9e161ae7e7a3b949a1e/src/main/java/com/harium/keel/catalano/math/function/Gamma.java#L437-L460
|
12,297
|
Harium/keel
|
src/main/java/com/harium/keel/catalano/math/function/Gamma.java
|
Gamma.Log
|
public static double Log(double x) {
double p, q, w, z;
double[] A =
{
8.11614167470508450300E-4,
-5.95061904284301438324E-4,
7.93650340457716943945E-4,
-2.77777777730099687205E-3,
8.33333333333331927722E-2
};
double[] B =
{
-1.37825152569120859100E3,
-3.88016315134637840924E4,
-3.31612992738871184744E5,
-1.16237097492762307383E6,
-1.72173700820839662146E6,
-8.53555664245765465627E5
};
double[] C =
{
-3.51815701436523470549E2,
-1.70642106651881159223E4,
-2.20528590553854454839E5,
-1.13933444367982507207E6,
-2.53252307177582951285E6,
-2.01889141433532773231E6
};
if (x < -34.0) {
q = -x;
w = Log(q);
p = Math.floor(q);
if (p == q) {
try {
throw new ArithmeticException("Overflow.");
} catch (Exception e) {
e.printStackTrace();
}
}
z = q - p;
if (z > 0.5) {
p += 1.0;
z = p - q;
}
z = q * Math.sin(Math.PI * z);
if (z == 0.0) {
try {
throw new ArithmeticException("Overflow.");
} catch (Exception e) {
e.printStackTrace();
}
}
z = Constants.LogPI - Math.log(z) - w;
return z;
}
if (x < 13.0) {
z = 1.0;
while (x >= 3.0) {
x -= 1.0;
z *= x;
}
while (x < 2.0) {
if (x == 0.0) {
try {
throw new ArithmeticException("Overflow.");
} catch (Exception e) {
e.printStackTrace();
}
}
z /= x;
x += 1.0;
}
if (z < 0.0) z = -z;
if (x == 2.0) return Math.log(z);
x -= 2.0;
p = x * Special.Polevl(x, B, 5) / Special.P1evl(x, C, 6);
return (Math.log(z) + p);
}
if (x > 2.556348e305) {
try {
throw new ArithmeticException("Overflow.");
} catch (Exception e) {
e.printStackTrace();
}
}
q = (x - 0.5) * Math.log(x) - x + 0.91893853320467274178;
if (x > 1.0e8) return (q);
p = 1.0 / (x * x);
if (x >= 1000.0) {
q += ((7.9365079365079365079365e-4 * p
- 2.7777777777777777777778e-3) * p
+ 0.0833333333333333333333) / x;
} else {
q += Special.Polevl(p, A, 4) / x;
}
return q;
}
|
java
|
public static double Log(double x) {
double p, q, w, z;
double[] A =
{
8.11614167470508450300E-4,
-5.95061904284301438324E-4,
7.93650340457716943945E-4,
-2.77777777730099687205E-3,
8.33333333333331927722E-2
};
double[] B =
{
-1.37825152569120859100E3,
-3.88016315134637840924E4,
-3.31612992738871184744E5,
-1.16237097492762307383E6,
-1.72173700820839662146E6,
-8.53555664245765465627E5
};
double[] C =
{
-3.51815701436523470549E2,
-1.70642106651881159223E4,
-2.20528590553854454839E5,
-1.13933444367982507207E6,
-2.53252307177582951285E6,
-2.01889141433532773231E6
};
if (x < -34.0) {
q = -x;
w = Log(q);
p = Math.floor(q);
if (p == q) {
try {
throw new ArithmeticException("Overflow.");
} catch (Exception e) {
e.printStackTrace();
}
}
z = q - p;
if (z > 0.5) {
p += 1.0;
z = p - q;
}
z = q * Math.sin(Math.PI * z);
if (z == 0.0) {
try {
throw new ArithmeticException("Overflow.");
} catch (Exception e) {
e.printStackTrace();
}
}
z = Constants.LogPI - Math.log(z) - w;
return z;
}
if (x < 13.0) {
z = 1.0;
while (x >= 3.0) {
x -= 1.0;
z *= x;
}
while (x < 2.0) {
if (x == 0.0) {
try {
throw new ArithmeticException("Overflow.");
} catch (Exception e) {
e.printStackTrace();
}
}
z /= x;
x += 1.0;
}
if (z < 0.0) z = -z;
if (x == 2.0) return Math.log(z);
x -= 2.0;
p = x * Special.Polevl(x, B, 5) / Special.P1evl(x, C, 6);
return (Math.log(z) + p);
}
if (x > 2.556348e305) {
try {
throw new ArithmeticException("Overflow.");
} catch (Exception e) {
e.printStackTrace();
}
}
q = (x - 0.5) * Math.log(x) - x + 0.91893853320467274178;
if (x > 1.0e8) return (q);
p = 1.0 / (x * x);
if (x >= 1000.0) {
q += ((7.9365079365079365079365e-4 * p
- 2.7777777777777777777778e-3) * p
+ 0.0833333333333333333333) / x;
} else {
q += Special.Polevl(p, A, 4) / x;
}
return q;
}
|
[
"public",
"static",
"double",
"Log",
"(",
"double",
"x",
")",
"{",
"double",
"p",
",",
"q",
",",
"w",
",",
"z",
";",
"double",
"[",
"]",
"A",
"=",
"{",
"8.11614167470508450300E-4",
",",
"-",
"5.95061904284301438324E-4",
",",
"7.93650340457716943945E-4",
",",
"-",
"2.77777777730099687205E-3",
",",
"8.33333333333331927722E-2",
"}",
";",
"double",
"[",
"]",
"B",
"=",
"{",
"-",
"1.37825152569120859100E3",
",",
"-",
"3.88016315134637840924E4",
",",
"-",
"3.31612992738871184744E5",
",",
"-",
"1.16237097492762307383E6",
",",
"-",
"1.72173700820839662146E6",
",",
"-",
"8.53555664245765465627E5",
"}",
";",
"double",
"[",
"]",
"C",
"=",
"{",
"-",
"3.51815701436523470549E2",
",",
"-",
"1.70642106651881159223E4",
",",
"-",
"2.20528590553854454839E5",
",",
"-",
"1.13933444367982507207E6",
",",
"-",
"2.53252307177582951285E6",
",",
"-",
"2.01889141433532773231E6",
"}",
";",
"if",
"(",
"x",
"<",
"-",
"34.0",
")",
"{",
"q",
"=",
"-",
"x",
";",
"w",
"=",
"Log",
"(",
"q",
")",
";",
"p",
"=",
"Math",
".",
"floor",
"(",
"q",
")",
";",
"if",
"(",
"p",
"==",
"q",
")",
"{",
"try",
"{",
"throw",
"new",
"ArithmeticException",
"(",
"\"Overflow.\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}",
"z",
"=",
"q",
"-",
"p",
";",
"if",
"(",
"z",
">",
"0.5",
")",
"{",
"p",
"+=",
"1.0",
";",
"z",
"=",
"p",
"-",
"q",
";",
"}",
"z",
"=",
"q",
"*",
"Math",
".",
"sin",
"(",
"Math",
".",
"PI",
"*",
"z",
")",
";",
"if",
"(",
"z",
"==",
"0.0",
")",
"{",
"try",
"{",
"throw",
"new",
"ArithmeticException",
"(",
"\"Overflow.\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}",
"z",
"=",
"Constants",
".",
"LogPI",
"-",
"Math",
".",
"log",
"(",
"z",
")",
"-",
"w",
";",
"return",
"z",
";",
"}",
"if",
"(",
"x",
"<",
"13.0",
")",
"{",
"z",
"=",
"1.0",
";",
"while",
"(",
"x",
">=",
"3.0",
")",
"{",
"x",
"-=",
"1.0",
";",
"z",
"*=",
"x",
";",
"}",
"while",
"(",
"x",
"<",
"2.0",
")",
"{",
"if",
"(",
"x",
"==",
"0.0",
")",
"{",
"try",
"{",
"throw",
"new",
"ArithmeticException",
"(",
"\"Overflow.\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}",
"z",
"/=",
"x",
";",
"x",
"+=",
"1.0",
";",
"}",
"if",
"(",
"z",
"<",
"0.0",
")",
"z",
"=",
"-",
"z",
";",
"if",
"(",
"x",
"==",
"2.0",
")",
"return",
"Math",
".",
"log",
"(",
"z",
")",
";",
"x",
"-=",
"2.0",
";",
"p",
"=",
"x",
"*",
"Special",
".",
"Polevl",
"(",
"x",
",",
"B",
",",
"5",
")",
"/",
"Special",
".",
"P1evl",
"(",
"x",
",",
"C",
",",
"6",
")",
";",
"return",
"(",
"Math",
".",
"log",
"(",
"z",
")",
"+",
"p",
")",
";",
"}",
"if",
"(",
"x",
">",
"2.556348e305",
")",
"{",
"try",
"{",
"throw",
"new",
"ArithmeticException",
"(",
"\"Overflow.\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}",
"q",
"=",
"(",
"x",
"-",
"0.5",
")",
"*",
"Math",
".",
"log",
"(",
"x",
")",
"-",
"x",
"+",
"0.91893853320467274178",
";",
"if",
"(",
"x",
">",
"1.0e8",
")",
"return",
"(",
"q",
")",
";",
"p",
"=",
"1.0",
"/",
"(",
"x",
"*",
"x",
")",
";",
"if",
"(",
"x",
">=",
"1000.0",
")",
"{",
"q",
"+=",
"(",
"(",
"7.9365079365079365079365e-4",
"*",
"p",
"-",
"2.7777777777777777777778e-3",
")",
"*",
"p",
"+",
"0.0833333333333333333333",
")",
"/",
"x",
";",
"}",
"else",
"{",
"q",
"+=",
"Special",
".",
"Polevl",
"(",
"p",
",",
"A",
",",
"4",
")",
"/",
"x",
";",
"}",
"return",
"q",
";",
"}"
] |
Natural logarithm of gamma function.
@param x Value.
@return Result.
|
[
"Natural",
"logarithm",
"of",
"gamma",
"function",
"."
] |
0369ae674f9e664bccc5f9e161ae7e7a3b949a1e
|
https://github.com/Harium/keel/blob/0369ae674f9e664bccc5f9e161ae7e7a3b949a1e/src/main/java/com/harium/keel/catalano/math/function/Gamma.java#L468-L578
|
12,298
|
Harium/keel
|
src/main/java/com/harium/keel/effect/CosineTransform.java
|
CosineTransform.Forward
|
public void Forward(ImageSource fastBitmap) {
this.width = fastBitmap.getWidth();
this.height = fastBitmap.getHeight();
if (!isTransformed) {
if (fastBitmap.isGrayscale()) {
if (Tools.isPowerOf2(width) && Tools.isPowerOf2(height)) {
data = new double[height][width];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
data[i][j] = Tools.Scale(0, 255, 0, 1, fastBitmap.getRGB(i, j));
}
}
DiscreteCosineTransform.Forward(data);
isTransformed = true;
} else {
try {
throw new IllegalArgumentException("Image width and height should be power of 2.");
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
try {
throw new IllegalArgumentException("Only grayscale images are supported.");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
|
java
|
public void Forward(ImageSource fastBitmap) {
this.width = fastBitmap.getWidth();
this.height = fastBitmap.getHeight();
if (!isTransformed) {
if (fastBitmap.isGrayscale()) {
if (Tools.isPowerOf2(width) && Tools.isPowerOf2(height)) {
data = new double[height][width];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
data[i][j] = Tools.Scale(0, 255, 0, 1, fastBitmap.getRGB(i, j));
}
}
DiscreteCosineTransform.Forward(data);
isTransformed = true;
} else {
try {
throw new IllegalArgumentException("Image width and height should be power of 2.");
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
try {
throw new IllegalArgumentException("Only grayscale images are supported.");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
|
[
"public",
"void",
"Forward",
"(",
"ImageSource",
"fastBitmap",
")",
"{",
"this",
".",
"width",
"=",
"fastBitmap",
".",
"getWidth",
"(",
")",
";",
"this",
".",
"height",
"=",
"fastBitmap",
".",
"getHeight",
"(",
")",
";",
"if",
"(",
"!",
"isTransformed",
")",
"{",
"if",
"(",
"fastBitmap",
".",
"isGrayscale",
"(",
")",
")",
"{",
"if",
"(",
"Tools",
".",
"isPowerOf2",
"(",
"width",
")",
"&&",
"Tools",
".",
"isPowerOf2",
"(",
"height",
")",
")",
"{",
"data",
"=",
"new",
"double",
"[",
"height",
"]",
"[",
"width",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"height",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"width",
";",
"j",
"++",
")",
"{",
"data",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"Tools",
".",
"Scale",
"(",
"0",
",",
"255",
",",
"0",
",",
"1",
",",
"fastBitmap",
".",
"getRGB",
"(",
"i",
",",
"j",
")",
")",
";",
"}",
"}",
"DiscreteCosineTransform",
".",
"Forward",
"(",
"data",
")",
";",
"isTransformed",
"=",
"true",
";",
"}",
"else",
"{",
"try",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Image width and height should be power of 2.\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}",
"}",
"else",
"{",
"try",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Only grayscale images are supported.\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}",
"}",
"}"
] |
Applies forward Cosine transformation to an image.
@param fastBitmap Image.
|
[
"Applies",
"forward",
"Cosine",
"transformation",
"to",
"an",
"image",
"."
] |
0369ae674f9e664bccc5f9e161ae7e7a3b949a1e
|
https://github.com/Harium/keel/blob/0369ae674f9e664bccc5f9e161ae7e7a3b949a1e/src/main/java/com/harium/keel/effect/CosineTransform.java#L78-L108
|
12,299
|
Harium/keel
|
src/main/java/com/harium/keel/effect/CosineTransform.java
|
CosineTransform.toFastBitmap
|
public ImageSource toFastBitmap() {
OneBandSource l = new OneBandSource(width, height);
PowerSpectrum();
double max = Math.log(PowerMax + 1.0);
double scale = 1.0;
if (scaleValue > 0) scale = scaleValue / max;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
double p = Power[i][j];
double plog = Math.log(p + 1.0);
l.setRGB(i, j, (int) (plog * scale * 255));
}
}
return l;
}
|
java
|
public ImageSource toFastBitmap() {
OneBandSource l = new OneBandSource(width, height);
PowerSpectrum();
double max = Math.log(PowerMax + 1.0);
double scale = 1.0;
if (scaleValue > 0) scale = scaleValue / max;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
double p = Power[i][j];
double plog = Math.log(p + 1.0);
l.setRGB(i, j, (int) (plog * scale * 255));
}
}
return l;
}
|
[
"public",
"ImageSource",
"toFastBitmap",
"(",
")",
"{",
"OneBandSource",
"l",
"=",
"new",
"OneBandSource",
"(",
"width",
",",
"height",
")",
";",
"PowerSpectrum",
"(",
")",
";",
"double",
"max",
"=",
"Math",
".",
"log",
"(",
"PowerMax",
"+",
"1.0",
")",
";",
"double",
"scale",
"=",
"1.0",
";",
"if",
"(",
"scaleValue",
">",
"0",
")",
"scale",
"=",
"scaleValue",
"/",
"max",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"height",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"width",
";",
"j",
"++",
")",
"{",
"double",
"p",
"=",
"Power",
"[",
"i",
"]",
"[",
"j",
"]",
";",
"double",
"plog",
"=",
"Math",
".",
"log",
"(",
"p",
"+",
"1.0",
")",
";",
"l",
".",
"setRGB",
"(",
"i",
",",
"j",
",",
"(",
"int",
")",
"(",
"plog",
"*",
"scale",
"*",
"255",
")",
")",
";",
"}",
"}",
"return",
"l",
";",
"}"
] |
Convert image's data to FastBitmap.
@return FastBitmap.
|
[
"Convert",
"image",
"s",
"data",
"to",
"FastBitmap",
"."
] |
0369ae674f9e664bccc5f9e161ae7e7a3b949a1e
|
https://github.com/Harium/keel/blob/0369ae674f9e664bccc5f9e161ae7e7a3b949a1e/src/main/java/com/harium/keel/effect/CosineTransform.java#L125-L142
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.