00001 /********************************************************************** 00002 * File: lmedsq.h (Formerly lms.h) 00003 * Description: Code for the LMS class. 00004 * Author: Ray Smith 00005 * Created: Fri Aug 7 09:30:53 BST 1992 00006 * 00007 * (C) Copyright 1992, Hewlett-Packard Ltd. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 * 00018 **********************************************************************/ 00019 00020 #ifndef LMEDSQ_H 00021 #define LMEDSQ_H 00022 00023 #include "points.h" 00024 #include "varable.h" 00025 #include "scrollview.h" 00026 #include "notdll.h" 00027 00028 class LMS 00029 { 00030 public: 00031 LMS( //constructor 00032 inT32 size); //no of samples 00033 ~LMS (); //destructor 00034 void clear(); //clear samples 00035 void add( //add sample 00036 FCOORD sample); //sample coords 00037 void fit( //generate fit 00038 float &m, //output line 00039 float &c); 00040 void constrained_fit( //fixed gradient 00041 float fixed_m, //forced gradient 00042 float &out_c); //output line 00043 void fit_quadratic( //easy quadratic 00044 float outlier_threshold, //min outlier 00045 double &a, //x squared 00046 float &b, //x 00047 float &c); //constant 00048 void plot( //plot fit 00049 ScrollView* win, //window 00050 ScrollView::Color colour); //colour to draw in 00051 float error() { //get error 00052 return fitted ? line_error : -1; 00053 } 00054 00055 private: 00056 00057 void pick_line( //random choice 00058 float &m, //output line 00059 float &c); 00060 void pick_quadratic( //random choice 00061 double &a, //output curve 00062 float &b, 00063 float &c); 00064 void compute_errors( //find errors 00065 float m, //from line 00066 float c); 00067 //find errors 00068 float compute_quadratic_errors(float outlier_threshold, //min outlier 00069 double a, //from curve 00070 float m, 00071 float c); 00072 00073 BOOL8 fitted; //line parts valid 00074 inT32 samplesize; //max samples 00075 inT32 samplecount; //current sample size 00076 FCOORD *samples; //array of samples 00077 float *errors; //error distances 00078 double a; //x squared 00079 float m; //line gradient 00080 float c; 00081 float line_error; //error of fit 00082 }; 00083 extern INT_VAR_H (lms_line_trials, 12, "Number of linew fits to do"); 00084 #endif
1.6.3