Package paramz :: Package tests :: Module verbose_optimize_tests
[hide private]
[frames] | no frames]

Source Code for Module paramz.tests.verbose_optimize_tests

 1  #=============================================================================== 
 2  # Copyright (c) 2016, Max Zwiessele 
 3  # All rights reserved. 
 4  #  
 5  # Redistribution and use in source and binary forms, with or without 
 6  # modification, are permitted provided that the following conditions are met: 
 7  #  
 8  # * Redistributions of source code must retain the above copyright notice, this 
 9  #   list of conditions and the following disclaimer. 
10  #  
11  # * Redistributions in binary form must reproduce the above copyright notice, 
12  #   this list of conditions and the following disclaimer in the documentation 
13  #   and/or other materials provided with the distribution. 
14  #  
15  # * Neither the name of paramz.tests.verbose_optimize_tests nor the names of its 
16  #   contributors may be used to endorse or promote products derived from 
17  #   this software without specific prior written permission. 
18  #  
19  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
20  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
21  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
22  # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
23  # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
24  # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
25  # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
26  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
27  # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
28  # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
29  #=============================================================================== 
30   
31  import unittest 
32  from paramz.optimization.verbose_optimization import VerboseOptimization 
33  from paramz.optimization.optimization import opt_bfgs 
34   
35 -class Test(unittest.TestCase):
36 - def setUp(self):
37 class Stub(object): 38 obj_grads = [10,0] 39 def add_observer(self, m, f): 40 self.obs = m 41 self.obs_f = f
42 def objective_function(self): 43 return 10
44 45 self.vo = VerboseOptimization(Stub(), opt_bfgs(), -10, verbose=True) 46
47 - def test_timestrings(self):
48 self.vo.print_out(0) 49 self.assertEqual(self.vo.timestring, '00s00') 50 51 self.vo.print_out(10.2455) 52 self.assertEqual(self.vo.timestring, '10s24') 53 54 self.vo.print_out(120) 55 self.assertEqual(self.vo.timestring, '02m00s00') 56 57 self.vo.print_out(60*60+120+12.2455) 58 self.assertEqual(self.vo.timestring, '01h02m12') 59 60 self.vo.print_out(2*3600*24+60*60+120+12.2455) 61 self.assertEqual(self.vo.timestring, '02d01h02')
62
63 - def test_finish(self):
64 self.assertEqual(self.vo.status, 'running')
65