Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace TPR_2_Console
- {
- class Program
- {
- static void Main(string[] args)
- {
- ICollection<Entity> teachingRow = Entity.GenerateEntities(
- new[] { 0, 1, 1, 2, 1, 1, 0, 2, 2, 5, 5, 4, 3, 5, 4, 3, 2, 4, 8, 3 },
- new[] { 1, 0, 1, 2, 3, 2, 0, 1, 3, 1, 3, 3, 6, 5, 4, 5, 7, 6, 1, 7 },
- new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
- );
- Entity weightVector = new Entity(1,1,1);
- Double alpha = 0.00005;
- Int32 tag = 1, iter = 0, a = 1;
- Int32 resultY;
- while ( tag != 0 )
- {
- tag = 0;
- foreach( Entity e in teachingRow)
- {
- Console.WriteLine("{0} {1} {2}", weightVector.X, weightVector.Y, weightVector.Class);
- if( weightVector.X * e.X + weightVector.Y * e.Y <= weightVector.Class)
- {
- resultY = 0;
- }
- else
- {
- resultY = 1;
- }
- if ( resultY != e.Class)
- {
- ++tag;
- }
- else
- {
- continue;
- }
- switch( a )
- {
- case 1:
- weightVector.X += alpha * e.X * (e.Class - resultY);
- ++a;
- break;
- case 2:
- weightVector.Y += alpha * e.Y * (e.Class - resultY);
- ++a;
- break;
- case 3:
- weightVector.Class += alpha * (e.Class - resultY);
- a = 1;
- break;
- default:
- break;
- }
- }
- ++iter;
- }
- Console.WriteLine("{0} {1} {2}", weightVector.X, weightVector.Y, weightVector.Class);
- Console.ReadKey();
- }
- }
- public class Entity
- {
- public Double X { get; set; }
- public Double Y { get; set; }
- public Double Class { get; set; }
- public Entity()
- {
- }
- public Entity(Int32 X, Int32 Y, Int32 Class)
- {
- this.X = X;
- this.Y = Y;
- this.Class = Class;
- }
- public static ICollection<Entity> GenerateEntities( Int32[] xArray, Int32[] yArray, Int32[] classArray)
- {
- ICollection<Entity> entities = new List<Entity>();
- for ( int i = 0; i < xArray.Length; ++i)
- {
- entities.Add(new Entity()
- {
- X = xArray[i],
- Y = yArray[i],
- Class = classArray[i]
- });
- }
- return entities;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement