当前位置: 首页>>代码示例>>Java>>正文


Java Pair.getFirst方法代码示例

本文整理汇总了Java中tberg.murphy.tuple.Pair.getFirst方法的典型用法代码示例。如果您正苦于以下问题:Java Pair.getFirst方法的具体用法?Java Pair.getFirst怎么用?Java Pair.getFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tberg.murphy.tuple.Pair的用法示例。


在下文中一共展示了Pair.getFirst方法的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);
}
 
开发者ID:tberg12,项目名称:klavier,代码行数:26,代码来源:Model.java

示例2: 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);
	}
 
开发者ID:tberg12,项目名称:murphy,代码行数:21,代码来源:ForwardBackward.java

示例3: 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<double[][],double[]> alphasAndScales = doPassScaling(new StationaryLatticeWrapper(lattice), false, viterbiEmissionOnly, d);
			double[][] alphas = alphasAndScales.getFirst();
			double [] alphaLogScales = alphasAndScales.getSecond();
			Pair<double[][],double[]> betasAndScales = doPassScaling(new StationaryLatticeWrapper(lattice), true, viterbiEmissionOnly, d);
			double[][] betas = betasAndScales.getFirst();
			double [] 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);
	}
 
开发者ID:tberg12,项目名称:murphy,代码行数:21,代码来源:ForwardBackward.java

示例4: test

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
public static void test(DifferentiableFunction func, double[] x, double relEps, double delInitial, double delMin) {
	double[] nextX = a.copy(x);
	Pair<Double,double[]> valAndGrad = func.calculate(x);
	double baseVal = valAndGrad.getFirst();
	double[] grad = valAndGrad.getSecond();
	for (int i=0; i<x.length; ++i) {
		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);
	}
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:24,代码来源:EmpiricalGradientTester.java

示例5: 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;
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:24,代码来源:SGDMinimizer.java

