コード例 #1
0
def test_brute_force_search_manual_grids():

    # create a parameter to estimate
    params = (10, 10)

    # we need to define some search bounds
    grid_1 = utils.grid_slice(5, 15, 5)
    grid_2 = utils.grid_slice(5, 15, 5)
    grids = (
        grid_1,
        grid_2,
    )
    bounds = ()

    # set the verbose level 0 is silent, 1 is final estimate, 2 is each iteration
    verbose = 0

    # create a simple function to transform the parameters
    func = lambda freq, offset: np.sin(
        np.linspace(0, 1, 1000) * 2 * np.pi * freq) + offset

    # create a "response"
    response = func(*params)

    # get the ball-park estimate
    p0 = utils.brute_force_search(response, utils.error_function, func, grids,
                                  bounds)

    # assert that the estimate is equal to the parameter
    npt.assert_equal(params, p0[0])
コード例 #2
0
def test_brute_force_search():

    # create a parameter to estimate
    params = (10, 10)

    # we need to define some search bounds
    grids = ((0, 20), (5, 15))

    # we don't need to specify bounds for the error function
    bounds = ()

    # set the number of grid samples for the coarse search
    Ns = 3

    # set the verbose level 0 is silent, 1 is final estimate, 2 is each iteration
    verbose = 0

    # create a simple function to transform the parameters
    func = lambda freq, offset: np.sin(
        np.linspace(0, 1, 1000) * 2 * np.pi * freq) + offset

    # create a "response"
    response = func(*params)

    # get the ball-park estimate
    p0 = utils.brute_force_search(response,
                                  utils.error_function,
                                  func,
                                  grids,
                                  bounds,
                                  Ns=Ns)

    # assert that the estimate is equal to the parameter
    npt.assert_equal(params, p0[0])
コード例 #3
0
ファイル: test_utilities.py プロジェクト: arokem/popeye
def test_brute_force_search():

    # create a parameter to estimate
    params = (10,10)

    # we need to define some search bounds
    grids = ((0,20),(5,15))

    # we don't need to specify bounds for the error function
    bounds = ()

    # set the number of grid samples for the coarse search
    Ns = 3

    # set the verbose level 0 is silent, 1 is final estimate, 2 is each iteration
    verbose = 0

    # create a simple function to transform the parameters
    func = lambda freq, offset: np.sin( np.linspace(0,1,1000) * 2 * np.pi * freq) + offset

    # create a "response"
    response = func(*params)

    # get the ball-park estimate
    p0 = utils.brute_force_search(response, utils.error_function, func, grids, bounds, Ns=Ns)

    # assert that the estimate is equal to the parameter
    npt.assert_equal(params, p0[0])
コード例 #4
0
ファイル: test_utilities.py プロジェクト: arokem/popeye
def test_brute_force_search_manual_grids():

    # create a parameter to estimate
    params = (10,10)

    # we need to define some search bounds
    grid_1 = utils.grid_slice(5,15,5)
    grid_2 = utils.grid_slice(5,15,5)
    grids = (grid_1,grid_2,)
    bounds = ()

    # set the verbose level 0 is silent, 1 is final estimate, 2 is each iteration
    verbose = 0

    # create a simple function to transform the parameters
    func = lambda freq, offset: np.sin( np.linspace(0,1,1000) * 2 * np.pi * freq) + offset

    # create a "response"
    response = func(*params)

    # get the ball-park estimate
    p0 = utils.brute_force_search(response, utils.error_function, func, grids, bounds)

    # assert that the estimate is equal to the parameter
    npt.assert_equal(params, p0[0])
コード例 #5
0
ファイル: base.py プロジェクト: arokem/popeye
 def brute_force(self):
     return utils.brute_force_search(self.data,
                                     utils.error_function,
                                     self.model.generate_ballpark_prediction,
                                     self.grids,
                                     self.bounds,
                                     self.Ns,
                                     self.very_verbose)
