Skip to content

Instantly share code, notes, and snippets.

@chaosct
Last active March 8, 2016 16:30
Show Gist options
  • Save chaosct/71e9f1412397f6e67d33 to your computer and use it in GitHub Desktop.
Save chaosct/71e9f1412397f6e67d33 to your computer and use it in GitHub Desktop.
replicating XMM crash
import xmm
import numpy as np
class GMM_regression(object):
def __init__(self):
self.clear(3,8)
def clear(self, idim = None, odim = None):
self.input_dimensions = idim or self.input_dimensions
self.output_dimensions = odim or self.output_dimensions
self.dimensions = self.input_dimensions + self.output_dimensions
self.labels = set()
self.now_training = None
self.now_performing = False
self.training_set = xmm.TrainingSet(xmm.BIMODAL)
self.training_set.set_dimension(self.dimensions)
self.training_set.set_dimension_input(self.input_dimensions)
self.gmm = xmm.GMMGroup(xmm.BIMODAL)
self.gmm.set_trainingSet(self.training_set)
self.output_vec = None
def record(self,n):
self.now_training = int(n)
def input(self,*l):
if self.now_training is not None:
self.labels.add(self.now_training)
if self.output_vec:
print "training", l+self.output_vec
self.training_set.recordPhrase(self.now_training,l+self.output_vec)
elif self.now_performing:
self.gmm.performance_update(l)
self.send('/instant',*self.gmm.results_instant_likelihoods)
self.send('/normalized',*self.gmm.results_normalized_likelihoods)
self.send('/log',*self.gmm.results_log_likelihoods)
self.send('/predicted',*self.gmm.results_predicted_output)
def output(self,*l):
self.output_vec = l
def train(self, nbmc=10, vo1=1., vo2=0.01):
for n in self.labels:
self.training_set.setPhraseLabel(n,xmm.Label(n+1))
self.gmm.set_nbMixtureComponents(nbmc)
self.gmm.set_varianceOffset(vo1, vo2)
self.gmm.train()
print "number of models: ", self.gmm.size()
for label in self.gmm.models.keys():
print "model", label.getInt(), ": trained in ", self.gmm.models[label].trainingNbIterations, \
"iterations, loglikelihood = ", self.gmm.models[label].trainingLogLikelihood
def perform(self, lw=40):
self.gmm.set_likelihoodwindow(40)
self.gmm.performance_init()
self.now_training = None
self.now_performing = True
def send(self, addr, *args):
print addr, args
gmm = GMM_regression()
gmm.clear(3,8)
gmm.record(0)
gmm.output(1,2,3,4,5,6,7,8)
for n in range(10):
gmm.input(2,3,4)
gmm.record(1)
gmm.output(8,7,6,5,4,3,2,1)
for n in range(10):
gmm.input(3,4,5)
gmm.train()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment