本文整理汇总了Java中tberg.murphy.tuple.Pair类的典型用法代码示例。如果您正苦于以下问题:Java Pair类的具体用法?Java Pair怎么用?Java Pair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Pair类属于tberg.murphy.tuple包,在下文中一共展示了Pair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: estepNotes
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
private Pair<List<NoteState[][]>,List<float[][]>> estepNotes(List<float[][]> activations, float[][] envelopes, List<NoteState[][]> prevNoteStates) {
System.out.println("Update notes..");
long start = System.nanoTime();
List<NoteState[][]> noteStates = new ArrayList<NoteState[][]>();
List<float[][]> preActivations = new ArrayList<float[][]>();
for (int d=0; d<activations.size(); ++d) {
NoteState[][] prevNoteStatesLocal;
if (prevNoteStates == null) {
Pair<NoteState[][],float[][]> prevNoteStateAndPreActivation = viterbi(activations.get(d), envelopes, null);
prevNoteStatesLocal = prevNoteStateAndPreActivation.getFirst();
} else {
prevNoteStatesLocal = prevNoteStates.get(d);
}
Pair<NoteState[][],float[][]> noteStateAndPreActivation = viterbi(activations.get(d), envelopes, prevNoteStatesLocal);
noteStates.add(noteStateAndPreActivation.getFirst());
preActivations.add(noteStateAndPreActivation.getSecond());
}
long end = System.nanoTime();
System.out.println("Compute time: "+(end - start)/(1e9)+"s");
return Pair.makePair(noteStates, preActivations);
}
示例2: filterSilence
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
private static Pair<float[][], int[]> filterSilence(float[][] X, float thresh) {
List<float[]> Xs = new ArrayList<float[]>();
int[] loud = new int[X.length];
int c = 0;
for (int i = 0; i < X.length; ++i) {
float[] f = X[i];
if (a.sum(f) > thresh) {
Xs.add(f);
loud[i] = c;
c++;
} else {
loud[i] = -1;
}
}
return new Pair<float[][], int[]>(Xs.toArray(new float[0][0]), loud);
}
示例3: computeChordFeatures
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
protected Pair<int[][][], double[][][]> computeChordFeatures() {
int[][][] indices = new int[knownChords.size()][][];
double[][][] values = new double[knownChords.size()][][];
for (Chord chord : knownChords) {
int c = chordIndexer.getIndex(chord);
indices[c] = new int[CLUSTERS][];
values[c] = new double[CLUSTERS][];
for (int s = 0; s < CLUSTERS; s++) {
List<String> emissionFeatures = makeEmissionFeatures(chord, s);
indices[c][s] = new int[emissionFeatures.size()];
values[c][s] = new double[emissionFeatures.size()];
for (int i = 0; i < emissionFeatures.size(); i++) {
String feat = emissionFeatures.get(i);
int featIndex = featIndexer.getIndex(feat);
indices[c][s][i] = featIndex;
values[c][s][i] = 1f;
}
}
}
return new Pair<int[][][], double[][][]>(indices, values);
}
示例4: computeTransitionFeatures
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
protected Pair<int[][][], double[][][]> computeTransitionFeatures(List<List<Chord>> sequences) {
int[][][] indices = new int[CLUSTERS][][];
double[][][] values = new double[CLUSTERS][][];
for (int s1 = 0; s1 < CLUSTERS; s1++) {
indices[s1] = new int[CLUSTERS][];
values[s1] = new double[CLUSTERS][];
for (int s2 = 0; s2 < CLUSTERS; s2++) {
List<String> transitionFeatures = makeTransitionFeatures(s1, s2);
indices[s1][s2] = new int[transitionFeatures.size()];
values[s1][s2] = new double[transitionFeatures.size()];
for (int i = 0; i < transitionFeatures.size(); i++) {
String feat = transitionFeatures.get(i);
int featIndex = featIndexer.getIndex(feat);
indices[s1][s2][i] = featIndex;
values[s1][s2][i] = 1f;
}
}
}
return new Pair<int[][][], double[][][]>(indices, values);
}
示例5: computeEmissionScores
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
protected Pair<double[][][], double[]> computeEmissionScores(double[] weights) {
double[][][] emissionScores = new double[emissionFeatIndices.length][][];
for (int d = 0; d < emissionFeatIndices.length; d++) {
emissionScores[d] = new double[emissionFeatIndices[d].length][];
for (int t = 0; t < emissionFeatIndices[d].length; t++) {
emissionScores[d][t] = new double[CLUSTERS];
for (int s = 0; s < CLUSTERS; s++) {
emissionScores[d][t][s] = dot(emissionFeatIndices[d][t][s], emissionFeatValues[d][t][s], weights);
}
}
}
double[] emissionNormalizers = new double[CLUSTERS];
for (int c = 0; c < chordFeatIndices.length; c++) {
for (int s = 0; s < CLUSTERS; s++) {
emissionNormalizers[s] += Math.exp(dot(chordFeatIndices[c][s], chordFeatValues[c][s], weights));
}
}
return new Pair<double[][][], double[]>(emissionScores, emissionNormalizers);
}
示例6: computeTransitionScores
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
protected Pair<double[][], double[]> computeTransitionScores(double[] weights) {
double[][] transitionScores = new double[CLUSTERS][CLUSTERS];
for (int s1 = 0; s1 < CLUSTERS; s1++) {
for (int s2 = 0; s2 < CLUSTERS; s2++) {
transitionScores[s1][s2] = dot(transitionFeatIndices[s1][s2], transitionFeatValues[s1][s2], weights);
}
}
double[] transitionNormalizers = new double[CLUSTERS];
for (int s1 = 0; s1 < CLUSTERS; s1++) {
for (int s2 = 0; s2 < CLUSTERS; s2++) {
transitionNormalizers[s1] += Math.exp(dot(transitionFeatIndices[s1][s2], transitionFeatValues[s1][s2], weights));
}
}
return new Pair<double[][], double[]>(transitionScores, transitionNormalizers);
}
示例7: buildDotProdCache
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
public void buildDotProdCache() {
if (!opts.primalSmo) {
System.out.println("Building dotprod cache");
final int numConstraints = numConstraints();
this.dotProdCache = new double[numConstraints][numConstraints];
for (int i = 0; i < numConstraints; ++i) {
Pair<Integer, Integer> relIndicesI = getAlphaRelativeIndicesFromAbsoluteIndex(i);
final CounterInterface<Integer> deltaI = indexToDelta[relIndicesI.getFirst()].get(relIndicesI.getSecond());
for (int j = 0; j < numConstraints; ++j) {
Pair<Integer, Integer> relIndicesJ = getAlphaRelativeIndicesFromAbsoluteIndex(j);
dotProdCache[i][j] = deltaI.dotProduct(indexToDelta[relIndicesJ.getFirst()].get(relIndicesJ.getSecond()));
}
}
}
}
示例8: next
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
public Pair<Pair<Pair<Integer, Integer>, Integer>, Float> next() {
if (nodeCondProbs == null) {
this.d = 0;
this.t = 0;
this.s = 0;
this.nodeCondProbs = nodeCondProbs(0,0);
} else {
if (s == numStates(d)-1) {
this.s = 0;
if (t == sequenceLength(d)-1) {
this.t=0;
this.d++;
} else {
this.t++;
}
this.nodeCondProbs = nodeCondProbs(d,t);
} else {
this.s++;
}
}
return Pair.makePair(Pair.makePair(Pair.makePair(d, t), s), nodeCondProbs[s]);
}
示例9: minimize
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
public double[] minimize(List<DifferentiableFunction> functions, double[] initial, boolean verbose, Callback iterCallbackFunction) {
Random rand = new Random(0);
double[] guess = a.copy(initial);
double update = 0;
for (int epoch=0; epoch<epochs; ++epoch) {
double valSum = 0.0;
double[] gradSum = new double[guess.length];
int[] indices = a.shuffle(a.enumerate(0, functions.size()), rand);
for (int funcIndex : indices) {
DifferentiableFunction func = functions.get(funcIndex);
Pair<Double,double[]> valAndGrad = func.calculate(guess);
valSum += valAndGrad.getFirst();
double[] grad = valAndGrad.getSecond();
double learningRate = startLearningRate + update/(epochs*functions.size()) * (endLearningRate - startLearningRate);
a.combi(guess, 1.0, grad, -learningRate);
a.combi(gradSum, 1.0, grad, 1.0);
update++;
}
if (verbose) System.out.println(String.format("[SGDMinimizer.minimize] Epoch %d ended with value %.6f", epoch, valSum));
if (iterCallbackFunction != null) iterCallbackFunction.callback(guess, epoch, valSum, gradSum);
}
return guess;
}
示例10: test
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
public static void test(DifferentiableFunction func, double[] x, double relEps, double delInitial, double delMin, int i) {
double[] nextX = a.copy(x);
Pair<Double,double[]> valAndGrad = func.calculate(x);
double baseVal = valAndGrad.getFirst();
double[] grad = valAndGrad.getSecond();
double delta = delInitial;
boolean ok = false;
double empDeriv = 0.0;
while (delta > delMin && !ok) {
nextX[i] += delta;
double nextVal = func.calculate(nextX).getFirst();
empDeriv = (nextVal - baseVal) / delta;
if (close(empDeriv, grad[i], relEps)) {
System.out.printf("Gradient ok for dim %d, delta %f, calculated %f, empirical: %f\n", i, delta, grad[i], empDeriv);
ok = true;
}
nextX[i] -= delta;
if (!ok) delta /= 2.0;
}
if (!ok) System.out.printf("Empirical gradient step-size underflow dim %d, delta %.12f, calculated %.12f, empirical: %.12f\n", i, delta, grad[i], empDeriv);
}
示例11: computeMarginalsLogSpace
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
public static Pair<NodeMarginals,NonStationaryEdgeMarginals> computeMarginalsLogSpace(final Lattice lattice, final StationaryStateProjector nodeMarginalsStateProjector, final boolean viterbiEmissionOnly, int numThreads) {
final NodeMarginalsLogSpace projectedNodeMarginals = new NodeMarginalsLogSpace(lattice, nodeMarginalsStateProjector);
final NonStationaryEdgeMarginalsLogSpace edgeMarginals = (viterbiEmissionOnly ? null : new NonStationaryEdgeMarginalsLogSpace(lattice));
BetterThreader.Function<Integer,Object> func = new BetterThreader.Function<Integer,Object>(){public void call(Integer d, Object ignore){
float[][] alphas = doPassLogSpace(lattice, false, viterbiEmissionOnly, d);
float[][] betas = doPassLogSpace(lattice, true, viterbiEmissionOnly, d);
projectedNodeMarginals.incrementExpectedCounts(alphas, betas, d, viterbiEmissionOnly);
if (!viterbiEmissionOnly) edgeMarginals.incrementExpectedCounts(alphas, betas, d);
}};
BetterThreader<Integer,Object> threader = new BetterThreader<Integer,Object>(func, numThreads);
for (int d=0; d<lattice.numSequences(); ++d) threader.addFunctionArgument(d);
threader.run();
// System.out.printf("Estimated node marginals size: %.3fgb\n", projectedNodeMarginals.estimateMemoryUsage());
// if (!viterbiEmissionOnly) System.out.printf("Estimated edge marginals size: %.3fgb\n", edgeMarginals.estimateMemoryUsage());
return Pair.makePair((NodeMarginals) projectedNodeMarginals, (NonStationaryEdgeMarginals) edgeMarginals);
}
示例12: computeMarginalsScaling
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
public static Pair<NodeMarginals,StationaryEdgeMarginals> computeMarginalsScaling(final StationaryLattice lattice, final StationaryStateProjector nodeMarginalsStateProjector, final boolean viterbiEmissionOnly, int numThreads) {
final NodeMarginalsScaling projectedNodeMarginals = new NodeMarginalsScaling(new StationaryLatticeWrapper(lattice), nodeMarginalsStateProjector);
final StationaryEdgeMarginalsScaling edgeMarginals = (viterbiEmissionOnly ? null : new StationaryEdgeMarginalsScaling(lattice));
BetterThreader.Function<Integer,Object> func = new BetterThreader.Function<Integer,Object>(){public void call(Integer d, Object ignore){
Pair<float[][],float[]> alphasAndScales = doPassScaling(new StationaryLatticeWrapper(lattice), false, viterbiEmissionOnly, d);
float[][] alphas = alphasAndScales.getFirst();
float [] alphaLogScales = alphasAndScales.getSecond();
Pair<float[][],float[]> betasAndScales = doPassScaling(new StationaryLatticeWrapper(lattice), true, viterbiEmissionOnly, d);
float[][] betas = betasAndScales.getFirst();
float [] betaLogScales = betasAndScales.getSecond();
projectedNodeMarginals.incrementExpectedCounts(alphas, alphaLogScales, betas, betaLogScales, d, viterbiEmissionOnly);
if (!viterbiEmissionOnly) edgeMarginals.incrementExpectedCounts(alphas, alphaLogScales, betas, betaLogScales, d);
}};
BetterThreader<Integer,Object> threader = new BetterThreader<Integer,Object>(func, numThreads);
for (int d=0; d<lattice.numSequences(); ++d) threader.addFunctionArgument(d);
threader.run();
// System.out.printf("Estimated node marginals size: %.3fgb\n", projectedNodeMarginals.estimateMemoryUsage());
// if (!viterbiEmissionOnly) System.out.printf("Estimated edge marginals size: %.3fgb\n", edgeMarginals.estimateMemoryUsage());
return Pair.makePair((NodeMarginals) projectedNodeMarginals, (StationaryEdgeMarginals) edgeMarginals);
}
示例13: train
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
public void train(List<Pair<CounterInterface<Integer>,Integer>> trainSet) {
Problem problem = new Problem();
FeatureNode[][] x = new FeatureNode[trainSet.size()][];
double[] y = new double[trainSet.size()];
int maxFeature = 0;
for (int i=0; i<x.length; ++i) {
CounterInterface<Integer> features = trainSet.get(i).getFirst();
for (Map.Entry<Integer, Double> feat : features.entries()) {
maxFeature = Math.max(feat.getKey()+1, maxFeature);
}
x[i] = convertToFeatureNodes(features);
y[i] = trainSet.get(i).getSecond();
}
problem.l = trainSet.size();
problem.n = maxFeature;
problem.x = x;
problem.y = y;
problem.bias = 0.0;
Parameter parameter = new Parameter(solverType, C, eps);
model = Linear.train(problem, parameter);
}
示例14: singleColumnSegment
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
private static Pair<Integer,Integer> singleColumnSegment(double[] varProfile, double minCenterWidthFrac) {
int minCenterWidth = (int) (minCenterWidthFrac * varProfile.length);
int bestI = -1;
int bestJ = -1;
double bestObjective = Double.POSITIVE_INFINITY;
for (int i=0; i<varProfile.length; i+=varProfile.length/NUM_CROP_POINTS) {
for (int j=i+minCenterWidth; j<varProfile.length; j+=varProfile.length/NUM_CROP_POINTS) {
double val = evalSingleSegmentation(i, j, varProfile);
if (val < bestObjective) {
bestObjective = val;
bestI = i;
bestJ = j;
}
}
}
return Pair.makePair(bestI, bestJ);
}
示例15: next
import tberg.murphy.tuple.Pair; //导入依赖的package包/类
public Pair<Pair<Pair<Integer, Integer>, Integer>, Double> next() {
if (nodeCondProbs == null) {
this.d = 0;
this.t = 0;
this.s = 0;
this.nodeCondProbs = nodeCondProbs(0,0);
} else {
if (s == numStates(d)-1) {
this.s = 0;
if (t == sequenceLength(d)-1) {
this.t=0;
this.d++;
} else {
this.t++;
}
this.nodeCondProbs = nodeCondProbs(d,t);
} else {
this.s++;
}
}
return Pair.makePair(Pair.makePair(Pair.makePair(d, t), s), nodeCondProbs[s]);
}