/** * Informs this sequence model that the value of the whole sequence is initialized to sequence * */ public void setInitialSequence(int[] sequence) { if(models != null){ for (SequenceListener model : models) model.setInitialSequence(sequence); return; } model1.setInitialSequence(sequence); model2.setInitialSequence(sequence); }
/** * Informs this sequence model that the value of the element at position pos has changed. * This allows this sequence model to update its internal model if desired. * */ public void updateSequenceElement(int[] sequence, int pos, int oldVal) { if(models != null){ for (SequenceListener model : models) model.updateSequenceElement(sequence, pos, oldVal); return; } model1.updateSequenceElement(sequence, pos, oldVal); model2.updateSequenceElement(sequence, pos, oldVal); }
/** * Samples the sequence repeatedly, making numSamples passes over the entire sequence. */ public double sampleSequenceRepeatedly(SequenceModel model, int[] sequence, int numSamples) { sequence = copy(sequence); // so we don't change the initial, or the one we just stored listener.setInitialSequence(sequence); double returnScore = Double.NEGATIVE_INFINITY; for (int iter=0; iter<numSamples; iter++) { returnScore = sampleSequenceForward(model, sequence); } return returnScore; }
/** * Samples a single position in the sequence. * Destructively modifies the sequence in place. * returns the score of the new sequence * @param sequence the sequence to start with * @param pos the position to sample. * @param temperature the temperature to control annealing */ public double samplePosition(SequenceModel model, int[] sequence, int pos, double temperature) { int oldTag = sequence[pos]; Pair<Integer, Double> newPosProb = samplePositionHelper(model, sequence, pos, temperature); int newTag = newPosProb.first(); // System.out.println("Sampled " + oldTag + "->" + newTag); sequence[pos] = newTag; listener.updateSequenceElement(sequence, pos, oldTag); return newPosProb.second(); }
/** * Collects numSamples samples of sequences, from the distribution over sequences defined * by the sequence model passed on construction. * All samples collected are sampleInterval samples apart, in an attempt to reduce * autocorrelation. * @return a Counter containing the sequence samples, as arrays of type int, and their scores */ public List<int[]> collectSamples(SequenceModel model, int numSamples, int sampleInterval, int[] initialSequence) { if (verbose>0) log.info("Collecting samples"); listener.setInitialSequence(initialSequence); List<int[]> result = new ArrayList<>(); int[] sequence = initialSequence; for (int i=0; i<numSamples; i++) { sequence = copy(sequence); // so we don't change the initial, or the one we just stored sampleSequenceRepeatedly(model, sequence, sampleInterval); // modifies tagSequence result.add(sequence); // save it to return later if (verbose>0) log.info("."); System.err.flush(); } if (verbose>1) { log.info(); printSamples(result, System.err); } if (verbose>0) log.info("done."); return result; }
/** * Informs this sequence model that the value of the element at position pos has changed. * This allows this sequence model to update its internal model if desired. * */ public void updateSequenceElement(int[] sequence, int pos, int oldVal) { if(models != null){ for (SequenceListener model : models) model.updateSequenceElement(sequence, pos, oldVal); return; } model1.updateSequenceElement(sequence, pos, oldVal); model2.updateSequenceElement(sequence, pos, oldVal); }
public int[] findBestUsingAnnealing(SequenceModel model, CoolingSchedule schedule, int[] initialSequence) { if (verbose>0) log.info("Doing annealing"); listener.setInitialSequence(initialSequence); List result = new ArrayList();
/** * Informs this sequence model that the value of the element at position pos has changed. * This allows this sequence model to update its internal model if desired. * */ public void updateSequenceElement(int[] sequence, int pos, int oldVal) { if(models != null){ for(int i = 0; i < models.length; i++) models[i].updateSequenceElement(sequence, pos, oldVal); return; } model1.updateSequenceElement(sequence, pos, oldVal); model2.updateSequenceElement(sequence, pos, oldVal); }
/** * Informs this sequence model that the value of the whole sequence is initialized to sequence * */ public void setInitialSequence(int[] sequence) { if(models != null){ for (SequenceListener model : models) model.setInitialSequence(sequence); return; } model1.setInitialSequence(sequence); model2.setInitialSequence(sequence); }
/** * Informs this sequence model that the value of the element at position pos has changed. * This allows this sequence model to update its internal model if desired. * */ public void updateSequenceElement(int[] sequence, int pos, int oldVal) { if(models != null){ for(int i = 0; i < models.length; i++) models[i].updateSequenceElement(sequence, pos, oldVal); return; } model1.updateSequenceElement(sequence, pos, 0); model2.updateSequenceElement(sequence, pos, 0); }
/** * Informs this sequence model that the value of the whole sequence is initialized to sequence * */ public void setInitialSequence(int[] sequence) { if(models != null){ for(int i = 0; i < models.length; i++) models[i].setInitialSequence(sequence); return; } model1.setInitialSequence(sequence); model2.setInitialSequence(sequence); }
/** * Samples a single position in the sequence. * Destructively modifies the sequence in place. * returns the score of the new sequence * @param sequence the sequence to start with * @param pos the position to sample. * @param temperature the temperature to control annealing */ public double samplePosition(SequenceModel model, int[] sequence, int pos, double temperature) { int oldTag = sequence[pos]; Pair<Integer, Double> newPosProb = samplePositionHelper(model, sequence, pos, temperature); int newTag = newPosProb.first(); // System.out.println("Sampled " + oldTag + "->" + newTag); sequence[pos] = newTag; listener.updateSequenceElement(sequence, pos, oldTag); return newPosProb.second(); }
/** * Informs this sequence model that the value of the whole sequence is initialized to sequence * */ public void setInitialSequence(int[] sequence) { if(models != null){ for(int i = 0; i < models.length; i++) models[i].setInitialSequence(sequence); return; } model1.setInitialSequence(sequence); model2.setInitialSequence(sequence); }
/** * Samples a single position in the sequence. * Destructively modifies the sequence in place. * returns the score of the new sequence * @param sequence the sequence to start with * @param pos the position to sample. * @param temperature the temperature to control annealing */ public double samplePosition(SequenceModel model, int[] sequence, int pos, double temperature) { int oldTag = sequence[pos]; Pair<Integer, Double> newPosProb = samplePositionHelper(model, sequence, pos, temperature); int newTag = newPosProb.first(); // System.out.println("Sampled " + oldTag + "->" + newTag); sequence[pos] = newTag; listener.updateSequenceElement(sequence, pos, oldTag); return newPosProb.second(); }
/** * Samples the sequence repeatedly, making numSamples passes over the entire sequence. */ public double sampleSequenceRepeatedly(SequenceModel model, int[] sequence, int numSamples) { sequence = copy(sequence); // so we don't change the initial, or the one we just stored listener.setInitialSequence(sequence); double returnScore = Double.NEGATIVE_INFINITY; for (int iter=0; iter<numSamples; iter++) { returnScore = sampleSequenceForward(model, sequence); } return returnScore; }
listener.updateSequenceElement(sequence, pos, oldTag); return distribution[newTag];
/** * Samples the sequence repeatedly, making numSamples passes over the entire sequence. */ public void sampleSequenceRepeatedly(SequenceModel model, int[] sequence, int numSamples) { sequence = copy(sequence); // so we don't change the initial, or the one we just stored listener.setInitialSequence(sequence); for (int iter=0; iter<numSamples; iter++) { sampleSequenceForward(model, sequence); } }
/** * Samples the sequence repeatedly, making numSamples passes over the entire sequence. */ public double sampleSequenceRepeatedly(SequenceModel model, int[] sequence, int numSamples) { sequence = copy(sequence); // so we don't change the initial, or the one we just stored listener.setInitialSequence(sequence); double returnScore = Double.NEGATIVE_INFINITY; for (int iter=0; iter<numSamples; iter++) { returnScore = sampleSequenceForward(model, sequence); } return returnScore; }
/** * Collects numSamples samples of sequences, from the distribution over sequences defined * by the sequence model passed on construction. * All samples collected are sampleInterval samples apart, in an attempt to reduce * autocorrelation. * @return a Counter containing the sequence samples, as arrays of type int, and their scores */ public List<int[]> collectSamples(SequenceModel model, int numSamples, int sampleInterval, int[] initialSequence) { if (verbose>0) System.err.print("Collecting samples"); listener.setInitialSequence(initialSequence); List<int[]> result = new ArrayList<int[]>(); int[] sequence = initialSequence; for (int i=0; i<numSamples; i++) { sequence = copy(sequence); // so we don't change the initial, or the one we just stored sampleSequenceRepeatedly(model, sequence, sampleInterval); // modifies tagSequence result.add(sequence); // save it to return later if (verbose>0) System.err.print("."); System.err.flush(); } if (verbose>1) { System.err.println(); printSamples(result, System.err); } if (verbose>0) System.err.println("done."); return result; }
/** * Collects numSamples samples of sequences, from the distribution over sequences defined * by the sequence model passed on construction. * All samples collected are sampleInterval samples apart, in an attempt to reduce * autocorrelation. * @return a Counter containing the sequence samples, as arrays of type int, and their scores */ public List<int[]> collectSamples(SequenceModel model, int numSamples, int sampleInterval, int[] initialSequence) { if (verbose>0) System.err.print("Collecting samples"); listener.setInitialSequence(initialSequence); List<int[]> result = new ArrayList<int[]>(); int[] sequence = initialSequence; for (int i=0; i<numSamples; i++) { sequence = copy(sequence); // so we don't change the initial, or the one we just stored sampleSequenceRepeatedly(model, sequence, sampleInterval); // modifies tagSequence result.add(sequence); // save it to return later if (verbose>0) System.err.print("."); System.err.flush(); } if (verbose>1) { System.err.println(); printSamples(result, System.err); } if (verbose>0) System.err.println("done."); return result; }