Beispiel #1
0
 def initialize_pi(self, pi):
     for i in range(1, self.K + 1):
         for j in range(1, self.K + 1):
             if i == j:
                 pi[i][j] = samplable.RealV(0.8)
             else:
                 pi[i][j] = samplable.RealV(0.2/ (self.K - 1))
Beispiel #2
0
 def initialize(self, dataset):
     self.M = dataset.get_label_id_size()
     print('The number of label ids = ' + str(self.M))
     self.I = dataset.get_instance_size()
     self.J = dataset.get_worker_size()
     print('Total ' + str(self.I) + ' instances and ' + str(self.J) +
           ' workers')
     self.initialK(dataset)
     print('K = ' + str(self.K))
     for i in range(1, self.I + 1):
         inst = dataset.get_instance(i)
         mcmldoc_inst = MCMLDOCInstance(inst)
         mcmldoc_inst.initialize(self.M, self.K, self.R)
         self.instances.append(mcmldoc_inst)
     for w in range(1, self.J + 1):
         worker = dataset.get_worker(w)
         mcmldoc_worker = MCMLDOCWorker(worker)
         mcmldoc_worker.initialize(self.M, self.K, self.R)
         self.workers.append(mcmldoc_worker)
     for r in range(1, self.R + 1):
         theta_list = [None]
         for m in range(1, self.M + 1):
             thetas = numpy.ndarray(shape=(self.K + 1),
                                    dtype=samplable.RealV,
                                    order='C')
             vals = utils.gen_rand_sum_one(self.K)  # todo: can optimize
             for i in range(1, self.K + 1):
                 thetas[i] = samplable.RealV(vals[i - 1])
             theta_list.append(thetas)
         self.theta_dict.setdefault(r, theta_list)
     # initialize omega
     if (len(self.omega) == 1):
         vals = utils.gen_uniform_sum_one(self.R)
         for r in range(1, self.R + 1):
             self.omega.append(samplable.RealV(vals[r - 1]))
Beispiel #3
0
 def initialize(self, M, K):
     self.M = M
     self.K = K
     for m in range(1, self.M + 1):
         self.y_list.append(samplable.IntV(0))
         probs = numpy.ndarray(shape=(self.K + 1), dtype=samplable.RealV, order='C')
         for i in range(1, self.K + 1):
             probs[i] = samplable.RealV(1.0 / self.K)
         self.y_prob_list.append(probs)
         self.likelihood_list.append(samplable.RealV(0.0))
Beispiel #4
0
 def initialize_pi_psi(self, pi, psi):
     # initialize pi
     for i in range(1, self.K + 1):
         for j in range(1, self.K + 1):
             ##  self.pi[i][j].setVal(1.0/self.K)
             if i == j:
                 pi[i][j] = samplable.RealV(0.80)
             else:
                 pi[i][j] = samplable.RealV(0.20 / (self.K - 1))
             psi[i][j] = samplable.RealV(1.0)
Beispiel #5
0
 def initialize(self, M, K, R):
     self.M = M
     self.K = K
     self.R = R
     for m in range(1, self.M + 1):
         self.y_list.append(samplable.IntV(0))
     self.y_combination.extend(utils.get_full_combination(self.M, self.K))
     for i in range(1, len(self.y_combination)):
         self.y_prob_list.append(samplable.RealV(0.0))
     self.z = samplable.IntV(0)
     for r in range(1, self.R + 1):
         self.z_prob_list.append(samplable.RealV(0.0))
Beispiel #6
0
 def random_initialize_pi(self, pi, diagonal_low, diagonal_high):
     # we get K diagonal elements randomly in the range of low - high
     diagonal = [None]
     for i in range(1, self.K + 1):
         val = random.uniform(diagonal_low, diagonal_high)
         diagonal.append(val)
     for i in range(1, self.K + 1):
         remainder = 1.0 - diagonal[i]
         parts = utils.split_val_rand(remainder, self.K - 1)
         parts_index = 0
         for j in range(1, self.K + 1):
             if i == j:
                 pi[i][j] = samplable.RealV(diagonal[i])
             else:
                 pi[i][j] = samplable.RealV(parts[parts_index])
                 parts_index += 1