コード例 #6
0
ファイル: og.py プロジェクト: mekman/popeye
 def ballpark_estimate(self):
     return utils.brute_force_search((self.model.stimulus.deg_x_coarse,
                                      self.model.stimulus.deg_y_coarse,
                                      self.model.stimulus.stim_arr_coarse,
                                      self.tr_length),
                                     self.search_bounds,
                                     self.fit_bounds,
                                     self.data,
                                     utils.error_function,
                                     compute_model_ts)
コード例 #7
0
ファイル: spectrotemporal.py プロジェクト: arokem/popeye
 def ballpark(self):
     return utils.brute_force_search((self.model.stimulus.spectrogram,
                                      self.model.stimulus.freqs,
                                      self.model.stimulus.target_times),
                                     self.grids,
                                     self.bounds,
                                     self.Ns,
                                     self.data,
                                     utils.error_function,
                                     compute_model_ts,
                                     self.very_verbose)
コード例 #8
0
def test_grid_slice():

    # test this case
    from_1 = 5
    to_1 = 15
    from_2 = 0
    to_2 = 2
    Ns = 5

    # set a parameter to estimate
    params = (10, 1)

    # see if we properly tile the parameter space for Ns=2
    grid_1 = utils.grid_slice(from_1, to_1, Ns)
    grid_2 = utils.grid_slice(from_2, to_2, Ns)
    grids = (grid_1, grid_2)

    # unbounded
    bounds = ()

    # create a simple function to generate a response from the parameter
    func = lambda freq, offset: np.sin(
        np.linspace(0, 1, 1000) * 2 * np.pi * freq) + offset

    # create a "response"
    response = func(*params)

    # get the ball-park estimate
    p0 = utils.brute_force_search(response, utils.error_function, func, grids,
                                  bounds)

    # make sure we fit right
    npt.assert_equal(params, p0[0])

    # make sure we sliced it right
    npt.assert_equal(p0[2][0].min(), from_1)
    npt.assert_equal(p0[2][0].max(), to_1)
    npt.assert_equal(p0[2][1].min(), from_2)
    npt.assert_equal(p0[2][1].max(), to_2)
コード例 #9
0
ファイル: test_utilities.py プロジェクト: arokem/popeye
def test_grid_slice():
    
    # test this case
    from_1 = 5
    to_1 = 15
    from_2 = 0
    to_2 = 2
    Ns=5
    
    # set a parameter to estimate
    params = (10,1)
    
    # see if we properly tile the parameter space for Ns=2
    grid_1 = utils.grid_slice(from_1, to_1, Ns)
    grid_2 = utils.grid_slice(from_2, to_2, Ns)
    grids = (grid_1, grid_2)
    
    # unbounded
    bounds = ()
    
    # create a simple function to generate a response from the parameter
    func = lambda freq,offset: np.sin( np.linspace(0,1,1000) * 2 * np.pi * freq) + offset
    
    # create a "response"
    response = func(*params)
    
    # get the ball-park estimate
    p0 = utils.brute_force_search(response, utils.error_function, func, grids, bounds)
    
    # make sure we fit right
    npt.assert_equal(params, p0[0])
    
    # make sure we sliced it right
    npt.assert_equal(p0[2][0].min(),from_1)
    npt.assert_equal(p0[2][0].max(),to_1)
    npt.assert_equal(p0[2][1].min(),from_2)
    npt.assert_equal(p0[2][1].max(),to_2)
コード例 #10
0
ファイル: spectrotemporal.py プロジェクト: noahbenson/popeye
 def ballpark(self):
     return utils.brute_force_search(
         (self.model.stimulus.spectrogram, self.model.stimulus.freqs,
          self.model.stimulus.target_times), self.grids, self.bounds,
         self.Ns, self.data, utils.error_function, compute_model_ts,
         self.very_verbose)
コード例 #11
0
 def brute_force(self):
     return utils.brute_force_search(
         self.data, utils.error_function,
         self.model.generate_ballpark_prediction, self.grids, self.bounds,
         self.Ns, self.very_verbose)