private void InitializeInterface() { string activityName = (string)SimilarActivitiesForm.ConfusingActivities[this.activityIndex]; this.label1.Text = "During " + activityName + ", how mobile are the following areas of your body?"; this.sensorLabels = new ArrayList(); this.sensorButtons = new ArrayList(); //Initialize Mobility Matrix MobilityForm.mobilityMatrix= new int[SimilarActivitiesForm.ConfusingActivities.Count][]; // this.mobilityIndex = new int[SimilarActivitiesForm.ConfusingActivities.Count][]; SXML.Reader sreader = new SXML.Reader(Constants.MASTER_DIRECTORY, TroubleshootModel.SelectedFolder); if (sreader.validate() == false) { throw new Exception("Error Code 0: XML format error - sensors.xml does not match sensors.xsd!"); } else { this.sensors = sreader.parse(Constants.MAX_CONTROLLERS); } for (int i = 0; (i < MobilityForm.mobilityMatrix.Length); i++) { MobilityForm.mobilityMatrix[i] = new int[this.sensors.Sensors.Count]; //this.mobilityIndex[i] = new int[this.sensors.Sensors.Count]; for (int j = 0; (j < this.sensors.Sensors.Count); j++) { MobilityForm.mobilityMatrix[i][j] = 0; //this.mobilityIndex[i][j] = 0; } } int index = 0; foreach (SXML.Sensor sensor in this.sensors.Sensors) { System.Windows.Forms.Label label = new System.Windows.Forms.Label(); label.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold); label.Location = new System.Drawing.Point(16, 97+ (30 * index)); label.Name = Convert.ToString(index); label.Size = new System.Drawing.Size(56, 19); label.Text = sensor.Location; this.Controls.Add(label); this.sensorLabels.Add(label); System.Windows.Forms.Button button = new System.Windows.Forms.Button(); button.Location = new System.Drawing.Point(78, 87 + (30 * index)); button.Name = Convert.ToString(index); button.Size = new System.Drawing.Size(120, 30); button.TabIndex = index; button.Text = Constants.MOBILITY_FORM_NOT_MOBILE_LABEL; button.Click += new System.EventHandler(this.button_Click); this.Controls.Add(button); this.sensorButtons.Add(button); index++; } this.button2.Location = new System.Drawing.Point(78, 87 + (30 * index)); this.button3.Location = new System.Drawing.Point(16, 87 + (30 * index)); }
public static void toARFF(string aDataDirectory, string masterDirectory, int maxControllers, string sourceFile, int annotators,string[] filter) { int featureVectorIndex = 0; MITesDecoder aMITesDecoder = new MITesDecoder(); MITesLoggerReader aMITesLoggerReader = new MITesLoggerReader(aMITesDecoder, aDataDirectory); SXML.SensorAnnotation sannotation = null; MITesFeatures.core.conf.GeneralConfiguration configuration = null; AXML.Annotation[] aannotation = new AXML.Annotation[annotators]; AXML.Reader[] readers=new AXML.Reader[annotators]; AXML.Annotation intersection = null; AXML.Annotation[] difference = new AXML.Annotation[annotators]; AXML.Annotation realtimeAnnotation = new AXML.Reader(masterDirectory, aDataDirectory).parse(); realtimeAnnotation.RemoveData(filter); for (int i = 0; (i < annotators); i++) { readers[i] = new AXML.Reader(masterDirectory, aDataDirectory, sourceFile + i + ".xml"); aannotation[i] = readers[i].parse(); aannotation[i].RemoveData(filter); aannotation[i].DataDirectory = aDataDirectory; if (intersection == null) intersection = aannotation[i]; else intersection = intersection.Intersect(aannotation[i]); } for (int i = 0; (i < annotators); i++) difference[i] = aannotation[i].Difference(intersection); SXML.Reader sreader = new SXML.Reader(masterDirectory, aDataDirectory); sannotation = sreader.parse(maxControllers); MITesFeatures.core.conf.ConfigurationReader creader = new MITesFeatures.core.conf.ConfigurationReader(aDataDirectory); configuration = creader.parse(); Extractor.Initialize(aMITesDecoder, aDataDirectory, aannotation[0], sannotation,configuration); TextWriter tw = new StreamWriter(aDataDirectory + "\\output-"+sourceFile+".arff"); tw.WriteLine("@RELATION wockets"); tw.WriteLine(Extractor.GetArffHeader()); tw.WriteLine("@ATTRIBUTE INDEX NUMERIC"); tw.WriteLine("@ATTRIBUTE ANNOTATORS_AGREE NUMERIC"); Hashtable recorded_activities = new Hashtable(); for (int k = 0; (k < annotators); k++) { //tw.Write("@ATTRIBUTE annotator"+k+" {unknown"); //tw.Write("@ATTRIBUTE annotator" + k + " {"); for (int i = 0; (i < aannotation[k].Data.Count); i++) { AXML.AnnotatedRecord record = ((AXML.AnnotatedRecord)aannotation[k].Data[i]); string activity = ""; for (int j = 0; (j < record.Labels.Count); j++) { if (j == record.Labels.Count - 1) activity += ((AXML.Label)record.Labels[j]).Name; else activity += ((AXML.Label)record.Labels[j]).Name + "_"; } activity = activity.Replace("none", "").Replace('-', '_').Replace(':', '_').Replace('%', '_').Replace('/', '_'); activity = Regex.Replace(activity, "[_]+", "_"); activity = Regex.Replace(activity, "^[_]+", ""); activity = Regex.Replace(activity, "[_]+$", ""); //only output activity labels that have not been seen if (recorded_activities.Contains(activity) == false) { //tw.Write("," + activity); recorded_activities[activity] = activity; } } } for (int k = 0; (k < annotators); k++) { tw.Write("@ATTRIBUTE annotator" + k + " {unknown,flapping,rocking,flaprock}\n"); //foreach ( DictionaryEntry de in recorded_activities ) // tw.Write("," + (string) de.Key); //tw.WriteLine("}"); } tw.Write("@ATTRIBUTE realtime {unknown,flapping,rocking,flaprock}\n"); //foreach (DictionaryEntry de in recorded_activities) // tw.Write("," + (string)de.Key); //tw.WriteLine("}"); tw.WriteLine("@DATA"); bool isData = aMITesLoggerReader.GetSensorData(10); int channel = 0, x = 0, y = 0, z = 0; double unixtimestamp = 0.0; int[] differenceIndex = new int[annotators]; AXML.AnnotatedRecord[] annotatedRecord = new AXML.AnnotatedRecord[annotators]; int intersectionIndex = 0; string intersection_activity = "unknown"; AXML.AnnotatedRecord intersectionRecord = ((AXML.AnnotatedRecord)intersection.Data[intersectionIndex]); string[] current_activity = new string[annotators]; string realtime_activity = "unknown"; int realtimeIndex = 0; AXML.AnnotatedRecord realtimeRecord = ((AXML.AnnotatedRecord)realtimeAnnotation.Data[realtimeIndex]); for (int i = 0; (i < annotators); i++) { differenceIndex[i] = 0; annotatedRecord[i] = ((AXML.AnnotatedRecord)difference[i].Data[differenceIndex[i]]); current_activity[i] = "unknown"; } do { //decode the frame channel = aMITesDecoder.GetSomeMITesData()[0].channel; x = aMITesDecoder.GetSomeMITesData()[0].x; y = aMITesDecoder.GetSomeMITesData()[0].y; z = aMITesDecoder.GetSomeMITesData()[0].z; unixtimestamp = aMITesDecoder.GetSomeMITesData()[0].unixTimeStamp; double lastTimeStamp = Extractor.StoreMITesWindow(); for (int i = 0; (i < annotators); i++) { if (unixtimestamp > annotatedRecord[i].EndUnix) { current_activity[i] = "unknown"; if (differenceIndex[i] < difference[i].Data.Count - 1) { differenceIndex[i] = differenceIndex[i]+1; annotatedRecord[i] = ((AXML.AnnotatedRecord)difference[i].Data[differenceIndex[i]]); } } } if (unixtimestamp > realtimeRecord.EndUnix) { realtime_activity = "unknown"; realtimeIndex++; if (realtimeIndex < realtimeAnnotation.Data.Count) realtimeRecord = ((AXML.AnnotatedRecord)realtimeAnnotation.Data[realtimeIndex]); } if (unixtimestamp > intersectionRecord.EndUnix) { intersection_activity = "unknown"; if (intersectionIndex < intersection.Data.Count - 1) { intersectionIndex = intersectionIndex + 1; intersectionRecord = ((AXML.AnnotatedRecord)intersection.Data[intersectionIndex]); } } for (int i = 0; (i < annotators); i++) { if ((lastTimeStamp >= annotatedRecord[i].StartUnix) && (lastTimeStamp <= annotatedRecord[i].EndUnix) && current_activity[i].Equals("unknown")) { current_activity[i] = ""; for (int j = 0; (j < annotatedRecord[i].Labels.Count); j++) { if (j == annotatedRecord[i].Labels.Count - 1) current_activity[i] += ((AXML.Label)annotatedRecord[i].Labels[j]).Name; else current_activity[i] += ((AXML.Label)annotatedRecord[i].Labels[j]).Name + "_"; } current_activity[i] = current_activity[i].Replace("none", "").Replace('-', '_').Replace(':', '_').Replace('%', '_').Replace('/', '_'); current_activity[i] = Regex.Replace(current_activity[i], "[_]+", "_"); current_activity[i] = Regex.Replace(current_activity[i], "^[_]+", ""); current_activity[i] = Regex.Replace(current_activity[i], "[_]+$", ""); } else if (lastTimeStamp > annotatedRecord[i].EndUnix) current_activity[i] = "unknown"; } if ((lastTimeStamp >= realtimeRecord.StartUnix) && (lastTimeStamp <= realtimeRecord.EndUnix) && realtime_activity.Equals("unknown")) { realtime_activity = ""; for (int j = 0; (j < realtimeRecord.Labels.Count); j++) { if (j == realtimeRecord.Labels.Count - 1) realtime_activity += ((AXML.Label)realtimeRecord.Labels[j]).Name; else realtime_activity += ((AXML.Label)realtimeRecord.Labels[j]).Name + "_"; } realtime_activity = realtime_activity.Replace("none", "").Replace('-', '_').Replace(':', '_').Replace('%', '_').Replace('/', '_'); realtime_activity = Regex.Replace(realtime_activity, "[_]+", "_"); realtime_activity = Regex.Replace(realtime_activity, "^[_]+", ""); realtime_activity = Regex.Replace(realtime_activity, "[_]+$", ""); } else if (lastTimeStamp > realtimeRecord.EndUnix) realtime_activity = "unknown"; if ((lastTimeStamp >= intersectionRecord.StartUnix) && (lastTimeStamp <= intersectionRecord.EndUnix) && intersection_activity.Equals("unknown")) { intersection_activity = ""; for (int j = 0; (j < intersectionRecord.Labels.Count); j++) { if (j == intersectionRecord.Labels.Count - 1) intersection_activity += ((AXML.Label)intersectionRecord.Labels[j]).Name; else intersection_activity += ((AXML.Label)intersectionRecord.Labels[j]).Name + "_"; } intersection_activity = intersection_activity.Replace("none", "").Replace('-', '_').Replace(':', '_').Replace('%', '_').Replace('/', '_'); intersection_activity = Regex.Replace(intersection_activity, "[_]+", "_"); intersection_activity = Regex.Replace(intersection_activity, "^[_]+", ""); intersection_activity = Regex.Replace(intersection_activity, "[_]+$", ""); } if ((Extractor.GenerateFeatureVector(lastTimeStamp))) { string activity_suffix = "," + featureVectorIndex; if (intersection_activity.Equals("unknown") == true) //disagreement or agreement unknown { if ((current_activity[0] == "unknown") && (current_activity[1] == "unknown")) activity_suffix += ",1"; else activity_suffix += ",0"; for (int i = 0; (i < annotators); i++) activity_suffix += "," + current_activity[i]; } else { activity_suffix += ",1"; for (int i = 0; (i < annotators); i++) activity_suffix += "," + intersection_activity; } string arffSample = Extractor.toString() + activity_suffix; //if (activity_suffix.Contains("unknown") == false) //{ tw.WriteLine(arffSample+","+realtime_activity); featureVectorIndex++; //} } } while (isData = aMITesLoggerReader.GetSensorData(10)); tw.Close(); }
public static void Initialize(MITesDecoder aMITesDecoder, string aDataDirectory, AXML.Annotation aannotation, SXML.SensorAnnotation sannotation, GeneralConfiguration configuration)//, string masterDirectory) { Extractor.aannotation = aannotation; Extractor.sannotation = sannotation; Extractor.dconfiguration = configuration; // count the sensors for feature extraction and identify their indicies in // sensor annotation - at the moment only accelerometers are used Extractor.sensorIndicies = new Hashtable(); Extractor.extractorSensorCount = 0; foreach (SXML.Sensor sensor in sannotation.Sensors) { int channel=Convert.ToInt32(sensor.ID); if (channel > 0) // if accelerometer { Extractor.sensorIndicies[channel] = extractorSensorCount; Extractor.extractorSensorCount++; } } //load sensor data //SXML.Reader sreader = new SXML.Reader(masterDirectory, aDataDirectory); //Extractor.sannotation = sreader.parse(); //load configuration // ConfigurationReader creader = new ConfigurationReader(aDataDirectory); // Extractor.dconfiguration = creader.parse(); //load annotation data //AXML.Reader reader = new AXML.Reader(masterDirectory, aDataDirectory + "\\" + AXML.Reader.DEFAULT_XML_FILE); //Extractor.aannotation = reader.parse(); //CHANGE: gathers training samples based on the first category only Extractor.trainingTime = new Hashtable();//int[((AXML.Category)Extractor.aannotation.Categories[0]).Labels.Count]; //for (int i = 0; (i < Extractor.trainingTime.Length); i++) foreach (AXML.Label label in ((AXML.Category)Extractor.aannotation.Categories[0]).Labels) Extractor.trainingTime.Add(label.Name, 0); //Extractor.trainingTime[i] = 0; Extractor.trainingCompleted = false; Extractor.inputRowSize = Extractor.extractorSensorCount * 3; Extractor.fftInterpolationPower = dconfiguration.FFTInterpolatedPower; Extractor.fftMaximumFrequencies = dconfiguration.FFTMaximumFrequencies; //Extractor.trainingTimePerClass = configuration.TrainingTime; //Extractor.trainingWaitTime = configuration.TrainingWaitTime; Extractor.inputColumnSize = (int)Math.Pow(2, Extractor.fftInterpolationPower); Extractor.num_features = Extractor.inputRowSize; // number of distances Extractor.num_features += 1; //total mean; Extractor.num_features += Extractor.inputRowSize; // number of variances Extractor.num_features += Extractor.inputRowSize; // number of ranges Extractor.num_features += 2 * Extractor.fftMaximumFrequencies * Extractor.inputRowSize; // number of fft magnitudes and frequencies Extractor.num_features += Extractor.inputRowSize; // number of energies Extractor.num_features += ((Extractor.inputRowSize * Extractor.inputRowSize) - Extractor.inputRowSize) / 2; //correlation coefficients off-di Extractor.features = new double[Extractor.num_features]; Extractor.arffAttriburesLabels = new string[Extractor.num_features]; Extractor.attributeLocation = new Hashtable(); Extractor.standardized = new double[inputRowSize][]; for (int i = 0; (i < inputRowSize); i++) Extractor.standardized[i] = new double[Extractor.inputColumnSize];//input[0].Length]; Extractor.means = new double[inputRowSize]; inputFFT = new int[Extractor.inputColumnSize]; FFT.Initialize(fftInterpolationPower, fftMaximumFrequencies); Extractor.aMITesDecoder = aMITesDecoder; //Create the ARFF File header string arffHeader = "@RELATION wockets\n\n" + Extractor.GetArffHeader();//sannotation.Sensors.Count * 3, configuration.FFTMaximumFrequencies); arffHeader += "@ATTRIBUTE activity {"; foreach (AXML.Label label in ((AXML.Category)Extractor.aannotation.Categories[0]).Labels) arffHeader += label.Name.Replace(' ', '_') + ","; arffHeader += "unknown}\n"; arffHeader += "\n@DATA\n\n"; //Calculating windowing parameters //total number of points per interpolated window Extractor.INTERPOLATED_SAMPLING_RATE_PER_WINDOW = (int)Math.Pow(2, dconfiguration.FFTInterpolatedPower); //128; //space between interpolated samples Extractor.INTERPOLATED_SAMPLES_SPACING = (double)dconfiguration.WindowTime / INTERPOLATED_SAMPLING_RATE_PER_WINDOW; //expected sampling rate per MITes //Extractor.EXPECTED_SAMPLING_RATE = dconfiguration.ExpectedSamplingRate / sannotation.Sensors.Count; //samples per second //expected samples per window //Extractor.EXPECTED_WINDOW_SIZE = (int)(EXPECTED_SAMPLING_RATE * (dconfiguration.WindowTime / 1000.0)); // expectedSamplingRate per window //what would be considered a good sampling rate //Extractor.EXPECTED_GOOD_SAMPLING_RATE = EXPECTED_WINDOW_SIZE - (int)(dconfiguration.MaximumNonconsecutiveFrameLoss * EXPECTED_WINDOW_SIZE); //number of packets lost per second //space between samples //Extractor.EXPECTED_SAMPLES_SPACING = (double)dconfiguration.WindowTime / EXPECTED_WINDOW_SIZE; Extractor.EXPECTED_SAMPLING_RATES = new int[Extractor.extractorSensorCount]; Extractor.EXPECTED_WINDOW_SIZES = new int[Extractor.extractorSensorCount]; Extractor.EXPECTED_GOOD_SAMPLING_RATES = new int[Extractor.extractorSensorCount]; Extractor.EXPECTED_SAMPLES_SPACING = new double[Extractor.extractorSensorCount]; //foreach (SXML.Sensor sensor in sannotation.Sensors) foreach (DictionaryEntry sensorEntry in Extractor.sensorIndicies) { //Get the channel and index in data array for only // extractor sensors (sensors that will be used to compute // features i.e. accelerometers) int channel=(int)sensorEntry.Key; int sensorIndex = (int)sensorEntry.Value; SXML.Sensor sensor = ((SXML.Sensor)sannotation.Sensors[(int)sannotation.SensorsIndex[channel]]); int receiverID = Convert.ToInt32(sensor.Receiver); if (channel == MITesDecoder.MAX_CHANNEL) //Built in sensor Extractor.EXPECTED_SAMPLING_RATES[sensorIndex] = sensor.SamplingRate; //used sensor sampling rate else Extractor.EXPECTED_SAMPLING_RATES[sensorIndex] = dconfiguration.ExpectedSamplingRate / sannotation.NumberSensors[receiverID]; Extractor.EXPECTED_WINDOW_SIZES[sensorIndex] = (int)(Extractor.EXPECTED_SAMPLING_RATES[sensorIndex] * (dconfiguration.WindowTime / 1000.0)); Extractor.EXPECTED_GOOD_SAMPLING_RATES[sensorIndex] = Extractor.EXPECTED_WINDOW_SIZES[sensorIndex] - (int)(dconfiguration.MaximumNonconsecutiveFrameLoss * Extractor.EXPECTED_WINDOW_SIZES[sensorIndex]); Extractor.EXPECTED_SAMPLES_SPACING[sensorIndex] = (double)dconfiguration.WindowTime / Extractor.EXPECTED_WINDOW_SIZES[sensorIndex]; } //window counters and delimiters Extractor.next_window_end = 0; Extractor.total_window_count = 0; Extractor.num_feature_windows = 0; //data quality variables Extractor.isAcceptableLossRate = true; Extractor.isAcceptableConsecutiveLoss = true; Extractor.unacceptable_window_count = 0; Extractor.unacceptable_consecutive_window_loss_count = 0; //2 D array that stores Sensor axes + time stamps on each row X expected WINDOW SIZE Extractor.data = new double[Extractor.extractorSensorCount * 4][]; // 1 row for each axis // 2D array that stores Sensor axes X INTERPOLATED WINDOW SIZE Extractor.interpolated_data = new double[Extractor.extractorSensorCount * 3][]; // array to store the y location for each axes as data is received // will be different for every sensor of course Extractor.y_index = new int[Extractor.extractorSensorCount]; //Initialize expected data array foreach (DictionaryEntry sensorEntry in Extractor.sensorIndicies) { //Get the channel and index in data array for only // extractor sensors (sensors that will be used to compute // features i.e. accelerometers) int channel=(int)sensorEntry.Key; int sensorIndex = (int)sensorEntry.Value; int adjusted_sensor_index = sensorIndex * 4; //Initialize 4 rows x,y,z timestamp for (int j = 0; j < 4; j++) { Extractor.data[adjusted_sensor_index] = new double[EXPECTED_WINDOW_SIZES[sensorIndex]]; for (int k = 0; (k < EXPECTED_WINDOW_SIZES[sensorIndex]); k++) Extractor.data[adjusted_sensor_index][k] = 0; adjusted_sensor_index++; } } //Here it is equal across all sensors, so we do not need to consider //the sampling rate of each sensor separately for (int j = 0; (j < (Extractor.extractorSensorCount * 3)); j++) { Extractor.interpolated_data[j] = new double[INTERPOLATED_SAMPLING_RATE_PER_WINDOW]; for (int k = 0; (k < INTERPOLATED_SAMPLING_RATE_PER_WINDOW); k++) Extractor.interpolated_data[j][k] = 0; } //Initialize y index for each sensor for (int j = 0; (j < Extractor.extractorSensorCount); j++) Extractor.y_index[j] = 0; }
public static void toARFF2(string aDataDirectory, string masterDirectory, int maxControllers) { MITesDecoder aMITesDecoder = new MITesDecoder(); MITesLoggerReader aMITesLoggerReader = new MITesLoggerReader(aMITesDecoder, aDataDirectory); AXML.Annotation aannotation = null; SXML.SensorAnnotation sannotation = null; Hashtable calibrations = null; AXML.Reader reader = new AXML.Reader(masterDirectory, aDataDirectory,"AnnotationIntervals.xml"); aannotation = reader.parse(); aannotation.DataDirectory = aDataDirectory; SXML.Reader sreader = new SXML.Reader(masterDirectory, aDataDirectory); sannotation = sreader.parse(maxControllers); SOXML.Reader calreader = new SOXML.Reader(aDataDirectory); calibrations = calreader.parse(); Extractor.Initialize2(aMITesDecoder, aDataDirectory, aannotation, sannotation,calibrations); TextWriter tw = new StreamWriter(aDataDirectory + "\\output2.arff"); tw.WriteLine("@RELATION wockets"); tw.WriteLine(Extractor.GetArffHeader2()); tw.Write("@ATTRIBUTE activity {unknown"); Hashtable recorded_activities = new Hashtable(); for (int i = 0; (i < aannotation.Data.Count); i++) { AXML.AnnotatedRecord record = ((AXML.AnnotatedRecord)aannotation.Data[i]); string activity = ""; for (int j = 0; (j < record.Labels.Count); j++) { if (j == record.Labels.Count - 1) activity += ((AXML.Label)record.Labels[j]).Name; else activity += ((AXML.Label)record.Labels[j]).Name + "_"; } activity = activity.Replace("none", "").Replace('-', '_').Replace(':', '_').Replace('%', '_').Replace('/', '_'); activity = Regex.Replace(activity, "[_]+", "_"); activity = Regex.Replace(activity, "^[_]+", ""); activity = Regex.Replace(activity, "[_]+$", ""); //only output activity labels that have not been seen if (recorded_activities.Contains(activity) == false) { tw.Write("," + activity); recorded_activities[activity] = activity; } } tw.WriteLine("}"); tw.WriteLine("@DATA"); bool isData = aMITesLoggerReader.GetSensorData(10); int channel = 0, x = 0, y = 0, z = 0; double unixtimestamp = 0.0; int activityIndex = 0; AXML.AnnotatedRecord annotatedRecord = ((AXML.AnnotatedRecord)aannotation.Data[activityIndex]); string current_activity = "unknown"; do { //decode the frame channel = aMITesDecoder.GetSomeMITesData()[0].channel; x = aMITesDecoder.GetSomeMITesData()[0].x; y = aMITesDecoder.GetSomeMITesData()[0].y; z = aMITesDecoder.GetSomeMITesData()[0].z; unixtimestamp = aMITesDecoder.GetSomeMITesData()[0].unixTimeStamp; double lastTimeStamp = Extractor.StoreMITesWindow(); //DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0); //dt=dt.AddMilliseconds(unixtimestamp); //DateTime dt2 = new DateTime(1970, 1, 1, 0, 0, 0, 0); //dt2 = dt2.AddMilliseconds(annotatedRecord.EndUnix); if (unixtimestamp > annotatedRecord.EndUnix) { current_activity = "unknown"; if (activityIndex < aannotation.Data.Count - 1) { activityIndex++; annotatedRecord = ((AXML.AnnotatedRecord)aannotation.Data[activityIndex]); } } if ((lastTimeStamp >= annotatedRecord.StartUnix) && (lastTimeStamp <= annotatedRecord.EndUnix) && current_activity.Equals("unknown")) { current_activity = ""; for (int j = 0; (j < annotatedRecord.Labels.Count); j++) { if (j == annotatedRecord.Labels.Count - 1) current_activity += ((AXML.Label)annotatedRecord.Labels[j]).Name; else current_activity += ((AXML.Label)annotatedRecord.Labels[j]).Name + "_"; } current_activity = current_activity.Replace("none", "").Replace('-', '_').Replace(':', '_').Replace('%', '_').Replace('/', '_'); current_activity = Regex.Replace(current_activity, "[_]+", "_"); current_activity = Regex.Replace(current_activity, "^[_]+", ""); current_activity = Regex.Replace(current_activity, "[_]+$", ""); } //if (lastTimeStamp>= if (current_activity.Equals("unknown") == false) { if ((Extractor.GenerateFeatureVector(lastTimeStamp))) { string arffSample = Extractor.toString() + "," + current_activity; tw.WriteLine(arffSample); } } } while (isData = aMITesLoggerReader.GetSensorData(10)); tw.Close(); }
private void InitializeInterface() { orientationMatrix = new int[SimilarActivitiesForm.ConfusingActivities.Count][]; //orientationIndex = new int[SimilarActivitiesForm.ConfusingActivities.Count][]; SXML.Reader sreader = new SXML.Reader(Constants.MASTER_DIRECTORY, TroubleshootModel.SelectedFolder); if (sreader.validate() == false) { throw new Exception("Error Code 0: XML format error - sensors.xml does not match sensors.xsd!"); } else { this.sensors = sreader.parse(Constants.MAX_CONTROLLERS); } for (int i = 0; (i < OrientationForm.orientationMatrix.Length); i++) { OrientationForm.orientationMatrix[i] = new int[this.sensors.Sensors.Count]; // this.orientationIndex[i] = new int[this.sensors.Sensors.Count]; for (int j = 0; (j < this.sensors.Sensors.Count); j++) { OrientationForm.orientationMatrix[i][j] = -1; // this.orientationIndex[i][j] = 0; } } BodyXML.Parser parser = new BodyXML.Parser(Constants.MASTER_DIRECTORY); this.bodyParts = parser.parse(); this.body_parts=new ArrayList(); this.body_parts_orientations= new ArrayList(); this.body_parts_orientations_names= new ArrayList(); int maxImageWidth = 0; int maxImageHeight = 0; foreach (BodyPart bodyPart in this.bodyParts.Bodyparts) { this.body_parts.Add(bodyPart.Label); ArrayList orientations= new ArrayList(); ArrayList names=new ArrayList(); foreach (BodyXML.Orientation orientation in bodyPart.Orientations){ System.Drawing.Image orientationImage=(System.Drawing.Image) new System.Drawing.Bitmap(Constants.NEEDED_FILES_PATH + "images\\orientations\\"+orientation.Imagefile); if (orientationImage.Width > maxImageWidth) maxImageWidth = orientationImage.Width; if (orientationImage.Height > maxImageHeight) maxImageHeight = orientationImage.Height; orientations.Add(orientationImage); names.Add(orientation.Label); } this.body_parts_orientations.Add(orientations); this.body_parts_orientations_names.Add(names); } this.bodyPartCurrentIndex = 0; this.orientationCurrentIndex = 0; this.activityCurrentIndex = 0; //this.pictureBox1.Width = maxImageWidth+Constants.WIDGET_SPACING*2; //this.pictureBox1.Height = maxImageHeight + Constants.WIDGET_SPACING * 2; //this.panel1.Width = this.pictureBox1.Width + Constants.WIDGET_SPACING * 2; //this.panel1.Height = this.pictureBox1.Height + Constants.WIDGET_SPACING * 2; this.panel1.BackColor = System.Drawing.Color.White; //this.button1.Location = new System.Drawing.Point(this.panel1.Location.X, this.panel1.Location.Y + this.panel1.Location.Y); //this.button2.Location = new System.Drawing.Point(this.panel1.Location.X, this.panel1.Location.Y + this.button1.Location.Y+this.button1.Width+Constants.WIDGET_SPACING); this.pictureBox1.Image = (System.Drawing.Image)((ArrayList)this.body_parts_orientations[this.bodyPartCurrentIndex])[this.orientationCurrentIndex]; this.label2.Text = (string)((ArrayList)this.body_parts_orientations_names[this.bodyPartCurrentIndex])[this.orientationCurrentIndex]; this.label1.Text = "During " + (string)SimilarActivitiesForm.ConfusingActivities[activityCurrentIndex] + ", how does your "+(string)this.body_parts[this.bodyPartCurrentIndex]+" look like?"; }
public static void Initialize(MITesDecoder aMITesDecoder, string aDataDirectory, AXML.Annotation aannotation,SXML.SensorAnnotation sannotation)//, string masterDirectory) { Extractor.aannotation = aannotation; Extractor.sannotation = sannotation; //load sensor data //SXML.Reader sreader = new SXML.Reader(masterDirectory, aDataDirectory); //Extractor.sannotation = sreader.parse(); //load configuration ConfigurationReader creader = new ConfigurationReader(aDataDirectory); Extractor.dconfiguration = creader.parse(); //load annotation data //AXML.Reader reader = new AXML.Reader(masterDirectory, aDataDirectory + "\\" + AXML.Reader.DEFAULT_XML_FILE); //Extractor.aannotation = reader.parse(); //CHANGE: gathers training samples based on the first category only Extractor.trainingTime = new Hashtable();//int[((AXML.Category)Extractor.aannotation.Categories[0]).Labels.Count]; //for (int i = 0; (i < Extractor.trainingTime.Length); i++) foreach (AXML.Label label in ((AXML.Category)Extractor.aannotation.Categories[0]).Labels) Extractor.trainingTime.Add(label.Name, 0); //Extractor.trainingTime[i] = 0; Extractor.trainingCompleted = false; Extractor.inputRowSize = sannotation.Sensors.Count * 3; Extractor.fftInterpolationPower = dconfiguration.FFTInterpolatedPower; Extractor.fftMaximumFrequencies = dconfiguration.FFTMaximumFrequencies; //Extractor.trainingTimePerClass = configuration.TrainingTime; //Extractor.trainingWaitTime = configuration.TrainingWaitTime; Extractor.inputColumnSize = (int)Math.Pow(2, Extractor.fftInterpolationPower); Extractor.num_features = Extractor.inputRowSize; // number of distances Extractor.num_features += 1; //total mean; Extractor.num_features += Extractor.inputRowSize; // number of variances Extractor.num_features += Extractor.inputRowSize; // number of ranges Extractor.num_features += 2 * Extractor.fftMaximumFrequencies * Extractor.inputRowSize; // number of fft magnitudes and frequencies Extractor.num_features += Extractor.inputRowSize; // number of energies Extractor.num_features += ((Extractor.inputRowSize * Extractor.inputRowSize) - Extractor.inputRowSize) / 2; //correlation coefficients off-di Extractor.features = new double[Extractor.num_features]; Extractor.arffAttriburesLabels = new string[Extractor.num_features]; Extractor.standardized = new double[inputRowSize][]; for (int i = 0; (i < inputRowSize); i++) Extractor.standardized[i] = new double[Extractor.inputColumnSize];//input[0].Length]; Extractor.means = new double[inputRowSize]; inputFFT = new int[Extractor.inputColumnSize]; FFT.Initialize(fftInterpolationPower, fftMaximumFrequencies); Extractor.aMITesDecoder = aMITesDecoder; //Create the ARFF File header string arffHeader = "@RELATION wockets\n\n" + Extractor.GetArffHeader();//sannotation.Sensors.Count * 3, configuration.FFTMaximumFrequencies); arffHeader += "@ATTRIBUTE activity {"; foreach (AXML.Label label in ((AXML.Category)Extractor.aannotation.Categories[0]).Labels) arffHeader += label.Name.Replace(' ', '_') + ","; arffHeader += "unknown}\n"; arffHeader += "\n@DATA\n\n"; //Calculating windowing parameters //total number of points per interpolated window Extractor.INTERPOLATED_SAMPLING_RATE_PER_WINDOW = (int)Math.Pow(2, dconfiguration.FFTInterpolatedPower); //128; //expected sampling rate per MITes Extractor.EXPECTED_SAMPLING_RATE = dconfiguration.ExpectedSamplingRate / sannotation.Sensors.Count; //samples per second //expected samples per window Extractor.EXPECTED_WINDOW_SIZE = (int)(EXPECTED_SAMPLING_RATE * (dconfiguration.WindowTime / 1000.0)); // expectedSamplingRate per window //what would be considered a good sampling rate Extractor.EXPECTED_GOOD_SAMPLING_RATE = EXPECTED_WINDOW_SIZE - (int)(dconfiguration.MaximumNonconsecutiveFrameLoss * EXPECTED_WINDOW_SIZE); //number of packets lost per second //space between samples Extractor.EXPECTED_SAMPLES_SPACING = (double)dconfiguration.WindowTime / EXPECTED_WINDOW_SIZE; //space between interpolated samples Extractor.INTERPOLATED_SAMPLES_SPACING = (double)dconfiguration.WindowTime / INTERPOLATED_SAMPLING_RATE_PER_WINDOW; //window counters and delimiters Extractor.next_window_end = 0; Extractor.total_window_count = 0; Extractor.num_feature_windows = 0; //data quality variables Extractor.isAcceptableLossRate = true; Extractor.isAcceptableConsecutiveLoss = true; Extractor.unacceptable_window_count = 0; Extractor.unacceptable_consecutive_window_loss_count = 0; //2 D array that stores Sensor axes + time stamps on each row X expected WINDOW SIZE Extractor.data = new double[Extractor.sannotation.Sensors.Count * 4][]; // 1 row for each axis // 2D array that stores Sensor axes X INTERPOLATED WINDOW SIZE Extractor.interpolated_data = new double[Extractor.sannotation.Sensors.Count * 3][]; // array to store the y location for each axes as data is received // will be different for every sensor of course Extractor.y_index = new int[Extractor.sannotation.Sensors.Count]; //Initialize expected data array for (int j = 0; (j < (Extractor.sannotation.Sensors.Count * 4)); j++) { Extractor.data[j] = new double[EXPECTED_WINDOW_SIZE]; for (int k = 0; (k < EXPECTED_WINDOW_SIZE); k++) Extractor.data[j][k] = 0; } //Initialize interpolated data array for (int j = 0; (j < (Extractor.sannotation.Sensors.Count * 3)); j++) { Extractor.interpolated_data[j] = new double[INTERPOLATED_SAMPLING_RATE_PER_WINDOW]; for (int k = 0; (k < INTERPOLATED_SAMPLING_RATE_PER_WINDOW); k++) Extractor.interpolated_data[j][k] = 0; } //Initialize y index for each sensor for (int j = 0; (j < Extractor.sannotation.Sensors.Count); j++) Extractor.y_index[j] = 0; }