-
Notifications
You must be signed in to change notification settings - Fork 1
/
Weight.cs
39 lines (29 loc) · 992 Bytes
/
Weight.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
//using Microsoft.Analytics.Interfaces;
//using Microsoft.Analytics.Types.Sql;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
// this section is refered from https://github.com/patrickmeiring/LeNet
namespace LeNet5
{
class Weight
{
private static ThreadLocal<Random> randomWrapper = new ThreadLocal<Random>(()=>new Random());
public static double[] RandomWeights(int Amount,int FanIn)
{
var res = new double[Amount];
for (int i = 0; i < res.Length; i++)
{
res[i] = (randomWrapper.Value.NextDouble() - 0.5) * (4.8 / FanIn);
}
return res;
}
public static double Random(int FanIn)
{
return (randomWrapper.Value.NextDouble() - 0.5) * (4.8 / FanIn);
}
}
}