Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Brilliant.ArtificialNeuralNetworks.Perceptrons.PerceptronLeaningAlgori...
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { private class WnB { private static int s_Id; public int[] W { get; set; } public int B { get; set; } public int Id { get; private set;} public WnB() { Id = s_Id++; } public override string ToString() { return "[" + Id + "] " + "W={" + string.Join(",", W.Select(v => v.ToString())) + "}, B=" + B; } public int Total { get { return B + W.Aggregate(0, (a, v) => a + v); } } } private class Datum { public int[] X { get; set; } public int Y { get; set; } public bool Test(WnB wnb) { return Y * (Multi(wnb.W, X) + wnb.B) > 0; } public override string ToString() { return "X={" + string.Join(",", X.Select(v => v.ToString())) + "}, Y=" + Y; } } public static void Main(string[] args) { var data = new[] { new Datum {X = new[] {-1, 1}, Y = 1}, new Datum {X = new[] {0, -1}, Y = -1}, new Datum {X = new[] {10, 1}, Y = 1} }; WnB wnb; int i=1; for (wnb = new WnB {W = new[] {0, 0}, B = 0}; data.Any(datum => !datum.Test(wnb)); wnb = data.Aggregate( wnb, (curWnB, datum) => { var nextWnB = datum.Test(curWnB) ? curWnB : new WnB {W = Add(curWnB.W, Multy(datum.Y, datum.X)), B = curWnB.B + datum.Y}; Console.WriteLine(datum + " begets " + nextWnB); return nextWnB; })) { Console.WriteLine("Round #" + i++); } Console.WriteLine("Total=" + wnb.Total); } private static int[] Add(int[] a, int[] b) { return a.Zip(b, (x, y) => x + y).ToArray(); } private static int[] Multy(int a, int[] b) { return b.Select(v => v * a).ToArray(); } private static int Multi(int[] a, int[] b) { return a.Zip(b, (x, y) => x * y).Sum(); } } }
run
|
edit
|
history
|
help
0
Events
Convert string to int
Factory Method Design Pattern
Maximum profit
tipos de bucle for, while, do while
sum 2
prime number
User
singly linked list traversal
Game Dev Challenge #1