private void button_next_Click(object sender, EventArgs e) { if (btn_next.DialogResult == DialogResult.OK) { if (!m_appMode) { m_network = uc_gesture.MyNNetwork; foreach (MyGesture group in uc_actions.NewGroups) { m_newGestures.Add(group); } foreach (MyGesture group in uc_actions.SelectedGroups) { string id = MyGesture.CreateUniqueId(m_tempGesture, m_gestures); MyGesture gest = new MyGesture(id); gest.SetItem(m_tempGesture); gest.Activator = m_tempGesture.Activator; gest.Action = m_tempGesture.Action; gest.AppGroup = group; m_newGestures.Add(gest); m_gestures.Add(gest); } } else { string id = MyGesture.CreateUniqueId(m_tempGesture, m_gestures); MyGesture gest = new MyGesture(id); gest.SetItem(m_tempGesture); gest.Action = m_tempGesture.Action; gest.Activator = new MouseActivator(string.Empty, MouseActivator.Types.Undefined); m_newGestures.Add(gest); } } MoveToPage(m_currentControl.Next); }
private void btn_ok_Click(object sender, EventArgs e) { if (!m_appMode) { m_network = uc_gesture.MyNNetwork; } if (modifiedGestures.Length == 1) { modifiedGestures[0].SetItem(tempGesture); modifiedGestures[0].Activator = tempGesture.Activator; modifiedGestures[0].Action = tempGesture.Action; if (modifiedGestures[0].IsImplicitOnly) { modifiedGestures[0].ExecutionType = ExecuteType.Implicit; } if (!m_appMode) { modifiedGestures[0].ItemPos = -1; } } else { foreach (MyGesture gest in modifiedGestures) { gest.Activator = tempGesture.Activator; gest.ItemPos = -1; } } }
private List <Neuron> CrossingGenomes(MyNeuralNetwork _choosenOne, MyNeuralNetwork _choosenTwo) { // Do a deepcopy. If not, referecnce will be use and change the _choosenOne neurons which converge List <Neuron> neurons = _choosenOne.Neurons.Select(neuron => new Neuron(neuron)).ToList(); this.DebugCrossing(" Tre", neurons); for (int i = 0; i < neurons.Count; i++) { for (int j = 0; j < neurons.ElementAt(i).Weights.Count; j++) { // Mutation change if (this.rand.NextDouble() >= GeneticConfig.MUTATION_PERCENT) { double cache = neurons.ElementAt(i).Weights[j]; neurons.ElementAt(i).Weights[j] = this.GetWeight(this.rand.NextDouble()); Console.WriteLine("Mution on neurone ==> Weight : " + j + " : " + cache + " ===> " + neurons.ElementAt(i).Weights[j]); } else { // 50% chance to get gene from one or the other if (this.rand.NextDouble() < 0.5) { neurons.ElementAt(i).Weights[j] = _choosenTwo.Neurons.ElementAt(i).Weights[j]; } } } } return(neurons); }
private void SetFromRecognizedGesture() { //m_network.StopLearning(); m_network = new MyNeuralNetwork(m_networkBackup); m_shortCurve = false; m_tempGesture.Activator = new MouseActivator(m_recognizedCurve); OnCanContinue(true); }
private void SetNewGesture() { if (m_newCurveUsed) { m_networkTrained.StopLearning(); m_networkTrained = new MyNeuralNetwork(m_networkBackup); m_networkTrained.LearnNewCurve(m_newCurve); m_newCurveUsed = false; } m_network = m_networkTrained; //tB_newName.Enabled = true; m_tempGesture.Activator = new MouseActivator(m_newCurve); SetCurveCaption(); }
private void button_next_Click(object sender, EventArgs e) { if (btn_next.DialogResult == DialogResult.OK) { if (!m_appMode) { m_network = uc_gesture.MyNNetwork; foreach (MyGesture group in uc_actions.NewGroups) m_newGestures.Add(group); foreach (MyGesture group in uc_actions.SelectedGroups) { string id = MyGesture.CreateUniqueId(m_tempGesture, m_gestures); MyGesture gest = new MyGesture(id); gest.SetItem(m_tempGesture); gest.Activator = m_tempGesture.Activator; gest.Action = m_tempGesture.Action; gest.AppGroup = group; m_newGestures.Add(gest); m_gestures.Add(gest); } } else { string id = MyGesture.CreateUniqueId(m_tempGesture, m_gestures); MyGesture gest = new MyGesture(id); gest.SetItem(m_tempGesture); gest.Action = m_tempGesture.Action; gest.Activator = new MouseActivator(string.Empty, MouseActivator.Types.Undefined); m_newGestures.Add(gest); } } MoveToPage(m_currentControl.Next); }
private void btn_ok_Click(object sender, EventArgs e) { if (!m_appMode) m_network = uc_gesture.MyNNetwork; if (modifiedGestures.Length == 1) { modifiedGestures[0].SetItem(tempGesture); modifiedGestures[0].Activator = tempGesture.Activator; modifiedGestures[0].Action = tempGesture.Action; if (modifiedGestures[0].IsImplicitOnly) modifiedGestures[0].ExecutionType = ExecuteType.Implicit; if (!m_appMode) modifiedGestures[0].ItemPos = -1; } else { foreach (MyGesture gest in modifiedGestures) { gest.Activator = tempGesture.Activator; gest.ItemPos = -1; } } }
public override void Initialize() { base.Initialize(); if (m_gesturesCollection.GetCurves().Count >= Config.User.NnOutputSize) m_maximumLimitReached = true; m_pen = new Pen(Color.Blue, 3); m_pen.StartCap = System.Drawing.Drawing2D.LineCap.Round; m_pen.EndCap = System.Drawing.Drawing2D.LineCap.Round; m_networkBackup = new MyNeuralNetwork(m_network); m_networkTrained = new MyNeuralNetwork(m_network); foreach (MyGesture gest in m_gesturesCollection.Gestures) if (gest.Activator.Type == MouseActivator.Types.ClassicCurve && !imageList1.Images.ContainsKey(gest.Activator.ID)) { ClassicCurve classicCurve = gest.Activator; imageList1.Images.Add(gest.Activator.ID, gest.Activator.ExtractIcon(imageList1.ImageSize)); ListViewItem item = new ListViewItem(new string[] { "", classicCurve.Caption }, gest.Activator.ID); item.Name = gest.Activator.ID; lv_curvesList.Items.Add(item); } if (m_tempGesture.Activator != null && m_tempGesture.Activator.Type == BaseActivator.Types.ClassicCurve) { ClassicCurve classicCurve = m_tempGesture.Activator; m_newCurve = m_tempGesture.Activator; tB_newName.Text = classicCurve.Caption; if (lv_curvesList.Items.ContainsKey(m_tempGesture.Activator.ID)) { //sameCurve = true; lv_curvesList.Focus(); lv_curvesList.EnsureVisible(lv_curvesList.Items[m_tempGesture.Activator.ID].Index); lv_curvesList.Items[m_tempGesture.Activator.ID].Selected = true; rB_newCurve.Enabled = false; } else { gB_use.Enabled = true; m_newCurveUsed = false; m_networkTrained = new MyNeuralNetwork(m_networkOriginal); rB_newCurve.Checked = true; //SetNewGesture(); } } else { rB_newCurve.Enabled = false; tB_newName.Enabled = false; tB_newName.Text = "curve_name"; } gB_alreadyInUse.Text = Translation.GetText("C_CurveG_gB_alreadyInUse"); cH_curve.Text = Translation.GetText("C_CurveG_cH_curve"); cH_name.Text = Translation.GetText("C_CurveG_cH_name"); cH_associatedActions.Text = Translation.GetText("C_Gestures_cH_associatedActions"); cH_group.Text = Translation.GetText("C_Gestures_cH_group"); gB_use.Text = Translation.GetText("C_CurveG_gB_useCurve"); rB_newCurve.Text = Translation.GetText("C_CurveG_rB_newOne"); rB_suggestedCurve.Text = Translation.GetText("C_CurveG_rB_selected"); lbl_name.Text = Translation.GetText("C_CurveG_lbl_name"); }
//private double GetOutPointsRatio(string learntCurveName) //{ // ClassicCurve learntCurve = m_gesturesCollection.GetCurve(learntCurveName); // if (learntCurve != null) // { // Rectangle rect = new Rectangle(0, 0, 20, 20); // int parts = 5; // List<PointF> centerLearnPoints = MyCurve.ScaleToCenter(MyCurve.CreateExactPath(learntCurve.Points, 1, 2), rect); // int centerCount = centerLearnPoints.Count / parts; // List<PointF> centerPoints = MyCurve.ScaleToCenter(MyCurve.CreateExactPath(m_pathPoints, 1, 2), rect); // int testCount = centerPoints.Count / parts; // int outPoints = 0; // for (int i = 0; i < parts; i++) // { // int centerMax = centerCount; // int testMax =testCount; // if (i + 1 == parts) // { // centerMax = centerLearnPoints.Count - i * centerCount; // testMax = centerPoints.Count - i * testCount; // } // System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); // List<PointF> center10 = centerLearnPoints.GetRange(i * centerCount, centerMax); // path.AddLines(center10.ToArray()); // path.Widen(new Pen(Color.Green, 3)); // List<PointF> test10 = centerPoints.GetRange(i * testCount, testMax); // foreach (PointF point in test10) // { // if (!path.IsVisible(point)) // outPoints++; // } // m_gp.DrawPath(new Pen(Brushes.Yellow, 1), path); // m_gp.DrawLines(new Pen(Brushes.Red, 1), test10.ToArray()); // } // m_pbDisplay.Invalidate(); // double ratio = outPoints / (double)centerPoints.Count; // Debug.WriteLine("Ratio of points out of region is: " + ratio); // return ratio; // } // return 1; //} #endregion Not in use public override void Display_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && m_pathPoints.Count > 1) { m_mouseDown = false; MyCurve curve = new MyCurve(m_pathPoints, true); if (m_curveLength > CURVE_MIN_LENGTH) { //if (curve != null && curve.Points.Count > 1) //{ // List<PointF> rotated = MyCurve.RotateCurve(curve.Points, 10); // m_gp.DrawLines(new Pen(Brushes.Yellow, 2), rotated.ToArray()); // rotated = MyCurve.RotateCurve(curve.Points, -10); // m_gp.DrawLines(new Pen(Brushes.Pink, 2), rotated.ToArray()); // m_pbDisplay.Invalidate(); //} //return; //if (curve != null && curve.Points.Count > 1) //{ // List<PointF> resized = MyCurve.ResizeCurve(curve.Points, 0.25, 0); // m_gp.DrawLines(new Pen(Brushes.Yellow, 2), resized.ToArray()); // resized = MyCurve.ResizeCurve(curve.Points, -0.25, 0); // m_gp.DrawLines(new Pen(Brushes.Pink, 2), resized.ToArray()); // m_pbDisplay.Invalidate(); //} //return; //m_network.StopLearning(); m_newCurveUsed = true; m_networkTrained.StopLearning(); m_network = new MyNeuralNetwork(m_networkBackup); m_shortCurve = false; double divergence; string name = m_network.RecognizeCurve(curve.GetScaledInput(), out divergence); m_tooMuchSimilar = (divergence >= 0 && divergence < MAX_DIVERGENCE); if (name != string.Empty) { if (m_tooMuchSimilar) m_newCurve = m_gesturesCollection.GetCurve(name); else m_newCurve = new ClassicCurve(m_pathPoints, m_gesturesCollection); rB_newCurve.Enabled = !m_tooMuchSimilar; lv_curvesList.Focus(); lv_curvesList.EnsureVisible(lv_curvesList.Items[name].Index); if (!lv_curvesList.Items[name].Selected) lv_curvesList.Items[name].Selected = true; else { if (!rB_suggestedCurve.Checked) rB_suggestedCurve.Checked = true; else { lv_curvesList.Items[name].Selected = false; lv_curvesList.Items[name].Selected = true; //panel_curveDraw.Refresh(); } } } else { m_newCurve = new ClassicCurve(m_pathPoints, m_gesturesCollection); rB_newCurve.Enabled = true; if (!rB_newCurve.Checked) rB_newCurve.Checked = true; else { Debug.WriteLine("Drawing - MouseUp (new gesture)"); m_newCurve.DrawToPictureBox(m_pbDisplay); SetNewGesture(); } } OnCanContinue(true); SetInfoValues(); } else { m_newCurve = null; m_shortCurve = true; //Debug.WriteLine("Drawing - MouseUp (short gesture)"); m_gp = Graphics.FromImage(m_pbDisplay.Image); m_gp.FillRectangle(Brushes.White, 0, 0, m_pbDisplay.Width, m_pbDisplay.Height); m_pbDisplay.Invalidate(); m_pbDisplay.Focus(); rB_newCurve.Enabled = false; OnCanContinue(false); SetInfoValues(); } m_gp.Dispose(); } }
public override void Initialize() { base.Initialize(); if (m_gesturesCollection.GetCurves().Count >= Config.User.NnOutputSize) { m_maximumLimitReached = true; } m_pen = new Pen(Color.Blue, 3); m_pen.StartCap = System.Drawing.Drawing2D.LineCap.Round; m_pen.EndCap = System.Drawing.Drawing2D.LineCap.Round; m_networkBackup = new MyNeuralNetwork(m_network); m_networkTrained = new MyNeuralNetwork(m_network); foreach (MyGesture gest in m_gesturesCollection.Gestures) { if (gest.Activator.Type == MouseActivator.Types.ClassicCurve && !imageList1.Images.ContainsKey(gest.Activator.ID)) { ClassicCurve classicCurve = gest.Activator; imageList1.Images.Add(gest.Activator.ID, gest.Activator.ExtractIcon(imageList1.ImageSize)); ListViewItem item = new ListViewItem(new string[] { "", classicCurve.Caption }, gest.Activator.ID); item.Name = gest.Activator.ID; lv_curvesList.Items.Add(item); } } if (m_tempGesture.Activator != null && m_tempGesture.Activator.Type == BaseActivator.Types.ClassicCurve) { ClassicCurve classicCurve = m_tempGesture.Activator; m_newCurve = m_tempGesture.Activator; tB_newName.Text = classicCurve.Caption; if (lv_curvesList.Items.ContainsKey(m_tempGesture.Activator.ID)) { //sameCurve = true; lv_curvesList.Focus(); lv_curvesList.EnsureVisible(lv_curvesList.Items[m_tempGesture.Activator.ID].Index); lv_curvesList.Items[m_tempGesture.Activator.ID].Selected = true; rB_newCurve.Enabled = false; } else { gB_use.Enabled = true; m_newCurveUsed = false; m_networkTrained = new MyNeuralNetwork(m_networkOriginal); rB_newCurve.Checked = true; //SetNewGesture(); } } else { rB_newCurve.Enabled = false; tB_newName.Enabled = false; tB_newName.Text = "curve_name"; } gB_alreadyInUse.Text = Translation.GetText("C_CurveG_gB_alreadyInUse"); cH_curve.Text = Translation.GetText("C_CurveG_cH_curve"); cH_name.Text = Translation.GetText("C_CurveG_cH_name"); cH_associatedActions.Text = Translation.GetText("C_Gestures_cH_associatedActions"); cH_group.Text = Translation.GetText("C_Gestures_cH_group"); gB_use.Text = Translation.GetText("C_CurveG_gB_useCurve"); rB_newCurve.Text = Translation.GetText("C_CurveG_rB_newOne"); rB_suggestedCurve.Text = Translation.GetText("C_CurveG_rB_selected"); lbl_name.Text = Translation.GetText("C_CurveG_lbl_name"); }
//private double GetOutPointsRatio(string learntCurveName) //{ // ClassicCurve learntCurve = m_gesturesCollection.GetCurve(learntCurveName); // if (learntCurve != null) // { // Rectangle rect = new Rectangle(0, 0, 20, 20); // int parts = 5; // List<PointF> centerLearnPoints = MyCurve.ScaleToCenter(MyCurve.CreateExactPath(learntCurve.Points, 1, 2), rect); // int centerCount = centerLearnPoints.Count / parts; // List<PointF> centerPoints = MyCurve.ScaleToCenter(MyCurve.CreateExactPath(m_pathPoints, 1, 2), rect); // int testCount = centerPoints.Count / parts; // int outPoints = 0; // for (int i = 0; i < parts; i++) // { // int centerMax = centerCount; // int testMax =testCount; // if (i + 1 == parts) // { // centerMax = centerLearnPoints.Count - i * centerCount; // testMax = centerPoints.Count - i * testCount; // } // System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); // List<PointF> center10 = centerLearnPoints.GetRange(i * centerCount, centerMax); // path.AddLines(center10.ToArray()); // path.Widen(new Pen(Color.Green, 3)); // List<PointF> test10 = centerPoints.GetRange(i * testCount, testMax); // foreach (PointF point in test10) // { // if (!path.IsVisible(point)) // outPoints++; // } // m_gp.DrawPath(new Pen(Brushes.Yellow, 1), path); // m_gp.DrawLines(new Pen(Brushes.Red, 1), test10.ToArray()); // } // m_pbDisplay.Invalidate(); // double ratio = outPoints / (double)centerPoints.Count; // Debug.WriteLine("Ratio of points out of region is: " + ratio); // return ratio; // } // return 1; //} #endregion Not in use public override void Display_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && m_pathPoints.Count > 1) { m_mouseDown = false; MyCurve curve = new MyCurve(m_pathPoints, true); if (m_curveLength > CURVE_MIN_LENGTH) { //if (curve != null && curve.Points.Count > 1) //{ // List<PointF> rotated = MyCurve.RotateCurve(curve.Points, 10); // m_gp.DrawLines(new Pen(Brushes.Yellow, 2), rotated.ToArray()); // rotated = MyCurve.RotateCurve(curve.Points, -10); // m_gp.DrawLines(new Pen(Brushes.Pink, 2), rotated.ToArray()); // m_pbDisplay.Invalidate(); //} //return; //if (curve != null && curve.Points.Count > 1) //{ // List<PointF> resized = MyCurve.ResizeCurve(curve.Points, 0.25, 0); // m_gp.DrawLines(new Pen(Brushes.Yellow, 2), resized.ToArray()); // resized = MyCurve.ResizeCurve(curve.Points, -0.25, 0); // m_gp.DrawLines(new Pen(Brushes.Pink, 2), resized.ToArray()); // m_pbDisplay.Invalidate(); //} //return; //m_network.StopLearning(); m_newCurveUsed = true; m_networkTrained.StopLearning(); m_network = new MyNeuralNetwork(m_networkBackup); m_shortCurve = false; double divergence; string name = m_network.RecognizeCurve(curve.GetScaledInput(), out divergence); m_tooMuchSimilar = (divergence >= 0 && divergence < MAX_DIVERGENCE); if (name != string.Empty) { if (m_tooMuchSimilar) { m_newCurve = m_gesturesCollection.GetCurve(name); } else { m_newCurve = new ClassicCurve(m_pathPoints, m_gesturesCollection); } rB_newCurve.Enabled = !m_tooMuchSimilar; lv_curvesList.Focus(); lv_curvesList.EnsureVisible(lv_curvesList.Items[name].Index); if (!lv_curvesList.Items[name].Selected) { lv_curvesList.Items[name].Selected = true; } else { if (!rB_suggestedCurve.Checked) { rB_suggestedCurve.Checked = true; } else { lv_curvesList.Items[name].Selected = false; lv_curvesList.Items[name].Selected = true; //panel_curveDraw.Refresh(); } } } else { m_newCurve = new ClassicCurve(m_pathPoints, m_gesturesCollection); rB_newCurve.Enabled = true; if (!rB_newCurve.Checked) { rB_newCurve.Checked = true; } else { Debug.WriteLine("Drawing - MouseUp (new gesture)"); m_newCurve.DrawToPictureBox(m_pbDisplay); SetNewGesture(); } } OnCanContinue(true); SetInfoValues(); } else { m_newCurve = null; m_shortCurve = true; //Debug.WriteLine("Drawing - MouseUp (short gesture)"); m_gp = Graphics.FromImage(m_pbDisplay.Image); m_gp.FillRectangle(Brushes.White, 0, 0, m_pbDisplay.Width, m_pbDisplay.Height); m_pbDisplay.Invalidate(); m_pbDisplay.Focus(); rB_newCurve.Enabled = false; OnCanContinue(false); SetInfoValues(); } m_gp.Dispose(); } }