<commit_before>'''
A collection of omega-potentials for Dual Averaging

@author: <NAME>
@date: May 8, 2015
'''

import numpy as np


class OmegaPotential(object):
    """ Base class for omega potentials """
        
    def phi(self, u):
        """ Returns phi(u), the value of the zero-potential at the points u"""
        return NotImplementedError
        
    def phi_prime(self, u):
        """ Returns phi'(u), the first derivative of the zero-potential at the points u """
        return NotImplementedError
 
    def phi_double_prime(self, u):
        """ Returns phi''(u), the second derivative of the zero-potential at the points u """
        return NotImplementedError
     
    def phi_inv(self, u):
        """ Returns phi^{-1}(u), the inverse function of the zero-potential at the points u """
        return NotImplementedError
    
    def alpha_opt(self, n):
        """ Returns the optimal decay parameter alpha in the learning rate 
            eta_t = theta*t**(-alpha). Here n is the dimension of the space. """
        return 1/(2 + n*self.bounds_asymp()[1])
    
    def theta_opt(self, domain, M):
        """ Computes the optimal constant theta for the learning rate eta_t = theta*t**(-alpha). """
        C, epsilon = self.bounds_asymp()
        lpsi, pdual = self.l_psi()
        n, v = domain.n, domain.v
        return np.sqrt(C*lpsi*(1+n*epsilon)/M**2/v**epsilon/(2+n*epsilon))
     
    def phi_inv_prime(self, u):
        """ Returns phi^{-1}'(u), the first derivative of the inverse 
            function of the zero-potential at the points u """
        return NotImplementedError
    
    
class ExponentialPotential(OmegaPotential):
    """ The exponential potential, which results in Entropy Dual Averaging """
    
    def __init__(self, omega=0, desc='ExpPot'):
        """ Constructor """
        if self.omega > 0:
            raise Exception('omega must be non-positive!')
        self.omega = 0
        self.desc = desc
        
    def phi(self, u):
        """ Returns phi(u), the value of the zero-potential at the points u"""<commit_msg>Fix bug in assignment of 'omega' parameter of ExponentialPotential<commit_after>'''
A collection of omega-potentials for Dual Averaging

@author: <NAME>
@date: May 8, 2015
'''

import numpy as np


class OmegaPotential(object):
    """ Base class for omega potentials """
        
    def phi(self, u):
        """ Returns phi(u), the value of the zero-potential at the points u"""
        return NotImplementedError
        
    def phi_prime(self, u):
        """ Returns phi'(u), the first derivative of the zero-potential at the points u """
        return NotImplementedError
 
    def phi_double_prime(self, u):
        """ Returns phi''(u), the second derivative of the zero-potential at the points u """
        return NotImplementedError
     
    def phi_inv(self, u):
        """ Returns phi^{-1}(u), the inverse function of the zero-potential at the points u """
        return NotImplementedError
    
    def alpha_opt(self, n):
        """ Returns the optimal decay parameter alpha in the learning rate 
            eta_t = theta*t**(-alpha). Here n is the dimension of the space. """
        return 1/(2 + n*self.bounds_asymp()[1])
    
    def theta_opt(self, domain, M):
        """ Computes the optimal constant theta for the learning rate eta_t = theta*t**(-alpha). """
        C, epsilon = self.bounds_asymp()
        lpsi, pdual = self.l_psi()
        n, v = domain.n, domain.v
        return np.sqrt(C*lpsi*(1+n*epsilon)/M**2/v**epsilon/(2+n*epsilon))
     
    def phi_inv_prime(self, u):
        """ Returns phi^{-1}'(u), the first derivative of the inverse 
            function of the zero-potential at the points u """
        return NotImplementedError
    
    
class ExponentialPotential(OmegaPotential):
    """ The exponential potential, which results in Entropy Dual Averaging (HEDGE) """
    
    def __init__(self, omega=0, desc='ExpPot'):
        """ Constructor """
        if omega > 0:
            raise Exception('omega must be non-positive!')
        self.omega = 0
        self.c_omega, self.d_omega = 1+np.log(1-omega), (1-omega)*np.log(1-omega)
        self.desc = desc
        
    def phi(self, u):
        """ Returns phi(u), the value of the zero-potential at the points u"""
{'fraction_non_alphanumeric': 0.11763341067285382, 'fraction_numerical': 0.008352668213457077, 'mean_word_length': 2.5481481481481483, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1848112', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1241, 'n_words': 428}