示例#1
0
 def test_bootstrap(self):
     c_bootstrap = CMeanSD_BOOTSTRAP(dimension=8)
     two_bootstrap = CMeanSD_BOOTSTRAP(with_openMP=True, dimension=8)
     two_bootstrap.omp_n_threads = 2
     four_bootstrap = CMeanSD_BOOTSTRAP(with_openMP=True, dimension=8)
     four_bootstrap.omp_n_threads = 4
     res_serial = c_bootstrap.run(self.data)
     res_two = two_bootstrap.run(self.data)
     res_four = four_bootstrap.run(self.data)
     actual = self.std
     p = percent_error(res_serial, actual)
     self.assertTrue((p <= self.threshold).all(),
                     msg=FAIL_MSG % ('serial', actual, res_serial, p))
     p = percent_error(res_two, actual)
     self.assertTrue((p <= self.threshold).all(),
                     msg=FAIL_MSG % ('two threads', actual, res_two, p))
     p = percent_error(res_four, actual)
     self.assertTrue((p <= self.threshold).all(),
                     msg=FAIL_MSG % ('four threads', actual, res_four, p))
示例#2
0
 def test_blb(self):
     c_blb = CMeanSD_BLB(dimension=8)
     two_blb = CMeanSD_BLB(with_openMP=True, dimension=8)
     two_blb.omp_n_threads = 2
     four_blb = CMeanSD_BLB(with_openMP=True, dimension=8)
     four_blb.omp_n_threads = 4
     res_serial = c_blb.run(self.data)
     res_two = two_blb.run(self.data)
     res_four = four_blb.run(self.data)
     actual = norm(self.std)
     p = percent_error(res_serial, actual)
     self.assertTrue(p <= self.threshold,
                     msg=FAIL_MSG % ('serial', actual, res_serial, p))
     p = percent_error(res_two, actual)
     self.assertTrue(p <= self.threshold,
                     msg=FAIL_MSG % ('two threads', actual, res_two, p))
     p = percent_error(res_four, actual)
     self.assertTrue(p <= self.threshold,
                     msg=FAIL_MSG % ('four threads', actual, res_four, p))
示例#3
0
        numpy.put(results, i * offset, y)
        numpy.put(results, xrange(i * offset + 1, (i + 1) * offset), x)
    return results, mapping


class LinRegBLB(blb.BLB):
    def compute_estimate(self, sample):
        linreg()

    def reduce_bootstraps(self, sample):
        mean()

    def average(self, sample):
        mean()


if __name__ == '__main__':
    data, mapping = create_gaussian_data(3000, 50)
    print 'mapping is, ', mapping
    cblb = LinRegBLB(dimension=51, num_subsamples=30)
    estimated_mapping = cblb.run(data)
    assert len(mapping) == len(
        estimated_mapping), "Mapping dimension are inequal!"
    for i in xrange(len(mapping)):
        print 'checking covariate ', i
        p = percent_error(mapping[i], estimated_mapping[i])
        if p > 0.05:
            print 'Error: covariate %d is %f, estimated as %f, percent error %f' % (
                i, mapping[i], estimated_mapping[i], p)
    print estimated_mapping
    print 'done'
示例#4
0
	#y = (numpy.random.rand() * y_eps) + reduce( float.__add__, map( float.__mul__, x, mapping ) )
	y = reduce( float.__add__, x*mapping )
	numpy.put( results, i*offset, y )
	numpy.put( results, xrange( i*offset+1, (i+1)*offset) , x )
    return results, mapping

class LinRegBLB( blb.BLB ):
    def compute_estimate( self, sample ):
	linreg()

    def reduce_bootstraps( self, sample ):
	mean()
	
    def average( self, sample ):
	mean()



if __name__ == '__main__':
    data, mapping = create_gaussian_data( 3000, 50 )
    print 'mapping is, ', mapping
    cblb = LinRegBLB(dimension=51, num_subsamples=30)
    estimated_mapping = cblb.run( data )
    assert len(mapping) == len(estimated_mapping), "Mapping dimension are inequal!" 
    for i in xrange( len( mapping ) ):
	print 'checking covariate ', i
	p = percent_error( mapping[i], estimated_mapping[i] )
	if p > 0.05:
	    print 'Error: covariate %d is %f, estimated as %f, percent error %f' % (i, mapping[i], estimated_mapping[i], p )
    print estimated_mapping
    print 'done'