Changeset 2666
- Timestamp:
- Apr 6, 2006, 11:07:20 AM (19 years ago)
- Location:
- inundation/pyvolution
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/least_squares.py
r2665 r2666 38 38 39 39 40 41 acceptable_fit_overshoot = 1.001 #Must be larger than 142 40 43 41 DEFAULT_ALPHA = 0.001 … … 159 157 alpha = DEFAULT_ALPHA, 160 158 verbose = False, 159 acceptable_overshoot = 1, 161 160 expand_search = False, 162 161 data_origin = None, … … 181 180 182 181 alpha: Smoothing parameter. 182 183 acceptable overshoot: controls the allowed factor by which fitted values 184 may exceed the value of input data. The lower limit is defined 185 as min(z) - acceptable_overshoot*delta z and upper limit 186 as max(z) + acceptable_overshoot*delta z 187 183 188 184 189 point_attributes: Vector or array of data at the point_coordinates. … … 252 257 zeta = Zeta[:,i] 253 258 z = Z[:,i] 254 zc = Zc[:,i] 259 zc = Zc[:,i] 260 261 max_zc = max(zc) 262 min_zc = min(zc) 263 delta_zc = max_zc-min_zc 264 upper_limit = max_zc + delta_zc*acceptable_overshoot 265 lower_limit = min_zc - delta_zc*acceptable_overshoot 255 266 256 if max(zeta) > max(zc)*acceptable_fit_overshoot or\ 257 min(zeta) < min(zc)/acceptable_fit_overshoot:258 msg = 'Least sqares produced values outside the range of the input'259 msg += ' data by a factor greater than %.2f. ' %acceptable_fit_overshoot260 msg += 'z in [%f, %f], zeta in [%f, %f].\n' %(min (zc), max(zc),267 268 if max(zeta) > upper_limit or min(zeta) < lower_limit: 269 msg = 'Least sqares produced values outside the allowed ' 270 msg += 'range [%f, %f].\n' %(lower_limit, upper_limit) 271 msg += 'z in [%f, %f], zeta in [%f, %f].\n' %(min_zc, max_zc, 261 272 min(zeta), max(zeta)) 262 263 offending_vertices = (zeta > max(zc)*acceptable_fit_overshoot) or\ 264 (zeta < min(zc)/acceptable_fit_overshoot) 265 273 msg += 'If greater range is needed, increase the value of ' 274 msg += 'acceptable_fit_overshoot (currently %f).\n' %(acceptable_overshoot) 275 276 277 offending_vertices = (zeta > upper_limit or zeta < lower_limit) 266 278 Xi_c = compress(offending_vertices, Xi) 267 279 Eta_c = compress(offending_vertices, Eta) -
inundation/pyvolution/test_least_squares.py
r2665 r2666 1856 1856 #Fit surface to mesh 1857 1857 z = linear_function(data_points1) #Example z-values 1858 v = fit_to_mesh(points, triangles, data_points1, z, alpha=0.0, 1859 precrop=True, verbose=False) 1858 v = fit_to_mesh(points, triangles, data_points1, z, alpha=0.0, 1859 precrop=True, verbose=False) 1860 1860 1861 assert allclose(linear_function(points), v) 1862 1863 1864 1865 def test_acceptable_overshoot(self): 1866 """Fit a surface to one set of points. Then interpolate that surface 1867 using another set of points. 1868 Check that exceedance in fitted values are caught. 1869 """ 1870 from mesh import Mesh 1871 1872 1873 #Setup mesh used to represent fitted function 1874 a = [0.0, 0.0] 1875 b = [0.0, 2.0] 1876 c = [2.0, 0.0] 1877 d = [0.0, 4.0] 1878 e = [2.0, 2.0] 1879 f = [4.0, 0.0] 1880 1881 points = [a, b, c, d, e, f] 1882 #bac, bce, ecf, dbe, daf, dae 1883 triangles = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] 1884 1885 #Datapoints to fit from 1886 data_points1 = [[ 0.66666667, 0.66666667], 1887 [ 1.33333333, 1.33333333], 1888 [ 2.66666667, 0.66666667], 1889 [ 0.66666667, 2.66666667], 1890 [ 0.0, 1.0], 1891 [ 0.0, 3.0], 1892 [ 1.0, 0.0], 1893 [ 1.0, 1.0], 1894 [ 15, -17], #Outside mesh 1895 [ 1.0, 2.0], 1896 [ 1.0, 3.0], 1897 [ 2.0, 1.0], 1898 [ 3.0, 0.0], 1899 [ 3.0, 1.0]] 1900 1901 #Fit surface to mesh 1902 z = linear_function(data_points1) #Example z-values 1903 1904 try: 1905 v = fit_to_mesh(points, triangles, data_points1, z, alpha=0.0, 1906 acceptable_overshoot = 0.2, 1907 precrop=True, verbose=False) 1908 except FittingError, e: 1909 pass 1910 else: 1911 raise 'Should have raised exception' 1912 1913 1914 #assert allclose(linear_function(points), v) 1915 1861 1916 1862 1917 … … 1864 1919 if __name__ == "__main__": 1865 1920 #suite = unittest.makeSuite(Test_Least_Squares,'test_smooth_attributes_to_mesh_function') 1866 suite = unittest.makeSuite(Test_Least_Squares,'test _fit_using_fit_to_mesh')1921 suite = unittest.makeSuite(Test_Least_Squares,'test') 1867 1922 1868 1923 #suite = unittest.makeSuite(Test_Least_Squares,'test_fit_to_msh_netcdf_fileII')
Note: See TracChangeset
for help on using the changeset viewer.