import shutil import random import numpy import cv from utils import cvarray from utils.prog_bar import ProgBar from gcp.gaussian import Gaussian from dpgmm import DPGMM # Tests the dpgmm model by seeing how well it fits a mixture of 2 1D Gaussians, which is visualised using open CV. # Define the Gaussian, draw the samples... dims = 1 gt_weight = [0.4, 0.6] gt = [Gaussian(dims), Gaussian(dims)] gt[0].setMean([5.0]) gt[0].setCovariance([[4.0]]) gt[1].setMean([-1.0]) gt[1].setCovariance([[4.0]]) sample_count = 2048 samples = [] for _ in xrange(sample_count): r = random.random() for i in xrange(len(gt)): r -= gt_weight[i] if r < 0.0: break x = gt[i].sample() samples.append(x)
import os import shutil import numpy import cv from utils import cvarray from utils.prog_bar import ProgBar from gcp.gaussian import Gaussian from dpgmm import DPGMM # Tests the dpgmm model by seeing how well it fits a single 1D Gaussian, which is visualised using open CV. # Define the Gaussian, draw the samples... dims = 1 gt = Gaussian(dims) gt.setMean([5.0]) gt.setCovariance([[4.0]]) sample_count = 2048 samples = [] for _ in xrange(sample_count): samples.append(gt.sample()) # Create the output directory... out_dir = 'test_1d_1mode' try: shutil.rmtree(out_dir) except: pass os.mkdir(out_dir)