-
Notifications
You must be signed in to change notification settings - Fork 0
/
NeuroHelper.cs
87 lines (68 loc) · 2.03 KB
/
NeuroHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.Linq;
namespace NeuralNetwork
{
public static class NeuroHelper
{
private static Random Random = new Random(DateTime.Today.Millisecond);
public static float NeuronWeightMutationChance { get; set; } = 0.25f;
public static float NeuronBiasMutationChance { get; set; } = 0.1f;
public static float LayerMutationChance { get; set; } = 0.001f;
public static float NeuronWeightMutationDefaultValue { get; set; } = 0.2f;
public static float NeuronBiasMutationDefaultValue { get; set; } = 0.2f;
public static float RandomNext(float min = -1f, float max = 1f)
{
return Random.Next((int)(min * 1000f), (int)(max * 1000f)) / 1000f;
}
public static int RandomNext(int min, int max)
{
return Random.Next(min, max);
}
public static float Sigmoid(float value)
{
return (2f / (1 + (float)Math.Exp(-2f * value))) - 1f;
}
public static string ToString(this float[] value, char seperator)
{
string s = "";
for (int i = 0; i < value.Length; i++)
{
s += value[i] + seperator.ToString();
}
s = s.Substring(0, s.Length - 1);
return s;
}
public static string ToString(this int[] value, char seperator)
{
float[] f = new float[value.Length];
value.CopyTo(f, 0);
return f.ToString(seperator);
}
public static int[] ToIntArray(this string value, char seperator)
{
List<int> values = new List<int>();
string s = value;
for(int i= 0; i < s.Count(x => x == seperator); i++)
{
values.Add(int.Parse(s.Substring(0, s.IndexOf(seperator))));
s = s.Substring(s.IndexOf(seperator) + 1);
}
return values.ToArray();
}
public static float[] ToFloatArray(this string value, char seperator)
{
List<float> values = new List<float>();
string s = value;
for (int i = 0; i < s.Count(x => x == seperator); i++)
{
if (s.Contains(seperator))
{
values.Add(float.Parse(s.Substring(0, s.IndexOf(seperator))));
s = s.Substring(s.IndexOf(seperator) + 1);
}
}
return values.ToArray();
}
}
}