示例6: lineSearch

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
private static Pair<double[],Double> lineSearch(DifferentiableFunction function, double[] initial, double[] direction, double initialStepSize, double stepSizeMultiplier) {
	double stepSize = initialStepSize;
	Pair<Double,double[]> initialValAndGrad = function.calculate(initial);
	double val = initialValAndGrad.getFirst();
	final double[] grad = initialValAndGrad.getSecond();
	double initialDirectionalDerivative = a.innerProd(grad, direction);
	double gradMax = a.max(a.abs(grad));
	double[] guess = null;
	double guessValue = 0.0;
	boolean sufficientDecreaseObtained = false;
	while (!sufficientDecreaseObtained) {
		guess = a.comb(initial, 1.0, direction, stepSize);
		guessValue = function.calculate(guess).getFirst();
		double sufficientDecreaseValue = val + LINE_SEARCH_SUFF_DECR * initialDirectionalDerivative * stepSize;
		sufficientDecreaseObtained = (guessValue <= sufficientDecreaseValue + EPS);
		if (!sufficientDecreaseObtained) {
			if (stepSize < EPS && stepSize * gradMax < EPS) {
				System.out.printf("[LBFGSMinimizer.minimize]: Line search step size underflow: %.15f, %.15f, %.15f, %.15f, %.15f, %.15f\n", stepSize, initialDirectionalDerivative, gradMax, guessValue, sufficientDecreaseValue, val);
				return null;
			}
			stepSize *= stepSizeMultiplier;
		}
	}
	return Pair.makePair(guess, stepSize);
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:26,代码来源:LBFGSMinimizer.java

示例7: minimize

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
public float[] minimize(List<DifferentiableFunction> functions, float[] initial, boolean verbose, Callback iterCallbackFunction) {
  Random rand = new Random(0);
  float[] guess = a.copy(initial);
  double update = 0;
  for (int epoch=0; epoch<epochs; ++epoch) {
    double valSum = 0.0;
    int[] indices = a.shuffle(a.enumerate(0, functions.size()), rand);
    for (int funcIndex : indices) {
      DifferentiableFunction func = functions.get(funcIndex);
      Pair<Double,CounterInterface<Integer>> valAndGrad = func.calculate(guess);
      valSum += valAndGrad.getFirst();
      CounterInterface<Integer> grad = valAndGrad.getSecond();
      double learningRate = startLearningRate + update/(epochs*functions.size()) * (endLearningRate - startLearningRate);
      for (Map.Entry<Integer,Double> entry : grad.entries()) {
        guess[entry.getKey()] += -learningRate * entry.getValue();
      }
      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);
  }
  return guess;
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:24,代码来源:SGDMinimizer.java

示例8: viterbi

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
private Pair<NoteState[][],float[][]> viterbi(final float[][] activations, final float[][] envelopes, NoteState[][] prevNoteStates) {
	final int numNotes = activations[0].length;
	final NoteState[][] noteStates = new NoteState[activations.length][numNotes];
	final float[][] preActivations = new float[activations.length][numNotes];
	for (int t=0; t<noteStates.length; ++t) {
		Arrays.fill(noteStates[t], NoteState.OFF);
	}
	final float[][] transActivations = a.transpose(activations);
	BetterThreader.Function<Integer,Object> func = new BetterThreader.Function<Integer,Object>(){public void call(Integer pitchId, Object ignore){
		DenseSemiMarkovDP.Model model = new EnvelopeActivationModel(transActivations[pitchId], envelopes[pitchId], widthScoresFactory.getMinWidth(pitchId), widthScoresFactory.getMaxWidth(pitchId), a.toFloat(widthScoresFactory.getLogAllowedWidthsScores(pitchId)), a.toFloat(transScoreFactory.getLogTransScores(pitchId)));
		List<Pair<Integer,Pair<Integer,Integer>>> decode = DenseSemiMarkovDP.viterbiDecode(model, pitchId);
		for (Pair<Integer,Pair<Integer,Integer>> segment : decode) {
			State s = State.values()[segment.getFirst()];
			int startT = segment.getSecond().getFirst();
			int endT = segment.getSecond().getSecond();
			if (s == State.ON) {
				float bestVolume = EnvelopeActivationModel.bestVolume(startT, endT-startT, transActivations[pitchId], envelopes[pitchId]);
				for (int t=startT; t<endT; ++t) {
					noteStates[t][pitchId] = NoteState.SUSTAIN;
					preActivations[t][pitchId] = bestVolume * envelopes[pitchId][t-startT];
				}
				noteStates[startT][pitchId] = NoteState.ONSET;
			}
		}
	}};
	BetterThreader<Integer,Object> threader = new BetterThreader<Integer,Object>(func, Main.numThreads);
	for (int pitchId=0; pitchId<numNotes; ++pitchId) threader.addFunctionArgument(pitchId);
	threader.run();
	return Pair.makePair(noteStates, preActivations);
}
 
开发者ID:tberg12,项目名称:klavier,代码行数:31,代码来源:Model.java

示例9: preprocessDatum

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
private static ProcDatum preprocessDatum(Datum datum, float[][] spectralAtoms) {
	Pair<float[][],Float> spectAndSecondsPerFrame = computeSpect(datum.wave);
	float[][] spect = spectAndSecondsPerFrame.getFirst();
	float secondsPerFrame = spectAndSecondsPerFrame.getSecond();
	float[][] activations = null;
	if (Main.nmfType == NMFType.KL) {
		activations = (Main.useGpu ? NMFUtilOpenCL.nmfKLGPU(spectralAtoms, false, a.onesFloat(spect.length, spectralAtoms.length), true, spect, Main.nmfNumIters, (float) Main.nmfSilenceEps, (float) Main.nmfMinEps).getSecond() : NMFUtilOpenCL.nmfKL(spectralAtoms, false, a.onesFloat(spect.length, spectralAtoms.length), true, spect, Main.nmfNumIters, (float) Main.nmfSilenceEps, (float) Main.nmfMinEps).getSecond());
	} else if (Main.nmfType == NMFType.Beta) {
		activations = (Main.useGpu ? NMFUtilOpenCL.nmfBetaGPU(spectralAtoms, false, a.onesFloat(spect.length, spectralAtoms.length), true, spect, Main.nmfNumIters, (float) Main.nmfSilenceEps, (float) Main.nmfMinEps, (float) Main.nmfBeta).getSecond() : NMFUtilOpenCL.nmfBeta(spectralAtoms, false, a.onesFloat(spect.length, spectralAtoms.length), true, spect, Main.nmfNumIters, (float) Main.nmfSilenceEps, (float) Main.nmfMinEps, (float) Main.nmfBeta).getSecond());
	} else if (Main.nmfType == NMFType.LogNormal) {
		float startStepSize = 1e-7f;
		float endStepSize = 1e-7f;
		float init = 1e-5f;
		activations = (Main.useGpu ? NMFUtilOpenCL.nmfLogNormalExpGradGPU(spectralAtoms, false, a.scale(a.onesFloat(spect.length, spectralAtoms.length), init), true, spect, startStepSize, endStepSize, Main.nmfNumIters, (float) Main.nmfSilenceEps, (float) Main.nmfMinEps, (float) Main.nmfC).getSecond() : NMFUtilOpenCL.nmfLogNormalExpGrad(spectralAtoms, false, a.scale(a.onesFloat(spect.length, spectralAtoms.length), init), true, spect, startStepSize, endStepSize, Main.nmfNumIters, (float) Main.nmfSilenceEps, (float) Main.nmfMinEps, (float) Main.nmfC).getSecond());
	}  else {
		activations = (Main.useGpu ? NMFUtilOpenCL.nmfL2GPU(spectralAtoms, false, a.onesFloat(spect.length, spectralAtoms.length), true, spect, Main.nmfNumIters, (float) Main.nmfSilenceEps, (float) Main.nmfMinEps).getSecond() : NMFUtilOpenCL.nmfL2(spectralAtoms, false, a.onesFloat(spect.length, spectralAtoms.length), true, spect, Main.nmfNumIters, (float) Main.nmfSilenceEps, (float) Main.nmfMinEps).getSecond());
	}
	
	if (ACTIVATIONS_POW) {
		a.powi(activations, POW);
	}
	if (ACTIVATIONS_DIVIDE_BY_MAX) {
		divideByMax(activations);
	}
	if (ACTIVATIONS_STRETCH_TO_UNIT) {
		stretchToUnit(activations);
	}
	if (ACTIVATIONS_LOG) {
		logSpace(activations);
		stretchToUnit(activations);
	}
	if (ACTIVATIONS_SCALE) {
		a.scalei(activations, SCALE);
	}
	if (ACTIVATIONS_BUCKET) {
		bucket(activations);
	}
	return new ProcDatum(datum, spect, activations, secondsPerFrame);
}
 
开发者ID:tberg12,项目名称:klavier,代码行数:40,代码来源:Preprocessing.java

示例10: Clustering

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
public Clustering(File corpusRoot) {
    knownChords = new HashSet<Chord>();
    List<List<Chord>> sequences = loadSongs(corpusRoot);
    featIndexer = new HashMapIndexer<String>();
    chordIndexer = new HashMapIndexer<Chord>();
    System.out.println("loaded activations");

    Pair<int[][][], double[][][]> chordFeatures = computeChordFeatures();
    chordFeatIndices = chordFeatures.getFirst();
    chordFeatValues = chordFeatures.getSecond();
    System.out.println("computed chord features");

    Pair<int[][][][], double[][][][]> emissionFeatures = computeEmissionFeatures(sequences);
    emissionFeatIndices = emissionFeatures.getFirst();
    emissionFeatValues = emissionFeatures.getSecond();
    System.out.println("computed emission features");
    //System.out.println(sequences);
    //System.out.println(emissionFeatIndices.length);
    //System.out.println(emissionFeatIndices[0].length);
    //System.out.println(emissionFeatIndices[0][0].length);
    //System.out.println(emissionFeatIndices[0][0][0].length);

    Pair<int[][][], double[][][]> transitionFeatures = computeTransitionFeatures(sequences);
    transitionFeatIndices = transitionFeatures.getFirst();
    transitionFeatValues = transitionFeatures.getSecond();
    System.out.println("computed transition features");
}
 
开发者ID:tberg12,项目名称:klavier,代码行数:28,代码来源:Clustering.java

示例11: IMSLPIndepTransitionReader

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
public IMSLPIndepTransitionReader(File corpusRoot) {
    loadSongs(corpusRoot);

    //int[] lengthCounts = new int[1000];

    //for (boolean[][] m : activations) {
    //    int offset = 0;
    //    int counter = 0;
    //    //System.out.println(m.length);
    //    for (int pitch = 0; pitch < m[0].length; pitch++) {
    //        while (offset < m.length && m[offset][pitch]) {
    //            offset++; }
    //        while (offset + counter < m.length && !m[offset + counter][pitch]) {
    //            counter++; }
    //        //while (m[offset++][pitch]) { if (offset >= m.length) break; }
    //        //while (m[offset + counter++][pitch]) { if (offset + counter >= m.length) break; }
    //        counter /= 10;
    //        counter = Math.min(counter, lengthCounts.length-1);
    //        lengthCounts[counter]++;
    //        offset = offset + counter;
    //        counter = 0;
    //    }
    //}

    //System.out.println(a.toString(lengthCounts));
    //System.exit(1);

    transitionScores = computeTransitionScores();
    Pair<double[], double[]> meansAndVars = computeStats();
    widthMeans = meansAndVars.getFirst();
    widthVars = meansAndVars.getSecond();
}
 
开发者ID:tberg12,项目名称:klavier,代码行数:33,代码来源:IMSLPIndepTransitionReader.java

示例12: decode

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
public static Pair<TransitionState[],int[]> decode(EmissionModel emissionModel, TransitionModel transitionModel, int beamSize) {
  GeneralPriorityQueue<SparseSemiMarkovDP.BeamState>[] alphas = doForwardPass(emissionModel, transitionModel, beamSize);
  Pair<TransitionState[],int[]> statesAndWidths = followBackpointers(alphas, emissionModel);
  TransitionState[] decodeStates = statesAndWidths.getFirst();
  int[] decodeWidths = statesAndWidths.getSecond();
  return Pair.makePair(decodeStates, decodeWidths);
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:8,代码来源:SparseSemiMarkovDP.java

示例13: addNullBackpointers

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
private static Collection<BeamState> addNullBackpointers(Collection<Pair<TransitionState,Double>> without) {
  List<BeamState> with = new ArrayList<BeamState>();
  for (Pair<TransitionState,Double> startPair : without) {
    BeamState beamState = new BeamState(startPair.getFirst());
    beamState.score = startPair.getSecond();
    beamState.backPointer = Pair.makePair(-1, null);
    with.add(beamState);
  }
  return with;
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:11,代码来源:SparseSemiMarkovDP.java

示例14: followBackpointers

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
private static Pair<TransitionState[],int[]> followBackpointers(GeneralPriorityQueue<SparseSemiMarkovDP.BeamState>[] alphas, EmissionModel emissionModel) {
  List<TransitionState> transStateDecodeList = new ArrayList<TransitionState>();
  List<Integer> widthsDecodeList = new ArrayList<Integer>();
  TransitionState bestFinalTs = null;
  double bestFinalScore = Double.NEGATIVE_INFINITY;
  for (BeamState beamState : alphas[emissionModel.sequenceLength()].getObjects()) {
    double score = beamState.score + beamState.transState.endScore();
    if (score > bestFinalScore) {
      bestFinalScore = score;
      bestFinalTs = beamState.transState;
    }
  }

  int currentT = emissionModel.sequenceLength();
  TransitionState currentTs = bestFinalTs;
  while (true) {
    Pair<Integer,TransitionState> backpointer = alphas[currentT].getObject(new BeamState(currentTs)).backPointer;
    int width =  currentT - backpointer.getFirst();
    transStateDecodeList.add(currentTs);
    widthsDecodeList.add(width);
    currentT = backpointer.getFirst();
    currentTs = backpointer.getSecond();
    if (currentT == 0) {
      break;
    }
  }

  Collections.reverse(transStateDecodeList);
  Collections.reverse(widthsDecodeList);
  int[] widthsDecode = a.toIntArray(widthsDecodeList);
  return Pair.makePair(transStateDecodeList.toArray(new TransitionState[0]), widthsDecode);
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:33,代码来源:SparseSemiMarkovDP.java

示例15: 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[] sqrGradSum = new double[guess.length];
	a.addi(sqrGradSum, delta);
	final double r = eta * regConstant;
	for (int epoch=0; epoch<epochs; ++epoch) {
		double epochValSum = 0.0;
		double[] epochGradSum = new double[guess.length];
		for (int funcIndex : a.shuffle(a.enumerate(0, functions.size()), rand)) {
			DifferentiableFunction func = functions.get(funcIndex);
			Pair<Double,double[]> valAndGrad = func.calculate(guess);
			epochValSum += valAndGrad.getFirst();
			double[] grad = valAndGrad.getSecond();
			a.combi(epochGradSum, 1.0, grad, 1.0);
		
			double[] sqrGrad = a.sqr(grad);
			a.combi(sqrGradSum, 1.0, sqrGrad, 1.0);
			
			for (int i=0; i<guess.length; ++i) {
				double s = Math.sqrt(sqrGradSum[i]);
				guess[i] = (s * guess[i] - eta * grad[i]) / (r + s);
			}
		}
		if (verbose) System.out.println(String.format("[AdaGradMinimizer.minimize] Epoch %d ended with value %.6f", epoch, epochValSum + regConstant * a.innerProd(guess, guess)));
		if (iterCallbackFunction != null) iterCallbackFunction.callback(guess, epoch, epochValSum, epochGradSum);
	}
	return guess;
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:30,代码来源:AdaGradL2Minimizer.java


注:本文中的tberg.murphy.tuple.Pair.getFirst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。