<commit_before>'''
Created on Feb 13, 2014

@author: maxzwiessele
'''
import unittest
import GPy
import numpy as np
from GPy.core.parameterization.parameter_core import HierarchyError
from GPy.core.parameterization.array_core import ObservableArray

class ArrayCoreTest(unittest.TestCase):
    def setUp(self):
        self.X = np.random.normal(1,1, size=(100,10))
        self.obsX = ObservableArray(self.X)

    def test_init(self):
        X = ObservableArray(self.X)
        X2 = ObservableArray(X)
        self.assertIs(X, X2, "no new Observable array, when Observable is given")

    def test_slice(self):
        t1 = self.X[2:78]
        t2 = self.obsX[2:78]
        self.assertListEqual(t1.tolist(), t2.tolist(), "Slicing should be the exact same, as in ndarray")

class ParameterizedTest(unittest.TestCase):

    def setUp(self):
        self.rbf = GPy.kern.RBF(1)
        self.white = GPy.kern.White(1)
        from GPy.core.parameterization import Param
        from GPy.core.parameterization.transformations import Logistic
        self.param = Param('param', np.random.rand(25,2), Logistic(0, 1))

        self.test1 = GPy.core.Parameterized("test model")
        self.test1.add_parameter(self.white)
        self.test1.add_parameter(self.rbf, 0)
        self.test1.add_parameter(self.param)

        x = np.linspace(-2,6,4)[:,None]
        y = np.sin(x)
        self.testmodel = GPy.models.GPRegression(x,y)

    def test_add_parameter(self):
        self.assertEquals(self.rbf._parent_index_, 0)
        self.assertEquals(self.white._parent_index_, 1)
        pass

    def test_fixes(self):
        self.white.fix(warning=False)
        self.test1.remove_parameter(self.test1.param)
        self.assertTrue(self.test1._has_fixes())
        import ipdb;ipdb.set_trace()
        
        from GPy.core.parameterization.transformations import FIXED, UNFIXED
        self.assertListEqual(self.test1._fixes_.tolist(),[UNFIXED,UNFIXED,FIXED])

        self.test1.add_parameter(self.white, 0)
        self.assertListEqual(self.test1._fixes_.tolist(),[FIXED,UNFIXED,UNFIXED])

    def test_remove_parameter(self):
        from GPy.core.parameterization.transformations import FIXED, UNFIXED, __fixed__, Logexp
        self.white.fix()
        self.test1.remove_parameter(self.white)
        self.assertIs(self.test1._fixes_,None)

        self.assertListEqual(self.white._fixes_.tolist(), [FIXED])
        self.assertEquals(self.white.constraints._offset, 0)
        self.assertIs(self.test1.constraints, self.rbf.constraints._param_index_ops)
        self.assertIs(self.test1.constraints, self.param.constraints._param_index_ops)

        self.test1.add_parameter(self.white, 0)
        self.assertIs(self.test1.constraints, self.white.constraints._param_index_ops)
        self.assertIs(self.test1.constraints, self.rbf.constraints._param_index_ops)
        self.assertIs(self.test1.constraints, self.param.constraints._param_index_ops)
        self.assertListEqual(self.test1.constraints[__fixed__].tolist(), [0])
        self.assertIs(self.white._fixes_,None)
        self.assertListEqual(self.test1._fixes_.tolist(),[FIXED] + [UNFIXED] * 52)

        self.test1.remove_parameter(self.white)
        self.assertIs(self.test1._fixes_,None)<commit_msg>fixes fixed and test updates<commit_after>'''
Created on Feb 13, 2014

@author: maxzwiessele
'''
import unittest
import GPy
import numpy as np
from GPy.core.parameterization.parameter_core import HierarchyError
from GPy.core.parameterization.array_core import ObservableArray

class ArrayCoreTest(unittest.TestCase):
    def setUp(self):
        self.X = np.random.normal(1,1, size=(100,10))
        self.obsX = ObservableArray(self.X)

    def test_init(self):
        X = ObservableArray(self.X)
        X2 = ObservableArray(X)
        self.assertIs(X, X2, "no new Observable array, when Observable is given")

    def test_slice(self):
        t1 = self.X[2:78]
        t2 = self.obsX[2:78]
        self.assertListEqual(t1.tolist(), t2.tolist(), "Slicing should be the exact same, as in ndarray")

class ParameterizedTest(unittest.TestCase):

    def setUp(self):
        self.rbf = GPy.kern.RBF(1)
        self.white = GPy.kern.White(1)
        from GPy.core.parameterization import Param
        from GPy.core.parameterization.transformations import Logistic
        self.param = Param('param', np.random.rand(25,2), Logistic(0, 1))

        self.test1 = GPy.core.Parameterized("test model")
        self.test1.add_parameter(self.white)
        self.test1.add_parameter(self.rbf, 0)
        self.test1.add_parameter(self.param)

        x = np.linspace(-2,6,4)[:,None]
        y = np.sin(x)
        self.testmodel = GPy.models.GPRegression(x,y)

    def test_add_parameter(self):
        self.assertEquals(self.rbf._parent_index_, 0)
        self.assertEquals(self.white._parent_index_, 1)
        pass

    def test_fixes(self):
        self.white.fix(warning=False)
        self.test1.remove_parameter(self.test1.param)
        self.assertTrue(self.test1._has_fixes())
        from GPy.core.parameterization.transformations import FIXED, UNFIXED
        self.assertListEqual(self.test1._fixes_.tolist(),[UNFIXED,UNFIXED,FIXED])

        self.test1.add_parameter(self.white, 0)
        self.assertListEqual(self.test1._fixes_.tolist(),[FIXED,UNFIXED,UNFIXED])

    def test_remove_parameter(self):
        from GPy.core.parameterization.transformations import FIXED, UNFIXED, __fixed__, Logexp
        self.white.fix()
        self.test1.remove_parameter(self.white)
        self.assertIs(self.test1._fixes_,None)

        self.assertListEqual(self.white._fixes_.tolist(), [FIXED])
        self.assertEquals(self.white.constraints._offset, 0)
        self.assertIs(self.test1.constraints, self.rbf.constraints._param_index_ops)
        self.assertIs(self.test1.constraints, self.param.constraints._param_index_ops)

        self.test1.add_parameter(self.white, 0)
        self.assertIs(self.test1.constraints, self.white.constraints._param_index_ops)
        self.assertIs(self.test1.constraints, self.rbf.constraints._param_index_ops)
        self.assertIs(self.test1.constraints, self.param.constraints._param_index_ops)
        self.assertListEqual(self.test1.constraints[__fixed__].tolist(), [0])
        self.assertIs(self.white._fixes_,None)
        self.assertListEqual(self.test1._fixes_.tolist(),[FIXED] + [UNFIXED] * 52)

        self.test1.remove_parameter(self.white)
        self.assertIs(self.test1._fixes_,None)
{'fraction_non_alphanumeric': 0.11855273287143957, 'fraction_numerical': 0.020323325635103928, 'mean_word_length': 3.3105507631055078, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '107577', 'n_tokens_mistral': 2203, 'n_tokens_neox': 2147, 'n_words': 319}