Beispiel #7
0
 def initialize(self, dataset):
     self.M = dataset.get_label_id_size()
     print('The number of label ids = ' + str(self.M))
     self.I = dataset.get_instance_size()
     self.J = dataset.get_worker_size()
     print('Total ' + str(self.I) + ' instances and ' + str(self.J) +
           ' workers')
     self.initialK(dataset)
     print('K = ' + str(self.K))
     for i in range(1, self.I + 1):
         inst = dataset.get_instance(i)
         mcoc_inst = MCOCInstance(inst)
         mcoc_inst.initialize(self.M, self.K)
         self.instances.append(mcoc_inst)
     for w in range(1, self.J + 1):
         worker = dataset.get_worker(w)
         mcoc_worker = MCOCWorker(worker)
         mcoc_worker.initialize(self.M, self.K)
         self.workers.append(mcoc_worker)
     for m in range(1, self.M + 1):
         thetas = numpy.ndarray(shape=(self.K + 1),
                                dtype=samplable.RealV,
                                order='C')
         for i in range(1, self.K + 1):
             thetas[i] = samplable.RealV(1.0 / self.K)
         self.theta_list.append(thetas)
Beispiel #8
0
 def __init__(self, inst):
     self.inst = inst
     self.M = 0
     self.K = 0
     self.y_list = [None]
     self.y_prob_list = [None]
     self.likelihood = samplable.RealV(0.0)
     self.y_combination = [None]
Beispiel #9
0
 def initialize(self, M, K):
     self.M = M
     self.K = K
     self.rho_list.append(None)
     for m in range(1, self.M + 1):
         rho = samplable.RealV(0.0)
         self.initialize_rho(rho)
         self.rho_list.append(rho)
Beispiel #10
0
 def initialize(self, M, K, R):
     self.M = M
     self.K = K
     self.R = R
     # initialize rho dictionary
     for r in range(1, self.R + 1):
         rho_list = [None]
         for m in range(1, self.M + 1):
             rho = samplable.RealV(0.0)
             self.random_initialize_rho(rho, 0.7, 0.9)
             rho_list.append(rho)
         self.rho_dict.setdefault(r, rho_list)
Beispiel #11
0
 def initialize(self, M, K):
     self.M = M
     self.K = K
     for m in range(1, self.M + 1):
         self.y_list.append(samplable.IntV(0))
         probs = numpy.ndarray(shape=(self.K + 1),
                               dtype=samplable.RealV,
                               order='C')
         r = [numpy.random.random() for i in range(0, self.K)]
         s = sum(r)
         r = [i / s for i in r]
         for i in range(1, self.K + 1):
             probs[i] = samplable.RealV(r[i - 1])
         self.y_prob_list.append(probs)
Beispiel #12
0
 def initialize(self, dataset):
     self.M = dataset.get_label_id_size()
     print('The number of label ids = ' + str(self.M))
     self.I = dataset.get_instance_size()
     self.J = dataset.get_worker_size()
     print('Total ' + str(self.I) + ' instances and ' + str(self.J) +
           ' workers')
     self.initialK(dataset)
     print('K = ' + str(self.K))
     for m in range(1, self.M + 1):
         lmd = numpy.ndarray(shape=(self.K + 1, self.K + 1),
                             dtype=samplable.RealV,
                             order='C')
         prob = [None]
         nu = [None]
         for i in range(1, self.K + 1):
             nu.append(samplable.RealV(1.0))
             # \lmb diagonals bigger than the off-diagonals
             for j in range(1, self.K + 1):
                 if i == j:
                     lmd[i][j] = samplable.RealV(1.5)
                 else:
                     lmd[i][j] = samplable.RealV(0.5)
             prob.append(samplable.RealV(1.0 / self.K))
         self.nu_list.append(nu)
         self.lmd_list.append(lmd)
         self.prob_list.append(prob)
     for i in range(1, self.I + 1):
         inst = dataset.get_instance(i)
         ibcc_inst = IBCCInstance(inst)
         ibcc_inst.initialize(self.M, self.K)
         self.instances.append(ibcc_inst)
     for w in range(1, self.J + 1):
         worker = dataset.get_worker(w)
         ibcc_worker = IBCCWorker(worker)
         ibcc_worker.initialize(self.M, self.K)
         self.workers.append(ibcc_worker)
Beispiel #13
0
 def set_omega(self, vals):
     for r in range(1, self.R + 1):
         self.omega.append(samplable.RealV(vals[r]))