Exemplo n.º 1
0
    def step(self, anneal, model_params, my_data):
        """ Perform an EM-step """

        # Noisify model parameters
        model_params = self.noisify_params(model_params, anneal)

        # Sanity check model parameters
        model_params = self.check_params(model_params)

        # For partial EM-step: select batch
        my_pdata = self.select_partial_data(anneal, my_data)

        # Annotate partial dataset with hidden-state candidates
        my_pdata = self.select_Hprimes(model_params, my_pdata)

        # Do E-step and calculate joint-probabilities
        my_joint_prob = self.E_step(anneal, model_params, my_pdata)

        # Use joint-probabilities to derive new parameter set
        new_model_params = self.M_step(
            anneal, model_params, my_joint_prob, my_pdata)

        # Calculate Objecive Function
        #[Q, theo_Q] = self.objective(my_joint_prob, model_params, my_pdata)
        #dlog.append('Q', Q)
        #dlog.append('theo_Q', theo_Q)

        # Log iboth model parameters and annealing parameters
        dlog.append_all(new_model_params)
        dlog.append_all(anneal.as_dict())

        return new_model_params
Exemplo n.º 2
0
               'sigma_gt')
    dlog.set_handler(print_list, TextPrinter)
    dlog.set_handler(print_list, StoreToTxt, output_path + '/result.h5')
    dlog.set_handler(h5_list, StoreToH5, output_path + '/result.h5')
    dlog.append('W_gt', params_gt['W'])
    dlog.append('sigma_gt', params_gt['sigma'])
    dlog.append('pi_gt', params_gt['pi'])
    dlog.append('N', N)
    dlog.append('Hprime', Hprime)
    dlog.append('H', H)
    dlog.append('gamma', gamma)
    dlog.append('states', states)

    model_params = model.standard_init(my_data)

    dlog.append_all(model_params)
    for param_name in model_params.keys():
        if param_name not in model.to_learn:
            model_params[param_name] = params_gt[param_name]

    model.s_gt = my_s
    # Choose annealing schedule
    anneal = LinearAnnealing(100)
    anneal['T'] = [(0.0, 2.), (0.1, 2.), (0.4, 1.)]
    anneal['Ncut_factor'] = [(0, 0.0), (0.6, 0.0), (0.9, 1.)]
    # anneal['W_noise'] = [(0, 5.0), (.6, 0.0)]
    # anneal['pi_noise'] = [(0, 0.1), (.6, 0.0)]
    anneal['anneal_prior'] = False

    # Create and start EM annealing
    em = EM(model=model, anneal=anneal)