Java Pair.makePair方法代码示例(javapair.makepair方法的典型用法代码示例)

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


Java Pair.makePair方法代码示例(javapair.makepair方法的典型用法代码示例)

在下文中一共展示了Pair.makePair方法的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: next

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
public Pair<Pair<Integer, Integer>, Double> next() {
	if (startCondProbs == null) {
		this.d = 0;
		this.s = 0;
		this.startCondProbs = startNodeCondProbs(d);
	} else {
		if (s == numStates(d,0)-1) {
			this.s = 0;
			this.d++;
			this.startCondProbs = startNodeCondProbs(d);
		} else {
			this.s++;
		}
	}
	return Pair.makePair(Pair.makePair(d, s), startCondProbs[s]);
} 
开发者ID:tberg12,项目名称:murphy,代码行数:17,代码来源:ForwardBackward.java

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

示例4: 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

示例5: computeMarginalsLogSpace

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
public static Pair<NodeMarginals,StationaryEdgeMarginals> computeMarginalsLogSpace(final StationaryLattice lattice, final StationaryStateProjector nodeMarginalsStateProjector, final boolean viterbiEmissionOnly, int numThreads) {
		final NodeMarginalsLogSpace projectedNodeMarginals = new NodeMarginalsLogSpace(new StationaryLatticeWrapper(lattice), nodeMarginalsStateProjector);
		final StationaryEdgeMarginalsLogSpace edgeMarginals = (viterbiEmissionOnly ? null : new StationaryEdgeMarginalsLogSpace(lattice));
		BetterThreader.Function<Integer,Object> func = new BetterThreader.Function<Integer,Object>(){public void call(Integer d, Object ignore){
			float[][] alphas = doPassLogSpace(new StationaryLatticeWrapper(lattice), false, viterbiEmissionOnly, d);
			float[][] betas = doPassLogSpace(new StationaryLatticeWrapper(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, (StationaryEdgeMarginals) edgeMarginals);
	} 
开发者ID:tberg12,项目名称:murphy,代码行数:17,代码来源:ForwardBackward.java

示例6: 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

示例7: 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

示例8: computeSpect

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
public static Pair<float[][],Float> computeSpect(Wave wave) {
	long start = System.nanoTime();
	float[][] spect = STFT.downsample(STFT.rstftMagnitudes(wave.amplitudes, Main.stftWindowSize, Main.stftWindowType, Main.stftHopSize, Main.stftFrequencyPrefixSize, Main.stftFrequencyOffset, Main.numThreads), Main.stftDownsampleSpectrogramHopSize);
	if (SPECT_POW) {
		a.powi(spect, POW);
	}
	if (SPECT_DIVIDE_BY_MAX) {
		divideByMax(spect);
	}
	if (SPECT_STRETCH_TO_UNIT) {
		stretchToUnit(spect);
	}
	if (SPECT_LOG) {
		logSpace(spect);
		stretchToUnit(spect);
	}
	if (SPECT_SCALE) {
		a.scalei(spect, SCALE);
	}
	if (SPECT_BUCKET) {
		bucket(spect);
	}
	float secondsPerSample = (1.0f / wave.sampleRateHz);
	float samplesPerFrame = Main.stftHopSize * Main.stftDownsampleSpectrogramHopSize;
	float secondsPerFrame = secondsPerSample * samplesPerFrame;
	long end = System.nanoTime();
	System.out.println("Compute spect time: "+(end - start)/(1e9)+"s");
	return Pair.makePair(spect, secondsPerFrame);
} 
开发者ID:tberg12,项目名称:klavier,代码行数:30,代码来源:Preprocessing.java

示例9: getCERSuffStats

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
public static Pair<Integer,Integer> getCERSuffStats(List<String>[] guessChars, List<String>[] goldChars, boolean removePunc, boolean allowFSConfusion, boolean charIncludesDiacritic) {
	String guessStr = fullyNormalize(guessChars, removePunc);
	String goldStr = fullyNormalize(goldChars, removePunc);
	Form guessForm = Form.charsAsGlyphs(guessStr, charIncludesDiacritic);
	Form goldForm = Form.charsAsGlyphs(goldStr, charIncludesDiacritic);
	EditDistanceParams params = EditDistanceParams.getStandardParams(guessForm, goldForm, allowFSConfusion);
	MarkovEditDistanceComputer medc = new MarkovEditDistanceComputer(params);
	AlignedFormPair alignedPair = medc.runEditDistance();
	return Pair.makePair((int)alignedPair.cost, goldForm.length());
} 
开发者ID:tberg12,项目名称:ocular,代码行数:11,代码来源:Evaluator.java

示例10: 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

示例11: 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

示例12: buildSpectralAtomsAndEnvelopes

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
private static Pair<Pair<float[][],float[][]>,Float> buildSpectralAtomsAndEnvelopes(String notesBasePath, String notesPaths, String instrName) {
		JaggedMatrixAverager spectralAtomsAvg = new JaggedMatrixAverager(PitchEventIO.N_MIDI_PITCH_IDS);
		JaggedMatrixAverager envelopesAvg = new JaggedMatrixAverager(PitchEventIO.N_MIDI_PITCH_IDS);
		float secondsPerFrame = 0.0f;
		for (String notesPath : notesPaths.trim().split(":")) {
			List<Datum> data = DatasetIO.readLabeledData(notesBasePath+"/"+instrName+"/"+notesPath, Float.POSITIVE_INFINITY);
			System.out.println(notesBasePath+"/"+instrName+"/"+notesPath+" num: "+data.size());
			for (Datum datum : data) {
				Pair<float[][],Float> spectAndSecondsPerFrame = computeSpect(datum.wave);
				float[][] spect = spectAndSecondsPerFrame.getFirst();
				secondsPerFrame = spectAndSecondsPerFrame.getSecond();
				for (int i=0; i<datum.events.size(); ++i) {
					int noteIndex = datum.events.get(i).noteIndex;
					if (noteIndex >= 0 && noteIndex < PitchEventIO.N_MIDI_PITCH_IDS) {

						List<float[]> subSpectList = new ArrayList<float[]>();
						for (int t : PitchEventUtil.framesByOverlap(datum.events.get(i).onsetSec + ((float) Main.initSpectEnvNotesOffsetMs * 1e-3f), datum.events.get(i).offsetSec + ((float) Main.initSpectEnvNotesOffsetMs * 1e-3f), secondsPerFrame, 0, spect.length-1)) {
//						for (int t : PitchEventUtil.framesByCenterWithinInterval(datum.events.get(i).onsetSec + ((float) Main.notesOffsetMs * 1e-3f), datum.events.get(i).offsetSec + ((float) Main.notesOffsetMs * 1e-3f), secondsPerFrame, 0, spect.length-1)) {
							subSpectList.add(spect[t]);
						}
						if (subSpectList.isEmpty()) continue;
						float[][] subSpect = subSpectList.toArray(new float[0][]);

						Pair<float[][],float[][]> atomAndEnvelope = null;
						if (Main.nmfType == NMFType.KL) {
							atomAndEnvelope = NMFUtilOpenCL.nmfKL(subSpect, 1, 20, (float) Main.nmfSilenceEps, (float) Main.nmfMinEps);
						} else if (Main.nmfType == NMFType.Beta) {
							atomAndEnvelope = NMFUtilOpenCL.nmfBeta(subSpect, 1, 20, (float) Main.nmfSilenceEps, (float) Main.nmfMinEps, (float) Main.nmfBeta);
						} else if (Main.nmfType == NMFType.LogNormal) {
							int iters = 2000;
							float startStepSize = 1e-8f;
							float endStepSize = 1e-8f;
							float init = 1e-5f;
							atomAndEnvelope = NMFUtilOpenCL.nmfLogNormalExpGrad(a.scale(a.onesFloat(1, subSpect[0].length), init), true, a.scale(a.onesFloat(subSpect.length, 1), init), true, subSpect, startStepSize, endStepSize, iters, (float) Main.nmfSilenceEps, (float) Main.nmfMinEps, (float) Main.nmfC);
							while (a.hasinf(atomAndEnvelope.getFirst()) || a.hasnan(atomAndEnvelope.getFirst()) || a.hasinf(atomAndEnvelope.getSecond()) || a.hasnan(atomAndEnvelope.getSecond())) {
								startStepSize *= 0.8;
								endStepSize *= 0.8;
								atomAndEnvelope = NMFUtilOpenCL.nmfLogNormalExpGrad(a.scale(a.onesFloat(1, subSpect[0].length), init), true, a.scale(a.onesFloat(subSpect.length, 1), init), true, subSpect, startStepSize, endStepSize, iters, (float) Main.nmfSilenceEps, (float) Main.nmfMinEps, (float) Main.nmfC);
							}
						} else {
							atomAndEnvelope = NMFUtilOpenCL.nmfL2(subSpect, 1, 20, (float) Main.nmfSilenceEps, (float) Main.nmfMinEps);
						}
						float[] atom = atomAndEnvelope.getFirst()[0];
						float[] envelope = a.transpose(atomAndEnvelope.getSecond())[0];

//						a.scalei(atom, 1.0f / a.max(atom));
//						a.scalei(atom, 1.0f / a.sum(atom));
						a.scalei(atom, 1.0f / (float) Math.sqrt(a.sum(a.sqr(atom))));
						spectralAtomsAvg.observe(noteIndex, atom);

						a.scalei(envelope, 1.0f / a.max(envelope));
						envelopesAvg.observe(noteIndex, envelope);
					}
				}
			}
		}
		return Pair.makePair(Pair.makePair(spectralAtomsAvg.getAverage(), envelopesAvg.getAverage()), secondsPerFrame);
	} 
开发者ID:tberg12,项目名称:klavier,代码行数:59,代码来源:Preprocessing.java

示例13: gradientTester

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
public static void gradientTester(float[][] Wtrans0, float[][] Htrans0, float[][] Xtrans0, float silenceEps) {
	int[] loud = null;
	if (silenceEps > 0.0) {
		Pair<float[][], int[]> filterSilence = filterSilence(Xtrans0, silenceEps);
		Xtrans0 = filterSilence.getFirst();
		loud = filterSilence.getSecond();
		Htrans0 = filterSilence(Htrans0, loud);
	}

	// W : n x r
	// H : r x m
	// X : n x m

	final int n = Xtrans0[0].length;
	final int m = Xtrans0.length;
	final int r = Wtrans0.length;

	System.out.println("Gradient Test GPU: ");

	final Matrix X = Matrix.build(a.transpose(Xtrans0));
	float[] flattenedWinit = Matrix.build(a.transpose(Wtrans0)).toArray();
	float[] flattenedHinit = Matrix.build(a.transpose(Htrans0)).toArray();

	DifferentiableFunction obj = new DifferentiableFunction() {
		public Pair<Double, double[]> calculate(double[] xDouble) {
			float[] x = a.toFloat(xDouble);
			Matrix W = Matrix.build(n, r, Arrays.copyOfRange(x, 0, n * r));
			Matrix H = Matrix.build(r, m, Arrays.copyOfRange(x, n * r, n * r + r * m));
			// Matrix Htrans = H.transpose();
			// Matrix Wtrans = W.transpose();
			Matrix WH = W.mmul(H);
			// Matrix logX = X.log();
			// Matrix logWH = WH.log();
			// float c = 1.0f;
			// Matrix logXsubLogWHdivWH = logX.sub(logWH).add(Matrix.ones(n,
			// m).mul(c)).div(WH);

			float beta = 0.5f;
			Matrix WHbetaSub1 = WH.pow(beta - 1.0f);
			Matrix WHbetaSub2 = WH.pow(beta - 2.0f);
			Matrix gH = W.transpose().mmul(WHbetaSub1.sub(X.mul(WHbetaSub2)));
			Matrix gW = (WHbetaSub1.sub(X.mul(WHbetaSub2))).mmul(H.transpose());
			double val = (1.0f / (beta * (beta - 1.0f))) * (X.pow(beta).norm1()
					+ (beta - 1.0f) * WH.pow(beta).norm1() - beta * (X.mul(WH.pow(beta - 1.0f)).norm1()));

			// Matrix gW = logXsubLogWHdivWH.mmul(Htrans).mul(-2.0f);
			// Matrix gH = Wtrans.mmul(logXsubLogWHdivWH).mul(-2.0f);
			// double val = Math.pow(logX.sub(logWH).add(Matrix.ones(n,
			// m).mul(c)).norm2(), 2.0);

			// Matrix gW = (X.mmul(Htrans)).comb(-2.0f, 2.0f,
			// (WH).mmul(Htrans));
			// Matrix gH = (Wtrans.mmul(X)).comb(-2.0f, 2.0f,
			// Wtrans.mmul(WH));
			// double val = Math.pow(X.distance2(WH), 2.0);
			Pair<Double, double[]> result = Pair.makePair(val, a.toDouble(a.append(gW.toArray(), gH.toArray())));
			CublasUtil.freeAllBut(X);
			return result;
		}
	};

	EmpiricalGradientTester.test(obj, a.toDouble(a.append(flattenedWinit, flattenedHinit)), 1e-2, 1.0, 1e-7);
} 
开发者ID:tberg12,项目名称:klavier,代码行数:64,代码来源:NMFUtil.java

示例14: gradientTester

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
public static void gradientTester(float[][] Wtrans0, float[][] Htrans0, float[][] Xtrans0, float silenceEps) {
	int[] loud = null;
	if (silenceEps > 0.0) {
		Pair<float[][], int[]> filterSilence = filterSilence(Xtrans0, silenceEps);
		Xtrans0 = filterSilence.getFirst();
		loud = filterSilence.getSecond();
		Htrans0 = filterSilence(Htrans0, loud);
	}

	// W : n x r
	// H : r x m
	// X : n x m

	final int n = Xtrans0[0].length;
	final int m = Xtrans0.length;
	final int r = Wtrans0.length;

	System.out.println("Gradient Test GPU: ");

	final Matrix X = Matrix.build(a.transpose(Xtrans0));
	float[] flattenedWinit = Matrix.build(a.transpose(Wtrans0)).toArray();
	float[] flattenedHinit = Matrix.build(a.transpose(Htrans0)).toArray();

	DifferentiableFunction obj = new DifferentiableFunction() {
		public Pair<Double, double[]> calculate(double[] xDouble) {
			float[] x = a.toFloat(xDouble);
			Matrix W = Matrix.build(n, r, Arrays.copyOfRange(x, 0, n * r));
			Matrix H = Matrix.build(r, m, Arrays.copyOfRange(x, n * r, n * r + r * m));
			// Matrix Htrans = H.transpose();
			// Matrix Wtrans = W.transpose();
			Matrix WH = W.mmul(H);
			// Matrix logX = X.log();
			// Matrix logWH = WH.log();
			// float c = 1.0f;
			// Matrix logXsubLogWHdivWH = logX.sub(logWH).add(Matrix.ones(n,
			// m).mul(c)).div(WH);

			float beta = 0.5f;
			Matrix WHbetaSub1 = WH.pow(beta - 1.0f);
			Matrix WHbetaSub2 = WH.pow(beta - 2.0f);
			Matrix gH = W.transpose().mmul(WHbetaSub1.sub(X.mul(WHbetaSub2)));
			Matrix gW = (WHbetaSub1.sub(X.mul(WHbetaSub2))).mmul(H.transpose());
			double val = (1.0f / (beta * (beta - 1.0f))) * (X.pow(beta).norm1()
					+ (beta - 1.0f) * WH.pow(beta).norm1() - beta * (X.mul(WH.pow(beta - 1.0f)).norm1()));

			// Matrix gW = logXsubLogWHdivWH.mmul(Htrans).mul(-2.0f);
			// Matrix gH = Wtrans.mmul(logXsubLogWHdivWH).mul(-2.0f);
			// double val = Math.pow(logX.sub(logWH).add(Matrix.ones(n,
			// m).mul(c)).norm2(), 2.0);

			// Matrix gW = (X.mmul(Htrans)).comb(-2.0f, 2.0f,
			// (WH).mmul(Htrans));
			// Matrix gH = (Wtrans.mmul(X)).comb(-2.0f, 2.0f,
			// Wtrans.mmul(WH));
			// double val = Math.pow(X.distance2(WH), 2.0);
			Pair<Double, double[]> result = Pair.makePair(val, a.toDouble(a.append(gW.toArray(), gH.toArray())));
			JOCLBlasUtil.freeAllBut(X);
			return result;
		}
	};

	EmpiricalGradientTester.test(obj, a.toDouble(a.append(flattenedWinit, flattenedHinit)), 1e-2, 1.0, 1e-7);
} 
开发者ID:tberg12,项目名称:klavier,代码行数:64,代码来源:NMFUtilOpenCL.java

示例15: getWERSuffStats

import tberg.murphy.tuple.Pair; //导入方法依赖的package包/类
public static Pair<Integer,Integer> getWERSuffStats(List<String>[] guessChars, List<String>[] goldChars, boolean removePunc, boolean allowFSConfusion) {
	AlignedFormPair alignedPair = getWordAlignments(guessChars, goldChars, removePunc, allowFSConfusion);
	return Pair.makePair((int)alignedPair.cost, alignedPair.trg.length());
} 
开发者ID:tberg12,项目名称:ocular,代码行数:5,代码来源:Evaluator.java

本文标签属性:

示例:示例是什么意思

代码:代码编程

java:java自行车

Pair:pair是什么意思中文翻译

makePair:makepair用法

上一篇:万宁市在哪个省(万宁哪些城市有)(万宁市在哪个城市)
下一篇:C++ CPaintDC::Rectangle方法代码示例

为您推荐