Code 1using System; 2using System.Collections; 3 4publicclass RANSAC 5{ 6publicinterface IRANSACModel : ICloneable, IComparable 7 { 8// Fit the model to the samples given. The number of samples is equal 9// to or larger than the smallest number of points required for a fit 10// ('n'). 11// Return true if the fit can be done, false otherwise. 12bool FitModel (ArrayList points); 13 14// Return the fitting error of a single point against the current 15// model. 16double FittingErrorSingle (object point); 17 18// Threshhold the given fit error of a point. 19// Return true if the fitting error is small enough and the point is 20// fitting. 21// Return false if the point is not fitting. 22bool ThreshholdPoint (double fitError); 23 24// The overall fitting error of all points in FittingGround. This 25// value is calculated by averaging all individual fitting errors of 26// the points in the FittingGround. 27double FittingErrorSum { 28get; 29set; 30 } 31 32// All the points used to fit. Has to be set explicitly. 33 ArrayList FittingGround { 34get; 35set; 36 } 37 } 38 39// Smallest number of points to be able to fit the model. 40privateint n; 41 42// The number of iterations required. 43privateint k; 44 45private RANSAC () 46 { 47 } 48 49// n: Smallest number of points to be able to fit the model. 50// k: The number of iterations required. 51public RANSAC (int n, int k) 52 { 53this.n = n; 54this.k = k; 55 } 56 57// ArrayList of Model's, sorted by summed fitting error. 58// model: Model to fit 59// points: List of point data to fit 60// d: Number of nearby points required for a model to be accepted 61public ArrayList FindModels (IRANSACModel model, ArrayList points, int d) 62 { 63 Random rand =new Random (); 64 ArrayList result =new ArrayList (); 65 66if (points.Count < n) 67throw (new ArgumentException 68 ("List of data is smaller than minimum fit requires.")); 69 70for (int ki =0 ; ki < k ; ++ki) { 71 ArrayList samples =new ArrayList (); 72 73// Build random samples 74for (int ri =0 ; ri < n ; ++ri) { 75object sampleToAdd; 76 sampleToAdd = points[rand.Next (0, points.Count)]; 77 78if (samples.Contains (sampleToAdd)) 79continue; 80 81 samples.Add (sampleToAdd); 82 } 83 84if (model.FitModel (samples) ==false) 85continue; 86 87 ArrayList good =new ArrayList (); 88double overAllFittingError =0.0; 89 90// Check all non-sample points for fit. 91foreach (object point in points) { 92if (samples.Contains (point)) 93continue; 94 95double fitError = model.FittingErrorSingle (point); 96if (model.ThreshholdPoint (fitError)) { 97 good.Add (point); 98 overAllFittingError += fitError; 99 } 100 } 101 102// good contains a list of all fitting points now. Check if there 103// are more than d points near our model. 104if (good.Count >= d) { 105 good.AddRange (samples); 106 IRANSACModel modelGood = (IRANSACModel) model.Clone (); 107 108 modelGood.FitModel (good); 109 modelGood.FittingErrorSum = overAllFittingError / good.Count; 110 modelGood.FittingGround = good; 111 112 result.Add (modelGood); 113 } 114 } 115 result.Sort (); 116//Console.WriteLine ("got {0} modelfits", result.Count); 117 118return (result); 119 } 120 121// Calculate the expected number of draws required when a fraction of 122// 'goodFraction' of the sample points is good and at least 'n' points are 123// required to fit the model. Add 'sdM' times the standard deviation to be 124// sure. 125// n: > 0 126// goodFraction: > 0.0 and <= 1.0 127// sdM: >= 0 128// return the guess for k, the expected number of draws. 129publicstaticint GetKFromGoodfraction (int n, double goodFraction, int sdM) 130 { 131double result; 132 133 result = Math.Pow (goodFraction, -n); 134if (sdM >0) 135 result += sdM * Math.Sqrt (1.0- Math.Pow (goodFraction, n)); 136 137return ((int) (result +0.5)); 138 } 139 140// Test Main 141publicstaticvoid Main (string[] args) 142 { 143 Console.WriteLine ("n = 3, goodFraction = 0.3, sdM = 0: {0}", 144 GetKFromGoodfraction (3, 0.3, 0)); 145 Console.WriteLine ("n = 3, goodFraction = 0.3, sdM = 10: {0}", 146 GetKFromGoodfraction (3, 0.3, 10)); 147 } 148} 149 150
不考虑Model部分,只考虑单次迭代过程中的随机抽样,可抽象出这样一个过程:
我把libsift的Ransac代码中上述逻辑部分单独提取出来了,并作了以下简化:
代码如下:
Code 1publicclass CaseLibSift 2 { 3 Random rand =new Random (); 4 5public List<int> RandomSample(List<int> points, int n) 6 { 7 List<int> samples =new List<int>(); 8 9// Build random samples 10for (int ri =0; ri < n; ++ri) 11 { 12int sampleToAdd; 13 sampleToAdd = points[rand.Next(0, points.Count)]; 14 15if (samples.Contains(sampleToAdd)) 16continue; 17 18 samples.Add(sampleToAdd); 19 } 20 21// Check all non-sample points for fit. 22foreach (int point in points) 23 { 24if (samples.Contains(point)) 25continue; 26else 27 samples.Add(point); 28 } 29return samples; 30 } 31 }
当某个数据库用户在数据库中插入、更新、删除一个表的数据,或者增加一个表的主键时或者表的索引时,常常会出现ora-00054:resource busy and acquire with nowait specified这样的错误。主要是因为有事务正在执行(或者事务已经被锁),所有导致执行不成功。
1.下面的语句
insert提示IGNORE_ROW_ON_DUPKEY_INDEX
转自:http://space.itpub.net/18922393/viewspace-752123
在 insert into tablea ...select * from tableb中,如果存在唯一约束,会导致整个insert操作失败。使用IGNORE_ROW_ON_DUPKEY_INDEX提示,会忽略唯一
1.记录慢查询配置
show variables where variable_name like 'slow%' ; --查看默认日志路径
查询结果:--不用的机器可能不同
slow_query_log_file=/var/lib/mysql/centos-slow.log
修改mysqld配置文件:/usr /my.cnf[一般在/etc/my.cnf,本机在/user/my.cn
@ControllerAdvice,是spring3.2提供的新注解,从名字上可以看出大体意思是控制器增强。让我们先看看@ControllerAdvice的实现:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Co
BW Element
OLAP Universe Element
Cube Dimension
Class
Charateristic
A class with dimension and detail objects (Detail objects for key and desription)
Hi