//Transform3D[] t3DModels = null; private void MoveBalls(TSkeleton skeleton) { for (int a = 0; a < 21; a++) { BallBoundingBox bbb = (BallBoundingBox)balls[a]; bbb.X = skeleton.Position[a].X; bbb.Y = skeleton.Position[a].Y; bbb.Z = skeleton.Position[a].Z; } for (int a = 0; a < jointIndexAray.Count; a++) { BallBoundingBox bbb = (BallBoundingBox)balls[a + 21]; JointIndex ji = (JointIndex)jointIndexAray[a]; int divHelper = ji.visuals.Count + 1; for (int b = 0; b < ji.visuals.Count; b++) { ModelVisual3D mv3d = (ModelVisual3D)ji.visuals[b]; float f16X = skeleton.Position[ji.joint1].X; float f16Y = skeleton.Position[ji.joint1].Y; float f16Z = skeleton.Position[ji.joint1].Z; float f17X = skeleton.Position[ji.joint2].X; float f17Y = skeleton.Position[ji.joint2].Y; float f17Z = skeleton.Position[ji.joint2].Z; float aa = (float)(b + 1) / divHelper; //float aa = (float)b / ji.visuals.Count; bbb.X = (aa * f16X) + ((1 - aa) * f17X); bbb.Y = (aa * f16Y) + ((1 - aa) * f17Y); bbb.Z = (aa * f16Z) + ((1 - aa) * f17Z); } } }
/// <summary> /// Draws a bone line between two joints /// </summary> /// <param name="skeleton">skeleton to draw bones from</param> /// <param name="drawingContext">drawing context to draw to</param> /// <param name="jointType0">joint to start drawing from</param> /// <param name="jointType1">joint to end drawing at</param> public static void DrawBone(TSkeleton skeleton, DrawingContext drawingContext, TJointType jointType0, TJointType jointType1) { TJoint joint0 = skeleton.Joints[(int)jointType0]; TJoint joint1 = skeleton.Joints[(int)jointType1]; // If we can't find either of these joints, exit if (joint0.TrackingState == TJointTrackingState.NotTracked || joint1.TrackingState == TJointTrackingState.NotTracked) { return; } // Don't draw if both points are inferred if (joint0.TrackingState == TJointTrackingState.Inferred && joint1.TrackingState == TJointTrackingState.Inferred) { return; } // We assume all drawn bones are inferred unless BOTH joints are tracked Pen drawPen = inferredBonePen; if (joint0.TrackingState == TJointTrackingState.Tracked && joint1.TrackingState == TJointTrackingState.Tracked) { drawPen = trackedBonePen; } drawingContext.DrawLine(drawPen, SkeletonPointToScreen(joint0.Position), SkeletonPointToScreen(joint1.Position)); }
/// <summary> /// Draws indicators to show which edges are clipping skeleton data /// </summary> /// <param name="skeleton">skeleton to draw clipping information for</param> /// <param name="drawingContext">drawing context to draw to</param> public static void RenderClippedEdges(TSkeleton skeleton, DrawingContext drawingContext) { if (skeleton.ClippedEdges.HasFlag(TFrameEdges.Bottom)) { drawingContext.DrawRectangle( Brushes.Red, null, new Rect(0, RenderHeight - ClipBoundsThickness, RenderWidth, ClipBoundsThickness)); } if (skeleton.ClippedEdges.HasFlag(TFrameEdges.Top)) { drawingContext.DrawRectangle( Brushes.Red, null, new Rect(0, 0, RenderWidth, ClipBoundsThickness)); } if (skeleton.ClippedEdges.HasFlag(TFrameEdges.Left)) { drawingContext.DrawRectangle( Brushes.Red, null, new Rect(0, 0, ClipBoundsThickness, RenderHeight)); } if (skeleton.ClippedEdges.HasFlag(TFrameEdges.Right)) { drawingContext.DrawRectangle( Brushes.Red, null, new Rect(RenderWidth - ClipBoundsThickness, 0, ClipBoundsThickness, RenderHeight)); } }
/// <summary> /// Draws a body /// </summary> /// <param name="joints">joints to draw</param> /// <param name="jointPoints">translated positions of joints to draw</param> /// <param name="drawingContext">drawing context to draw to</param> /// <param name="drawingPen">specifies color to draw a specific body</param> private void DrawBody(TSkeleton tSkeleton, Point[] updatedPositions, DrawingContext drawingContext, Pen drawingPen) //private void DrawBody(IReadOnlyDictionary<JointType, Joint> joints, IDictionary<JointType, Point> jointPoints, DrawingContext drawingContext, Pen drawingPen) { // Draw the bones //foreach (var bone in this.bones) for (int a = 0; a < HendlerHolder.ArrayJointsConnectivity.Length; a++) { this.DrawBone(tSkeleton, updatedPositions, HendlerHolder.ArrayJointsConnectivity[a][0], HendlerHolder.ArrayJointsConnectivity[a][1], drawingContext, drawingPen); } // Draw the joints for (int a = 0; a < tSkeleton.Position.Length; a++) { Brush drawBrush = null; TrackingState trackingState = tSkeleton.TrackingState[a]; if (trackingState == TrackingState.Tracked) { drawBrush = HendlerHolder.TrackedJointBrush; } else if (trackingState == TrackingState.Inferred) { drawBrush = HendlerHolder.InferredJointBrush; } if (drawBrush != null) { drawingContext.DrawEllipse(drawBrush, null, updatedPositions[a], HendlerHolder.JointThickness, HendlerHolder.JointThickness); } } }
private void DrawImage(TSkeleton[] tSkeletons) { using (DrawingContext dc = this.drawingGroup.Open()) { // Draw a transparent background to set the render size dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, HendlerHolder.DisplayWidth, HendlerHolder.DisplayHeight)); if (tSkeletons == null) { return; } int penIndex = 0; //foreach (Body body in this.bodies) for (int a = 0; a < tSkeletons.Length; a++) { TSkeleton tSkeleton = tSkeletons[a]; Pen drawPen = HendlerHolder.BodyColors[penIndex++]; if (tSkeleton.IsTracked) { this.DrawClippedEdges(tSkeleton, dc); //IReadOnlyDictionary<JointType, Joint> joints = body.Joints; // convert the joint points to depth (display) space //Dictionary<JointType, Point> jointPoints = new Dictionary<JointType, Point>(); //foreach (JointType jointType in joints.Keys) Point[] updatedPositions = new Point[tSkeleton.Position.Length]; for (int b = 0; b < tSkeleton.Position.Length; b++) { // sometimes the depth(Z) of an inferred joint may show as negative // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity) updatedPositions[b] = new Point(); CameraSpacePoint updatedCSP = new CameraSpacePoint(); updatedCSP.X = tSkeleton.Position[b].X; updatedCSP.Y = tSkeleton.Position[b].Y; updatedCSP.Z = tSkeleton.Position[b].Z; if (updatedCSP.Z < 0) { updatedCSP.Z = HendlerHolder.InferredZPositionClamp; } DepthSpacePoint depthSpacePoint = HendlerHolder.MapSkeletonPointToDepthPointOffline(updatedCSP); //DepthSpacePoint depthSpacePoint = HendlerHolder.coordinateMapper.MapCameraPointToDepthSpace(updatedCSP); updatedPositions[b] = new Point(depthSpacePoint.X, depthSpacePoint.Y); //jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y); } this.DrawBody(tSkeleton, updatedPositions, dc, drawPen); this.DrawHand(tSkeleton.HandLeftState, updatedPositions[(int)JointType.HandLeft], dc); this.DrawHand(tSkeleton.HandRightState, updatedPositions[(int)JointType.HandRight], dc); } } // prevent drawing outside of our render area this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, HendlerHolder.DisplayWidth, HendlerHolder.DisplayHeight)); } }
private void CompareSkeletons(TSkeleton skeleton1, TSkeleton skeleton2) { Assert.True(skeleton1.ClippedEdges == skeleton2.ClippedEdges); Assert.True(skeleton1.TrackingId == skeleton2.TrackingId); Assert.True(skeleton1.TrackingState == skeleton2.TrackingState); for (int i = 0; i < 10; i++) { CompareJoint(skeleton1.Joints[i], skeleton2.Joints[i]); } CompareSkeletonPoints(skeleton1.Position, skeleton2.Position); }
/// <summary> /// Draws a skeleton's bones and joints /// </summary> /// <param name="skeleton">skeleton to draw</param> /// <param name="drawingContext">drawing context to draw to</param> public static void DrawBonesAndJoints(TSkeleton skeleton, DrawingContext drawingContext) { // Render Torso DrawBone(skeleton, drawingContext, TJointType.Head, TJointType.ShoulderCenter); DrawBone(skeleton, drawingContext, TJointType.ShoulderCenter, TJointType.ShoulderLeft); DrawBone(skeleton, drawingContext, TJointType.ShoulderCenter, TJointType.ShoulderRight); DrawBone(skeleton, drawingContext, TJointType.ShoulderCenter, TJointType.Spine); DrawBone(skeleton, drawingContext, TJointType.Spine, TJointType.HipCenter); DrawBone(skeleton, drawingContext, TJointType.HipCenter, TJointType.HipLeft); DrawBone(skeleton, drawingContext, TJointType.HipCenter, TJointType.HipRight); // Left Arm DrawBone(skeleton, drawingContext, TJointType.ShoulderLeft, TJointType.ElbowLeft); DrawBone(skeleton, drawingContext, TJointType.ElbowLeft, TJointType.WristLeft); DrawBone(skeleton, drawingContext, TJointType.WristLeft, TJointType.HandLeft); // Right Arm DrawBone(skeleton, drawingContext, TJointType.ShoulderRight, TJointType.ElbowRight); DrawBone(skeleton, drawingContext, TJointType.ElbowRight, TJointType.WristRight); DrawBone(skeleton, drawingContext, TJointType.WristRight, TJointType.HandRight); // Left Leg DrawBone(skeleton, drawingContext, TJointType.HipLeft, TJointType.KneeLeft); DrawBone(skeleton, drawingContext, TJointType.KneeLeft, TJointType.AnkleLeft); DrawBone(skeleton, drawingContext, TJointType.AnkleLeft, TJointType.FootLeft); // Right Leg DrawBone(skeleton, drawingContext, TJointType.HipRight, TJointType.KneeRight); DrawBone(skeleton, drawingContext, TJointType.KneeRight, TJointType.AnkleRight); DrawBone(skeleton, drawingContext, TJointType.AnkleRight, TJointType.FootRight); // Render Joints foreach (TJoint joint in skeleton.Joints) { Brush drawBrush = null; if (joint.TrackingState == TJointTrackingState.Tracked) { drawBrush = trackedJointBrush; } else if (joint.TrackingState == TJointTrackingState.Inferred) { drawBrush = inferredJointBrush; } if (drawBrush != null) { drawingContext.DrawEllipse(drawBrush, null, SkeletonPointToScreen(joint.Position), JointThickness, JointThickness); } } }
protected override TSkeletonFrame InitializeFrame() { var skeletons = new TSkeleton[10]; for (int i = 0; i < 10; i++) { skeletons[i] = GetSkeleton(); } return(new TSkeletonFrame() { Timestamp = Random.Next(), FrameNumber = Random.Next(), FloorClipPlane = new Tuple <float, float, float, float>(Random.NextFloat(), Random.NextFloat(), Random.NextFloat(), Random.NextFloat()), SkeletonArrayLength = 10, Skeletons = skeletons, }); }
public static Point3D[] GenerateBodyPartArray(TSkeleton skeleton, int user) { Point3D[] returnArray = new Point3D[skeleton.Position.Length]; if (skeleton == null) return null; for (int a = 0; a < returnArray.Length; a++) { returnArray[a] = new Point3D(0, 0, 0); try { returnArray[a].X = skeleton.Position[a].X * 1000.0f; returnArray[a].Y = skeleton.Position[a].Y * 1000.0f; returnArray[a].Z = skeleton.Position[a].Z * 1000.0f; } catch { } } return returnArray; }
/// <summary> /// Draws one bone of a body (joint to joint) /// </summary> /// <param name="joints">joints to draw</param> /// <param name="jointPoints">translated positions of joints to draw</param> /// <param name="jointType0">first joint of bone to draw</param> /// <param name="jointType1">second joint of bone to draw</param> /// <param name="drawingContext">drawing context to draw to</param> /// /// <param name="drawingPen">specifies color to draw a specific bone</param> //private void DrawBone(IReadOnlyDictionary<JointType, Joint> joints, IDictionary<JointType, Point> jointPoints, JointType jointType0, JointType jointType1, DrawingContext drawingContext, Pen drawingPen) private void DrawBone(TSkeleton tSkeleton, Point[] jointPoints, int jointType0, int jointType1, DrawingContext drawingContext, Pen drawingPen) { //Joint joint0 = joints[jointType0]; //Joint joint1 = joints[jointType1]; // If we can't find either of these joints, exit if (tSkeleton.TrackingState[jointType0] == TrackingState.NotTracked || tSkeleton.TrackingState[jointType1] == TrackingState.NotTracked) { return; } // We assume all drawn bones are inferred unless BOTH joints are tracked Pen drawPen = HendlerHolder.InferredBonePen; if ((tSkeleton.TrackingState[jointType0] == TrackingState.Tracked) && (tSkeleton.TrackingState[jointType1] == TrackingState.Tracked)) { drawPen = drawingPen; } drawingContext.DrawLine(drawPen, jointPoints[jointType0], jointPoints[jointType1]); }
private void DrawClippedEdges(TSkeleton body, DrawingContext drawingContext) { FrameEdges clippedEdges = body.ClippedEdges; if (clippedEdges.HasFlag(FrameEdges.Bottom)) { drawingContext.DrawRectangle( Brushes.Red, null, new Rect(0, HendlerHolder.DisplayHeight - HendlerHolder.ClipBoundsThickness, HendlerHolder.DisplayWidth, HendlerHolder.ClipBoundsThickness)); } if (clippedEdges.HasFlag(FrameEdges.Top)) { drawingContext.DrawRectangle( Brushes.Red, null, new Rect(0, 0, HendlerHolder.DisplayWidth, HendlerHolder.ClipBoundsThickness)); } if (clippedEdges.HasFlag(FrameEdges.Left)) { drawingContext.DrawRectangle( Brushes.Red, null, new Rect(0, 0, HendlerHolder.ClipBoundsThickness, HendlerHolder.DisplayHeight)); } if (clippedEdges.HasFlag(FrameEdges.Right)) { drawingContext.DrawRectangle( Brushes.Red, null, new Rect(HendlerHolder.DisplayWidth - HendlerHolder.ClipBoundsThickness, 0, HendlerHolder.ClipBoundsThickness, HendlerHolder.DisplayHeight)); } }
public void RenderModel(bool CheckBoxRelativeMoveIsChecked, TSkeleton skeleton) { MoveBalls(skeleton); for (int a = 0; a < 21; a++) { ModelVisual3D mv3d = _models[a]; //Transform3DGroup transGroup = new Transform3DGroup(); TranslateTransform3D translationTraansorm; if (CheckBoxRelativeMoveIsChecked == true) { translationTraansorm = new TranslateTransform3D(skeleton.Position[a].X - skeleton.Position[0].X, skeleton.Position[a].Y,// - skeletons[0].Position[0].Y, skeleton.Position[a].Z - skeleton.Position[0].Z); } else { translationTraansorm = new TranslateTransform3D(skeleton.Position[a].X, skeleton.Position[a].Y,// - skeletons[0].Position[0].Y, skeleton.Position[a].Z); } var myTransform3DGroup = new Transform3DGroup(); myTransform3DGroup.Children.Add(translationTraansorm); mv3d.Transform = myTransform3DGroup; } for (int a = 0; a < jointIndexAray.Count; a++) { JointIndex ji = (JointIndex)jointIndexAray[a]; int divHelper = ji.visuals.Count + 1; for (int b = 0; b < ji.visuals.Count; b++) { ModelVisual3D mv3d = (ModelVisual3D)ji.visuals[b]; float f16X = skeleton.Position[ji.joint1].X; float f16Y = skeleton.Position[ji.joint1].Y; float f16Z = skeleton.Position[ji.joint1].Z; float f17X = skeleton.Position[ji.joint2].X; float f17Y = skeleton.Position[ji.joint2].Y; float f17Z = skeleton.Position[ji.joint2].Z; float aa = (float)(b + 1) / divHelper; //float aa = (float)b / ji.visuals.Count; TranslateTransform3D translationTraansorm; if (CheckBoxRelativeMoveIsChecked == true) { translationTraansorm = new TranslateTransform3D((aa * f16X) + ((1 - aa) * f17X) - skeleton.Position[0].X, (aa * f16Y) + ((1 - aa) * f17Y),// - skeletons[0].Position[0].Y, (aa * f16Z) + ((1 - aa) * f17Z) - skeleton.Position[0].Z); } else { translationTraansorm = new TranslateTransform3D((aa * f16X) + ((1 - aa) * f17X), (aa * f16Y) + ((1 - aa) * f17Y),// - skeletons[0].Position[0].Y, (aa * f16Z) + ((1 - aa) * f17Z)); } var myTransform3DGroup = new Transform3DGroup(); myTransform3DGroup.Children.Add(translationTraansorm); mv3d.Transform = myTransform3DGroup; } } }
//public static void GenerateRules(ArrayList recording, ParserToken[] features, String oldFileName, String newFileName, int clastersCount, double minimalTimeDistance) public static String GenerateRules(ArrayList recording, ParserToken[] features, String oldFileContent, int clastersCount, double minimalTimeDistance, int maxIterationsCount, String ruleName, String GDLVersion, double epsilon, int randomSeed, ref int[] keyframes) { double[][] rawData; rawData = new double[recording.Count][]; GDLInterpreter inter = new GDLInterpreter(features, null); String[] foo = null; long[] time = new long[recording.Count]; for (int a = 0; a < rawData.Length; a++) { rawData[a] = new double[features.Length]; TSkeleton ts = ((TSkeleton[])recording[a])[0]; if (a > 0) { //time[a] = time[a - 1] + ts.TimePeriod; time[a] = ts.TimePeriod; } Point3D[] bodyParts = HendlerHolder.GenerateBodyPartArray(ts, 0); foo = inter.ReturnConclusions(bodyParts, 0); TrackingMemory tm = (TrackingMemory)inter.Heap[0]; for (int b = 0; b < features.Length; b++) { double v = (double)tm.Features[features[b].Conclusion]; rawData[a][b] = v; //RuleReturnValue rrV = IsSatisfied(FeatureTable[a], conclusions, tm.Features); //if (rrV.RuleType == ParserToken.RuleTypeNumeric) } } //inter = new GDLInterpreter(AllFeatures, AllRules); ClasteringResults cr = KMeansClustering.Clasterize(rawData, clastersCount, maxIterationsCount, randomSeed); /* * double step = 2; * double[][] rawDataSubset = new double[(int)(rawData.Length/step)][]; * * for (int a = 0; (int)step * a < rawData.Length && a < rawDataSubset.Length; a++) * { * rawDataSubset[a] = new double[rawData[(int)step * a].Length]; * for (int b = 0; b < rawData[(int)step * a].Length; b++) * { * rawDataSubset[a][b] = rawData[a * (int)step][b]; * } * } * * ClasteringResults cr = HierarchicalClustering.Clasterize(rawDataSubset, clastersCount, 0); * SaveClusteringToFile(cr.clustering, rawDataSubset, 3); * //ClasteringResults cr = HierarchicalClustering.Clasterize(rawData, clastersCount, 0); * //SaveClusteringToFile(cr.clustering, rawData, 3); * * //ClasteringResults cr = DBSCAN.Clasterize(rawData, 64, 32); * //SaveClusteringToFile(cr.clustering, rawData, 3); * * int abc = 0; * if (abc == 0) * return null; */ //TimeAnalyser(cr.clustering, time,2); String newFeatures = ""; double festureEPS = epsilon; keyframes = new int[clastersCount]; int [] sequence = new int[rawData.Length]; for (int a = 0; a < rawData.Length; a++) { sequence[a] = -1; int classIndex = -1; //po wszytskich klastrach for (int c = 0; c < cr.means.Length; c++) { bool satisfied = true; for (int b = 0; b < rawData[a].Length; b++) { if (Math.Abs(rawData[a][b] - cr.means[c][b]) > cr.standardDeviations[c][b] + festureEPS) { satisfied = false; } } if (satisfied) { classIndex = c; keyframes[classIndex] = a; } } sequence[a] = classIndex; } //SaveClusteringToFile(sequence, rawData, 3); string newGDLFileContent = ""; //HowLong[] hla = GenerateSequenceFromClusteredData(cr.clustering, time); HowLong[] hla = GenerateSequenceFromRawData(sequence, time); if (GDLVersion == "1.0") { String[] featuresArray = new String[features.Length]; int position = 0; for (int a = 0; a < featuresArray.Length; a++) { int startF = oldFileContent.IndexOf("FEATURE", position, StringComparison.OrdinalIgnoreCase); int endF = oldFileContent.IndexOf("AS", startF, StringComparison.OrdinalIgnoreCase); int startLength = startF + "FEATURE".Length + 1; featuresArray[a] = oldFileContent.Substring(startLength, endF - startLength); position = endF; } String rules = ""; for (int a = 0; a < cr.means.Length; a++) { if (a > 0) { rules += "\r\n"; } rules += "RULE "; for (int b = 0; b < cr.means[0].Length; b++) { if (b > 0) { rules += "\r\n\t& "; } rules += "abs(" + featuresArray[b] + " -" + cr.means[a][b].ToString(CultureInfo.InvariantCulture) + ") <= " + cr.standardDeviations[a][b].ToString(CultureInfo.InvariantCulture) + " + " + festureEPS.ToString(CultureInfo.InvariantCulture); } rules += " THEN " + ruleName + "" + a; } String sequenceRules = ""; double[] probability; double[][][] seqHelp = NGramAnalyser(hla, time, clastersCount, minimalTimeDistance, out probability); for (int grams = 0; grams < seqHelp.Length; grams++) { if (grams > 0) { sequenceRules += "\r\n"; } if (seqHelp[grams] != null) { sequenceRules += "//Frequency of appearance: " + probability[grams].ToString(CultureInfo.InvariantCulture) + "\r\n"; sequenceRules += "RULE " + ruleName + "" + (int)seqHelp[grams][0][0]; if (seqHelp[grams].Length > 1) { sequenceRules += " & sequenceexists(\""; for (int a = 1; a < seqHelp[grams].Length; a++) { sequenceRules += "[" + ruleName + "" + (int)seqHelp[grams][a][0] + "," + (seqHelp[grams][a][1] / 1000).ToString(CultureInfo.InvariantCulture) + "]"; } } /*sequenceRules += "RULE sequenceexists(\""; * for (int a = 0; a < seqHelp[grams].Length; a++) * { * sequenceRules += "[" + ruleName + "" + (int)seqHelp[grams][a][0] + "," + (seqHelp[grams][a][1] / 1000).ToString(CultureInfo.InvariantCulture) + "]"; * }*/ sequenceRules += "\") THEN " + ruleName + "_" + (clastersCount - 1 + grams) + "GRAMS!"; } } String configuration = ""; configuration += "//Date and time of an analysis: " + DateTime.Now + "\r\n" + "//Done by: Tomasz Hachaj\r\n" + "//Clustering method: K-Means clustering\r\n" + "//Clusters count: " + clastersCount + "\r\n" + "//N-grams range: [" + (clastersCount - 1) + "," + (2 * clastersCount - 1) + "]\r\n" + "//Minimal time distance between rules in sequence: " + minimalTimeDistance.ToString(CultureInfo.InvariantCulture) + " seconds"; Random random = new Random(); String sentencjaDnia = SentencjaDnia[random.Next(SentencjaDnia.Length)]; newGDLFileContent += "//-------------R-GDLv1.0 RULES---------------------------------------\r\n" + rules; newGDLFileContent += "\r\n\r\n"; newGDLFileContent += "//-------------N-gram based analysis of sequences--------------------\r\n"; newGDLFileContent += sequenceRules; newGDLFileContent += "\r\n\r\n"; newGDLFileContent += "//-------------R-GDLv1.0 configuration details----------------------\r\n"; newGDLFileContent += configuration; newGDLFileContent += "\r\n\r\n"; newGDLFileContent += "//Citation of the day: " + sentencjaDnia; //String rules = Generate1_0Rules(cr, features); } if (GDLVersion == "1.1") { for (int a = 0; a < features.Length; a++) { if (a > 0) { newFeatures += "\r\n"; } newFeatures += "FEATURE " + festureEPS.ToString(CultureInfo.InvariantCulture) + " AS " + features[a].Conclusion + "_EPS"; } newFeatures += "\r\n"; newFeatures += "\r\n"; for (int a = 0; a < cr.means.Length; a++) { if (a > 0) { newFeatures += "\r\n"; } for (int b = 0; b < cr.means[0].Length; b++) { newFeatures += "FEATURE " + cr.means[a][b].ToString(CultureInfo.InvariantCulture) + " AS " + features[b].Conclusion + "_MEAN_" + a + "\r\n"; newFeatures += "FEATURE " + cr.standardDeviations[a][b].ToString(CultureInfo.InvariantCulture) + " AS " + features[b].Conclusion + "_DEV_" + a + "\r\n"; } } String rules = ""; for (int a = 0; a < cr.means.Length; a++) { if (a > 0) { rules += "\r\n"; } rules += "RULE "; for (int b = 0; b < cr.means[0].Length; b++) { if (b > 0) { rules += "& "; } rules += "abs(" + features[b].Conclusion + " -" + features[b].Conclusion + "_MEAN_" + a + ") <= " + features[b].Conclusion + "_DEV_" + a + " + " + features[b].Conclusion + "_EPS "; } rules += "THEN " + ruleName + "" + a; } String sequenceRules = ""; double[] probability; /*double[][][] seqHelp = NGramAnalyser(hla, time, clastersCount, minimalTimeDistance, out probability); * for (int grams = 0; grams < seqHelp.Length; grams++) * { * if (grams > 0) * sequenceRules += "\r\n"; * if (seqHelp[grams] != null) * { * sequenceRules += "//Frequency of appearance: " + probability[grams].ToString(CultureInfo.InvariantCulture) + "\r\n"; * //odwrócić kolejność wypisywania - od ostatniego do pierwszego * sequenceRules += "RULE " + ruleName + "" + (int)seqHelp[grams][0][0]; * if (seqHelp[grams].Length > 1) * { * sequenceRules += " & sequenceexists(\""; * for (int a = 1; a < seqHelp[grams].Length; a++) * { * sequenceRules += "[" + ruleName + "" + (int)seqHelp[grams][a][0] + "," + (seqHelp[grams][a][1] / 1000).ToString(CultureInfo.InvariantCulture) + "]"; * } * sequenceRules += "\")"; * } * sequenceRules += " THEN GESTURE_" + (clastersCount - 1 + grams) + "GRAMS!"; * } * }*/ String configuration = ""; configuration += "//Date and time of an analysis: " + DateTime.Now + "\r\n" + "//Done by: Tomasz Hachaj\r\n" + "//Clustering method: K-Means clustering\r\n" + "//Clusters count: " + clastersCount + "\r\n" + "//N-grams range: [" + (clastersCount - 1) + "," + (2 * clastersCount - 1) + "]\r\n" + "//Minimal time distance between rules in sequence: " + minimalTimeDistance.ToString(CultureInfo.InvariantCulture) + " seconds"; Random random = new Random(); String sentencjaDnia = SentencjaDnia[random.Next(SentencjaDnia.Length)]; //string newGDLFileContent = System.IO.File.ReadAllText(oldFileName); newGDLFileContent = oldFileContent; newGDLFileContent = "//-------------Original FEATURES-------------------------------------\r\n" + newGDLFileContent + "\r\n"; newGDLFileContent += "//-------------R-GDLv1.0 FEATURES------------------------------------\r\n" + newFeatures + "\r\n"; newGDLFileContent += "//-------------R-GDLv1.0 RULES---------------------------------------\r\n" + rules; /* * newGDLFileContent += "\r\n\r\n"; * newGDLFileContent += "//-------------N-gram based analysis of sequences--------------------\r\n"; * newGDLFileContent += sequenceRules; * newGDLFileContent += "\r\n\r\n"; * newGDLFileContent += "//-------------R-GDLv1.0 configuration details----------------------\r\n"; * newGDLFileContent += configuration; * newGDLFileContent += "\r\n\r\n"; * newGDLFileContent += "//Citation of the day: " + sentencjaDnia;*/ } if (GDLVersion == "1.2") { for (int a = 0; a < features.Length; a++) { if (a > 0) { newFeatures += "\r\n"; } newFeatures += "FEATURE " + festureEPS.ToString(CultureInfo.InvariantCulture) + " AS " + features[a].Conclusion + "_EPS"; } newFeatures += "\r\n"; newFeatures += "\r\n"; for (int a = 0; a < cr.means.Length; a++) { if (a > 0) { newFeatures += "\r\n"; } for (int b = 0; b < cr.means[0].Length; b++) { newFeatures += "FEATURE " + cr.means[a][b].ToString(CultureInfo.InvariantCulture) + " AS " + features[b].Conclusion + "_MEAN_" + a + "\r\n"; newFeatures += "FEATURE " + cr.standardDeviations[a][b].ToString(CultureInfo.InvariantCulture) + " AS " + features[b].Conclusion + "_DEV_" + a + "\r\n"; } } //newFeatures += "\r\n"; String clusterBordersFeatures = ""; for (int a = 0; a < cr.means.Length; a++) { for (int b = 0; b < cr.means[0].Length; b++) { clusterBordersFeatures += "FEATURE " + "abs(" + features[b].Conclusion + " -" + features[b].Conclusion + "_MEAN_" + a + ") / (" + features[b].Conclusion + "_DEV_" + a + " + " + features[b].Conclusion + "_EPS ) AS " + features[b].Conclusion + "_RULE_" + a + "_FEATURE_" + b; clusterBordersFeatures += "\r\n"; } } //newFeatures += "\r\n"; String ClustersScoresFeatures = ""; for (int a = 0; a < cr.means.Length; a++) { ClustersScoresFeatures += "FEATURE ("; for (int b = 0; b < cr.means[0].Length; b++) { if (b > 0) { ClustersScoresFeatures += " + "; } ClustersScoresFeatures += features[b].Conclusion + "_RULE_" + a + "_FEATURE_" + b; } ClustersScoresFeatures += " ) / " + cr.means[0].Length + " AS " + ruleName + a + "_SCORE\r\n"; } /* * ClustersScoresFeatures += "FEATURE ("; * for (int a = 0; a < cr.means.Length; a++) * { * if (a > 0) * ClustersScoresFeatures += "+ "; * ClustersScoresFeatures += ruleName + a + "_SCORE "; * } * ClustersScoresFeatures += ") / " + cr.means.Length + " AS " + ruleName + "_OVERALL_SCORE\r\n"; */ String rules = ""; for (int a = 0; a < cr.means.Length; a++) { if (a > 0) { rules += "\r\n"; } rules += "RULE "; for (int b = 0; b < cr.means[0].Length; b++) { if (b > 0) { rules += " & "; } rules += features[b].Conclusion + "_RULE_" + a + "_FEATURE_" + b + " <= 1"; } rules += " THEN " + ruleName + "" + a; } String sequenceRules = ""; /*double[] probability; * double[][][] seqHelp = NGramAnalyser(hla, time, clastersCount, minimalTimeDistance, out probability); * for (int grams = 0; grams < seqHelp.Length; grams++) * { * if (grams > 0) * sequenceRules += "\r\n"; * if (seqHelp[grams] != null) * { * sequenceRules += "//Frequency of appearance: " + probability[grams].ToString(CultureInfo.InvariantCulture) + "\r\n"; * //odwrócić kolejność wypisywania - od ostatniego do pierwszego * sequenceRules += "RULE " + ruleName + "" + (int)seqHelp[grams][0][0]; * if (seqHelp[grams].Length > 1) * { * sequenceRules += " & sequenceexists(\""; * for (int a = 1; a < seqHelp[grams].Length; a++) * { * sequenceRules += "[" + ruleName + "" + (int)seqHelp[grams][a][0] + "," + (seqHelp[grams][a][1] / 1000).ToString(CultureInfo.InvariantCulture) + "]"; * } * sequenceRules += "\")"; * } * * sequenceRules += " THEN GESTURE_" + (clastersCount - 1 + grams) + "GRAMS!"; * } * }*/ String configuration = ""; configuration += "//Date and time of an analysis: " + DateTime.Now + "\r\n" + "//Done by: Tomasz Hachaj\r\n" + "//Clustering method: K-Means clustering\r\n" + "//Clusters count: " + clastersCount + "\r\n" + "//N-grams range: [" + (clastersCount - 1) + "," + (2 * clastersCount - 1) + "]\r\n" + "//Minimal time distance between rules in sequence: " + minimalTimeDistance.ToString(CultureInfo.InvariantCulture) + " seconds"; Random random = new Random(); String sentencjaDnia = SentencjaDnia[random.Next(SentencjaDnia.Length)]; newGDLFileContent = oldFileContent; newGDLFileContent = "//-------------ORIGINAL FEATURES--------------------------------------\r\n" + newGDLFileContent + "\r\n"; newGDLFileContent += "//-------------R-GDLv1.0 FEATURES------------------------------------\r\n"; newGDLFileContent += "//-------------CLUSTER ANALYSIS--------------------------------------\r\n" + newFeatures + "\r\n"; newGDLFileContent += "//-------------CLUSTER BORDERS---------------------------------------\r\n"; newGDLFileContent += clusterBordersFeatures + "\r\n"; newGDLFileContent += "//-------------FEATURE SCORES----------------------------------------\r\n"; newGDLFileContent += ClustersScoresFeatures + "\r\n"; newGDLFileContent += "//-------------R-GDLv1.0 RULES---------------------------------------\r\n" + rules; /* * newGDLFileContent += "\r\n\r\n"; * newGDLFileContent += "//-------------N-gram based analysis of sequences--------------------\r\n"; * newGDLFileContent += sequenceRules; * newGDLFileContent += "\r\n\r\n"; * newGDLFileContent += "//-------------R-GDLv1.0 configuration details----------------------\r\n"; * newGDLFileContent += configuration; * newGDLFileContent += "\r\n\r\n"; * newGDLFileContent += "//Citation of the day: " + sentencjaDnia;*/ } return(newGDLFileContent); //System.IO.File.WriteAllText(newFileName, newGDLFileContent); }