<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# SMC.py: Tomgraphic models module
##
# © 2012 <NAME> (<EMAIL>) and
#        <NAME> (<EMAIL>)
#     
# This file is a part of the Qinfer project.
# Licensed under the AGPL version 3.
##
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
##

## IMPORTS ##

import numpy as np

class StateModel(object):
    """
    Represents an experimental system with unknown quantum state,
    and known measurement operators.
    """    
    
    def __init__(self, hs_dim):
        self.hs_dim = hs_dim
        
    def likelihood(outcomes,expparams,modelparams):
        """
        Calculates the likelihood function at the states specified 
        by modelparams and measurement specified by expparams.
        This is given by the Born rule and is the probability of
        outcomes given the state and measurement operators.
        
        Parameters
        ----------
        outcomes = 
            measurement outcome counts
        expparams = 
            measurement operator specs and other experimental specs
        modelparams = 
            quantum state specs
        """
        
        # assumes Pauli X,Y,Z measurements for now (i.e. expparams does nothing)
        
        ps = method to turn params to probabilities(expparams,modelparams)                
        prob = some function for multinomial PDF(outcomes,ps)
                
        return prob
        
    def params2probs(expparams,modelparams):
        """
        Converts (via the Born rule) a description of the states and
        measurements to probabilities
        
        Parameters
        ----------
        expparams = 
            measurement operator specs and other experimental specs
        modelparams = 
            quantum state specs
        """
        
        # assumes Pauli X,Y,Z measurements for now (i.e. expparams does nothing)
        ps = zeros((,3))
        
        return ps<commit_msg>helper methods for tomography likelihood function writen<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# SMC.py: Tomgraphic models module
##
# © 2012 <NAME> (<EMAIL>) and
#        <NAME> (<EMAIL>)
#     
# This file is a part of the Qinfer project.
# Licensed under the AGPL version 3.
##
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
##

## IMPORTS ##

import numpy as np

class StateModel(object):
    """
    Represents an experimental system with unknown quantum state,
    and known measurement operators.
    """    
    
    def __init__(self, hs_dim):
        self.hs_dim = hs_dim
        
    def likelihood(outcomes,expparams,modelparams):
        """
        Calculates the likelihood function at the states specified 
        by modelparams and measurement specified by expparams.
        This is given by the Born rule and is the probability of
        outcomes given the state and measurement operators.
        
        Parameters
        ----------
        outcomes = 
            measurement outcome counts
        expparams = 
            measurement operator specs and other experimental specs
        modelparams = 
            quantum state specs
        """
        
        # assumes Pauli X,Y,Z measurements for now (i.e. expparams does nothing)
        
        ps = self.params2probs(expparams,modelparams)                
        prob = self.finalprobs(outcomes,ps)
                
        return prob
        
    def params2probs(expparams,modelparams):
        """
        Converts (via the Born rule) a description of the states and
        measurements to probabilities
        
        Parameters
        ----------
        expparams = 
            measurement operator specs and other experimental specs
        modelparams = 
            quantum state specs
        """
        # assumes qubit state in Pauli basis
        state = 0.5 * (PauliI + modelparams[1]*PauliX +
            modelparams[2]*PauliY + modelparams[3]*PauliZ)        
        
        
        # assumes Pauli X,Y,Z measurements for now (i.e. expparams does nothing)
        ps = np.zeros((3,))
        
        ps[1] = 0.5*(1+np.trace(np.dot(PauliX,state)))
        ps[2] = 0.5*(1+np.trace(np.dot(PauliY,state)))
        ps[3] = 0.5*(1+np.trace(np.dot(PauliZ,state)))
        
        return ps
        
    def finalprob(outcomes,ps):
        """
        Converts the probabilities of each measurement into the final 
        
        Parameters
        ----------
        outcomes = 
            measurement outcome counts
        ps = 
            probabilities for each measurement outcome
        """

        # assumes each measurement is Bernoulli trial
        prob = outcomes        
                
        return prob
{'fraction_non_alphanumeric': 0.07440183546378237, 'fraction_numerical': 0.0058997050147492625, 'mean_word_length': 1.8692994828396803, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2454012', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1558, 'n_words': 598}