use of edu.stanford.nlp.util.MutableDouble in project CoreNLP by stanfordnlp.
the class GeneralizedCounter method incrementCount1D.
/**
* Equivalent to <code>{@link #incrementCount}({o}, count)</code>;
* only works for a depth 1 GeneralizedCounter.
*/
public void incrementCount1D(K o, double count) {
if (depth > 1) {
wrongDepth();
}
addToTotal(count);
if (tempMDouble == null) {
tempMDouble = new MutableDouble();
}
tempMDouble.set(count);
MutableDouble oldMDouble = (MutableDouble) map.put(o, tempMDouble);
if (oldMDouble != null) {
tempMDouble.set(count + oldMDouble.doubleValue());
}
tempMDouble = oldMDouble;
}
use of edu.stanford.nlp.util.MutableDouble in project CoreNLP by stanfordnlp.
the class LambdaSolve method improvedIterative.
/**
* Does a fixed number of IIS iterations.
*
* @param iters Number of iterations to run
*/
public void improvedIterative(int iters) {
int iterations = 0;
lambda_converged = new boolean[p.fSize];
int numNConverged = p.fSize;
// double lOld=logLikelihood();
do {
iterations++;
for (int i = 0; i < lambda.length; i++) {
if (lambda_converged[i]) {
continue;
}
MutableDouble deltaI = new MutableDouble();
boolean fl = iterate(i, eps, deltaI);
if (fl) {
updateConds(i, deltaI.doubleValue());
// checkCorrectness();
} else {
// lambda_converged[i]=true;
numNConverged--;
}
}
if (iterations % 100 == 0) {
save_lambdas(iterations + ".lam");
}
log.info(iterations);
} while (iterations < iters);
}
use of edu.stanford.nlp.util.MutableDouble in project CoreNLP by stanfordnlp.
the class LambdaSolve method improvedIterative.
/**
* Iterate until convergence. I usually use the other method that
* does a fixed number of iterations.
*/
public void improvedIterative() {
boolean flag;
int iterations = 0;
lambda_converged = new boolean[p.fSize];
int numNConverged = p.fSize;
do {
if (VERBOSE) {
log.info(iterations);
}
flag = false;
iterations++;
for (int i = 0; i < lambda.length; i++) {
if (lambda_converged[i]) {
continue;
}
MutableDouble deltaI = new MutableDouble();
boolean fl = iterate(i, eps, deltaI);
if (fl) {
flag = true;
updateConds(i, deltaI.doubleValue());
// checkCorrectness();
} else {
// lambda_converged[i]=true;
numNConverged--;
}
}
} while ((flag) && (iterations < 1000));
}
use of edu.stanford.nlp.util.MutableDouble in project CoreNLP by stanfordnlp.
the class GeneralizedCounter method entrySet.
/* this is (non-tail) recursive right now, haven't figured out a way
* to speed it up */
private Set<Map.Entry<Object, Double>> entrySet(Set<Map.Entry<Object, Double>> s, Object[] key, boolean useLists) {
if (depth == 1) {
// System.out.println("key is long enough to add to set");
Set<K> keys = map.keySet();
for (K finalKey : keys) {
// array doesn't escape
K[] newKey = ErasureUtils.<K>mkTArray(Object.class, key.length + 1);
if (key.length > 0) {
System.arraycopy(key, 0, newKey, 0, key.length);
}
newKey[key.length] = finalKey;
MutableDouble value = (MutableDouble) map.get(finalKey);
Double value1 = Double.valueOf(value.doubleValue());
if (useLists) {
s.add(new Entry<>(Arrays.asList(newKey), value1));
} else {
s.add(new Entry<>(newKey[0], value1));
}
}
} else {
Set<K> keys = map.keySet();
// System.out.println("keyset level " + depth + " " + keys);
for (K o : keys) {
Object[] newKey = new Object[key.length + 1];
if (key.length > 0) {
System.arraycopy(key, 0, newKey, 0, key.length);
}
newKey[key.length] = o;
// System.out.println("level " + key.length + " current key " + Arrays.asList(newKey));
conditionalizeHelper(o).entrySet(s, newKey, true);
}
}
// System.out.println("leaving key length " + key.length);
return s;
}
use of edu.stanford.nlp.util.MutableDouble in project CoreNLP by stanfordnlp.
the class ClassicCounter method incrementCount.
/**
* {@inheritDoc}
*/
@Override
public double incrementCount(E key, double count) {
if (tempMDouble == null) {
tempMDouble = new MutableDouble();
}
MutableDouble oldMDouble = map.put(key, tempMDouble);
totalCount += count;
if (oldMDouble != null) {
count += oldMDouble.doubleValue();
}
tempMDouble.set(count);
tempMDouble = oldMDouble;
return count;
}
Aggregations